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