qpnp-adc-tm.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  1. /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #define pr_fmt(fmt) "%s: " fmt, __func__
  14. #include <linux/kernel.h>
  15. #include <linux/of.h>
  16. #include <linux/err.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/delay.h>
  20. #include <linux/mutex.h>
  21. #include <linux/types.h>
  22. #include <linux/hwmon.h>
  23. #include <linux/module.h>
  24. #include <linux/debugfs.h>
  25. #include <linux/spmi.h>
  26. #include <linux/of_irq.h>
  27. #include <linux/wakelock.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/completion.h>
  30. #include <linux/hwmon-sysfs.h>
  31. #include <linux/qpnp/qpnp-adc.h>
  32. #include <linux/thermal.h>
  33. #include <linux/platform_device.h>
  34. /* QPNP VADC TM register definition */
  35. #define QPNP_REVISION3 0x2
  36. #define QPNP_PERPH_SUBTYPE 0x5
  37. #define QPNP_PERPH_TYPE2 0x2
  38. #define QPNP_REVISION_EIGHT_CHANNEL_SUPPORT 2
  39. #define QPNP_STATUS1 0x8
  40. #define QPNP_STATUS1_OP_MODE 4
  41. #define QPNP_STATUS1_MEAS_INTERVAL_EN_STS BIT(2)
  42. #define QPNP_STATUS1_REQ_STS BIT(1)
  43. #define QPNP_STATUS1_EOC BIT(0)
  44. #define QPNP_STATUS2 0x9
  45. #define QPNP_STATUS2_CONV_SEQ_STATE 6
  46. #define QPNP_STATUS2_FIFO_NOT_EMPTY_FLAG BIT(1)
  47. #define QPNP_STATUS2_CONV_SEQ_TIMEOUT_STS BIT(0)
  48. #define QPNP_CONV_TIMEOUT_ERR 2
  49. #define QPNP_MODE_CTL 0x40
  50. #define QPNP_OP_MODE_SHIFT 3
  51. #define QPNP_VREF_XO_THM_FORCE BIT(2)
  52. #define QPNP_AMUX_TRIM_EN BIT(1)
  53. #define QPNP_ADC_TRIM_EN BIT(0)
  54. #define QPNP_EN_CTL1 0x46
  55. #define QPNP_ADC_TM_EN BIT(7)
  56. #define QPNP_ADC_CH_SEL_CTL 0x48
  57. #define QPNP_ADC_DIG_PARAM 0x50
  58. #define QPNP_ADC_DIG_DEC_RATIO_SEL_SHIFT 3
  59. #define QPNP_HW_SETTLE_DELAY 0x51
  60. #define QPNP_CONV_REQ 0x52
  61. #define QPNP_CONV_REQ_SET BIT(7)
  62. #define QPNP_CONV_SEQ_CTL 0x54
  63. #define QPNP_CONV_SEQ_HOLDOFF_SHIFT 4
  64. #define QPNP_CONV_SEQ_TRIG_CTL 0x55
  65. #define QPNP_ADC_TM_MEAS_INTERVAL_CTL 0x57
  66. #define QPNP_ADC_TM_MEAS_INTERVAL_TIME_SHIFT 0x3
  67. #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2 0x58
  68. #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2_SHIFT 0x4
  69. #define QPNP_ADC_TM_MEAS_INTERVAL_CTL2_MASK 0xf0
  70. #define QPNP_ADC_TM_MEAS_INTERVAL_CTL3_MASK 0xf
  71. #define QPNP_ADC_MEAS_INTERVAL_OP_CTL 0x59
  72. #define QPNP_ADC_MEAS_INTERVAL_OP BIT(7)
  73. #define QPNP_FAST_AVG_CTL 0x5a
  74. #define QPNP_FAST_AVG_EN 0x5b
  75. #define QPNP_M0_LOW_THR_LSB 0x5c
  76. #define QPNP_M0_LOW_THR_MSB 0x5d
  77. #define QPNP_M0_HIGH_THR_LSB 0x5e
  78. #define QPNP_M0_HIGH_THR_MSB 0x5f
  79. #define QPNP_M1_ADC_CH_SEL_CTL 0x68
  80. #define QPNP_M1_LOW_THR_LSB 0x69
  81. #define QPNP_M1_LOW_THR_MSB 0x6a
  82. #define QPNP_M1_HIGH_THR_LSB 0x6b
  83. #define QPNP_M1_HIGH_THR_MSB 0x6c
  84. #define QPNP_M2_ADC_CH_SEL_CTL 0x70
  85. #define QPNP_M2_LOW_THR_LSB 0x71
  86. #define QPNP_M2_LOW_THR_MSB 0x72
  87. #define QPNP_M2_HIGH_THR_LSB 0x73
  88. #define QPNP_M2_HIGH_THR_MSB 0x74
  89. #define QPNP_M3_ADC_CH_SEL_CTL 0x78
  90. #define QPNP_M3_LOW_THR_LSB 0x79
  91. #define QPNP_M3_LOW_THR_MSB 0x7a
  92. #define QPNP_M3_HIGH_THR_LSB 0x7b
  93. #define QPNP_M3_HIGH_THR_MSB 0x7c
  94. #define QPNP_M4_ADC_CH_SEL_CTL 0x80
  95. #define QPNP_M4_LOW_THR_LSB 0x81
  96. #define QPNP_M4_LOW_THR_MSB 0x82
  97. #define QPNP_M4_HIGH_THR_LSB 0x83
  98. #define QPNP_M4_HIGH_THR_MSB 0x84
  99. #define QPNP_M5_ADC_CH_SEL_CTL 0x88
  100. #define QPNP_M5_LOW_THR_LSB 0x89
  101. #define QPNP_M5_LOW_THR_MSB 0x8a
  102. #define QPNP_M5_HIGH_THR_LSB 0x8b
  103. #define QPNP_M5_HIGH_THR_MSB 0x8c
  104. #define QPNP_M6_ADC_CH_SEL_CTL 0x90
  105. #define QPNP_M6_LOW_THR_LSB 0x91
  106. #define QPNP_M6_LOW_THR_MSB 0x92
  107. #define QPNP_M6_HIGH_THR_LSB 0x93
  108. #define QPNP_M6_HIGH_THR_MSB 0x94
  109. #define QPNP_M7_ADC_CH_SEL_CTL 0x98
  110. #define QPNP_M7_LOW_THR_LSB 0x99
  111. #define QPNP_M7_LOW_THR_MSB 0x9a
  112. #define QPNP_M7_HIGH_THR_LSB 0x9b
  113. #define QPNP_M7_HIGH_THR_MSB 0x9c
  114. #define QPNP_ADC_TM_MULTI_MEAS_EN 0x41
  115. #define QPNP_ADC_TM_MULTI_MEAS_EN_M0 BIT(0)
  116. #define QPNP_ADC_TM_MULTI_MEAS_EN_M1 BIT(1)
  117. #define QPNP_ADC_TM_MULTI_MEAS_EN_M2 BIT(2)
  118. #define QPNP_ADC_TM_MULTI_MEAS_EN_M3 BIT(3)
  119. #define QPNP_ADC_TM_MULTI_MEAS_EN_M4 BIT(4)
  120. #define QPNP_ADC_TM_MULTI_MEAS_EN_M5 BIT(5)
  121. #define QPNP_ADC_TM_MULTI_MEAS_EN_M6 BIT(6)
  122. #define QPNP_ADC_TM_MULTI_MEAS_EN_M7 BIT(7)
  123. #define QPNP_ADC_TM_LOW_THR_INT_EN 0x42
  124. #define QPNP_ADC_TM_LOW_THR_INT_EN_M0 BIT(0)
  125. #define QPNP_ADC_TM_LOW_THR_INT_EN_M1 BIT(1)
  126. #define QPNP_ADC_TM_LOW_THR_INT_EN_M2 BIT(2)
  127. #define QPNP_ADC_TM_LOW_THR_INT_EN_M3 BIT(3)
  128. #define QPNP_ADC_TM_LOW_THR_INT_EN_M4 BIT(4)
  129. #define QPNP_ADC_TM_LOW_THR_INT_EN_M5 BIT(5)
  130. #define QPNP_ADC_TM_LOW_THR_INT_EN_M6 BIT(6)
  131. #define QPNP_ADC_TM_LOW_THR_INT_EN_M7 BIT(7)
  132. #define QPNP_ADC_TM_HIGH_THR_INT_EN 0x43
  133. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M0 BIT(0)
  134. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M1 BIT(1)
  135. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M2 BIT(2)
  136. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M3 BIT(3)
  137. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M4 BIT(4)
  138. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M5 BIT(5)
  139. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M6 BIT(6)
  140. #define QPNP_ADC_TM_HIGH_THR_INT_EN_M7 BIT(7)
  141. #define QPNP_ADC_TM_M0_MEAS_INTERVAL_CTL 0x59
  142. #define QPNP_ADC_TM_M1_MEAS_INTERVAL_CTL 0x6d
  143. #define QPNP_ADC_TM_M2_MEAS_INTERVAL_CTL 0x75
  144. #define QPNP_ADC_TM_M3_MEAS_INTERVAL_CTL 0x7d
  145. #define QPNP_ADC_TM_M4_MEAS_INTERVAL_CTL 0x85
  146. #define QPNP_ADC_TM_M5_MEAS_INTERVAL_CTL 0x8d
  147. #define QPNP_ADC_TM_M6_MEAS_INTERVAL_CTL 0x95
  148. #define QPNP_ADC_TM_M7_MEAS_INTERVAL_CTL 0x9d
  149. #define QPNP_ADC_TM_STATUS1 0x8
  150. #define QPNP_ADC_TM_STATUS_LOW 0xa
  151. #define QPNP_ADC_TM_STATUS_HIGH 0xb
  152. #define QPNP_ADC_TM_M0_LOW_THR 0x5d5c
  153. #define QPNP_ADC_TM_M0_HIGH_THR 0x5f5e
  154. #define QPNP_ADC_TM_MEAS_INTERVAL 0x0
  155. #define QPNP_ADC_TM_THR_LSB_MASK(val) (val & 0xff)
  156. #define QPNP_ADC_TM_THR_MSB_MASK(val) ((val & 0xff00) >> 8)
  157. #define QPNP_MIN_TIME 2000
  158. #define QPNP_MAX_TIME 2100
  159. struct qpnp_adc_thr_client_info {
  160. struct list_head list;
  161. struct qpnp_adc_tm_btm_param *btm_param;
  162. int32_t low_thr_requested;
  163. int32_t high_thr_requested;
  164. enum qpnp_state_request state_requested;
  165. enum qpnp_state_request state_req_copy;
  166. bool low_thr_set;
  167. bool high_thr_set;
  168. bool notify_low_thr;
  169. bool notify_high_thr;
  170. };
  171. struct qpnp_adc_tm_sensor {
  172. struct thermal_zone_device *tz_dev;
  173. struct qpnp_adc_tm_chip *chip;
  174. enum thermal_device_mode mode;
  175. uint32_t sensor_num;
  176. enum qpnp_adc_meas_timer_select timer_select;
  177. uint32_t meas_interval;
  178. uint32_t low_thr;
  179. uint32_t high_thr;
  180. uint32_t btm_channel_num;
  181. uint32_t vadc_channel_num;
  182. struct work_struct work;
  183. bool thermal_node;
  184. uint32_t scale_type;
  185. struct list_head thr_list;
  186. };
  187. struct qpnp_adc_tm_chip {
  188. struct device *dev;
  189. struct qpnp_adc_drv *adc;
  190. struct list_head list;
  191. bool adc_tm_initialized;
  192. int max_channels_available;
  193. struct qpnp_vadc_chip *vadc_dev;
  194. struct work_struct trigger_high_thr_work;
  195. struct work_struct trigger_low_thr_work;
  196. struct qpnp_adc_tm_sensor sensor[0];
  197. };
  198. LIST_HEAD(qpnp_adc_tm_device_list);
  199. struct qpnp_adc_tm_trip_reg_type {
  200. enum qpnp_adc_tm_channel_select btm_amux_chan;
  201. uint16_t low_thr_lsb_addr;
  202. uint16_t low_thr_msb_addr;
  203. uint16_t high_thr_lsb_addr;
  204. uint16_t high_thr_msb_addr;
  205. u8 multi_meas_en;
  206. u8 low_thr_int_chan_en;
  207. u8 high_thr_int_chan_en;
  208. u8 meas_interval_ctl;
  209. };
  210. static struct qpnp_adc_tm_trip_reg_type adc_tm_data[] = {
  211. [QPNP_ADC_TM_CHAN0] = {QPNP_ADC_TM_M0_ADC_CH_SEL_CTL,
  212. QPNP_M0_LOW_THR_LSB,
  213. QPNP_M0_LOW_THR_MSB, QPNP_M0_HIGH_THR_LSB,
  214. QPNP_M0_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M0,
  215. QPNP_ADC_TM_LOW_THR_INT_EN_M0, QPNP_ADC_TM_HIGH_THR_INT_EN_M0,
  216. QPNP_ADC_TM_M0_MEAS_INTERVAL_CTL},
  217. [QPNP_ADC_TM_CHAN1] = {QPNP_ADC_TM_M1_ADC_CH_SEL_CTL,
  218. QPNP_M1_LOW_THR_LSB,
  219. QPNP_M1_LOW_THR_MSB, QPNP_M1_HIGH_THR_LSB,
  220. QPNP_M1_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M1,
  221. QPNP_ADC_TM_LOW_THR_INT_EN_M1, QPNP_ADC_TM_HIGH_THR_INT_EN_M1,
  222. QPNP_ADC_TM_M1_MEAS_INTERVAL_CTL},
  223. [QPNP_ADC_TM_CHAN2] = {QPNP_ADC_TM_M2_ADC_CH_SEL_CTL,
  224. QPNP_M2_LOW_THR_LSB,
  225. QPNP_M2_LOW_THR_MSB, QPNP_M2_HIGH_THR_LSB,
  226. QPNP_M2_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M2,
  227. QPNP_ADC_TM_LOW_THR_INT_EN_M2, QPNP_ADC_TM_HIGH_THR_INT_EN_M2,
  228. QPNP_ADC_TM_M2_MEAS_INTERVAL_CTL},
  229. [QPNP_ADC_TM_CHAN3] = {QPNP_ADC_TM_M3_ADC_CH_SEL_CTL,
  230. QPNP_M3_LOW_THR_LSB,
  231. QPNP_M3_LOW_THR_MSB, QPNP_M3_HIGH_THR_LSB,
  232. QPNP_M3_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M3,
  233. QPNP_ADC_TM_LOW_THR_INT_EN_M3, QPNP_ADC_TM_HIGH_THR_INT_EN_M3,
  234. QPNP_ADC_TM_M3_MEAS_INTERVAL_CTL},
  235. [QPNP_ADC_TM_CHAN4] = {QPNP_ADC_TM_M4_ADC_CH_SEL_CTL,
  236. QPNP_M4_LOW_THR_LSB,
  237. QPNP_M4_LOW_THR_MSB, QPNP_M4_HIGH_THR_LSB,
  238. QPNP_M4_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M4,
  239. QPNP_ADC_TM_LOW_THR_INT_EN_M4, QPNP_ADC_TM_HIGH_THR_INT_EN_M4,
  240. QPNP_ADC_TM_M4_MEAS_INTERVAL_CTL},
  241. [QPNP_ADC_TM_CHAN5] = {QPNP_ADC_TM_M5_ADC_CH_SEL_CTL,
  242. QPNP_M5_LOW_THR_LSB,
  243. QPNP_M5_LOW_THR_MSB, QPNP_M5_HIGH_THR_LSB,
  244. QPNP_M5_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M5,
  245. QPNP_ADC_TM_LOW_THR_INT_EN_M5, QPNP_ADC_TM_HIGH_THR_INT_EN_M5,
  246. QPNP_ADC_TM_M5_MEAS_INTERVAL_CTL},
  247. [QPNP_ADC_TM_CHAN6] = {QPNP_ADC_TM_M6_ADC_CH_SEL_CTL,
  248. QPNP_M6_LOW_THR_LSB,
  249. QPNP_M6_LOW_THR_MSB, QPNP_M6_HIGH_THR_LSB,
  250. QPNP_M6_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M6,
  251. QPNP_ADC_TM_LOW_THR_INT_EN_M6, QPNP_ADC_TM_HIGH_THR_INT_EN_M6,
  252. QPNP_ADC_TM_M6_MEAS_INTERVAL_CTL},
  253. [QPNP_ADC_TM_CHAN7] = {QPNP_ADC_TM_M7_ADC_CH_SEL_CTL,
  254. QPNP_M7_LOW_THR_LSB,
  255. QPNP_M7_LOW_THR_MSB, QPNP_M7_HIGH_THR_LSB,
  256. QPNP_M7_HIGH_THR_MSB, QPNP_ADC_TM_MULTI_MEAS_EN_M7,
  257. QPNP_ADC_TM_LOW_THR_INT_EN_M7, QPNP_ADC_TM_HIGH_THR_INT_EN_M7,
  258. QPNP_ADC_TM_M7_MEAS_INTERVAL_CTL},
  259. };
  260. static struct qpnp_adc_tm_reverse_scale_fn adc_tm_rscale_fn[] = {
  261. [SCALE_R_VBATT] = {qpnp_adc_vbatt_rscaler},
  262. [SCALE_RBATT_THERM] = {qpnp_adc_btm_scaler},
  263. [SCALE_R_USB_ID] = {qpnp_adc_usb_scaler},
  264. [SCALE_RPMIC_THERM] = {qpnp_adc_scale_millidegc_pmic_voltage_thr},
  265. };
  266. static int32_t qpnp_adc_tm_read_reg(struct qpnp_adc_tm_chip *chip,
  267. int16_t reg, u8 *data)
  268. {
  269. int rc = 0;
  270. rc = spmi_ext_register_readl(chip->adc->spmi->ctrl,
  271. chip->adc->slave, (chip->adc->offset + reg), data, 1);
  272. if (rc < 0)
  273. pr_err("adc-tm read reg %d failed with %d\n", reg, rc);
  274. return rc;
  275. }
  276. static int32_t qpnp_adc_tm_write_reg(struct qpnp_adc_tm_chip *chip,
  277. int16_t reg, u8 data)
  278. {
  279. int rc = 0;
  280. u8 *buf;
  281. buf = &data;
  282. rc = spmi_ext_register_writel(chip->adc->spmi->ctrl,
  283. chip->adc->slave, (chip->adc->offset + reg), buf, 1);
  284. if (rc < 0)
  285. pr_err("adc-tm write reg %d failed with %d\n", reg, rc);
  286. return rc;
  287. }
  288. static int32_t qpnp_adc_tm_enable(struct qpnp_adc_tm_chip *chip)
  289. {
  290. int rc = 0;
  291. u8 data = 0;
  292. data = QPNP_ADC_TM_EN;
  293. rc = qpnp_adc_tm_write_reg(chip, QPNP_EN_CTL1, data);
  294. if (rc < 0)
  295. pr_err("adc-tm enable failed\n");
  296. return rc;
  297. }
  298. static int32_t qpnp_adc_tm_disable(struct qpnp_adc_tm_chip *chip)
  299. {
  300. u8 data = 0;
  301. int rc = 0;
  302. rc = qpnp_adc_tm_write_reg(chip, QPNP_EN_CTL1, data);
  303. if (rc < 0)
  304. pr_err("adc-tm disable failed\n");
  305. return rc;
  306. }
  307. static int qpnp_adc_tm_is_valid(struct qpnp_adc_tm_chip *chip)
  308. {
  309. struct qpnp_adc_tm_chip *adc_tm_chip = NULL;
  310. list_for_each_entry(adc_tm_chip, &qpnp_adc_tm_device_list, list)
  311. if (chip == adc_tm_chip)
  312. return 0;
  313. return -EINVAL;
  314. }
  315. static int32_t qpnp_adc_tm_enable_if_channel_meas(
  316. struct qpnp_adc_tm_chip *chip)
  317. {
  318. u8 adc_tm_meas_en = 0;
  319. int rc = 0;
  320. /* Check if a measurement request is still required */
  321. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN,
  322. &adc_tm_meas_en);
  323. if (rc) {
  324. pr_err("adc-tm-tm read status high failed with %d\n", rc);
  325. return rc;
  326. }
  327. /* Enable only if there are pending measurement requests */
  328. if (adc_tm_meas_en) {
  329. qpnp_adc_tm_enable(chip);
  330. /* Request conversion */
  331. rc = qpnp_adc_tm_write_reg(chip, QPNP_CONV_REQ,
  332. QPNP_CONV_REQ_SET);
  333. if (rc < 0) {
  334. pr_err("adc-tm request conversion failed\n");
  335. return rc;
  336. }
  337. }
  338. return rc;
  339. }
  340. static int32_t qpnp_adc_tm_req_sts_check(struct qpnp_adc_tm_chip *chip)
  341. {
  342. u8 status1;
  343. int rc, count = 0;
  344. /* The VADC_TM bank needs to be disabled for new conversion request */
  345. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1);
  346. if (rc) {
  347. pr_err("adc-tm read status1 failed\n");
  348. return rc;
  349. }
  350. /* Disable the bank if a conversion is occuring */
  351. while ((status1 & QPNP_STATUS1_REQ_STS) && (count < 5)) {
  352. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS1, &status1);
  353. if (rc < 0)
  354. pr_err("adc-tm disable failed\n");
  355. /* Wait time is based on the optimum sampling rate
  356. * and adding enough time buffer to account for ADC conversions
  357. * occuring on different peripheral banks */
  358. usleep_range(QPNP_MIN_TIME, QPNP_MAX_TIME);
  359. count++;
  360. }
  361. return rc;
  362. }
  363. static int32_t qpnp_adc_tm_get_btm_idx(uint32_t btm_chan,
  364. uint32_t *btm_chan_idx)
  365. {
  366. int rc = 0, i;
  367. bool chan_found = false;
  368. for (i = 0; i < QPNP_ADC_TM_CHAN_NONE; i++) {
  369. if (adc_tm_data[i].btm_amux_chan == btm_chan) {
  370. *btm_chan_idx = i;
  371. chan_found = true;
  372. }
  373. }
  374. if (!chan_found)
  375. return -EINVAL;
  376. return rc;
  377. }
  378. static int32_t qpnp_adc_tm_check_revision(struct qpnp_adc_tm_chip *chip,
  379. uint32_t btm_chan_num)
  380. {
  381. u8 rev, perph_subtype;
  382. int rc = 0;
  383. rc = qpnp_adc_tm_read_reg(chip, QPNP_REVISION3, &rev);
  384. if (rc) {
  385. pr_err("adc-tm revision read failed\n");
  386. return rc;
  387. }
  388. rc = qpnp_adc_tm_read_reg(chip, QPNP_PERPH_SUBTYPE, &perph_subtype);
  389. if (rc) {
  390. pr_err("adc-tm perph_subtype read failed\n");
  391. return rc;
  392. }
  393. if (perph_subtype == QPNP_PERPH_TYPE2) {
  394. if ((rev < QPNP_REVISION_EIGHT_CHANNEL_SUPPORT) &&
  395. (btm_chan_num > QPNP_ADC_TM_M4_ADC_CH_SEL_CTL)) {
  396. pr_debug("Version does not support more than 5 channels\n");
  397. return -EINVAL;
  398. }
  399. }
  400. return rc;
  401. }
  402. static int32_t qpnp_adc_tm_mode_select(struct qpnp_adc_tm_chip *chip,
  403. u8 mode_ctl)
  404. {
  405. int rc;
  406. mode_ctl |= (QPNP_ADC_TRIM_EN | QPNP_AMUX_TRIM_EN);
  407. /* VADC_BTM current sets mode to recurring measurements */
  408. rc = qpnp_adc_tm_write_reg(chip, QPNP_MODE_CTL, mode_ctl);
  409. if (rc < 0)
  410. pr_err("adc-tm write mode selection err\n");
  411. return rc;
  412. }
  413. static int32_t qpnp_adc_tm_timer_interval_select(
  414. struct qpnp_adc_tm_chip *chip, uint32_t btm_chan,
  415. struct qpnp_vadc_chan_properties *chan_prop)
  416. {
  417. int rc, chan_idx = 0, i = 0;
  418. bool chan_found = false;
  419. u8 meas_interval_timer2 = 0, timer_interval_store = 0;
  420. uint32_t btm_chan_idx = 0;
  421. while (i < chip->max_channels_available) {
  422. if (chip->sensor[i].btm_channel_num == btm_chan) {
  423. chan_idx = i;
  424. chan_found = true;
  425. i++;
  426. } else
  427. i++;
  428. }
  429. if (!chan_found) {
  430. pr_err("Channel not found\n");
  431. return -EINVAL;
  432. }
  433. switch (chip->sensor[chan_idx].timer_select) {
  434. case ADC_MEAS_TIMER_SELECT1:
  435. rc = qpnp_adc_tm_write_reg(chip,
  436. QPNP_ADC_TM_MEAS_INTERVAL_CTL,
  437. chip->sensor[chan_idx].meas_interval);
  438. if (rc < 0) {
  439. pr_err("timer1 configure failed\n");
  440. return rc;
  441. }
  442. break;
  443. case ADC_MEAS_TIMER_SELECT2:
  444. /* Thermal channels uses timer2, default to 1 second */
  445. rc = qpnp_adc_tm_read_reg(chip,
  446. QPNP_ADC_TM_MEAS_INTERVAL_CTL2,
  447. &meas_interval_timer2);
  448. if (rc < 0) {
  449. pr_err("timer2 configure read failed\n");
  450. return rc;
  451. }
  452. timer_interval_store = chip->sensor[chan_idx].meas_interval;
  453. timer_interval_store <<= QPNP_ADC_TM_MEAS_INTERVAL_CTL2_SHIFT;
  454. timer_interval_store &= QPNP_ADC_TM_MEAS_INTERVAL_CTL2_MASK;
  455. meas_interval_timer2 |= timer_interval_store;
  456. rc = qpnp_adc_tm_write_reg(chip,
  457. QPNP_ADC_TM_MEAS_INTERVAL_CTL2,
  458. meas_interval_timer2);
  459. if (rc < 0) {
  460. pr_err("timer2 configure failed\n");
  461. return rc;
  462. }
  463. break;
  464. case ADC_MEAS_TIMER_SELECT3:
  465. rc = qpnp_adc_tm_read_reg(chip,
  466. QPNP_ADC_TM_MEAS_INTERVAL_CTL2,
  467. &meas_interval_timer2);
  468. if (rc < 0) {
  469. pr_err("timer3 read failed\n");
  470. return rc;
  471. }
  472. timer_interval_store = chip->sensor[chan_idx].meas_interval;
  473. timer_interval_store &= QPNP_ADC_TM_MEAS_INTERVAL_CTL3_MASK;
  474. meas_interval_timer2 |= timer_interval_store;
  475. rc = qpnp_adc_tm_write_reg(chip,
  476. QPNP_ADC_TM_MEAS_INTERVAL_CTL2,
  477. meas_interval_timer2);
  478. if (rc < 0) {
  479. pr_err("timer3 configure failed\n");
  480. return rc;
  481. }
  482. break;
  483. default:
  484. pr_err("Invalid timer selection\n");
  485. return -EINVAL;
  486. }
  487. /* Select the timer to use for the corresponding channel */
  488. rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx);
  489. if (rc < 0) {
  490. pr_err("Invalid btm channel idx\n");
  491. return rc;
  492. }
  493. rc = qpnp_adc_tm_write_reg(chip,
  494. adc_tm_data[btm_chan_idx].meas_interval_ctl,
  495. chip->sensor[chan_idx].timer_select);
  496. if (rc < 0) {
  497. pr_err("TM channel timer configure failed\n");
  498. return rc;
  499. }
  500. pr_debug("timer select:%d, timer_value_within_select:%d, channel:%x\n",
  501. chip->sensor[chan_idx].timer_select,
  502. chip->sensor[chan_idx].meas_interval,
  503. btm_chan);
  504. return rc;
  505. }
  506. static int32_t qpnp_adc_tm_add_to_list(struct qpnp_adc_tm_chip *chip,
  507. uint32_t dt_index,
  508. struct qpnp_adc_tm_btm_param *param,
  509. struct qpnp_vadc_chan_properties *chan_prop)
  510. {
  511. struct qpnp_adc_thr_client_info *client_info = NULL;
  512. bool client_info_exists = false;
  513. list_for_each_entry(client_info,
  514. &chip->sensor[dt_index].thr_list, list) {
  515. if (client_info->btm_param == param) {
  516. client_info->low_thr_requested = chan_prop->low_thr;
  517. client_info->high_thr_requested = chan_prop->high_thr;
  518. client_info->state_requested = param->state_request;
  519. client_info->state_req_copy = param->state_request;
  520. client_info->notify_low_thr = false;
  521. client_info->notify_high_thr = false;
  522. client_info_exists = true;
  523. pr_debug("client found\n");
  524. }
  525. }
  526. if (!client_info_exists) {
  527. client_info = devm_kzalloc(chip->dev,
  528. sizeof(struct qpnp_adc_thr_client_info), GFP_KERNEL);
  529. if (!client_info) {
  530. pr_err("%s: kzalloc() failed.\n", __func__);
  531. return -ENOMEM;
  532. }
  533. pr_debug("new client\n");
  534. client_info->btm_param = param;
  535. client_info->low_thr_requested = chan_prop->low_thr;
  536. client_info->high_thr_requested = chan_prop->high_thr;
  537. client_info->state_requested = param->state_request;
  538. client_info->state_req_copy = param->state_request;
  539. list_add_tail(&client_info->list,
  540. &chip->sensor[dt_index].thr_list);
  541. }
  542. return 0;
  543. }
  544. static int32_t qpnp_adc_tm_reg_update(struct qpnp_adc_tm_chip *chip,
  545. uint16_t addr, u8 mask, bool state)
  546. {
  547. u8 reg_value = 0;
  548. int rc = 0;
  549. rc = qpnp_adc_tm_read_reg(chip, addr, &reg_value);
  550. if (rc < 0) {
  551. pr_err("read failed for addr:0x%x\n", addr);
  552. return rc;
  553. }
  554. reg_value = reg_value & ~mask;
  555. if (state)
  556. reg_value |= mask;
  557. pr_debug("state:%d, reg:0x%x with bits:0x%x and mask:0x%x\n",
  558. state, addr, reg_value, ~mask);
  559. rc = qpnp_adc_tm_write_reg(chip, addr, reg_value);
  560. if (rc < 0) {
  561. pr_err("write failed for addr:%x\n", addr);
  562. return rc;
  563. }
  564. return rc;
  565. }
  566. static int32_t qpnp_adc_tm_thr_update(struct qpnp_adc_tm_chip *chip,
  567. uint32_t btm_chan, int32_t high_thr, int32_t low_thr)
  568. {
  569. int rc = 0;
  570. uint32_t btm_chan_idx = 0;
  571. rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx);
  572. if (rc < 0) {
  573. pr_err("Invalid btm channel idx\n");
  574. return rc;
  575. }
  576. rc = qpnp_adc_tm_write_reg(chip,
  577. adc_tm_data[btm_chan_idx].low_thr_lsb_addr,
  578. QPNP_ADC_TM_THR_LSB_MASK(low_thr));
  579. if (rc < 0) {
  580. pr_err("low threshold lsb setting failed\n");
  581. return rc;
  582. }
  583. rc = qpnp_adc_tm_write_reg(chip,
  584. adc_tm_data[btm_chan_idx].low_thr_msb_addr,
  585. QPNP_ADC_TM_THR_MSB_MASK(low_thr));
  586. if (rc < 0) {
  587. pr_err("low threshold msb setting failed\n");
  588. return rc;
  589. }
  590. rc = qpnp_adc_tm_write_reg(chip,
  591. adc_tm_data[btm_chan_idx].high_thr_lsb_addr,
  592. QPNP_ADC_TM_THR_LSB_MASK(high_thr));
  593. if (rc < 0) {
  594. pr_err("high threshold lsb setting failed\n");
  595. return rc;
  596. }
  597. rc = qpnp_adc_tm_write_reg(chip,
  598. adc_tm_data[btm_chan_idx].high_thr_msb_addr,
  599. QPNP_ADC_TM_THR_MSB_MASK(high_thr));
  600. if (rc < 0)
  601. pr_err("high threshold msb setting failed\n");
  602. pr_debug("client requested high:%d and low:%d\n",
  603. high_thr, low_thr);
  604. return rc;
  605. }
  606. static int32_t qpnp_adc_tm_manage_thresholds(struct qpnp_adc_tm_chip *chip,
  607. uint32_t dt_index, uint32_t btm_chan)
  608. {
  609. struct qpnp_adc_thr_client_info *client_info = NULL;
  610. struct list_head *thr_list;
  611. int high_thr = 0, low_thr = 0, rc = 0;
  612. /* high_thr/low_thr starting point and reset the high_thr_set and
  613. low_thr_set back to reset since the thresholds will be
  614. recomputed */
  615. list_for_each(thr_list,
  616. &chip->sensor[dt_index].thr_list) {
  617. client_info = list_entry(thr_list,
  618. struct qpnp_adc_thr_client_info, list);
  619. high_thr = client_info->high_thr_requested;
  620. low_thr = client_info->low_thr_requested;
  621. client_info->high_thr_set = false;
  622. client_info->low_thr_set = false;
  623. }
  624. pr_debug("init threshold is high:%d and low:%d\n", high_thr, low_thr);
  625. /* Find the min of high_thr and max of low_thr */
  626. list_for_each(thr_list,
  627. &chip->sensor[dt_index].thr_list) {
  628. client_info = list_entry(thr_list,
  629. struct qpnp_adc_thr_client_info, list);
  630. if ((client_info->state_req_copy == ADC_TM_HIGH_THR_ENABLE) ||
  631. (client_info->state_req_copy ==
  632. ADC_TM_HIGH_LOW_THR_ENABLE))
  633. if (client_info->high_thr_requested < high_thr)
  634. high_thr = client_info->high_thr_requested;
  635. if ((client_info->state_req_copy == ADC_TM_LOW_THR_ENABLE) ||
  636. (client_info->state_req_copy ==
  637. ADC_TM_HIGH_LOW_THR_ENABLE))
  638. if (client_info->low_thr_requested > low_thr)
  639. low_thr = client_info->low_thr_requested;
  640. pr_debug("threshold compared is high:%d and low:%d\n",
  641. client_info->high_thr_requested,
  642. client_info->low_thr_requested);
  643. pr_debug("current threshold is high:%d and low:%d\n",
  644. high_thr, low_thr);
  645. }
  646. /* Check which of the high_thr and low_thr got set */
  647. list_for_each(thr_list,
  648. &chip->sensor[dt_index].thr_list) {
  649. client_info = list_entry(thr_list,
  650. struct qpnp_adc_thr_client_info, list);
  651. if ((client_info->state_req_copy == ADC_TM_HIGH_THR_ENABLE) ||
  652. (client_info->state_req_copy ==
  653. ADC_TM_HIGH_LOW_THR_ENABLE))
  654. if (high_thr == client_info->high_thr_requested)
  655. client_info->high_thr_set = true;
  656. if ((client_info->state_req_copy == ADC_TM_LOW_THR_ENABLE) ||
  657. (client_info->state_req_copy ==
  658. ADC_TM_HIGH_LOW_THR_ENABLE))
  659. if (low_thr == client_info->low_thr_requested)
  660. client_info->low_thr_set = true;
  661. }
  662. rc = qpnp_adc_tm_thr_update(chip, btm_chan, high_thr, low_thr);
  663. if (rc < 0)
  664. pr_err("setting chan:%d threshold failed\n", btm_chan);
  665. pr_debug("threshold written is high:%d and low:%d\n",
  666. high_thr, low_thr);
  667. return 0;
  668. }
  669. static int32_t qpnp_adc_tm_channel_configure(struct qpnp_adc_tm_chip *chip,
  670. uint32_t btm_chan,
  671. struct qpnp_vadc_chan_properties *chan_prop,
  672. uint32_t amux_channel)
  673. {
  674. int rc = 0, i = 0, chan_idx = 0;
  675. bool chan_found = false, high_thr_set = false, low_thr_set = false;
  676. u8 sensor_mask = 0;
  677. struct qpnp_adc_thr_client_info *client_info = NULL;
  678. while (i < chip->max_channels_available) {
  679. if (chip->sensor[i].btm_channel_num == btm_chan) {
  680. chan_idx = i;
  681. chan_found = true;
  682. i++;
  683. } else
  684. i++;
  685. }
  686. if (!chan_found) {
  687. pr_err("Channel not found\n");
  688. return -EINVAL;
  689. }
  690. sensor_mask = 1 << chan_idx;
  691. if (!chip->sensor[chan_idx].thermal_node) {
  692. /* Update low and high notification thresholds */
  693. rc = qpnp_adc_tm_manage_thresholds(chip, chan_idx,
  694. btm_chan);
  695. if (rc < 0) {
  696. pr_err("setting chan:%d threshold failed\n", btm_chan);
  697. return rc;
  698. }
  699. list_for_each_entry(client_info,
  700. &chip->sensor[chan_idx].thr_list, list) {
  701. if (client_info->high_thr_set == true)
  702. high_thr_set = true;
  703. if (client_info->low_thr_set == true)
  704. low_thr_set = true;
  705. }
  706. if (low_thr_set) {
  707. pr_debug("low sensor mask:%x with state:%d\n",
  708. sensor_mask, chan_prop->state_request);
  709. /* Enable low threshold's interrupt */
  710. rc = qpnp_adc_tm_reg_update(chip,
  711. QPNP_ADC_TM_LOW_THR_INT_EN, sensor_mask, true);
  712. if (rc < 0) {
  713. pr_err("low thr enable err:%d\n", btm_chan);
  714. return rc;
  715. }
  716. }
  717. if (high_thr_set) {
  718. /* Enable high threshold's interrupt */
  719. pr_debug("high sensor mask:%x\n", sensor_mask);
  720. rc = qpnp_adc_tm_reg_update(chip,
  721. QPNP_ADC_TM_HIGH_THR_INT_EN, sensor_mask, true);
  722. if (rc < 0) {
  723. pr_err("high thr enable err:%d\n", btm_chan);
  724. return rc;
  725. }
  726. }
  727. }
  728. /* Enable corresponding BTM channel measurement */
  729. rc = qpnp_adc_tm_reg_update(chip,
  730. QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, true);
  731. if (rc < 0) {
  732. pr_err("multi measurement en failed\n");
  733. return rc;
  734. }
  735. return rc;
  736. }
  737. static int32_t qpnp_adc_tm_configure(struct qpnp_adc_tm_chip *chip,
  738. struct qpnp_adc_amux_properties *chan_prop)
  739. {
  740. u8 decimation = 0, op_cntrl = 0;
  741. int rc = 0;
  742. uint32_t btm_chan = 0;
  743. /* Disable bank */
  744. rc = qpnp_adc_tm_disable(chip);
  745. if (rc)
  746. return rc;
  747. /* Check if a conversion is in progress */
  748. rc = qpnp_adc_tm_req_sts_check(chip);
  749. if (rc < 0) {
  750. pr_err("adc-tm req_sts check failed\n");
  751. return rc;
  752. }
  753. /* Set measurement in recurring mode */
  754. rc = qpnp_adc_tm_mode_select(chip, chan_prop->mode_sel);
  755. if (rc < 0) {
  756. pr_err("adc-tm mode select failed\n");
  757. return rc;
  758. }
  759. /* Configure AMUX channel select for the corresponding BTM channel*/
  760. btm_chan = chan_prop->chan_prop->tm_channel_select;
  761. rc = qpnp_adc_tm_write_reg(chip, btm_chan, chan_prop->amux_channel);
  762. if (rc < 0) {
  763. pr_err("adc-tm channel selection err\n");
  764. return rc;
  765. }
  766. /* Digital paramater setup */
  767. decimation |= chan_prop->decimation <<
  768. QPNP_ADC_DIG_DEC_RATIO_SEL_SHIFT;
  769. rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_DIG_PARAM, decimation);
  770. if (rc < 0) {
  771. pr_err("adc-tm digital parameter setup err\n");
  772. return rc;
  773. }
  774. /* Hardware setting time */
  775. #ifdef CONFIG_MACH_ATLANTICLTE_ATT
  776. rc = qpnp_adc_tm_write_reg(chip, QPNP_HW_SETTLE_DELAY, 0xF);
  777. #else
  778. rc = qpnp_adc_tm_write_reg(chip, QPNP_HW_SETTLE_DELAY,
  779. chan_prop->hw_settle_time);
  780. #endif
  781. if (rc < 0) {
  782. pr_err("adc-tm hw settling time setup err\n");
  783. return rc;
  784. }
  785. /* Fast averaging setup */
  786. rc = qpnp_adc_tm_write_reg(chip, QPNP_FAST_AVG_CTL,
  787. chan_prop->fast_avg_setup);
  788. if (rc < 0) {
  789. pr_err("adc-tm fast-avg setup err\n");
  790. return rc;
  791. }
  792. /* Measurement interval setup */
  793. rc = qpnp_adc_tm_timer_interval_select(chip, btm_chan,
  794. chan_prop->chan_prop);
  795. if (rc < 0) {
  796. pr_err("adc-tm timer select failed\n");
  797. return rc;
  798. }
  799. /* Channel configuration setup */
  800. rc = qpnp_adc_tm_channel_configure(chip, btm_chan,
  801. chan_prop->chan_prop, chan_prop->amux_channel);
  802. if (rc < 0) {
  803. pr_err("adc-tm channel configure failed\n");
  804. return rc;
  805. }
  806. /* Recurring interval measurement enable */
  807. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_MEAS_INTERVAL_OP_CTL,
  808. &op_cntrl);
  809. op_cntrl |= QPNP_ADC_MEAS_INTERVAL_OP;
  810. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_MEAS_INTERVAL_OP_CTL,
  811. op_cntrl, true);
  812. if (rc < 0) {
  813. pr_err("adc-tm meas interval op configure failed\n");
  814. return rc;
  815. }
  816. /* Enable bank */
  817. rc = qpnp_adc_tm_enable(chip);
  818. if (rc)
  819. return rc;
  820. /* Request conversion */
  821. rc = qpnp_adc_tm_write_reg(chip, QPNP_CONV_REQ, QPNP_CONV_REQ_SET);
  822. if (rc < 0) {
  823. pr_err("adc-tm request conversion failed\n");
  824. return rc;
  825. }
  826. return 0;
  827. }
  828. static int qpnp_adc_tm_get_mode(struct thermal_zone_device *thermal,
  829. enum thermal_device_mode *mode)
  830. {
  831. struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata;
  832. if ((IS_ERR(adc_tm)) || qpnp_adc_tm_check_revision(
  833. adc_tm->chip, adc_tm->btm_channel_num))
  834. return -EINVAL;
  835. *mode = adc_tm->mode;
  836. return 0;
  837. }
  838. static int qpnp_adc_tm_set_mode(struct thermal_zone_device *thermal,
  839. enum thermal_device_mode mode)
  840. {
  841. struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata;
  842. struct qpnp_adc_tm_chip *chip = adc_tm->chip;
  843. int rc = 0, channel;
  844. u8 sensor_mask = 0;
  845. if (qpnp_adc_tm_is_valid(chip)) {
  846. pr_err("invalid device\n");
  847. return -ENODEV;
  848. }
  849. if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num))
  850. return -EINVAL;
  851. if (mode == THERMAL_DEVICE_ENABLED) {
  852. chip->adc->amux_prop->amux_channel =
  853. adc_tm->vadc_channel_num;
  854. channel = adc_tm->sensor_num;
  855. chip->adc->amux_prop->decimation =
  856. chip->adc->adc_channels[channel].adc_decimation;
  857. chip->adc->amux_prop->hw_settle_time =
  858. chip->adc->adc_channels[channel].hw_settle_time;
  859. chip->adc->amux_prop->fast_avg_setup =
  860. chip->adc->adc_channels[channel].fast_avg_setup;
  861. chip->adc->amux_prop->mode_sel =
  862. ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT;
  863. chip->adc->amux_prop->chan_prop->low_thr = adc_tm->low_thr;
  864. chip->adc->amux_prop->chan_prop->high_thr = adc_tm->high_thr;
  865. chip->adc->amux_prop->chan_prop->tm_channel_select =
  866. adc_tm->btm_channel_num;
  867. rc = qpnp_adc_tm_configure(chip, chip->adc->amux_prop);
  868. if (rc) {
  869. pr_err("adc-tm tm configure failed with %d\n", rc);
  870. return -EINVAL;
  871. }
  872. } else if (mode == THERMAL_DEVICE_DISABLED) {
  873. sensor_mask = 1 << adc_tm->sensor_num;
  874. /* Disable bank */
  875. rc = qpnp_adc_tm_disable(chip);
  876. if (rc < 0) {
  877. pr_err("adc-tm disable failed\n");
  878. return rc;
  879. }
  880. /* Check if a conversion is in progress */
  881. rc = qpnp_adc_tm_req_sts_check(chip);
  882. if (rc < 0) {
  883. pr_err("adc-tm req_sts check failed\n");
  884. return rc;
  885. }
  886. rc = qpnp_adc_tm_reg_update(chip,
  887. QPNP_ADC_TM_MULTI_MEAS_EN, sensor_mask, false);
  888. if (rc < 0) {
  889. pr_err("multi measurement update failed\n");
  890. return rc;
  891. }
  892. rc = qpnp_adc_tm_enable_if_channel_meas(chip);
  893. if (rc < 0) {
  894. pr_err("re-enabling measurement failed\n");
  895. return rc;
  896. }
  897. }
  898. adc_tm->mode = mode;
  899. return 0;
  900. }
  901. static int qpnp_adc_tm_get_trip_type(struct thermal_zone_device *thermal,
  902. int trip, enum thermal_trip_type *type)
  903. {
  904. struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata;
  905. struct qpnp_adc_tm_chip *chip = adc_tm->chip;
  906. if (qpnp_adc_tm_is_valid(chip))
  907. return -ENODEV;
  908. if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num))
  909. return -EINVAL;
  910. switch (trip) {
  911. case ADC_TM_TRIP_HIGH_WARM:
  912. *type = THERMAL_TRIP_CONFIGURABLE_HI;
  913. break;
  914. case ADC_TM_TRIP_LOW_COOL:
  915. *type = THERMAL_TRIP_CONFIGURABLE_LOW;
  916. break;
  917. default:
  918. return -EINVAL;
  919. }
  920. return 0;
  921. }
  922. static int qpnp_adc_tm_get_trip_temp(struct thermal_zone_device *thermal,
  923. int trip, unsigned long *temp)
  924. {
  925. struct qpnp_adc_tm_sensor *adc_tm_sensor = thermal->devdata;
  926. struct qpnp_adc_tm_chip *chip = adc_tm_sensor->chip;
  927. int64_t result = 0;
  928. u8 trip_cool_thr0, trip_cool_thr1, trip_warm_thr0, trip_warm_thr1;
  929. unsigned int reg, rc = 0;
  930. uint16_t reg_low_thr_lsb, reg_low_thr_msb;
  931. uint16_t reg_high_thr_lsb, reg_high_thr_msb;
  932. uint32_t btm_chan_idx = 0, btm_chan = 0;
  933. if (qpnp_adc_tm_is_valid(chip))
  934. return -ENODEV;
  935. if (qpnp_adc_tm_check_revision(chip, adc_tm_sensor->btm_channel_num))
  936. return -EINVAL;
  937. btm_chan = adc_tm_sensor->btm_channel_num;
  938. rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx);
  939. if (rc < 0) {
  940. pr_err("Invalid btm channel idx\n");
  941. return rc;
  942. }
  943. reg_low_thr_lsb = adc_tm_data[btm_chan_idx].low_thr_lsb_addr;
  944. reg_low_thr_msb = adc_tm_data[btm_chan_idx].low_thr_msb_addr;
  945. reg_high_thr_lsb = adc_tm_data[btm_chan_idx].high_thr_lsb_addr;
  946. reg_high_thr_msb = adc_tm_data[btm_chan_idx].high_thr_msb_addr;
  947. switch (trip) {
  948. case ADC_TM_TRIP_HIGH_WARM:
  949. rc = qpnp_adc_tm_read_reg(chip, reg_low_thr_lsb,
  950. &trip_warm_thr0);
  951. if (rc) {
  952. pr_err("adc-tm low_thr_lsb err\n");
  953. return rc;
  954. }
  955. rc = qpnp_adc_tm_read_reg(chip, reg_low_thr_msb,
  956. &trip_warm_thr1);
  957. if (rc) {
  958. pr_err("adc-tm low_thr_msb err\n");
  959. return rc;
  960. }
  961. reg = (trip_warm_thr1 << 8) | trip_warm_thr0;
  962. break;
  963. case ADC_TM_TRIP_LOW_COOL:
  964. rc = qpnp_adc_tm_read_reg(chip, reg_high_thr_lsb,
  965. &trip_cool_thr0);
  966. if (rc) {
  967. pr_err("adc-tm_tm high_thr_lsb err\n");
  968. return rc;
  969. }
  970. rc = qpnp_adc_tm_read_reg(chip, reg_high_thr_msb,
  971. &trip_cool_thr1);
  972. if (rc) {
  973. pr_err("adc-tm_tm high_thr_lsb err\n");
  974. return rc;
  975. }
  976. reg = (trip_cool_thr1 << 8) | trip_cool_thr0;
  977. break;
  978. default:
  979. return -EINVAL;
  980. }
  981. rc = qpnp_adc_tm_scale_voltage_therm_pu2(chip->vadc_dev, reg,
  982. &result);
  983. if (rc < 0) {
  984. pr_err("Failed to lookup the therm thresholds\n");
  985. return rc;
  986. }
  987. *temp = result;
  988. return 0;
  989. }
  990. static int qpnp_adc_tm_set_trip_temp(struct thermal_zone_device *thermal,
  991. int trip, long temp)
  992. {
  993. struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata;
  994. struct qpnp_adc_tm_chip *chip = adc_tm->chip;
  995. struct qpnp_adc_tm_config tm_config;
  996. u8 trip_cool_thr0, trip_cool_thr1, trip_warm_thr0, trip_warm_thr1;
  997. uint16_t reg_low_thr_lsb, reg_low_thr_msb;
  998. uint16_t reg_high_thr_lsb, reg_high_thr_msb;
  999. int rc = 0;
  1000. uint32_t btm_chan = 0, btm_chan_idx = 0;
  1001. if (qpnp_adc_tm_is_valid(chip))
  1002. return -ENODEV;
  1003. if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num))
  1004. return -EINVAL;
  1005. tm_config.channel = adc_tm->vadc_channel_num;
  1006. switch (trip) {
  1007. case ADC_TM_TRIP_HIGH_WARM:
  1008. tm_config.high_thr_temp = temp;
  1009. break;
  1010. case ADC_TM_TRIP_LOW_COOL:
  1011. tm_config.low_thr_temp = temp;
  1012. break;
  1013. default:
  1014. return -EINVAL;
  1015. }
  1016. pr_debug("requested a high - %d and low - %d with trip - %d\n",
  1017. tm_config.high_thr_temp, tm_config.low_thr_temp, trip);
  1018. rc = qpnp_adc_tm_scale_therm_voltage_pu2(chip->vadc_dev, &tm_config);
  1019. if (rc < 0) {
  1020. pr_err("Failed to lookup the adc-tm thresholds\n");
  1021. return rc;
  1022. }
  1023. trip_warm_thr0 = ((tm_config.low_thr_voltage << 24) >> 24);
  1024. trip_warm_thr1 = ((tm_config.low_thr_voltage << 16) >> 24);
  1025. trip_cool_thr0 = ((tm_config.high_thr_voltage << 24) >> 24);
  1026. trip_cool_thr1 = ((tm_config.high_thr_voltage << 16) >> 24);
  1027. btm_chan = adc_tm->btm_channel_num;
  1028. rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx);
  1029. if (rc < 0) {
  1030. pr_err("Invalid btm channel idx\n");
  1031. return rc;
  1032. }
  1033. reg_low_thr_lsb = adc_tm_data[btm_chan_idx].low_thr_lsb_addr;
  1034. reg_low_thr_msb = adc_tm_data[btm_chan_idx].low_thr_msb_addr;
  1035. reg_high_thr_lsb = adc_tm_data[btm_chan_idx].high_thr_lsb_addr;
  1036. reg_high_thr_msb = adc_tm_data[btm_chan_idx].high_thr_msb_addr;
  1037. switch (trip) {
  1038. case ADC_TM_TRIP_HIGH_WARM:
  1039. rc = qpnp_adc_tm_write_reg(chip, reg_low_thr_lsb,
  1040. trip_cool_thr0);
  1041. if (rc) {
  1042. pr_err("adc-tm_tm read threshold err\n");
  1043. return rc;
  1044. }
  1045. rc = qpnp_adc_tm_write_reg(chip, reg_low_thr_msb,
  1046. trip_cool_thr1);
  1047. if (rc) {
  1048. pr_err("adc-tm_tm read threshold err\n");
  1049. return rc;
  1050. }
  1051. adc_tm->low_thr = tm_config.high_thr_voltage;
  1052. break;
  1053. case ADC_TM_TRIP_LOW_COOL:
  1054. rc = qpnp_adc_tm_write_reg(chip, reg_high_thr_lsb,
  1055. trip_warm_thr0);
  1056. if (rc) {
  1057. pr_err("adc-tm_tm read threshold err\n");
  1058. return rc;
  1059. }
  1060. rc = qpnp_adc_tm_write_reg(chip, reg_high_thr_msb,
  1061. trip_warm_thr1);
  1062. if (rc) {
  1063. pr_err("adc-tm_tm read threshold err\n");
  1064. return rc;
  1065. }
  1066. adc_tm->high_thr = tm_config.low_thr_voltage;
  1067. break;
  1068. default:
  1069. return -EINVAL;
  1070. }
  1071. return 0;
  1072. }
  1073. static void notify_battery_therm(struct qpnp_adc_tm_sensor *adc_tm)
  1074. {
  1075. struct qpnp_adc_thr_client_info *client_info = NULL;
  1076. list_for_each_entry(client_info,
  1077. &adc_tm->thr_list, list) {
  1078. /* Batt therm's warm temperature translates to low voltage */
  1079. if (client_info->notify_low_thr) {
  1080. /* HIGH_STATE = WARM_TEMP for battery client */
  1081. client_info->btm_param->threshold_notification(
  1082. ADC_TM_WARM_STATE, client_info->btm_param->btm_ctx);
  1083. client_info->notify_low_thr = false;
  1084. }
  1085. /* Batt therm's cool temperature translates to high voltage */
  1086. if (client_info->notify_high_thr) {
  1087. /* LOW_STATE = COOL_TEMP for battery client */
  1088. client_info->btm_param->threshold_notification(
  1089. ADC_TM_COOL_STATE, client_info->btm_param->btm_ctx);
  1090. client_info->notify_high_thr = false;
  1091. }
  1092. }
  1093. return;
  1094. }
  1095. static void notify_clients(struct qpnp_adc_tm_sensor *adc_tm)
  1096. {
  1097. struct qpnp_adc_thr_client_info *client_info = NULL;
  1098. list_for_each_entry(client_info,
  1099. &adc_tm->thr_list, list) {
  1100. /* For non batt therm clients */
  1101. if (client_info->notify_low_thr) {
  1102. if (client_info->btm_param->threshold_notification
  1103. != NULL) {
  1104. pr_debug("notify kernel with low state\n");
  1105. client_info->btm_param->threshold_notification(
  1106. ADC_TM_LOW_STATE,
  1107. client_info->btm_param->btm_ctx);
  1108. client_info->notify_low_thr = false;
  1109. }
  1110. }
  1111. if (client_info->notify_high_thr) {
  1112. if (client_info->btm_param->threshold_notification
  1113. != NULL) {
  1114. pr_debug("notify kernel with high state\n");
  1115. client_info->btm_param->threshold_notification(
  1116. ADC_TM_HIGH_STATE,
  1117. client_info->btm_param->btm_ctx);
  1118. client_info->notify_high_thr = false;
  1119. }
  1120. }
  1121. }
  1122. return;
  1123. }
  1124. static void notify_adc_tm_fn(struct work_struct *work)
  1125. {
  1126. struct qpnp_adc_tm_sensor *adc_tm = container_of(work,
  1127. struct qpnp_adc_tm_sensor, work);
  1128. if (adc_tm->thermal_node) {
  1129. sysfs_notify(&adc_tm->tz_dev->device.kobj,
  1130. NULL, "btm");
  1131. pr_debug("notifying uspace client\n");
  1132. } else {
  1133. if (adc_tm->scale_type == SCALE_RBATT_THERM)
  1134. notify_battery_therm(adc_tm);
  1135. else
  1136. notify_clients(adc_tm);
  1137. }
  1138. return;
  1139. }
  1140. static int qpnp_adc_tm_activate_trip_type(struct thermal_zone_device *thermal,
  1141. int trip, enum thermal_trip_activation_mode mode)
  1142. {
  1143. struct qpnp_adc_tm_sensor *adc_tm = thermal->devdata;
  1144. struct qpnp_adc_tm_chip *chip = adc_tm->chip;
  1145. int rc = 0, sensor_mask = 0;
  1146. u8 thr_int_en = 0;
  1147. bool state = false;
  1148. uint32_t btm_chan_idx = 0, btm_chan = 0;
  1149. if (qpnp_adc_tm_is_valid(chip))
  1150. return -ENODEV;
  1151. if (qpnp_adc_tm_check_revision(chip, adc_tm->btm_channel_num))
  1152. return -EINVAL;
  1153. if (mode == THERMAL_TRIP_ACTIVATION_ENABLED)
  1154. state = true;
  1155. sensor_mask = 1 << adc_tm->sensor_num;
  1156. pr_debug("Sensor number:%x with state:%d\n", adc_tm->sensor_num, state);
  1157. btm_chan = adc_tm->btm_channel_num;
  1158. rc = qpnp_adc_tm_get_btm_idx(btm_chan, &btm_chan_idx);
  1159. if (rc < 0) {
  1160. pr_err("Invalid btm channel idx\n");
  1161. return rc;
  1162. }
  1163. switch (trip) {
  1164. case ADC_TM_TRIP_HIGH_WARM:
  1165. /* low_thr (lower voltage) for higher temp */
  1166. thr_int_en = adc_tm_data[btm_chan_idx].low_thr_int_chan_en;
  1167. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN,
  1168. sensor_mask, state);
  1169. if (rc)
  1170. pr_err("channel:%x failed\n", btm_chan);
  1171. break;
  1172. case ADC_TM_TRIP_LOW_COOL:
  1173. /* high_thr (higher voltage) for cooler temp */
  1174. thr_int_en = adc_tm_data[btm_chan_idx].high_thr_int_chan_en;
  1175. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN,
  1176. sensor_mask, state);
  1177. if (rc)
  1178. pr_err("channel:%x failed\n", btm_chan);
  1179. break;
  1180. default:
  1181. return -EINVAL;
  1182. }
  1183. return rc;
  1184. }
  1185. static int qpnp_adc_tm_read_status(struct qpnp_adc_tm_chip *chip)
  1186. {
  1187. u8 status_low = 0, status_high = 0, qpnp_adc_tm_meas_en = 0;
  1188. u8 adc_tm_low_enable = 0, adc_tm_high_enable = 0;
  1189. u8 sensor_mask = 0, adc_tm_low_thr_set = 0, adc_tm_high_thr_set = 0;
  1190. int rc = 0, sensor_notify_num = 0, i = 0, sensor_num = 0;
  1191. uint32_t btm_chan_num = 0;
  1192. struct qpnp_adc_thr_client_info *client_info = NULL;
  1193. struct list_head *thr_list;
  1194. if (qpnp_adc_tm_is_valid(chip))
  1195. return -ENODEV;
  1196. mutex_lock(&chip->adc->adc_lock);
  1197. rc = qpnp_adc_tm_req_sts_check(chip);
  1198. if (rc) {
  1199. pr_err("adc-tm-tm req sts check failed with %d\n", rc);
  1200. goto fail;
  1201. }
  1202. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS_LOW, &status_low);
  1203. if (rc) {
  1204. pr_err("adc-tm-tm read status low failed with %d\n", rc);
  1205. goto fail;
  1206. }
  1207. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_STATUS_HIGH, &status_high);
  1208. if (rc) {
  1209. pr_err("adc-tm-tm read status high failed with %d\n", rc);
  1210. goto fail;
  1211. }
  1212. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_LOW_THR_INT_EN,
  1213. &adc_tm_low_thr_set);
  1214. if (rc) {
  1215. pr_err("adc-tm-tm read low thr failed with %d\n", rc);
  1216. goto fail;
  1217. }
  1218. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_HIGH_THR_INT_EN,
  1219. &adc_tm_high_thr_set);
  1220. if (rc) {
  1221. pr_err("adc-tm-tm read high thr failed with %d\n", rc);
  1222. goto fail;
  1223. }
  1224. /* Check which interrupt threshold is lower and measure against the
  1225. * enabled channel */
  1226. rc = qpnp_adc_tm_read_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN,
  1227. &qpnp_adc_tm_meas_en);
  1228. if (rc) {
  1229. pr_err("adc-tm-tm read status high failed with %d\n", rc);
  1230. goto fail;
  1231. }
  1232. adc_tm_low_enable = qpnp_adc_tm_meas_en & status_low;
  1233. adc_tm_low_enable &= adc_tm_low_thr_set;
  1234. adc_tm_high_enable = qpnp_adc_tm_meas_en & status_high;
  1235. adc_tm_high_enable &= adc_tm_high_thr_set;
  1236. if (adc_tm_high_enable) {
  1237. sensor_notify_num = adc_tm_high_enable;
  1238. while (i < chip->max_channels_available) {
  1239. if ((sensor_notify_num & 0x1) == 1)
  1240. sensor_num = i;
  1241. sensor_notify_num >>= 1;
  1242. i++;
  1243. }
  1244. btm_chan_num = chip->sensor[sensor_num].btm_channel_num;
  1245. pr_debug("high:sen:%d, hs:0x%x, ls:0x%x, meas_en:0x%x\n",
  1246. sensor_num, adc_tm_high_enable, adc_tm_low_enable,
  1247. qpnp_adc_tm_meas_en);
  1248. if (!chip->sensor[sensor_num].thermal_node) {
  1249. /* For non thermal registered clients
  1250. such as usb_id, vbatt, pmic_therm */
  1251. sensor_mask = 1 << sensor_num;
  1252. pr_debug("non thermal node - mask:%x\n", sensor_mask);
  1253. rc = qpnp_adc_tm_reg_update(chip,
  1254. QPNP_ADC_TM_HIGH_THR_INT_EN,
  1255. sensor_mask, false);
  1256. if (rc < 0) {
  1257. pr_err("high threshold int read failed\n");
  1258. goto fail;
  1259. }
  1260. } else {
  1261. /* Uses the thermal sysfs registered device to disable
  1262. the corresponding high voltage threshold which
  1263. is triggered by low temp */
  1264. pr_debug("thermal node with mask:%x\n", sensor_mask);
  1265. rc = qpnp_adc_tm_activate_trip_type(
  1266. chip->sensor[sensor_num].tz_dev,
  1267. ADC_TM_TRIP_LOW_COOL,
  1268. THERMAL_TRIP_ACTIVATION_DISABLED);
  1269. if (rc < 0) {
  1270. pr_err("notify error:%d\n", sensor_num);
  1271. goto fail;
  1272. }
  1273. }
  1274. list_for_each(thr_list, &chip->sensor[sensor_num].thr_list) {
  1275. client_info = list_entry(thr_list,
  1276. struct qpnp_adc_thr_client_info, list);
  1277. if (client_info->high_thr_set) {
  1278. client_info->high_thr_set = false;
  1279. client_info->notify_high_thr = true;
  1280. if (client_info->state_req_copy ==
  1281. ADC_TM_HIGH_LOW_THR_ENABLE)
  1282. client_info->state_req_copy =
  1283. ADC_TM_LOW_THR_ENABLE;
  1284. else
  1285. client_info->state_req_copy =
  1286. ADC_TM_HIGH_THR_DISABLE;
  1287. }
  1288. }
  1289. }
  1290. if (adc_tm_low_enable) {
  1291. sensor_notify_num = adc_tm_low_enable;
  1292. i = 0;
  1293. while (i < chip->max_channels_available) {
  1294. if ((sensor_notify_num & 0x1) == 1)
  1295. sensor_num = i;
  1296. sensor_notify_num >>= 1;
  1297. i++;
  1298. }
  1299. btm_chan_num = chip->sensor[sensor_num].btm_channel_num;
  1300. pr_debug("low:sen:%d, hs:0x%x, ls:0x%x, meas_en:0x%x\n",
  1301. sensor_num, adc_tm_high_enable, adc_tm_low_enable,
  1302. qpnp_adc_tm_meas_en);
  1303. if (!chip->sensor[sensor_num].thermal_node) {
  1304. /* For non thermal registered clients
  1305. such as usb_id, vbatt, pmic_therm */
  1306. pr_debug("non thermal node - mask:%x\n", sensor_mask);
  1307. sensor_mask = 1 << sensor_num;
  1308. rc = qpnp_adc_tm_reg_update(chip,
  1309. QPNP_ADC_TM_LOW_THR_INT_EN,
  1310. sensor_mask, false);
  1311. if (rc < 0) {
  1312. pr_err("low threshold int read failed\n");
  1313. goto fail;
  1314. }
  1315. } else {
  1316. /* Uses the thermal sysfs registered device to disable
  1317. the corresponding low voltage threshold which
  1318. is triggered by high temp */
  1319. pr_debug("thermal node with mask:%x\n", sensor_mask);
  1320. rc = qpnp_adc_tm_activate_trip_type(
  1321. chip->sensor[sensor_num].tz_dev,
  1322. ADC_TM_TRIP_HIGH_WARM,
  1323. THERMAL_TRIP_ACTIVATION_DISABLED);
  1324. if (rc < 0) {
  1325. pr_err("notify error:%d\n", sensor_num);
  1326. goto fail;
  1327. }
  1328. }
  1329. list_for_each(thr_list, &chip->sensor[sensor_num].thr_list) {
  1330. client_info = list_entry(thr_list,
  1331. struct qpnp_adc_thr_client_info, list);
  1332. if (client_info->low_thr_set) {
  1333. /* mark the corresponding clients threshold
  1334. as not set */
  1335. client_info->low_thr_set = false;
  1336. client_info->notify_low_thr = true;
  1337. if (client_info->state_req_copy ==
  1338. ADC_TM_HIGH_LOW_THR_ENABLE)
  1339. client_info->state_req_copy =
  1340. ADC_TM_HIGH_THR_ENABLE;
  1341. else
  1342. client_info->state_req_copy =
  1343. ADC_TM_LOW_THR_DISABLE;
  1344. }
  1345. }
  1346. }
  1347. qpnp_adc_tm_manage_thresholds(chip, sensor_num, btm_chan_num);
  1348. if (adc_tm_high_enable || adc_tm_low_enable) {
  1349. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN,
  1350. sensor_mask, false);
  1351. if (rc < 0) {
  1352. pr_err("multi meas disable for channel failed\n");
  1353. goto fail;
  1354. }
  1355. rc = qpnp_adc_tm_enable_if_channel_meas(chip);
  1356. if (rc < 0) {
  1357. pr_err("re-enabling measurement failed\n");
  1358. return rc;
  1359. }
  1360. } else
  1361. pr_debug("No threshold status enable %d for high/low??\n",
  1362. sensor_mask);
  1363. fail:
  1364. mutex_unlock(&chip->adc->adc_lock);
  1365. if (adc_tm_high_enable || adc_tm_low_enable)
  1366. schedule_work(&chip->sensor[sensor_num].work);
  1367. return rc;
  1368. }
  1369. static void qpnp_adc_tm_high_thr_work(struct work_struct *work)
  1370. {
  1371. struct qpnp_adc_tm_chip *chip = container_of(work,
  1372. struct qpnp_adc_tm_chip, trigger_high_thr_work);
  1373. int rc;
  1374. rc = qpnp_adc_tm_read_status(chip);
  1375. if (rc < 0)
  1376. pr_err("adc-tm high thr work failed\n");
  1377. return;
  1378. }
  1379. static irqreturn_t qpnp_adc_tm_high_thr_isr(int irq, void *data)
  1380. {
  1381. struct qpnp_adc_tm_chip *chip = data;
  1382. qpnp_adc_tm_disable(chip);
  1383. schedule_work(&chip->trigger_high_thr_work);
  1384. return IRQ_HANDLED;
  1385. }
  1386. static void qpnp_adc_tm_low_thr_work(struct work_struct *work)
  1387. {
  1388. struct qpnp_adc_tm_chip *chip = container_of(work,
  1389. struct qpnp_adc_tm_chip, trigger_low_thr_work);
  1390. int rc;
  1391. rc = qpnp_adc_tm_read_status(chip);
  1392. if (rc < 0)
  1393. pr_err("adc-tm low thr work failed\n");
  1394. return;
  1395. }
  1396. static irqreturn_t qpnp_adc_tm_low_thr_isr(int irq, void *data)
  1397. {
  1398. struct qpnp_adc_tm_chip *chip = data;
  1399. qpnp_adc_tm_disable(chip);
  1400. schedule_work(&chip->trigger_low_thr_work);
  1401. return IRQ_HANDLED;
  1402. }
  1403. static int qpnp_adc_read_temp(struct thermal_zone_device *thermal,
  1404. unsigned long *temp)
  1405. {
  1406. struct qpnp_adc_tm_sensor *adc_tm_sensor = thermal->devdata;
  1407. struct qpnp_adc_tm_chip *chip = adc_tm_sensor->chip;
  1408. struct qpnp_vadc_result result;
  1409. int rc = 0;
  1410. rc = qpnp_vadc_read(chip->vadc_dev,
  1411. adc_tm_sensor->vadc_channel_num, &result);
  1412. if (rc)
  1413. return rc;
  1414. *temp = result.physical;
  1415. return rc;
  1416. }
  1417. static struct thermal_zone_device_ops qpnp_adc_tm_thermal_ops = {
  1418. .get_temp = qpnp_adc_read_temp,
  1419. .get_mode = qpnp_adc_tm_get_mode,
  1420. .set_mode = qpnp_adc_tm_set_mode,
  1421. .get_trip_type = qpnp_adc_tm_get_trip_type,
  1422. .activate_trip_type = qpnp_adc_tm_activate_trip_type,
  1423. .get_trip_temp = qpnp_adc_tm_get_trip_temp,
  1424. .set_trip_temp = qpnp_adc_tm_set_trip_temp,
  1425. };
  1426. int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip,
  1427. struct qpnp_adc_tm_btm_param *param)
  1428. {
  1429. uint32_t channel, dt_index = 0, scale_type = 0;
  1430. int rc = 0, i = 0;
  1431. bool chan_found = false;
  1432. if (qpnp_adc_tm_is_valid(chip)) {
  1433. pr_err("chip not valid\n");
  1434. return -ENODEV;
  1435. }
  1436. if (param->threshold_notification == NULL) {
  1437. pr_debug("No notification for high/low temp??\n");
  1438. return -EINVAL;
  1439. }
  1440. mutex_lock(&chip->adc->adc_lock);
  1441. channel = param->channel;
  1442. while (i < chip->max_channels_available) {
  1443. if (chip->adc->adc_channels[i].channel_num ==
  1444. channel) {
  1445. dt_index = i;
  1446. chan_found = true;
  1447. i++;
  1448. } else
  1449. i++;
  1450. }
  1451. if (!chan_found) {
  1452. pr_err("not a valid ADC_TM channel\n");
  1453. rc = -EINVAL;
  1454. goto fail_unlock;
  1455. }
  1456. rc = qpnp_adc_tm_check_revision(chip,
  1457. chip->sensor[dt_index].btm_channel_num);
  1458. if (rc < 0)
  1459. goto fail_unlock;
  1460. scale_type = chip->adc->adc_channels[dt_index].adc_scale_fn;
  1461. if (scale_type >= SCALE_RSCALE_NONE) {
  1462. rc = -EBADF;
  1463. goto fail_unlock;
  1464. }
  1465. pr_debug("channel:%d, scale_type:%d, dt_idx:%d",
  1466. channel, scale_type, dt_index);
  1467. chip->adc->amux_prop->amux_channel = channel;
  1468. chip->adc->amux_prop->decimation =
  1469. chip->adc->adc_channels[dt_index].adc_decimation;
  1470. chip->adc->amux_prop->hw_settle_time =
  1471. chip->adc->adc_channels[dt_index].hw_settle_time;
  1472. chip->adc->amux_prop->fast_avg_setup =
  1473. chip->adc->adc_channels[dt_index].fast_avg_setup;
  1474. chip->adc->amux_prop->mode_sel =
  1475. ADC_OP_MEASUREMENT_INTERVAL << QPNP_OP_MODE_SHIFT;
  1476. adc_tm_rscale_fn[scale_type].chan(chip->vadc_dev, param,
  1477. &chip->adc->amux_prop->chan_prop->low_thr,
  1478. &chip->adc->amux_prop->chan_prop->high_thr);
  1479. qpnp_adc_tm_add_to_list(chip, dt_index, param,
  1480. chip->adc->amux_prop->chan_prop);
  1481. chip->adc->amux_prop->chan_prop->tm_channel_select =
  1482. chip->sensor[dt_index].btm_channel_num;
  1483. chip->adc->amux_prop->chan_prop->state_request =
  1484. param->state_request;
  1485. rc = qpnp_adc_tm_configure(chip, chip->adc->amux_prop);
  1486. if (rc) {
  1487. pr_err("adc-tm configure failed with %d\n", rc);
  1488. goto fail_unlock;
  1489. }
  1490. chip->sensor[dt_index].scale_type = scale_type;
  1491. fail_unlock:
  1492. mutex_unlock(&chip->adc->adc_lock);
  1493. return rc;
  1494. }
  1495. EXPORT_SYMBOL(qpnp_adc_tm_channel_measure);
  1496. int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip,
  1497. struct qpnp_adc_tm_btm_param *param)
  1498. {
  1499. uint32_t channel, dt_index = 0, btm_chan_num;
  1500. u8 sensor_mask = 0;
  1501. int rc = 0;
  1502. if (qpnp_adc_tm_is_valid(chip))
  1503. return -ENODEV;
  1504. mutex_lock(&chip->adc->adc_lock);
  1505. /* Disable bank */
  1506. rc = qpnp_adc_tm_disable(chip);
  1507. if (rc < 0) {
  1508. pr_err("adc-tm disable failed\n");
  1509. goto fail;
  1510. }
  1511. /* Check if a conversion is in progress */
  1512. rc = qpnp_adc_tm_req_sts_check(chip);
  1513. if (rc < 0) {
  1514. pr_err("adc-tm req_sts check failed\n");
  1515. goto fail;
  1516. }
  1517. channel = param->channel;
  1518. while ((chip->adc->adc_channels[dt_index].channel_num
  1519. != channel) && (dt_index < chip->max_channels_available))
  1520. dt_index++;
  1521. if (dt_index >= chip->max_channels_available) {
  1522. pr_err("not a valid ADC_TMN channel\n");
  1523. rc = -EINVAL;
  1524. goto fail;
  1525. }
  1526. btm_chan_num = chip->sensor[dt_index].btm_channel_num;
  1527. sensor_mask = 1 << chip->sensor[dt_index].sensor_num;
  1528. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_LOW_THR_INT_EN,
  1529. sensor_mask, false);
  1530. if (rc < 0) {
  1531. pr_err("low threshold int write failed\n");
  1532. goto fail;
  1533. }
  1534. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_HIGH_THR_INT_EN,
  1535. sensor_mask, false);
  1536. if (rc < 0) {
  1537. pr_err("high threshold int enable failed\n");
  1538. goto fail;
  1539. }
  1540. rc = qpnp_adc_tm_reg_update(chip, QPNP_ADC_TM_MULTI_MEAS_EN,
  1541. sensor_mask, false);
  1542. if (rc < 0) {
  1543. pr_err("multi measurement en failed\n");
  1544. goto fail;
  1545. }
  1546. rc = qpnp_adc_tm_enable_if_channel_meas(chip);
  1547. if (rc < 0)
  1548. pr_err("re-enabling measurement failed\n");
  1549. fail:
  1550. mutex_unlock(&chip->adc->adc_lock);
  1551. return rc;
  1552. }
  1553. EXPORT_SYMBOL(qpnp_adc_tm_disable_chan_meas);
  1554. int32_t qpnp_adc_tm_usbid_configure(struct qpnp_adc_tm_chip *chip,
  1555. struct qpnp_adc_tm_btm_param *param)
  1556. {
  1557. param->channel = LR_MUX10_PU2_AMUX_USB_ID_LV;
  1558. return qpnp_adc_tm_channel_measure(chip, param);
  1559. }
  1560. EXPORT_SYMBOL(qpnp_adc_tm_usbid_configure);
  1561. int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip)
  1562. {
  1563. struct qpnp_adc_tm_btm_param param;
  1564. return qpnp_adc_tm_disable_chan_meas(chip, &param);
  1565. }
  1566. EXPORT_SYMBOL(qpnp_adc_tm_usbid_end);
  1567. struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, const char *name)
  1568. {
  1569. struct qpnp_adc_tm_chip *chip;
  1570. struct device_node *node = NULL;
  1571. char prop_name[QPNP_MAX_PROP_NAME_LEN];
  1572. snprintf(prop_name, QPNP_MAX_PROP_NAME_LEN, "qcom,%s-adc_tm", name);
  1573. node = of_parse_phandle(dev->of_node, prop_name, 0);
  1574. if (node == NULL)
  1575. return ERR_PTR(-ENODEV);
  1576. list_for_each_entry(chip, &qpnp_adc_tm_device_list, list)
  1577. if (chip->adc->spmi->dev.of_node == node)
  1578. return chip;
  1579. return ERR_PTR(-EPROBE_DEFER);
  1580. }
  1581. EXPORT_SYMBOL(qpnp_get_adc_tm);
  1582. static int __devinit qpnp_adc_tm_probe(struct spmi_device *spmi)
  1583. {
  1584. struct device_node *node = spmi->dev.of_node, *child;
  1585. struct qpnp_adc_tm_chip *chip;
  1586. struct qpnp_adc_drv *adc_qpnp;
  1587. int32_t count_adc_channel_list = 0, rc, sen_idx = 0, i = 0;
  1588. u8 thr_init = 0;
  1589. bool thermal_node = false;
  1590. for_each_child_of_node(node, child)
  1591. count_adc_channel_list++;
  1592. if (!count_adc_channel_list) {
  1593. pr_err("No channel listing\n");
  1594. return -EINVAL;
  1595. }
  1596. chip = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_adc_tm_chip) +
  1597. (count_adc_channel_list *
  1598. sizeof(struct qpnp_adc_tm_sensor)),
  1599. GFP_KERNEL);
  1600. if (!chip) {
  1601. dev_err(&spmi->dev, "Unable to allocate memory\n");
  1602. return -ENOMEM;
  1603. }
  1604. adc_qpnp = devm_kzalloc(&spmi->dev, sizeof(struct qpnp_adc_drv),
  1605. GFP_KERNEL);
  1606. if (!adc_qpnp) {
  1607. dev_err(&spmi->dev, "Unable to allocate memory\n");
  1608. rc = -ENOMEM;
  1609. goto fail;
  1610. }
  1611. chip->dev = &(spmi->dev);
  1612. chip->adc = adc_qpnp;
  1613. rc = qpnp_adc_get_devicetree_data(spmi, chip->adc);
  1614. if (rc) {
  1615. dev_err(&spmi->dev, "failed to read device tree\n");
  1616. goto fail;
  1617. }
  1618. mutex_init(&chip->adc->adc_lock);
  1619. /* Register the ADC peripheral interrupt */
  1620. chip->adc->adc_high_thr_irq = spmi_get_irq_byname(spmi,
  1621. NULL, "high-thr-en-set");
  1622. if (chip->adc->adc_high_thr_irq < 0) {
  1623. pr_err("Invalid irq\n");
  1624. rc = -ENXIO;
  1625. goto fail;
  1626. }
  1627. chip->adc->adc_low_thr_irq = spmi_get_irq_byname(spmi,
  1628. NULL, "low-thr-en-set");
  1629. if (chip->adc->adc_low_thr_irq < 0) {
  1630. pr_err("Invalid irq\n");
  1631. rc = -ENXIO;
  1632. goto fail;
  1633. }
  1634. chip->vadc_dev = qpnp_get_vadc(&spmi->dev, "adc_tm");
  1635. if (IS_ERR(chip->vadc_dev)) {
  1636. rc = PTR_ERR(chip->vadc_dev);
  1637. if (rc != -EPROBE_DEFER)
  1638. pr_err("vadc property missing, rc=%d\n", rc);
  1639. goto fail;
  1640. }
  1641. for_each_child_of_node(node, child) {
  1642. char name[25];
  1643. int btm_channel_num, timer_select = 0;
  1644. rc = of_property_read_u32(child,
  1645. "qcom,btm-channel-number", &btm_channel_num);
  1646. if (rc) {
  1647. pr_err("Invalid btm channel number\n");
  1648. goto fail;
  1649. }
  1650. rc = of_property_read_u32(child,
  1651. "qcom,meas-interval-timer-idx", &timer_select);
  1652. if (rc) {
  1653. pr_debug("Default to timer1 with interval of 1 sec\n");
  1654. chip->sensor[sen_idx].timer_select =
  1655. ADC_MEAS_TIMER_SELECT1;
  1656. chip->sensor[sen_idx].meas_interval =
  1657. ADC_MEAS1_INTERVAL_1S;
  1658. } else {
  1659. if (timer_select >= ADC_MEAS_TIMER_NUM) {
  1660. pr_err("Invalid timer selection number\n");
  1661. goto fail;
  1662. }
  1663. chip->sensor[sen_idx].timer_select = timer_select;
  1664. if (timer_select == ADC_MEAS_TIMER_SELECT2)
  1665. chip->sensor[sen_idx].meas_interval =
  1666. ADC_MEAS2_INTERVAL_500MS;
  1667. if (timer_select == ADC_MEAS_TIMER_SELECT3)
  1668. chip->sensor[sen_idx].meas_interval =
  1669. ADC_MEAS3_INTERVAL_4S;
  1670. }
  1671. chip->sensor[sen_idx].btm_channel_num = btm_channel_num;
  1672. chip->sensor[sen_idx].vadc_channel_num =
  1673. chip->adc->adc_channels[sen_idx].channel_num;
  1674. chip->sensor[sen_idx].sensor_num = sen_idx;
  1675. chip->sensor[sen_idx].chip = chip;
  1676. pr_debug("btm_chan:%x, vadc_chan:%x\n", btm_channel_num,
  1677. chip->adc->adc_channels[sen_idx].channel_num);
  1678. thermal_node = of_property_read_bool(child,
  1679. "qcom,thermal-node");
  1680. if (thermal_node) {
  1681. /* Register with the thermal zone */
  1682. pr_debug("thermal node%x\n", btm_channel_num);
  1683. chip->sensor[sen_idx].mode = THERMAL_DEVICE_DISABLED;
  1684. chip->sensor[sen_idx].thermal_node = true;
  1685. snprintf(name, sizeof(name), "%s",
  1686. chip->adc->adc_channels[sen_idx].name);
  1687. chip->sensor[sen_idx].meas_interval =
  1688. QPNP_ADC_TM_MEAS_INTERVAL;
  1689. chip->sensor[sen_idx].low_thr =
  1690. QPNP_ADC_TM_M0_LOW_THR;
  1691. chip->sensor[sen_idx].high_thr =
  1692. QPNP_ADC_TM_M0_HIGH_THR;
  1693. chip->sensor[sen_idx].tz_dev =
  1694. thermal_zone_device_register(name,
  1695. ADC_TM_TRIP_NUM,
  1696. &chip->sensor[sen_idx],
  1697. &qpnp_adc_tm_thermal_ops, 0, 0, 0, 0);
  1698. if (IS_ERR(chip->sensor[sen_idx].tz_dev))
  1699. pr_err("thermal device register failed.\n");
  1700. }
  1701. INIT_WORK(&chip->sensor[sen_idx].work, notify_adc_tm_fn);
  1702. INIT_LIST_HEAD(&chip->sensor[sen_idx].thr_list);
  1703. sen_idx++;
  1704. }
  1705. chip->max_channels_available = count_adc_channel_list;
  1706. INIT_WORK(&chip->trigger_high_thr_work, qpnp_adc_tm_high_thr_work);
  1707. INIT_WORK(&chip->trigger_low_thr_work, qpnp_adc_tm_low_thr_work);
  1708. rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_HIGH_THR_INT_EN,
  1709. thr_init);
  1710. if (rc < 0) {
  1711. pr_err("high thr init failed\n");
  1712. goto fail;
  1713. }
  1714. rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_LOW_THR_INT_EN,
  1715. thr_init);
  1716. if (rc < 0) {
  1717. pr_err("low thr init failed\n");
  1718. goto fail;
  1719. }
  1720. rc = qpnp_adc_tm_write_reg(chip, QPNP_ADC_TM_MULTI_MEAS_EN,
  1721. thr_init);
  1722. if (rc < 0) {
  1723. pr_err("multi meas en failed\n");
  1724. goto fail;
  1725. }
  1726. rc = devm_request_irq(&spmi->dev, chip->adc->adc_high_thr_irq,
  1727. qpnp_adc_tm_high_thr_isr,
  1728. IRQF_TRIGGER_RISING, "qpnp_adc_tm_high_interrupt", chip);
  1729. if (rc) {
  1730. dev_err(&spmi->dev, "failed to request adc irq\n");
  1731. goto fail;
  1732. } else {
  1733. enable_irq_wake(chip->adc->adc_high_thr_irq);
  1734. }
  1735. rc = devm_request_irq(&spmi->dev, chip->adc->adc_low_thr_irq,
  1736. qpnp_adc_tm_low_thr_isr,
  1737. IRQF_TRIGGER_RISING, "qpnp_adc_tm_low_interrupt", chip);
  1738. if (rc) {
  1739. dev_err(&spmi->dev, "failed to request adc irq\n");
  1740. goto fail;
  1741. } else {
  1742. enable_irq_wake(chip->adc->adc_low_thr_irq);
  1743. }
  1744. dev_set_drvdata(&spmi->dev, chip);
  1745. list_add(&chip->list, &qpnp_adc_tm_device_list);
  1746. pr_debug("OK\n");
  1747. return 0;
  1748. fail:
  1749. for_each_child_of_node(node, child) {
  1750. thermal_node = of_property_read_bool(child,
  1751. "qcom,thermal-node");
  1752. if (thermal_node)
  1753. thermal_zone_device_unregister(chip->sensor[i].tz_dev);
  1754. i++;
  1755. }
  1756. dev_set_drvdata(&spmi->dev, NULL);
  1757. return rc;
  1758. }
  1759. static int __devexit qpnp_adc_tm_remove(struct spmi_device *spmi)
  1760. {
  1761. struct qpnp_adc_tm_chip *chip = dev_get_drvdata(&spmi->dev);
  1762. struct device_node *node = spmi->dev.of_node, *child;
  1763. bool thermal_node = false;
  1764. int i = 0;
  1765. for_each_child_of_node(node, child) {
  1766. thermal_node = of_property_read_bool(child,
  1767. "qcom,thermal-node");
  1768. if (thermal_node)
  1769. thermal_zone_device_unregister(chip->sensor[i].tz_dev);
  1770. i++;
  1771. }
  1772. dev_set_drvdata(&spmi->dev, NULL);
  1773. return 0;
  1774. }
  1775. static const struct of_device_id qpnp_adc_tm_match_table[] = {
  1776. { .compatible = "qcom,qpnp-adc-tm" },
  1777. {}
  1778. };
  1779. static struct spmi_driver qpnp_adc_tm_driver = {
  1780. .driver = {
  1781. .name = "qcom,qpnp-adc-tm",
  1782. .of_match_table = qpnp_adc_tm_match_table,
  1783. },
  1784. .probe = qpnp_adc_tm_probe,
  1785. .remove = qpnp_adc_tm_remove,
  1786. };
  1787. static int __init qpnp_adc_tm_init(void)
  1788. {
  1789. return spmi_driver_register(&qpnp_adc_tm_driver);
  1790. }
  1791. module_init(qpnp_adc_tm_init);
  1792. static void __exit qpnp_adc_tm_exit(void)
  1793. {
  1794. spmi_driver_unregister(&qpnp_adc_tm_driver);
  1795. }
  1796. module_exit(qpnp_adc_tm_exit);
  1797. MODULE_DESCRIPTION("QPNP PMIC ADC Threshold Monitoring driver");
  1798. MODULE_LICENSE("GPL v2");