mt_auxadc.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  1. /*
  2. * Copyright (C) 2015 MediaTek Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. /*****************************************************************************
  14. *
  15. * Filename:
  16. * ---------
  17. * mt_auxadc.c
  18. *
  19. * Project:
  20. * --------
  21. * Android_Software
  22. *
  23. * Description:
  24. * ------------
  25. * This Module defines functions of AUXADC common code
  26. *
  27. * Author:
  28. * -------
  29. * Zhong Wang
  30. *
  31. ****************************************************************************/
  32. #include <linux/init.h> /* For init/exit macros */
  33. #include <linux/module.h> /* For MODULE_ marcros */
  34. #include <linux/fs.h>
  35. #include <linux/device.h>
  36. #include <linux/interrupt.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/platform_device.h>
  39. #include <linux/device.h>
  40. #include <linux/kdev_t.h>
  41. #include <linux/fs.h>
  42. #include <linux/cdev.h>
  43. #include <linux/delay.h>
  44. #include <linux/kernel.h>
  45. #include <linux/types.h>
  46. #include <linux/slab.h>
  47. #include <linux/sched.h>
  48. #include <linux/proc_fs.h>
  49. #include <linux/kthread.h>
  50. #include <asm/uaccess.h>
  51. #include <asm/io.h>
  52. #include <asm/irq.h>
  53. #include <mt-plat/sync_write.h>
  54. #include "mt_auxadc.h"
  55. #include "mt_auxadc_hw.h"
  56. #ifdef CONFIG_OF
  57. #include <linux/of.h>
  58. #include <linux/of_address.h>
  59. #endif
  60. #if !defined(CONFIG_MTK_CLKMGR)
  61. #ifdef CONFIG_OF
  62. static struct clk *clk_auxadc;
  63. #endif
  64. #endif
  65. #ifdef CONFIG_OF
  66. void __iomem *auxadc_base = NULL;
  67. void __iomem *auxadc_apmix_base = NULL;
  68. #if defined(EFUSE_CALI)
  69. void __iomem *auxadc_efuse_base = NULL;
  70. #endif
  71. #endif
  72. #if !defined(CONFIG_MTK_CLKMGR)
  73. #include <linux/clk.h>
  74. #else
  75. /*#include <cust_adc.h>*/ /* generate by DCT Tool */
  76. #include <mach/mt_clkmgr.h>
  77. #endif
  78. typedef unsigned short UINT16;
  79. #define READ_REGISTER_UINT16(reg) (*(volatile UINT16 * const)(reg))
  80. #define INREG16(x) READ_REGISTER_UINT16((UINT16 *)((void *)(x)))
  81. #define DRV_Reg16(addr) INREG16(addr)
  82. #define DRV_Reg(addr) DRV_Reg16(addr)
  83. /******************************************************/
  84. #define DRV_ClearBits(addr, data) {\
  85. unsigned short temp;\
  86. temp = DRV_Reg16(addr);\
  87. temp &= ~(data);\
  88. mt_reg_sync_writew(temp, addr);\
  89. }
  90. #define DRV_SetBits(addr, data) {\
  91. unsigned short temp;\
  92. temp = DRV_Reg16(addr);\
  93. temp |= (data);\
  94. mt_reg_sync_writew(temp, addr);\
  95. }
  96. #define DRV_SetData(addr, bitmask, value) {\
  97. unsigned short temp;\
  98. temp = (~(bitmask)) & DRV_Reg16(addr);\
  99. temp |= (value);\
  100. mt_reg_sync_writew(temp, addr);\
  101. }
  102. #define AUXADC_DRV_ClearBits16(addr, data) DRV_ClearBits(addr, data)
  103. #define AUXADC_DRV_SetBits16(addr, data) DRV_SetBits(addr, data)
  104. #define AUXADC_DRV_WriteReg16(addr, data) mt_reg_sync_writew(data, addr)
  105. #define AUXADC_DRV_ReadReg16(addr) DRV_Reg(addr)
  106. #define AUXADC_DRV_SetData16(addr, bitmask, value) DRV_SetData(addr, bitmask, value)
  107. #define AUXADC_CLR_BITS(BS, REG) {\
  108. unsigned int temp;\
  109. temp = DRV_Reg32(REG);\
  110. temp &= ~(BS);\
  111. mt_reg_sync_writel(temp, REG);\
  112. }
  113. #define AUXADC_SET_BITS(BS, REG) {\
  114. unsigned int temp;\
  115. temp = DRV_Reg32(REG);\
  116. temp |= (BS);\
  117. mt_reg_sync_writel(temp, REG);\
  118. }
  119. #define VOLTAGE_FULL_RANGE 1500 /* VA voltage */
  120. #define AUXADC_PRECISE 4096 /* 12 bits */
  121. /******************************************************/
  122. /*****************************************************************************
  123. * Integrate with NVRAM
  124. ****************************************************************************/
  125. #define AUXADC_CALI_DEVNAME "mtk-adc-cali"
  126. #define TEST_ADC_CALI_PRINT _IO('k', 0)
  127. #define SET_ADC_CALI_Slop _IOW('k', 1, int)
  128. #define SET_ADC_CALI_Offset _IOW('k', 2, int)
  129. #define SET_ADC_CALI_Cal _IOW('k', 3, int)
  130. #define ADC_CHANNEL_READ _IOW('k', 4, int)
  131. typedef struct adc_info {
  132. char channel_name[64];
  133. int channel_number;
  134. int reserve1;
  135. int reserve2;
  136. int reserve3;
  137. } ADC_INFO;
  138. static ADC_INFO g_adc_info[ADC_CHANNEL_MAX];
  139. static int auxadc_cali_slop[ADC_CHANNEL_MAX] = { 0 };
  140. static int auxadc_cali_offset[ADC_CHANNEL_MAX] = { 0 };
  141. static bool g_AUXADC_Cali;
  142. static int auxadc_cali_cal[1] = { 0 };
  143. static int auxadc_in_data[2] = { 1, 1 };
  144. static int auxadc_out_data[2] = { 1, 1 };
  145. static DEFINE_MUTEX(auxadc_mutex);
  146. static DEFINE_MUTEX(mutex_get_cali_value);
  147. static int adc_auto_set;
  148. #if !defined(CONFIG_AUXADC_NOT_CONTROL_APMIXED_BASE)
  149. static int adc_rtp_set = 1;
  150. #endif
  151. static dev_t auxadc_cali_devno;
  152. static int auxadc_cali_major;
  153. static struct cdev *auxadc_cali_cdev;
  154. static struct class *auxadc_cali_class;
  155. static struct task_struct *thread;
  156. static int g_start_debug_thread;
  157. static int g_adc_init_flag;
  158. static u32 cali_reg;
  159. static u32 cali_oe;
  160. static u32 cali_ge;
  161. static u32 cali_ge_a;
  162. static u32 cali_oe_a;
  163. static u32 gain;
  164. static void mt_auxadc_update_cali(void)
  165. {
  166. cali_oe = 0;
  167. cali_ge = 0;
  168. #if defined(EFUSE_CALI)
  169. cali_reg = (*(volatile unsigned int *const)(ADC_CALI_EN_A_REG));
  170. if (((cali_reg & ADC_CALI_EN_A_MASK) >> ADC_CALI_EN_A_SHIFT) != 0) {
  171. cali_oe_a = (cali_reg & ADC_OE_A_MASK) >> ADC_OE_A_SHIFT;
  172. cali_ge_a = ((cali_reg & ADC_GE_A_MASK) >> ADC_GE_A_SHIFT);
  173. cali_ge = cali_ge_a - 512;
  174. cali_oe = cali_oe_a - 512;
  175. gain = 1 + cali_ge;
  176. }
  177. /*pr_debug("[AUXADC] cali_reg=%x,cali_oe_a(%x), cali_ge_a(%x),cali_ge(%x),cali_oe(%x),gain(%x)\n",
  178. cali_reg, cali_oe_a, cali_ge_a, cali_ge, cali_oe, gain);*/
  179. #endif
  180. }
  181. static void mt_auxadc_get_cali_data(unsigned int rawdata, int data[4], bool enable_cali)
  182. {
  183. if (enable_cali == true) {
  184. #if defined(EFUSE_CALI)
  185. rawdata = rawdata - cali_oe;
  186. data[0] = (rawdata * 1500 / (4096 + cali_ge)) / 1000; /* convert to volt */
  187. data[1] = (rawdata * 150 / (4096 + cali_ge)) % 100; /* convert to mv, need multiply 10 */
  188. data[2] = (rawdata * 1500 / (4096 + cali_ge)) % 1000; /* data[2] provide high precision mv */
  189. #else
  190. data[0] = (rawdata * 150 / AUXADC_PRECISE / 100);
  191. data[1] = ((rawdata * 150 / AUXADC_PRECISE) % 100);
  192. data[2] = ((rawdata * 1500 / AUXADC_PRECISE) % 1000);
  193. #endif
  194. } else {
  195. data[0] = (rawdata * 150 / AUXADC_PRECISE / 100);
  196. data[1] = ((rawdata * 150 / AUXADC_PRECISE) % 100);
  197. data[2] = ((rawdata * 1500 / AUXADC_PRECISE) % 1000);
  198. }
  199. }
  200. #if defined(CONFIG_AUXADC_NOT_CONTROL_APMIXED_BASE)
  201. static void mt_auxadc_disable_penirq(void)
  202. {
  203. }
  204. #else
  205. static u16 mt_tpd_read_adc(u16 pos)
  206. {
  207. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_TP_ADDR, pos);
  208. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_TP_CON0, 0x01);
  209. while (0x01 & AUXADC_DRV_ReadReg16((volatile u16 *)AUXADC_TP_CON0))
  210. pr_debug("AUXADC_TP_CON0 waiting.\n"); /* wait for write finish */
  211. return AUXADC_DRV_ReadReg16((volatile u16 *)AUXADC_TP_DATA0);
  212. }
  213. static void mt_auxadc_disable_penirq(void)
  214. {
  215. if (adc_rtp_set) {
  216. adc_rtp_set = 0;
  217. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_CON_RTP, 1);
  218. /* Turn off PENIRQ detection circuit */
  219. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_TP_CMD, 1);
  220. /* run once touch function */
  221. mt_tpd_read_adc(TP_CMD_ADDR_X);
  222. }
  223. }
  224. #endif
  225. /* HAL API */
  226. static int IMM_auxadc_GetOneChannelValue(int dwChannel, int data[4], int *rawdata)
  227. {
  228. unsigned int channel[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  229. int idle_count = 0;
  230. int data_ready_count = 0;
  231. int ret = 0;
  232. mutex_lock(&mutex_get_cali_value);
  233. #if !defined(CONFIG_MTK_CLKMGR)
  234. if (clk_auxadc) {
  235. ret = clk_prepare_enable(clk_auxadc);
  236. if (ret) {
  237. pr_err("hwEnableClock AUXADC failed.");
  238. mutex_unlock(&mutex_get_cali_value);
  239. return -1;
  240. }
  241. } else {
  242. pr_err("hwEnableClock AUXADC failed.");
  243. mutex_unlock(&mutex_get_cali_value);
  244. return -1;
  245. }
  246. #else
  247. #ifndef CONFIG_MTK_FPGA
  248. if (enable_clock(MT_PDN_PERI_AUXADC, "AUXADC")) {
  249. pr_err("hwEnableClock AUXADC failed.");
  250. mutex_unlock(&mutex_get_cali_value);
  251. return -1;
  252. }
  253. #endif
  254. #endif
  255. mt_auxadc_update_cali();
  256. if (dwChannel == PAD_AUX_XP || dwChannel == PAD_AUX_YM)
  257. mt_auxadc_disable_penirq();
  258. /* step1 check con2 if auxadc is busy */
  259. while (AUXADC_DRV_ReadReg16((volatile u16 *)AUXADC_CON2) & 0x01) {
  260. pr_debug("[adc_api]: wait for module idle\n");
  261. mdelay(1);
  262. idle_count++;
  263. if (idle_count > 30) {
  264. /* wait for idle time out */
  265. pr_err("[adc_api]: wait for auxadc idle time out\n");
  266. mutex_unlock(&mutex_get_cali_value);
  267. return -1;
  268. }
  269. }
  270. /* step2 clear bit */
  271. if (0 == adc_auto_set) {
  272. /* clear bit */
  273. AUXADC_DRV_ClearBits16((volatile u16 *)AUXADC_CON1, (1 << dwChannel));
  274. }
  275. /* step3 read channel and make sure old ready bit ==0 */
  276. while (AUXADC_DRV_ReadReg16(AUXADC_DAT0 + dwChannel * 0x04) & (1 << 12)) {
  277. pr_debug("[adc_api]: wait for channel[%d] ready bit clear\n", dwChannel);
  278. mdelay(1);
  279. data_ready_count++;
  280. if (data_ready_count > 30) {
  281. /* wait for idle time out */
  282. pr_err("[adc_api]: wait for channel[%d] ready bit clear time out\n",
  283. dwChannel);
  284. mutex_unlock(&mutex_get_cali_value);
  285. return -2;
  286. }
  287. }
  288. /* step4 set bit to trigger sample */
  289. if (0 == adc_auto_set)
  290. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_CON1, (1 << dwChannel));
  291. /* step5 read channel and make sure ready bit ==1 */
  292. udelay(25); /* we must dealay here for hw sample cahnnel data */
  293. while (0 == (AUXADC_DRV_ReadReg16(AUXADC_DAT0 + dwChannel * 0x04) & (1 << 12))) {
  294. pr_debug("[adc_api]: wait for channel[%d] ready bit ==1\n", dwChannel);
  295. mdelay(1);
  296. data_ready_count++;
  297. if (data_ready_count > 30) {
  298. /* wait for idle time out */
  299. pr_err("[adc_api]: wait for channel[%d] data ready time out\n", dwChannel);
  300. mutex_unlock(&mutex_get_cali_value);
  301. return -3;
  302. }
  303. }
  304. /* step6 read data */
  305. channel[dwChannel] = AUXADC_DRV_ReadReg16(AUXADC_DAT0 + dwChannel * 0x04) & 0x0FFF;
  306. if (NULL != rawdata)
  307. *rawdata = channel[dwChannel];
  308. mt_auxadc_get_cali_data(channel[dwChannel], data, true);
  309. #if !defined(CONFIG_MTK_CLKMGR)
  310. if (clk_auxadc) {
  311. clk_disable_unprepare(clk_auxadc);
  312. } else {
  313. pr_err("hwdisableClock AUXADC failed.");
  314. mutex_unlock(&mutex_get_cali_value);
  315. return -1;
  316. }
  317. #else
  318. #ifndef CONFIG_MTK_FPGA
  319. if (disable_clock(MT_PDN_PERI_AUXADC, "AUXADC")) {
  320. pr_err("hwdisableClock AUXADC failed.");
  321. mutex_unlock(&mutex_get_cali_value);
  322. return -1;
  323. }
  324. #endif
  325. #endif
  326. mutex_unlock(&mutex_get_cali_value);
  327. return ret;
  328. }
  329. /* 1v == 1000000 uv */
  330. /* this function voltage Unit is uv */
  331. static int IMM_auxadc_GetOneChannelValue_Cali(int Channel, int *voltage)
  332. {
  333. int ret = 0, data[4], rawvalue;
  334. u_int64_t temp_vol;
  335. ret = IMM_auxadc_GetOneChannelValue(Channel, data, &rawvalue);
  336. if (ret) {
  337. pr_err("[adc_api]:IMM_auxadc_GetOneChannelValue_Cali get raw value error %d\n",
  338. ret);
  339. return -1;
  340. }
  341. temp_vol = (u_int64_t) rawvalue * 1500000 / AUXADC_PRECISE;
  342. *voltage = temp_vol;
  343. /* pr_debug("[adc_api]:IMM_auxadc_GetOneChannelValue_Cali voltage= %d uv\n",*voltage); */
  344. return 0;
  345. }
  346. static void mt_auxadc_cal_prepare(void)
  347. {
  348. /* no voltage calibration */
  349. }
  350. #if defined(CONFIG_AUXADC_NEED_POWER_ON)
  351. static void mt_auxadc_power_on(void)
  352. {
  353. AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_MISC, 1 << 14); /* power on ADC */
  354. }
  355. #else
  356. static void mt_auxadc_power_on(void)
  357. {
  358. }
  359. #endif
  360. void mt_auxadc_hal_init(struct platform_device *dev)
  361. {
  362. #ifdef CONFIG_OF
  363. struct device_node *node;
  364. node = of_find_compatible_node(NULL, NULL, "mediatek,APMIXED");
  365. if (node) {
  366. /* Setup IO addresses */
  367. auxadc_apmix_base = of_iomap(node, 0);
  368. pr_debug("[AUXADC] auxadc auxadc_apmix_base=0x%p\n", auxadc_apmix_base);
  369. } else
  370. pr_err("[AUXADC] auxadc_apmix_base error\n");
  371. node = of_find_compatible_node(NULL, NULL, AUXADC_NODE);
  372. if (!node)
  373. pr_err("[AUXADC] find node failed\n");
  374. auxadc_base = of_iomap(node, 0);
  375. if (!auxadc_base)
  376. pr_err("[AUXADC] base failed\n");
  377. #if defined(EFUSE_CALI)
  378. node = of_find_compatible_node(NULL, NULL, "mediatek,EFUSEC");
  379. if (!node)
  380. pr_debug("[AUXADC] find node failed\n");
  381. auxadc_efuse_base = of_iomap(node, 0);
  382. if (!auxadc_efuse_base)
  383. pr_debug("[AUXADC] auxadc_efuse_base base failed\n");
  384. pr_debug("[AUXADC]: auxadc_efuse_base:0x%p\n", auxadc_efuse_base);
  385. #endif
  386. pr_debug("[AUXADC]: auxadc:0x%p\n", auxadc_base);
  387. #endif
  388. mt_auxadc_cal_prepare();
  389. mt_auxadc_power_on();
  390. /* AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_CON_RTP, 1); //disable RTP */
  391. }
  392. static void mt_auxadc_hal_suspend(void)
  393. {
  394. pr_debug("******** MT auxadc driver suspend!! ********\n");
  395. #if !defined(AUXADC_CLOCK_BY_SPM)
  396. #if !defined(CONFIG_MTK_CLKMGR)
  397. if (clk_auxadc)
  398. clk_disable_unprepare(clk_auxadc);
  399. #else
  400. #ifndef CONFIG_MTK_FPGA
  401. if (disable_clock(MT_PDN_PERI_AUXADC, "AUXADC"))
  402. pr_err("hwEnableClock AUXADC failed.");
  403. #endif
  404. #endif
  405. #endif
  406. }
  407. static void mt_auxadc_hal_resume(void)
  408. {
  409. pr_debug("******** MT auxadc driver resume!! ********\n");
  410. #if !defined(AUXADC_CLOCK_BY_SPM)
  411. #if !defined(CONFIG_MTK_CLKMGR)
  412. if (clk_auxadc)
  413. clk_prepare_enable(clk_auxadc);
  414. #else
  415. #ifndef CONFIG_MTK_FPGA
  416. if (enable_clock(MT_PDN_PERI_AUXADC, "AUXADC"))
  417. pr_err("hwEnableClock AUXADC failed!!!.");
  418. #endif
  419. #endif
  420. #endif
  421. mt_auxadc_power_on();
  422. /* AUXADC_DRV_SetBits16((volatile u16 *)AUXADC_CON_RTP, 1); //disable RTP */
  423. }
  424. static int mt_auxadc_dump_register(char *buf)
  425. {
  426. pr_debug("[auxadc]: AUXADC_CON0=%x\n", *(volatile u16 *)AUXADC_CON0);
  427. pr_debug("[auxadc]: AUXADC_CON1=%x\n", *(volatile u16 *)AUXADC_CON1);
  428. pr_debug("[auxadc]: AUXADC_CON2=%x\n", *(volatile u16 *)AUXADC_CON2);
  429. return sprintf(buf, "AUXADC_CON0:%x\n AUXADC_CON1:%x\n AUXADC_CON2:%x\n",
  430. *(volatile u16 *)AUXADC_CON0, *(volatile u16 *)AUXADC_CON1,
  431. *(volatile u16 *)AUXADC_CON2);
  432. }
  433. /* */
  434. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  435. /* // fop Common API */
  436. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  437. int IMM_IsAdcInitReady(void)
  438. {
  439. return g_adc_init_flag;
  440. }
  441. int IMM_get_adc_channel_num(char *channel_name, int len)
  442. {
  443. unsigned int i;
  444. pr_debug("[ADC] name = %s\n", channel_name);
  445. pr_debug("[ADC] name_len = %d\n", len);
  446. for (i = 0; i < ADC_CHANNEL_MAX; i++) {
  447. if (!strncmp(channel_name, g_adc_info[i].channel_name, len))
  448. return g_adc_info[i].channel_number;
  449. }
  450. pr_err("[ADC] find channel number failed\n");
  451. return -1;
  452. }
  453. int IMM_GetOneChannelValue(int dwChannel, int data[4], int *rawdata)
  454. {
  455. return IMM_auxadc_GetOneChannelValue(dwChannel, data, rawdata);
  456. }
  457. /* 1v == 1000000 uv */
  458. /* this function voltage Unit is uv */
  459. int IMM_GetOneChannelValue_Cali(int Channel, int *voltage)
  460. {
  461. return IMM_auxadc_GetOneChannelValue_Cali(Channel, voltage);
  462. }
  463. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  464. /* // fop API */
  465. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  466. static long auxadc_cali_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  467. {
  468. int i = 0, ret = 0;
  469. long *user_data_addr;
  470. long *nvram_data_addr;
  471. mutex_lock(&auxadc_mutex);
  472. switch (cmd) {
  473. case TEST_ADC_CALI_PRINT:
  474. g_AUXADC_Cali = false;
  475. break;
  476. case SET_ADC_CALI_Slop:
  477. nvram_data_addr = (long *)arg;
  478. ret = copy_from_user(auxadc_cali_slop, nvram_data_addr, 36);
  479. g_AUXADC_Cali = false;
  480. /* Protection */
  481. for (i = 0; i < ADC_CHANNEL_MAX; i++) {
  482. if ((*(auxadc_cali_slop + i) == 0) || (*(auxadc_cali_slop + i) == 1))
  483. *(auxadc_cali_slop + i) = 1000;
  484. }
  485. for (i = 0; i < ADC_CHANNEL_MAX; i++)
  486. pr_debug("auxadc_cali_slop[%d] = %d\n", i, *(auxadc_cali_slop + i));
  487. pr_debug("**** MT auxadc_cali ioctl : SET_ADC_CALI_Slop Done!\n");
  488. break;
  489. case SET_ADC_CALI_Offset:
  490. nvram_data_addr = (long *)arg;
  491. ret = copy_from_user(auxadc_cali_offset, nvram_data_addr, 36);
  492. g_AUXADC_Cali = false;
  493. for (i = 0; i < ADC_CHANNEL_MAX; i++)
  494. pr_debug("auxadc_cali_offset[%d] = %d\n", i, *(auxadc_cali_offset + i));
  495. pr_debug("**** MT auxadc_cali ioctl : SET_ADC_CALI_Offset Done!\n");
  496. break;
  497. case SET_ADC_CALI_Cal:
  498. nvram_data_addr = (long *)arg;
  499. ret = copy_from_user(auxadc_cali_cal, nvram_data_addr, 4);
  500. g_AUXADC_Cali = true; /* enable calibration after setting AUXADC_CALI_Cal */
  501. if (auxadc_cali_cal[0] == 1)
  502. g_AUXADC_Cali = true;
  503. else
  504. g_AUXADC_Cali = false;
  505. for (i = 0; i < 1; i++)
  506. pr_debug("auxadc_cali_cal[%d] = %d\n", i, *(auxadc_cali_cal + i));
  507. pr_debug("**** MT auxadc_cali ioctl : SET_ADC_CALI_Cal Done!\n");
  508. break;
  509. case ADC_CHANNEL_READ:
  510. g_AUXADC_Cali = false; /* 20100508 Infinity */
  511. user_data_addr = (long *)arg;
  512. ret = copy_from_user(auxadc_in_data, user_data_addr, 8); /* 2*int = 2*4 */
  513. pr_debug("this api is removed !!\n");
  514. ret = copy_to_user(user_data_addr, auxadc_out_data, 8);
  515. pr_debug("**** ioctl : AUXADC Channel %d * %d times = %d\n", auxadc_in_data[0],
  516. auxadc_in_data[1], auxadc_out_data[0]);
  517. break;
  518. default:
  519. g_AUXADC_Cali = false;
  520. break;
  521. }
  522. mutex_unlock(&auxadc_mutex);
  523. return 0;
  524. }
  525. #ifdef CONFIG_COMPAT
  526. static long compat_auxadc_unlocked_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  527. {
  528. if (!filp->f_op || !filp->f_op->unlocked_ioctl) {
  529. pr_err("compat_ion_ioctl file has no f_op or no f_op->unlocked_ioctl.\n");
  530. return -ENOTTY;
  531. }
  532. switch (cmd) {
  533. case TEST_ADC_CALI_PRINT:
  534. case SET_ADC_CALI_Slop:
  535. case SET_ADC_CALI_Offset:
  536. case SET_ADC_CALI_Cal:
  537. case ADC_CHANNEL_READ:
  538. return filp->f_op->unlocked_ioctl(filp, cmd,
  539. (unsigned long)compat_ptr(arg));
  540. default:
  541. pr_err("compat_ion_ioctl : No such command!! 0x%x\n", cmd);
  542. return -ENOIOCTLCMD;
  543. }
  544. }
  545. #endif
  546. static int auxadc_cali_open(struct inode *inode, struct file *file)
  547. {
  548. return 0;
  549. }
  550. static int auxadc_cali_release(struct inode *inode, struct file *file)
  551. {
  552. return 0;
  553. }
  554. static const struct file_operations auxadc_cali_fops = {
  555. .owner = THIS_MODULE,
  556. .unlocked_ioctl = auxadc_cali_unlocked_ioctl,
  557. .open = auxadc_cali_open,
  558. .release = auxadc_cali_release,
  559. #if IS_ENABLED(CONFIG_COMPAT)
  560. .compat_ioctl = compat_auxadc_unlocked_ioctl,
  561. #endif
  562. };
  563. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  564. /* // Create File For EM : AUXADC_Channel_X_Slope/Offset */
  565. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  566. #if ADC_CHANNEL_MAX > 0
  567. static ssize_t show_AUXADC_Channel_0_Slope(struct device *dev, struct device_attribute *attr,
  568. char *buf)
  569. {
  570. int ret_value = 1;
  571. ret_value = (*(auxadc_cali_slop + 0));
  572. pr_debug("[EM] AUXADC_Channel_0_Slope : %d\n", ret_value);
  573. return sprintf(buf, "%u\n", ret_value);
  574. }
  575. static ssize_t store_AUXADC_Channel_0_Slope(struct device *dev, struct device_attribute *attr,
  576. const char *buf, size_t size)
  577. {
  578. pr_debug("[EM] Not Support Write Function\n");
  579. return size;
  580. }
  581. static DEVICE_ATTR(AUXADC_Channel_0_Slope, 0664, show_AUXADC_Channel_0_Slope,
  582. store_AUXADC_Channel_0_Slope);
  583. static ssize_t show_AUXADC_Channel_0_Offset(struct device *dev, struct device_attribute *attr,
  584. char *buf)
  585. {
  586. int ret_value = 1;
  587. ret_value = (*(auxadc_cali_offset + 0));
  588. pr_debug("[EM] AUXADC_Channel_0_Offset : %d\n", ret_value);
  589. return sprintf(buf, "%u\n", ret_value);
  590. }
  591. static ssize_t store_AUXADC_Channel_0_Offset(struct device *dev, struct device_attribute *attr,
  592. const char *buf, size_t size)
  593. {
  594. pr_debug("[EM] Not Support Write Function\n");
  595. return size;
  596. }
  597. static DEVICE_ATTR(AUXADC_Channel_0_Offset, 0664, show_AUXADC_Channel_0_Offset,
  598. store_AUXADC_Channel_0_Offset);
  599. #endif
  600. #if ADC_CHANNEL_MAX > 1
  601. static ssize_t show_AUXADC_Channel_1_Slope(struct device *dev, struct device_attribute *attr,
  602. char *buf)
  603. {
  604. int ret_value = 1;
  605. ret_value = (*(auxadc_cali_slop + 1));
  606. pr_debug("[EM] AUXADC_Channel_1_Slope : %d\n", ret_value);
  607. return sprintf(buf, "%u\n", ret_value);
  608. }
  609. static ssize_t store_AUXADC_Channel_1_Slope(struct device *dev, struct device_attribute *attr,
  610. const char *buf, size_t size)
  611. {
  612. pr_debug("[EM] Not Support Write Function\n");
  613. return size;
  614. }
  615. static DEVICE_ATTR(AUXADC_Channel_1_Slope, 0664, show_AUXADC_Channel_1_Slope,
  616. store_AUXADC_Channel_1_Slope);
  617. static ssize_t show_AUXADC_Channel_1_Offset(struct device *dev, struct device_attribute *attr,
  618. char *buf)
  619. {
  620. int ret_value = 1;
  621. ret_value = (*(auxadc_cali_offset + 1));
  622. pr_debug("[EM] AUXADC_Channel_1_Offset : %d\n", ret_value);
  623. return sprintf(buf, "%u\n", ret_value);
  624. }
  625. static ssize_t store_AUXADC_Channel_1_Offset(struct device *dev, struct device_attribute *attr,
  626. const char *buf, size_t size)
  627. {
  628. pr_debug("[EM] Not Support Write Function\n");
  629. return size;
  630. }
  631. static DEVICE_ATTR(AUXADC_Channel_1_Offset, 0664, show_AUXADC_Channel_1_Offset,
  632. store_AUXADC_Channel_1_Offset);
  633. #endif
  634. #if ADC_CHANNEL_MAX > 2
  635. static ssize_t show_AUXADC_Channel_2_Slope(struct device *dev, struct device_attribute *attr,
  636. char *buf)
  637. {
  638. int ret_value = 1;
  639. ret_value = (*(auxadc_cali_slop + 2));
  640. pr_debug("[EM] AUXADC_Channel_2_Slope : %d\n", ret_value);
  641. return sprintf(buf, "%u\n", ret_value);
  642. }
  643. static ssize_t store_AUXADC_Channel_2_Slope(struct device *dev, struct device_attribute *attr,
  644. const char *buf, size_t size)
  645. {
  646. pr_debug("[EM] Not Support Write Function\n");
  647. return size;
  648. }
  649. static DEVICE_ATTR(AUXADC_Channel_2_Slope, 0664, show_AUXADC_Channel_2_Slope,
  650. store_AUXADC_Channel_2_Slope);
  651. static ssize_t show_AUXADC_Channel_2_Offset(struct device *dev, struct device_attribute *attr,
  652. char *buf)
  653. {
  654. int ret_value = 1;
  655. ret_value = (*(auxadc_cali_offset + 2));
  656. pr_debug("[EM] AUXADC_Channel_2_Offset : %d\n", ret_value);
  657. return sprintf(buf, "%u\n", ret_value);
  658. }
  659. static ssize_t store_AUXADC_Channel_2_Offset(struct device *dev, struct device_attribute *attr,
  660. const char *buf, size_t size)
  661. {
  662. pr_debug("[EM] Not Support Write Function\n");
  663. return size;
  664. }
  665. static DEVICE_ATTR(AUXADC_Channel_2_Offset, 0664, show_AUXADC_Channel_2_Offset,
  666. store_AUXADC_Channel_2_Offset);
  667. #endif
  668. #if ADC_CHANNEL_MAX > 3
  669. static ssize_t show_AUXADC_Channel_3_Slope(struct device *dev, struct device_attribute *attr,
  670. char *buf)
  671. {
  672. int ret_value = 1;
  673. ret_value = (*(auxadc_cali_slop + 3));
  674. pr_debug("[EM] AUXADC_Channel_3_Slope : %d\n", ret_value);
  675. return sprintf(buf, "%u\n", ret_value);
  676. }
  677. static ssize_t store_AUXADC_Channel_3_Slope(struct device *dev, struct device_attribute *attr,
  678. const char *buf, size_t size)
  679. {
  680. pr_debug("[EM] Not Support Write Function\n");
  681. return size;
  682. }
  683. static DEVICE_ATTR(AUXADC_Channel_3_Slope, 0664, show_AUXADC_Channel_3_Slope,
  684. store_AUXADC_Channel_3_Slope);
  685. static ssize_t show_AUXADC_Channel_3_Offset(struct device *dev, struct device_attribute *attr,
  686. char *buf)
  687. {
  688. int ret_value = 1;
  689. ret_value = (*(auxadc_cali_offset + 3));
  690. pr_debug("[EM] AUXADC_Channel_3_Offset : %d\n", ret_value);
  691. return sprintf(buf, "%u\n", ret_value);
  692. }
  693. static ssize_t store_AUXADC_Channel_3_Offset(struct device *dev, struct device_attribute *attr,
  694. const char *buf, size_t size)
  695. {
  696. pr_debug("[EM] Not Support Write Function\n");
  697. return size;
  698. }
  699. static DEVICE_ATTR(AUXADC_Channel_3_Offset, 0664, show_AUXADC_Channel_3_Offset,
  700. store_AUXADC_Channel_3_Offset);
  701. #endif
  702. #if ADC_CHANNEL_MAX > 4
  703. static ssize_t show_AUXADC_Channel_4_Slope(struct device *dev, struct device_attribute *attr,
  704. char *buf)
  705. {
  706. int ret_value = 1;
  707. ret_value = (*(auxadc_cali_slop + 4));
  708. pr_debug("[EM] AUXADC_Channel_4_Slope : %d\n", ret_value);
  709. return sprintf(buf, "%u\n", ret_value);
  710. }
  711. static ssize_t store_AUXADC_Channel_4_Slope(struct device *dev, struct device_attribute *attr,
  712. const char *buf, size_t size)
  713. {
  714. pr_debug("[EM] Not Support Write Function\n");
  715. return size;
  716. }
  717. static DEVICE_ATTR(AUXADC_Channel_4_Slope, 0664, show_AUXADC_Channel_4_Slope,
  718. store_AUXADC_Channel_4_Slope);
  719. static ssize_t show_AUXADC_Channel_4_Offset(struct device *dev, struct device_attribute *attr,
  720. char *buf)
  721. {
  722. int ret_value = 1;
  723. ret_value = (*(auxadc_cali_offset + 4));
  724. pr_debug("[EM] AUXADC_Channel_4_Offset : %d\n", ret_value);
  725. return sprintf(buf, "%u\n", ret_value);
  726. }
  727. static ssize_t store_AUXADC_Channel_4_Offset(struct device *dev, struct device_attribute *attr,
  728. const char *buf, size_t size)
  729. {
  730. pr_debug("[EM] Not Support Write Function\n");
  731. return size;
  732. }
  733. static DEVICE_ATTR(AUXADC_Channel_4_Offset, 0664, show_AUXADC_Channel_4_Offset,
  734. store_AUXADC_Channel_4_Offset);
  735. #endif
  736. #if ADC_CHANNEL_MAX > 5
  737. static ssize_t show_AUXADC_Channel_5_Slope(struct device *dev, struct device_attribute *attr,
  738. char *buf)
  739. {
  740. int ret_value = 1;
  741. ret_value = (*(auxadc_cali_slop + 5));
  742. pr_debug("[EM] AUXADC_Channel_5_Slope : %d\n", ret_value);
  743. return sprintf(buf, "%u\n", ret_value);
  744. }
  745. static ssize_t store_AUXADC_Channel_5_Slope(struct device *dev, struct device_attribute *attr,
  746. const char *buf, size_t size)
  747. {
  748. pr_debug("[EM] Not Support Write Function\n");
  749. return size;
  750. }
  751. static DEVICE_ATTR(AUXADC_Channel_5_Slope, 0664, show_AUXADC_Channel_5_Slope,
  752. store_AUXADC_Channel_5_Slope);
  753. static ssize_t show_AUXADC_Channel_5_Offset(struct device *dev, struct device_attribute *attr,
  754. char *buf)
  755. {
  756. int ret_value = 1;
  757. ret_value = (*(auxadc_cali_offset + 5));
  758. pr_debug("[EM] AUXADC_Channel_5_Offset : %d\n", ret_value);
  759. return sprintf(buf, "%u\n", ret_value);
  760. }
  761. static ssize_t store_AUXADC_Channel_5_Offset(struct device *dev, struct device_attribute *attr,
  762. const char *buf, size_t size)
  763. {
  764. pr_debug("[EM] Not Support Write Function\n");
  765. return size;
  766. }
  767. static DEVICE_ATTR(AUXADC_Channel_5_Offset, 0664, show_AUXADC_Channel_5_Offset,
  768. store_AUXADC_Channel_5_Offset);
  769. #endif
  770. #if ADC_CHANNEL_MAX > 6
  771. static ssize_t show_AUXADC_Channel_6_Slope(struct device *dev, struct device_attribute *attr,
  772. char *buf)
  773. {
  774. int ret_value = 1;
  775. ret_value = (*(auxadc_cali_slop + 6));
  776. pr_debug("[EM] AUXADC_Channel_6_Slope : %d\n", ret_value);
  777. return sprintf(buf, "%u\n", ret_value);
  778. }
  779. static ssize_t store_AUXADC_Channel_6_Slope(struct device *dev, struct device_attribute *attr,
  780. const char *buf, size_t size)
  781. {
  782. pr_debug("[EM] Not Support Write Function\n");
  783. return size;
  784. }
  785. static DEVICE_ATTR(AUXADC_Channel_6_Slope, 0664, show_AUXADC_Channel_6_Slope,
  786. store_AUXADC_Channel_6_Slope);
  787. static ssize_t show_AUXADC_Channel_6_Offset(struct device *dev, struct device_attribute *attr,
  788. char *buf)
  789. {
  790. int ret_value = 1;
  791. ret_value = (*(auxadc_cali_offset + 6));
  792. pr_debug("[EM] AUXADC_Channel_6_Offset : %d\n", ret_value);
  793. return sprintf(buf, "%u\n", ret_value);
  794. }
  795. static ssize_t store_AUXADC_Channel_6_Offset(struct device *dev, struct device_attribute *attr,
  796. const char *buf, size_t size)
  797. {
  798. pr_debug("[EM] Not Support Write Function\n");
  799. return size;
  800. }
  801. static DEVICE_ATTR(AUXADC_Channel_6_Offset, 0664, show_AUXADC_Channel_6_Offset,
  802. store_AUXADC_Channel_6_Offset);
  803. #endif
  804. #if ADC_CHANNEL_MAX > 7
  805. static ssize_t show_AUXADC_Channel_7_Slope(struct device *dev, struct device_attribute *attr,
  806. char *buf)
  807. {
  808. int ret_value = 1;
  809. ret_value = (*(auxadc_cali_slop + 7));
  810. pr_debug("[EM] AUXADC_Channel_7_Slope : %d\n", ret_value);
  811. return sprintf(buf, "%u\n", ret_value);
  812. }
  813. static ssize_t store_AUXADC_Channel_7_Slope(struct device *dev, struct device_attribute *attr,
  814. const char *buf, size_t size)
  815. {
  816. pr_debug("[EM] Not Support Write Function\n");
  817. return size;
  818. }
  819. static DEVICE_ATTR(AUXADC_Channel_7_Slope, 0664, show_AUXADC_Channel_7_Slope,
  820. store_AUXADC_Channel_7_Slope);
  821. static ssize_t show_AUXADC_Channel_7_Offset(struct device *dev, struct device_attribute *attr,
  822. char *buf)
  823. {
  824. int ret_value = 1;
  825. ret_value = (*(auxadc_cali_offset + 7));
  826. pr_debug("[EM] AUXADC_Channel_7_Offset : %d\n", ret_value);
  827. return sprintf(buf, "%u\n", ret_value);
  828. }
  829. static ssize_t store_AUXADC_Channel_7_Offset(struct device *dev, struct device_attribute *attr,
  830. const char *buf, size_t size)
  831. {
  832. pr_debug("[EM] Not Support Write Function\n");
  833. return size;
  834. }
  835. static DEVICE_ATTR(AUXADC_Channel_7_Offset, 0664, show_AUXADC_Channel_7_Offset,
  836. store_AUXADC_Channel_7_Offset);
  837. #endif
  838. #if ADC_CHANNEL_MAX > 8
  839. static ssize_t show_AUXADC_Channel_8_Slope(struct device *dev, struct device_attribute *attr,
  840. char *buf)
  841. {
  842. int ret_value = 1;
  843. ret_value = (*(auxadc_cali_slop + 8));
  844. pr_debug("[EM] AUXADC_Channel_8_Slope : %d\n", ret_value);
  845. return sprintf(buf, "%u\n", ret_value);
  846. }
  847. static ssize_t store_AUXADC_Channel_8_Slope(struct device *dev, struct device_attribute *attr,
  848. const char *buf, size_t size)
  849. {
  850. pr_debug("[EM] Not Support Write Function\n");
  851. return size;
  852. }
  853. static DEVICE_ATTR(AUXADC_Channel_8_Slope, 0664, show_AUXADC_Channel_8_Slope,
  854. store_AUXADC_Channel_8_Slope);
  855. static ssize_t show_AUXADC_Channel_8_Offset(struct device *dev, struct device_attribute *attr,
  856. char *buf)
  857. {
  858. int ret_value = 1;
  859. ret_value = (*(auxadc_cali_offset + 8));
  860. pr_debug("[EM] AUXADC_Channel_8_Offset : %d\n", ret_value);
  861. return sprintf(buf, "%u\n", ret_value);
  862. }
  863. static ssize_t store_AUXADC_Channel_8_Offset(struct device *dev, struct device_attribute *attr,
  864. const char *buf, size_t size)
  865. {
  866. pr_debug("[EM] Not Support Write Function\n");
  867. return size;
  868. }
  869. static DEVICE_ATTR(AUXADC_Channel_8_Offset, 0664, show_AUXADC_Channel_8_Offset,
  870. store_AUXADC_Channel_8_Offset);
  871. #endif
  872. #if ADC_CHANNEL_MAX > 9
  873. static ssize_t show_AUXADC_Channel_9_Slope(struct device *dev, struct device_attribute *attr,
  874. char *buf)
  875. {
  876. int ret_value = 1;
  877. ret_value = (*(auxadc_cali_slop + 9));
  878. pr_debug("[EM] AUXADC_Channel_9_Slope : %d\n", ret_value);
  879. return sprintf(buf, "%u\n", ret_value);
  880. }
  881. static ssize_t store_AUXADC_Channel_9_Slope(struct device *dev, struct device_attribute *attr,
  882. const char *buf, size_t size)
  883. {
  884. pr_debug("[EM] Not Support Write Function\n");
  885. return size;
  886. }
  887. static DEVICE_ATTR(AUXADC_Channel_9_Slope, 0664, show_AUXADC_Channel_9_Slope,
  888. store_AUXADC_Channel_9_Slope);
  889. static ssize_t show_AUXADC_Channel_9_Offset(struct device *dev, struct device_attribute *attr,
  890. char *buf)
  891. {
  892. int ret_value = 1;
  893. ret_value = (*(auxadc_cali_offset + 9));
  894. pr_debug("[EM] AUXADC_Channel_9_Offset : %d\n", ret_value);
  895. return sprintf(buf, "%u\n", ret_value);
  896. }
  897. static ssize_t store_AUXADC_Channel_9_Offset(struct device *dev, struct device_attribute *attr,
  898. const char *buf, size_t size)
  899. {
  900. pr_debug("[EM] Not Support Write Function\n");
  901. return size;
  902. }
  903. static DEVICE_ATTR(AUXADC_Channel_9_Offset, 0664, show_AUXADC_Channel_9_Offset,
  904. store_AUXADC_Channel_9_Offset);
  905. #endif
  906. #if ADC_CHANNEL_MAX > 10
  907. static ssize_t show_AUXADC_Channel_10_Slope(struct device *dev, struct device_attribute *attr,
  908. char *buf)
  909. {
  910. int ret_value = 1;
  911. ret_value = (*(auxadc_cali_slop + 10));
  912. pr_debug("[EM] AUXADC_Channel_10_Slope : %d\n", ret_value);
  913. return sprintf(buf, "%u\n", ret_value);
  914. }
  915. static ssize_t store_AUXADC_Channel_10_Slope(struct device *dev, struct device_attribute *attr,
  916. const char *buf, size_t size)
  917. {
  918. pr_debug("[EM] Not Support Write Function\n");
  919. return size;
  920. }
  921. static DEVICE_ATTR(AUXADC_Channel_10_Slope, 0664, show_AUXADC_Channel_10_Slope,
  922. store_AUXADC_Channel_10_Slope);
  923. static ssize_t show_AUXADC_Channel_10_Offset(struct device *dev, struct device_attribute *attr,
  924. char *buf)
  925. {
  926. int ret_value = 1;
  927. ret_value = (*(auxadc_cali_offset + 10));
  928. pr_debug("[EM] AUXADC_Channel_10_Offset : %d\n", ret_value);
  929. return sprintf(buf, "%u\n", ret_value);
  930. }
  931. static ssize_t store_AUXADC_Channel_10_Offset(struct device *dev, struct device_attribute *attr,
  932. const char *buf, size_t size)
  933. {
  934. pr_debug("[EM] Not Support Write Function\n");
  935. return size;
  936. }
  937. static DEVICE_ATTR(AUXADC_Channel_10_Offset, 0664, show_AUXADC_Channel_10_Offset,
  938. store_AUXADC_Channel_10_Offset);
  939. #endif
  940. #if ADC_CHANNEL_MAX > 11
  941. static ssize_t show_AUXADC_Channel_11_Slope(struct device *dev, struct device_attribute *attr,
  942. char *buf)
  943. {
  944. int ret_value = 1;
  945. ret_value = (*(auxadc_cali_slop + 11));
  946. pr_debug("[EM] AUXADC_Channel_11_Slope : %d\n", ret_value);
  947. return sprintf(buf, "%u\n", ret_value);
  948. }
  949. static ssize_t store_AUXADC_Channel_11_Slope(struct device *dev, struct device_attribute *attr,
  950. const char *buf, size_t size)
  951. {
  952. pr_debug("[EM] Not Support Write Function\n");
  953. return size;
  954. }
  955. static DEVICE_ATTR(AUXADC_Channel_11_Slope, 0664, show_AUXADC_Channel_11_Slope,
  956. store_AUXADC_Channel_11_Slope);
  957. static ssize_t show_AUXADC_Channel_11_Offset(struct device *dev, struct device_attribute *attr,
  958. char *buf)
  959. {
  960. int ret_value = 1;
  961. ret_value = (*(auxadc_cali_offset + 11));
  962. pr_debug("[EM] AUXADC_Channel_11_Offset : %d\n", ret_value);
  963. return sprintf(buf, "%u\n", ret_value);
  964. }
  965. static ssize_t store_AUXADC_Channel_11_Offset(struct device *dev, struct device_attribute *attr,
  966. const char *buf, size_t size)
  967. {
  968. pr_debug("[EM] Not Support Write Function\n");
  969. return size;
  970. }
  971. static DEVICE_ATTR(AUXADC_Channel_11_Offset, 0664, show_AUXADC_Channel_11_Offset,
  972. store_AUXADC_Channel_11_Offset);
  973. #endif
  974. #if ADC_CHANNEL_MAX > 12
  975. static ssize_t show_AUXADC_Channel_12_Slope(struct device *dev, struct device_attribute *attr,
  976. char *buf)
  977. {
  978. int ret_value = 1;
  979. ret_value = (*(auxadc_cali_slop + 12));
  980. pr_debug("[EM] AUXADC_Channel_12_Slope : %d\n", ret_value);
  981. return sprintf(buf, "%u\n", ret_value);
  982. }
  983. static ssize_t store_AUXADC_Channel_12_Slope(struct device *dev, struct device_attribute *attr,
  984. const char *buf, size_t size)
  985. {
  986. pr_debug("[EM] Not Support Write Function\n");
  987. return size;
  988. }
  989. static DEVICE_ATTR(AUXADC_Channel_12_Slope, 0664, show_AUXADC_Channel_12_Slope,
  990. store_AUXADC_Channel_12_Slope);
  991. static ssize_t show_AUXADC_Channel_12_Offset(struct device *dev, struct device_attribute *attr,
  992. char *buf)
  993. {
  994. int ret_value = 1;
  995. ret_value = (*(auxadc_cali_offset + 12));
  996. pr_debug("[EM] AUXADC_Channel_12_Offset : %d\n", ret_value);
  997. return sprintf(buf, "%u\n", ret_value);
  998. }
  999. static ssize_t store_AUXADC_Channel_12_Offset(struct device *dev, struct device_attribute *attr,
  1000. const char *buf, size_t size)
  1001. {
  1002. pr_debug("[EM] Not Support Write Function\n");
  1003. return size;
  1004. }
  1005. static DEVICE_ATTR(AUXADC_Channel_12_Offset, 0664, show_AUXADC_Channel_12_Offset,
  1006. store_AUXADC_Channel_12_Offset);
  1007. #endif
  1008. #if ADC_CHANNEL_MAX > 13
  1009. static ssize_t show_AUXADC_Channel_13_Slope(struct device *dev, struct device_attribute *attr,
  1010. char *buf)
  1011. {
  1012. int ret_value = 1;
  1013. ret_value = (*(auxadc_cali_slop + 13));
  1014. pr_debug("[EM] AUXADC_Channel_13_Slope : %d\n", ret_value);
  1015. return sprintf(buf, "%u\n", ret_value);
  1016. }
  1017. static ssize_t store_AUXADC_Channel_13_Slope(struct device *dev, struct device_attribute *attr,
  1018. const char *buf, size_t size)
  1019. {
  1020. pr_debug("[EM] Not Support Write Function\n");
  1021. return size;
  1022. }
  1023. static DEVICE_ATTR(AUXADC_Channel_13_Slope, 0664, show_AUXADC_Channel_13_Slope,
  1024. store_AUXADC_Channel_13_Slope);
  1025. static ssize_t show_AUXADC_Channel_13_Offset(struct device *dev, struct device_attribute *attr,
  1026. char *buf)
  1027. {
  1028. int ret_value = 1;
  1029. ret_value = (*(auxadc_cali_offset + 13));
  1030. pr_debug("[EM] AUXADC_Channel_13_Offset : %d\n", ret_value);
  1031. return sprintf(buf, "%u\n", ret_value);
  1032. }
  1033. static ssize_t store_AUXADC_Channel_13_Offset(struct device *dev, struct device_attribute *attr,
  1034. const char *buf, size_t size)
  1035. {
  1036. pr_debug("[EM] Not Support Write Function\n");
  1037. return size;
  1038. }
  1039. static DEVICE_ATTR(AUXADC_Channel_13_Offset, 0664, show_AUXADC_Channel_13_Offset,
  1040. store_AUXADC_Channel_13_Offset);
  1041. #endif
  1042. #if ADC_CHANNEL_MAX > 14
  1043. static ssize_t show_AUXADC_Channel_14_Slope(struct device *dev, struct device_attribute *attr,
  1044. char *buf)
  1045. {
  1046. int ret_value = 1;
  1047. ret_value = (*(auxadc_cali_slop + 14));
  1048. pr_debug("[EM] AUXADC_Channel_14_Slope : %d\n", ret_value);
  1049. return sprintf(buf, "%u\n", ret_value);
  1050. }
  1051. static ssize_t store_AUXADC_Channel_14_Slope(struct device *dev, struct device_attribute *attr,
  1052. const char *buf, size_t size)
  1053. {
  1054. pr_debug("[EM] Not Support Write Function\n");
  1055. return size;
  1056. }
  1057. static DEVICE_ATTR(AUXADC_Channel_14_Slope, 0664, show_AUXADC_Channel_14_Slope,
  1058. store_AUXADC_Channel_14_Slope);
  1059. static ssize_t show_AUXADC_Channel_14_Offset(struct device *dev, struct device_attribute *attr,
  1060. char *buf)
  1061. {
  1062. int ret_value = 1;
  1063. ret_value = (*(auxadc_cali_offset + 14));
  1064. pr_debug("[EM] AUXADC_Channel_14_Offset : %d\n", ret_value);
  1065. return sprintf(buf, "%u\n", ret_value);
  1066. }
  1067. static ssize_t store_AUXADC_Channel_14_Offset(struct device *dev, struct device_attribute *attr,
  1068. const char *buf, size_t size)
  1069. {
  1070. pr_debug("[EM] Not Support Write Function\n");
  1071. return size;
  1072. }
  1073. static DEVICE_ATTR(AUXADC_Channel_14_Offset, 0664, show_AUXADC_Channel_14_Offset,
  1074. store_AUXADC_Channel_14_Offset);
  1075. #endif
  1076. #if ADC_CHANNEL_MAX > 15
  1077. static ssize_t show_AUXADC_Channel_15_Slope(struct device *dev, struct device_attribute *attr,
  1078. char *buf)
  1079. {
  1080. int ret_value = 1;
  1081. ret_value = (*(auxadc_cali_slop + 15));
  1082. pr_debug("[EM] AUXADC_Channel_15_Slope : %d\n", ret_value);
  1083. return sprintf(buf, "%u\n", ret_value);
  1084. }
  1085. static ssize_t store_AUXADC_Channel_15_Slope(struct device *dev, struct device_attribute *attr,
  1086. const char *buf, size_t size)
  1087. {
  1088. pr_debug("[EM] Not Support Write Function\n");
  1089. return size;
  1090. }
  1091. static DEVICE_ATTR(AUXADC_Channel_15_Slope, 0664, show_AUXADC_Channel_15_Slope,
  1092. store_AUXADC_Channel_15_Slope);
  1093. static ssize_t show_AUXADC_Channel_15_Offset(struct device *dev, struct device_attribute *attr,
  1094. char *buf)
  1095. {
  1096. int ret_value = 1;
  1097. ret_value = (*(auxadc_cali_offset + 15));
  1098. pr_debug("[EM] AUXADC_Channel_15_Offset : %d\n", ret_value);
  1099. return sprintf(buf, "%u\n", ret_value);
  1100. }
  1101. static ssize_t store_AUXADC_Channel_15_Offset(struct device *dev, struct device_attribute *attr,
  1102. const char *buf, size_t size)
  1103. {
  1104. pr_debug("[EM] Not Support Write Function\n");
  1105. return size;
  1106. }
  1107. static DEVICE_ATTR(AUXADC_Channel_15_Offset, 0664, show_AUXADC_Channel_15_Offset,
  1108. store_AUXADC_Channel_15_Offset);
  1109. #endif
  1110. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  1111. /* // Create File For EM : AUXADC_Channel_Is_Calibration */
  1112. /* ///////////////////////////////////////////////////////////////////////////////////////// */
  1113. static ssize_t show_AUXADC_Channel_Is_Calibration(struct device *dev, struct device_attribute *attr,
  1114. char *buf)
  1115. {
  1116. int ret_value = 2;
  1117. ret_value = g_AUXADC_Cali;
  1118. pr_debug("[EM] AUXADC_Channel_Is_Calibration : %d\n", ret_value);
  1119. return sprintf(buf, "%u\n", ret_value);
  1120. }
  1121. static ssize_t store_AUXADC_Channel_Is_Calibration(struct device *dev,
  1122. struct device_attribute *attr, const char *buf,
  1123. size_t size)
  1124. {
  1125. pr_debug("[EM] Not Support Write Function\n");
  1126. return size;
  1127. }
  1128. static DEVICE_ATTR(AUXADC_Channel_Is_Calibration, 0664, show_AUXADC_Channel_Is_Calibration,
  1129. store_AUXADC_Channel_Is_Calibration);
  1130. static ssize_t show_AUXADC_register(struct device *dev, struct device_attribute *attr, char *buf)
  1131. {
  1132. return mt_auxadc_dump_register(buf);
  1133. }
  1134. static ssize_t store_AUXADC_register(struct device *dev, struct device_attribute *attr,
  1135. const char *buf, size_t size)
  1136. {
  1137. pr_debug("[EM] Not Support store_AUXADC_register\n");
  1138. return size;
  1139. }
  1140. static DEVICE_ATTR(AUXADC_register, 0664, show_AUXADC_register, store_AUXADC_register);
  1141. static ssize_t show_AUXADC_chanel(struct device *dev, struct device_attribute *attr, char *buf)
  1142. {
  1143. /* read data */
  1144. int i = 0, data[4] = { 0, 0, 0, 0 };
  1145. char buf_temp[256];
  1146. int res = 0;
  1147. for (i = 0; i < 5; i++) {
  1148. res = IMM_auxadc_GetOneChannelValue(i, data, NULL);
  1149. if (res < 0) {
  1150. pr_debug("[adc_driver]: get data error\n");
  1151. } else {
  1152. pr_debug("[adc_driver]: channel[%d]=%d.%d\n", i, data[0], data[1]);
  1153. sprintf(buf_temp, "channel[%d]=%d.%d\n", i, data[0], data[1]);
  1154. strcat(buf, buf_temp);
  1155. }
  1156. }
  1157. mt_auxadc_dump_register(buf_temp);
  1158. strcat(buf, buf_temp);
  1159. return strlen(buf);
  1160. }
  1161. static int dbug_thread(void *unused)
  1162. {
  1163. int i = 0, data[4] = { 0, 0, 0, 0 };
  1164. int res = 0;
  1165. int rawdata = 0;
  1166. int cali_voltage = 0;
  1167. while (g_start_debug_thread) {
  1168. for (i = 0; i < ADC_CHANNEL_MAX; i++) {
  1169. res = IMM_auxadc_GetOneChannelValue(i, data, &rawdata);
  1170. if (res < 0) {
  1171. pr_debug("[adc_driver]: get data error\n");
  1172. } else {
  1173. pr_debug("[adc_driver]: channel[%d]raw =%d\n", i, rawdata);
  1174. pr_debug("[adc_driver]: channel[%d]=%d.%.02d\n", i, data[0],
  1175. data[1]);
  1176. }
  1177. res = IMM_auxadc_GetOneChannelValue_Cali(i, &cali_voltage);
  1178. if (res < 0) {
  1179. pr_debug("[adc_driver]: get cali voltage error\n");
  1180. } else
  1181. pr_debug("[adc_driver]: channel[%d] cali_voltage =%d\n", i,
  1182. cali_voltage);
  1183. msleep(500);
  1184. }
  1185. msleep(500);
  1186. }
  1187. return 0;
  1188. }
  1189. static ssize_t store_AUXADC_channel(struct device *dev, struct device_attribute *attr,
  1190. const char *buf, size_t size)
  1191. {
  1192. char start_flag;
  1193. int error;
  1194. if (sscanf(buf, "%s", &start_flag) != 1) {
  1195. pr_debug("[adc_driver]: Invalid values\n");
  1196. return -EINVAL;
  1197. }
  1198. pr_debug("[adc_driver] start flag =%d\n", start_flag);
  1199. g_start_debug_thread = start_flag;
  1200. if (1 == start_flag) {
  1201. thread = kthread_run(dbug_thread, 0, "AUXADC");
  1202. if (IS_ERR(thread)) {
  1203. error = PTR_ERR(thread);
  1204. pr_debug("[adc_driver] failed to create kernel thread: %d\n", error);
  1205. }
  1206. }
  1207. return size;
  1208. }
  1209. static DEVICE_ATTR(AUXADC_read_channel, 0664, show_AUXADC_chanel, store_AUXADC_channel);
  1210. static int mt_auxadc_create_device_attr(struct device *dev)
  1211. {
  1212. int ret = 0;
  1213. /* For EM */
  1214. ret = device_create_file(dev, &dev_attr_AUXADC_register);
  1215. if (ret != 0)
  1216. goto exit;
  1217. ret = device_create_file(dev, &dev_attr_AUXADC_read_channel);
  1218. if (ret != 0)
  1219. goto exit;
  1220. #if ADC_CHANNEL_MAX > 0
  1221. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_0_Slope);
  1222. if (ret != 0)
  1223. goto exit;
  1224. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_0_Offset);
  1225. if (ret != 0)
  1226. goto exit;
  1227. #endif
  1228. #if ADC_CHANNEL_MAX > 1
  1229. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_1_Slope);
  1230. if (ret != 0)
  1231. goto exit;
  1232. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_1_Offset);
  1233. if (ret != 0)
  1234. goto exit;
  1235. #endif
  1236. #if ADC_CHANNEL_MAX > 2
  1237. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_2_Slope);
  1238. if (ret != 0)
  1239. goto exit;
  1240. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_2_Offset);
  1241. if (ret != 0)
  1242. goto exit;
  1243. #endif
  1244. #if ADC_CHANNEL_MAX > 3
  1245. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_3_Slope);
  1246. if (ret != 0)
  1247. goto exit;
  1248. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_3_Offset);
  1249. if (ret != 0)
  1250. goto exit;
  1251. #endif
  1252. #if ADC_CHANNEL_MAX > 4
  1253. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_4_Slope);
  1254. if (ret != 0)
  1255. goto exit;
  1256. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_4_Offset);
  1257. if (ret != 0)
  1258. goto exit;
  1259. #endif
  1260. #if ADC_CHANNEL_MAX > 5
  1261. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_5_Slope);
  1262. if (ret != 0)
  1263. goto exit;
  1264. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_5_Offset);
  1265. if (ret != 0)
  1266. goto exit;
  1267. #endif
  1268. #if ADC_CHANNEL_MAX > 6
  1269. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_6_Slope);
  1270. if (ret != 0)
  1271. goto exit;
  1272. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_6_Offset);
  1273. if (ret != 0)
  1274. goto exit;
  1275. #endif
  1276. #if ADC_CHANNEL_MAX > 7
  1277. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_7_Slope);
  1278. if (ret != 0)
  1279. goto exit;
  1280. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_7_Offset);
  1281. if (ret != 0)
  1282. goto exit;
  1283. #endif
  1284. #if ADC_CHANNEL_MAX > 8
  1285. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_8_Slope);
  1286. if (ret != 0)
  1287. goto exit;
  1288. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_8_Offset);
  1289. if (ret != 0)
  1290. goto exit;
  1291. #endif
  1292. #if ADC_CHANNEL_MAX > 9
  1293. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_9_Slope);
  1294. if (ret != 0)
  1295. goto exit;
  1296. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_9_Offset);
  1297. if (ret != 0)
  1298. goto exit;
  1299. #endif
  1300. #if ADC_CHANNEL_MAX > 10
  1301. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_10_Slope);
  1302. if (ret != 0)
  1303. goto exit;
  1304. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_10_Offset);
  1305. if (ret != 0)
  1306. goto exit;
  1307. #endif
  1308. #if ADC_CHANNEL_MAX > 11
  1309. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_11_Slope);
  1310. if (ret != 0)
  1311. goto exit;
  1312. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_11_Offset);
  1313. if (ret != 0)
  1314. goto exit;
  1315. #endif
  1316. #if ADC_CHANNEL_MAX > 12
  1317. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_12_Slope);
  1318. if (ret != 0)
  1319. goto exit;
  1320. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_12_Offset);
  1321. if (ret != 0)
  1322. goto exit;
  1323. #endif
  1324. #if ADC_CHANNEL_MAX > 13
  1325. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_13_Slope);
  1326. if (ret != 0)
  1327. goto exit;
  1328. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_13_Offset);
  1329. if (ret != 0)
  1330. goto exit;
  1331. #endif
  1332. #if ADC_CHANNEL_MAX > 14
  1333. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_14_Slope);
  1334. if (ret != 0)
  1335. goto exit;
  1336. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_14_Offset);
  1337. if (ret != 0)
  1338. goto exit;
  1339. #endif
  1340. #if ADC_CHANNEL_MAX > 15
  1341. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_15_Slope);
  1342. if (ret != 0)
  1343. goto exit;
  1344. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_15_Offset);
  1345. if (ret != 0)
  1346. goto exit;
  1347. #endif
  1348. ret = device_create_file(dev, &dev_attr_AUXADC_Channel_Is_Calibration);
  1349. if (ret != 0)
  1350. goto exit;
  1351. return 0;
  1352. exit:
  1353. return 1;
  1354. }
  1355. static int proc_utilization_show(struct seq_file *m, void *v)
  1356. {
  1357. int i, res;
  1358. int data[4] = { 0, 0, 0, 0 };
  1359. seq_puts(m, "********** Auxadc status dump **********\n");
  1360. seq_printf(m, "reg=0x%x ADC_GE_A=0x%x ADC_OE_A=0x%x GE:0x%x OE:0x%x gain:0x%x\n",
  1361. cali_reg, cali_ge_a, cali_oe_a, cali_ge, cali_oe, gain);
  1362. #if defined(EFUSE_CALI)
  1363. seq_printf(m, "ADC_GE_A_MASK:0x%x ADC_GE_A_SHIFT:0x%x\n", ADC_GE_A_MASK, ADC_GE_A_SHIFT);
  1364. seq_printf(m, "ADC_OE_A_MASK:0x%x ADC_OE_A_SHIFT:0x%x\n", ADC_OE_A_MASK, ADC_OE_A_SHIFT);
  1365. seq_printf(m, "ADC_CALI_EN_A_MASK:0x%x ADC_CALI_EN_A_SHIFT:0x%x\n", ADC_CALI_EN_A_MASK,
  1366. ADC_CALI_EN_A_SHIFT);
  1367. #endif
  1368. for (i = 100; i <= 1000; i = i + 100) {
  1369. mt_auxadc_get_cali_data(i, data, true);
  1370. seq_printf(m, "raw:%d data:%d %d %d with cali\n", i, data[0], data[1], data[2]);
  1371. mt_auxadc_get_cali_data(i, data, false);
  1372. seq_printf(m, "raw:%d data:%d %d %d without cali\n", i, data[0], data[1], data[2]);
  1373. }
  1374. for (i = 0; i < 5; i++) {
  1375. res = IMM_auxadc_GetOneChannelValue(i, data, NULL);
  1376. if (res < 0)
  1377. seq_printf(m, "[adc_driver]: get data error res:%d\n", res);
  1378. else
  1379. seq_printf(m, "channel[%d]=%d.%d %d\n", i, data[0], data[1], data[2]);
  1380. }
  1381. return 0;
  1382. }
  1383. static int proc_utilization_open(struct inode *inode, struct file *file)
  1384. {
  1385. return single_open(file, proc_utilization_show, NULL);
  1386. }
  1387. static const struct file_operations auxadc_debug_proc_fops = {
  1388. .open = proc_utilization_open,
  1389. .read = seq_read,
  1390. };
  1391. static void adc_debug_init(void)
  1392. {
  1393. struct proc_dir_entry *mt_auxadc_dir;
  1394. mt_auxadc_dir = proc_mkdir("mt-auxadc", NULL);
  1395. if (!mt_auxadc_dir) {
  1396. pr_err("fail to mkdir /proc/mt-auxadc\n");
  1397. return;
  1398. }
  1399. proc_create("dump_auxadc_status", S_IRUGO | S_IWUSR, mt_auxadc_dir, &auxadc_debug_proc_fops);
  1400. pr_err("proc_create auxadc_debug_proc_fops\n");
  1401. }
  1402. /* platform_driver API */
  1403. static int mt_auxadc_probe(struct platform_device *dev)
  1404. {
  1405. int ret = 0;
  1406. struct device *adc_dev = NULL;
  1407. #ifdef CONFIG_OF
  1408. int used_channel_counter = 0;
  1409. int of_value = 0;
  1410. #endif
  1411. #ifdef CONFIG_OF
  1412. struct device_node *node;
  1413. #endif
  1414. pr_debug("******** MT AUXADC driver probe!! ********\n");
  1415. #if !defined(CONFIG_MTK_CLKMGR)
  1416. #else
  1417. #ifndef CONFIG_MTK_FPGA
  1418. if (clock_is_on(MT_PDN_PERI_AUXADC) == 0) {
  1419. if (enable_clock(MT_PDN_PERI_AUXADC, "AUXADC"))
  1420. pr_debug("hwEnableClock AUXADC failed.");
  1421. }
  1422. #endif
  1423. #endif
  1424. /* Integrate with NVRAM */
  1425. ret = alloc_chrdev_region(&auxadc_cali_devno, 0, 1, AUXADC_CALI_DEVNAME);
  1426. if (ret)
  1427. pr_err("[AUXADC_AP]Error: Can't Get Major number for auxadc_cali\n");
  1428. auxadc_cali_cdev = cdev_alloc();
  1429. auxadc_cali_cdev->owner = THIS_MODULE;
  1430. auxadc_cali_cdev->ops = &auxadc_cali_fops;
  1431. ret = cdev_add(auxadc_cali_cdev, auxadc_cali_devno, 1);
  1432. if (ret)
  1433. pr_err("auxadc_cali Error: cdev_add\n");
  1434. auxadc_cali_major = MAJOR(auxadc_cali_devno);
  1435. auxadc_cali_class = class_create(THIS_MODULE, AUXADC_CALI_DEVNAME);
  1436. adc_dev = (struct device *)device_create(auxadc_cali_class,
  1437. NULL, auxadc_cali_devno, NULL,
  1438. AUXADC_CALI_DEVNAME);
  1439. pr_debug("[MT AUXADC_probe] NVRAM prepare : done !!\n");
  1440. /* read calibration data from EFUSE */
  1441. mt_auxadc_hal_init(dev);
  1442. pr_debug("[MT AUXADC_probe2] mt_auxadc_hal_init : done !!\n");
  1443. #ifdef CONFIG_OF
  1444. pr_warn("[MT AUXADC_probe3] get device tree info : start !!\n");
  1445. node = of_find_compatible_node(NULL, NULL, "mediatek,adc_channel");
  1446. if (node) {
  1447. ret = of_property_read_u32_array(node, "mediatek,temperature0", &of_value, 1);
  1448. if (ret == 0) {
  1449. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_RFTMP");
  1450. g_adc_info[used_channel_counter].channel_number = of_value;
  1451. pr_warn("[AUXADC_AP] find node TEMPERATURE:%d\n", of_value);
  1452. used_channel_counter++;
  1453. }
  1454. ret = of_property_read_u32_array(node, "mediatek,temperature1", &of_value, 1);
  1455. if (ret == 0) {
  1456. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_APTMP");
  1457. g_adc_info[used_channel_counter].channel_number = of_value;
  1458. pr_warn("[AUXADC_AP] find node TEMPERATURE1:%d\n", of_value);
  1459. used_channel_counter++;
  1460. }
  1461. ret =
  1462. of_property_read_u32_array(node, "mediatek,adc_fdd_rf_params_dynamic_custom_ch",
  1463. &of_value, 1);
  1464. if (ret == 0) {
  1465. sprintf(g_adc_info[used_channel_counter].channel_name,
  1466. "ADC_FDD_Rf_Params_Dynamic_Custom");
  1467. g_adc_info[used_channel_counter].channel_number = of_value;
  1468. pr_warn("[AUXADC_AP] find node ADC_FDD_RF_PARAMS_DYNAMIC_CUSTOM_CH:%d\n",
  1469. of_value);
  1470. used_channel_counter++;
  1471. }
  1472. ret = of_property_read_u32_array(node, "mediatek,hf_mic", &of_value, 1);
  1473. if (ret == 0) {
  1474. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_MIC");
  1475. g_adc_info[used_channel_counter].channel_number = of_value;
  1476. pr_warn("[AUXADC_AP] find node HF_MIC:%d\n", of_value);
  1477. used_channel_counter++;
  1478. }
  1479. ret = of_property_read_u32_array(node, "mediatek,lcm_voltage", &of_value, 1);
  1480. if (ret == 0) {
  1481. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_LCM_VOLTAGE");
  1482. g_adc_info[used_channel_counter].channel_number = of_value;
  1483. pr_warn("[AUXADC_AP] find node LCM_VOLTAGE:%d\n", of_value);
  1484. used_channel_counter++;
  1485. }
  1486. ret = of_property_read_u32_array(node, "mediatek,battery_voltage", &of_value, 1);
  1487. if (ret == 0) {
  1488. sprintf(g_adc_info[used_channel_counter].channel_name,
  1489. "ADC_BATTERY_VOLTAGE");
  1490. g_adc_info[used_channel_counter].channel_number = of_value;
  1491. pr_warn("[AUXADC_AP] find node BATTERY_VOLTAGE:%d\n", of_value);
  1492. used_channel_counter++;
  1493. }
  1494. ret = of_property_read_u32_array(node, "mediatek,charger_voltage", &of_value, 1);
  1495. if (ret == 0) {
  1496. sprintf(g_adc_info[used_channel_counter].channel_name,
  1497. "ADC_CHARGER_VOLTAGE");
  1498. g_adc_info[used_channel_counter].channel_number = of_value;
  1499. pr_warn("[AUXADC_AP] find node CHARGER_VOLTAGE:%d\n", of_value);
  1500. used_channel_counter++;
  1501. }
  1502. ret = of_property_read_u32_array(node, "mediatek,utms", &of_value, 1);
  1503. if (ret == 0) {
  1504. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_UTMS");
  1505. g_adc_info[used_channel_counter].channel_number = of_value;
  1506. pr_warn("[AUXADC_AP] find node UTMS:%d\n", of_value);
  1507. used_channel_counter++;
  1508. }
  1509. ret = of_property_read_u32_array(node, "mediatek,ref_current", &of_value, 1);
  1510. if (ret == 0) {
  1511. sprintf(g_adc_info[used_channel_counter].channel_name, "ADC_REF_CURRENT");
  1512. g_adc_info[used_channel_counter].channel_number = of_value;
  1513. pr_warn("[AUXADC_AP] find node REF_CURRENT:%d\n", of_value);
  1514. used_channel_counter++;
  1515. }
  1516. } else {
  1517. pr_err("[AUXADC_AP] find node failed\n");
  1518. }
  1519. #endif
  1520. pr_warn("[MT AUXADC_AP] adc_channel_info_init : done !!\n");
  1521. #if !defined(CONFIG_MTK_CLKMGR)
  1522. #ifdef CONFIG_OF
  1523. clk_auxadc = devm_clk_get(&dev->dev, "auxadc-main");
  1524. if (!clk_auxadc) {
  1525. pr_err("[AUXADC] devm_clk_get failed\n");
  1526. return -1;
  1527. }
  1528. pr_debug("[AUXADC]: auxadc CLK:0x%p\n", clk_auxadc);
  1529. ret = clk_prepare_enable(clk_auxadc);
  1530. if (ret)
  1531. pr_err("hwEnableClock AUXADC failed.");
  1532. #endif
  1533. #else
  1534. #endif
  1535. adc_debug_init();
  1536. g_adc_init_flag = 1;
  1537. if (mt_auxadc_create_device_attr(adc_dev))
  1538. goto exit;
  1539. exit:
  1540. return ret;
  1541. }
  1542. static int mt_auxadc_remove(struct platform_device *dev)
  1543. {
  1544. pr_debug("******** MT auxadc driver remove!! ********\n");
  1545. return 0;
  1546. }
  1547. static void mt_auxadc_shutdown(struct platform_device *dev)
  1548. {
  1549. pr_debug("******** MT auxadc driver shutdown!! ********\n");
  1550. }
  1551. static int mt_auxadc_suspend(struct platform_device *dev, pm_message_t state)
  1552. {
  1553. /* pr_debug("******** MT auxadc driver suspend!! ********\n" ); */
  1554. mt_auxadc_hal_suspend();
  1555. return 0;
  1556. }
  1557. static int mt_auxadc_resume(struct platform_device *dev)
  1558. {
  1559. /* pr_debug("******** MT auxadc driver resume!! ********\n" ); */
  1560. mt_auxadc_hal_resume();
  1561. return 0;
  1562. }
  1563. #ifdef CONFIG_OF
  1564. static const struct of_device_id mt_auxadc_of_match[] = {
  1565. {.compatible = "mediatek,mt6735-auxadc",},
  1566. {.compatible = "mediatek,mt6797-auxadc",},
  1567. {.compatible = "mediatek,mt6755-auxadc",},
  1568. {},
  1569. };
  1570. #endif
  1571. static struct platform_driver mt_auxadc_driver = {
  1572. .probe = mt_auxadc_probe,
  1573. .remove = mt_auxadc_remove,
  1574. .shutdown = mt_auxadc_shutdown,
  1575. #ifdef CONFIG_PM
  1576. .suspend = mt_auxadc_suspend,
  1577. .resume = mt_auxadc_resume,
  1578. #endif
  1579. .driver = {
  1580. .name = "mt-auxadc",
  1581. #ifdef CONFIG_OF
  1582. .of_match_table = mt_auxadc_of_match,
  1583. #endif
  1584. },
  1585. };
  1586. static int __init mt_auxadc_init(void)
  1587. {
  1588. int ret;
  1589. #if !defined(CONFIG_MTK_CLKMGR)
  1590. #else
  1591. #ifndef CONFIG_MTK_FPGA
  1592. if (enable_clock(MT_PDN_PERI_AUXADC, "AUXADC"))
  1593. pr_err("hwEnableClock AUXADC failed.");
  1594. #endif
  1595. #endif
  1596. ret = platform_driver_register(&mt_auxadc_driver);
  1597. if (ret) {
  1598. pr_err("****[mt_auxadc_driver] Unable to register driver (%d)\n", ret);
  1599. return ret;
  1600. }
  1601. pr_debug("****[mt_auxadc_driver] Initialization : DONE\n");
  1602. return 0;
  1603. }
  1604. static void __exit mt_auxadc_exit(void)
  1605. {
  1606. }
  1607. module_init(mt_auxadc_init);
  1608. module_exit(mt_auxadc_exit);
  1609. MODULE_AUTHOR("MTK");
  1610. MODULE_DESCRIPTION("MTK AUXADC Device Driver");
  1611. MODULE_LICENSE("GPL");