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