blob: 9d5de907c6e4416a313dc3f4485417c77d550822 [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,
31 SPARE2_03,
32 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,
84 LR_MUX10_USB_ID,
85 AMUX_PU1,
86 AMUX_PU2,
87 LR_MUX3_BUF_XO_THERM_BUF,
88 LR_MUX1_PU1_BAT_THERM,
89 LR_MUX2_PU1_BAT_ID,
90 LR_MUX3_PU1_XO_THERM,
91 LR_MUX4_PU1_AMUX_THM1,
92 LR_MUX5_PU1_AMUX_THM2,
93 LR_MUX6_PU1_AMUX_THM3,
94 LR_MUX7_PU1_AMUX_HW_ID,
95 LR_MUX8_PU1_AMUX_THM4,
96 LR_MUX9_PU1_AMUX_THM5,
97 LR_MUX10_PU1_AMUX_USB_ID,
98 LR_MUX3_BUF_PU1_XO_THERM_BUF,
99 LR_MUX1_PU2_BAT_THERM,
100 LR_MUX2_PU2_BAT_ID,
101 LR_MUX3_PU2_XO_THERM,
102 LR_MUX4_PU2_AMUX_THM1,
103 LR_MUX5_PU2_AMUX_THM2,
104 LR_MUX6_PU2_AMUX_THM3,
105 LR_MUX7_PU2_AMUX_HW_ID,
106 LR_MUX8_PU2_AMUX_THM4,
107 LR_MUX9_PU2_AMUX_THM5,
108 LR_MUX10_PU2_AMUX_USB_ID,
109 LR_MUX3_BUF_PU2_XO_THERM_BUF,
110 LR_MUX1_PU1_PU2_BAT_THERM,
111 LR_MUX2_PU1_PU2_BAT_ID,
112 LR_MUX3_PU1_PU2_XO_THERM,
113 LR_MUX4_PU1_PU2_AMUX_THM1,
114 LR_MUX5_PU1_PU2_AMUX_THM2,
115 LR_MUX6_PU1_PU2_AMUX_THM3,
116 LR_MUX7_PU1_PU2_AMUX_HW_ID,
117 LR_MUX8_PU1_PU2_AMUX_THM4,
118 LR_MUX9_PU1_PU2_AMUX_THM5,
119 LR_MUX10_PU1_PU2_AMUX_USB_ID,
120 LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF,
121 ALL_OFF,
122 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/**
405 * enum qpnp_adc_meas_timer - Selects the measurement interval time.
406 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
407 * %ADC_MEAS_INTERVAL_0MS : 0ms
408 * %ADC_MEAS_INTERVAL_1P0MS : 1ms
409 * %ADC_MEAS_INTERVAL_2P0MS : 2ms
410 * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms
411 * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms
412 * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms
413 * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms
414 * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms
415 * %ADC_MEAS_INTERVAL_125MS : 125ms
416 * %ADC_MEAS_INTERVAL_250MS : 250ms
417 * %ADC_MEAS_INTERVAL_500MS : 500ms
418 * %ADC_MEAS_INTERVAL_1S : 1seconds
419 * %ADC_MEAS_INTERVAL_2S : 2seconds
420 * %ADC_MEAS_INTERVAL_4S : 4seconds
421 * %ADC_MEAS_INTERVAL_8S : 8seconds
422 * %ADC_MEAS_INTERVAL_16S: 16seconds
423 */
424enum qpnp_adc_meas_timer {
425 ADC_MEAS_INTERVAL_0MS = 0,
426 ADC_MEAS_INTERVAL_1P0MS,
427 ADC_MEAS_INTERVAL_2P0MS,
428 ADC_MEAS_INTERVAL_3P9MS,
429 ADC_MEAS_INTERVAL_7P8MS,
430 ADC_MEAS_INTERVAL_15P6MS,
431 ADC_MEAS_INTERVAL_31P3MS,
432 ADC_MEAS_INTERVAL_62P5MS,
433 ADC_MEAS_INTERVAL_125MS,
434 ADC_MEAS_INTERVAL_250MS,
435 ADC_MEAS_INTERVAL_500MS,
436 ADC_MEAS_INTERVAL_1S,
437 ADC_MEAS_INTERVAL_2S,
438 ADC_MEAS_INTERVAL_4S,
439 ADC_MEAS_INTERVAL_8S,
440 ADC_MEAS_INTERVAL_16S,
441 ADC_MEAS_INTERVAL_NONE,
442};
443
444/**
445 * enum qpnp_adc_meas_interval_op_ctl - Select operating mode.
446 * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time
447 * delay.
448 * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval
449 * times.
450 */
451enum qpnp_adc_meas_interval_op_ctl {
452 ADC_MEAS_INTERVAL_OP_SINGLE = 0,
453 ADC_MEAS_INTERVAL_OP_CONTINUOUS,
454 ADC_MEAS_INTERVAL_OP_NONE,
455};
456
457/**
458 * struct qpnp_vadc_linear_graph - Represent ADC characteristics.
459 * @dy: Numerator slope to calculate the gain.
460 * @dx: Denominator slope to calculate the gain.
461 * @adc_vref: A/D word of the voltage reference used for the channel.
462 * @adc_gnd: A/D word of the ground reference used for the channel.
463 *
464 * Each ADC device has different offset and gain parameters which are computed
465 * to calibrate the device.
466 */
467struct qpnp_vadc_linear_graph {
468 int64_t dy;
469 int64_t dx;
470 int64_t adc_vref;
471 int64_t adc_gnd;
472};
473
474/**
475 * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel
476 * @x: Represent the ADC digitized code.
477 * @y: Represent the physical data which can be temperature, voltage,
478 * resistance.
479 */
480struct qpnp_vadc_map_pt {
481 int32_t x;
482 int32_t y;
483};
484
485/**
486 * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input.
487 * @num: Numerator scaling parameter.
488 * @den: Denominator scaling parameter.
489 */
490struct qpnp_vadc_scaling_ratio {
491 int32_t num;
492 int32_t den;
493};
494
495/**
496 * struct qpnp_adc_properties - Represent the ADC properties.
497 * @adc_reference: Reference voltage for QPNP ADC.
498 * @bitresolution: ADC bit resolution for QPNP ADC.
499 * @biploar: Polarity for QPNP ADC.
500 */
501struct qpnp_adc_properties {
502 uint32_t adc_vdd_reference;
503 uint32_t bitresolution;
504 bool bipolar;
505};
506
507/**
508 * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC.
509 * @offset_gain_numerator: The inverse numerator of the gain applied to the
510 * input channel.
511 * @offset_gain_denominator: The inverse denominator of the gain applied to the
512 * input channel.
513 * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph.
514 */
515struct qpnp_vadc_chan_properties {
516 uint32_t offset_gain_numerator;
517 uint32_t offset_gain_denominator;
518 struct qpnp_vadc_linear_graph adc_graph[2];
519};
520
521/**
522 * struct qpnp_adc_result - Represent the result of the QPNP ADC.
523 * @chan: The channel number of the requested conversion.
524 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
525 * the ADC reference.
526 * @measurement: In units specific for a given ADC; most ADC uses reference
527 * voltage but some ADC uses reference current. This measurement
528 * here is a number relative to a reference of a given ADC.
529 * @physical: The data meaningful for each individual channel whether it is
530 * voltage, current, temperature, etc.
531 * All voltage units are represented in micro - volts.
532 * -Battery temperature units are represented as 0.1 DegC.
533 * -PA Therm temperature units are represented as DegC.
534 * -PMIC Die temperature units are represented as 0.001 DegC.
535 */
536struct qpnp_vadc_result {
537 uint32_t chan;
538 int32_t adc_code;
539 int64_t measurement;
540 int64_t physical;
541};
542
543/**
544 * struct qpnp_adc_amux - AMUX properties for individual channel
545 * @name: Channel string name.
546 * @channel_num: Channel in integer used from qpnp_adc_channels.
547 * @chan_path_prescaling: Channel scaling performed on the input signal.
548 * @adc_decimation: Sampling rate desired for the channel.
549 * adc_scale_fn: Scaling function to convert to the data meaningful for
550 * each individual channel whether it is voltage, current,
551 * temperature, etc and compensates the channel properties.
552 */
553struct qpnp_vadc_amux {
554 char *name;
555 enum qpnp_vadc_channels channel_num;
556 enum qpnp_adc_channel_scaling_param chan_path_prescaling;
557 enum qpnp_adc_decimation_type adc_decimation;
558 enum qpnp_adc_scale_fn_type adc_scale_fn;
559 enum qpnp_adc_fast_avg_ctl fast_avg_setup;
560 enum qpnp_adc_hw_settle_time hw_settle_time;
561};
562
563/**
564 * struct qpnp_vadc_scaling_ratio
565 *
566 */
567static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = {
568 {1, 1},
569 {1, 3},
570 {1, 4},
571 {1, 6},
572 {1, 20}
573};
574
575/**
576 * struct qpnp_vadc_scale_fn - Scaling function prototype
577 * @chan: Function pointer to one of the scaling functions
578 * which takes the adc properties, channel properties,
579 * and returns the physical result
580 */
581struct qpnp_vadc_scale_fn {
582 int32_t (*chan) (int32_t,
583 const struct qpnp_adc_properties *,
584 const struct qpnp_vadc_chan_properties *,
585 struct qpnp_vadc_result *);
586};
587
588/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700589 * struct qpnp_iadc_calib - IADC channel calibration structure.
590 * @channel - Channel for which the historical offset and gain is
591 * calculated. Available channels are internal rsense,
592 * external rsense and alternate lead pairs.
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700593 * @offset_raw - raw Offset value for the channel.
594 * @gain_raw - raw Gain of the channel.
595 * @ideal_offset_uv - ideal offset value for the channel.
596 * @ideal_gain_nv - ideal gain for the channel.
597 * @offset_uv - converted value of offset in uV.
598 * @gain_uv - converted value of gain in uV.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700599 */
600struct qpnp_iadc_calib {
601 enum qpnp_iadc_channels channel;
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700602 uint16_t offset_raw;
603 uint16_t gain_raw;
604 uint32_t ideal_offset_uv;
605 uint32_t ideal_gain_nv;
606 uint32_t offset_uv;
607 uint32_t gain_uv;
608};
609
610/**
611 * struct qpnp_iadc_result - IADC read result structure.
612 * @oresult_uv - Result of ADC in uV.
613 * @result_ua - Result of ADC in uA.
614 */
615struct qpnp_iadc_result {
616 int32_t result_uv;
617 int32_t result_ua;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700618};
619
620/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700621 * struct qpnp_adc_drv - QPNP ADC device structure.
622 * @spmi - spmi device for ADC peripheral.
623 * @offset - base offset for the ADC peripheral.
624 * @adc_prop - ADC properties specific to the ADC peripheral.
625 * @amux_prop - AMUX properties representing the ADC peripheral.
626 * @adc_channels - ADC channel properties for the ADC peripheral.
627 * @adc_irq - IRQ number that is mapped to the ADC peripheral.
628 * @adc_lock - ADC lock for access to the peripheral.
629 * @adc_rslt_completion - ADC result notification after interrupt
630 * is received.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700631 * @calib - Internal rsens calibration values for gain and offset.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700632 */
633struct qpnp_adc_drv {
634 struct spmi_device *spmi;
635 uint8_t slave;
636 uint16_t offset;
637 struct qpnp_adc_properties *adc_prop;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700638 struct qpnp_adc_amux_properties *amux_prop;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700639 struct qpnp_vadc_amux *adc_channels;
640 int adc_irq;
641 struct mutex adc_lock;
642 struct completion adc_rslt_completion;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700643 struct qpnp_iadc_calib calib;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700644};
645
646/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700647 * struct qpnp_adc_amux_properties - QPNP VADC amux channel property.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700648 * @amux_channel - Refer to the qpnp_vadc_channel list.
649 * @decimation - Sampling rate supported for the channel.
650 * @mode_sel - The basic mode of operation.
651 * @hw_settle_time - The time between AMUX being configured and the
652 * start of conversion.
653 * @fast_avg_setup - Ability to provide single result from the ADC
654 * that is an average of multiple measurements.
655 * @trigger_channel - HW trigger channel for conversion sequencer.
656 * @chan_prop - Represent the channel properties of the ADC.
657 */
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700658struct qpnp_adc_amux_properties {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700659 uint32_t amux_channel;
660 uint32_t decimation;
661 uint32_t mode_sel;
662 uint32_t hw_settle_time;
663 uint32_t fast_avg_setup;
664 enum qpnp_vadc_trigger trigger_channel;
665 struct qpnp_vadc_chan_properties chan_prop[0];
666};
667
668/* Public API */
669#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \
670 || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE)
671/**
672 * qpnp_vadc_read() - Performs ADC read on the channel.
673 * @channel: Input channel to perform the ADC read.
674 * @result: Structure pointer of type adc_chan_result
675 * in which the ADC read results are stored.
676 */
677int32_t qpnp_vadc_read(enum qpnp_vadc_channels channel,
678 struct qpnp_vadc_result *result);
679
680/**
681 * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion
682 * sequencer channel.
683 * @channel: Input channel to perform the ADC read.
684 * @result: Structure pointer of type adc_chan_result
685 * in which the ADC read results are stored.
686 */
687int32_t qpnp_vadc_conv_seq_request(
688 enum qpnp_vadc_trigger trigger_channel,
689 enum qpnp_vadc_channels channel,
690 struct qpnp_vadc_result *result);
691
692/**
693 * qpnp_vadc_check_result() - Performs check on the ADC raw code.
694 * @data: Data used for verifying the range of the ADC code.
695 */
696int32_t qpnp_vadc_check_result(int32_t *data);
697
698/**
699 * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data.
700 * @spmi: spmi ADC device.
701 * @adc_qpnp: spmi device tree node structure
702 */
703int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi,
704 struct qpnp_adc_drv *adc_qpnp);
705
706/**
707 * qpnp_vadc_configure() - Configure ADC device to start conversion.
708 * @chan_prop: Individual channel properties for the AMUX channel.
709 */
710int32_t qpnp_vadc_configure(
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700711 struct qpnp_adc_amux_properties *chan_prop);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700712
713/**
714 * qpnp_adc_scale_default() - Scales the pre-calibrated digital output
715 * of an ADC to the ADC reference and compensates for the
716 * gain and offset.
717 * @adc_code: pre-calibrated digital ouput of the ADC.
718 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
719 * reference voltage.
720 * @chan_prop: Individual channel properties to compensate the i/p scaling,
721 * slope and offset.
722 * @chan_rslt: Physical result to be stored.
723 */
724int32_t qpnp_adc_scale_default(int32_t adc_code,
725 const struct qpnp_adc_properties *adc_prop,
726 const struct qpnp_vadc_chan_properties *chan_prop,
727 struct qpnp_vadc_result *chan_rslt);
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700728/**
729 * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
730 * of an ADC to the ADC reference and compensates for the
731 * gain and offset. Performs the AMUX out as 2mV/K and returns
732 * the temperature in milli degC.
733 * @adc_code: pre-calibrated digital ouput of the ADC.
734 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
735 * reference voltage.
736 * @chan_prop: Individual channel properties to compensate the i/p scaling,
737 * slope and offset.
738 * @chan_rslt: Physical result to be stored.
739 */
740int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
741 const struct qpnp_adc_properties *adc_prop,
742 const struct qpnp_vadc_chan_properties *chan_prop,
743 struct qpnp_vadc_result *chan_rslt);
744/**
745 * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
746 * of an ADC to the ADC reference and compensates for the
747 * gain and offset. Returns the temperature in degC.
748 * @adc_code: pre-calibrated digital ouput of the ADC.
749 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
750 * reference voltage.
751 * @chan_prop: individual channel properties to compensate the i/p scaling,
752 * slope and offset.
753 * @chan_rslt: physical result to be stored.
754 */
755int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
756 const struct qpnp_adc_properties *adc_prop,
757 const struct qpnp_vadc_chan_properties *chan_prop,
758 struct qpnp_vadc_result *chan_rslt);
759/**
760 * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output
761 * of an ADC to the ADC reference and compensates for the
762 * gain and offset.
763 * @adc_code: pre-calibrated digital ouput of the ADC.
764 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
765 * reference voltage.
766 * @chan_prop: individual channel properties to compensate the i/p scaling,
767 * slope and offset.
768 * @chan_rslt: physical result to be stored.
769 */
770int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
771 const struct qpnp_adc_properties *adc_prop,
772 const struct qpnp_vadc_chan_properties *chan_prop,
773 struct qpnp_vadc_result *chan_rslt);
774/**
775 * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
776 * of an ADC to the ADC reference and compensates for the
777 * gain and offset. Returns the temperature of the xo therm in mili
778 degC.
779 * @adc_code: pre-calibrated digital ouput of the ADC.
780 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
781 * reference voltage.
782 * @chan_prop: individual channel properties to compensate the i/p scaling,
783 * slope and offset.
784 * @chan_rslt: physical result to be stored.
785 */
786int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
787 const struct qpnp_adc_properties *adc_prop,
788 const struct qpnp_vadc_chan_properties *chan_prop,
789 struct qpnp_vadc_result *chan_rslt);
790/**
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700791 * qpnp_adc_scale_therm_pu1() - Scales the pre-calibrated digital output
792 * of an ADC to the ADC reference and compensates for the
793 * gain and offset. Returns the temperature of the therm in degC.
794 * It uses a mapping table computed for a 150K pull-up.
795 * Pull-up1 is an internal pull-up on the AMUX of 150K.
796 * @adc_code: pre-calibrated digital ouput of the ADC.
797 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
798 * reference voltage.
799 * @chan_prop: individual channel properties to compensate the i/p scaling,
800 * slope and offset.
801 * @chan_rslt: physical result to be stored.
802 */
803int32_t qpnp_adc_scale_therm_pu1(int32_t adc_code,
804 const struct qpnp_adc_properties *adc_prop,
805 const struct qpnp_vadc_chan_properties *chan_prop,
806 struct qpnp_vadc_result *chan_rslt);
807/**
808 * qpnp_adc_scale_therm_pu2() - Scales the pre-calibrated digital output
809 * of an ADC to the ADC reference and compensates for the
810 * gain and offset. Returns the temperature of the therm in degC.
811 * It uses a mapping table computed for a 100K pull-up.
812 * Pull-up2 is an internal pull-up on the AMUX of 100K.
813 * @adc_code: pre-calibrated digital ouput of the ADC.
814 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
815 * reference voltage.
816 * @chan_prop: individual channel properties to compensate the i/p scaling,
817 * slope and offset.
818 * @chan_rslt: physical result to be stored.
819 */
820int32_t qpnp_adc_scale_therm_pu2(int32_t adc_code,
821 const struct qpnp_adc_properties *adc_prop,
822 const struct qpnp_vadc_chan_properties *chan_prop,
823 struct qpnp_vadc_result *chan_rslt);
824/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700825 * qpnp_vadc_is_ready() - Clients can use this API to check if the
826 * device is ready to use.
827 * @result: 0 on success and -EPROBE_DEFER when probe for the device
828 * has not occured.
829 */
830int32_t qpnp_vadc_is_ready(void);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700831#else
832static inline int32_t qpnp_vadc_read(uint32_t channel,
833 struct qpnp_vadc_result *result)
834{ return -ENXIO; }
835static inline int32_t qpnp_vadc_conv_seq_request(
836 enum qpnp_vadc_trigger trigger_channel,
837 enum qpnp_vadc_channels channel,
838 struct qpnp_vadc_result *result)
839{ return -ENXIO; }
840static inline int32_t qpnp_adc_scale_default(int32_t adc_code,
841 const struct qpnp_adc_properties *adc_prop,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700842 const struct qpnp_vadc_chan_properties *chan_prop,
843 struct qpnp_vadc_result *chan_rslt)
844{ return -ENXIO; }
845static inline int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
846 const struct qpnp_adc_properties *adc_prop,
847 const struct qpnp_vadc_chan_properties *chan_prop,
848 struct qpnp_vadc_result *chan_rslt)
849{ return -ENXIO; }
850static inline int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
851 const struct qpnp_adc_properties *adc_prop,
852 const struct qpnp_vadc_chan_properties *chan_prop,
853 struct qpnp_vadc_result *chan_rslt)
854{ return -ENXIO; }
855static inline int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
856 const struct qpnp_adc_properties *adc_prop,
857 const struct qpnp_vadc_chan_properties *chan_prop,
858 struct qpnp_vadc_result *chan_rslt)
859{ return -ENXIO; }
860static inline int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
861 const struct qpnp_adc_properties *adc_prop,
862 const struct qpnp_vadc_chan_properties *chan_prop,
863 struct qpnp_vadc_result *chan_rslt)
864{ return -ENXIO; }
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700865static inline int32_t qpnp_adc_scale_therm_pu1(int32_t adc_code,
866 const struct qpnp_adc_properties *adc_prop,
867 const struct qpnp_vadc_chan_properties *chan_prop,
868 struct qpnp_vadc_result *chan_rslt);
869{ return -ENXIO; }
870static inline int32_t qpnp_adc_scale_therm_pu2(int32_t adc_code,
871 const struct qpnp_adc_properties *adc_prop,
872 const struct qpnp_vadc_chan_properties *chan_prop,
873 struct qpnp_vadc_result *chan_rslt);
874{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700875static inline int32_t qpnp_vadc_is_ready(void)
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700876{ return -ENXIO; }
877#endif
878
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700879/* Public API */
880#if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \
881 || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE)
882/**
883 * qpnp_iadc_read() - Performs ADC read on the current channel.
884 * @channel: Input channel to perform the ADC read.
885 * @result: Current across rsens in mV.
886 */
887int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700888 struct qpnp_iadc_result *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700889/**
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700890 * qpnp_iadc_get_gain_and_offset() - Performs gain calibration
891 * over 17.8571mV and offset over selected
892 * channel. Channel can be internal rsense,
893 * external rsense and alternate lead pair.
894 * @result: result structure where the gain and offset is stored of
895 * type qpnp_iadc_calib.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700896 */
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700897int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_calib *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700898
899/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700900 * qpnp_iadc_is_ready() - Clients can use this API to check if the
901 * device is ready to use.
902 * @result: 0 on success and -EPROBE_DEFER when probe for the device
903 * has not occured.
904 */
905int32_t qpnp_iadc_is_ready(void);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700906#else
907static inline int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700908 struct qpnp_iadc_result *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700909{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700910static inline int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_calib
911 *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700912{ return -ENXIO; }
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700913static inline int32_t qpnp_iadc_is_ready(void)
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700914{ return -ENXIO; }
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700915#endif
916
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700917#endif