blob: fc34b22038bb77c070cab75483d8a61e18c9722a [file] [log] [blame]
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001/*
2 * Copyright (c) 2012, 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 QPNP ADC driver header file
15 *
16 */
17
18#ifndef __QPNP_ADC_H
19#define __QPNP_ADC_H
20
21#include <linux/kernel.h>
22#include <linux/list.h>
23/**
24 * enum qpnp_vadc_channels - QPNP AMUX arbiter channels
25 */
26enum qpnp_vadc_channels {
27 USBIN = 0,
28 DCIN,
29 VCHG_SNS,
30 SPARE1_03,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080031 USB_ID_MV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070032 VCOIN,
33 VBAT_SNS,
34 VSYS,
35 DIE_TEMP,
36 REF_625MV,
37 REF_125V,
38 CHG_TEMP,
39 SPARE1,
40 SPARE2,
41 GND_REF,
42 VDD_VADC,
43 P_MUX1_1_1,
44 P_MUX2_1_1,
45 P_MUX3_1_1,
46 P_MUX4_1_1,
47 P_MUX5_1_1,
48 P_MUX6_1_1,
49 P_MUX7_1_1,
50 P_MUX8_1_1,
51 P_MUX9_1_1,
52 P_MUX10_1_1,
53 P_MUX11_1_1,
54 P_MUX12_1_1,
55 P_MUX13_1_1,
56 P_MUX14_1_1,
57 P_MUX15_1_1,
58 P_MUX16_1_1,
59 P_MUX1_1_3,
60 P_MUX2_1_3,
61 P_MUX3_1_3,
62 P_MUX4_1_3,
63 P_MUX5_1_3,
64 P_MUX6_1_3,
65 P_MUX7_1_3,
66 P_MUX8_1_3,
67 P_MUX9_1_3,
68 P_MUX10_1_3,
69 P_MUX11_1_3,
70 P_MUX12_1_3,
71 P_MUX13_1_3,
72 P_MUX14_1_3,
73 P_MUX15_1_3,
74 P_MUX16_1_3,
75 LR_MUX1_BATT_THERM,
76 LR_MUX2_BAT_ID,
77 LR_MUX3_XO_THERM,
78 LR_MUX4_AMUX_THM1,
79 LR_MUX5_AMUX_THM2,
80 LR_MUX6_AMUX_THM3,
81 LR_MUX7_HW_ID,
82 LR_MUX8_AMUX_THM4,
83 LR_MUX9_AMUX_THM5,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080084 LR_MUX10_USB_ID_LV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070085 AMUX_PU1,
86 AMUX_PU2,
87 LR_MUX3_BUF_XO_THERM_BUF,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080088 LR_MUX1_PU1_BAT_THERM = 112,
89 LR_MUX2_PU1_BAT_ID = 113,
90 LR_MUX3_PU1_XO_THERM = 114,
91 LR_MUX4_PU1_AMUX_THM1 = 115,
92 LR_MUX5_PU1_AMUX_THM2 = 116,
93 LR_MUX6_PU1_AMUX_THM3 = 117,
94 LR_MUX7_PU1_AMUX_HW_ID = 118,
95 LR_MUX8_PU1_AMUX_THM4 = 119,
96 LR_MUX9_PU1_AMUX_THM5 = 120,
97 LR_MUX10_PU1_AMUX_USB_ID_LV = 121,
98 LR_MUX3_BUF_PU1_XO_THERM_BUF = 124,
99 LR_MUX1_PU2_BAT_THERM = 176,
100 LR_MUX2_PU2_BAT_ID = 177,
101 LR_MUX3_PU2_XO_THERM = 178,
102 LR_MUX4_PU2_AMUX_THM1 = 179,
103 LR_MUX5_PU2_AMUX_THM2 = 180,
104 LR_MUX6_PU2_AMUX_THM3 = 181,
105 LR_MUX7_PU2_AMUX_HW_ID = 182,
106 LR_MUX8_PU2_AMUX_THM4 = 183,
107 LR_MUX9_PU2_AMUX_THM5 = 184,
108 LR_MUX10_PU2_AMUX_USB_ID_LV = 185,
109 LR_MUX3_BUF_PU2_XO_THERM_BUF = 188,
110 LR_MUX1_PU1_PU2_BAT_THERM = 240,
111 LR_MUX2_PU1_PU2_BAT_ID = 241,
112 LR_MUX3_PU1_PU2_XO_THERM = 242,
113 LR_MUX4_PU1_PU2_AMUX_THM1 = 243,
114 LR_MUX5_PU1_PU2_AMUX_THM2 = 244,
115 LR_MUX6_PU1_PU2_AMUX_THM3 = 245,
116 LR_MUX7_PU1_PU2_AMUX_HW_ID = 246,
117 LR_MUX8_PU1_PU2_AMUX_THM4 = 247,
118 LR_MUX9_PU1_PU2_AMUX_THM5 = 248,
119 LR_MUX10_PU1_PU2_AMUX_USB_ID_LV = 249,
120 LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF = 252,
121 ALL_OFF = 255,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700122 ADC_MAX_NUM,
123};
124
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700125/**
126 * enum qpnp_iadc_channels - QPNP IADC channel list
127 */
128enum qpnp_iadc_channels {
129 INTERNAL_RSENSE = 0,
130 EXTERNAL_RSENSE,
131 ALT_LEAD_PAIR,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700132 GAIN_CALIBRATION_17P857MV,
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700133 OFFSET_CALIBRATION_SHORT_CADC_LEADS,
134 OFFSET_CALIBRATION_CSP_CSN,
135 OFFSET_CALIBRATION_CSP2_CSN2,
136 IADC_MUX_NUM,
137};
138
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700139#define QPNP_ADC_625_UV 625000
Siddartha Mohanadoss1c218312012-11-08 11:30:43 -0800140#define QPNP_ADC_HWMON_NAME_LENGTH 64
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700141
142/**
143 * enum qpnp_adc_decimation_type - Sampling rate supported.
144 * %DECIMATION_TYPE1: 512
145 * %DECIMATION_TYPE2: 1K
146 * %DECIMATION_TYPE3: 2K
147 * %DECIMATION_TYPE4: 4k
148 * %DECIMATION_NONE: Do not use this Sampling type.
149 *
150 * The Sampling rate is specific to each channel of the QPNP ADC arbiter.
151 */
152enum qpnp_adc_decimation_type {
153 DECIMATION_TYPE1 = 0,
154 DECIMATION_TYPE2,
155 DECIMATION_TYPE3,
156 DECIMATION_TYPE4,
157 DECIMATION_NONE,
158};
159
160/**
161 * enum qpnp_adc_calib_type - QPNP ADC Calibration type.
162 * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels.
163 * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND.
164 * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type.
165 *
166 * Use the input reference voltage depending on the calibration type
167 * to calcluate the offset and gain parameters. The calibration is
168 * specific to each channel of the QPNP ADC.
169 */
170enum qpnp_adc_calib_type {
171 CALIB_ABSOLUTE = 0,
172 CALIB_RATIOMETRIC,
173 CALIB_NONE,
174};
175
176/**
177 * enum qpnp_adc_channel_scaling_param - pre-scaling AMUX ratio.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700178 * %CHAN_PATH_SCALING0: ratio of {1, 1}
179 * %CHAN_PATH_SCALING1: ratio of {1, 3}
180 * %CHAN_PATH_SCALING2: ratio of {1, 4}
181 * %CHAN_PATH_SCALING3: ratio of {1, 6}
182 * %CHAN_PATH_SCALING4: ratio of {1, 20}
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700183 * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type.
184 *
185 * The pre-scaling is applied for signals to be within the voltage range
186 * of the ADC.
187 */
188enum qpnp_adc_channel_scaling_param {
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700189 PATH_SCALING0 = 0,
190 PATH_SCALING1,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700191 PATH_SCALING2,
192 PATH_SCALING3,
193 PATH_SCALING4,
194 PATH_SCALING_NONE,
195};
196
197/**
198 * enum qpnp_adc_scale_fn_type - Scaling function for pm8921 pre calibrated
199 * digital data relative to ADC reference.
200 * %ADC_SCALE_DEFAULT: Default scaling to convert raw adc code to voltage.
201 * %ADC_SCALE_BATT_THERM: Conversion to temperature based on btm parameters.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700202 * %ADC_SCALE_THERM_100K_PULLUP: Returns temperature in degC.
203 * Uses a mapping table with 100K pullup.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700204 * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700205 * %ADC_SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700206 * %ADC_SCALE_THERM_150K_PULLUP: Returns temperature in degC.
207 * Uses a mapping table with 150K pullup.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700208 * %ADC_SCALE_NONE: Do not use this scaling type.
209 */
210enum qpnp_adc_scale_fn_type {
211 SCALE_DEFAULT = 0,
212 SCALE_BATT_THERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700213 SCALE_THERM_100K_PULLUP,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700214 SCALE_PMIC_THERM,
215 SCALE_XOTHERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700216 SCALE_THERM_150K_PULLUP,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700217 SCALE_NONE,
218};
219
220/**
221 * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result
222 * from the ADC that is an average of multiple measurement
223 * samples. Select number of samples for use in fast
224 * average mode (i.e. 2 ^ value).
225 * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1
226 * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2
227 * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4
228 * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8
229 * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16
230 * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32
231 * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64
232 * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128
233 * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256
234 * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512
235 */
236enum qpnp_adc_fast_avg_ctl {
237 ADC_FAST_AVG_SAMPLE_1 = 0,
238 ADC_FAST_AVG_SAMPLE_2,
239 ADC_FAST_AVG_SAMPLE_4,
240 ADC_FAST_AVG_SAMPLE_8,
241 ADC_FAST_AVG_SAMPLE_16,
242 ADC_FAST_AVG_SAMPLE_32,
243 ADC_FAST_AVG_SAMPLE_64,
244 ADC_FAST_AVG_SAMPLE_128,
245 ADC_FAST_AVG_SAMPLE_256,
246 ADC_FAST_AVG_SAMPLE_512,
247 ADC_FAST_AVG_SAMPLE_NONE,
248};
249
250/**
251 * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and
252 * the ADC starting conversion. Delay = 100us * value for
253 * value < 11 and 2ms * (value - 10) otherwise.
254 * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us
255 * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us
256 * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us
257 * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us
258 * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us
259 * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us
260 * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us
261 * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us
262 * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us
263 * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us
264 * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms
265 * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms
266 * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms
267 * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms
268 * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms
269 * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms
270 * %ADC_CHANNEL_HW_SETTLE_NONE
271 */
272enum qpnp_adc_hw_settle_time {
273 ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0,
274 ADC_CHANNEL_HW_SETTLE_DELAY_100US,
275 ADC_CHANNEL_HW_SETTLE_DELAY_2000US,
276 ADC_CHANNEL_HW_SETTLE_DELAY_300US,
277 ADC_CHANNEL_HW_SETTLE_DELAY_400US,
278 ADC_CHANNEL_HW_SETTLE_DELAY_500US,
279 ADC_CHANNEL_HW_SETTLE_DELAY_600US,
280 ADC_CHANNEL_HW_SETTLE_DELAY_700US,
281 ADC_CHANNEL_HW_SETTLE_DELAY_800US,
282 ADC_CHANNEL_HW_SETTLE_DELAY_900US,
283 ADC_CHANNEL_HW_SETTLE_DELAY_1MS,
284 ADC_CHANNEL_HW_SETTLE_DELAY_2MS,
285 ADC_CHANNEL_HW_SETTLE_DELAY_4MS,
286 ADC_CHANNEL_HW_SETTLE_DELAY_6MS,
287 ADC_CHANNEL_HW_SETTLE_DELAY_8MS,
288 ADC_CHANNEL_HW_SETTLE_DELAY_10MS,
289 ADC_CHANNEL_HW_SETTLE_NONE,
290};
291
292/**
293 * enum qpnp_vadc_mode_sel - Selects the basic mode of operation.
294 * - The normal mode is used for single measurement.
295 * - The Conversion sequencer is used to trigger an
296 * ADC read when a HW trigger is selected.
297 * - The measurement interval performs a single or
298 * continous measurement at a specified interval/delay.
299 * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement.
300 * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger
301 * an ADC read on a HW supported trigger.
302 * Refer to enum qpnp_vadc_trigger for
303 * supported HW triggers.
304 * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a
305 * single or continous measurement after a specified delay.
306 * For delay look at qpnp_adc_meas_timer.
307 */
308enum qpnp_vadc_mode_sel {
309 ADC_OP_NORMAL_MODE = 0,
310 ADC_OP_CONVERSION_SEQUENCER,
311 ADC_OP_MEASUREMENT_INTERVAL,
312 ADC_OP_MODE_NONE,
313};
314
315/**
316 * enum qpnp_vadc_trigger - Select the HW trigger to be used while
317 * measuring the ADC reading.
318 * %ADC_GSM_PA_ON : GSM power amplifier on.
319 * %ADC_TX_GTR_THRES : Transmit power greater than threshold.
320 * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done.
321 * %ADC_DTEST : DTEST.
322 */
323enum qpnp_vadc_trigger {
324 ADC_GSM_PA_ON = 0,
325 ADC_TX_GTR_THRES,
326 ADC_CAMERA_FLASH_RAMP,
327 ADC_DTEST,
328 ADC_SEQ_NONE,
329};
330
331/**
332 * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from
333 * conversion request to triggering conversion sequencer
334 * hold off time.
335 */
336enum qpnp_vadc_conv_seq_timeout {
337 ADC_CONV_SEQ_TIMEOUT_0MS = 0,
338 ADC_CONV_SEQ_TIMEOUT_1MS,
339 ADC_CONV_SEQ_TIMEOUT_2MS,
340 ADC_CONV_SEQ_TIMEOUT_3MS,
341 ADC_CONV_SEQ_TIMEOUT_4MS,
342 ADC_CONV_SEQ_TIMEOUT_5MS,
343 ADC_CONV_SEQ_TIMEOUT_6MS,
344 ADC_CONV_SEQ_TIMEOUT_7MS,
345 ADC_CONV_SEQ_TIMEOUT_8MS,
346 ADC_CONV_SEQ_TIMEOUT_9MS,
347 ADC_CONV_SEQ_TIMEOUT_10MS,
348 ADC_CONV_SEQ_TIMEOUT_11MS,
349 ADC_CONV_SEQ_TIMEOUT_12MS,
350 ADC_CONV_SEQ_TIMEOUT_13MS,
351 ADC_CONV_SEQ_TIMEOUT_14MS,
352 ADC_CONV_SEQ_TIMEOUT_15MS,
353 ADC_CONV_SEQ_TIMEOUT_NONE,
354};
355
356/**
357 * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion
358 * trigger signal (i.e. adc_conv_seq_trig) transition
359 * to ADC enable. Delay = 25us * (value + 1).
360 */
361enum qpnp_adc_conv_seq_holdoff {
362 ADC_SEQ_HOLD_25US = 0,
363 ADC_SEQ_HOLD_50US,
364 ADC_SEQ_HOLD_75US,
365 ADC_SEQ_HOLD_100US,
366 ADC_SEQ_HOLD_125US,
367 ADC_SEQ_HOLD_150US,
368 ADC_SEQ_HOLD_175US,
369 ADC_SEQ_HOLD_200US,
370 ADC_SEQ_HOLD_225US,
371 ADC_SEQ_HOLD_250US,
372 ADC_SEQ_HOLD_275US,
373 ADC_SEQ_HOLD_300US,
374 ADC_SEQ_HOLD_325US,
375 ADC_SEQ_HOLD_350US,
376 ADC_SEQ_HOLD_375US,
377 ADC_SEQ_HOLD_400US,
378 ADC_SEQ_HOLD_NONE,
379};
380
381/**
382 * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state
383 * %ADC_CONV_SEQ_IDLE : Sequencer is in idle.
384 * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger.
385 * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time.
386 * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal.
387 * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge.
388 * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time.
389 * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal.
390 * %ADC_CONV_ERROR : Aberrant Hardware problem.
391 */
392enum qpnp_adc_conv_seq_state {
393 ADC_CONV_SEQ_IDLE = 0,
394 ADC_CONV_TRIG_RISE,
395 ADC_CONV_TRIG_HOLDOFF,
396 ADC_CONV_MEAS_RISE,
397 ADC_CONV_TRIG_FALL,
398 ADC_CONV_FALL_HOLDOFF,
399 ADC_CONV_MEAS_FALL,
400 ADC_CONV_ERROR,
401 ADC_CONV_NONE,
402};
403
404/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800405 * enum qpnp_adc_meas_timer_1 - Selects the measurement interval time.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700406 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800407 * The timer period is used by the USB_ID. Do not set a polling rate
408 * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0
409 * appears to be limited to 1 second.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700410 * %ADC_MEAS_INTERVAL_0MS : 0ms
411 * %ADC_MEAS_INTERVAL_1P0MS : 1ms
412 * %ADC_MEAS_INTERVAL_2P0MS : 2ms
413 * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms
414 * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms
415 * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms
416 * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms
417 * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms
418 * %ADC_MEAS_INTERVAL_125MS : 125ms
419 * %ADC_MEAS_INTERVAL_250MS : 250ms
420 * %ADC_MEAS_INTERVAL_500MS : 500ms
421 * %ADC_MEAS_INTERVAL_1S : 1seconds
422 * %ADC_MEAS_INTERVAL_2S : 2seconds
423 * %ADC_MEAS_INTERVAL_4S : 4seconds
424 * %ADC_MEAS_INTERVAL_8S : 8seconds
425 * %ADC_MEAS_INTERVAL_16S: 16seconds
426 */
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800427enum qpnp_adc_meas_timer_1 {
428 ADC_MEAS1_INTERVAL_0MS = 0,
429 ADC_MEAS1_INTERVAL_1P0MS,
430 ADC_MEAS1_INTERVAL_2P0MS,
431 ADC_MEAS1_INTERVAL_3P9MS,
432 ADC_MEAS1_INTERVAL_7P8MS,
433 ADC_MEAS1_INTERVAL_15P6MS,
434 ADC_MEAS1_INTERVAL_31P3MS,
435 ADC_MEAS1_INTERVAL_62P5MS,
436 ADC_MEAS1_INTERVAL_125MS,
437 ADC_MEAS1_INTERVAL_250MS,
438 ADC_MEAS1_INTERVAL_500MS,
439 ADC_MEAS1_INTERVAL_1S,
440 ADC_MEAS1_INTERVAL_2S,
441 ADC_MEAS1_INTERVAL_4S,
442 ADC_MEAS1_INTERVAL_8S,
443 ADC_MEAS1_INTERVAL_16S,
444 ADC_MEAS1_INTERVAL_NONE,
445};
446
447/**
448 * enum qpnp_adc_meas_timer_2 - Selects the measurement interval time.
449 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
450 * The timer period is used by the batt_therm. Do not set a polling rate
451 * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0
452 * appears to be limited to 1 second.
453 * %ADC_MEAS_INTERVAL_0MS : 0ms
454 * %ADC_MEAS_INTERVAL_100MS : 100ms
455 * %ADC_MEAS_INTERVAL_200MS : 200ms
456 * %ADC_MEAS_INTERVAL_300MS : 300ms
457 * %ADC_MEAS_INTERVAL_400MS : 400ms
458 * %ADC_MEAS_INTERVAL_500MS : 500ms
459 * %ADC_MEAS_INTERVAL_600MS : 600ms
460 * %ADC_MEAS_INTERVAL_700MS : 700ms
461 * %ADC_MEAS_INTERVAL_800MS : 800ms
462 * %ADC_MEAS_INTERVAL_900MS : 900ms
463 * %ADC_MEAS_INTERVAL_1S: 1seconds
464 * %ADC_MEAS_INTERVAL_1P1S: 1.1seconds
465 * %ADC_MEAS_INTERVAL_1P2S: 1.2seconds
466 * %ADC_MEAS_INTERVAL_1P3S: 1.3seconds
467 * %ADC_MEAS_INTERVAL_1P4S: 1.4seconds
468 * %ADC_MEAS_INTERVAL_1P5S: 1.5seconds
469 */
470enum qpnp_adc_meas_timer_2 {
471 ADC_MEAS2_INTERVAL_0MS = 0,
472 ADC_MEAS2_INTERVAL_100MS,
473 ADC_MEAS2_INTERVAL_200MS,
474 ADC_MEAS2_INTERVAL_300MS,
475 ADC_MEAS2_INTERVAL_400MS,
476 ADC_MEAS2_INTERVAL_500MS,
477 ADC_MEAS2_INTERVAL_600MS,
478 ADC_MEAS2_INTERVAL_700MS,
479 ADC_MEAS2_INTERVAL_800MS,
480 ADC_MEAS2_INTERVAL_900MS,
481 ADC_MEAS2_INTERVAL_1S,
482 ADC_MEAS2_INTERVAL_1P1S,
483 ADC_MEAS2_INTERVAL_1P2S,
484 ADC_MEAS2_INTERVAL_1P3S,
485 ADC_MEAS2_INTERVAL_1P4S,
486 ADC_MEAS2_INTERVAL_1P5S,
487 ADC_MEAS2_INTERVAL_NONE,
488};
489
490/**
491 * enum qpnp_adc_meas_timer_3 - Selects the measurement interval time.
492 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
493 * Do not set a polling rate greater than 1 second on PMIC 2.0.
494 * The max polling rate on the PMIC 2.0 appears to be limited to 1 second.
495 * %ADC_MEAS_INTERVAL_0MS : 0ms
496 * %ADC_MEAS_INTERVAL_1S : 1seconds
497 * %ADC_MEAS_INTERVAL_2S : 2seconds
498 * %ADC_MEAS_INTERVAL_3S : 3seconds
499 * %ADC_MEAS_INTERVAL_4S : 4seconds
500 * %ADC_MEAS_INTERVAL_5S : 5seconds
501 * %ADC_MEAS_INTERVAL_6S: 6seconds
502 * %ADC_MEAS_INTERVAL_7S : 7seconds
503 * %ADC_MEAS_INTERVAL_8S : 8seconds
504 * %ADC_MEAS_INTERVAL_9S : 9seconds
505 * %ADC_MEAS_INTERVAL_10S : 10seconds
506 * %ADC_MEAS_INTERVAL_11S : 11seconds
507 * %ADC_MEAS_INTERVAL_12S : 12seconds
508 * %ADC_MEAS_INTERVAL_13S : 13seconds
509 * %ADC_MEAS_INTERVAL_14S : 14seconds
510 * %ADC_MEAS_INTERVAL_15S : 15seconds
511 */
512enum qpnp_adc_meas_timer_3 {
513 ADC_MEAS3_INTERVAL_0S = 0,
514 ADC_MEAS3_INTERVAL_1S,
515 ADC_MEAS3_INTERVAL_2S,
516 ADC_MEAS3_INTERVAL_3S,
517 ADC_MEAS3_INTERVAL_4S,
518 ADC_MEAS3_INTERVAL_5S,
519 ADC_MEAS3_INTERVAL_6S,
520 ADC_MEAS3_INTERVAL_7S,
521 ADC_MEAS3_INTERVAL_8S,
522 ADC_MEAS3_INTERVAL_9S,
523 ADC_MEAS3_INTERVAL_10S,
524 ADC_MEAS3_INTERVAL_11S,
525 ADC_MEAS3_INTERVAL_12S,
526 ADC_MEAS3_INTERVAL_13S,
527 ADC_MEAS3_INTERVAL_14S,
528 ADC_MEAS3_INTERVAL_15S,
529 ADC_MEAS3_INTERVAL_NONE,
530};
531
532/**
533 * enum qpnp_adc_meas_timer_select - Selects the timer for which
534 * the appropriate polling frequency is set.
535 * %ADC_MEAS_TIMER_SELECT1 - Select this timer if the client is USB_ID.
536 * %ADC_MEAS_TIMER_SELECT2 - Select this timer if the client is batt_therm.
537 * %ADC_MEAS_TIMER_SELECT3 - The timer is added only for completion. It is
538 * not used by kernel space clients and user space clients cannot set
539 * the polling frequency. The driver will set a appropriate polling
540 * frequency to measure the user space clients from qpnp_adc_meas_timer_3.
541 */
542enum qpnp_adc_meas_timer_select {
543 ADC_MEAS_TIMER_SELECT1 = 0,
544 ADC_MEAS_TIMER_SELECT2,
545 ADC_MEAS_TIMER_SELECT3,
546 ADC_MEAS_TIMER_NUM,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700547};
548
549/**
550 * enum qpnp_adc_meas_interval_op_ctl - Select operating mode.
551 * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time
552 * delay.
553 * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval
554 * times.
555 */
556enum qpnp_adc_meas_interval_op_ctl {
557 ADC_MEAS_INTERVAL_OP_SINGLE = 0,
558 ADC_MEAS_INTERVAL_OP_CONTINUOUS,
559 ADC_MEAS_INTERVAL_OP_NONE,
560};
561
562/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800563 * Channel selection registers for each of the 5 configurable measurements
564 * Channels allotment is fixed for the given channels below.
565 * The USB_ID and BATT_THERM channels are used only by the kernel space
566 * USB and Battery drivers.
567 * The other 3 channels are configurable for use by userspace clients.
568 * USB_ID uses QPNP_ADC_TM_M0_ADC_CH_SEL_CTL
569 * BATT_TEMP uses QPNP_ADC_TM_M1_ADC_CH_SEL_CTL
570 * PA_THERM1 uses QPNP_ADC_TM_M2_ADC_CH_SEL_CTL
571 * PA_THERM2 uses QPNP_ADC_TM_M3_ADC_CH_SEL_CTL
572 * EMMC_THERM uses QPNP_ADC_TM_M4_ADC_CH_SEL_CTL
573 */
574enum qpnp_adc_tm_channel_select {
575 QPNP_ADC_TM_M0_ADC_CH_SEL_CTL = 0x48,
576 QPNP_ADC_TM_M1_ADC_CH_SEL_CTL = 0x68,
577 QPNP_ADC_TM_M2_ADC_CH_SEL_CTL = 0x70,
578 QPNP_ADC_TM_M3_ADC_CH_SEL_CTL = 0x78,
579 QPNP_ADC_TM_M4_ADC_CH_SEL_CTL = 0x80,
580 QPNP_ADC_TM_CH_SELECT_NONE
581};
582
583/**
584 * struct qpnp_adc_tm_config - Represent ADC Thermal Monitor configuration.
585 * @channel: ADC channel for which thermal monitoring is requested.
586 * @adc_code: The pre-calibrated digital output of a given ADC releative to the
587 * ADC reference.
588 * @high_thr_temp: Temperature at which high threshold notification is required.
589 * @low_thr_temp: Temperature at which low threshold notification is required.
590 * @low_thr_voltage : Low threshold voltage ADC code used for reverse
591 * calibration.
592 * @high_thr_voltage: High threshold voltage ADC code used for reverse
593 * calibration.
594 */
595struct qpnp_adc_tm_config {
596 int channel;
597 int adc_code;
598 int high_thr_temp;
599 int low_thr_temp;
600 int64_t high_thr_voltage;
601 int64_t low_thr_voltage;
602};
603
604/**
605 * enum qpnp_adc_tm_trip_type - Type for setting high/low temperature/voltage.
606 * %ADC_TM_TRIP_HIGH_WARM: Setting high temperature. Note that high temperature
607 * corresponds to low voltage. Driver handles this case
608 * appropriately to set high/low thresholds for voltage.
609 * threshold.
610 * %ADC_TM_TRIP_LOW_COOL: Setting low temperature.
611 */
612enum qpnp_adc_tm_trip_type {
613 ADC_TM_TRIP_HIGH_WARM = 0,
614 ADC_TM_TRIP_LOW_COOL,
615 ADC_TM_TRIP_NUM,
616};
617
618/**
619 * enum qpnp_tm_state - This lets the client know whether the threshold
620 * that was crossed was high/low.
621 * %ADC_TM_HIGH_STATE: Client is notified of crossing the requested high
622 * threshold.
623 * %ADC_TM_LOW_STATE: Client is notified of crossing the requested low
624 * threshold.
625 */
626enum qpnp_tm_state {
627 ADC_TM_HIGH_STATE = 0,
628 ADC_TM_LOW_STATE,
629 ADC_TM_STATE_NUM,
630};
631
632/**
633 * enum qpnp_state_request - Request to enable/disable the corresponding
634 * high/low voltage/temperature thresholds.
635 * %ADC_TM_HIGH_THR_ENABLE: Enable high voltage/temperature threshold.
636 * %ADC_TM_LOW_THR_ENABLE: Enable low voltage/temperature threshold.
637 * %ADC_TM_HIGH_LOW_THR_ENABLE: Enable high and low voltage/temperature
638 * threshold.
639 * %ADC_TM_HIGH_THR_DISABLE: Disable high voltage/temperature threshold.
640 * %ADC_TM_LOW_THR_DISABLE: Disable low voltage/temperature threshold.
641 * %ADC_TM_HIGH_THR_DISABLE: Disable high and low voltage/temperature
642 * threshold.
643 */
644enum qpnp_state_request {
645 ADC_TM_HIGH_THR_ENABLE = 0,
646 ADC_TM_LOW_THR_ENABLE,
647 ADC_TM_HIGH_LOW_THR_ENABLE,
648 ADC_TM_HIGH_THR_DISABLE,
649 ADC_TM_LOW_THR_DISABLE,
650 ADC_TM_HIGH_LOW_THR_DISABLE,
651 ADC_TM_THR_NUM,
652};
653
654/**
655 * struct qpnp_adc_tm_usbid_param - Represent USB_ID threshold
656 * monitoring configuration.
657 * @high_thr: High voltage threshold for which notification is requested.
658 * @low_thr: Low voltage threshold for which notification is requested.
659 * @state_request: Enable/disable the corresponding high and low voltage
660 * thresholds.
661 * @timer_interval: Select polling rate from qpnp_adc_meas_timer_1 type.
662 * @threshold_notification: Notification callback once threshold are crossed.
663 */
664struct qpnp_adc_tm_usbid_param {
665 int32_t high_thr;
666 int32_t low_thr;
667 enum qpnp_state_request state_request;
668 enum qpnp_adc_meas_timer_1 timer_interval;
669 void (*threshold_notification) (enum qpnp_tm_state state);
670};
671
672/**
673 * struct qpnp_adc_tm_btm_param - Represent Battery temperature threshold
674 * monitoring configuration.
675 * @high_temp: High temperature threshold for which notification is requested.
676 * @low_temp: Low temperature threshold for which notification is requested.
677 * @state_request: Enable/disable the corresponding high and low temperature
678 * thresholds.
679 * @timer_interval: Select polling rate from qpnp_adc_meas_timer_2 type.
680 * @threshold_notification: Notification callback once threshold are crossed.
681 */
682struct qpnp_adc_tm_btm_param {
683 int32_t high_temp;
684 int32_t low_temp;
685 enum qpnp_state_request state_request;
686 enum qpnp_adc_meas_timer_2 timer_interval;
687 void (*threshold_notification) (enum qpnp_tm_state state);
688};
689
690/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700691 * struct qpnp_vadc_linear_graph - Represent ADC characteristics.
692 * @dy: Numerator slope to calculate the gain.
693 * @dx: Denominator slope to calculate the gain.
694 * @adc_vref: A/D word of the voltage reference used for the channel.
695 * @adc_gnd: A/D word of the ground reference used for the channel.
696 *
697 * Each ADC device has different offset and gain parameters which are computed
698 * to calibrate the device.
699 */
700struct qpnp_vadc_linear_graph {
701 int64_t dy;
702 int64_t dx;
703 int64_t adc_vref;
704 int64_t adc_gnd;
705};
706
707/**
708 * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel
709 * @x: Represent the ADC digitized code.
710 * @y: Represent the physical data which can be temperature, voltage,
711 * resistance.
712 */
713struct qpnp_vadc_map_pt {
714 int32_t x;
715 int32_t y;
716};
717
718/**
719 * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input.
720 * @num: Numerator scaling parameter.
721 * @den: Denominator scaling parameter.
722 */
723struct qpnp_vadc_scaling_ratio {
724 int32_t num;
725 int32_t den;
726};
727
728/**
729 * struct qpnp_adc_properties - Represent the ADC properties.
730 * @adc_reference: Reference voltage for QPNP ADC.
731 * @bitresolution: ADC bit resolution for QPNP ADC.
732 * @biploar: Polarity for QPNP ADC.
733 */
734struct qpnp_adc_properties {
735 uint32_t adc_vdd_reference;
736 uint32_t bitresolution;
737 bool bipolar;
738};
739
740/**
741 * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC.
742 * @offset_gain_numerator: The inverse numerator of the gain applied to the
743 * input channel.
744 * @offset_gain_denominator: The inverse denominator of the gain applied to the
745 * input channel.
746 * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph.
747 */
748struct qpnp_vadc_chan_properties {
749 uint32_t offset_gain_numerator;
750 uint32_t offset_gain_denominator;
751 struct qpnp_vadc_linear_graph adc_graph[2];
752};
753
754/**
755 * struct qpnp_adc_result - Represent the result of the QPNP ADC.
756 * @chan: The channel number of the requested conversion.
757 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
758 * the ADC reference.
759 * @measurement: In units specific for a given ADC; most ADC uses reference
760 * voltage but some ADC uses reference current. This measurement
761 * here is a number relative to a reference of a given ADC.
762 * @physical: The data meaningful for each individual channel whether it is
763 * voltage, current, temperature, etc.
764 * All voltage units are represented in micro - volts.
765 * -Battery temperature units are represented as 0.1 DegC.
766 * -PA Therm temperature units are represented as DegC.
767 * -PMIC Die temperature units are represented as 0.001 DegC.
768 */
769struct qpnp_vadc_result {
770 uint32_t chan;
771 int32_t adc_code;
772 int64_t measurement;
773 int64_t physical;
774};
775
776/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800777 * struct qpnp_vadc_amux - AMUX properties for individual channel
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700778 * @name: Channel string name.
779 * @channel_num: Channel in integer used from qpnp_adc_channels.
780 * @chan_path_prescaling: Channel scaling performed on the input signal.
781 * @adc_decimation: Sampling rate desired for the channel.
782 * adc_scale_fn: Scaling function to convert to the data meaningful for
783 * each individual channel whether it is voltage, current,
784 * temperature, etc and compensates the channel properties.
785 */
786struct qpnp_vadc_amux {
787 char *name;
788 enum qpnp_vadc_channels channel_num;
789 enum qpnp_adc_channel_scaling_param chan_path_prescaling;
790 enum qpnp_adc_decimation_type adc_decimation;
791 enum qpnp_adc_scale_fn_type adc_scale_fn;
792 enum qpnp_adc_fast_avg_ctl fast_avg_setup;
793 enum qpnp_adc_hw_settle_time hw_settle_time;
794};
795
796/**
797 * struct qpnp_vadc_scaling_ratio
798 *
799 */
800static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = {
801 {1, 1},
802 {1, 3},
803 {1, 4},
804 {1, 6},
805 {1, 20}
806};
807
808/**
809 * struct qpnp_vadc_scale_fn - Scaling function prototype
810 * @chan: Function pointer to one of the scaling functions
811 * which takes the adc properties, channel properties,
812 * and returns the physical result
813 */
814struct qpnp_vadc_scale_fn {
815 int32_t (*chan) (int32_t,
816 const struct qpnp_adc_properties *,
817 const struct qpnp_vadc_chan_properties *,
818 struct qpnp_vadc_result *);
819};
820
821/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700822 * struct qpnp_iadc_calib - IADC channel calibration structure.
823 * @channel - Channel for which the historical offset and gain is
824 * calculated. Available channels are internal rsense,
825 * external rsense and alternate lead pairs.
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700826 * @offset_raw - raw Offset value for the channel.
827 * @gain_raw - raw Gain of the channel.
828 * @ideal_offset_uv - ideal offset value for the channel.
829 * @ideal_gain_nv - ideal gain for the channel.
830 * @offset_uv - converted value of offset in uV.
831 * @gain_uv - converted value of gain in uV.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700832 */
833struct qpnp_iadc_calib {
834 enum qpnp_iadc_channels channel;
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700835 uint16_t offset_raw;
836 uint16_t gain_raw;
837 uint32_t ideal_offset_uv;
838 uint32_t ideal_gain_nv;
839 uint32_t offset_uv;
840 uint32_t gain_uv;
841};
842
843/**
844 * struct qpnp_iadc_result - IADC read result structure.
845 * @oresult_uv - Result of ADC in uV.
846 * @result_ua - Result of ADC in uA.
847 */
848struct qpnp_iadc_result {
849 int32_t result_uv;
850 int32_t result_ua;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700851};
852
853/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700854 * struct qpnp_adc_drv - QPNP ADC device structure.
855 * @spmi - spmi device for ADC peripheral.
856 * @offset - base offset for the ADC peripheral.
857 * @adc_prop - ADC properties specific to the ADC peripheral.
858 * @amux_prop - AMUX properties representing the ADC peripheral.
859 * @adc_channels - ADC channel properties for the ADC peripheral.
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800860 * @adc_irq_eoc - End of Conversion IRQ.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700861 * @adc_lock - ADC lock for access to the peripheral.
862 * @adc_rslt_completion - ADC result notification after interrupt
863 * is received.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700864 * @calib - Internal rsens calibration values for gain and offset.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700865 */
866struct qpnp_adc_drv {
867 struct spmi_device *spmi;
868 uint8_t slave;
869 uint16_t offset;
870 struct qpnp_adc_properties *adc_prop;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700871 struct qpnp_adc_amux_properties *amux_prop;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700872 struct qpnp_vadc_amux *adc_channels;
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800873 int adc_irq_eoc;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700874 struct mutex adc_lock;
875 struct completion adc_rslt_completion;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700876 struct qpnp_iadc_calib calib;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700877};
878
879/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700880 * struct qpnp_adc_amux_properties - QPNP VADC amux channel property.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700881 * @amux_channel - Refer to the qpnp_vadc_channel list.
882 * @decimation - Sampling rate supported for the channel.
883 * @mode_sel - The basic mode of operation.
884 * @hw_settle_time - The time between AMUX being configured and the
885 * start of conversion.
886 * @fast_avg_setup - Ability to provide single result from the ADC
887 * that is an average of multiple measurements.
888 * @trigger_channel - HW trigger channel for conversion sequencer.
889 * @chan_prop - Represent the channel properties of the ADC.
890 */
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700891struct qpnp_adc_amux_properties {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700892 uint32_t amux_channel;
893 uint32_t decimation;
894 uint32_t mode_sel;
895 uint32_t hw_settle_time;
896 uint32_t fast_avg_setup;
897 enum qpnp_vadc_trigger trigger_channel;
898 struct qpnp_vadc_chan_properties chan_prop[0];
899};
900
901/* Public API */
902#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \
903 || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE)
904/**
905 * qpnp_vadc_read() - Performs ADC read on the channel.
906 * @channel: Input channel to perform the ADC read.
907 * @result: Structure pointer of type adc_chan_result
908 * in which the ADC read results are stored.
909 */
910int32_t qpnp_vadc_read(enum qpnp_vadc_channels channel,
911 struct qpnp_vadc_result *result);
912
913/**
914 * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion
915 * sequencer channel.
916 * @channel: Input channel to perform the ADC read.
917 * @result: Structure pointer of type adc_chan_result
918 * in which the ADC read results are stored.
919 */
920int32_t qpnp_vadc_conv_seq_request(
921 enum qpnp_vadc_trigger trigger_channel,
922 enum qpnp_vadc_channels channel,
923 struct qpnp_vadc_result *result);
924
925/**
926 * qpnp_vadc_check_result() - Performs check on the ADC raw code.
927 * @data: Data used for verifying the range of the ADC code.
928 */
929int32_t qpnp_vadc_check_result(int32_t *data);
930
931/**
932 * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data.
933 * @spmi: spmi ADC device.
934 * @adc_qpnp: spmi device tree node structure
935 */
936int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi,
937 struct qpnp_adc_drv *adc_qpnp);
938
939/**
940 * qpnp_vadc_configure() - Configure ADC device to start conversion.
941 * @chan_prop: Individual channel properties for the AMUX channel.
942 */
943int32_t qpnp_vadc_configure(
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700944 struct qpnp_adc_amux_properties *chan_prop);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700945
946/**
947 * qpnp_adc_scale_default() - Scales the pre-calibrated digital output
948 * of an ADC to the ADC reference and compensates for the
949 * gain and offset.
950 * @adc_code: pre-calibrated digital ouput of the ADC.
951 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
952 * reference voltage.
953 * @chan_prop: Individual channel properties to compensate the i/p scaling,
954 * slope and offset.
955 * @chan_rslt: Physical result to be stored.
956 */
957int32_t qpnp_adc_scale_default(int32_t adc_code,
958 const struct qpnp_adc_properties *adc_prop,
959 const struct qpnp_vadc_chan_properties *chan_prop,
960 struct qpnp_vadc_result *chan_rslt);
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700961/**
962 * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
963 * of an ADC to the ADC reference and compensates for the
964 * gain and offset. Performs the AMUX out as 2mV/K and returns
965 * the temperature in milli degC.
966 * @adc_code: pre-calibrated digital ouput of the ADC.
967 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
968 * reference voltage.
969 * @chan_prop: Individual channel properties to compensate the i/p scaling,
970 * slope and offset.
971 * @chan_rslt: Physical result to be stored.
972 */
973int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
974 const struct qpnp_adc_properties *adc_prop,
975 const struct qpnp_vadc_chan_properties *chan_prop,
976 struct qpnp_vadc_result *chan_rslt);
977/**
978 * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
979 * of an ADC to the ADC reference and compensates for the
980 * gain and offset. Returns the temperature in degC.
981 * @adc_code: pre-calibrated digital ouput of the ADC.
982 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
983 * reference voltage.
984 * @chan_prop: individual channel properties to compensate the i/p scaling,
985 * slope and offset.
986 * @chan_rslt: physical result to be stored.
987 */
988int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
989 const struct qpnp_adc_properties *adc_prop,
990 const struct qpnp_vadc_chan_properties *chan_prop,
991 struct qpnp_vadc_result *chan_rslt);
992/**
993 * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output
994 * of an ADC to the ADC reference and compensates for the
995 * gain and offset.
996 * @adc_code: pre-calibrated digital ouput of the ADC.
997 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
998 * reference voltage.
999 * @chan_prop: individual channel properties to compensate the i/p scaling,
1000 * slope and offset.
1001 * @chan_rslt: physical result to be stored.
1002 */
1003int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
1004 const struct qpnp_adc_properties *adc_prop,
1005 const struct qpnp_vadc_chan_properties *chan_prop,
1006 struct qpnp_vadc_result *chan_rslt);
1007/**
1008 * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
1009 * of an ADC to the ADC reference and compensates for the
1010 * gain and offset. Returns the temperature of the xo therm in mili
1011 degC.
1012 * @adc_code: pre-calibrated digital ouput of the ADC.
1013 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1014 * reference voltage.
1015 * @chan_prop: individual channel properties to compensate the i/p scaling,
1016 * slope and offset.
1017 * @chan_rslt: physical result to be stored.
1018 */
1019int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
1020 const struct qpnp_adc_properties *adc_prop,
1021 const struct qpnp_vadc_chan_properties *chan_prop,
1022 struct qpnp_vadc_result *chan_rslt);
1023/**
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001024 * qpnp_adc_scale_therm_pu1() - Scales the pre-calibrated digital output
1025 * of an ADC to the ADC reference and compensates for the
1026 * gain and offset. Returns the temperature of the therm in degC.
1027 * It uses a mapping table computed for a 150K pull-up.
1028 * Pull-up1 is an internal pull-up on the AMUX of 150K.
1029 * @adc_code: pre-calibrated digital ouput of the ADC.
1030 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1031 * reference voltage.
1032 * @chan_prop: individual channel properties to compensate the i/p scaling,
1033 * slope and offset.
1034 * @chan_rslt: physical result to be stored.
1035 */
1036int32_t qpnp_adc_scale_therm_pu1(int32_t adc_code,
1037 const struct qpnp_adc_properties *adc_prop,
1038 const struct qpnp_vadc_chan_properties *chan_prop,
1039 struct qpnp_vadc_result *chan_rslt);
1040/**
1041 * qpnp_adc_scale_therm_pu2() - Scales the pre-calibrated digital output
1042 * of an ADC to the ADC reference and compensates for the
1043 * gain and offset. Returns the temperature of the therm in degC.
1044 * It uses a mapping table computed for a 100K pull-up.
1045 * Pull-up2 is an internal pull-up on the AMUX of 100K.
1046 * @adc_code: pre-calibrated digital ouput of the ADC.
1047 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1048 * reference voltage.
1049 * @chan_prop: individual channel properties to compensate the i/p scaling,
1050 * slope and offset.
1051 * @chan_rslt: physical result to be stored.
1052 */
1053int32_t qpnp_adc_scale_therm_pu2(int32_t adc_code,
1054 const struct qpnp_adc_properties *adc_prop,
1055 const struct qpnp_vadc_chan_properties *chan_prop,
1056 struct qpnp_vadc_result *chan_rslt);
1057/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001058 * qpnp_vadc_is_ready() - Clients can use this API to check if the
1059 * device is ready to use.
1060 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1061 * has not occured.
1062 */
1063int32_t qpnp_vadc_is_ready(void);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001064/**
1065 * qpnp_adc_tm_scaler() - Performs reverse calibration.
1066 * @config: Thermal monitoring configuration.
1067 * @adc_prop: adc properties of the qpnp adc such as bit resolution and
1068 * reference voltage.
1069 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1070 * slope and offset.
1071 */
1072static inline int32_t qpnp_adc_tm_scaler(struct qpnp_adc_tm_config *tm_config,
1073 const struct qpnp_adc_properties *adc_prop,
1074 const struct qpnp_vadc_chan_properties *chan_prop)
1075{ return -ENXIO; }
1076/**
1077 * qpnp_get_vadc_gain_and_offset() - Obtains the VADC gain and offset
1078 * for absolute and ratiometric calibration.
1079 * @param: The result in which the ADC offset and gain values are stored.
1080 * @type: The calibration type whether client needs the absolute or
1081 * ratiometric gain and offset values.
1082 */
1083int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_linear_graph *param,
1084 enum qpnp_adc_calib_type calib_type);
1085/**
1086 * qpnp_adc_btm_scaler() - Performs reverse calibration on the low/high
1087 * temperature threshold values passed by the client.
1088 * The function maps the temperature to voltage and applies
1089 * ratiometric calibration on the voltage values.
1090 * @param: The input parameters that contain the low/high temperature
1091 * values.
1092 * @low_threshold: The low threshold value that needs to be updated with
1093 * the above calibrated voltage value.
1094 * @high_threshold: The low threshold value that needs to be updated with
1095 * the above calibrated voltage value.
1096 */
1097int32_t qpnp_adc_btm_scaler(struct qpnp_adc_tm_btm_param *param,
1098 uint32_t *low_threshold, uint32_t *high_threshold);
1099/**
1100 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1101 * and convert given temperature to voltage on supported
1102 * thermistor channels using 100k pull-up.
1103 * @param: The input temperature values.
1104 */
1105int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_adc_tm_config *param);
1106/**
1107 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1108 * and converts the given ADC code to temperature for
1109 * thermistor channels using 100k pull-up.
1110 * @reg: The input ADC code.
1111 * @result: The physical measurement temperature on the thermistor.
1112 */
1113int32_t qpnp_adc_tm_scale_voltage_therm_pu2(uint32_t reg, int64_t *result);
1114/**
1115 * qpnp_adc_usb_scaler() - Performs reverse calibration on the low/high
1116 * voltage threshold values passed by the client.
1117 * The function applies ratiometric calibration on the
1118 * voltage values.
1119 * @param: The input parameters that contain the low/high voltage
1120 * threshold values.
1121 * @low_threshold: The low threshold value that needs to be updated with
1122 * the above calibrated voltage value.
1123 * @high_threshold: The low threshold value that needs to be updated with
1124 * the above calibrated voltage value.
1125 */
1126int32_t qpnp_adc_usb_scaler(struct qpnp_adc_tm_usbid_param *param,
1127 uint32_t *low_threshold, uint32_t *high_threshold);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001128#else
1129static inline int32_t qpnp_vadc_read(uint32_t channel,
1130 struct qpnp_vadc_result *result)
1131{ return -ENXIO; }
1132static inline int32_t qpnp_vadc_conv_seq_request(
1133 enum qpnp_vadc_trigger trigger_channel,
1134 enum qpnp_vadc_channels channel,
1135 struct qpnp_vadc_result *result)
1136{ return -ENXIO; }
1137static inline int32_t qpnp_adc_scale_default(int32_t adc_code,
1138 const struct qpnp_adc_properties *adc_prop,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001139 const struct qpnp_vadc_chan_properties *chan_prop,
1140 struct qpnp_vadc_result *chan_rslt)
1141{ return -ENXIO; }
1142static inline int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
1143 const struct qpnp_adc_properties *adc_prop,
1144 const struct qpnp_vadc_chan_properties *chan_prop,
1145 struct qpnp_vadc_result *chan_rslt)
1146{ return -ENXIO; }
1147static inline int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
1148 const struct qpnp_adc_properties *adc_prop,
1149 const struct qpnp_vadc_chan_properties *chan_prop,
1150 struct qpnp_vadc_result *chan_rslt)
1151{ return -ENXIO; }
1152static inline int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
1153 const struct qpnp_adc_properties *adc_prop,
1154 const struct qpnp_vadc_chan_properties *chan_prop,
1155 struct qpnp_vadc_result *chan_rslt)
1156{ return -ENXIO; }
1157static inline int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
1158 const struct qpnp_adc_properties *adc_prop,
1159 const struct qpnp_vadc_chan_properties *chan_prop,
1160 struct qpnp_vadc_result *chan_rslt)
1161{ return -ENXIO; }
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001162static inline int32_t qpnp_adc_scale_therm_pu1(int32_t adc_code,
1163 const struct qpnp_adc_properties *adc_prop,
1164 const struct qpnp_vadc_chan_properties *chan_prop,
1165 struct qpnp_vadc_result *chan_rslt);
1166{ return -ENXIO; }
1167static inline int32_t qpnp_adc_scale_therm_pu2(int32_t adc_code,
1168 const struct qpnp_adc_properties *adc_prop,
1169 const struct qpnp_vadc_chan_properties *chan_prop,
1170 struct qpnp_vadc_result *chan_rslt);
1171{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001172static inline int32_t qpnp_vadc_is_ready(void)
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001173{ return -ENXIO; }
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001174static inline int32_t qpnp_adc_scale_default(int32_t adc_code,
1175 const struct qpnp_adc_properties *adc_prop,
1176 const struct qpnp_adc_chan_properties *chan_prop,
1177 struct qpnp_adc_chan_result *chan_rslt)
1178{ return -ENXIO; }
1179static inline int32_t qpnp_get_vadc_gain_and_offset(
1180 struct qpnp_vadc_linear_graph *param,
1181 enum qpnp_adc_calib_type calib_type)
1182{ return -ENXIO; }
1183static inline int32_t qpnp_adc_usb_scaler(
1184 struct qpnp_adc_tm_usbid_param *param,
1185 uint32_t *low_threshold, uint32_t *high_threshold)
1186{ return -ENXIO; }
1187static inline int32_t qpnp_adc_btm_scaler(
1188 struct qpnp_adc_tm_btm_param *param,
1189 uint32_t *low_threshold, uint32_t *high_threshold)
1190{ return -ENXIO; }
1191static inline int32_t qpnp_adc_tm_scale_therm_voltage_pu2(
1192 struct qpnp_adc_tm_config *param)
1193{ return -ENXIO; }
1194static inline int32_t qpnp_adc_tm_scale_voltage_therm_pu2(
1195 uint32_t reg, int64_t *result)
1196{ return -ENXIO; }
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001197#endif
1198
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001199/* Public API */
1200#if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \
1201 || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE)
1202/**
1203 * qpnp_iadc_read() - Performs ADC read on the current channel.
1204 * @channel: Input channel to perform the ADC read.
1205 * @result: Current across rsens in mV.
1206 */
1207int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001208 struct qpnp_iadc_result *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001209/**
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001210 * qpnp_iadc_get_gain_and_offset() - Performs gain calibration
1211 * over 17.8571mV and offset over selected
1212 * channel. Channel can be internal rsense,
1213 * external rsense and alternate lead pair.
1214 * @result: result structure where the gain and offset is stored of
1215 * type qpnp_iadc_calib.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001216 */
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001217int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_calib *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001218
1219/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001220 * qpnp_iadc_is_ready() - Clients can use this API to check if the
1221 * device is ready to use.
1222 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1223 * has not occured.
1224 */
1225int32_t qpnp_iadc_is_ready(void);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001226#else
1227static inline int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001228 struct qpnp_iadc_result *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001229{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001230static inline int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_calib
1231 *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001232{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001233static inline int32_t qpnp_iadc_is_ready(void)
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001234{ return -ENXIO; }
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001235#endif
1236
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001237#endif