mtk_ts_tsx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. #include <linux/version.h>
  2. #include <linux/kernel.h>
  3. #include <linux/module.h>
  4. #include <linux/dmi.h>
  5. #include <linux/acpi.h>
  6. #include <linux/thermal.h>
  7. #include <linux/platform_device.h>
  8. #include <mt-plat/aee.h>
  9. #include <linux/types.h>
  10. #include <linux/delay.h>
  11. #include <linux/proc_fs.h>
  12. #include <linux/seq_file.h>
  13. #include "mt-plat/mtk_thermal_monitor.h"
  14. #include "mtk_thermal_typedefs.h"
  15. #include "mach/mt_thermal.h"
  16. #include <mt-plat/upmu_common.h>
  17. #include <tspmic_settings.h>
  18. #include <linux/slab.h>
  19. /*=============================================================
  20. *Local variable definition
  21. *=============================================================*/
  22. /**
  23. * If curr_temp >= polling_trip_temp1, use interval
  24. * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1
  25. * else, use interval*polling_factor2
  26. */
  27. /*=============================================================*/
  28. static kuid_t uid = KUIDT_INIT(0);
  29. static kgid_t gid = KGIDT_INIT(1000);
  30. static unsigned int interval; /* seconds, 0 : no auto polling */
  31. static unsigned int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 };
  32. /*static unsigned int cl_dev_sysrst_state;*/
  33. static struct thermal_zone_device *thz_dev;
  34. static struct thermal_cooling_device *cl_dev_sysrst;
  35. static int kernelmode;
  36. static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  37. static int num_trip;
  38. static char g_bind0[20] = { 0 };
  39. static char g_bind1[20] = { 0 };
  40. static char g_bind2[20] = { 0 };
  41. static char g_bind3[20] = { 0 };
  42. static char g_bind4[20] = { 0 };
  43. static char g_bind5[20] = { 0 };
  44. static char g_bind6[20] = { 0 };
  45. static char g_bind7[20] = { 0 };
  46. static char g_bind8[20] = { 0 };
  47. static char g_bind9[20] = { 0 };
  48. static long int mtktstsx_cur_temp;
  49. /*=============================================================*/
  50. static int mtktstsx_get_temp(struct thermal_zone_device *thermal, unsigned long *t)
  51. {
  52. *t = mtktstsx_get_hw_temp();
  53. mtktstsx_cur_temp = *t;
  54. /* pr_warn("[mtktstsx_cur_temp] Raw=%d\n", mtktstsx_cur_temp);*/
  55. thermal->polling_delay = interval * 1000;
  56. #if 0
  57. if ((int)*t >= polling_trip_temp1)
  58. thermal->polling_delay = interval * 1000;
  59. else if ((int)*t < polling_trip_temp2)
  60. thermal->polling_delay = interval * polling_factor2;
  61. else
  62. thermal->polling_delay = interval * polling_factor1;
  63. #endif
  64. return 0;
  65. }
  66. static int mtktstsx_bind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev)
  67. {
  68. int table_val = 0;
  69. if (!strcmp(cdev->type, g_bind0)) {
  70. table_val = 0;
  71. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  72. } else if (!strcmp(cdev->type, g_bind1)) {
  73. table_val = 1;
  74. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  75. } else if (!strcmp(cdev->type, g_bind2)) {
  76. table_val = 2;
  77. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  78. } else if (!strcmp(cdev->type, g_bind3)) {
  79. table_val = 3;
  80. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  81. } else if (!strcmp(cdev->type, g_bind4)) {
  82. table_val = 4;
  83. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  84. } else if (!strcmp(cdev->type, g_bind5)) {
  85. table_val = 5;
  86. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  87. } else if (!strcmp(cdev->type, g_bind6)) {
  88. table_val = 6;
  89. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  90. } else if (!strcmp(cdev->type, g_bind7)) {
  91. table_val = 7;
  92. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  93. } else if (!strcmp(cdev->type, g_bind8)) {
  94. table_val = 8;
  95. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  96. } else if (!strcmp(cdev->type, g_bind9)) {
  97. table_val = 9;
  98. mtktstsx_dprintk("[mtktstsx_bind] %s\n", cdev->type);
  99. } else {
  100. return 0;
  101. }
  102. if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
  103. mtktstsx_info("[mtktstsx_bind] error binding cooling dev\n");
  104. return -EINVAL;
  105. }
  106. mtktstsx_dprintk("[mtktstsx_bind] binding OK, %d\n", table_val);
  107. return 0;
  108. }
  109. static int mtktstsx_unbind(struct thermal_zone_device *thermal,
  110. struct thermal_cooling_device *cdev)
  111. {
  112. int table_val = 0;
  113. if (!strcmp(cdev->type, g_bind0)) {
  114. table_val = 0;
  115. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  116. } else if (!strcmp(cdev->type, g_bind1)) {
  117. table_val = 1;
  118. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  119. } else if (!strcmp(cdev->type, g_bind2)) {
  120. table_val = 2;
  121. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  122. } else if (!strcmp(cdev->type, g_bind3)) {
  123. table_val = 3;
  124. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  125. } else if (!strcmp(cdev->type, g_bind4)) {
  126. table_val = 4;
  127. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  128. } else if (!strcmp(cdev->type, g_bind5)) {
  129. table_val = 5;
  130. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  131. } else if (!strcmp(cdev->type, g_bind6)) {
  132. table_val = 6;
  133. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  134. } else if (!strcmp(cdev->type, g_bind7)) {
  135. table_val = 7;
  136. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  137. } else if (!strcmp(cdev->type, g_bind8)) {
  138. table_val = 8;
  139. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  140. } else if (!strcmp(cdev->type, g_bind9)) {
  141. table_val = 9;
  142. mtktstsx_dprintk("[mtktstsx_unbind] %s\n", cdev->type);
  143. } else
  144. return 0;
  145. if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
  146. mtktstsx_info("[mtktstsx_unbind] error unbinding cooling dev\n");
  147. return -EINVAL;
  148. }
  149. mtktstsx_dprintk("[mtktstsx_unbind] unbinding OK\n");
  150. return 0;
  151. }
  152. static int mtktstsx_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode)
  153. {
  154. *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
  155. return 0;
  156. }
  157. static int mtktstsx_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode)
  158. {
  159. kernelmode = mode;
  160. return 0;
  161. }
  162. static int mtktstsx_get_trip_type(struct thermal_zone_device *thermal, int trip,
  163. enum thermal_trip_type *type)
  164. {
  165. *type = g_THERMAL_TRIP[trip];
  166. return 0;
  167. }
  168. static int mtktstsx_get_trip_temp(struct thermal_zone_device *thermal, int trip,
  169. unsigned long *temp)
  170. {
  171. *temp = trip_temp[trip];
  172. return 0;
  173. }
  174. static int mtktstsx_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temperature)
  175. {
  176. *temperature = mtktstsx_TEMP_CRIT;
  177. return 0;
  178. }
  179. /* bind callback functions to thermalzone */
  180. static struct thermal_zone_device_ops mtktstsx_dev_ops = {
  181. .bind = mtktstsx_bind,
  182. .unbind = mtktstsx_unbind,
  183. .get_temp = mtktstsx_get_temp,
  184. .get_mode = mtktstsx_get_mode,
  185. .set_mode = mtktstsx_set_mode,
  186. .get_trip_type = mtktstsx_get_trip_type,
  187. .get_trip_temp = mtktstsx_get_trip_temp,
  188. .get_crit_temp = mtktstsx_get_crit_temp,
  189. };
  190. #if 0
  191. static int tstsx_sysrst_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  192. {
  193. *state = 1;
  194. return 0;
  195. }
  196. static int tstsx_sysrst_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  197. {
  198. *state = cl_dev_sysrst_state;
  199. return 0;
  200. }
  201. static int tstsx_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  202. {
  203. cl_dev_sysrst_state = state;
  204. if (cl_dev_sysrst_state == 1) {
  205. mtktstsx_info("Power/PMIC_Thermal: reset, reset, reset!!!");
  206. mtktstsx_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  207. mtktstsx_info("*****************************************");
  208. mtktstsx_info("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  209. /* BUG(); */
  210. *(unsigned int *)0x0 = 0xdead; /* To trigger data abort to reset the system for thermal protection. */
  211. /* arch_reset(0,NULL); */
  212. }
  213. return 0;
  214. }
  215. static struct thermal_cooling_device_ops mtktstsx_cooling_sysrst_ops = {
  216. .get_max_state = tstsx_sysrst_get_max_state,
  217. .get_cur_state = tstsx_sysrst_get_cur_state,
  218. .set_cur_state = tstsx_sysrst_set_cur_state,
  219. };
  220. #endif
  221. static int mtktstsx_read(struct seq_file *m, void *v)
  222. {
  223. seq_printf(m, "[ mtktstsx_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n",
  224. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]);
  225. seq_printf(m, "trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n",
  226. trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]);
  227. seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n",
  228. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]);
  229. seq_printf(m, "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n",
  230. g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]);
  231. seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  232. seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n",
  233. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  234. seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n",
  235. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000);
  236. return 0;
  237. }
  238. static int mtktstsx_register_thermal(void);
  239. static void mtktstsx_unregister_thermal(void);
  240. static ssize_t mtktstsx_write(struct file *file, const char __user *buffer, size_t count,
  241. loff_t *data)
  242. {
  243. int len = 0;
  244. int i;
  245. struct mtktstsx_data {
  246. int trip[10];
  247. int t_type[10];
  248. char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20];
  249. char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20];
  250. int time_msec;
  251. char desc[512];
  252. };
  253. struct mtktstsx_data *ptr_mtktstsx_data;
  254. ptr_mtktstsx_data = kmalloc(sizeof(*ptr_mtktstsx_data) , GFP_KERNEL);
  255. if (ptr_mtktstsx_data == NULL)
  256. return -ENOMEM;
  257. len = (count < (sizeof(ptr_mtktstsx_data->desc) - 1)) ? count : (sizeof(ptr_mtktstsx_data->desc) - 1);
  258. if (copy_from_user(ptr_mtktstsx_data->desc, buffer, len)) {
  259. kfree(ptr_mtktstsx_data);
  260. return 0;
  261. }
  262. ptr_mtktstsx_data->desc[len] = '\0';
  263. if (sscanf
  264. (ptr_mtktstsx_data->desc,
  265. "%d %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d %d %s %d",
  266. &num_trip,
  267. &ptr_mtktstsx_data->trip[0], &ptr_mtktstsx_data->t_type[0], ptr_mtktstsx_data->bind0,
  268. &ptr_mtktstsx_data->trip[1], &ptr_mtktstsx_data->t_type[1], ptr_mtktstsx_data->bind1,
  269. &ptr_mtktstsx_data->trip[2], &ptr_mtktstsx_data->t_type[2], ptr_mtktstsx_data->bind2,
  270. &ptr_mtktstsx_data->trip[3], &ptr_mtktstsx_data->t_type[3], ptr_mtktstsx_data->bind3,
  271. &ptr_mtktstsx_data->trip[4], &ptr_mtktstsx_data->t_type[4], ptr_mtktstsx_data->bind4,
  272. &ptr_mtktstsx_data->trip[5], &ptr_mtktstsx_data->t_type[5], ptr_mtktstsx_data->bind5,
  273. &ptr_mtktstsx_data->trip[6], &ptr_mtktstsx_data->t_type[6], ptr_mtktstsx_data->bind6,
  274. &ptr_mtktstsx_data->trip[7], &ptr_mtktstsx_data->t_type[7], ptr_mtktstsx_data->bind7,
  275. &ptr_mtktstsx_data->trip[8], &ptr_mtktstsx_data->t_type[8], ptr_mtktstsx_data->bind8,
  276. &ptr_mtktstsx_data->trip[9], &ptr_mtktstsx_data->t_type[9], ptr_mtktstsx_data->bind9,
  277. &ptr_mtktstsx_data->time_msec) == 32) {
  278. mtktstsx_dprintk("[mtktstsx_write] mtktstsx_unregister_thermal\n");
  279. mtktstsx_unregister_thermal();
  280. if (num_trip < 0 || num_trip > 10) {
  281. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mtktstsx_write",
  282. "Bad argument");
  283. mtktspmic_dprintk("[mtktstsx_write] bad argument\n");
  284. kfree(ptr_mtktstsx_data);
  285. return -EINVAL;
  286. }
  287. for (i = 0; i < num_trip; i++)
  288. g_THERMAL_TRIP[i] = ptr_mtktstsx_data->t_type[i];
  289. g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] =
  290. g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0';
  291. for (i = 0; i < 20; i++) {
  292. g_bind0[i] = ptr_mtktstsx_data->bind0[i];
  293. g_bind1[i] = ptr_mtktstsx_data->bind1[i];
  294. g_bind2[i] = ptr_mtktstsx_data->bind2[i];
  295. g_bind3[i] = ptr_mtktstsx_data->bind3[i];
  296. g_bind4[i] = ptr_mtktstsx_data->bind4[i];
  297. g_bind5[i] = ptr_mtktstsx_data->bind5[i];
  298. g_bind6[i] = ptr_mtktstsx_data->bind6[i];
  299. g_bind7[i] = ptr_mtktstsx_data->bind7[i];
  300. g_bind8[i] = ptr_mtktstsx_data->bind8[i];
  301. g_bind9[i] = ptr_mtktstsx_data->bind9[i];
  302. }
  303. mtktstsx_dprintk("[mtktstsx_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,",
  304. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]);
  305. mtktstsx_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,",
  306. g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]);
  307. mtktstsx_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
  308. g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  309. mtktstsx_dprintk("[mtktstsx_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,",
  310. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  311. mtktstsx_dprintk("cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
  312. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9);
  313. for (i = 0; i < num_trip; i++)
  314. trip_temp[i] = ptr_mtktstsx_data->trip[i];
  315. interval = ptr_mtktstsx_data->time_msec / 1000;
  316. mtktstsx_dprintk("[mtktstsx_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,",
  317. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]);
  318. mtktstsx_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,",
  319. trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]);
  320. mtktstsx_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval * 1000);
  321. mtktstsx_dprintk("[mtktstsx_write] mtktstsx_register_thermal\n");
  322. mtktstsx_register_thermal();
  323. kfree(ptr_mtktstsx_data);
  324. return count;
  325. }
  326. mtktstsx_dprintk("[mtktstsx_write] bad argument\n");
  327. kfree(ptr_mtktstsx_data);
  328. return -EINVAL;
  329. }
  330. void mtkts_tsx_cancel_thermal_timer(void)
  331. {
  332. /* cancel timer */
  333. /* pr_debug("mtkts_tsx_cancel_thermal_timer\n"); */
  334. /* stop thermal framework polling when entering deep idle */
  335. if (thz_dev)
  336. cancel_delayed_work(&(thz_dev->poll_queue));
  337. }
  338. void mtkts_tsx_start_thermal_timer(void)
  339. {
  340. /* pr_debug("mtkts_tsx_start_thermal_timer\n"); */
  341. /* resume thermal framework polling when leaving deep idle */
  342. if (thz_dev != NULL && interval != 0)
  343. mod_delayed_work(system_freezable_wq, &(thz_dev->poll_queue), round_jiffies(msecs_to_jiffies(1000)));
  344. }
  345. /*
  346. int mtktstsx_register_cooler(void)
  347. {
  348. cl_dev_sysrst = mtk_thermal_cooling_device_register("mtktstsx-sysrst", NULL,
  349. &mtktstsx_cooling_sysrst_ops);
  350. return 0;
  351. }
  352. */
  353. static int mtktstsx_register_thermal(void)
  354. {
  355. mtktstsx_dprintk("[mtktstsx_register_thermal]\n");
  356. /* trips : trip 0~2 */
  357. thz_dev = mtk_thermal_zone_device_register("mtktstsx", num_trip, NULL,
  358. &mtktstsx_dev_ops, 0, 0, 0, interval * 1000);
  359. return 0;
  360. }
  361. void mtktstsx_unregister_cooler(void)
  362. {
  363. if (cl_dev_sysrst) {
  364. mtk_thermal_cooling_device_unregister(cl_dev_sysrst);
  365. cl_dev_sysrst = NULL;
  366. }
  367. }
  368. static void mtktstsx_unregister_thermal(void)
  369. {
  370. mtktstsx_dprintk("[mtktstsx_unregister_thermal]\n");
  371. if (thz_dev) {
  372. mtk_thermal_zone_device_unregister(thz_dev);
  373. thz_dev = NULL;
  374. }
  375. }
  376. static int mtktstsx_open(struct inode *inode, struct file *file)
  377. {
  378. return single_open(file, mtktstsx_read, NULL);
  379. }
  380. static const struct file_operations mtktstsx_fops = {
  381. .owner = THIS_MODULE,
  382. .open = mtktstsx_open,
  383. .read = seq_read,
  384. .llseek = seq_lseek,
  385. .write = mtktstsx_write,
  386. .release = single_release,
  387. };
  388. static int mtktstsx_read_log(struct seq_file *m, void *v)
  389. {
  390. seq_printf(m, "mtktstsx_read_log = %d\n", mtktstsx_debug_log);
  391. return 0;
  392. }
  393. static ssize_t mtktstsx_write_log(struct file *file, const char __user *buffer, size_t count,
  394. loff_t *data)
  395. {
  396. char desc[32];
  397. int log_switch;
  398. int len = 0;
  399. len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
  400. if (copy_from_user(desc, buffer, len))
  401. return 0;
  402. desc[len] = '\0';
  403. if (kstrtoint(desc, 10, &log_switch) == 0) {
  404. mtktstsx_debug_log = log_switch;
  405. return count;
  406. }
  407. mtktstsx_info("mtktstsx_write_log bad argument\n");
  408. return -EINVAL;
  409. }
  410. static int mtktstsx_open_log(struct inode *inode, struct file *file)
  411. {
  412. return single_open(file, mtktstsx_read_log, NULL);
  413. }
  414. static const struct file_operations mtktstsx_log_fops = {
  415. .owner = THIS_MODULE,
  416. .open = mtktstsx_open_log,
  417. .read = seq_read,
  418. .llseek = seq_lseek,
  419. .write = mtktstsx_write_log,
  420. .release = single_release,
  421. };
  422. static int __init mtktstsx_init(void)
  423. {
  424. int err = 0;
  425. struct proc_dir_entry *entry = NULL;
  426. struct proc_dir_entry *mtktstsx_dir = NULL;
  427. mtktstsx_info("[mtktstsx_init]\n");
  428. err = mtktstsx_register_thermal();
  429. if (err)
  430. goto err_unreg;
  431. mtktstsx_dir = mtk_thermal_get_proc_drv_therm_dir_entry();
  432. if (!mtktstsx_dir) {
  433. mtktstsx_info("[%s]: mkdir /proc/driver/thermal failed\n", __func__);
  434. } else {
  435. entry =
  436. proc_create("tztsx", S_IRUGO | S_IWUSR | S_IWGRP, mtktstsx_dir,
  437. &mtktstsx_fops);
  438. if (entry)
  439. proc_set_user(entry, uid, gid);
  440. entry =
  441. proc_create("tztsx_log", S_IRUGO | S_IWUSR, mtktstsx_dir,
  442. &mtktstsx_log_fops);
  443. }
  444. return 0;
  445. err_unreg:
  446. mtktstsx_unregister_cooler();
  447. return err;
  448. }
  449. static void __exit mtktstsx_exit(void)
  450. {
  451. mtktstsx_info("[mtktstsx_exit]\n");
  452. mtktstsx_unregister_thermal();
  453. mtktstsx_unregister_cooler();
  454. }
  455. module_init(mtktstsx_init);
  456. module_exit(mtktstsx_exit);