mtk_ts_btsmdpa.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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/syscalls.h>
  13. #include <linux/sched.h>
  14. #include <linux/writeback.h>
  15. #include <asm/uaccess.h>
  16. #include "mt-plat/mtk_thermal_monitor.h"
  17. #include "mtk_thermal_typedefs.h"
  18. #include "mach/mt_thermal.h"
  19. #include <linux/uidgid.h>
  20. #include <tmp_bts.h>
  21. #include <linux/slab.h>
  22. /*=============================================================
  23. *Weak functions
  24. *=============================================================*/
  25. int __attribute__ ((weak))
  26. IMM_IsAdcInitReady(void)
  27. {
  28. pr_err("E_WF: %s doesn't exist\n", __func__);
  29. return 0;
  30. }
  31. int __attribute__ ((weak))
  32. IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata)
  33. {
  34. pr_err("E_WF: %s doesn't exist\n", __func__);
  35. return -1;
  36. }
  37. /*=============================================================*/
  38. static kuid_t uid = KUIDT_INIT(0);
  39. static kgid_t gid = KGIDT_INIT(1000);
  40. static unsigned int interval; /* seconds, 0 : no auto polling */
  41. static int trip_temp[10] = { 120000, 110000, 100000, 90000, 80000, 70000, 65000, 60000, 55000, 50000 };
  42. static struct thermal_zone_device *thz_dev;
  43. static int mtkts_btsmdpa_debug_log;
  44. static int kernelmode;
  45. static int g_THERMAL_TRIP[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  46. static int num_trip;
  47. static char g_bind0[20] = { 0 };
  48. static char g_bind1[20] = { 0 };
  49. static char g_bind2[20] = { 0 };
  50. static char g_bind3[20] = { 0 };
  51. static char g_bind4[20] = { 0 };
  52. static char g_bind5[20] = { 0 };
  53. static char g_bind6[20] = { 0 };
  54. static char g_bind7[20] = { 0 };
  55. static char g_bind8[20] = { 0 };
  56. static char g_bind9[20] = { 0 };
  57. /**
  58. * If curr_temp >= polling_trip_temp1, use interval
  59. * else if cur_temp >= polling_trip_temp2 && curr_temp < polling_trip_temp1, use interval*polling_factor1
  60. * else, use interval*polling_factor2
  61. */
  62. static int polling_trip_temp1 = 40000;
  63. static int polling_trip_temp2 = 20000;
  64. static int polling_factor1 = 5000;
  65. static int polling_factor2 = 10000;
  66. #define MTKTS_BTSMDPA_SW_FILTER (0)
  67. #define MTKTS_BTSMDPA_TEMP_CRIT 60000 /* 60.000 degree Celsius */
  68. #define mtkts_btsmdpa_dprintk(fmt, args...) \
  69. do { \
  70. if (mtkts_btsmdpa_debug_log) { \
  71. pr_debug("[Power/BTSMDPA_Thermal]" fmt, ##args); \
  72. } \
  73. } while (0)
  74. /* #define INPUT_PARAM_FROM_USER_AP */
  75. /*
  76. * kernel fopen/fclose
  77. */
  78. /*
  79. static mm_segment_t oldfs;
  80. static void my_close(int fd)
  81. {
  82. set_fs(oldfs);
  83. sys_close(fd);
  84. }
  85. static int my_open(char *fname, int flag)
  86. {
  87. oldfs = get_fs();
  88. set_fs(KERNEL_DS);
  89. return sys_open(fname, flag, 0);
  90. }
  91. */
  92. typedef struct {
  93. INT32 BTSMDPA_Temp;
  94. INT32 TemperatureR;
  95. } BTSMDPA_TEMPERATURE;
  96. #define AUX_IN1_NTC (1) /* NTC6302 */
  97. #if 1 /* K2 */
  98. static int g_RAP_pull_up_R = 390000; /* 390K,pull up resister */
  99. static int g_TAP_over_critical_low = 4251000; /* base on 100K NTC temp default value -40 deg */
  100. static int g_RAP_pull_up_voltage = 1800; /* 1.8V ,pull up voltage */
  101. static int g_RAP_ntc_table = 6; /* default is //NTCG104EF104F(100K) */
  102. static int g_RAP_ADC_channel = AUX_IN1_NTC; /* default is 0 */
  103. #else
  104. static int g_RAP_pull_up_R = 39000; /* 39K,pull up resister */
  105. static int g_TAP_over_critical_low = 188500; /* base on 10K NTC temp default value -40 deg */
  106. static int g_RAP_pull_up_voltage = 1800; /* 1.8V ,pull up voltage */
  107. static int g_RAP_ntc_table = 4; /* default is AP_NTC_10 */
  108. static int g_RAP_ADC_channel = AUX_IN1_NTC; /* default is 0 */
  109. #endif
  110. static int g_btsmdpa_TemperatureR;
  111. /* BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table[] = {0}; */
  112. static BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table[] = {
  113. {0, 0},
  114. {0, 0},
  115. {0, 0},
  116. {0, 0},
  117. {0, 0},
  118. {0, 0},
  119. {0, 0},
  120. {0, 0},
  121. {0, 0},
  122. {0, 0},
  123. {0, 0},
  124. {0, 0},
  125. {0, 0},
  126. {0, 0},
  127. {0, 0},
  128. {0, 0},
  129. {0, 0},
  130. {0, 0},
  131. {0, 0},
  132. {0, 0},
  133. {0, 0},
  134. {0, 0},
  135. {0, 0},
  136. {0, 0},
  137. {0, 0},
  138. {0, 0},
  139. {0, 0},
  140. {0, 0},
  141. {0, 0},
  142. {0, 0},
  143. {0, 0},
  144. {0, 0},
  145. {0, 0},
  146. {0, 0}
  147. };
  148. /* AP_NTC_BL197 */
  149. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table1[] = {
  150. {-40, 74354}, /* FIX_ME */
  151. {-35, 74354}, /* FIX_ME */
  152. {-30, 74354}, /* FIX_ME */
  153. {-25, 74354}, /* FIX_ME */
  154. {-20, 74354},
  155. {-15, 57626},
  156. {-10, 45068},
  157. {-5, 35548},
  158. {0, 28267},
  159. {5, 22650},
  160. {10, 18280},
  161. {15, 14855},
  162. {20, 12151},
  163. {25, 10000}, /* 10K */
  164. {30, 8279},
  165. {35, 6892},
  166. {40, 5768},
  167. {45, 4852},
  168. {50, 4101},
  169. {55, 3483},
  170. {60, 2970}, /* FIX_ME */
  171. {60, 2970}, /* FIX_ME */
  172. {60, 2970}, /* FIX_ME */
  173. {60, 2970}, /* FIX_ME */
  174. {60, 2970}, /* FIX_ME */
  175. {60, 2970}, /* FIX_ME */
  176. {60, 2970}, /* FIX_ME */
  177. {60, 2970}, /* FIX_ME */
  178. {60, 2970}, /* FIX_ME */
  179. {60, 2970}, /* FIX_ME */
  180. {60, 2970}, /* FIX_ME */
  181. {60, 2970}, /* FIX_ME */
  182. {60, 2970}, /* FIX_ME */
  183. {60, 2970} /* FIX_ME */
  184. };
  185. /* AP_NTC_TSM_1 */
  186. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table2[] = {
  187. {-40, 70603}, /* FIX_ME */
  188. {-35, 70603}, /* FIX_ME */
  189. {-30, 70603}, /* FIX_ME */
  190. {-25, 70603}, /* FIX_ME */
  191. {-20, 70603},
  192. {-15, 55183},
  193. {-10, 43499},
  194. {-5, 34569},
  195. {0, 27680},
  196. {5, 22316},
  197. {10, 18104},
  198. {15, 14773},
  199. {20, 12122},
  200. {25, 10000}, /* 10K */
  201. {30, 8294},
  202. {35, 6915},
  203. {40, 5795},
  204. {45, 4882},
  205. {50, 4133},
  206. {55, 3516},
  207. {60, 3004}, /* FIX_ME */
  208. {60, 3004}, /* FIX_ME */
  209. {60, 3004}, /* FIX_ME */
  210. {60, 3004}, /* FIX_ME */
  211. {60, 3004}, /* FIX_ME */
  212. {60, 3004}, /* FIX_ME */
  213. {60, 3004}, /* FIX_ME */
  214. {60, 3004}, /* FIX_ME */
  215. {60, 3004}, /* FIX_ME */
  216. {60, 3004}, /* FIX_ME */
  217. {60, 3004}, /* FIX_ME */
  218. {60, 3004}, /* FIX_ME */
  219. {60, 3004}, /* FIX_ME */
  220. {60, 3004} /* FIX_ME */
  221. };
  222. /* AP_NTC_10_SEN_1 */
  223. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table3[] = {
  224. {-40, 74354}, /* FIX_ME */
  225. {-35, 74354}, /* FIX_ME */
  226. {-30, 74354}, /* FIX_ME */
  227. {-25, 74354}, /* FIX_ME */
  228. {-20, 74354},
  229. {-15, 57626},
  230. {-10, 45068},
  231. {-5, 35548},
  232. {0, 28267},
  233. {5, 22650},
  234. {10, 18280},
  235. {15, 14855},
  236. {20, 12151},
  237. {25, 10000}, /* 10K */
  238. {30, 8279},
  239. {35, 6892},
  240. {40, 5768},
  241. {45, 4852},
  242. {50, 4101},
  243. {55, 3483},
  244. {60, 2970},
  245. {60, 2970}, /* FIX_ME */
  246. {60, 2970}, /* FIX_ME */
  247. {60, 2970}, /* FIX_ME */
  248. {60, 2970}, /* FIX_ME */
  249. {60, 2970}, /* FIX_ME */
  250. {60, 2970}, /* FIX_ME */
  251. {60, 2970}, /* FIX_ME */
  252. {60, 2970}, /* FIX_ME */
  253. {60, 2970}, /* FIX_ME */
  254. {60, 2970}, /* FIX_ME */
  255. {60, 2970}, /* FIX_ME */
  256. {60, 2970}, /* FIX_ME */
  257. {60, 2970} /* FIX_ME */
  258. };
  259. #if 0
  260. /* AP_NTC_10 */
  261. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table4[] = {
  262. {-20, 68237},
  263. {-15, 53650},
  264. {-10, 42506},
  265. {-5, 33892},
  266. {0, 27219},
  267. {5, 22021},
  268. {10, 17926},
  269. {15, 14674},
  270. {20, 12081},
  271. {25, 10000},
  272. {30, 8315},
  273. {35, 6948},
  274. {40, 5834},
  275. {45, 4917},
  276. {50, 4161},
  277. {55, 3535},
  278. {60, 3014}
  279. };
  280. #else
  281. /* AP_NTC_10(TSM0A103F34D1RZ) */
  282. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table4[] = {
  283. {-40, 188500},
  284. {-35, 144290},
  285. {-30, 111330},
  286. {-25, 86560},
  287. {-20, 67790},
  288. {-15, 53460},
  289. {-10, 42450},
  290. {-5, 33930},
  291. {0, 27280},
  292. {5, 22070},
  293. {10, 17960},
  294. {15, 14700},
  295. {20, 12090},
  296. {25, 10000}, /* 10K */
  297. {30, 8310},
  298. {35, 6940},
  299. {40, 5830},
  300. {45, 4910},
  301. {50, 4160},
  302. {55, 3540},
  303. {60, 3020},
  304. {65, 2590},
  305. {70, 2230},
  306. {75, 1920},
  307. {80, 1670},
  308. {85, 1450},
  309. {90, 1270},
  310. {95, 1110},
  311. {100, 975},
  312. {105, 860},
  313. {110, 760},
  314. {115, 674},
  315. {120, 599},
  316. {125, 534}
  317. };
  318. #endif
  319. /* AP_NTC_47 */
  320. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table5[] = {
  321. {-40, 483954}, /* FIX_ME */
  322. {-35, 483954}, /* FIX_ME */
  323. {-30, 483954}, /* FIX_ME */
  324. {-25, 483954}, /* FIX_ME */
  325. {-20, 483954},
  326. {-15, 360850},
  327. {-10, 271697},
  328. {-5, 206463},
  329. {0, 158214},
  330. {5, 122259},
  331. {10, 95227},
  332. {15, 74730},
  333. {20, 59065},
  334. {25, 47000}, /* 47K */
  335. {30, 37643},
  336. {35, 30334},
  337. {40, 24591},
  338. {45, 20048},
  339. {50, 16433},
  340. {55, 13539},
  341. {60, 11210},
  342. {60, 11210}, /* FIX_ME */
  343. {60, 11210}, /* FIX_ME */
  344. {60, 11210}, /* FIX_ME */
  345. {60, 11210}, /* FIX_ME */
  346. {60, 11210}, /* FIX_ME */
  347. {60, 11210}, /* FIX_ME */
  348. {60, 11210}, /* FIX_ME */
  349. {60, 11210}, /* FIX_ME */
  350. {60, 11210}, /* FIX_ME */
  351. {60, 11210}, /* FIX_ME */
  352. {60, 11210}, /* FIX_ME */
  353. {60, 11210}, /* FIX_ME */
  354. {60, 11210} /* FIX_ME */
  355. };
  356. /* NTCG104EF104F(100K) */
  357. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table6[] = {
  358. {-40, 4251000},
  359. {-35, 3005000},
  360. {-30, 2149000},
  361. {-25, 1554000},
  362. {-20, 1135000},
  363. {-15, 837800},
  364. {-10, 624100},
  365. {-5, 469100},
  366. {0, 355600},
  367. {5, 271800},
  368. {10, 209400},
  369. {15, 162500},
  370. {20, 127000},
  371. {25, 100000}, /* 100K */
  372. {30, 79230},
  373. {35, 63180},
  374. {40, 50680},
  375. {45, 40900},
  376. {50, 33190},
  377. {55, 27090},
  378. {60, 22220},
  379. {65, 18320},
  380. {70, 15180},
  381. {75, 12640},
  382. {80, 10580},
  383. {85, 8887},
  384. {90, 7500},
  385. {95, 6357},
  386. {100, 5410},
  387. {105, 4623},
  388. {110, 3965},
  389. {115, 3415},
  390. {120, 2951},
  391. {125, 2560}
  392. };
  393. /* NCP15WF104F03RC(100K) */
  394. BTSMDPA_TEMPERATURE BTSMDPA_Temperature_Table7[] = {
  395. {-40, 4397119},
  396. {-35, 3088599},
  397. {-30, 2197225},
  398. {-25, 1581881},
  399. {-20, 1151037},
  400. {-15, 846579},
  401. {-10, 628988},
  402. {-5, 471632},
  403. {0, 357012},
  404. {5, 272500},
  405. {10, 209710},
  406. {15, 162651},
  407. {20, 127080},
  408. {25, 100000}, /* 100K */
  409. {30, 79222},
  410. {35, 63167},
  411. {40, 50677},
  412. {45, 40904},
  413. {50, 33195},
  414. {55, 27091},
  415. {60, 22224},
  416. {65, 18323},
  417. {70, 15184},
  418. {75, 12635},
  419. {80, 10566},
  420. {85, 8873},
  421. {90, 7481},
  422. {95, 6337},
  423. {100, 5384},
  424. {105, 4594},
  425. {110, 3934},
  426. {115, 3380},
  427. {120, 2916},
  428. {125, 2522}
  429. };
  430. /* convert register to temperature */
  431. static INT16 mtkts_btsmdpa_thermistor_conver_temp(INT32 Res)
  432. {
  433. int i = 0;
  434. int asize = 0;
  435. INT32 RES1 = 0, RES2 = 0;
  436. INT32 TAP_Value = -200, TMP1 = 0, TMP2 = 0;
  437. asize = (sizeof(BTSMDPA_Temperature_Table) / sizeof(BTSMDPA_TEMPERATURE));
  438. /* mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : asize = %d, Res = %d\n",asize,Res); */
  439. if (Res >= BTSMDPA_Temperature_Table[0].TemperatureR) {
  440. TAP_Value = -40; /* min */
  441. } else if (Res <= BTSMDPA_Temperature_Table[asize - 1].TemperatureR) {
  442. TAP_Value = 125; /* max */
  443. } else {
  444. RES1 = BTSMDPA_Temperature_Table[0].TemperatureR;
  445. TMP1 = BTSMDPA_Temperature_Table[0].BTSMDPA_Temp;
  446. /* mtkts_btsmdpa_dprintk("%d : RES1 = %d,TMP1 = %d\n",__LINE__,RES1,TMP1); */
  447. for (i = 0; i < asize; i++) {
  448. if (Res >= BTSMDPA_Temperature_Table[i].TemperatureR) {
  449. RES2 = BTSMDPA_Temperature_Table[i].TemperatureR;
  450. TMP2 = BTSMDPA_Temperature_Table[i].BTSMDPA_Temp;
  451. /* mtkts_btsmdpa_dprintk("%d :i=%d, RES2 = %d,TMP2 = %d\n",__LINE__,i,RES2,TMP2); */
  452. break;
  453. }
  454. RES1 = BTSMDPA_Temperature_Table[i].TemperatureR;
  455. TMP1 = BTSMDPA_Temperature_Table[i].BTSMDPA_Temp;
  456. /* mtkts_btsmdpa_dprintk("%d :i=%d, RES1 = %d,TMP1 = %d\n",__LINE__,i,RES1,TMP1); */
  457. }
  458. TAP_Value = (((Res - RES2) * TMP1) + ((RES1 - Res) * TMP2)) / (RES1 - RES2);
  459. }
  460. #if 0
  461. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : TAP_Value = %d\n",
  462. TAP_Value);
  463. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : Res = %d\n", Res);
  464. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : RES1 = %d\n", RES1);
  465. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : RES2 = %d\n", RES2);
  466. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : TMP1 = %d\n", TMP1);
  467. mtkts_btsmdpa_dprintk("mtkts_btsmdpa_thermistor_conver_temp() : TMP2 = %d\n", TMP2);
  468. #endif
  469. return TAP_Value;
  470. }
  471. /* convert ADC_AP_temp_volt to register */
  472. /*Volt to Temp formula same with 6589*/
  473. static INT16 mtk_ts_btsmdpa_volt_to_temp(UINT32 dwVolt)
  474. {
  475. INT32 TRes;
  476. INT32 dwVCriAP = 0;
  477. INT32 BTSMDPA_TMP = -100;
  478. /* SW workaround----------------------------------------------------- */
  479. /* dwVCriAP = (TAP_OVER_CRITICAL_LOW * 1800) / (TAP_OVER_CRITICAL_LOW + 39000); */
  480. /* dwVCriAP = (TAP_OVER_CRITICAL_LOW * RAP_PULL_UP_VOLT) / (TAP_OVER_CRITICAL_LOW + RAP_PULL_UP_R); */
  481. dwVCriAP =
  482. (g_TAP_over_critical_low * g_RAP_pull_up_voltage) / (g_TAP_over_critical_low +
  483. g_RAP_pull_up_R);
  484. if (dwVolt > dwVCriAP) {
  485. TRes = g_TAP_over_critical_low;
  486. } else {
  487. /* TRes = (39000*dwVolt) / (1800-dwVolt); */
  488. /* TRes = (RAP_PULL_UP_R*dwVolt) / (RAP_PULL_UP_VOLT-dwVolt); */
  489. TRes = (g_RAP_pull_up_R * dwVolt) / (g_RAP_pull_up_voltage - dwVolt);
  490. }
  491. /* ------------------------------------------------------------------ */
  492. g_btsmdpa_TemperatureR = TRes;
  493. /* convert register to temperature */
  494. BTSMDPA_TMP = mtkts_btsmdpa_thermistor_conver_temp(TRes);
  495. return BTSMDPA_TMP;
  496. }
  497. static int get_hw_btsmdpa_temp(void)
  498. {
  499. int ret = 0, data[4], i, ret_value = 0, ret_temp = 0, output;
  500. int times = 1, Channel = g_RAP_ADC_channel; /* 6752=0(AUX_IN1_NTC) */
  501. if (IMM_IsAdcInitReady() == 0) {
  502. pr_debug("[thermal_auxadc_get_data]: AUXADC is not ready\n");
  503. return 0;
  504. }
  505. i = times;
  506. while (i--) {
  507. ret_value = IMM_GetOneChannelValue(Channel, data, &ret_temp);
  508. ret += ret_temp;
  509. mtkts_btsmdpa_dprintk("[thermal_auxadc_get_data(AUX_IN1_NTC)]: ret_temp=%d\n",
  510. ret_temp);
  511. }
  512. /* Mt_auxadc_hal.c */
  513. /* #define VOLTAGE_FULL_RANGE 1500 // VA voltage */
  514. /* #define AUXADC_PRECISE 4096 // 12 bits */
  515. ret = ret * 1500 / 4096;
  516. /* ret = ret*1800/4096;//82's ADC power */
  517. mtkts_btsmdpa_dprintk("APtery output mV = %d\n", ret);
  518. output = mtk_ts_btsmdpa_volt_to_temp(ret);
  519. mtkts_btsmdpa_dprintk("BTSMDPA output temperature = %d\n", output);
  520. return output;
  521. }
  522. static DEFINE_MUTEX(BTSMDPA_lock);
  523. int ts_btsmdpa_at_boot_time = 0;
  524. int mtkts_btsmdpa_get_hw_temp(void)
  525. {
  526. int t_ret = 0;
  527. #if MTKTS_BTSMDPA_SW_FILTER
  528. static int pre_temp1;
  529. #define DELTA_TEMP 2000
  530. #endif
  531. mutex_lock(&BTSMDPA_lock);
  532. /* get HW AP temp (TSAP) */
  533. /* cat /sys/class/power_supply/AP/AP_temp */
  534. t_ret = get_hw_btsmdpa_temp();
  535. t_ret = t_ret * 1000;
  536. #if MTKTS_BTSMDPA_SW_FILTER
  537. if ((t_ret > 100000) || (t_ret < -30000)) {
  538. pr_debug("[Power/BTSMDPA_Thermal] drop this data\n");
  539. t_ret = pre_temp1;
  540. } else if ((pre_temp1 != 0)
  541. && (((pre_temp1 - t_ret) >= DELTA_TEMP)
  542. || ((t_ret - pre_temp1) >= DELTA_TEMP))) {
  543. mtkts_btsmdpa_dprintk
  544. ("[Power/BTSMDPA_Thermal] t_ret=%d,(t_ret-pre_temp1)=%d,(pre_temp1-t_ret)=%d\n",
  545. t_ret, (t_ret - pre_temp1), (pre_temp1 - t_ret));
  546. t_ret = pre_temp1;
  547. } else {
  548. /* update previous temp */
  549. pre_temp1 = t_ret;
  550. mtkts_btsmdpa_dprintk("[Power/BTSMDPA_Thermal] pre_temp1=%d\n", pre_temp1);
  551. }
  552. #endif
  553. mutex_unlock(&BTSMDPA_lock);
  554. if (t_ret > 40000) /* abnormal high temp */
  555. pr_debug("[Power/BTSMDPA_Thermal] T_btsmdpa=%d\n", t_ret);
  556. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_get_hw_temp] T_btsmdpa, %d\n", t_ret);
  557. return t_ret;
  558. }
  559. static int mtkts_btsmdpa_get_temp(struct thermal_zone_device *thermal, unsigned long *t)
  560. {
  561. *t = mtkts_btsmdpa_get_hw_temp();
  562. if ((int)*t > 52000)
  563. mtkts_btsmdpa_dprintk("T=%d\n", (int)*t);
  564. if ((int)*t >= polling_trip_temp1)
  565. thermal->polling_delay = interval * 1000;
  566. else if ((int)*t < polling_trip_temp2)
  567. thermal->polling_delay = interval * polling_factor2;
  568. else
  569. thermal->polling_delay = interval * polling_factor1;
  570. return 0;
  571. }
  572. static int mtkts_btsmdpa_bind(struct thermal_zone_device *thermal,
  573. struct thermal_cooling_device *cdev)
  574. {
  575. int table_val = 0;
  576. if (!strcmp(cdev->type, g_bind0)) {
  577. table_val = 0;
  578. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  579. } else if (!strcmp(cdev->type, g_bind1)) {
  580. table_val = 1;
  581. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  582. } else if (!strcmp(cdev->type, g_bind2)) {
  583. table_val = 2;
  584. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  585. } else if (!strcmp(cdev->type, g_bind3)) {
  586. table_val = 3;
  587. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  588. } else if (!strcmp(cdev->type, g_bind4)) {
  589. table_val = 4;
  590. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  591. } else if (!strcmp(cdev->type, g_bind5)) {
  592. table_val = 5;
  593. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  594. } else if (!strcmp(cdev->type, g_bind6)) {
  595. table_val = 6;
  596. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  597. } else if (!strcmp(cdev->type, g_bind7)) {
  598. table_val = 7;
  599. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  600. } else if (!strcmp(cdev->type, g_bind8)) {
  601. table_val = 8;
  602. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  603. } else if (!strcmp(cdev->type, g_bind9)) {
  604. table_val = 9;
  605. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] %s\n", cdev->type);
  606. } else {
  607. return 0;
  608. }
  609. if (mtk_thermal_zone_bind_cooling_device(thermal, table_val, cdev)) {
  610. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] error binding cooling dev\n");
  611. return -EINVAL;
  612. }
  613. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_bind] binding OK, %d\n", table_val);
  614. return 0;
  615. }
  616. static int mtkts_btsmdpa_unbind(struct thermal_zone_device *thermal,
  617. struct thermal_cooling_device *cdev)
  618. {
  619. int table_val = 0;
  620. if (!strcmp(cdev->type, g_bind0)) {
  621. table_val = 0;
  622. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  623. } else if (!strcmp(cdev->type, g_bind1)) {
  624. table_val = 1;
  625. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  626. } else if (!strcmp(cdev->type, g_bind2)) {
  627. table_val = 2;
  628. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  629. } else if (!strcmp(cdev->type, g_bind3)) {
  630. table_val = 3;
  631. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  632. } else if (!strcmp(cdev->type, g_bind4)) {
  633. table_val = 4;
  634. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  635. } else if (!strcmp(cdev->type, g_bind5)) {
  636. table_val = 5;
  637. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  638. } else if (!strcmp(cdev->type, g_bind6)) {
  639. table_val = 6;
  640. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  641. } else if (!strcmp(cdev->type, g_bind7)) {
  642. table_val = 7;
  643. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  644. } else if (!strcmp(cdev->type, g_bind8)) {
  645. table_val = 8;
  646. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  647. } else if (!strcmp(cdev->type, g_bind9)) {
  648. table_val = 9;
  649. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] %s\n", cdev->type);
  650. } else
  651. return 0;
  652. if (thermal_zone_unbind_cooling_device(thermal, table_val, cdev)) {
  653. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] error unbinding cooling dev\n");
  654. return -EINVAL;
  655. }
  656. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unbind] unbinding OK\n");
  657. return 0;
  658. }
  659. static int mtkts_btsmdpa_get_mode(struct thermal_zone_device *thermal,
  660. enum thermal_device_mode *mode)
  661. {
  662. *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED;
  663. return 0;
  664. }
  665. static int mtkts_btsmdpa_set_mode(struct thermal_zone_device *thermal,
  666. enum thermal_device_mode mode)
  667. {
  668. kernelmode = mode;
  669. return 0;
  670. }
  671. static int mtkts_btsmdpa_get_trip_type(struct thermal_zone_device *thermal, int trip,
  672. enum thermal_trip_type *type)
  673. {
  674. *type = g_THERMAL_TRIP[trip];
  675. return 0;
  676. }
  677. static int mtkts_btsmdpa_get_trip_temp(struct thermal_zone_device *thermal, int trip,
  678. unsigned long *temp)
  679. {
  680. *temp = trip_temp[trip];
  681. return 0;
  682. }
  683. static int mtkts_btsmdpa_get_crit_temp(struct thermal_zone_device *thermal,
  684. unsigned long *temperature)
  685. {
  686. *temperature = MTKTS_BTSMDPA_TEMP_CRIT;
  687. return 0;
  688. }
  689. /* bind callback functions to thermalzone */
  690. static struct thermal_zone_device_ops mtkts_btsmdpa_dev_ops = {
  691. .bind = mtkts_btsmdpa_bind,
  692. .unbind = mtkts_btsmdpa_unbind,
  693. .get_temp = mtkts_btsmdpa_get_temp,
  694. .get_mode = mtkts_btsmdpa_get_mode,
  695. .set_mode = mtkts_btsmdpa_set_mode,
  696. .get_trip_type = mtkts_btsmdpa_get_trip_type,
  697. .get_trip_temp = mtkts_btsmdpa_get_trip_temp,
  698. .get_crit_temp = mtkts_btsmdpa_get_crit_temp,
  699. };
  700. static int mtkts_btsmdpa_read(struct seq_file *m, void *v)
  701. {
  702. seq_printf(m, "[mtkts_btsmdpa_read] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,trip_3_temp=%d,\n",
  703. trip_temp[0], trip_temp[1], trip_temp[2], trip_temp[3]);
  704. 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",
  705. trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7], trip_temp[8], trip_temp[9]);
  706. seq_printf(m, "g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,\n",
  707. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1], g_THERMAL_TRIP[2], g_THERMAL_TRIP[3]);
  708. seq_printf(m, "g_THERMAL_TRIP_4=%d,g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,\n",
  709. g_THERMAL_TRIP[4], g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]);
  710. seq_printf(m, "g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n", g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  711. seq_printf(m, "cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,cooldev4=%s,\n",
  712. g_bind0, g_bind1, g_bind2, g_bind3, g_bind4);
  713. seq_printf(m, "cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s,time_ms=%d\n",
  714. g_bind5, g_bind6, g_bind7, g_bind8, g_bind9, interval * 1000);
  715. return 0;
  716. }
  717. static int mtkts_btsmdpa_register_thermal(void);
  718. static void mtkts_btsmdpa_unregister_thermal(void);
  719. static ssize_t mtkts_btsmdpa_write(struct file *file, const char __user *buffer, size_t count,
  720. loff_t *data)
  721. {
  722. int len = 0;
  723. int i;
  724. struct btsmdpa_data {
  725. int trip[10];
  726. int t_type[10];
  727. char bind0[20], bind1[20], bind2[20], bind3[20], bind4[20];
  728. char bind5[20], bind6[20], bind7[20], bind8[20], bind9[20];
  729. int time_msec;
  730. char desc[512];
  731. };
  732. struct btsmdpa_data *ptr_btsmdpa_data = kmalloc(sizeof(*ptr_btsmdpa_data), GFP_KERNEL);
  733. if (ptr_btsmdpa_data == NULL)
  734. return -ENOMEM;
  735. len = (count < (sizeof(ptr_btsmdpa_data->desc) - 1)) ? count : (sizeof(ptr_btsmdpa_data->desc) - 1);
  736. if (copy_from_user(ptr_btsmdpa_data->desc, buffer, len)) {
  737. kfree(ptr_btsmdpa_data);
  738. return 0;
  739. }
  740. ptr_btsmdpa_data->desc[len] = '\0';
  741. if (sscanf
  742. (ptr_btsmdpa_data->desc,
  743. "%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",
  744. &num_trip, &ptr_btsmdpa_data->trip[0], &ptr_btsmdpa_data->t_type[0],
  745. ptr_btsmdpa_data->bind0, &ptr_btsmdpa_data->trip[1], &ptr_btsmdpa_data->t_type[1], ptr_btsmdpa_data->bind1,
  746. &ptr_btsmdpa_data->trip[2], &ptr_btsmdpa_data->t_type[2], ptr_btsmdpa_data->bind2,
  747. &ptr_btsmdpa_data->trip[3], &ptr_btsmdpa_data->t_type[3], ptr_btsmdpa_data->bind3,
  748. &ptr_btsmdpa_data->trip[4], &ptr_btsmdpa_data->t_type[4], ptr_btsmdpa_data->bind4,
  749. &ptr_btsmdpa_data->trip[5], &ptr_btsmdpa_data->t_type[5], ptr_btsmdpa_data->bind5,
  750. &ptr_btsmdpa_data->trip[6], &ptr_btsmdpa_data->t_type[6], ptr_btsmdpa_data->bind6,
  751. &ptr_btsmdpa_data->trip[7], &ptr_btsmdpa_data->t_type[7], ptr_btsmdpa_data->bind7,
  752. &ptr_btsmdpa_data->trip[8], &ptr_btsmdpa_data->t_type[8], ptr_btsmdpa_data->bind8,
  753. &ptr_btsmdpa_data->trip[9], &ptr_btsmdpa_data->t_type[9], ptr_btsmdpa_data->bind9,
  754. &ptr_btsmdpa_data->time_msec) == 32) {
  755. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] mtkts_btsmdpa_unregister_thermal\n");
  756. mtkts_btsmdpa_unregister_thermal();
  757. if (num_trip < 0 || num_trip > 10) {
  758. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mtkts_btsmdpa_write",
  759. "Bad argument");
  760. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] bad argument\n");
  761. kfree(ptr_btsmdpa_data);
  762. return -EINVAL;
  763. }
  764. for (i = 0; i < num_trip; i++)
  765. g_THERMAL_TRIP[i] = ptr_btsmdpa_data->t_type[i];
  766. g_bind0[0] = g_bind1[0] = g_bind2[0] = g_bind3[0] = g_bind4[0] = g_bind5[0] =
  767. g_bind6[0] = g_bind7[0] = g_bind8[0] = g_bind9[0] = '\0';
  768. for (i = 0; i < 20; i++) {
  769. g_bind0[i] = ptr_btsmdpa_data->bind0[i];
  770. g_bind1[i] = ptr_btsmdpa_data->bind1[i];
  771. g_bind2[i] = ptr_btsmdpa_data->bind2[i];
  772. g_bind3[i] = ptr_btsmdpa_data->bind3[i];
  773. g_bind4[i] = ptr_btsmdpa_data->bind4[i];
  774. g_bind5[i] = ptr_btsmdpa_data->bind5[i];
  775. g_bind6[i] = ptr_btsmdpa_data->bind6[i];
  776. g_bind7[i] = ptr_btsmdpa_data->bind7[i];
  777. g_bind8[i] = ptr_btsmdpa_data->bind8[i];
  778. g_bind9[i] = ptr_btsmdpa_data->bind9[i];
  779. }
  780. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] g_THERMAL_TRIP_0=%d,g_THERMAL_TRIP_1=%d,",
  781. g_THERMAL_TRIP[0], g_THERMAL_TRIP[1]);
  782. mtkts_btsmdpa_dprintk("g_THERMAL_TRIP_2=%d,g_THERMAL_TRIP_3=%d,g_THERMAL_TRIP_4=%d,",
  783. g_THERMAL_TRIP[2], g_THERMAL_TRIP[3], g_THERMAL_TRIP[4]);
  784. mtkts_btsmdpa_dprintk("g_THERMAL_TRIP_5=%d,g_THERMAL_TRIP_6=%d,g_THERMAL_TRIP_7=%d,",
  785. g_THERMAL_TRIP[5], g_THERMAL_TRIP[6], g_THERMAL_TRIP[7]);
  786. mtkts_btsmdpa_dprintk("g_THERMAL_TRIP_8=%d,g_THERMAL_TRIP_9=%d,\n",
  787. g_THERMAL_TRIP[8], g_THERMAL_TRIP[9]);
  788. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] cooldev0=%s,cooldev1=%s,cooldev2=%s,cooldev3=%s,",
  789. g_bind0, g_bind1, g_bind2, g_bind3);
  790. mtkts_btsmdpa_dprintk("cooldev4=%s,cooldev5=%s,cooldev6=%s,cooldev7=%s,cooldev8=%s,cooldev9=%s\n",
  791. g_bind4, g_bind5, g_bind6, g_bind7, g_bind8, g_bind9);
  792. for (i = 0; i < num_trip; i++)
  793. trip_temp[i] = ptr_btsmdpa_data->trip[i];
  794. interval = ptr_btsmdpa_data->time_msec / 1000;
  795. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] trip_0_temp=%d,trip_1_temp=%d,trip_2_temp=%d,",
  796. trip_temp[0], trip_temp[1], trip_temp[2]);
  797. mtkts_btsmdpa_dprintk("trip_3_temp=%d,trip_4_temp=%d,trip_5_temp=%d,trip_6_temp=%d,trip_7_temp=%d,",
  798. trip_temp[3], trip_temp[4], trip_temp[5], trip_temp[6], trip_temp[7]);
  799. mtkts_btsmdpa_dprintk("trip_8_temp=%d,trip_9_temp=%d,time_ms=%d\n",
  800. trip_temp[8], trip_temp[9], interval * 1000);
  801. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] mtkts_btsmdpa_register_thermal\n");
  802. mtkts_btsmdpa_register_thermal();
  803. kfree(ptr_btsmdpa_data);
  804. /* AP_write_flag=1; */
  805. return count;
  806. }
  807. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write] bad argument\n");
  808. aee_kernel_warning_api(__FILE__, __LINE__, DB_OPT_DEFAULT, "mtkts_btsmdpa_write",
  809. "Bad argument");
  810. kfree(ptr_btsmdpa_data);
  811. return -EINVAL;
  812. }
  813. void mtkts_btsmdpa_copy_table(BTSMDPA_TEMPERATURE *des, BTSMDPA_TEMPERATURE *src)
  814. {
  815. int i = 0;
  816. int j = 0;
  817. j = (sizeof(BTSMDPA_Temperature_Table) / sizeof(BTSMDPA_TEMPERATURE));
  818. /* mtkts_btsmdpa_dprintk("mtkts_btsmdpa_copy_table() : j = %d\n",j); */
  819. for (i = 0; i < j; i++)
  820. des[i] = src[i];
  821. }
  822. void mtkts_btsmdpa_prepare_table(int table_num)
  823. {
  824. switch (table_num) {
  825. case 1: /* AP_NTC_BL197 */
  826. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table1);
  827. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table1));
  828. break;
  829. case 2: /* AP_NTC_TSM_1 */
  830. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table2);
  831. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table2));
  832. break;
  833. case 3: /* AP_NTC_10_SEN_1 */
  834. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table3);
  835. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table3));
  836. break;
  837. case 4: /* AP_NTC_10 */
  838. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table4);
  839. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table4));
  840. break;
  841. case 5: /* AP_NTC_47 */
  842. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table5);
  843. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table5));
  844. break;
  845. case 6: /* NTCG104EF104F */
  846. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table6);
  847. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table6));
  848. break;
  849. case 7: /* NCP15WF104F03RC */
  850. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table7);
  851. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table7));
  852. break;
  853. default: /* AP_NTC_10 */
  854. mtkts_btsmdpa_copy_table(BTSMDPA_Temperature_Table, BTSMDPA_Temperature_Table4);
  855. BUG_ON(sizeof(BTSMDPA_Temperature_Table) != sizeof(BTSMDPA_Temperature_Table4));
  856. break;
  857. }
  858. #if 0
  859. {
  860. int i = 0;
  861. for (i = 0; i < (sizeof(BTSMDPA_Temperature_Table) / sizeof(BTSMDPA_TEMPERATURE));
  862. i++) {
  863. mtkts_btsmdpa_dprintk("BTSMDPA_Temperature_Table[%d].APteryTemp =%d\n", i,
  864. BTSMDPA_Temperature_Table[i].BTSMDPA_Temp);
  865. mtkts_btsmdpa_dprintk("BTSMDPA_Temperature_Table[%d].TemperatureR=%d\n", i,
  866. BTSMDPA_Temperature_Table[i].TemperatureR);
  867. }
  868. }
  869. #endif
  870. }
  871. static int mtkts_btsmdpa_param_read(struct seq_file *m, void *v)
  872. {
  873. seq_printf(m, "%d\n", g_RAP_pull_up_R);
  874. seq_printf(m, "%d\n", g_RAP_pull_up_voltage);
  875. seq_printf(m, "%d\n", g_TAP_over_critical_low);
  876. seq_printf(m, "%d\n", g_RAP_ntc_table);
  877. seq_printf(m, "%d\n", g_RAP_ADC_channel);
  878. return 0;
  879. }
  880. static ssize_t mtkts_btsmdpa_param_write(struct file *file, const char __user *buffer,
  881. size_t count, loff_t *data)
  882. {
  883. int len = 0;
  884. struct param_data {
  885. char desc[512];
  886. char pull_R[10], pull_V[10];
  887. char overcrilow[16];
  888. char NTC_TABLE[10];
  889. unsigned int valR, valV, over_cri_low, ntc_table;
  890. };
  891. /* external pin: 0/1/12/13/14/15, can't use pin:2/3/4/5/6/7/8/9/10/11,
  892. choose "adc_channel=11" to check if there is any param input */
  893. unsigned int adc_channel = 11;
  894. struct param_data *ptr_param_data = kmalloc(sizeof(*ptr_param_data), GFP_KERNEL);
  895. if (ptr_param_data == NULL)
  896. return -ENOMEM;
  897. len = (count < (sizeof(ptr_param_data->desc) - 1)) ? count : (sizeof(ptr_param_data->desc) - 1);
  898. if (copy_from_user(ptr_param_data->desc, buffer, len)) {
  899. kfree(ptr_param_data);
  900. return 0;
  901. }
  902. ptr_param_data->desc[len] = '\0';
  903. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_write]\n");
  904. if (sscanf
  905. (ptr_param_data->desc, "%s %d %s %d %s %d %s %d %d", ptr_param_data->pull_R, &ptr_param_data->valR,
  906. ptr_param_data->pull_V, &ptr_param_data->valV, ptr_param_data->overcrilow,
  907. &ptr_param_data->over_cri_low, ptr_param_data->NTC_TABLE,
  908. &ptr_param_data->ntc_table, &adc_channel) >= 8) {
  909. if (!strcmp(ptr_param_data->pull_R, "PUP_R")) {
  910. g_RAP_pull_up_R = ptr_param_data->valR;
  911. mtkts_btsmdpa_dprintk("g_RAP_pull_up_R=%d\n", g_RAP_pull_up_R);
  912. } else {
  913. kfree(ptr_param_data);
  914. pr_debug("[mtkts_btsmdpa_write] bad PUP_R argument\n");
  915. return -EINVAL;
  916. }
  917. if (!strcmp(ptr_param_data->pull_V, "PUP_VOLT")) {
  918. g_RAP_pull_up_voltage = ptr_param_data->valV;
  919. mtkts_btsmdpa_dprintk("g_Rat_pull_up_voltage=%d\n", g_RAP_pull_up_voltage);
  920. } else {
  921. kfree(ptr_param_data);
  922. pr_debug("[mtkts_btsmdpa_write] bad PUP_VOLT argument\n");
  923. return -EINVAL;
  924. }
  925. if (!strcmp(ptr_param_data->overcrilow, "OVER_CRITICAL_L")) {
  926. g_TAP_over_critical_low = ptr_param_data->over_cri_low;
  927. mtkts_btsmdpa_dprintk("g_TAP_over_critical_low=%d\n",
  928. g_TAP_over_critical_low);
  929. } else {
  930. kfree(ptr_param_data);
  931. pr_debug("[mtkts_btsmdpa_write] bad OVERCRIT_L argument\n");
  932. return -EINVAL;
  933. }
  934. if (!strcmp(ptr_param_data->NTC_TABLE, "NTC_TABLE")) {
  935. g_RAP_ntc_table = ptr_param_data->ntc_table;
  936. mtkts_btsmdpa_dprintk("g_RAP_ntc_table=%d\n", g_RAP_ntc_table);
  937. } else {
  938. kfree(ptr_param_data);
  939. pr_debug("[mtkts_btsmdpa_write] bad NTC_TABLE argument\n");
  940. return -EINVAL;
  941. }
  942. /* external pin: 0/1/12/13/14/15, can't use pin:2/3/4/5/6/7/8/9/10/11,
  943. choose "adc_channel=11" to check if there is any param input */
  944. if ((adc_channel >= 2) && (adc_channel <= 11))
  945. /* check unsupport pin value, if unsupport, set channel = 1 as default setting. */
  946. g_RAP_ADC_channel = AUX_IN1_NTC;
  947. else {
  948. g_RAP_ADC_channel = adc_channel;
  949. }
  950. mtkts_btsmdpa_dprintk("adc_channel=%d\n", adc_channel);
  951. mtkts_btsmdpa_dprintk("g_RAP_ADC_channel=%d\n", g_RAP_ADC_channel);
  952. mtkts_btsmdpa_prepare_table(g_RAP_ntc_table);
  953. kfree(ptr_param_data);
  954. return count;
  955. }
  956. pr_debug("[mtkts_btsmdpa_write] bad argument\n");
  957. kfree(ptr_param_data);
  958. return -EINVAL;
  959. }
  960. /* int mtkts_btsmdpa_register_cooler(void) */
  961. /* { */
  962. /* cooling devices */
  963. /* cl_dev_sysrst = mtk_thermal_cooling_device_register("mtktsbtsmdpatery-sysrst", NULL, */
  964. /* &mtkts_btsmdpa_cooling_sysrst_ops); */
  965. /* return 0; */
  966. /* } */
  967. void mtkts_btsmdpa_cancel_thermal_timer(void)
  968. {
  969. /* cancel timer */
  970. /* pr_debug("mtkts_btsmdpa_cancel_thermal_timer\n"); */
  971. /* stop thermal framework polling when entering deep idle */
  972. /* if (thz_dev)
  973. cancel_delayed_work(&(thz_dev->poll_queue)); */
  974. }
  975. void mtkts_btsmdpa_start_thermal_timer(void)
  976. {
  977. /* pr_debug("mtkts_btsmdpa_start_thermal_timer\n"); */
  978. /* resume thermal framework polling when leaving deep idle */
  979. /* if (thz_dev != NULL && interval != 0)
  980. mod_delayed_work(system_freezable_wq, &(thz_dev->poll_queue), round_jiffies(msecs_to_jiffies(3000)));*/
  981. }
  982. static int mtkts_btsmdpa_register_thermal(void)
  983. {
  984. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_register_thermal]\n");
  985. /* trips : trip 0~1 */
  986. thz_dev = mtk_thermal_zone_device_register("mtktsbtsmdpa", num_trip, NULL,
  987. &mtkts_btsmdpa_dev_ops, 0, 0, 0,
  988. interval * 1000);
  989. return 0;
  990. }
  991. /* void mtkts_btsmdpa_unregister_cooler(void) */
  992. /* { */
  993. /* if (cl_dev_sysrst) { */
  994. /* mtk_thermal_cooling_device_unregister(cl_dev_sysrst); */
  995. /* cl_dev_sysrst = NULL; */
  996. /* } */
  997. /* } */
  998. static void mtkts_btsmdpa_unregister_thermal(void)
  999. {
  1000. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_unregister_thermal]\n");
  1001. if (thz_dev) {
  1002. mtk_thermal_zone_device_unregister(thz_dev);
  1003. thz_dev = NULL;
  1004. }
  1005. }
  1006. static int mtkts_btsmdpa_open(struct inode *inode, struct file *file)
  1007. {
  1008. return single_open(file, mtkts_btsmdpa_read, NULL);
  1009. }
  1010. static const struct file_operations mtkts_btsmdpa_fops = {
  1011. .owner = THIS_MODULE,
  1012. .open = mtkts_btsmdpa_open,
  1013. .read = seq_read,
  1014. .llseek = seq_lseek,
  1015. .write = mtkts_btsmdpa_write,
  1016. .release = single_release,
  1017. };
  1018. static int mtkts_btsmdpa_param_open(struct inode *inode, struct file *file)
  1019. {
  1020. return single_open(file, mtkts_btsmdpa_param_read, NULL);
  1021. }
  1022. static const struct file_operations mtkts_btsmdpa_param_fops = {
  1023. .owner = THIS_MODULE,
  1024. .open = mtkts_btsmdpa_param_open,
  1025. .read = seq_read,
  1026. .llseek = seq_lseek,
  1027. .write = mtkts_btsmdpa_param_write,
  1028. .release = single_release,
  1029. };
  1030. static int __init mtkts_btsmdpa_init(void)
  1031. {
  1032. struct proc_dir_entry *entry = NULL;
  1033. struct proc_dir_entry *mtkts_btsmdpa_dir = NULL;
  1034. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_init]\n");
  1035. /* setup default table */
  1036. mtkts_btsmdpa_prepare_table(g_RAP_ntc_table);
  1037. mtkts_btsmdpa_dir = mtk_thermal_get_proc_drv_therm_dir_entry();
  1038. if (!mtkts_btsmdpa_dir) {
  1039. mtkts_btsmdpa_dprintk("[%s]: mkdir /proc/driver/thermal failed\n", __func__);
  1040. } else {
  1041. entry =
  1042. proc_create("tzbtspa", S_IRUGO | S_IWUSR | S_IWGRP, mtkts_btsmdpa_dir,
  1043. &mtkts_btsmdpa_fops);
  1044. if (entry)
  1045. proc_set_user(entry, uid, gid);
  1046. entry =
  1047. proc_create("tzbtspa_param", S_IRUGO | S_IWUSR | S_IWGRP, mtkts_btsmdpa_dir,
  1048. &mtkts_btsmdpa_param_fops);
  1049. if (entry)
  1050. proc_set_user(entry, uid, gid);
  1051. }
  1052. return 0;
  1053. }
  1054. static void __exit mtkts_btsmdpa_exit(void)
  1055. {
  1056. mtkts_btsmdpa_dprintk("[mtkts_btsmdpa_exit]\n");
  1057. mtkts_btsmdpa_unregister_thermal();
  1058. /* mtkts_btsmdpa_unregister_cooler(); */
  1059. }
  1060. module_init(mtkts_btsmdpa_init);
  1061. module_exit(mtkts_btsmdpa_exit);