mtk_cooler_amdtxctrl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/types.h>
  4. #include <linux/kobject.h>
  5. #include <linux/proc_fs.h>
  6. #include <asm/uaccess.h>
  7. #include <linux/err.h>
  8. #include <linux/syscalls.h>
  9. #include <linux/timer.h>
  10. #include <mach/mtk_eemcs_helper.h>
  11. #include "mt-plat/mtk_thermal_monitor.h"
  12. #define CONFIG_SIGNAL_USER_SPACE (0)
  13. #if CONFIG_SIGNAL_USER_SPACE
  14. #include <linux/pid.h>
  15. #endif
  16. #define cl_type_upper "cl-amdtxctrl-u"
  17. #define cl_type_lower "cl-amdtxctrl-l"
  18. #define mtk_cooler_amdtxctrl_dprintk_always(fmt, args...) \
  19. pr_debug("thermal/cooler/amdtxctrl" fmt, ##args)
  20. #define mtk_cooler_amdtxctrl_dprintk(fmt, args...) \
  21. do { \
  22. if (1 == cl_amdtxctrl_klog_on) { \
  23. pr_debug("thermal/cooler/amdtxctrl" fmt, ##args); \
  24. } \
  25. } while (0)
  26. #define MAX_NUM_INSTANCE_MTK_COOLER_MDULTHRO 1
  27. static int cl_amdtxctrl_klog_on;
  28. /* over_up_time * polling interval > up_duration --> throttling */
  29. static unsigned int over_up_time; /* polling time */
  30. static unsigned int up_duration = 30; /* sec */
  31. static unsigned int up_step = 1; /* step */
  32. /* below_low_time * polling interval > low_duration --> throttling */
  33. static unsigned int below_low_time; /* polling time */
  34. static unsigned int low_duration = 10; /* sec */
  35. static unsigned int low_step = 1; /* step */
  36. static unsigned int low_rst_time;
  37. static unsigned int low_rst_max = 3;
  38. static int polling_interval = 1; /* second */
  39. #define UNK_STAT -1
  40. #define LOW_STAT 0
  41. #define MID_STAT 1
  42. #define HIGH_STAT 2
  43. #define MAX_LEN 256
  44. #define COOLER_STEPS 5
  45. #if CONFIG_SIGNAL_USER_SPACE
  46. static unsigned int tm_pid;
  47. static unsigned int tm_input_pid;
  48. static struct task_struct g_task;
  49. static struct task_struct *pg_task = &g_task;
  50. #endif
  51. static unsigned int cl_upper_dev_state;
  52. static unsigned int cl_lower_dev_state;
  53. static struct thermal_cooling_device *cl_upper_dev;
  54. static struct thermal_cooling_device *cl_lower_dev;
  55. typedef int (*activate_cooler_opp_func) (int level);
  56. static activate_cooler_opp_func opp_func[COOLER_STEPS] = { 0 };
  57. typedef struct adaptive_cooler {
  58. int cur_level;
  59. int max_level;
  60. activate_cooler_opp_func *opp_func_array;
  61. } adaptive_coolers;
  62. static adaptive_coolers amdtxctrl;
  63. static int amdtxpwr_backoff(int level)
  64. {
  65. int ret;
  66. if (level == 0) {
  67. /* no throttle */
  68. /* ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_DTX_REQ, 8); */
  69. ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_TX_PWR_REDU_REQ, 23); /* TODO: 30db as unlimit... */
  70. mtk_cooler_amdtxctrl_dprintk_always("[%s] unlimit DTX and TX\n", __func__);
  71. }
  72. #if 0
  73. else if (level >= 1 && level <= 7) {
  74. /* only DTX */
  75. ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_DTX_REQ, 8 - level);
  76. ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_TX_PWR_REDU_REQ, 23); /* TODO: 30db as unlimit... */
  77. mtk_cooler_amdtxctrl_dprintk_always("[%s] limit DTX %d and unlimit TX\n", __func__,
  78. 8 - level);
  79. }
  80. #endif
  81. else if (level >= 1 && level <= COOLER_STEPS - 1) {
  82. /* DTX 1/8 + Tx power back off */
  83. /* ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_DTX_REQ, 1); */
  84. /* TODO: 30db as unlimit... */
  85. ret = eemcs_notify_md_by_sys_msg(MD_SYS5, EXT_MD_TX_PWR_REDU_REQ, (23 - (level) * 3));
  86. mtk_cooler_amdtxctrl_dprintk_always("[%s] limit DTX 1 and limit TX %d\n", __func__,
  87. (23 - (level) * 3));
  88. } else {
  89. /* error... */
  90. ret = -1;
  91. mtk_cooler_amdtxctrl_dprintk_always("[%s] ouf of range\n", __func__);
  92. }
  93. return ret;
  94. }
  95. static int down_throttle(adaptive_coolers *p, int step)
  96. {
  97. if (NULL == p)
  98. return -1;
  99. if (step <= 0)
  100. return p->cur_level;
  101. if (p->cur_level + step > p->max_level) {
  102. p->cur_level = p->max_level;
  103. p->opp_func_array[p->cur_level] (p->cur_level);
  104. return p->cur_level;
  105. }
  106. p->cur_level += step;
  107. p->opp_func_array[p->cur_level] (p->cur_level);
  108. return p->cur_level;
  109. }
  110. static int up_throttle(adaptive_coolers *p, int step)
  111. {
  112. if (NULL == p)
  113. return -1;
  114. if (step <= 0)
  115. return p->cur_level;
  116. if (p->cur_level - step < 0) {
  117. p->cur_level = 0;
  118. p->opp_func_array[p->cur_level] (p->cur_level);
  119. return p->cur_level;
  120. }
  121. p->cur_level -= step;
  122. p->opp_func_array[p->cur_level] (p->cur_level);
  123. return p->cur_level;
  124. }
  125. static int rst_throttle(adaptive_coolers *p)
  126. {
  127. if (NULL == p)
  128. return -1;
  129. p->cur_level = 0;
  130. p->opp_func_array[p->cur_level] (p->cur_level);
  131. return p->cur_level;
  132. }
  133. #if CONFIG_SIGNAL_USER_SPACE
  134. static int wmt_send_signal(int level)
  135. {
  136. int ret = 0;
  137. int thro = level;
  138. if (tm_input_pid == 0) {
  139. mtk_cooler_amdtxctrl_dprintk("[%s] pid is empty\n", __func__);
  140. ret = -1;
  141. }
  142. mtk_cooler_amdtxctrl_dprintk_always("[%s] pid is %d, %d, %d\n", __func__, tm_pid,
  143. tm_input_pid, thro);
  144. if (ret == 0 && tm_input_pid != tm_pid) {
  145. tm_pid = tm_input_pid;
  146. pg_task = get_pid_task(find_vpid(tm_pid), PIDTYPE_PID);
  147. }
  148. if (ret == 0 && pg_task) {
  149. siginfo_t info;
  150. info.si_signo = SIGIO;
  151. info.si_errno = 1; /* for md ul throttling */
  152. info.si_code = thro;
  153. info.si_addr = NULL;
  154. ret = send_sig_info(SIGIO, &info, pg_task);
  155. }
  156. if (ret != 0)
  157. mtk_cooler_amdtxctrl_dprintk("[%s] ret=%d\n", __func__, ret);
  158. return ret;
  159. }
  160. #endif /* CONFIG_SIGNAL_USER_SPACE */
  161. /* index --> 0, lower; 1, upper */
  162. /* is_on --> 0, off; 1, on */
  163. static int judge_throttling(int index, int is_on, int interval)
  164. {
  165. /*
  166. * throttling_stat
  167. * 2 ( upper=1,lower=1 )
  168. * UPPER ----
  169. * 1 ( upper=0,lower=1 )
  170. * LOWER ----
  171. * 0 ( upper=0,lower=0 )
  172. */
  173. static unsigned int throttling_pre_stat;
  174. static int mail_box[2] = { -1, -1 };
  175. static bool is_reset;
  176. /* unsigned long cur_thro = tx_throughput; */
  177. /* static unsigned long thro_constraint = 99 * 1000; */
  178. int cur_wifi_stat = 0;
  179. mtk_cooler_amdtxctrl_dprintk("[%s]+ [0]=%d, [1]=%d || [%d] is %s\n", __func__, mail_box[0],
  180. mail_box[1], index, (is_on == 1 ? "ON" : "OFF"));
  181. mail_box[index] = is_on;
  182. if (mail_box[0] >= 0 && mail_box[1] >= 0) {
  183. cur_wifi_stat = mail_box[0] + mail_box[1];
  184. switch (cur_wifi_stat) {
  185. case HIGH_STAT:
  186. if (throttling_pre_stat < HIGH_STAT) {
  187. /* 1st down throttle */
  188. int new_step = down_throttle(&amdtxctrl, up_step);
  189. mtk_cooler_amdtxctrl_dprintk_always("LOW/MID-->HIGH: step %d\n",
  190. new_step);
  191. throttling_pre_stat = HIGH_STAT;
  192. over_up_time = 0;
  193. } else if (throttling_pre_stat == HIGH_STAT) {
  194. /* keep down throttle */
  195. over_up_time++;
  196. if ((over_up_time * interval) >= up_duration) {
  197. int new_step = down_throttle(&amdtxctrl, up_step);
  198. mtk_cooler_amdtxctrl_dprintk_always
  199. ("HIGH-->HIGH: step %d\n", new_step);
  200. over_up_time = 0;
  201. }
  202. } else {
  203. mtk_cooler_amdtxctrl_dprintk("[%s] Error state1!!\n", __func__,
  204. throttling_pre_stat);
  205. }
  206. mtk_cooler_amdtxctrl_dprintk_always("case2 time=%d\n", over_up_time);
  207. break;
  208. case MID_STAT:
  209. if (throttling_pre_stat == LOW_STAT) {
  210. below_low_time = 0;
  211. throttling_pre_stat = MID_STAT;
  212. mtk_cooler_amdtxctrl_dprintk_always("[%s] Go up!!\n", __func__);
  213. } else if (throttling_pre_stat == HIGH_STAT) {
  214. over_up_time = 0;
  215. throttling_pre_stat = MID_STAT;
  216. mtk_cooler_amdtxctrl_dprintk_always("[%s] Go down!!\n", __func__);
  217. } else {
  218. throttling_pre_stat = MID_STAT;
  219. mtk_cooler_amdtxctrl_dprintk("[%s] pre_stat=%d!!\n", __func__,
  220. throttling_pre_stat);
  221. }
  222. break;
  223. case LOW_STAT:
  224. if (throttling_pre_stat > LOW_STAT) {
  225. /* 1st up throttle */
  226. int new_step = up_throttle(&amdtxctrl, low_step);
  227. mtk_cooler_amdtxctrl_dprintk_always("MID/HIGH-->LOW: step %d\n",
  228. new_step);
  229. throttling_pre_stat = LOW_STAT;
  230. below_low_time = 0;
  231. low_rst_time = 0;
  232. is_reset = false;
  233. } else if (throttling_pre_stat == LOW_STAT) {
  234. below_low_time++;
  235. if ((below_low_time * interval) >= low_duration) {
  236. if (low_rst_time >= low_rst_max && !is_reset) {
  237. /* rst */
  238. rst_throttle(&amdtxctrl);
  239. mtk_cooler_amdtxctrl_dprintk_always
  240. ("over rst time=%d\n", low_rst_time);
  241. low_rst_time = low_rst_max;
  242. is_reset = true;
  243. } else if (!is_reset) {
  244. /* keep up throttle */
  245. int new_step = up_throttle(&amdtxctrl, low_step);
  246. low_rst_time++;
  247. mtk_cooler_amdtxctrl_dprintk_always
  248. ("LOW-->LOW: step %d\n", new_step);
  249. below_low_time = 0;
  250. } else {
  251. mtk_cooler_amdtxctrl_dprintk
  252. ("Have reset, no control!!");
  253. }
  254. }
  255. } else {
  256. mtk_cooler_amdtxctrl_dprintk_always("[%s] Error state3 %d!!\n",
  257. __func__, throttling_pre_stat);
  258. }
  259. mtk_cooler_amdtxctrl_dprintk("case0 time=%d, rst=%d %d\n", below_low_time,
  260. low_rst_time, is_reset);
  261. break;
  262. default:
  263. mtk_cooler_amdtxctrl_dprintk_always("[%s] Error cur_wifi_stat=%d!!\n",
  264. __func__, cur_wifi_stat);
  265. break;
  266. }
  267. mail_box[0] = UNK_STAT;
  268. mail_box[1] = UNK_STAT;
  269. } else {
  270. mtk_cooler_amdtxctrl_dprintk("[%s] dont get all info!!\n", __func__);
  271. }
  272. return 0;
  273. }
  274. /* +amdtxctrl_cooler_upper_ops+ */
  275. static int amdtxctrl_cooler_upper_get_max_state(struct thermal_cooling_device *cool_dev,
  276. unsigned long *pv)
  277. {
  278. *pv = 1;
  279. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, *pv);
  280. return 0;
  281. }
  282. static int amdtxctrl_cooler_upper_get_cur_state(struct thermal_cooling_device *cool_dev,
  283. unsigned long *pv)
  284. {
  285. *pv = cl_upper_dev_state;
  286. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, *pv);
  287. return 0;
  288. }
  289. static int amdtxctrl_cooler_upper_set_cur_state(struct thermal_cooling_device *cool_dev,
  290. unsigned long v)
  291. {
  292. int ret = 0;
  293. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, v);
  294. cl_upper_dev_state = (unsigned int)v;
  295. if (cl_upper_dev_state == 1)
  296. ret = judge_throttling(1, 1, polling_interval);
  297. else
  298. ret = judge_throttling(1, 0, polling_interval);
  299. if (ret != 0)
  300. mtk_cooler_amdtxctrl_dprintk_always("[%s] ret=%d\n", __func__, ret);
  301. return ret;
  302. }
  303. static struct thermal_cooling_device_ops amdtxctrl_cooler_upper_ops = {
  304. .get_max_state = amdtxctrl_cooler_upper_get_max_state,
  305. .get_cur_state = amdtxctrl_cooler_upper_get_cur_state,
  306. .set_cur_state = amdtxctrl_cooler_upper_set_cur_state,
  307. };
  308. /* -amdtxctrl_cooler_upper_ops- */
  309. /* +amdtxctrl_cooler_lower_ops+ */
  310. static int amdtxctrl_cooler_lower_get_max_state(struct thermal_cooling_device *cool_dev,
  311. unsigned long *pv)
  312. {
  313. *pv = 1;
  314. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, *pv);
  315. return 0;
  316. }
  317. static int amdtxctrl_cooler_lower_get_cur_state(struct thermal_cooling_device *cool_dev,
  318. unsigned long *pv)
  319. {
  320. *pv = cl_lower_dev_state;
  321. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, *pv);
  322. return 0;
  323. }
  324. static int amdtxctrl_cooler_lower_set_cur_state(struct thermal_cooling_device *cool_dev,
  325. unsigned long v)
  326. {
  327. int ret = 0;
  328. mtk_cooler_amdtxctrl_dprintk("[%s] %d\n", __func__, v);
  329. cl_lower_dev_state = (unsigned int)v;
  330. if (cl_lower_dev_state == 1)
  331. ret = judge_throttling(0, 1, polling_interval);
  332. else
  333. ret = judge_throttling(0, 0, polling_interval);
  334. if (ret != 0)
  335. mtk_cooler_amdtxctrl_dprintk_always("[%s] ret=%d\n", __func__, ret);
  336. return ret;
  337. }
  338. static struct thermal_cooling_device_ops amdtxctrl_cooler_lower_ops = {
  339. .get_max_state = amdtxctrl_cooler_lower_get_max_state,
  340. .get_cur_state = amdtxctrl_cooler_lower_get_cur_state,
  341. .set_cur_state = amdtxctrl_cooler_lower_set_cur_state,
  342. };
  343. /* -amdtxctrl_cooler_lower_ops- */
  344. static int mtk_cooler_amdtxctrl_register_ltf(void)
  345. {
  346. mtk_cooler_amdtxctrl_dprintk("[%s]\n", __func__);
  347. cl_upper_dev = mtk_thermal_cooling_device_register("cl-amdtxctrl-upper", NULL,
  348. &amdtxctrl_cooler_upper_ops);
  349. cl_lower_dev = mtk_thermal_cooling_device_register("cl-amdtxctrl-lower", NULL,
  350. &amdtxctrl_cooler_lower_ops);
  351. return 0;
  352. }
  353. static void mtk_cooler_amdtxctrl_unregister_ltf(void)
  354. {
  355. mtk_cooler_amdtxctrl_dprintk("[%s]\n", __func__);
  356. if (cl_upper_dev) {
  357. mtk_thermal_cooling_device_unregister(cl_upper_dev);
  358. cl_upper_dev = NULL;
  359. }
  360. if (cl_lower_dev) {
  361. mtk_thermal_cooling_device_unregister(cl_lower_dev);
  362. cl_lower_dev = NULL;
  363. }
  364. }
  365. /*New Wifi throttling Algo+*/
  366. int amdtxctrl_param_read(char *buf, char **start, off_t offset, int count, int *eof, void *data)
  367. {
  368. int ret;
  369. char tmp[MAX_LEN] = { 0 };
  370. sprintf(tmp, "[up]\t%3d(sec)\t%2d\n[low]\t%3d(sec)\t%2d\nrst=%2d\ninterval=%d\n",
  371. up_duration, up_step, low_duration, low_step, low_rst_max, polling_interval);
  372. ret = strlen(tmp);
  373. memcpy(buf, tmp, ret * sizeof(char));
  374. mtk_cooler_amdtxctrl_dprintk_always("[%s] [up]%d %d, [low]%d %d, rst=%d, interval=%d\n",
  375. __func__, up_duration, up_step, low_duration, low_step,
  376. low_rst_max, polling_interval);
  377. return ret;
  378. }
  379. ssize_t amdtxctrl_param_write(struct file *filp, const char __user *buf, unsigned long len,
  380. void *data)
  381. {
  382. char desc[MAX_LEN] = { 0 };
  383. unsigned int tmp_up_dur = 10;
  384. unsigned int tmp_up_step = 1;
  385. unsigned int tmp_low_dur = 10;
  386. unsigned int tmp_low_step = 1;
  387. unsigned int tmp_low_rst_max = 6;
  388. int tmp_polling_interval = 1;
  389. unsigned int tmp_log = 0;
  390. len = (len < (sizeof(desc) - 1)) ? len : (sizeof(desc) - 1);
  391. /* write data to the buffer */
  392. if (copy_from_user(desc, buf, len))
  393. return -EFAULT;
  394. if (sscanf(desc, "%d %d %d %d %d %d", &tmp_up_dur, &tmp_up_step, &tmp_low_dur,
  395. &tmp_low_step, &tmp_low_rst_max, &tmp_polling_interval) == 6) {
  396. up_duration = tmp_up_dur;
  397. up_step = tmp_up_step;
  398. low_duration = tmp_low_dur;
  399. low_step = tmp_low_step;
  400. low_rst_max = tmp_low_rst_max;
  401. polling_interval = tmp_polling_interval;
  402. over_up_time = 0;
  403. below_low_time = 0;
  404. low_rst_time = 0;
  405. mtk_cooler_amdtxctrl_dprintk_always
  406. ("[%s] %s [up]%d %d, [low]%d %d, rst=%d, interval=%d\n", __func__, desc,
  407. up_duration, up_step, low_duration, low_step, low_rst_max, polling_interval);
  408. return len;
  409. }
  410. if (sscanf(desc, "log=%d", &tmp_log) == 1) {
  411. if (tmp_log == 1)
  412. cl_amdtxctrl_klog_on = 1;
  413. else
  414. cl_amdtxctrl_klog_on = 0;
  415. return len;
  416. }
  417. mtk_cooler_amdtxctrl_dprintk_always("[%s] bad argument = %s\n", __func__, desc);
  418. return -EINVAL;
  419. }
  420. /*New Wifi throttling Algo-*/
  421. #if CONFIG_SIGNAL_USER_SPACE
  422. int amdtxctrl_pid_read(char *buf, char **start, off_t offset, int count, int *eof, void *data)
  423. {
  424. int ret;
  425. char tmp[MAX_LEN] = { 0 };
  426. sprintf(tmp, "%d\n", tm_input_pid);
  427. ret = strlen(tmp);
  428. memcpy(buf, tmp, ret * sizeof(char));
  429. mtk_cooler_amdtxctrl_dprintk_always("[%s] %s = %d\n", __func__, buf, tm_input_pid);
  430. return ret;
  431. }
  432. ssize_t amdtxctrl_pid_write(struct file *filp, const char __user *buf, unsigned long count,
  433. void *data)
  434. {
  435. int ret = 0;
  436. char tmp[MAX_LEN] = { 0 };
  437. int len = 0;
  438. /* write data to the buffer */
  439. len = (count < (sizeof(tmp) - 1)) ? count : (sizeof(tmp) - 1);
  440. if (copy_from_user(tmp, buf, len))
  441. return -EFAULT;
  442. ret = kstrtouint(tmp, 10, &tm_input_pid);
  443. if (ret)
  444. WARN_ON(1);
  445. mtk_cooler_amdtxctrl_dprintk_always("[%s] %s = %d\n", __func__, tmp, tm_input_pid);
  446. return len;
  447. }
  448. #endif /* CONFIG_SIGNAL_USER_SPACE */
  449. static int amdtxctrl_proc_register(void)
  450. {
  451. struct proc_dir_entry *entry = NULL;
  452. struct proc_dir_entry *amdtxctrl_proc_dir = NULL;
  453. mtk_cooler_amdtxctrl_dprintk("[%s]\n", __func__);
  454. amdtxctrl_proc_dir = proc_mkdir("amdtxctrl", NULL);
  455. if (!amdtxctrl_proc_dir) {
  456. mtk_cooler_amdtxctrl_dprintk("[%s] mkdir /proc/amdtxctrl failed\n", __func__);
  457. } else {
  458. #if CONFIG_SIGNAL_USER_SPACE
  459. entry =
  460. create_proc_entry("tm_pid", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
  461. amdtxctrl_proc_dir);
  462. if (entry) {
  463. entry->read_proc = amdtxctrl_pid_read;
  464. entry->write_proc = amdtxctrl_pid_write;
  465. entry->gid = 1000; /* allow system process to write this proc */
  466. }
  467. #endif /* CONFIG_SIGNAL_USER_SPACE */
  468. entry =
  469. create_proc_entry("amdtxctrl_param", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
  470. amdtxctrl_proc_dir);
  471. if (entry) {
  472. entry->read_proc = amdtxctrl_param_read;
  473. entry->write_proc = amdtxctrl_param_write;
  474. entry->gid = 1000; /* allow system process to write this proc */
  475. }
  476. }
  477. return 0;
  478. }
  479. static int __init mtk_cooler_amdtxctrl_init(void)
  480. {
  481. int err = 0, i = 0;
  482. mtk_cooler_amdtxctrl_dprintk("[%s]\n", __func__);
  483. for (; i < COOLER_STEPS; i++)
  484. opp_func[i] = amdtxpwr_backoff;
  485. amdtxctrl.cur_level = 0;
  486. amdtxctrl.max_level = COOLER_STEPS - 1;
  487. amdtxctrl.opp_func_array = &opp_func[0];
  488. err = amdtxctrl_proc_register();
  489. if (err)
  490. return err;
  491. err = mtk_cooler_amdtxctrl_register_ltf();
  492. if (err)
  493. goto err_unreg;
  494. return 0;
  495. err_unreg:
  496. mtk_cooler_amdtxctrl_unregister_ltf();
  497. return err;
  498. }
  499. static void __exit mtk_cooler_amdtxctrl_exit(void)
  500. {
  501. mtk_cooler_amdtxctrl_dprintk("[%s]\n", __func__);
  502. /* remove the proc file */
  503. /* remove_proc_entry("amdtxctrl", NULL); */
  504. mtk_cooler_amdtxctrl_unregister_ltf();
  505. }
  506. module_init(mtk_cooler_amdtxctrl_init);
  507. module_exit(mtk_cooler_amdtxctrl_exit);