pm8xxx-adc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. /*
  2. * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. /*
  14. * Qualcomm PMIC 8921/8018 ADC driver header file
  15. *
  16. */
  17. #ifndef __PM8XXX_ADC_H
  18. #define __PM8XXX_ADC_H
  19. #include <linux/kernel.h>
  20. #include <linux/list.h>
  21. /**
  22. * enum pm8xxx_adc_channels - PM8XXX AMUX arbiter channels
  23. * %CHANNEL_VCOIN: Backup voltage for certain register set
  24. * %CHANNEL_VBAT: Battery voltage
  25. * %CHANNEL_DCIN: Charger input voltage without internal OVP
  26. * %CHANNEL_ICHG: Charge-current monitor
  27. * %CHANNEL_VPH_PWR: Main system power
  28. * %CHANNEL_IBAT: Battery charge current
  29. * %CHANNEL_MPP_1: 16:1 pre-mux unity scale MPP input
  30. * %CHANNEL_MPP_2: 16:1 pre-mux 1/3 scale MPP input
  31. * %CHANNEL_BATT_THERM: Battery temperature
  32. * %CHANNEL_BATT_ID: Battery detection
  33. * %CHANNEL_USBIN: Charger input voltage with internal OVP
  34. * %CHANNEL_DIE_TEMP: Pmic_die temperature
  35. * %CHANNEL_625MV: 625mv reference channel
  36. * %CHANNEL_125V: 1.25v reference channel
  37. * %CHANNEL_CHG_TEMP: Charger temperature
  38. * %CHANNEL_MUXOFF: Channel to reduce input load on the mux
  39. * %CHANNEL_NONE: Do not use this channel
  40. */
  41. enum pm8xxx_adc_channels {
  42. CHANNEL_VCOIN = 0,
  43. CHANNEL_VBAT,
  44. CHANNEL_DCIN,
  45. CHANNEL_ICHG,
  46. CHANNEL_VPH_PWR,
  47. CHANNEL_IBAT,
  48. CHANNEL_MPP_1,
  49. CHANNEL_MPP_2,
  50. CHANNEL_BATT_THERM,
  51. /* PM8018 ADC Arbiter uses a single channel on AMUX8
  52. * to read either Batt_id or Batt_therm.
  53. */
  54. CHANNEL_BATT_ID_THERM = CHANNEL_BATT_THERM,
  55. CHANNEL_BATT_ID,
  56. CHANNEL_USBIN,
  57. CHANNEL_DIE_TEMP,
  58. CHANNEL_625MV,
  59. CHANNEL_125V,
  60. CHANNEL_CHG_TEMP,
  61. CHANNEL_MUXOFF,
  62. CHANNEL_NONE,
  63. ADC_MPP_1_ATEST_8 = 20,
  64. ADC_MPP_1_USB_SNS_DIV20,
  65. ADC_MPP_1_DCIN_SNS_DIV20,
  66. ADC_MPP_1_AMUX3,
  67. ADC_MPP_1_AMUX4,
  68. ADC_MPP_1_AMUX5,
  69. ADC_MPP_1_AMUX6,
  70. ADC_MPP_1_AMUX7,
  71. ADC_MPP_1_AMUX8,
  72. ADC_MPP_1_ATEST_1,
  73. ADC_MPP_1_ATEST_2,
  74. ADC_MPP_1_ATEST_3,
  75. ADC_MPP_1_ATEST_4,
  76. ADC_MPP_1_ATEST_5,
  77. ADC_MPP_1_ATEST_6,
  78. ADC_MPP_1_ATEST_7,
  79. ADC_MPP_2_ATEST_8 = 40,
  80. ADC_MPP_2_USB_SNS_DIV20,
  81. ADC_MPP_2_DCIN_SNS_DIV20,
  82. ADC_MPP_2_AMUX3,
  83. ADC_MPP_2_AMUX4,
  84. ADC_MPP_2_AMUX5,
  85. ADC_MPP_2_AMUX6,
  86. ADC_MPP_2_AMUX7,
  87. ADC_MPP_2_AMUX8,
  88. ADC_MPP_2_ATEST_1,
  89. ADC_MPP_2_ATEST_2,
  90. ADC_MPP_2_ATEST_3,
  91. ADC_MPP_2_ATEST_4,
  92. ADC_MPP_2_ATEST_5,
  93. ADC_MPP_2_ATEST_6,
  94. ADC_MPP_2_ATEST_7,
  95. ADC_CHANNEL_MAX_NUM,
  96. };
  97. #define PM8XXX_ADC_PMIC_0 0x0
  98. #define PM8XXX_CHANNEL_ADC_625_UV 625000
  99. #define PM8XXX_CHANNEL_MPP_SCALE1_IDX 20
  100. #define PM8XXX_CHANNEL_MPP_SCALE3_IDX 40
  101. #define PM8XXX_AMUX_MPP_3 0x3
  102. #define PM8XXX_AMUX_MPP_4 0x4
  103. #define PM8XXX_AMUX_MPP_5 0x5
  104. #define PM8XXX_AMUX_MPP_6 0x6
  105. #define PM8XXX_AMUX_MPP_7 0x7
  106. #define PM8XXX_AMUX_MPP_8 0x8
  107. #define PM8XXX_ADC_DEV_NAME "pm8xxx-adc"
  108. /**
  109. * enum pm8xxx_adc_decimation_type - Sampling rate supported
  110. * %ADC_DECIMATION_TYPE1: 512
  111. * %ADC_DECIMATION_TYPE2: 1K
  112. * %ADC_DECIMATION_TYPE3: 2K
  113. * %ADC_DECIMATION_TYPE4: 4k
  114. * %ADC_DECIMATION_NONE: Do not use this Sampling type
  115. *
  116. * The Sampling rate is specific to each channel of the PM8XXX ADC arbiter.
  117. */
  118. enum pm8xxx_adc_decimation_type {
  119. ADC_DECIMATION_TYPE1 = 0,
  120. ADC_DECIMATION_TYPE2,
  121. ADC_DECIMATION_TYPE3,
  122. ADC_DECIMATION_TYPE4,
  123. ADC_DECIMATION_NONE,
  124. };
  125. /**
  126. * enum pm8xxx_adc_calib_type - PM8XXX ADC Calibration type
  127. * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels
  128. * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND
  129. * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type
  130. *
  131. * Use the input reference voltage depending on the calibration type
  132. * to calcluate the offset and gain parameters. The calibration is
  133. * specific to each channel of the PM8XXX ADC.
  134. */
  135. enum pm8xxx_adc_calib_type {
  136. ADC_CALIB_ABSOLUTE = 0,
  137. ADC_CALIB_RATIOMETRIC,
  138. ADC_CALIB_NONE,
  139. };
  140. /**
  141. * enum pm8xxx_adc_channel_scaling_param - pre-scaling AMUX ratio
  142. * %CHAN_PATH_SCALING1: ratio of {1, 1}
  143. * %CHAN_PATH_SCALING2: ratio of {1, 3}
  144. * %CHAN_PATH_SCALING3: ratio of {1, 4}
  145. * %CHAN_PATH_SCALING4: ratio of {1, 6}
  146. * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type
  147. *
  148. * The pre-scaling is applied for signals to be within the voltage range
  149. * of the ADC.
  150. */
  151. enum pm8xxx_adc_channel_scaling_param {
  152. CHAN_PATH_SCALING1 = 0,
  153. CHAN_PATH_SCALING2,
  154. CHAN_PATH_SCALING3,
  155. CHAN_PATH_SCALING4,
  156. CHAN_PATH_SCALING_NONE,
  157. };
  158. /**
  159. * enum pm8xxx_adc_amux_input_rsv - HK/XOADC reference voltage
  160. * %AMUX_RSV0: XO_IN/XOADC_GND
  161. * %AMUX_RSV1: PMIC_IN/XOADC_GND
  162. * %AMUX_RSV2: PMIC_IN/BMS_CSP
  163. * %AMUX_RSV3: not used
  164. * %AMUX_RSV4: XOADC_GND/XOADC_GND
  165. * %AMUX_RSV5: XOADC_VREF/XOADC_GND
  166. * %AMUX_NONE: Do not use this input reference voltage selection
  167. */
  168. enum pm8xxx_adc_amux_input_rsv {
  169. AMUX_RSV0 = 0,
  170. AMUX_RSV1,
  171. AMUX_RSV2,
  172. AMUX_RSV3,
  173. AMUX_RSV4,
  174. AMUX_RSV5,
  175. AMUX_NONE,
  176. };
  177. /**
  178. * enum pm8xxx_adc_premux_mpp_scale_type - 16:1 pre-mux scale ratio
  179. * %PREMUX_MPP_SCALE_0: No scaling to the input signal
  180. * %PREMUX_MPP_SCALE_1: Unity scaling selected by the user for MPP input
  181. * %PREMUX_MPP_SCALE_1_DIV3: 1/3 pre-scale to the input MPP signal
  182. * %PREMUX_MPP_NONE: Do not use this pre-scale mpp type
  183. */
  184. enum pm8xxx_adc_premux_mpp_scale_type {
  185. PREMUX_MPP_SCALE_0 = 0,
  186. PREMUX_MPP_SCALE_1,
  187. PREMUX_MPP_SCALE_1_DIV3,
  188. PREMUX_MPP_NONE,
  189. };
  190. /**
  191. * enum pm8xxx_adc_scale_fn_type - Scaling function for pm8921 pre calibrated
  192. * digital data relative to ADC reference
  193. * %ADC_SCALE_DEFAULT: Default scaling to convert raw adc code to voltage
  194. * %ADC_SCALE_BATT_THERM: Conversion to temperature based on btm parameters
  195. * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade
  196. * %ADC_SCALE_XTERN_CHGR_CUR: Returns current across 0.1 ohm resistor
  197. * %ADC_SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade
  198. * %ADC_SCALE_NONE: Do not use this scaling type
  199. */
  200. enum pm8xxx_adc_scale_fn_type {
  201. ADC_SCALE_DEFAULT = 0,
  202. ADC_SCALE_BATT_THERM,
  203. ADC_SCALE_PA_THERM,
  204. ADC_SCALE_PMIC_THERM,
  205. ADC_SCALE_XOTHERM,
  206. ADC_SCALE_NONE,
  207. };
  208. /**
  209. * struct pm8xxx_adc_linear_graph - Represent ADC characteristics
  210. * @dy: Numerator slope to calculate the gain
  211. * @dx: Denominator slope to calculate the gain
  212. * @adc_vref: A/D word of the voltage reference used for the channel
  213. * @adc_gnd: A/D word of the ground reference used for the channel
  214. *
  215. * Each ADC device has different offset and gain parameters which are computed
  216. * to calibrate the device.
  217. */
  218. struct pm8xxx_adc_linear_graph {
  219. int64_t dy;
  220. int64_t dx;
  221. int64_t adc_vref;
  222. int64_t adc_gnd;
  223. };
  224. /**
  225. * struct pm8xxx_adc_map_pt - Map the graph representation for ADC channel
  226. * @x: Represent the ADC digitized code
  227. * @y: Represent the physical data which can be temperature, voltage,
  228. * resistance
  229. */
  230. struct pm8xxx_adc_map_pt {
  231. int32_t x;
  232. int32_t y;
  233. };
  234. /**
  235. * struct pm8xxx_adc_scaling_ratio - Represent scaling ratio for adc input
  236. * @num: Numerator scaling parameter
  237. * @den: Denominator scaling parameter
  238. */
  239. struct pm8xxx_adc_scaling_ratio {
  240. int32_t num;
  241. int32_t den;
  242. };
  243. /**
  244. * struct pm8xxx_adc_properties - Represent the ADC properties
  245. * @adc_reference: Reference voltage for PM8XXX ADC
  246. * @bitresolution: ADC bit resolution for PM8XXX ADC
  247. * @biploar: Polarity for PM8XXX ADC
  248. */
  249. struct pm8xxx_adc_properties {
  250. uint32_t adc_vdd_reference;
  251. uint32_t bitresolution;
  252. bool bipolar;
  253. };
  254. /**
  255. * struct pm8xxx_adc_chan_properties - Represent channel properties of the ADC
  256. * @offset_gain_numerator: The inverse numerator of the gain applied to the
  257. * input channel
  258. * @offset_gain_denominator: The inverse denominator of the gain applied to the
  259. * input channel
  260. * @adc_graph: ADC graph for the channel of struct type pm8xxx_adc_linear_graph
  261. */
  262. struct pm8xxx_adc_chan_properties {
  263. uint32_t offset_gain_numerator;
  264. uint32_t offset_gain_denominator;
  265. struct pm8xxx_adc_linear_graph adc_graph[2];
  266. };
  267. /**
  268. * struct pm8xxx_adc_chan_result - Represent the result of the PM8XXX ADC
  269. * @chan: The channel number of the requested conversion
  270. * @adc_code: The pre-calibrated digital output of a given ADC relative to the
  271. * the ADC reference
  272. * @measurement: In units specific for a given ADC; most ADC uses reference
  273. * voltage but some ADC uses reference current. This measurement
  274. * here is a number relative to a reference of a given ADC
  275. * @physical: The data meaningful for each individual channel whether it is
  276. * voltage, current, temperature, etc.
  277. * All voltage units are represented in micro - volts.
  278. * -Battery temperature units are represented as 0.1 DegC
  279. * -PA Therm temperature units are represented as DegC
  280. * -PMIC Die temperature units are represented as 0.001 DegC
  281. */
  282. struct pm8xxx_adc_chan_result {
  283. uint32_t chan;
  284. int32_t adc_code;
  285. int64_t measurement;
  286. int64_t physical;
  287. };
  288. #if defined(CONFIG_SENSORS_PM8XXX_ADC) \
  289. || defined(CONFIG_SENSORS_PM8XXX_ADC_MODULE)
  290. /**
  291. * pm8xxx_adc_scale_default() - Scales the pre-calibrated digital output
  292. * of an ADC to the ADC reference and compensates for the
  293. * gain and offset.
  294. * @adc_code: pre-calibrated digital ouput of the ADC.
  295. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  296. * reference voltage.
  297. * @chan_prop: individual channel properties to compensate the i/p scaling,
  298. * slope and offset.
  299. * @chan_rslt: Physical result to be stored.
  300. */
  301. int32_t pm8xxx_adc_scale_default(int32_t adc_code,
  302. const struct pm8xxx_adc_properties *adc_prop,
  303. const struct pm8xxx_adc_chan_properties *chan_prop,
  304. struct pm8xxx_adc_chan_result *chan_rslt);
  305. /**
  306. * pm8xxx_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
  307. * of an ADC to the ADC reference and compensates for the
  308. * gain and offset. Returns the temperature of the xo therm in mili
  309. degC.
  310. * @adc_code: pre-calibrated digital ouput of the ADC.
  311. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  312. * reference voltage.
  313. * @chan_prop: individual channel properties to compensate the i/p scaling,
  314. * slope and offset.
  315. * @chan_rslt: physical result to be stored.
  316. */
  317. int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
  318. const struct pm8xxx_adc_properties *adc_prop,
  319. const struct pm8xxx_adc_chan_properties *chan_prop,
  320. struct pm8xxx_adc_chan_result *chan_rslt);
  321. /**
  322. * pm8xxx_adc_scale_batt_therm() - Scales the pre-calibrated digital output
  323. * of an ADC to the ADC reference and compensates for the
  324. * gain and offset. Returns the temperature in degC.
  325. * @adc_code: pre-calibrated digital ouput of the ADC.
  326. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  327. * reference voltage.
  328. * @chan_prop: individual channel properties to compensate the i/p scaling,
  329. * slope and offset.
  330. * @chan_rslt: physical result to be stored.
  331. */
  332. int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
  333. const struct pm8xxx_adc_properties *adc_prop,
  334. const struct pm8xxx_adc_chan_properties *chan_prop,
  335. struct pm8xxx_adc_chan_result *chan_rslt);
  336. /**
  337. * pm8xxx_adc_scale_pa_therm() - Scales the pre-calibrated digital output
  338. * of an ADC to the ADC reference and compensates for the
  339. * gain and offset. Returns the temperature in degC.
  340. * @adc_code: pre-calibrated digital ouput of the ADC.
  341. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  342. * reference voltage.
  343. * @chan_prop: individual channel properties to compensate the i/p scaling,
  344. * slope and offset.
  345. * @chan_rslt: physical result to be stored.
  346. */
  347. int32_t pm8xxx_adc_scale_pa_therm(int32_t adc_code,
  348. const struct pm8xxx_adc_properties *adc_prop,
  349. const struct pm8xxx_adc_chan_properties *chan_prop,
  350. struct pm8xxx_adc_chan_result *chan_rslt);
  351. /**
  352. * pm8xxx_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
  353. * of an ADC to the ADC reference and compensates for the
  354. * gain and offset. Performs the AMUX out as 2mv/K and returns
  355. * the temperature in mili degC.
  356. * @adc_code: pre-calibrated digital ouput of the ADC.
  357. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  358. * reference voltage.
  359. * @chan_prop: individual channel properties to compensate the i/p scaling,
  360. * slope and offset.
  361. * @chan_rslt: physical result to be stored.
  362. */
  363. int32_t pm8xxx_adc_scale_pmic_therm(int32_t adc_code,
  364. const struct pm8xxx_adc_properties *adc_prop,
  365. const struct pm8xxx_adc_chan_properties *chan_prop,
  366. struct pm8xxx_adc_chan_result *chan_rslt);
  367. /**
  368. * pm8xxx_adc_scale_batt_id() - Scales the pre-calibrated digital output
  369. * of an ADC to the ADC reference and compensates for the
  370. * gain and offset.
  371. * @adc_code: pre-calibrated digital ouput of the ADC.
  372. * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
  373. * reference voltage.
  374. * @chan_prop: individual channel properties to compensate the i/p scaling,
  375. * slope and offset.
  376. * @chan_rslt: physical result to be stored.
  377. */
  378. int32_t pm8xxx_adc_scale_batt_id(int32_t adc_code,
  379. const struct pm8xxx_adc_properties *adc_prop,
  380. const struct pm8xxx_adc_chan_properties *chan_prop,
  381. struct pm8xxx_adc_chan_result *chan_rslt);
  382. #else
  383. static inline int32_t pm8xxx_adc_scale_default(int32_t adc_code,
  384. const struct pm8xxx_adc_properties *adc_prop,
  385. const struct pm8xxx_adc_chan_properties *chan_prop,
  386. struct pm8xxx_adc_chan_result *chan_rslt)
  387. { return -ENXIO; }
  388. static inline int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
  389. const struct pm8xxx_adc_properties *adc_prop,
  390. const struct pm8xxx_adc_chan_properties *chan_prop,
  391. struct pm8xxx_adc_chan_result *chan_rslt)
  392. { return -ENXIO; }
  393. static inline int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
  394. const struct pm8xxx_adc_properties *adc_prop,
  395. const struct pm8xxx_adc_chan_properties *chan_prop,
  396. struct pm8xxx_adc_chan_result *chan_rslt)
  397. { return -ENXIO; }
  398. static inline int32_t pm8xxx_adc_scale_pa_therm(int32_t adc_code,
  399. const struct pm8xxx_adc_properties *adc_prop,
  400. const struct pm8xxx_adc_chan_properties *chan_prop,
  401. struct pm8xxx_adc_chan_result *chan_rslt)
  402. { return -ENXIO; }
  403. static inline int32_t pm8xxx_adc_scale_pmic_therm(int32_t adc_code,
  404. const struct pm8xxx_adc_properties *adc_prop,
  405. const struct pm8xxx_adc_chan_properties *chan_prop,
  406. struct pm8xxx_adc_chan_result *chan_rslt)
  407. { return -ENXIO; }
  408. static inline int32_t pm8xxx_adc_scale_batt_id(int32_t adc_code,
  409. const struct pm8xxx_adc_properties *adc_prop,
  410. const struct pm8xxx_adc_chan_properties *chan_prop,
  411. struct pm8xxx_adc_chan_result *chan_rslt)
  412. { return -ENXIO; }
  413. #endif
  414. /**
  415. * struct pm8xxx_adc_scale_fn - Scaling function prototype
  416. * @chan: Function pointer to one of the scaling functions
  417. * which takes the adc properties, channel properties,
  418. * and returns the physical result
  419. */
  420. struct pm8xxx_adc_scale_fn {
  421. int32_t (*chan) (int32_t,
  422. const struct pm8xxx_adc_properties *,
  423. const struct pm8xxx_adc_chan_properties *,
  424. struct pm8xxx_adc_chan_result *);
  425. };
  426. /**
  427. * struct pm8xxx_adc_amux - AMUX properties for individual channel
  428. * @name: Channel name
  429. * @channel_name: Channel in integer used from pm8xxx_adc_channels
  430. * @chan_path_prescaling: Channel scaling performed on the input signal
  431. * @adc_rsv: Input reference Voltage/GND selection to the ADC
  432. * @adc_decimation: Sampling rate desired for the channel
  433. * adc_scale_fn: Scaling function to convert to the data meaningful for
  434. * each individual channel whether it is voltage, current,
  435. * temperature, etc and compensates the channel properties
  436. */
  437. struct pm8xxx_adc_amux {
  438. char *name;
  439. enum pm8xxx_adc_channels channel_name;
  440. enum pm8xxx_adc_channel_scaling_param chan_path_prescaling;
  441. enum pm8xxx_adc_amux_input_rsv adc_rsv;
  442. enum pm8xxx_adc_decimation_type adc_decimation;
  443. enum pm8xxx_adc_scale_fn_type adc_scale_fn;
  444. };
  445. /**
  446. * struct pm8xxx_adc_arb_btm_param - PM8XXX ADC BTM parameters to set threshold
  447. * temperature for client notification
  448. * @low_thr_temp: low temperature threshold request for notification
  449. * @high_thr_temp: high temperature threshold request for notification
  450. * @low_thr_voltage: low temperature converted to voltage by arbiter driver
  451. * @high_thr_voltage: high temperature converted to voltage by arbiter driver
  452. * @interval: Interval period to check for temperature notification
  453. * @btm_warm_fn: Remote function call for warm threshold.
  454. * @btm_cool_fn: Remote function call for cold threshold.
  455. *
  456. * BTM client passes the parameters to be set for the
  457. * temperature threshold notifications. The client is
  458. * responsible for setting the new threshold
  459. * levels once the thresholds are reached
  460. */
  461. struct pm8xxx_adc_arb_btm_param {
  462. int32_t low_thr_temp;
  463. int32_t high_thr_temp;
  464. uint64_t low_thr_voltage;
  465. uint64_t high_thr_voltage;
  466. int32_t interval;
  467. void (*btm_warm_fn) (bool);
  468. void (*btm_cool_fn) (bool);
  469. };
  470. int32_t pm8xxx_adc_batt_scaler(struct pm8xxx_adc_arb_btm_param *,
  471. const struct pm8xxx_adc_properties *adc_prop,
  472. const struct pm8xxx_adc_chan_properties *chan_prop);
  473. /**
  474. * struct pm8xxx_adc_platform_data - PM8XXX ADC platform data
  475. * @adc_prop: ADC specific parameters, voltage and channel setup
  476. * @adc_channel: Channel properties of the ADC arbiter
  477. * @adc_num_board_channel: Number of channels added in the board file
  478. * @adc_mpp_base: PM8XXX MPP0 base passed from board file. This is used
  479. * to offset the PM8XXX MPP passed to configure the
  480. * the MPP to AMUX mapping.
  481. */
  482. struct pm8xxx_adc_platform_data {
  483. struct pm8xxx_adc_properties *adc_prop;
  484. struct pm8xxx_adc_amux *adc_channel;
  485. uint32_t adc_num_board_channel;
  486. uint32_t adc_mpp_base;
  487. };
  488. /* Public API */
  489. #if defined(CONFIG_SENSORS_PM8XXX_ADC) \
  490. || defined(CONFIG_SENSORS_PM8XXX_ADC_MODULE)
  491. /**
  492. * pm8xxx_adc_read() - Performs ADC read on the channel.
  493. * @channel: Input channel to perform the ADC read.
  494. * @result: Structure pointer of type adc_chan_result
  495. * in which the ADC read results are stored.
  496. */
  497. uint32_t pm8xxx_adc_read(enum pm8xxx_adc_channels channel,
  498. struct pm8xxx_adc_chan_result *result);
  499. /**
  500. * pm8xxx_adc_mpp_config_read() - Configure's the PM8XXX MPP
  501. * to AMUX6 and performs an ADC read.
  502. *
  503. * On PM8921 ADC the MPP needs to first be configured
  504. * as an analog input to the AMUX pre-mux channel before
  505. * issuing a read request. PM8921 MPP 8 is mapped to AMUX8
  506. * and is common between remote processor's.
  507. *
  508. * On PM8018 ADC the MPP is directly connected to the AMUX
  509. * pre-mux. Therefore clients of the PM8018 MPP do not need
  510. * to configure the MPP as an analog input to the pre-mux.
  511. * Clients can directly issue request on the pre-mux AMUX
  512. * channel to read the ADC on the MPP. Clients can directly
  513. * call the pm8xxx_adc_read().
  514. * @mpp_num PM8XXX MPP number to configure to AMUX6.
  515. * @channel: Input channel to perform the ADC read.
  516. * a) 'ADC_MPP_1_AMUX6' if the input voltage is less than 1.8V
  517. * b) 'ADC_MPP_2_AMUX6' if the input voltage is greater then 1.8V
  518. * the input voltage is pre-divided by 3 and passed to the ADC.
  519. * The appropriate scaling function needs to be selected to let
  520. * the driver know a post scaling is required before returning
  521. * the result.
  522. * @result: Structure pointer of type adc_chan_result
  523. * in which the ADC read results are stored.
  524. */
  525. uint32_t pm8xxx_adc_mpp_config_read(uint32_t mpp_num,
  526. enum pm8xxx_adc_channels channel,
  527. struct pm8xxx_adc_chan_result *result);
  528. /**
  529. * pm8xxx_adc_btm_start() - Configure the BTM registers and start
  530. monitoring the BATT_THERM channel for
  531. threshold warm/cold temperature set
  532. by the Battery client. The btm_start
  533. api is to be used after calling the
  534. pm8xxx_btm_configure() api which sets
  535. the temperature thresholds, interval
  536. and functions to call when warm/cold
  537. events are triggered.
  538. * @param: none.
  539. */
  540. uint32_t pm8xxx_adc_btm_start(void);
  541. /**
  542. * pm8xxx_adc_btm_end() - Configures the BTM registers to stop
  543. * monitoring the BATT_THERM channel for
  544. * warm/cold events and disables the
  545. * interval timer.
  546. * @param: none.
  547. */
  548. uint32_t pm8xxx_adc_btm_end(void);
  549. /**
  550. * pm8xxx_adc_btm_configure() - Configures the BATT_THERM channel
  551. * parameters for warm/cold thresholds.
  552. * Sets the interval timer for perfoming
  553. * reading the temperature done by the HW.
  554. * @btm_param: Structure pointer of type adc_arb_btm_param *
  555. * which client provides for threshold warm/cold,
  556. * interval and functions to call when warm/cold
  557. * events are triggered.
  558. */
  559. uint32_t pm8xxx_adc_btm_configure(struct pm8xxx_adc_arb_btm_param *);
  560. #else
  561. static inline uint32_t pm8xxx_adc_read(uint32_t channel,
  562. struct pm8xxx_adc_chan_result *result)
  563. { return -ENXIO; }
  564. static inline uint32_t pm8xxx_adc_mpp_config_read(uint32_t mpp_num,
  565. enum pm8xxx_adc_channels channel,
  566. struct pm8xxx_adc_chan_result *result)
  567. { return -ENXIO; }
  568. static inline uint32_t pm8xxx_adc_btm_start(void)
  569. { return -ENXIO; }
  570. static inline uint32_t pm8xxx_adc_btm_end(void)
  571. { return -ENXIO; }
  572. static inline uint32_t pm8xxx_adc_btm_configure(
  573. struct pm8xxx_adc_arb_btm_param *param)
  574. { return -ENXIO; }
  575. #endif
  576. #endif /* PM8XXX_ADC_H */