mtk_ts_6311buck.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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 <mach/upmu_hw.h>
  18. #include <mach/mt_pmic_wrap.h>
  19. #include <mt6311.h>
  20. #include "mt_cpufreq.h"
  21. #include <tmp_6311buck.h>
  22. #include <linux/uidgid.h>
  23. #include <linux/slab.h>
  24. static kuid_t uid = KUIDT_INIT(0);
  25. static kgid_t gid = KGIDT_INIT(1000);
  26. static unsigned int interval; /* seconds, 0 : no auto polling */
  27. static int trip_temp[10] = { 125000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 };
  28. #if 1
  29. static unsigned int cl_dev_sysrst_state;
  30. #endif
  31. static struct thermal_zone_device *thz_dev;
  32. #if 1
  33. static struct thermal_cooling_device *cl_dev_sysrst;
  34. /* static struct thermal_cooling_device *cl_dev_6311= NULL;; */
  35. #endif
  36. static int mtkts6311_debug_log;
  37. static int kernelmode;
  38. static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  39. static int num_trip;
  40. static char g_bind0[20] = "mtkts6311-sysrst";
  41. static char g_bind1[20] = "cpu01";
  42. static char g_bind2[20] = "";
  43. static char g_bind3[20] = "";
  44. static char g_bind4[20] = "";
  45. static char g_bind5[20] = "";
  46. static char g_bind6[20] = "";
  47. static char g_bind7[20] = "";
  48. static char g_bind8[20] = "";
  49. static char g_bind9[20] = "";
  50. #define mtkts6311_TEMP_CRIT 150000 /* 150.000 degree Celsius */
  51. #define mtkts6331_dprintk(fmt, args...) \
  52. do { \
  53. if (mtkts6311_debug_log) { \
  54. pr_debug("[Thermal/PMIC_6311]" fmt, ##args); \
  55. } \
  56. } while (0)
  57. #define PMIC6333_INT_TEMP_CUNT 0xF
  58. /* static kal_uint32 tempsetting_count=0; */
  59. typedef struct {
  60. INT32 regsetting;
  61. INT32 Temperature;
  62. } pmic6333_TEMPERATURE;
  63. #define mtkts6311_dprintk(fmt, args...) \
  64. do { \
  65. if (mtkts6311_debug_log) { \
  66. pr_debug("[Power/6311_Thermal]" fmt, ##args); \
  67. } \
  68. } while (0)
  69. static int mtkts6311_get_temp(struct thermal_zone_device *thermal, unsigned long *t)
  70. {
  71. mtkts6311_dprintk("[mtkts6311_get_temp]\n");
  72. *t = 50000; /* default 50 degree */
  73. if (mt6311_get_pmu_thr_status() == 0x0) {/* T<110 */
  74. *t = 60000;
  75. mtkts6331_dprintk("mt6311_get_pmu_thr_status()==0x0\n");
  76. if (mt6311_get_rg_thr_l_int_status() == 1) { /* receive interrupt */
  77. *t = 80000; /* 60 degree */
  78. pr_debug("[Thermal/PMIC_6331]mt6311_get_thr_l_int_status()==1,6311 T=80 deg\n");
  79. mt6311_clr_thr_l_int_status();
  80. mt6311_set_rg_strup_thr_110_clr(1); /* Set 0x28 bit 0=1 ;CLR 110 INT */
  81. udelay(10);
  82. mt6311_set_rg_strup_thr_110_clr(0);
  83. mt6311_set_rg_strup_thr_110_irq_en(0); /* Set 0x28 bit 2=0 ; disable 110 INT */
  84. mt6311_set_rg_strup_thr_125_irq_en(1); /* Set 0x28 bit 3=1; EN >125 INT */
  85. }
  86. } else if (mt6311_get_pmu_thr_status() == 0x1) {/* 110<T<125 */
  87. mtkts6331_dprintk("mt6311_get_pmu_thr_status()==0x1\n");
  88. *t = 115000; /* 115 degree */
  89. pr_debug("[Thermal/PMIC_6331]6311 pmic temp : 110<T<125 deg\n");
  90. } else if (mt6311_get_pmu_thr_status() == 0x3) {/* 125<T<150 */
  91. *t = 130000; /* 130 degree */
  92. /*pr_debug("[Thermal/PMIC_6331]mt6311_get_pmu_thr_status()==0x3\n"); */
  93. pr_debug("[Thermal/PMIC_6331]6311 pmic temp 125<T<150 deg\n");
  94. if (mt6311_get_rg_thr_h_int_status() == 1) { /* receive interrupt */
  95. *t = 135000; /* 135 degree */
  96. pr_debug("[Thermal/PMIC_6331]6311 pmic temp =140 deg\n");
  97. /*pr_debug("[Thermal/PMIC_6331]mt6311_get_rg_thr_h_int_status()==1,6311 T=135 deg\n"); */
  98. mtkts6331_dprintk("mt6311_get_thr_h_int_status()==1\n");
  99. mt6311_clr_thr_h_int_status();
  100. mt6311_set_rg_strup_thr_125_clr(1); /* Set 0x28 bit 1=1 ;CLR 125 INT */
  101. udelay(10);
  102. mt6311_set_rg_strup_thr_125_clr(0);
  103. mt6311_set_rg_strup_thr_125_irq_en(0); /* Set 0x28 bit 3=0 ; disable 125 INT */
  104. mt6311_set_rg_strup_thr_110_irq_en(1); /* Set 0x28 bit 2=1; EN <110 INT */
  105. }
  106. }
  107. mtkts6331_dprintk("6311 pmic temp =%lu\n", *t);
  108. return 0;
  109. }
  110. static int mtkts6311_bind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev)
  111. {
  112. int table_val = 0;
  113. if (!strcmp(cdev->type, g_bind0))
  114. table_val = 0;
  115. else if (!strcmp(cdev->type, g_bind1))
  116. table_val = 1;
  117. else if (!strcmp(cdev->type, g_bind2))
  118. table_val = 2;
  119. else if (!strcmp(cdev->type, g_bind3))
  120. table_val = 3;
  121. else if (!strcmp(cdev->type, g_bind4))
  122. table_val = 4;
  123. else if (!strcmp(cdev->type, g_bind5))
  124. table_val = 5;
  125. else if (!strcmp(cdev->type, g_bind6))
  126. table_val = 6;
  127. else if (!strcmp(cdev->type, g_bind7))
  128. table_val = 7;
  129. else if (!strcmp(cdev->type, g_bind8))
  130. table_val = 8;
  131. else if (!strcmp(cdev->type, g_bind9))
  132. table_val = 9;
  133. else
  134. return 0;
  135. if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
  136. mtkts6311_dprintk("[mtkts6311_bind] error binding cooling dev\n");
  137. return -EINVAL;
  138. }
  139. mtkts6311_dprintk("[mtkts6311_bind] binding OK, %d\n", table_val);
  140. return 0;
  141. }
  142. static int mtkts6311_unbind(struct thermal_zone_device *thermal,
  143. struct thermal_cooling_device *cdev)
  144. {
  145. int table_val = 0;
  146. if (!strcmp(cdev->type, g_bind0))
  147. table_val = 0;
  148. else if (!strcmp(cdev->type, g_bind1))
  149. table_val = 1;
  150. else if (!strcmp(cdev->type, g_bind2))
  151. table_val = 2;
  152. else if (!strcmp(cdev->type, g_bind3))
  153. table_val = 3;
  154. else if (!strcmp(cdev->type, g_bind4))
  155. table_val = 4;
  156. else if (!strcmp(cdev->type, g_bind5))
  157. table_val = 5;
  158. else if (!strcmp(cdev->type, g_bind6))
  159. table_val = 6;
  160. else if (!strcmp(cdev->type, g_bind7))
  161. table_val = 7;
  162. else if (!strcmp(cdev->type, g_bind8))
  163. table_val = 8;
  164. else if (!strcmp(cdev->type, g_bind9))
  165. table_val = 9;
  166. else
  167. return 0;
  168. if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
  169. mtkts6311_dprintk("[mtkts6311_unbind] error unbinding cooling dev\n");
  170. return -EINVAL;
  171. }
  172. mtkts6311_dprintk("[mtkts6311_unbind] unbinding OK\n");
  173. return 0;
  174. }
  175. static int mtkts6311_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode)
  176. {
  177. *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
  178. return 0;
  179. }
  180. static int mtkts6311_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode)
  181. {
  182. kernelmode = mode;
  183. return 0;
  184. }
  185. static int mtkts6311_get_trip_type(struct thermal_zone_device *thermal, int trip,
  186. enum thermal_trip_type *type)
  187. {
  188. *type = g_THERMAL_TRIP[trip];
  189. return 0;
  190. }
  191. static int mtkts6311_get_trip_temp(struct thermal_zone_device *thermal, int trip,
  192. unsigned long *temp)
  193. {
  194. *temp = trip_temp[trip];
  195. return 0;
  196. }
  197. static int mtkts6311_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temperature)
  198. {
  199. *temperature = mtkts6311_TEMP_CRIT;
  200. return 0;
  201. }
  202. /* bind callback functions to thermalzone */
  203. static struct thermal_zone_device_ops mtkts6311_dev_ops = {
  204. .bind = mtkts6311_bind,
  205. .unbind = mtkts6311_unbind,
  206. .get_temp = mtkts6311_get_temp,
  207. .get_mode = mtkts6311_get_mode,
  208. .set_mode = mtkts6311_set_mode,
  209. .get_trip_type = mtkts6311_get_trip_type,
  210. .get_trip_temp = mtkts6311_get_trip_temp,
  211. .get_crit_temp = mtkts6311_get_crit_temp,
  212. };
  213. #if 1
  214. /*
  215. static int mtkts6311_get_max_state(struct thermal_cooling_device *cdev,
  216. unsigned long *state)
  217. {
  218. mtkts6311_dprintk("[mtkts6311_get_max_state]\n");
  219. *state = 1;
  220. return 0;
  221. }
  222. static int mtkts6311_get_cur_state(struct thermal_cooling_device *cdev,
  223. unsigned long *state)
  224. {
  225. mtkts6311_dprintk("[mtkts6311_get_cur_state]\n");
  226. *state = "cpu01";
  227. return 0;
  228. }
  229. static int mtkts6311_set_cur_state(struct thermal_cooling_device *cdev,
  230. unsigned long state)
  231. {
  232. mtkts6311_dprintk("[mtkts6311_set_cur_state]\n");
  233. mt_cpufreq_thermal_protect(700);
  234. return 0;
  235. }
  236. static struct thermal_cooling_device_ops mtktscpu_cooler_cpu_ops = {
  237. .get_max_state = mtkts6311_get_max_state,
  238. .get_cur_state = mtkts6311_get_cur_state,
  239. .set_cur_state = mtkts6311_set_cur_state,
  240. };
  241. */
  242. static int ts6311_sysrst_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  243. {
  244. mtkts6311_dprintk("ts6311_sysrst_get_max_state!!!\n");
  245. *state = 1;
  246. return 0;
  247. }
  248. static int ts6311_sysrst_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  249. {
  250. mtkts6311_dprintk("ts6311_sysrst_get_cur_state = %d\n", cl_dev_sysrst_state);
  251. *state = cl_dev_sysrst_state;
  252. return 0;
  253. }
  254. static int ts6311_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  255. {
  256. mtkts6311_dprintk("ts6311_sysrst_set_cur_state = %d\n", cl_dev_sysrst_state);
  257. cl_dev_sysrst_state = state;
  258. if (cl_dev_sysrst_state == 1) {
  259. pr_debug("Power/6311_Thermal: reset, reset, reset!!!");
  260. pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  261. pr_debug("*****************************************");
  262. pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  263. #ifndef CONFIG_ARM64
  264. BUG();
  265. #else
  266. *(unsigned int *)0x0 = 0xdead; /* To trigger data abort to reset the system for thermal protection. */
  267. #endif
  268. }
  269. return 0;
  270. }
  271. static struct thermal_cooling_device_ops mtkts6311_cooling_sysrst_ops = {
  272. .get_max_state = ts6311_sysrst_get_max_state,
  273. .get_cur_state = ts6311_sysrst_get_cur_state,
  274. .set_cur_state = ts6311_sysrst_set_cur_state,
  275. };
  276. int mtkts6311_register_cooler(void)
  277. {
  278. cl_dev_sysrst = mtk_thermal_cooling_device_register("mtkts6311-sysrst", NULL,
  279. &mtkts6311_cooling_sysrst_ops);
  280. /*
  281. cl_dev_6311 = mtk_thermal_cooling_device_register("cpu01", NULL,
  282. &mtktscpu_cooler_cpu_ops);
  283. */
  284. return 0;
  285. }
  286. #endif
  287. static int mtkts6311_read(struct seq_file *m, void *v)
  288. {
  289. seq_printf(m, "[ mtkts6311_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d,\n",
  290. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3], trip_temp[4]);
  291. seq_printf(m, "trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n",
  292. trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]);
  293. seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d\n",
  294. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]);
  295. seq_printf(m, "g_THERMAL_TRIP_4=%d, g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d\n",
  296. g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]);
  297. seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
  298. g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  299. seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n",
  300. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  301. seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n",
  302. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000);
  303. return 0;
  304. }
  305. static int mtkts6311_register_thermal(void);
  306. static void mtkts6311_unregister_thermal(void);
  307. static ssize_t mtkts6311_write(struct file *file, const char __user *buffer, size_t count,
  308. loff_t *data)
  309. {
  310. int len = 0, i;
  311. struct mtkts6311_data {
  312. int trip[10];
  313. int t_type[10];
  314. char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20];
  315. char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20];
  316. int time_msec;
  317. char desc[512];
  318. };
  319. struct mtkts6311_data *ptr_mtkts6311_data = kmalloc(sizeof(*ptr_mtkts6311_data), GFP_KERNEL);
  320. if (ptr_mtkts6311_data == NULL)
  321. return -ENOMEM;
  322. len = (count < (sizeof(ptr_mtkts6311_data->desc) - 1)) ? count : (sizeof(ptr_mtkts6311_data->desc) - 1);
  323. if (copy_from_user(ptr_mtkts6311_data->desc, buffer, len)) {
  324. kfree(ptr_mtkts6311_data);
  325. return 0;
  326. }
  327. ptr_mtkts6311_data->desc[len] = '\0';
  328. if (sscanf
  329. (ptr_mtkts6311_data->desc,
  330. "%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",
  331. &num_trip,
  332. &ptr_mtkts6311_data->trip[0], &ptr_mtkts6311_data->t_type[0], ptr_mtkts6311_data->bind0,
  333. &ptr_mtkts6311_data->trip[1], &ptr_mtkts6311_data->t_type[1], ptr_mtkts6311_data->bind1,
  334. &ptr_mtkts6311_data->trip[2], &ptr_mtkts6311_data->t_type[2], ptr_mtkts6311_data->bind2,
  335. &ptr_mtkts6311_data->trip[3], &ptr_mtkts6311_data->t_type[3], ptr_mtkts6311_data->bind3,
  336. &ptr_mtkts6311_data->trip[4], &ptr_mtkts6311_data->t_type[4], ptr_mtkts6311_data->bind4,
  337. &ptr_mtkts6311_data->trip[5], &ptr_mtkts6311_data->t_type[5], ptr_mtkts6311_data->bind5,
  338. &ptr_mtkts6311_data->trip[6], &ptr_mtkts6311_data->t_type[6], ptr_mtkts6311_data->bind6,
  339. &ptr_mtkts6311_data->trip[7], &ptr_mtkts6311_data->t_type[7], ptr_mtkts6311_data->bind7,
  340. &ptr_mtkts6311_data->trip[8], &ptr_mtkts6311_data->t_type[8], ptr_mtkts6311_data->bind8,
  341. &ptr_mtkts6311_data->trip[9], &ptr_mtkts6311_data->t_type[9], ptr_mtkts6311_data->bind9,
  342. &ptr_mtkts6311_data->time_msec) == 32) {
  343. mtkts6311_dprintk("[mtkts6311_write] mtkts6311_unregister_thermal\n");
  344. mtkts6311_unregister_thermal();
  345. if (num_trip < 0 || num_trip > 10) {
  346. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mtkts6311_write",
  347. "Bad argument");
  348. mtkts6311_dprintk("[mtkts6311_write] bad argument\n");
  349. kfree(ptr_mtkts6311_data);
  350. return -EINVAL;
  351. }
  352. for (i = 0; i < num_trip; i++)
  353. g_THERMAL_TRIP[i] = ptr_mtkts6311_data->t_type[i];
  354. g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] =
  355. g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0';
  356. for (i = 0; i < 20; i++) {
  357. g_bind0[i] = ptr_mtkts6311_data->bind0[i];
  358. g_bind1[i] = ptr_mtkts6311_data->bind1[i];
  359. g_bind2[i] = ptr_mtkts6311_data->bind2[i];
  360. g_bind3[i] = ptr_mtkts6311_data->bind3[i];
  361. g_bind4[i] = ptr_mtkts6311_data->bind4[i];
  362. g_bind5[i] = ptr_mtkts6311_data->bind5[i];
  363. g_bind6[i] = ptr_mtkts6311_data->bind6[i];
  364. g_bind7[i] = ptr_mtkts6311_data->bind7[i];
  365. g_bind8[i] = ptr_mtkts6311_data->bind8[i];
  366. g_bind9[i] = ptr_mtkts6311_data->bind9[i];
  367. }
  368. mtkts6311_dprintk("[mtkts6311_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,",
  369. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]);
  370. mtkts6311_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d",
  371. g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]);
  372. mtkts6311_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
  373. g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  374. mtkts6311_dprintk("[mtkts6311_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,",
  375. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  376. mtkts6311_dprintk("cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
  377. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9);
  378. for (i = 0; i < num_trip; i++)
  379. trip_temp[i] = ptr_mtkts6311_data->trip[i];
  380. interval = ptr_mtkts6311_data->time_msec / 1000;
  381. mtkts6311_dprintk("[mtkts6311_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,",
  382. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]);
  383. mtkts6311_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,",
  384. trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]);
  385. mtkts6311_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval * 1000);
  386. mtkts6311_dprintk("[mtkts6311_write] mtkts6311_register_thermal\n");
  387. mtkts6311_register_thermal();
  388. kfree(ptr_mtkts6311_data);
  389. return count;
  390. }
  391. mtkts6311_dprintk("[mtkts6311_write] bad argument\n");
  392. kfree(ptr_mtkts6311_data);
  393. return -EINVAL;
  394. }
  395. static int mtkts6311_register_thermal(void)
  396. {
  397. mtkts6311_dprintk("[mtkts6311_register_thermal]\n");
  398. /* trips : trip 0~2 */
  399. thz_dev = mtk_thermal_zone_device_register("mtkts6311", num_trip, NULL,
  400. &mtkts6311_dev_ops, 0, 0, 0, interval * 1000);
  401. return 0;
  402. }
  403. #if 1
  404. void mtkts6311_unregister_cooler(void)
  405. {
  406. if (cl_dev_sysrst) {
  407. mtk_thermal_cooling_device_unregister(cl_dev_sysrst);
  408. cl_dev_sysrst = NULL;
  409. }
  410. }
  411. #endif
  412. static void mtkts6311_unregister_thermal(void)
  413. {
  414. mtkts6311_dprintk("[mtkts6311_unregister_thermal]\n");
  415. if (thz_dev) {
  416. mtk_thermal_zone_device_unregister(thz_dev);
  417. thz_dev = NULL;
  418. }
  419. }
  420. #if 0
  421. static int mtkts63116333_thermal_zone_handler(void)
  422. {
  423. int temp = 0;
  424. mtkts6311_dprintk("[mtkts63116333_thermal_zone_handler] ,tempsetting_count=0x%x\n",
  425. tempsetting_count);
  426. mt6333_6311_int = get_thermal_mt6333_6311_int_status();
  427. if (mt6333_6311_int == 1) { /* receive thermal 6311 INT */
  428. tempsetting_count--;
  429. if (tempsetting_count <= 0) {
  430. tempsetting_count = 0;
  431. pr_debug("6333 temp is over 140 degree\n");
  432. }
  433. set_thermal_mt6333_6311_int_status(0);
  434. /* increase temperature */
  435. mt6333_set_rg_strup_ther_rg_th((pmic6333_temp_map[tempsetting_count].regsetting));
  436. mtkts6311_dprintk("increase change INT threshold to tempsetting_count=%d\n",
  437. tempsetting_count);
  438. } else {
  439. tempsetting_count++;
  440. if (tempsetting_count >= PMIC6333_INT_TEMP_CUNT) {
  441. tempsetting_count = PMIC6333_INT_TEMP_CUNT; /* 65 degree */
  442. mtkts6311_dprintk("6333 temp is below 65 degree\n");
  443. }
  444. /* decrease temperature */
  445. mt6333_set_rg_strup_ther_rg_th((pmic6333_temp_map[tempsetting_count].regsetting));
  446. mtkts6311_dprintk("decrease change INT threshold to tempsetting_count=%d\n",
  447. tempsetting_count);
  448. }
  449. mtkts6311_dprintk("decrease pmic6333_temp_map[%d].regsetting=0x%x\n", tempsetting_count,
  450. pmic6333_temp_map[tempsetting_count].regsetting);
  451. mtkts6311_dprintk("decrease pmic6333_temp_map[%d].Temperature=%d\n", tempsetting_count,
  452. pmic6333_temp_map[tempsetting_count].Temperature);
  453. temp = pmic6333_temp_map[tempsetting_count].Temperature;
  454. if (temp >= 70) /* printing high temperature */
  455. pr_debug("[Power/6311_Thermal] Buck 6333 T=%d\n", temp);
  456. mtkts6311_dprintk("mt6333_6311_int=%d\n", mt6333_6311_int);
  457. return temp * 1000;
  458. }
  459. #endif
  460. static void mtktspmic6311_thermal_zone_init(void)
  461. {
  462. mtkts6311_dprintk("[mtktspmic6311_thermal_zone_init]\n");
  463. mt6311_set_rg_thrdet_sel(0); /* 0x6C bit0=0 ; thermal 110/125 EN */
  464. mt6311_set_rg_strup_thr_125_irq_en(1); /* 0x28 bit3=1 ; >125 INT EN */
  465. mt6311_set_rg_strup_thr_110_irq_en(0); /* 0x28 bit3=1 ; <110 INT DIS */
  466. mt6311_set_rg_int_en(1); /* 0x18 bit1=1 ; Top INT EN */
  467. mt6311_clr_thr_l_int_status();
  468. mt6311_clr_thr_h_int_status();
  469. }
  470. static int mtkts6311_open(struct inode *inode, struct file *file)
  471. {
  472. return single_open(file, mtkts6311_read, NULL);
  473. }
  474. static const struct file_operations mtkts6311_fops = {
  475. .owner = THIS_MODULE,
  476. .open = mtkts6311_open,
  477. .read = seq_read,
  478. .llseek = seq_lseek,
  479. .write = mtkts6311_write,
  480. .release = single_release,
  481. };
  482. static int __init mtkts6311_init(void)
  483. {
  484. int err = 0;
  485. struct proc_dir_entry *entry = NULL;
  486. struct proc_dir_entry *mtkts6311_dir = NULL;
  487. mtkts6311_dprintk("mtkts6311_init: Start\n");
  488. /* return 1 means with 6311, else return 0 */
  489. if (is_ext_buck_exist() == 0) {
  490. mtkts6311_dprintk("mtkts6311_init: Buck is not exist\n");
  491. return err;
  492. }
  493. mtktspmic6311_thermal_zone_init();
  494. err = mtkts6311_register_cooler();
  495. if (err)
  496. return err;
  497. err = mtkts6311_register_thermal();
  498. if (err)
  499. goto err_unreg;
  500. mtkts6311_dir = mtk_thermal_get_proc_drv_therm_dir_entry();
  501. if (!mtkts6311_dir) {
  502. mtkts6311_dprintk("[%s]: mkdir /proc/driver/thermal failed\n", __func__);
  503. } else {
  504. entry =
  505. proc_create("tz6311", S_IRUGO | S_IWUSR | S_IWGRP, mtkts6311_dir,
  506. &mtkts6311_fops);
  507. if (entry)
  508. proc_set_user(entry, uid, gid);
  509. /* entry = proc_create("mtkts6311_log", S_IRUGO | S_IWUSR, mtkts6311_dir, &mtkts6311_log_fops); */
  510. }
  511. return 0;
  512. err_unreg:
  513. mtkts6311_unregister_cooler();
  514. return err;
  515. }
  516. static void __exit mtkts6311_exit(void)
  517. {
  518. mtkts6311_dprintk("[mtkts6311_exit]\n");
  519. mtkts6311_unregister_thermal();
  520. mtkts6311_unregister_cooler();
  521. }
  522. late_initcall(mtkts6311_init);
  523. module_exit(mtkts6311_exit);