qcom-spmi-adc-tm5.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020 Linaro Limited
  4. *
  5. * Based on original driver:
  6. * Copyright (c) 2012-2020, The Linux Foundation. All rights reserved.
  7. *
  8. * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  9. */
  10. #include <linux/bitfield.h>
  11. #include <linux/iio/adc/qcom-vadc-common.h>
  12. #include <linux/iio/consumer.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/of_device.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/regmap.h>
  19. #include <linux/thermal.h>
  20. #include <asm-generic/unaligned.h>
  21. #include "../thermal_hwmon.h"
  22. /*
  23. * Thermal monitoring block consists of 8 (ADC_TM5_NUM_CHANNELS) channels. Each
  24. * channel is programmed to use one of ADC channels for voltage comparison.
  25. * Voltages are programmed using ADC codes, so we have to convert temp to
  26. * voltage and then to ADC code value.
  27. *
  28. * Configuration of TM channels must match configuration of corresponding ADC
  29. * channels.
  30. */
  31. #define ADC5_MAX_CHANNEL 0xc0
  32. #define ADC_TM5_NUM_CHANNELS 8
  33. #define ADC_TM5_STATUS_LOW 0x0a
  34. #define ADC_TM5_STATUS_HIGH 0x0b
  35. #define ADC_TM5_NUM_BTM 0x0f
  36. #define ADC_TM5_ADC_DIG_PARAM 0x42
  37. #define ADC_TM5_FAST_AVG_CTL (ADC_TM5_ADC_DIG_PARAM + 1)
  38. #define ADC_TM5_FAST_AVG_EN BIT(7)
  39. #define ADC_TM5_MEAS_INTERVAL_CTL (ADC_TM5_ADC_DIG_PARAM + 2)
  40. #define ADC_TM5_TIMER1 3 /* 3.9ms */
  41. #define ADC_TM5_MEAS_INTERVAL_CTL2 (ADC_TM5_ADC_DIG_PARAM + 3)
  42. #define ADC_TM5_MEAS_INTERVAL_CTL2_MASK 0xf0
  43. #define ADC_TM5_TIMER2 10 /* 1 second */
  44. #define ADC_TM5_MEAS_INTERVAL_CTL3_MASK 0xf
  45. #define ADC_TM5_TIMER3 4 /* 4 second */
  46. #define ADC_TM_EN_CTL1 0x46
  47. #define ADC_TM_EN BIT(7)
  48. #define ADC_TM_CONV_REQ 0x47
  49. #define ADC_TM_CONV_REQ_EN BIT(7)
  50. #define ADC_TM5_M_CHAN_BASE 0x60
  51. #define ADC_TM5_M_ADC_CH_SEL_CTL(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 0)
  52. #define ADC_TM5_M_LOW_THR0(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 1)
  53. #define ADC_TM5_M_LOW_THR1(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 2)
  54. #define ADC_TM5_M_HIGH_THR0(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 3)
  55. #define ADC_TM5_M_HIGH_THR1(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 4)
  56. #define ADC_TM5_M_MEAS_INTERVAL_CTL(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 5)
  57. #define ADC_TM5_M_CTL(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 6)
  58. #define ADC_TM5_M_CTL_HW_SETTLE_DELAY_MASK 0xf
  59. #define ADC_TM5_M_CTL_CAL_SEL_MASK 0x30
  60. #define ADC_TM5_M_CTL_CAL_VAL 0x40
  61. #define ADC_TM5_M_EN(n) (ADC_TM5_M_CHAN_BASE + ((n) * 8) + 7)
  62. #define ADC_TM5_M_MEAS_EN BIT(7)
  63. #define ADC_TM5_M_HIGH_THR_INT_EN BIT(1)
  64. #define ADC_TM5_M_LOW_THR_INT_EN BIT(0)
  65. #define ADC_TM_GEN2_STATUS1 0x08
  66. #define ADC_TM_GEN2_STATUS_LOW_SET 0x09
  67. #define ADC_TM_GEN2_STATUS_LOW_CLR 0x0a
  68. #define ADC_TM_GEN2_STATUS_HIGH_SET 0x0b
  69. #define ADC_TM_GEN2_STATUS_HIGH_CLR 0x0c
  70. #define ADC_TM_GEN2_CFG_HS_SET 0x0d
  71. #define ADC_TM_GEN2_CFG_HS_FLAG BIT(0)
  72. #define ADC_TM_GEN2_CFG_HS_CLR 0x0e
  73. #define ADC_TM_GEN2_SID 0x40
  74. #define ADC_TM_GEN2_CH_CTL 0x41
  75. #define ADC_TM_GEN2_TM_CH_SEL GENMASK(7, 5)
  76. #define ADC_TM_GEN2_MEAS_INT_SEL GENMASK(3, 2)
  77. #define ADC_TM_GEN2_ADC_DIG_PARAM 0x42
  78. #define ADC_TM_GEN2_CTL_CAL_SEL GENMASK(5, 4)
  79. #define ADC_TM_GEN2_CTL_DEC_RATIO_MASK GENMASK(3, 2)
  80. #define ADC_TM_GEN2_FAST_AVG_CTL 0x43
  81. #define ADC_TM_GEN2_FAST_AVG_EN BIT(7)
  82. #define ADC_TM_GEN2_ADC_CH_SEL_CTL 0x44
  83. #define ADC_TM_GEN2_DELAY_CTL 0x45
  84. #define ADC_TM_GEN2_HW_SETTLE_DELAY GENMASK(3, 0)
  85. #define ADC_TM_GEN2_EN_CTL1 0x46
  86. #define ADC_TM_GEN2_EN BIT(7)
  87. #define ADC_TM_GEN2_CONV_REQ 0x47
  88. #define ADC_TM_GEN2_CONV_REQ_EN BIT(7)
  89. #define ADC_TM_GEN2_LOW_THR0 0x49
  90. #define ADC_TM_GEN2_LOW_THR1 0x4a
  91. #define ADC_TM_GEN2_HIGH_THR0 0x4b
  92. #define ADC_TM_GEN2_HIGH_THR1 0x4c
  93. #define ADC_TM_GEN2_LOWER_MASK(n) ((n) & GENMASK(7, 0))
  94. #define ADC_TM_GEN2_UPPER_MASK(n) (((n) & GENMASK(15, 8)) >> 8)
  95. #define ADC_TM_GEN2_MEAS_IRQ_EN 0x4d
  96. #define ADC_TM_GEN2_MEAS_EN BIT(7)
  97. #define ADC_TM5_GEN2_HIGH_THR_INT_EN BIT(1)
  98. #define ADC_TM5_GEN2_LOW_THR_INT_EN BIT(0)
  99. #define ADC_TM_GEN2_MEAS_INT_LSB 0x50
  100. #define ADC_TM_GEN2_MEAS_INT_MSB 0x51
  101. #define ADC_TM_GEN2_MEAS_INT_MODE 0x52
  102. #define ADC_TM_GEN2_Mn_DATA0(n) ((n * 2) + 0xa0)
  103. #define ADC_TM_GEN2_Mn_DATA1(n) ((n * 2) + 0xa1)
  104. #define ADC_TM_GEN2_DATA_SHIFT 8
  105. enum adc5_timer_select {
  106. ADC5_TIMER_SEL_1 = 0,
  107. ADC5_TIMER_SEL_2,
  108. ADC5_TIMER_SEL_3,
  109. ADC5_TIMER_SEL_NONE,
  110. };
  111. enum adc5_gen {
  112. ADC_TM5,
  113. ADC_TM_HC,
  114. ADC_TM5_GEN2,
  115. ADC_TM5_MAX
  116. };
  117. enum adc_tm5_cal_method {
  118. ADC_TM5_NO_CAL = 0,
  119. ADC_TM5_RATIOMETRIC_CAL,
  120. ADC_TM5_ABSOLUTE_CAL
  121. };
  122. enum adc_tm_gen2_time_select {
  123. MEAS_INT_50MS = 0,
  124. MEAS_INT_100MS,
  125. MEAS_INT_1S,
  126. MEAS_INT_SET,
  127. MEAS_INT_NONE,
  128. };
  129. struct adc_tm5_chip;
  130. struct adc_tm5_channel;
  131. struct adc_tm5_data {
  132. const u32 full_scale_code_volt;
  133. unsigned int *decimation;
  134. unsigned int *hw_settle;
  135. int (*disable_channel)(struct adc_tm5_channel *channel);
  136. int (*configure)(struct adc_tm5_channel *channel, int low, int high);
  137. irqreturn_t (*isr)(int irq, void *data);
  138. int (*init)(struct adc_tm5_chip *chip);
  139. char *irq_name;
  140. int gen;
  141. };
  142. /**
  143. * struct adc_tm5_channel - ADC Thermal Monitoring channel data.
  144. * @channel: channel number.
  145. * @adc_channel: corresponding ADC channel number.
  146. * @cal_method: calibration method.
  147. * @prescale: channel scaling performed on the input signal.
  148. * @hw_settle_time: the time between AMUX being configured and the
  149. * start of conversion.
  150. * @decimation: sampling rate supported for the channel.
  151. * @avg_samples: ability to provide single result from the ADC
  152. * that is an average of multiple measurements.
  153. * @high_thr_en: channel upper voltage threshold enable state.
  154. * @low_thr_en: channel lower voltage threshold enable state.
  155. * @meas_en: recurring measurement enable state
  156. * @iio: IIO channel instance used by this channel.
  157. * @chip: ADC TM chip instance.
  158. * @tzd: thermal zone device used by this channel.
  159. */
  160. struct adc_tm5_channel {
  161. unsigned int channel;
  162. unsigned int adc_channel;
  163. enum adc_tm5_cal_method cal_method;
  164. unsigned int prescale;
  165. unsigned int hw_settle_time;
  166. unsigned int decimation; /* For Gen2 ADC_TM */
  167. unsigned int avg_samples; /* For Gen2 ADC_TM */
  168. bool high_thr_en; /* For Gen2 ADC_TM */
  169. bool low_thr_en; /* For Gen2 ADC_TM */
  170. bool meas_en; /* For Gen2 ADC_TM */
  171. struct iio_channel *iio;
  172. struct adc_tm5_chip *chip;
  173. struct thermal_zone_device *tzd;
  174. };
  175. /**
  176. * struct adc_tm5_chip - ADC Thermal Monitoring properties
  177. * @regmap: SPMI ADC5 Thermal Monitoring peripheral register map field.
  178. * @dev: SPMI ADC5 device.
  179. * @data: software configuration data.
  180. * @channels: array of ADC TM channel data.
  181. * @nchannels: amount of channels defined/allocated
  182. * @decimation: sampling rate supported for the channel.
  183. * Applies to all channels, used only on Gen1 ADC_TM.
  184. * @avg_samples: ability to provide single result from the ADC
  185. * that is an average of multiple measurements. Applies to all
  186. * channels, used only on Gen1 ADC_TM.
  187. * @irq: adc-tm interrupt, triggered when temperature violations happen.
  188. * @base: base address of TM registers.
  189. * @adc_mutex_lock: ADC_TM mutex lock, used only on Gen2 ADC_TM.
  190. * It is used to ensure only one ADC channel configuration
  191. * is done at a time using the shared set of configuration
  192. * registers.
  193. */
  194. struct adc_tm5_chip {
  195. struct regmap *regmap;
  196. struct device *dev;
  197. const struct adc_tm5_data *data;
  198. struct adc_tm5_channel *channels;
  199. unsigned int nchannels;
  200. unsigned int decimation;
  201. unsigned int avg_samples;
  202. int irq;
  203. u16 base;
  204. struct mutex adc_mutex_lock;
  205. };
  206. static int adc_tm5_read(struct adc_tm5_chip *adc_tm, u16 offset, u8 *data, int len)
  207. {
  208. return regmap_bulk_read(adc_tm->regmap, adc_tm->base + offset, data, len);
  209. }
  210. static int adc_tm5_write(struct adc_tm5_chip *adc_tm, u16 offset, u8 *data, int len)
  211. {
  212. return regmap_bulk_write(adc_tm->regmap, adc_tm->base + offset, data, len);
  213. }
  214. static int adc_tm5_reg_update(struct adc_tm5_chip *adc_tm, u16 offset, u8 mask, u8 val)
  215. {
  216. return regmap_write_bits(adc_tm->regmap, adc_tm->base + offset, mask, val);
  217. }
  218. static irqreturn_t adc_tm5_isr(int irq, void *data)
  219. {
  220. struct adc_tm5_chip *chip = data;
  221. u8 status_low, status_high, ctl;
  222. int ret, i;
  223. ret = adc_tm5_read(chip, ADC_TM5_STATUS_LOW, &status_low, sizeof(status_low));
  224. if (unlikely(ret)) {
  225. dev_err(chip->dev, "read status low failed: %d\n", ret);
  226. return IRQ_HANDLED;
  227. }
  228. ret = adc_tm5_read(chip, ADC_TM5_STATUS_HIGH, &status_high, sizeof(status_high));
  229. if (unlikely(ret)) {
  230. dev_err(chip->dev, "read status high failed: %d\n", ret);
  231. return IRQ_HANDLED;
  232. }
  233. for (i = 0; i < chip->nchannels; i++) {
  234. bool upper_set = false, lower_set = false;
  235. unsigned int ch = chip->channels[i].channel;
  236. /* No TZD, we warned at the boot time */
  237. if (!chip->channels[i].tzd)
  238. continue;
  239. ret = adc_tm5_read(chip, ADC_TM5_M_EN(ch), &ctl, sizeof(ctl));
  240. if (unlikely(ret)) {
  241. dev_err(chip->dev, "ctl read failed: %d, channel %d\n", ret, i);
  242. continue;
  243. }
  244. if (!(ctl & ADC_TM5_M_MEAS_EN))
  245. continue;
  246. lower_set = (status_low & BIT(ch)) &&
  247. (ctl & ADC_TM5_M_LOW_THR_INT_EN);
  248. upper_set = (status_high & BIT(ch)) &&
  249. (ctl & ADC_TM5_M_HIGH_THR_INT_EN);
  250. if (upper_set || lower_set)
  251. thermal_zone_device_update(chip->channels[i].tzd,
  252. THERMAL_EVENT_UNSPECIFIED);
  253. }
  254. return IRQ_HANDLED;
  255. }
  256. static irqreturn_t adc_tm5_gen2_isr(int irq, void *data)
  257. {
  258. struct adc_tm5_chip *chip = data;
  259. u8 status_low, status_high;
  260. int ret, i;
  261. ret = adc_tm5_read(chip, ADC_TM_GEN2_STATUS_LOW_CLR, &status_low, sizeof(status_low));
  262. if (ret) {
  263. dev_err(chip->dev, "read status_low failed: %d\n", ret);
  264. return IRQ_HANDLED;
  265. }
  266. ret = adc_tm5_read(chip, ADC_TM_GEN2_STATUS_HIGH_CLR, &status_high, sizeof(status_high));
  267. if (ret) {
  268. dev_err(chip->dev, "read status_high failed: %d\n", ret);
  269. return IRQ_HANDLED;
  270. }
  271. ret = adc_tm5_write(chip, ADC_TM_GEN2_STATUS_LOW_CLR, &status_low, sizeof(status_low));
  272. if (ret < 0) {
  273. dev_err(chip->dev, "clear status low failed with %d\n", ret);
  274. return IRQ_HANDLED;
  275. }
  276. ret = adc_tm5_write(chip, ADC_TM_GEN2_STATUS_HIGH_CLR, &status_high, sizeof(status_high));
  277. if (ret < 0) {
  278. dev_err(chip->dev, "clear status high failed with %d\n", ret);
  279. return IRQ_HANDLED;
  280. }
  281. for (i = 0; i < chip->nchannels; i++) {
  282. bool upper_set = false, lower_set = false;
  283. unsigned int ch = chip->channels[i].channel;
  284. /* No TZD, we warned at the boot time */
  285. if (!chip->channels[i].tzd)
  286. continue;
  287. if (!chip->channels[i].meas_en)
  288. continue;
  289. lower_set = (status_low & BIT(ch)) &&
  290. (chip->channels[i].low_thr_en);
  291. upper_set = (status_high & BIT(ch)) &&
  292. (chip->channels[i].high_thr_en);
  293. if (upper_set || lower_set)
  294. thermal_zone_device_update(chip->channels[i].tzd,
  295. THERMAL_EVENT_UNSPECIFIED);
  296. }
  297. return IRQ_HANDLED;
  298. }
  299. static int adc_tm5_get_temp(struct thermal_zone_device *tz, int *temp)
  300. {
  301. struct adc_tm5_channel *channel = tz->devdata;
  302. int ret;
  303. if (!channel || !channel->iio)
  304. return -EINVAL;
  305. ret = iio_read_channel_processed(channel->iio, temp);
  306. if (ret < 0)
  307. return ret;
  308. if (ret != IIO_VAL_INT)
  309. return -EINVAL;
  310. return 0;
  311. }
  312. static int adc_tm5_disable_channel(struct adc_tm5_channel *channel)
  313. {
  314. struct adc_tm5_chip *chip = channel->chip;
  315. unsigned int reg = ADC_TM5_M_EN(channel->channel);
  316. return adc_tm5_reg_update(chip, reg,
  317. ADC_TM5_M_MEAS_EN |
  318. ADC_TM5_M_HIGH_THR_INT_EN |
  319. ADC_TM5_M_LOW_THR_INT_EN,
  320. 0);
  321. }
  322. #define ADC_TM_GEN2_POLL_DELAY_MIN_US 100
  323. #define ADC_TM_GEN2_POLL_DELAY_MAX_US 110
  324. #define ADC_TM_GEN2_POLL_RETRY_COUNT 3
  325. static int32_t adc_tm5_gen2_conv_req(struct adc_tm5_chip *chip)
  326. {
  327. int ret;
  328. u8 data;
  329. unsigned int count;
  330. data = ADC_TM_GEN2_EN;
  331. ret = adc_tm5_write(chip, ADC_TM_GEN2_EN_CTL1, &data, 1);
  332. if (ret < 0) {
  333. dev_err(chip->dev, "adc-tm enable failed with %d\n", ret);
  334. return ret;
  335. }
  336. data = ADC_TM_GEN2_CFG_HS_FLAG;
  337. ret = adc_tm5_write(chip, ADC_TM_GEN2_CFG_HS_SET, &data, 1);
  338. if (ret < 0) {
  339. dev_err(chip->dev, "adc-tm handshake failed with %d\n", ret);
  340. return ret;
  341. }
  342. data = ADC_TM_GEN2_CONV_REQ_EN;
  343. ret = adc_tm5_write(chip, ADC_TM_GEN2_CONV_REQ, &data, 1);
  344. if (ret < 0) {
  345. dev_err(chip->dev, "adc-tm request conversion failed with %d\n", ret);
  346. return ret;
  347. }
  348. /*
  349. * SW sets a handshake bit and waits for PBS to clear it
  350. * before the next conversion request can be queued.
  351. */
  352. for (count = 0; count < ADC_TM_GEN2_POLL_RETRY_COUNT; count++) {
  353. ret = adc_tm5_read(chip, ADC_TM_GEN2_CFG_HS_SET, &data, sizeof(data));
  354. if (ret < 0) {
  355. dev_err(chip->dev, "adc-tm read failed with %d\n", ret);
  356. return ret;
  357. }
  358. if (!(data & ADC_TM_GEN2_CFG_HS_FLAG))
  359. return ret;
  360. usleep_range(ADC_TM_GEN2_POLL_DELAY_MIN_US,
  361. ADC_TM_GEN2_POLL_DELAY_MAX_US);
  362. }
  363. dev_err(chip->dev, "adc-tm conversion request handshake timed out\n");
  364. return -ETIMEDOUT;
  365. }
  366. static int adc_tm5_gen2_disable_channel(struct adc_tm5_channel *channel)
  367. {
  368. struct adc_tm5_chip *chip = channel->chip;
  369. int ret;
  370. u8 val;
  371. mutex_lock(&chip->adc_mutex_lock);
  372. channel->meas_en = false;
  373. channel->high_thr_en = false;
  374. channel->low_thr_en = false;
  375. ret = adc_tm5_read(chip, ADC_TM_GEN2_CH_CTL, &val, sizeof(val));
  376. if (ret < 0) {
  377. dev_err(chip->dev, "adc-tm block read failed with %d\n", ret);
  378. goto disable_fail;
  379. }
  380. val &= ~ADC_TM_GEN2_TM_CH_SEL;
  381. val |= FIELD_PREP(ADC_TM_GEN2_TM_CH_SEL, channel->channel);
  382. ret = adc_tm5_write(chip, ADC_TM_GEN2_CH_CTL, &val, 1);
  383. if (ret < 0) {
  384. dev_err(chip->dev, "adc-tm channel disable failed with %d\n", ret);
  385. goto disable_fail;
  386. }
  387. val = 0;
  388. ret = adc_tm5_write(chip, ADC_TM_GEN2_MEAS_IRQ_EN, &val, 1);
  389. if (ret < 0) {
  390. dev_err(chip->dev, "adc-tm interrupt disable failed with %d\n", ret);
  391. goto disable_fail;
  392. }
  393. ret = adc_tm5_gen2_conv_req(channel->chip);
  394. if (ret < 0)
  395. dev_err(chip->dev, "adc-tm channel configure failed with %d\n", ret);
  396. disable_fail:
  397. mutex_unlock(&chip->adc_mutex_lock);
  398. return ret;
  399. }
  400. static int adc_tm5_enable(struct adc_tm5_chip *chip)
  401. {
  402. int ret;
  403. u8 data;
  404. data = ADC_TM_EN;
  405. ret = adc_tm5_write(chip, ADC_TM_EN_CTL1, &data, sizeof(data));
  406. if (ret < 0) {
  407. dev_err(chip->dev, "adc-tm enable failed\n");
  408. return ret;
  409. }
  410. data = ADC_TM_CONV_REQ_EN;
  411. ret = adc_tm5_write(chip, ADC_TM_CONV_REQ, &data, sizeof(data));
  412. if (ret < 0) {
  413. dev_err(chip->dev, "adc-tm request conversion failed\n");
  414. return ret;
  415. }
  416. return 0;
  417. }
  418. static int adc_tm5_configure(struct adc_tm5_channel *channel, int low, int high)
  419. {
  420. struct adc_tm5_chip *chip = channel->chip;
  421. u8 buf[8];
  422. u16 reg = ADC_TM5_M_ADC_CH_SEL_CTL(channel->channel);
  423. int ret;
  424. ret = adc_tm5_read(chip, reg, buf, sizeof(buf));
  425. if (ret) {
  426. dev_err(chip->dev, "channel %d params read failed: %d\n", channel->channel, ret);
  427. return ret;
  428. }
  429. buf[0] = channel->adc_channel;
  430. /* High temperature corresponds to low voltage threshold */
  431. if (high != INT_MAX) {
  432. u16 adc_code = qcom_adc_tm5_temp_volt_scale(channel->prescale,
  433. chip->data->full_scale_code_volt, high);
  434. put_unaligned_le16(adc_code, &buf[1]);
  435. buf[7] |= ADC_TM5_M_LOW_THR_INT_EN;
  436. } else {
  437. buf[7] &= ~ADC_TM5_M_LOW_THR_INT_EN;
  438. }
  439. /* Low temperature corresponds to high voltage threshold */
  440. if (low != -INT_MAX) {
  441. u16 adc_code = qcom_adc_tm5_temp_volt_scale(channel->prescale,
  442. chip->data->full_scale_code_volt, low);
  443. put_unaligned_le16(adc_code, &buf[3]);
  444. buf[7] |= ADC_TM5_M_HIGH_THR_INT_EN;
  445. } else {
  446. buf[7] &= ~ADC_TM5_M_HIGH_THR_INT_EN;
  447. }
  448. buf[5] = ADC5_TIMER_SEL_2;
  449. /* Set calibration select, hw_settle delay */
  450. buf[6] &= ~ADC_TM5_M_CTL_HW_SETTLE_DELAY_MASK;
  451. buf[6] |= FIELD_PREP(ADC_TM5_M_CTL_HW_SETTLE_DELAY_MASK, channel->hw_settle_time);
  452. buf[6] &= ~ADC_TM5_M_CTL_CAL_SEL_MASK;
  453. buf[6] |= FIELD_PREP(ADC_TM5_M_CTL_CAL_SEL_MASK, channel->cal_method);
  454. buf[7] |= ADC_TM5_M_MEAS_EN;
  455. ret = adc_tm5_write(chip, reg, buf, sizeof(buf));
  456. if (ret) {
  457. dev_err(chip->dev, "channel %d params write failed: %d\n", channel->channel, ret);
  458. return ret;
  459. }
  460. return adc_tm5_enable(chip);
  461. }
  462. static int adc_tm5_gen2_configure(struct adc_tm5_channel *channel, int low, int high)
  463. {
  464. struct adc_tm5_chip *chip = channel->chip;
  465. int ret;
  466. u8 buf[14];
  467. u16 adc_code;
  468. mutex_lock(&chip->adc_mutex_lock);
  469. channel->meas_en = true;
  470. ret = adc_tm5_read(chip, ADC_TM_GEN2_SID, buf, sizeof(buf));
  471. if (ret < 0) {
  472. dev_err(chip->dev, "adc-tm block read failed with %d\n", ret);
  473. goto config_fail;
  474. }
  475. /* Set SID from virtual channel number */
  476. buf[0] = channel->adc_channel >> 8;
  477. /* Set TM channel number used and measurement interval */
  478. buf[1] &= ~ADC_TM_GEN2_TM_CH_SEL;
  479. buf[1] |= FIELD_PREP(ADC_TM_GEN2_TM_CH_SEL, channel->channel);
  480. buf[1] &= ~ADC_TM_GEN2_MEAS_INT_SEL;
  481. buf[1] |= FIELD_PREP(ADC_TM_GEN2_MEAS_INT_SEL, MEAS_INT_1S);
  482. buf[2] &= ~ADC_TM_GEN2_CTL_DEC_RATIO_MASK;
  483. buf[2] |= FIELD_PREP(ADC_TM_GEN2_CTL_DEC_RATIO_MASK, channel->decimation);
  484. buf[2] &= ~ADC_TM_GEN2_CTL_CAL_SEL;
  485. buf[2] |= FIELD_PREP(ADC_TM_GEN2_CTL_CAL_SEL, channel->cal_method);
  486. buf[3] = channel->avg_samples | ADC_TM_GEN2_FAST_AVG_EN;
  487. buf[4] = channel->adc_channel & 0xff;
  488. buf[5] = channel->hw_settle_time & ADC_TM_GEN2_HW_SETTLE_DELAY;
  489. /* High temperature corresponds to low voltage threshold */
  490. if (high != INT_MAX) {
  491. channel->low_thr_en = true;
  492. adc_code = qcom_adc_tm5_gen2_temp_res_scale(high);
  493. put_unaligned_le16(adc_code, &buf[9]);
  494. } else {
  495. channel->low_thr_en = false;
  496. }
  497. /* Low temperature corresponds to high voltage threshold */
  498. if (low != -INT_MAX) {
  499. channel->high_thr_en = true;
  500. adc_code = qcom_adc_tm5_gen2_temp_res_scale(low);
  501. put_unaligned_le16(adc_code, &buf[11]);
  502. } else {
  503. channel->high_thr_en = false;
  504. }
  505. buf[13] = ADC_TM_GEN2_MEAS_EN;
  506. if (channel->high_thr_en)
  507. buf[13] |= ADC_TM5_GEN2_HIGH_THR_INT_EN;
  508. if (channel->low_thr_en)
  509. buf[13] |= ADC_TM5_GEN2_LOW_THR_INT_EN;
  510. ret = adc_tm5_write(chip, ADC_TM_GEN2_SID, buf, sizeof(buf));
  511. if (ret) {
  512. dev_err(chip->dev, "channel %d params write failed: %d\n", channel->channel, ret);
  513. goto config_fail;
  514. }
  515. ret = adc_tm5_gen2_conv_req(channel->chip);
  516. if (ret < 0)
  517. dev_err(chip->dev, "adc-tm channel configure failed with %d\n", ret);
  518. config_fail:
  519. mutex_unlock(&chip->adc_mutex_lock);
  520. return ret;
  521. }
  522. static int adc_tm5_set_trips(struct thermal_zone_device *tz, int low, int high)
  523. {
  524. struct adc_tm5_channel *channel = tz->devdata;
  525. struct adc_tm5_chip *chip;
  526. int ret;
  527. if (!channel)
  528. return -EINVAL;
  529. chip = channel->chip;
  530. dev_dbg(chip->dev, "%d:low(mdegC):%d, high(mdegC):%d\n",
  531. channel->channel, low, high);
  532. if (high == INT_MAX && low <= -INT_MAX)
  533. ret = chip->data->disable_channel(channel);
  534. else
  535. ret = chip->data->configure(channel, low, high);
  536. return ret;
  537. }
  538. static const struct thermal_zone_device_ops adc_tm5_thermal_ops = {
  539. .get_temp = adc_tm5_get_temp,
  540. .set_trips = adc_tm5_set_trips,
  541. };
  542. static const struct thermal_zone_device_ops adc_tm5_thermal_iio_ops = {
  543. .get_temp = adc_tm5_get_temp,
  544. };
  545. static int adc_tm5_register_tzd(struct adc_tm5_chip *adc_tm, bool set_trips)
  546. {
  547. unsigned int i;
  548. struct thermal_zone_device *tzd;
  549. for (i = 0; i < adc_tm->nchannels; i++) {
  550. adc_tm->channels[i].chip = adc_tm;
  551. if (set_trips)
  552. tzd = devm_thermal_of_zone_register(adc_tm->dev,
  553. adc_tm->channels[i].channel,
  554. &adc_tm->channels[i],
  555. &adc_tm5_thermal_ops);
  556. else
  557. tzd = devm_thermal_of_zone_register(adc_tm->dev,
  558. adc_tm->channels[i].channel,
  559. &adc_tm->channels[i],
  560. &adc_tm5_thermal_iio_ops);
  561. if (IS_ERR(tzd)) {
  562. if (PTR_ERR(tzd) == -ENODEV) {
  563. dev_warn(adc_tm->dev, "thermal sensor on channel %d is not used\n",
  564. adc_tm->channels[i].channel);
  565. continue;
  566. }
  567. dev_err(adc_tm->dev, "Error registering TZ zone for channel %d: %ld\n",
  568. adc_tm->channels[i].channel, PTR_ERR(tzd));
  569. return PTR_ERR(tzd);
  570. }
  571. adc_tm->channels[i].tzd = tzd;
  572. if (devm_thermal_add_hwmon_sysfs(tzd))
  573. dev_warn(adc_tm->dev,
  574. "Failed to add hwmon sysfs attributes\n");
  575. }
  576. return 0;
  577. }
  578. static int adc_tm_hc_init(struct adc_tm5_chip *chip)
  579. {
  580. unsigned int i;
  581. u8 buf[2];
  582. int ret;
  583. for (i = 0; i < chip->nchannels; i++) {
  584. if (chip->channels[i].channel >= ADC_TM5_NUM_CHANNELS) {
  585. dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
  586. return -EINVAL;
  587. }
  588. }
  589. buf[0] = chip->decimation;
  590. buf[1] = chip->avg_samples | ADC_TM5_FAST_AVG_EN;
  591. ret = adc_tm5_write(chip, ADC_TM5_ADC_DIG_PARAM, buf, sizeof(buf));
  592. if (ret)
  593. dev_err(chip->dev, "block write failed: %d\n", ret);
  594. return ret;
  595. }
  596. static int adc_tm5_init(struct adc_tm5_chip *chip)
  597. {
  598. u8 buf[4], channels_available;
  599. int ret;
  600. unsigned int i;
  601. ret = adc_tm5_read(chip, ADC_TM5_NUM_BTM,
  602. &channels_available, sizeof(channels_available));
  603. if (ret) {
  604. dev_err(chip->dev, "read failed for BTM channels\n");
  605. return ret;
  606. }
  607. for (i = 0; i < chip->nchannels; i++) {
  608. if (chip->channels[i].channel >= channels_available) {
  609. dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
  610. return -EINVAL;
  611. }
  612. }
  613. buf[0] = chip->decimation;
  614. buf[1] = chip->avg_samples | ADC_TM5_FAST_AVG_EN;
  615. buf[2] = ADC_TM5_TIMER1;
  616. buf[3] = FIELD_PREP(ADC_TM5_MEAS_INTERVAL_CTL2_MASK, ADC_TM5_TIMER2) |
  617. FIELD_PREP(ADC_TM5_MEAS_INTERVAL_CTL3_MASK, ADC_TM5_TIMER3);
  618. ret = adc_tm5_write(chip, ADC_TM5_ADC_DIG_PARAM, buf, sizeof(buf));
  619. if (ret) {
  620. dev_err(chip->dev, "block write failed: %d\n", ret);
  621. return ret;
  622. }
  623. return ret;
  624. }
  625. static int adc_tm5_gen2_init(struct adc_tm5_chip *chip)
  626. {
  627. u8 channels_available;
  628. int ret;
  629. unsigned int i;
  630. ret = adc_tm5_read(chip, ADC_TM5_NUM_BTM,
  631. &channels_available, sizeof(channels_available));
  632. if (ret) {
  633. dev_err(chip->dev, "read failed for BTM channels\n");
  634. return ret;
  635. }
  636. for (i = 0; i < chip->nchannels; i++) {
  637. if (chip->channels[i].channel >= channels_available) {
  638. dev_err(chip->dev, "Invalid channel %d\n", chip->channels[i].channel);
  639. return -EINVAL;
  640. }
  641. }
  642. mutex_init(&chip->adc_mutex_lock);
  643. return ret;
  644. }
  645. static int adc_tm5_get_dt_channel_data(struct adc_tm5_chip *adc_tm,
  646. struct adc_tm5_channel *channel,
  647. struct device_node *node)
  648. {
  649. const char *name = node->name;
  650. u32 chan, value, adc_channel, varr[2];
  651. int ret;
  652. struct device *dev = adc_tm->dev;
  653. struct of_phandle_args args;
  654. ret = of_property_read_u32(node, "reg", &chan);
  655. if (ret) {
  656. dev_err(dev, "%s: invalid channel number %d\n", name, ret);
  657. return ret;
  658. }
  659. if (chan >= ADC_TM5_NUM_CHANNELS) {
  660. dev_err(dev, "%s: channel number too big: %d\n", name, chan);
  661. return -EINVAL;
  662. }
  663. channel->channel = chan;
  664. /*
  665. * We are tied to PMIC's ADC controller, which always use single
  666. * argument for channel number. So don't bother parsing
  667. * #io-channel-cells, just enforce cell_count = 1.
  668. */
  669. ret = of_parse_phandle_with_fixed_args(node, "io-channels", 1, 0, &args);
  670. if (ret < 0) {
  671. dev_err(dev, "%s: error parsing ADC channel number %d: %d\n", name, chan, ret);
  672. return ret;
  673. }
  674. of_node_put(args.np);
  675. if (args.args_count != 1) {
  676. dev_err(dev, "%s: invalid args count for ADC channel %d\n", name, chan);
  677. return -EINVAL;
  678. }
  679. adc_channel = args.args[0];
  680. if (adc_tm->data->gen == ADC_TM5_GEN2)
  681. adc_channel &= 0xff;
  682. if (adc_channel >= ADC5_MAX_CHANNEL) {
  683. dev_err(dev, "%s: invalid ADC channel number %d\n", name, chan);
  684. return -EINVAL;
  685. }
  686. channel->adc_channel = args.args[0];
  687. channel->iio = devm_fwnode_iio_channel_get_by_name(adc_tm->dev,
  688. of_fwnode_handle(node), NULL);
  689. if (IS_ERR(channel->iio)) {
  690. ret = PTR_ERR(channel->iio);
  691. if (ret != -EPROBE_DEFER)
  692. dev_err(dev, "%s: error getting channel: %d\n", name, ret);
  693. return ret;
  694. }
  695. ret = of_property_read_u32_array(node, "qcom,pre-scaling", varr, 2);
  696. if (!ret) {
  697. ret = qcom_adc5_prescaling_from_dt(varr[0], varr[1]);
  698. if (ret < 0) {
  699. dev_err(dev, "%s: invalid pre-scaling <%d %d>\n",
  700. name, varr[0], varr[1]);
  701. return ret;
  702. }
  703. channel->prescale = ret;
  704. } else {
  705. /* 1:1 prescale is index 0 */
  706. channel->prescale = 0;
  707. }
  708. ret = of_property_read_u32(node, "qcom,hw-settle-time-us", &value);
  709. if (!ret) {
  710. ret = qcom_adc5_hw_settle_time_from_dt(value, adc_tm->data->hw_settle);
  711. if (ret < 0) {
  712. dev_err(dev, "%s invalid hw-settle-time-us %d us\n",
  713. name, value);
  714. return ret;
  715. }
  716. channel->hw_settle_time = ret;
  717. } else {
  718. channel->hw_settle_time = VADC_DEF_HW_SETTLE_TIME;
  719. }
  720. if (of_property_read_bool(node, "qcom,ratiometric"))
  721. channel->cal_method = ADC_TM5_RATIOMETRIC_CAL;
  722. else
  723. channel->cal_method = ADC_TM5_ABSOLUTE_CAL;
  724. if (adc_tm->data->gen == ADC_TM5_GEN2) {
  725. ret = of_property_read_u32(node, "qcom,decimation", &value);
  726. if (!ret) {
  727. ret = qcom_adc5_decimation_from_dt(value, adc_tm->data->decimation);
  728. if (ret < 0) {
  729. dev_err(dev, "invalid decimation %d\n", value);
  730. return ret;
  731. }
  732. channel->decimation = ret;
  733. } else {
  734. channel->decimation = ADC5_DECIMATION_DEFAULT;
  735. }
  736. ret = of_property_read_u32(node, "qcom,avg-samples", &value);
  737. if (!ret) {
  738. ret = qcom_adc5_avg_samples_from_dt(value);
  739. if (ret < 0) {
  740. dev_err(dev, "invalid avg-samples %d\n", value);
  741. return ret;
  742. }
  743. channel->avg_samples = ret;
  744. } else {
  745. channel->avg_samples = VADC_DEF_AVG_SAMPLES;
  746. }
  747. }
  748. return 0;
  749. }
  750. static const struct adc_tm5_data adc_tm5_data_pmic = {
  751. .full_scale_code_volt = 0x70e4,
  752. .decimation = (unsigned int []) { 250, 420, 840 },
  753. .hw_settle = (unsigned int []) { 15, 100, 200, 300, 400, 500, 600, 700,
  754. 1000, 2000, 4000, 8000, 16000, 32000,
  755. 64000, 128000 },
  756. .disable_channel = adc_tm5_disable_channel,
  757. .configure = adc_tm5_configure,
  758. .isr = adc_tm5_isr,
  759. .init = adc_tm5_init,
  760. .irq_name = "pm-adc-tm5",
  761. .gen = ADC_TM5,
  762. };
  763. static const struct adc_tm5_data adc_tm_hc_data_pmic = {
  764. .full_scale_code_volt = 0x70e4,
  765. .decimation = (unsigned int []) { 256, 512, 1024 },
  766. .hw_settle = (unsigned int []) { 0, 100, 200, 300, 400, 500, 600, 700,
  767. 1000, 2000, 4000, 6000, 8000, 10000 },
  768. .disable_channel = adc_tm5_disable_channel,
  769. .configure = adc_tm5_configure,
  770. .isr = adc_tm5_isr,
  771. .init = adc_tm_hc_init,
  772. .irq_name = "pm-adc-tm5",
  773. .gen = ADC_TM_HC,
  774. };
  775. static const struct adc_tm5_data adc_tm5_gen2_data_pmic = {
  776. .full_scale_code_volt = 0x70e4,
  777. .decimation = (unsigned int []) { 85, 340, 1360 },
  778. .hw_settle = (unsigned int []) { 15, 100, 200, 300, 400, 500, 600, 700,
  779. 1000, 2000, 4000, 8000, 16000, 32000,
  780. 64000, 128000 },
  781. .disable_channel = adc_tm5_gen2_disable_channel,
  782. .configure = adc_tm5_gen2_configure,
  783. .isr = adc_tm5_gen2_isr,
  784. .init = adc_tm5_gen2_init,
  785. .irq_name = "pm-adc-tm5-gen2",
  786. .gen = ADC_TM5_GEN2,
  787. };
  788. static int adc_tm5_get_dt_data(struct adc_tm5_chip *adc_tm, struct device_node *node)
  789. {
  790. struct adc_tm5_channel *channels;
  791. struct device_node *child;
  792. u32 value;
  793. int ret;
  794. struct device *dev = adc_tm->dev;
  795. adc_tm->nchannels = of_get_available_child_count(node);
  796. if (!adc_tm->nchannels)
  797. return -EINVAL;
  798. adc_tm->channels = devm_kcalloc(dev, adc_tm->nchannels,
  799. sizeof(*adc_tm->channels), GFP_KERNEL);
  800. if (!adc_tm->channels)
  801. return -ENOMEM;
  802. channels = adc_tm->channels;
  803. adc_tm->data = of_device_get_match_data(dev);
  804. if (!adc_tm->data)
  805. adc_tm->data = &adc_tm5_data_pmic;
  806. ret = of_property_read_u32(node, "qcom,decimation", &value);
  807. if (!ret) {
  808. ret = qcom_adc5_decimation_from_dt(value, adc_tm->data->decimation);
  809. if (ret < 0) {
  810. dev_err(dev, "invalid decimation %d\n", value);
  811. return ret;
  812. }
  813. adc_tm->decimation = ret;
  814. } else {
  815. adc_tm->decimation = ADC5_DECIMATION_DEFAULT;
  816. }
  817. ret = of_property_read_u32(node, "qcom,avg-samples", &value);
  818. if (!ret) {
  819. ret = qcom_adc5_avg_samples_from_dt(value);
  820. if (ret < 0) {
  821. dev_err(dev, "invalid avg-samples %d\n", value);
  822. return ret;
  823. }
  824. adc_tm->avg_samples = ret;
  825. } else {
  826. adc_tm->avg_samples = VADC_DEF_AVG_SAMPLES;
  827. }
  828. for_each_available_child_of_node(node, child) {
  829. ret = adc_tm5_get_dt_channel_data(adc_tm, channels, child);
  830. if (ret) {
  831. of_node_put(child);
  832. return ret;
  833. }
  834. channels++;
  835. }
  836. return 0;
  837. }
  838. static int adc_tm5_probe(struct platform_device *pdev)
  839. {
  840. struct device_node *node = pdev->dev.of_node;
  841. struct device *dev = &pdev->dev;
  842. struct adc_tm5_chip *adc_tm;
  843. struct regmap *regmap;
  844. int ret;
  845. u32 reg;
  846. regmap = dev_get_regmap(dev->parent, NULL);
  847. if (!regmap)
  848. return -ENODEV;
  849. ret = of_property_read_u32(node, "reg", &reg);
  850. if (ret)
  851. return ret;
  852. adc_tm = devm_kzalloc(&pdev->dev, sizeof(*adc_tm), GFP_KERNEL);
  853. if (!adc_tm)
  854. return -ENOMEM;
  855. adc_tm->regmap = regmap;
  856. adc_tm->dev = dev;
  857. adc_tm->base = reg;
  858. ret = adc_tm5_get_dt_data(adc_tm, node);
  859. if (ret) {
  860. dev_err(dev, "get dt data failed: %d\n", ret);
  861. return ret;
  862. }
  863. if (of_device_is_compatible(node, "qcom,spmi-adc-tm5-iio")) {
  864. ret = adc_tm5_register_tzd(adc_tm, false);
  865. if (ret)
  866. dev_err(dev, "tzd register failed for adc tm5 iio channel\n");
  867. return ret;
  868. }
  869. adc_tm->irq = platform_get_irq(pdev, 0);
  870. if (adc_tm->irq < 0)
  871. return adc_tm->irq;
  872. dev_set_drvdata(dev, adc_tm);
  873. ret = adc_tm->data->init(adc_tm);
  874. if (ret) {
  875. dev_err(dev, "adc-tm init failed\n");
  876. return ret;
  877. }
  878. ret = adc_tm5_register_tzd(adc_tm, true);
  879. if (ret) {
  880. dev_err(dev, "tzd register failed\n");
  881. return ret;
  882. }
  883. return devm_request_threaded_irq(dev, adc_tm->irq, NULL,
  884. adc_tm->data->isr, IRQF_ONESHOT,
  885. adc_tm->data->irq_name, adc_tm);
  886. }
  887. static int adc_tm_restore(struct device *dev)
  888. {
  889. struct adc_tm5_chip *adc_tm = dev_get_drvdata(dev);
  890. int ret;
  891. if (adc_tm->irq > 0) {
  892. ret = devm_request_threaded_irq(dev, adc_tm->irq, NULL,
  893. adc_tm->data->isr, IRQF_ONESHOT,
  894. adc_tm->data->irq_name, adc_tm);
  895. if (ret < 0)
  896. return ret;
  897. }
  898. ret = adc_tm->data->init(adc_tm);
  899. if (ret < 0)
  900. dev_err(dev, "init failed\n");
  901. return ret;
  902. }
  903. static int adc_tm_freeze(struct device *dev)
  904. {
  905. struct adc_tm5_chip *adc_tm = dev_get_drvdata(dev);
  906. if (adc_tm->irq > 0) {
  907. disable_irq(adc_tm->irq);
  908. devm_free_irq(dev, adc_tm->irq, adc_tm);
  909. }
  910. return 0;
  911. }
  912. static const struct dev_pm_ops adc_tm_pm_ops = {
  913. .freeze = adc_tm_freeze,
  914. .restore = adc_tm_restore,
  915. };
  916. static const struct of_device_id adc_tm5_match_table[] = {
  917. {
  918. .compatible = "qcom,spmi-adc-tm5",
  919. .data = &adc_tm5_data_pmic,
  920. },
  921. {
  922. .compatible = "qcom,spmi-adc-tm-hc",
  923. .data = &adc_tm_hc_data_pmic,
  924. },
  925. {
  926. .compatible = "qcom,spmi-adc-tm5-gen2",
  927. .data = &adc_tm5_gen2_data_pmic,
  928. },
  929. {
  930. .compatible = "qcom,spmi-adc-tm5-iio",
  931. .data = &adc_tm5_data_pmic,
  932. },
  933. { }
  934. };
  935. MODULE_DEVICE_TABLE(of, adc_tm5_match_table);
  936. static struct platform_driver adc_tm5_driver = {
  937. .driver = {
  938. .name = "qcom-spmi-adc-tm5",
  939. .of_match_table = adc_tm5_match_table,
  940. .pm = &adc_tm_pm_ops,
  941. },
  942. .probe = adc_tm5_probe,
  943. };
  944. module_platform_driver(adc_tm5_driver);
  945. MODULE_DESCRIPTION("SPMI PMIC Thermal Monitor ADC driver");
  946. MODULE_LICENSE("GPL v2");