blob: d2b1cfcaff5bfc62c1a44a9fc5190629e00957cb [file] [log] [blame]
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -07001/*
Siddartha Mohanadosscb6d3002012-03-15 10:44:11 -07002 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -07003 *
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,
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -070078 ADC_MPP_2_ATEST_8 = 40,
79 ADC_MPP_2_USB_SNS_DIV20,
80 ADC_MPP_2_DCIN_SNS_DIV20,
81 ADC_MPP_2_AMUX3,
82 ADC_MPP_2_AMUX4,
83 ADC_MPP_2_AMUX5,
84 ADC_MPP_2_AMUX6,
85 ADC_MPP_2_AMUX7,
86 ADC_MPP_2_AMUX8,
87 ADC_MPP_2_ATEST_1,
88 ADC_MPP_2_ATEST_2,
89 ADC_MPP_2_ATEST_3,
90 ADC_MPP_2_ATEST_4,
91 ADC_MPP_2_ATEST_5,
92 ADC_MPP_2_ATEST_6,
93 ADC_MPP_2_ATEST_7,
Siddartha Mohanadosscb6d3002012-03-15 10:44:11 -070094 ADC_CHANNEL_MAX_NUM,
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -070095};
96
97#define PM8XXX_ADC_PMIC_0 0x0
98
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -080099#define PM8XXX_CHANNEL_ADC_625_UV 625000
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700100#define PM8XXX_CHANNEL_MPP_SCALE1_IDX 20
101#define PM8XXX_CHANNEL_MPP_SCALE3_IDX 40
102
103#define PM8XXX_AMUX_MPP_3 0x3
104#define PM8XXX_AMUX_MPP_4 0x4
105#define PM8XXX_AMUX_MPP_5 0x5
106#define PM8XXX_AMUX_MPP_6 0x6
107#define PM8XXX_AMUX_MPP_7 0x7
108#define PM8XXX_AMUX_MPP_8 0x8
109
110#define PM8XXX_ADC_DEV_NAME "pm8xxx-adc"
111
112/**
113 * enum pm8xxx_adc_decimation_type - Sampling rate supported
114 * %ADC_DECIMATION_TYPE1: 512
115 * %ADC_DECIMATION_TYPE2: 1K
116 * %ADC_DECIMATION_TYPE3: 2K
117 * %ADC_DECIMATION_TYPE4: 4k
118 * %ADC_DECIMATION_NONE: Do not use this Sampling type
119 *
120 * The Sampling rate is specific to each channel of the PM8XXX ADC arbiter.
121 */
122enum pm8xxx_adc_decimation_type {
123 ADC_DECIMATION_TYPE1 = 0,
124 ADC_DECIMATION_TYPE2,
125 ADC_DECIMATION_TYPE3,
126 ADC_DECIMATION_TYPE4,
127 ADC_DECIMATION_NONE,
128};
129
130/**
131 * enum pm8xxx_adc_calib_type - PM8XXX ADC Calibration type
132 * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels
133 * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND
134 * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type
135 *
136 * Use the input reference voltage depending on the calibration type
137 * to calcluate the offset and gain parameters. The calibration is
138 * specific to each channel of the PM8XXX ADC.
139 */
140enum pm8xxx_adc_calib_type {
141 ADC_CALIB_ABSOLUTE = 0,
142 ADC_CALIB_RATIOMETRIC,
143 ADC_CALIB_NONE,
144};
145
146/**
147 * enum pm8xxx_adc_channel_scaling_param - pre-scaling AMUX ratio
148 * %CHAN_PATH_SCALING1: ratio of {1, 1}
149 * %CHAN_PATH_SCALING2: ratio of {1, 3}
150 * %CHAN_PATH_SCALING3: ratio of {1, 4}
151 * %CHAN_PATH_SCALING4: ratio of {1, 6}
152 * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type
153 *
154 * The pre-scaling is applied for signals to be within the voltage range
155 * of the ADC.
156 */
157enum pm8xxx_adc_channel_scaling_param {
158 CHAN_PATH_SCALING1 = 0,
159 CHAN_PATH_SCALING2,
160 CHAN_PATH_SCALING3,
161 CHAN_PATH_SCALING4,
162 CHAN_PATH_SCALING_NONE,
163};
164
165/**
166 * enum pm8xxx_adc_amux_input_rsv - HK/XOADC reference voltage
167 * %AMUX_RSV0: XO_IN/XOADC_GND
168 * %AMUX_RSV1: PMIC_IN/XOADC_GND
169 * %AMUX_RSV2: PMIC_IN/BMS_CSP
170 * %AMUX_RSV3: not used
171 * %AMUX_RSV4: XOADC_GND/XOADC_GND
172 * %AMUX_RSV5: XOADC_VREF/XOADC_GND
173 * %AMUX_NONE: Do not use this input reference voltage selection
174 */
175enum pm8xxx_adc_amux_input_rsv {
176 AMUX_RSV0 = 0,
177 AMUX_RSV1,
178 AMUX_RSV2,
179 AMUX_RSV3,
180 AMUX_RSV4,
181 AMUX_RSV5,
182 AMUX_NONE,
183};
184
185/**
186 * enum pm8xxx_adc_premux_mpp_scale_type - 16:1 pre-mux scale ratio
187 * %PREMUX_MPP_SCALE_0: No scaling to the input signal
188 * %PREMUX_MPP_SCALE_1: Unity scaling selected by the user for MPP input
189 * %PREMUX_MPP_SCALE_1_DIV3: 1/3 pre-scale to the input MPP signal
190 * %PREMUX_MPP_NONE: Do not use this pre-scale mpp type
191 */
192enum pm8xxx_adc_premux_mpp_scale_type {
193 PREMUX_MPP_SCALE_0 = 0,
194 PREMUX_MPP_SCALE_1,
195 PREMUX_MPP_SCALE_1_DIV3,
196 PREMUX_MPP_NONE,
197};
198
199/**
200 * enum pm8xxx_adc_scale_fn_type - Scaling function for pm8921 pre calibrated
201 * digital data relative to ADC reference
202 * %ADC_SCALE_DEFAULT: Default scaling to convert raw adc code to voltage
203 * %ADC_SCALE_BATT_THERM: Conversion to temperature based on btm parameters
204 * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade
205 * %ADC_SCALE_XTERN_CHGR_CUR: Returns current across 0.1 ohm resistor
206 * %ADC_SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade
207 * %ADC_SCALE_NONE: Do not use this scaling type
208 */
209enum pm8xxx_adc_scale_fn_type {
210 ADC_SCALE_DEFAULT = 0,
211 ADC_SCALE_BATT_THERM,
212 ADC_SCALE_PA_THERM,
213 ADC_SCALE_PMIC_THERM,
214 ADC_SCALE_XOTHERM,
215 ADC_SCALE_NONE,
216};
217
218/**
219 * struct pm8xxx_adc_linear_graph - Represent ADC characteristics
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700220 * @dy: Numerator slope to calculate the gain
221 * @dx: Denominator slope to calculate the gain
Siddartha Mohanadossae39c902011-11-09 17:54:31 -0800222 * @adc_vref: A/D word of the voltage reference used for the channel
223 * @adc_gnd: A/D word of the ground reference used for the channel
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700224 *
225 * Each ADC device has different offset and gain parameters which are computed
226 * to calibrate the device.
227 */
228struct pm8xxx_adc_linear_graph {
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -0800229 int64_t dy;
230 int64_t dx;
231 int64_t adc_vref;
232 int64_t adc_gnd;
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700233};
234
235/**
236 * struct pm8xxx_adc_map_pt - Map the graph representation for ADC channel
237 * @x: Represent the ADC digitized code
238 * @y: Represent the physical data which can be temperature, voltage,
239 * resistance
240 */
241struct pm8xxx_adc_map_pt {
242 int32_t x;
243 int32_t y;
244};
245
246/**
247 * struct pm8xxx_adc_scaling_ratio - Represent scaling ratio for adc input
248 * @num: Numerator scaling parameter
249 * @den: Denominator scaling parameter
250 */
251struct pm8xxx_adc_scaling_ratio {
252 int32_t num;
253 int32_t den;
254};
255
256/**
257 * struct pm8xxx_adc_properties - Represent the ADC properties
258 * @adc_reference: Reference voltage for PM8XXX ADC
259 * @bitresolution: ADC bit resolution for PM8XXX ADC
260 * @biploar: Polarity for PM8XXX ADC
261 */
262struct pm8xxx_adc_properties {
263 uint32_t adc_vdd_reference;
264 uint32_t bitresolution;
265 bool bipolar;
266};
267
268/**
269 * struct pm8xxx_adc_chan_properties - Represent channel properties of the ADC
270 * @offset_gain_numerator: The inverse numerator of the gain applied to the
271 * input channel
272 * @offset_gain_denominator: The inverse denominator of the gain applied to the
273 * input channel
274 * @adc_graph: ADC graph for the channel of struct type pm8xxx_adc_linear_graph
275 */
276struct pm8xxx_adc_chan_properties {
277 uint32_t offset_gain_numerator;
278 uint32_t offset_gain_denominator;
279 struct pm8xxx_adc_linear_graph adc_graph[2];
280};
281
282/**
283 * struct pm8xxx_adc_chan_result - Represent the result of the PM8XXX ADC
284 * @chan: The channel number of the requested conversion
285 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
286 * the ADC reference
287 * @measurement: In units specific for a given ADC; most ADC uses reference
288 * voltage but some ADC uses reference current. This measurement
289 * here is a number relative to a reference of a given ADC
290 * @physical: The data meaningful for each individual channel whether it is
291 * voltage, current, temperature, etc.
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -0800292 * All voltage units are represented in micro - volts.
293 * -Battery temperature units are represented as 0.1 DegC
294 * -PA Therm temperature units are represented as DegC
295 * -PMIC Die temperature units are represented as 0.001 DegC
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700296 */
297struct pm8xxx_adc_chan_result {
298 uint32_t chan;
299 int32_t adc_code;
300 int64_t measurement;
301 int64_t physical;
302};
303
304#if defined(CONFIG_SENSORS_PM8XXX_ADC) \
305 || defined(CONFIG_SENSORS_PM8XXX_ADC_MODULE)
306/**
307 * pm8xxx_adc_scale_default() - Scales the pre-calibrated digital output
308 * of an ADC to the ADC reference and compensates for the
309 * gain and offset.
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 */
317int32_t pm8xxx_adc_scale_default(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_tdkntcg_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 of the xo therm in mili
325 degC.
326 * @adc_code: pre-calibrated digital ouput of the ADC.
327 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
328 * reference voltage.
329 * @chan_prop: individual channel properties to compensate the i/p scaling,
330 * slope and offset.
331 * @chan_rslt: physical result to be stored.
332 */
333int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
334 const struct pm8xxx_adc_properties *adc_prop,
335 const struct pm8xxx_adc_chan_properties *chan_prop,
336 struct pm8xxx_adc_chan_result *chan_rslt);
337/**
338 * pm8xxx_adc_scale_batt_therm() - Scales the pre-calibrated digital output
339 * of an ADC to the ADC reference and compensates for the
340 * gain and offset. Returns the temperature in degC.
341 * @adc_code: pre-calibrated digital ouput of the ADC.
342 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
343 * reference voltage.
344 * @chan_prop: individual channel properties to compensate the i/p scaling,
345 * slope and offset.
346 * @chan_rslt: physical result to be stored.
347 */
348int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
349 const struct pm8xxx_adc_properties *adc_prop,
350 const struct pm8xxx_adc_chan_properties *chan_prop,
351 struct pm8xxx_adc_chan_result *chan_rslt);
352/**
353 * pm8xxx_adc_scale_pa_therm() - Scales the pre-calibrated digital output
354 * of an ADC to the ADC reference and compensates for the
355 * gain and offset. Returns the temperature in 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 */
363int32_t pm8xxx_adc_scale_pa_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_pmic_therm() - Scales the pre-calibrated digital output
369 * of an ADC to the ADC reference and compensates for the
370 * gain and offset. Performs the AMUX out as 2mv/K and returns
371 * the temperature in mili degC.
372 * @adc_code: pre-calibrated digital ouput of the ADC.
373 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
374 * reference voltage.
375 * @chan_prop: individual channel properties to compensate the i/p scaling,
376 * slope and offset.
377 * @chan_rslt: physical result to be stored.
378 */
379int32_t pm8xxx_adc_scale_pmic_therm(int32_t adc_code,
380 const struct pm8xxx_adc_properties *adc_prop,
381 const struct pm8xxx_adc_chan_properties *chan_prop,
382 struct pm8xxx_adc_chan_result *chan_rslt);
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -0800383/**
384 * pm8xxx_adc_scale_batt_id() - Scales the pre-calibrated digital output
385 * of an ADC to the ADC reference and compensates for the
386 * gain and offset.
387 * @adc_code: pre-calibrated digital ouput of the ADC.
388 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
389 * reference voltage.
390 * @chan_prop: individual channel properties to compensate the i/p scaling,
391 * slope and offset.
392 * @chan_rslt: physical result to be stored.
393 */
394int32_t pm8xxx_adc_scale_batt_id(int32_t adc_code,
395 const struct pm8xxx_adc_properties *adc_prop,
396 const struct pm8xxx_adc_chan_properties *chan_prop,
397 struct pm8xxx_adc_chan_result *chan_rslt);
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700398#else
399static inline int32_t pm8xxx_adc_scale_default(int32_t adc_code,
400 const struct pm8xxx_adc_properties *adc_prop,
401 const struct pm8xxx_adc_chan_properties *chan_prop,
402 struct pm8xxx_adc_chan_result *chan_rslt)
403{ return -ENXIO; }
404static inline int32_t pm8xxx_adc_tdkntcg_therm(int32_t adc_code,
405 const struct pm8xxx_adc_properties *adc_prop,
406 const struct pm8xxx_adc_chan_properties *chan_prop,
407 struct pm8xxx_adc_chan_result *chan_rslt)
408{ return -ENXIO; }
409static inline int32_t pm8xxx_adc_scale_batt_therm(int32_t adc_code,
410 const struct pm8xxx_adc_properties *adc_prop,
411 const struct pm8xxx_adc_chan_properties *chan_prop,
412 struct pm8xxx_adc_chan_result *chan_rslt)
413{ return -ENXIO; }
414static inline int32_t pm8xxx_adc_scale_pa_therm(int32_t adc_code,
415 const struct pm8xxx_adc_properties *adc_prop,
416 const struct pm8xxx_adc_chan_properties *chan_prop,
417 struct pm8xxx_adc_chan_result *chan_rslt)
418{ return -ENXIO; }
419static inline int32_t pm8xxx_adc_scale_pmic_therm(int32_t adc_code,
420 const struct pm8xxx_adc_properties *adc_prop,
421 const struct pm8xxx_adc_chan_properties *chan_prop,
422 struct pm8xxx_adc_chan_result *chan_rslt)
423{ return -ENXIO; }
Siddartha Mohanadoss37e6fc02011-11-16 16:57:03 -0800424static inline int32_t pm8xxx_adc_scale_batt_id(int32_t adc_code,
425 const struct pm8xxx_adc_properties *adc_prop,
426 const struct pm8xxx_adc_chan_properties *chan_prop,
427 struct pm8xxx_adc_chan_result *chan_rslt)
428{ return -ENXIO; }
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700429#endif
430
431/**
432 * struct pm8xxx_adc_scale_fn - Scaling function prototype
433 * @chan: Function pointer to one of the scaling functions
434 * which takes the adc properties, channel properties,
435 * and returns the physical result
436 */
437struct pm8xxx_adc_scale_fn {
438 int32_t (*chan) (int32_t,
439 const struct pm8xxx_adc_properties *,
440 const struct pm8xxx_adc_chan_properties *,
441 struct pm8xxx_adc_chan_result *);
442};
443
444/**
445 * struct pm8xxx_adc_amux - AMUX properties for individual channel
446 * @name: Channel name
447 * @channel_name: Channel in integer used from pm8xxx_adc_channels
448 * @chan_path_prescaling: Channel scaling performed on the input signal
449 * @adc_rsv: Input reference Voltage/GND selection to the ADC
450 * @adc_decimation: Sampling rate desired for the channel
451 * adc_scale_fn: Scaling function to convert to the data meaningful for
452 * each individual channel whether it is voltage, current,
453 * temperature, etc and compensates the channel properties
454 */
455struct pm8xxx_adc_amux {
456 char *name;
457 enum pm8xxx_adc_channels channel_name;
458 enum pm8xxx_adc_channel_scaling_param chan_path_prescaling;
459 enum pm8xxx_adc_amux_input_rsv adc_rsv;
460 enum pm8xxx_adc_decimation_type adc_decimation;
461 enum pm8xxx_adc_scale_fn_type adc_scale_fn;
462};
463
464/**
465 * struct pm8xxx_adc_arb_btm_param - PM8XXX ADC BTM parameters to set threshold
466 * temperature for client notification
467 * @low_thr_temp: low temperature threshold request for notification
468 * @high_thr_temp: high temperature threshold request for notification
469 * @low_thr_voltage: low temperature converted to voltage by arbiter driver
470 * @high_thr_voltage: high temperature converted to voltage by arbiter driver
471 * @interval: Interval period to check for temperature notification
472 * @btm_warm_fn: Remote function call for warm threshold.
473 * @btm_cool_fn: Remote function call for cold threshold.
474 *
475 * BTM client passes the parameters to be set for the
476 * temperature threshold notifications. The client is
477 * responsible for setting the new threshold
478 * levels once the thresholds are reached
479 */
480struct pm8xxx_adc_arb_btm_param {
Siddartha Mohanadossae39c902011-11-09 17:54:31 -0800481 int32_t low_thr_temp;
482 int32_t high_thr_temp;
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700483 uint64_t low_thr_voltage;
484 uint64_t high_thr_voltage;
485 int32_t interval;
486 void (*btm_warm_fn) (bool);
487 void (*btm_cool_fn) (bool);
488};
489
Siddartha Mohanadossae39c902011-11-09 17:54:31 -0800490int32_t pm8xxx_adc_batt_scaler(struct pm8xxx_adc_arb_btm_param *,
491 const struct pm8xxx_adc_properties *adc_prop,
492 const struct pm8xxx_adc_chan_properties *chan_prop);
Siddartha Mohanadoss17607d22011-10-05 10:36:20 -0700493/**
494 * struct pm8xxx_adc_platform_data - PM8XXX ADC platform data
495 * @adc_prop: ADC specific parameters, voltage and channel setup
496 * @adc_channel: Channel properties of the ADC arbiter
497 * @adc_num_board_channel: Number of channels added in the board file
498 * @adc_mpp_base: PM8XXX MPP0 base passed from board file. This is used
499 * to offset the PM8XXX MPP passed to configure the
500 * the MPP to AMUX mapping.
501 */
502struct pm8xxx_adc_platform_data {
503 struct pm8xxx_adc_properties *adc_prop;
504 struct pm8xxx_adc_amux *adc_channel;
505 uint32_t adc_num_board_channel;
506 uint32_t adc_mpp_base;
507};
508
509/* Public API */
510#if defined(CONFIG_SENSORS_PM8XXX_ADC) \
511 || defined(CONFIG_SENSORS_PM8XXX_ADC_MODULE)
512/**
513 * pm8xxx_adc_read() - Performs ADC read on the channel.
514 * @channel: Input channel to perform the ADC read.
515 * @result: Structure pointer of type adc_chan_result
516 * in which the ADC read results are stored.
517 */
518uint32_t pm8xxx_adc_read(enum pm8xxx_adc_channels channel,
519 struct pm8xxx_adc_chan_result *result);
520/**
521 * pm8xxx_adc_mpp_config_read() - Configure's the PM8XXX MPP
522 * to AMUX6 and performs an ADC read.
523 *
524 * On PM8921 ADC the MPP needs to first be configured
525 * as an analog input to the AMUX pre-mux channel before
526 * issuing a read request. PM8921 MPP 8 is mapped to AMUX8
527 * and is common between remote processor's.
528 *
529 * On PM8018 ADC the MPP is directly connected to the AMUX
530 * pre-mux. Therefore clients of the PM8018 MPP do not need
531 * to configure the MPP as an analog input to the pre-mux.
532 * Clients can directly issue request on the pre-mux AMUX
533 * channel to read the ADC on the MPP. Clients can directly
534 * call the pm8xxx_adc_read().
535 * @mpp_num PM8XXX MPP number to configure to AMUX6.
536 * @channel: Input channel to perform the ADC read.
537 * a) 'ADC_MPP_1_AMUX6' if the input voltage is less than 1.8V
538 * b) 'ADC_MPP_2_AMUX6' if the input voltage is greater then 1.8V
539 * the input voltage is pre-divided by 3 and passed to the ADC.
540 * The appropriate scaling function needs to be selected to let
541 * the driver know a post scaling is required before returning
542 * the result.
543 * @result: Structure pointer of type adc_chan_result
544 * in which the ADC read results are stored.
545 */
546uint32_t pm8xxx_adc_mpp_config_read(uint32_t mpp_num,
547 enum pm8xxx_adc_channels channel,
548 struct pm8xxx_adc_chan_result *result);
549/**
550 * pm8xxx_adc_btm_start() - Configure the BTM registers and start
551 monitoring the BATT_THERM channel for
552 threshold warm/cold temperature set
553 by the Battery client. The btm_start
554 api is to be used after calling the
555 pm8xxx_btm_configure() api which sets
556 the temperature thresholds, interval
557 and functions to call when warm/cold
558 events are triggered.
559 * @param: none.
560 */
561uint32_t pm8xxx_adc_btm_start(void);
562
563/**
564 * pm8xxx_adc_btm_end() - Configures the BTM registers to stop
565 * monitoring the BATT_THERM channel for
566 * warm/cold events and disables the
567 * interval timer.
568 * @param: none.
569 */
570uint32_t pm8xxx_adc_btm_end(void);
571
572/**
573 * pm8xxx_adc_btm_configure() - Configures the BATT_THERM channel
574 * parameters for warm/cold thresholds.
575 * Sets the interval timer for perfoming
576 * reading the temperature done by the HW.
577 * @btm_param: Structure pointer of type adc_arb_btm_param *
578 * which client provides for threshold warm/cold,
579 * interval and functions to call when warm/cold
580 * events are triggered.
581 */
582uint32_t pm8xxx_adc_btm_configure(struct pm8xxx_adc_arb_btm_param *);
583#else
584static inline uint32_t pm8xxx_adc_read(uint32_t channel,
585 struct pm8xxx_adc_chan_result *result)
586{ return -ENXIO; }
587static inline uint32_t pm8xxx_adc_mpp_config_read(uint32_t mpp_num,
588 enum pm8xxx_adc_channels channel,
589 struct pm8xxx_adc_chan_result *result)
590{ return -ENXIO; }
591static inline uint32_t pm8xxx_adc_btm_start(void)
592{ return -ENXIO; }
593static inline uint32_t pm8xxx_adc_btm_end(void)
594{ return -ENXIO; }
595static inline uint32_t pm8xxx_adc_btm_configure(
596 struct pm8xxx_adc_arb_btm_param *param)
597{ return -ENXIO; }
598#endif
599
600#endif /* PM8XXX_ADC_H */