mtk_ts_buck.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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 <mach/pmic_mt6329_hw_bank1.h> */
  17. /* #include <mach/pmic_mt6329_sw_bank1.h> */
  18. /* #include <mach/pmic_mt6329_hw.h> */
  19. /* #include <mach/pmic_mt6329_sw.h> */
  20. #include <mt-plat/upmu_common.h>
  21. #include <mach/upmu_hw.h>
  22. #include <mach/mt_pmic_wrap.h>
  23. /* 2015.5.20 Jerry FIX_ME #include <mach/pmic_mt6331_6332_sw.h> */
  24. #include <mach/pmic_mt6325_sw.h>
  25. #include <linux/uidgid.h>
  26. static kuid_t uid = KUIDT_INIT(0);
  27. static kgid_t gid = KGIDT_INIT(1000);
  28. static unsigned int interval; /* seconds, 0 : no auto polling */
  29. static unsigned int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 };
  30. static unsigned int cl_dev_sysrst_state;
  31. static struct thermal_zone_device *thz_dev;
  32. static struct thermal_cooling_device *cl_dev_sysrst;
  33. static int tsbuck_debug_log;
  34. static int kernelmode;
  35. static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  36. static int num_trip;
  37. static char g_bind0[20] = { 0 };
  38. static char g_bind1[20] = { 0 };
  39. static char g_bind2[20] = { 0 };
  40. static char g_bind3[20] = { 0 };
  41. static char g_bind4[20] = { 0 };
  42. static char g_bind5[20] = { 0 };
  43. static char g_bind6[20] = { 0 };
  44. static char g_bind7[20] = { 0 };
  45. static char g_bind8[20] = { 0 };
  46. static char g_bind9[20] = { 0 };
  47. /**
  48. * If curr_temp >= polling_trip_temp1, use interval
  49. * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1
  50. * else, use interval*polling_factor2
  51. */
  52. static int polling_trip_temp1 = 40000;
  53. static int polling_trip_temp2 = 20000;
  54. static int polling_factor1 = 5000;
  55. static int polling_factor2 = 10000;
  56. #define TSBUCK_TEMP_CRIT 150000 /* 150.000 degree Celsius */
  57. #define tsbuck_dprintk(fmt, args...) \
  58. do { \
  59. if (tsbuck_debug_log) { \
  60. pr_debug("Power/PMIC_Thermal", fmt, ##args); \
  61. } \
  62. } while (0)
  63. /* Cali */
  64. static kal_int32 g_o_vts;
  65. static kal_int32 g_degc_cali;
  66. static kal_int32 g_adc_cali_en;
  67. static kal_int32 g_o_slope;
  68. static kal_int32 g_o_slope_sign;
  69. static kal_int32 g_id;
  70. static kal_int32 g_slope1;
  71. static kal_int32 g_slope2;
  72. static kal_int32 g_intercept;
  73. #define y_pmic_repeat_times 1
  74. void tsbuck_read_6332_efuse(void)
  75. {
  76. U32 ret = 0;
  77. U32 reg_val = 0;
  78. int i = 0, j = 0;
  79. U32 efusevalue[2];
  80. pr_debug("[tsbuck_read_6332_efuse] start\n");
  81. /* 1. enable efuse ctrl engine clock */
  82. ret = pmic_config_interface(0x80B6, 0x0010, 0xFFFF, 0);
  83. ret = pmic_config_interface(0x80A4, 0x0004, 0xFFFF, 0);
  84. /* 2. */
  85. ret = pmic_config_interface(0x8C6C, 0x1, 0x1, 0);
  86. /*
  87. //dump
  88. tsbuck_dprintk("Reg[0x%x]=0x%x,Reg[0x%x]=0x%x,Reg[0x%x]=0x%x\n",
  89. 0x80B2,upmu_get_reg_value(0x80B2),
  90. 0x80A0,upmu_get_reg_value(0x80A0),
  91. 0x8C6C,upmu_get_reg_value(0x8C6C)
  92. );
  93. */
  94. /* for(i=0;i<=0x1F;i++) */
  95. for (i = 0x10; i <= 0x11; i++) {
  96. /* 3. set row to read */
  97. ret = pmic_config_interface(0x8C56, i, 0x1F, 1);
  98. /* 4. Toggle */
  99. ret = pmic_read_interface(0x8C66, &reg_val, 0x1, 0);
  100. if (reg_val == 0)
  101. ret = pmic_config_interface(0x8C66, 1, 0x1, 0);
  102. else
  103. ret = pmic_config_interface(0x8C66, 0, 0x1, 0);
  104. reg_val = 1;
  105. while (reg_val == 1) {
  106. ret = pmic_read_interface(0x8C70, &reg_val, 0x1, 0);
  107. pr_debug("5. polling Reg[0x61A][0]=0x%x\n", reg_val);
  108. }
  109. udelay(1000); /* Need to delay at least 1ms for 0x8C70 and than can read 0x8C6E */
  110. pr_debug("5. 6332 delay 1 ms\n");
  111. /* 6. read data */
  112. efusevalue[j] = upmu_get_reg_value(0x8C6E);
  113. pr_debug("6332_efuse : efusevalue[%d]=0x%x\n", j, efusevalue[j]);
  114. /*
  115. tsbuck_dprintk("i=0x%x,Reg[0x%x]=0x%x,Reg[0x%x]=0x%x,Reg[0x%x]=0x%x\n",
  116. i,
  117. 0x8C56,upmu_get_reg_value(0x8C56),
  118. 0x8C70,upmu_get_reg_value(0x8C70),
  119. 0x8C6E,upmu_get_reg_value(0x8C6E)
  120. );
  121. */
  122. j++;
  123. }
  124. /* 7. Disable efuse ctrl engine clock */
  125. ret = pmic_config_interface(0x80A2, 0x0004, 0xFFFF, 0);
  126. ret = pmic_config_interface(0x80B4, 0x0010, 0xFFFF, 0); /* new add */
  127. /*
  128. //dump
  129. tsbuck_dprintk("Reg[0x%x]=0x%x\n",
  130. 0x80A0,upmu_get_reg_value(0x80A0)
  131. );
  132. */
  133. g_adc_cali_en = (efusevalue[0]) & 0x1;
  134. g_degc_cali = (efusevalue[0] >> 1) & 0x3F;
  135. g_o_vts = ((efusevalue[0] >> 7) & 0x1FF) + (((efusevalue[1]) & 0xF) << 9);
  136. g_o_slope_sign = (efusevalue[1] >> 4) & 0x1;
  137. g_o_slope = (efusevalue[1] >> 5) & 0x3F;
  138. g_id = (efusevalue[1] >> 11) & 0x1;
  139. tsbuck_dprintk("tsbuck_read_6332_efuse: g_o_vts = %x\n", g_o_vts);
  140. tsbuck_dprintk("tsbuck_read_6332_efuse: g_degc_cali = %x\n", g_degc_cali);
  141. tsbuck_dprintk("tsbuck_read_6332_efuse: g_adc_cali_en = %x\n", g_adc_cali_en);
  142. tsbuck_dprintk("tsbuck_read_6332_efuse: g_o_slope = %x\n", g_o_slope);
  143. tsbuck_dprintk("tsbuck_read_6332_efuse: g_o_slope_sign = %x\n", g_o_slope_sign);
  144. tsbuck_dprintk("tsbuck_read_6332_efuse: g_id = %x\n", g_id);
  145. tsbuck_dprintk("tsbuck_read_6332_efuse: ((efusevalue[0]>>7)&0x1FF) = 0x%x\n",
  146. ((efusevalue[0] >> 7) & 0x1FF));
  147. tsbuck_dprintk("tsbuck_read_6332_efuse: (((efusevalue[1])&0xF)<<9) = 0x%x\n",
  148. (((efusevalue[1]) & 0xF) << 9));
  149. tsbuck_dprintk("[tsbuck_read_6332_efuse] Done\n");
  150. }
  151. static void tsbuck_cali_prepare(void)
  152. {
  153. tsbuck_read_6332_efuse();
  154. if (g_id == 0)
  155. g_o_slope = 0;
  156. /* g_adc_cali_en=0;//FIX ME */
  157. if (g_adc_cali_en == 0) { /* no calibration */
  158. g_o_vts = 896;
  159. g_degc_cali = 50;
  160. g_o_slope = 0;
  161. g_o_slope_sign = 0;
  162. }
  163. pr_debug("Power/BUCK_Thermal: g_o_vts = 0x%x\n", g_o_vts);
  164. pr_debug("Power/BUCK_Thermal: g_degc_cali = 0x%x\n", g_degc_cali);
  165. pr_debug("Power/BUCK_Thermal: g_adc_cali_en = 0x%x\n", g_adc_cali_en);
  166. pr_debug("Power/BUCK_Thermal: g_o_slope = 0x%x\n", g_o_slope);
  167. pr_debug("Power/BUCK_Thermal: g_o_slope_sign = 0x%x\n", g_o_slope_sign);
  168. pr_debug("Power/BUCK_Thermal: g_id = 0x%x\n", g_id);
  169. }
  170. static void tsbuck_cali_prepare2(void)
  171. {
  172. kal_int32 vbe_t;
  173. g_slope1 = (100 * 1000); /* 1000 is for 0.001 degree */
  174. if (g_o_slope_sign == 0)
  175. g_slope2 = -(171 + g_o_slope);
  176. else
  177. g_slope2 = -(171 - g_o_slope);
  178. vbe_t = (-1) * (((g_o_vts) * 3200) / 4096) * 1000;
  179. if (g_o_slope_sign == 0)
  180. g_intercept = (vbe_t * 100) / (-(171 + g_o_slope)); /* 0.001 degree */
  181. else
  182. g_intercept = (vbe_t * 100) / (-(171 - g_o_slope)); /* 0.001 degree */
  183. g_intercept = g_intercept + (g_degc_cali * (1000 / 2)); /* 1000 is for 0.1 degree */
  184. pr_debug
  185. ("[Power/PMIC_Thermal] [Thermal calibration] SLOPE1=%d SLOPE2=%d INTERCEPT=%d, Vbe = %d\n",
  186. g_slope1, g_slope2, g_intercept, vbe_t);
  187. }
  188. static kal_int32 pmic_raw_to_temp(kal_uint32 ret)
  189. {
  190. kal_int32 y_curr = ret;
  191. kal_int32 t_current;
  192. t_current = g_intercept + ((g_slope1 * y_curr) / (g_slope2));
  193. /* tsbuck_dprintk("[pmic_raw_to_temp] t_current=%d\n",t_current); */
  194. return t_current;
  195. }
  196. /* int ts_pmic_at_boot_time=0; */
  197. static DEFINE_MUTEX(TSPMIC_lock);
  198. static int pre_temp1 = 0, PMIC_counter;
  199. static int tsbuck_get_hw_temp(void)
  200. {
  201. int temp = 0, temp1 = 0;
  202. /* int temp3=0; */
  203. mutex_lock(&TSPMIC_lock);
  204. temp = PMIC_IMM_GetOneChannelValue(AUX_TSENSE_32_AP, y_pmic_repeat_times, 2);
  205. temp1 = pmic_raw_to_temp(temp);
  206. /* temp2 = pmic_raw_to_temp(675); */
  207. tsbuck_dprintk("[tsbuck_get_hw_temp] Raw=%d, T=%d\n", temp, temp1);
  208. if ((temp1 > 100000) || (temp1 < -30000))
  209. pr_debug("[Power/PMIC_Thermal] raw=%d, PMIC T=%d", temp, temp1);
  210. if ((temp1 > 150000) || (temp1 < -50000)) {
  211. pr_debug("[Power/PMIC_Thermal] drop this data\n");
  212. temp1 = pre_temp1;
  213. } else if ((PMIC_counter != 0)
  214. && (((pre_temp1 - temp1) > 30000) || ((temp1 - pre_temp1) > 30000))) {
  215. pr_debug("[Power/PMIC_Thermal] drop this data 2\n");
  216. temp1 = pre_temp1;
  217. } else {
  218. /* update previous temp */
  219. pre_temp1 = temp1;
  220. tsbuck_dprintk("[Power/PMIC_Thermal] pre_temp1=%d\n", pre_temp1);
  221. if (PMIC_counter == 0)
  222. PMIC_counter++;
  223. }
  224. mutex_unlock(&TSPMIC_lock);
  225. return temp1;
  226. }
  227. static int tsbuck_get_temp(struct thermal_zone_device *thermal, unsigned long *t)
  228. {
  229. *t = tsbuck_get_hw_temp();
  230. if ((int)*t >= polling_trip_temp1)
  231. thermal->polling_delay = interval * 1000;
  232. else if ((int)*t < polling_trip_temp2)
  233. thermal->polling_delay = interval * polling_factor2;
  234. else
  235. thermal->polling_delay = interval * polling_factor1;
  236. return 0;
  237. }
  238. static int tsbuck_bind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev)
  239. {
  240. int table_val = 0;
  241. if (!strcmp(cdev->type, g_bind0)) {
  242. table_val = 0;
  243. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  244. } else if (!strcmp(cdev->type, g_bind1)) {
  245. table_val = 1;
  246. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  247. } else if (!strcmp(cdev->type, g_bind2)) {
  248. table_val = 2;
  249. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  250. } else if (!strcmp(cdev->type, g_bind3)) {
  251. table_val = 3;
  252. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  253. } else if (!strcmp(cdev->type, g_bind4)) {
  254. table_val = 4;
  255. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  256. } else if (!strcmp(cdev->type, g_bind5)) {
  257. table_val = 5;
  258. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  259. } else if (!strcmp(cdev->type, g_bind6)) {
  260. table_val = 6;
  261. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  262. } else if (!strcmp(cdev->type, g_bind7)) {
  263. table_val = 7;
  264. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  265. } else if (!strcmp(cdev->type, g_bind8)) {
  266. table_val = 8;
  267. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  268. } else if (!strcmp(cdev->type, g_bind9)) {
  269. table_val = 9;
  270. tsbuck_dprintk("[tsbuck_bind] %s\n", cdev->type);
  271. } else {
  272. return 0;
  273. }
  274. if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
  275. tsbuck_dprintk("[tsbuck_bind] error binding cooling dev\n");
  276. return -EINVAL;
  277. }
  278. tsbuck_dprintk("[tsbuck_bind] binding OK, %d\n", table_val);
  279. return 0;
  280. }
  281. static int tsbuck_unbind(struct thermal_zone_device *thermal, struct thermal_cooling_device *cdev)
  282. {
  283. int table_val = 0;
  284. if (!strcmp(cdev->type, g_bind0)) {
  285. table_val = 0;
  286. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  287. } else if (!strcmp(cdev->type, g_bind1)) {
  288. table_val = 1;
  289. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  290. } else if (!strcmp(cdev->type, g_bind2)) {
  291. table_val = 2;
  292. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  293. } else if (!strcmp(cdev->type, g_bind3)) {
  294. table_val = 3;
  295. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  296. } else if (!strcmp(cdev->type, g_bind4)) {
  297. table_val = 4;
  298. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  299. } else if (!strcmp(cdev->type, g_bind5)) {
  300. table_val = 5;
  301. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  302. } else if (!strcmp(cdev->type, g_bind6)) {
  303. table_val = 6;
  304. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  305. } else if (!strcmp(cdev->type, g_bind7)) {
  306. table_val = 7;
  307. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  308. } else if (!strcmp(cdev->type, g_bind8)) {
  309. table_val = 8;
  310. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  311. } else if (!strcmp(cdev->type, g_bind9)) {
  312. table_val = 9;
  313. tsbuck_dprintk("[tsbuck_unbind] %s\n", cdev->type);
  314. } else
  315. return 0;
  316. if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
  317. tsbuck_dprintk("[tsbuck_unbind] error unbinding cooling dev\n");
  318. return -EINVAL;
  319. }
  320. tsbuck_dprintk("[tsbuck_unbind] unbinding OK\n");
  321. return 0;
  322. }
  323. static int tsbuck_get_mode(struct thermal_zone_device *thermal, enum thermal_device_mode *mode)
  324. {
  325. *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
  326. return 0;
  327. }
  328. static int tsbuck_set_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode)
  329. {
  330. kernelmode = mode;
  331. return 0;
  332. }
  333. static int tsbuck_get_trip_type(struct thermal_zone_device *thermal, int trip,
  334. enum thermal_trip_type *type)
  335. {
  336. *type = g_THERMAL_TRIP[trip];
  337. return 0;
  338. }
  339. static int tsbuck_get_trip_temp(struct thermal_zone_device *thermal, int trip, unsigned long *temp)
  340. {
  341. *temp = trip_temp[trip];
  342. return 0;
  343. }
  344. static int tsbuck_get_crit_temp(struct thermal_zone_device *thermal, unsigned long *temperature)
  345. {
  346. *temperature = TSBUCK_TEMP_CRIT;
  347. return 0;
  348. }
  349. /* bind callback functions to thermalzone */
  350. static struct thermal_zone_device_ops tsbuck_dev_ops = {
  351. .bind = tsbuck_bind,
  352. .unbind = tsbuck_unbind,
  353. .get_temp = tsbuck_get_temp,
  354. .get_mode = tsbuck_get_mode,
  355. .set_mode = tsbuck_set_mode,
  356. .get_trip_type = tsbuck_get_trip_type,
  357. .get_trip_temp = tsbuck_get_trip_temp,
  358. .get_crit_temp = tsbuck_get_crit_temp,
  359. };
  360. static int tspmic_sysrst_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state)
  361. {
  362. *state = 1;
  363. return 0;
  364. }
  365. static int tspmic_sysrst_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state)
  366. {
  367. *state = cl_dev_sysrst_state;
  368. return 0;
  369. }
  370. static int tspmic_sysrst_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
  371. {
  372. cl_dev_sysrst_state = state;
  373. if (cl_dev_sysrst_state == 1) {
  374. pr_debug("Power/PMIC_Thermal: reset, reset, reset!!!");
  375. pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  376. pr_debug("*****************************************");
  377. pr_debug("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
  378. /* BUG(); */
  379. /* arch_reset(0,NULL); */
  380. *(unsigned int *)0x0 = 0xdead; /* To trigger data abort to reset the system for thermal protection. */
  381. }
  382. return 0;
  383. }
  384. static struct thermal_cooling_device_ops tsbuck_cooling_sysrst_ops = {
  385. .get_max_state = tspmic_sysrst_get_max_state,
  386. .get_cur_state = tspmic_sysrst_get_cur_state,
  387. .set_cur_state = tspmic_sysrst_set_cur_state,
  388. };
  389. static int tsbuck_read(struct seq_file *m, void *v)
  390. {
  391. seq_printf(m, "[ tsbuck_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,trip_4_temp=%d,\n",
  392. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3], trip_temp[4]);
  393. seq_printf(m, "trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,trip_9_temp=%d,\n",
  394. trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]);
  395. seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n",
  396. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]);
  397. seq_printf(m, "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n",
  398. g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]);
  399. seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  400. seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n",
  401. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  402. seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n",
  403. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000);
  404. return 0;
  405. }
  406. static int tsbuck_register_thermal(void);
  407. static void tsbuck_unregister_thermal(void);
  408. static ssize_t tsbuck_write(struct file *file, const char __user *buffer, size_t count,
  409. loff_t *data)
  410. {
  411. int len = 0, time_msec = 0;
  412. int trip[10] = { 0 };
  413. int t_type[10] = { 0 };
  414. int i;
  415. char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20];
  416. char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20];
  417. char desc[512];
  418. len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
  419. if (copy_from_user(desc, buffer, len))
  420. return 0;
  421. desc[len] = '\0';
  422. if (sscanf
  423. (desc,
  424. "%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",
  425. &num_trip, &trip[0], &t_type[0], bind0, &trip[1], &t_type[1], bind1, &trip[2],
  426. &t_type[2], bind2, &trip[3], &t_type[3], bind3, &trip[4], &t_type[4], bind4, &trip[5],
  427. &t_type[5], bind5, &trip[6], &t_type[6], bind6, &trip[7], &t_type[7], bind7, &trip[8],
  428. &t_type[8], bind8, &trip[9], &t_type[9], bind9, &time_msec) == 32) {
  429. tsbuck_dprintk("[tsbuck_write] tsbuck_unregister_thermal\n");
  430. tsbuck_unregister_thermal();
  431. for (i = 0; i < num_trip; i++)
  432. g_THERMAL_TRIP[i] = t_type[i];
  433. g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] =
  434. g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0';
  435. for (i = 0; i < 20; i++) {
  436. g_bind0[i] = bind0[i];
  437. g_bind1[i] = bind1[i];
  438. g_bind2[i] = bind2[i];
  439. g_bind3[i] = bind3[i];
  440. g_bind4[i] = bind4[i];
  441. g_bind5[i] = bind5[i];
  442. g_bind6[i] = bind6[i];
  443. g_bind7[i] = bind7[i];
  444. g_bind8[i] = bind8[i];
  445. g_bind9[i] = bind9[i];
  446. }
  447. tsbuck_dprintk("[tsbuck_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,",
  448. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2]);
  449. tsbuck_dprintk("g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,",
  450. g_THERMAL_TRIP[3], g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6]);
  451. tsbuck_dprintk("g_THERMAL_TRIP_7=%d,g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
  452. g_THERMAL_TRIP[7], g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  453. tsbuck_dprintk("[tsbuck_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,",
  454. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  455. tsbuck_dprintk("cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
  456. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9);
  457. for (i = 0; i < num_trip; i++)
  458. trip_temp[i] = trip[i];
  459. interval = time_msec / 1000;
  460. tsbuck_dprintk("[tsbuck_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,",
  461. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]);
  462. tsbuck_dprintk("trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,trip_8_temp=%d,",
  463. trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8]);
  464. tsbuck_dprintk("trip_9_temp=%d,time_ms=%d\n", trip_temp[9], interval * 1000);
  465. tsbuck_dprintk("[tsbuck_write] tsbuck_register_thermal\n");
  466. tsbuck_register_thermal();
  467. return count;
  468. }
  469. tsbuck_dprintk("[tsbuck_write] bad argument\n");
  470. return -EINVAL;
  471. }
  472. int tsbuck_register_cooler(void)
  473. {
  474. cl_dev_sysrst = mtk_thermal_cooling_device_register("mtktsbuck-sysrst", NULL,
  475. &tsbuck_cooling_sysrst_ops);
  476. return 0;
  477. }
  478. static int tsbuck_register_thermal(void)
  479. {
  480. tsbuck_dprintk("[tsbuck_register_thermal]\n");
  481. /* trips : trip 0~2 */
  482. thz_dev = mtk_thermal_zone_device_register("mtktsbuck", num_trip, NULL,
  483. &tsbuck_dev_ops, 0, 0, 0, interval * 1000);
  484. return 0;
  485. }
  486. void tsbuck_unregister_cooler(void)
  487. {
  488. if (cl_dev_sysrst) {
  489. mtk_thermal_cooling_device_unregister(cl_dev_sysrst);
  490. cl_dev_sysrst = NULL;
  491. }
  492. }
  493. static void tsbuck_unregister_thermal(void)
  494. {
  495. tsbuck_dprintk("[tsbuck_unregister_thermal]\n");
  496. if (thz_dev) {
  497. mtk_thermal_zone_device_unregister(thz_dev);
  498. thz_dev = NULL;
  499. }
  500. }
  501. static int tsbuck_open(struct inode *inode, struct file *file)
  502. {
  503. return single_open(file, tsbuck_read, NULL);
  504. }
  505. static const struct file_operations tsbuck_fops = {
  506. .owner = THIS_MODULE,
  507. .open = tsbuck_open,
  508. .read = seq_read,
  509. .llseek = seq_lseek,
  510. .write = tsbuck_write,
  511. .release = single_release,
  512. };
  513. static int __init tsbuck_init(void)
  514. {
  515. int err = 0;
  516. struct proc_dir_entry *entry = NULL;
  517. struct proc_dir_entry *tsbuck_dir = NULL;
  518. tsbuck_dprintk("[tsbuck_init]\n");
  519. tsbuck_cali_prepare();
  520. tsbuck_cali_prepare2();
  521. err = tsbuck_register_cooler();
  522. if (err)
  523. return err;
  524. err = tsbuck_register_thermal();
  525. if (err)
  526. goto err_unreg;
  527. tsbuck_dir = proc_mkdir("mtktsbuck", NULL);
  528. if (!tsbuck_dir) {
  529. tsbuck_dprintk("[tsbuck_init]: mkdir /proc/mtktsbuck failed\n");
  530. } else {
  531. entry =
  532. proc_create("mtktsbuck", S_IRUGO | S_IWUSR | S_IWGRP, tsbuck_dir, &tsbuck_fops);
  533. if (entry)
  534. proc_set_user(entry, uid, gid);
  535. }
  536. return 0;
  537. err_unreg:
  538. tsbuck_unregister_cooler();
  539. return err;
  540. }
  541. static void __exit tsbuck_exit(void)
  542. {
  543. tsbuck_dprintk("[tsbuck_exit]\n");
  544. tsbuck_unregister_thermal();
  545. tsbuck_unregister_cooler();
  546. }
  547. module_init(tsbuck_init);
  548. module_exit(tsbuck_exit);