blob: 19a1d972c51962fab8dda4741ab051f7929ad0bf [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,
132 GAIN_CALIBRATION_25MV,
133 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 Mohanadossc4a6af12012-07-13 18:50:12 -0700140#define QPNP_ADC_HWMON_NAME_LENGTH 16
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 Mohanadoss336d8b12012-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 Mohanadoss336d8b12012-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 Mohanadoss336d8b12012-08-20 23:18:10 -0700202 * %ADC_SCALE_PA_THERM: Returns temperature in degC.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700203 * %ADC_SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700204 * %ADC_SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade.
205 * %ADC_SCALE_NONE: Do not use this scaling type.
206 */
207enum qpnp_adc_scale_fn_type {
208 SCALE_DEFAULT = 0,
209 SCALE_BATT_THERM,
210 SCALE_PA_THERM,
211 SCALE_PMIC_THERM,
212 SCALE_XOTHERM,
213 SCALE_NONE,
214};
215
216/**
217 * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result
218 * from the ADC that is an average of multiple measurement
219 * samples. Select number of samples for use in fast
220 * average mode (i.e. 2 ^ value).
221 * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1
222 * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2
223 * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4
224 * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8
225 * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16
226 * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32
227 * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64
228 * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128
229 * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256
230 * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512
231 */
232enum qpnp_adc_fast_avg_ctl {
233 ADC_FAST_AVG_SAMPLE_1 = 0,
234 ADC_FAST_AVG_SAMPLE_2,
235 ADC_FAST_AVG_SAMPLE_4,
236 ADC_FAST_AVG_SAMPLE_8,
237 ADC_FAST_AVG_SAMPLE_16,
238 ADC_FAST_AVG_SAMPLE_32,
239 ADC_FAST_AVG_SAMPLE_64,
240 ADC_FAST_AVG_SAMPLE_128,
241 ADC_FAST_AVG_SAMPLE_256,
242 ADC_FAST_AVG_SAMPLE_512,
243 ADC_FAST_AVG_SAMPLE_NONE,
244};
245
246/**
247 * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and
248 * the ADC starting conversion. Delay = 100us * value for
249 * value < 11 and 2ms * (value - 10) otherwise.
250 * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us
251 * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us
252 * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us
253 * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us
254 * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us
255 * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us
256 * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us
257 * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us
258 * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us
259 * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us
260 * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms
261 * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms
262 * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms
263 * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms
264 * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms
265 * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms
266 * %ADC_CHANNEL_HW_SETTLE_NONE
267 */
268enum qpnp_adc_hw_settle_time {
269 ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0,
270 ADC_CHANNEL_HW_SETTLE_DELAY_100US,
271 ADC_CHANNEL_HW_SETTLE_DELAY_2000US,
272 ADC_CHANNEL_HW_SETTLE_DELAY_300US,
273 ADC_CHANNEL_HW_SETTLE_DELAY_400US,
274 ADC_CHANNEL_HW_SETTLE_DELAY_500US,
275 ADC_CHANNEL_HW_SETTLE_DELAY_600US,
276 ADC_CHANNEL_HW_SETTLE_DELAY_700US,
277 ADC_CHANNEL_HW_SETTLE_DELAY_800US,
278 ADC_CHANNEL_HW_SETTLE_DELAY_900US,
279 ADC_CHANNEL_HW_SETTLE_DELAY_1MS,
280 ADC_CHANNEL_HW_SETTLE_DELAY_2MS,
281 ADC_CHANNEL_HW_SETTLE_DELAY_4MS,
282 ADC_CHANNEL_HW_SETTLE_DELAY_6MS,
283 ADC_CHANNEL_HW_SETTLE_DELAY_8MS,
284 ADC_CHANNEL_HW_SETTLE_DELAY_10MS,
285 ADC_CHANNEL_HW_SETTLE_NONE,
286};
287
288/**
289 * enum qpnp_vadc_mode_sel - Selects the basic mode of operation.
290 * - The normal mode is used for single measurement.
291 * - The Conversion sequencer is used to trigger an
292 * ADC read when a HW trigger is selected.
293 * - The measurement interval performs a single or
294 * continous measurement at a specified interval/delay.
295 * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement.
296 * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger
297 * an ADC read on a HW supported trigger.
298 * Refer to enum qpnp_vadc_trigger for
299 * supported HW triggers.
300 * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a
301 * single or continous measurement after a specified delay.
302 * For delay look at qpnp_adc_meas_timer.
303 */
304enum qpnp_vadc_mode_sel {
305 ADC_OP_NORMAL_MODE = 0,
306 ADC_OP_CONVERSION_SEQUENCER,
307 ADC_OP_MEASUREMENT_INTERVAL,
308 ADC_OP_MODE_NONE,
309};
310
311/**
312 * enum qpnp_vadc_trigger - Select the HW trigger to be used while
313 * measuring the ADC reading.
314 * %ADC_GSM_PA_ON : GSM power amplifier on.
315 * %ADC_TX_GTR_THRES : Transmit power greater than threshold.
316 * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done.
317 * %ADC_DTEST : DTEST.
318 */
319enum qpnp_vadc_trigger {
320 ADC_GSM_PA_ON = 0,
321 ADC_TX_GTR_THRES,
322 ADC_CAMERA_FLASH_RAMP,
323 ADC_DTEST,
324 ADC_SEQ_NONE,
325};
326
327/**
328 * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from
329 * conversion request to triggering conversion sequencer
330 * hold off time.
331 */
332enum qpnp_vadc_conv_seq_timeout {
333 ADC_CONV_SEQ_TIMEOUT_0MS = 0,
334 ADC_CONV_SEQ_TIMEOUT_1MS,
335 ADC_CONV_SEQ_TIMEOUT_2MS,
336 ADC_CONV_SEQ_TIMEOUT_3MS,
337 ADC_CONV_SEQ_TIMEOUT_4MS,
338 ADC_CONV_SEQ_TIMEOUT_5MS,
339 ADC_CONV_SEQ_TIMEOUT_6MS,
340 ADC_CONV_SEQ_TIMEOUT_7MS,
341 ADC_CONV_SEQ_TIMEOUT_8MS,
342 ADC_CONV_SEQ_TIMEOUT_9MS,
343 ADC_CONV_SEQ_TIMEOUT_10MS,
344 ADC_CONV_SEQ_TIMEOUT_11MS,
345 ADC_CONV_SEQ_TIMEOUT_12MS,
346 ADC_CONV_SEQ_TIMEOUT_13MS,
347 ADC_CONV_SEQ_TIMEOUT_14MS,
348 ADC_CONV_SEQ_TIMEOUT_15MS,
349 ADC_CONV_SEQ_TIMEOUT_NONE,
350};
351
352/**
353 * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion
354 * trigger signal (i.e. adc_conv_seq_trig) transition
355 * to ADC enable. Delay = 25us * (value + 1).
356 */
357enum qpnp_adc_conv_seq_holdoff {
358 ADC_SEQ_HOLD_25US = 0,
359 ADC_SEQ_HOLD_50US,
360 ADC_SEQ_HOLD_75US,
361 ADC_SEQ_HOLD_100US,
362 ADC_SEQ_HOLD_125US,
363 ADC_SEQ_HOLD_150US,
364 ADC_SEQ_HOLD_175US,
365 ADC_SEQ_HOLD_200US,
366 ADC_SEQ_HOLD_225US,
367 ADC_SEQ_HOLD_250US,
368 ADC_SEQ_HOLD_275US,
369 ADC_SEQ_HOLD_300US,
370 ADC_SEQ_HOLD_325US,
371 ADC_SEQ_HOLD_350US,
372 ADC_SEQ_HOLD_375US,
373 ADC_SEQ_HOLD_400US,
374 ADC_SEQ_HOLD_NONE,
375};
376
377/**
378 * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state
379 * %ADC_CONV_SEQ_IDLE : Sequencer is in idle.
380 * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger.
381 * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time.
382 * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal.
383 * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge.
384 * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time.
385 * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal.
386 * %ADC_CONV_ERROR : Aberrant Hardware problem.
387 */
388enum qpnp_adc_conv_seq_state {
389 ADC_CONV_SEQ_IDLE = 0,
390 ADC_CONV_TRIG_RISE,
391 ADC_CONV_TRIG_HOLDOFF,
392 ADC_CONV_MEAS_RISE,
393 ADC_CONV_TRIG_FALL,
394 ADC_CONV_FALL_HOLDOFF,
395 ADC_CONV_MEAS_FALL,
396 ADC_CONV_ERROR,
397 ADC_CONV_NONE,
398};
399
400/**
401 * enum qpnp_adc_meas_timer - Selects the measurement interval time.
402 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
403 * %ADC_MEAS_INTERVAL_0MS : 0ms
404 * %ADC_MEAS_INTERVAL_1P0MS : 1ms
405 * %ADC_MEAS_INTERVAL_2P0MS : 2ms
406 * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms
407 * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms
408 * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms
409 * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms
410 * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms
411 * %ADC_MEAS_INTERVAL_125MS : 125ms
412 * %ADC_MEAS_INTERVAL_250MS : 250ms
413 * %ADC_MEAS_INTERVAL_500MS : 500ms
414 * %ADC_MEAS_INTERVAL_1S : 1seconds
415 * %ADC_MEAS_INTERVAL_2S : 2seconds
416 * %ADC_MEAS_INTERVAL_4S : 4seconds
417 * %ADC_MEAS_INTERVAL_8S : 8seconds
418 * %ADC_MEAS_INTERVAL_16S: 16seconds
419 */
420enum qpnp_adc_meas_timer {
421 ADC_MEAS_INTERVAL_0MS = 0,
422 ADC_MEAS_INTERVAL_1P0MS,
423 ADC_MEAS_INTERVAL_2P0MS,
424 ADC_MEAS_INTERVAL_3P9MS,
425 ADC_MEAS_INTERVAL_7P8MS,
426 ADC_MEAS_INTERVAL_15P6MS,
427 ADC_MEAS_INTERVAL_31P3MS,
428 ADC_MEAS_INTERVAL_62P5MS,
429 ADC_MEAS_INTERVAL_125MS,
430 ADC_MEAS_INTERVAL_250MS,
431 ADC_MEAS_INTERVAL_500MS,
432 ADC_MEAS_INTERVAL_1S,
433 ADC_MEAS_INTERVAL_2S,
434 ADC_MEAS_INTERVAL_4S,
435 ADC_MEAS_INTERVAL_8S,
436 ADC_MEAS_INTERVAL_16S,
437 ADC_MEAS_INTERVAL_NONE,
438};
439
440/**
441 * enum qpnp_adc_meas_interval_op_ctl - Select operating mode.
442 * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time
443 * delay.
444 * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval
445 * times.
446 */
447enum qpnp_adc_meas_interval_op_ctl {
448 ADC_MEAS_INTERVAL_OP_SINGLE = 0,
449 ADC_MEAS_INTERVAL_OP_CONTINUOUS,
450 ADC_MEAS_INTERVAL_OP_NONE,
451};
452
453/**
454 * struct qpnp_vadc_linear_graph - Represent ADC characteristics.
455 * @dy: Numerator slope to calculate the gain.
456 * @dx: Denominator slope to calculate the gain.
457 * @adc_vref: A/D word of the voltage reference used for the channel.
458 * @adc_gnd: A/D word of the ground reference used for the channel.
459 *
460 * Each ADC device has different offset and gain parameters which are computed
461 * to calibrate the device.
462 */
463struct qpnp_vadc_linear_graph {
464 int64_t dy;
465 int64_t dx;
466 int64_t adc_vref;
467 int64_t adc_gnd;
468};
469
470/**
471 * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel
472 * @x: Represent the ADC digitized code.
473 * @y: Represent the physical data which can be temperature, voltage,
474 * resistance.
475 */
476struct qpnp_vadc_map_pt {
477 int32_t x;
478 int32_t y;
479};
480
481/**
482 * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input.
483 * @num: Numerator scaling parameter.
484 * @den: Denominator scaling parameter.
485 */
486struct qpnp_vadc_scaling_ratio {
487 int32_t num;
488 int32_t den;
489};
490
491/**
492 * struct qpnp_adc_properties - Represent the ADC properties.
493 * @adc_reference: Reference voltage for QPNP ADC.
494 * @bitresolution: ADC bit resolution for QPNP ADC.
495 * @biploar: Polarity for QPNP ADC.
496 */
497struct qpnp_adc_properties {
498 uint32_t adc_vdd_reference;
499 uint32_t bitresolution;
500 bool bipolar;
501};
502
503/**
504 * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC.
505 * @offset_gain_numerator: The inverse numerator of the gain applied to the
506 * input channel.
507 * @offset_gain_denominator: The inverse denominator of the gain applied to the
508 * input channel.
509 * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph.
510 */
511struct qpnp_vadc_chan_properties {
512 uint32_t offset_gain_numerator;
513 uint32_t offset_gain_denominator;
514 struct qpnp_vadc_linear_graph adc_graph[2];
515};
516
517/**
518 * struct qpnp_adc_result - Represent the result of the QPNP ADC.
519 * @chan: The channel number of the requested conversion.
520 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
521 * the ADC reference.
522 * @measurement: In units specific for a given ADC; most ADC uses reference
523 * voltage but some ADC uses reference current. This measurement
524 * here is a number relative to a reference of a given ADC.
525 * @physical: The data meaningful for each individual channel whether it is
526 * voltage, current, temperature, etc.
527 * All voltage units are represented in micro - volts.
528 * -Battery temperature units are represented as 0.1 DegC.
529 * -PA Therm temperature units are represented as DegC.
530 * -PMIC Die temperature units are represented as 0.001 DegC.
531 */
532struct qpnp_vadc_result {
533 uint32_t chan;
534 int32_t adc_code;
535 int64_t measurement;
536 int64_t physical;
537};
538
539/**
540 * struct qpnp_adc_amux - AMUX properties for individual channel
541 * @name: Channel string name.
542 * @channel_num: Channel in integer used from qpnp_adc_channels.
543 * @chan_path_prescaling: Channel scaling performed on the input signal.
544 * @adc_decimation: Sampling rate desired for the channel.
545 * adc_scale_fn: Scaling function to convert to the data meaningful for
546 * each individual channel whether it is voltage, current,
547 * temperature, etc and compensates the channel properties.
548 */
549struct qpnp_vadc_amux {
550 char *name;
551 enum qpnp_vadc_channels channel_num;
552 enum qpnp_adc_channel_scaling_param chan_path_prescaling;
553 enum qpnp_adc_decimation_type adc_decimation;
554 enum qpnp_adc_scale_fn_type adc_scale_fn;
555 enum qpnp_adc_fast_avg_ctl fast_avg_setup;
556 enum qpnp_adc_hw_settle_time hw_settle_time;
557};
558
559/**
560 * struct qpnp_vadc_scaling_ratio
561 *
562 */
563static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = {
564 {1, 1},
565 {1, 3},
566 {1, 4},
567 {1, 6},
568 {1, 20}
569};
570
571/**
572 * struct qpnp_vadc_scale_fn - Scaling function prototype
573 * @chan: Function pointer to one of the scaling functions
574 * which takes the adc properties, channel properties,
575 * and returns the physical result
576 */
577struct qpnp_vadc_scale_fn {
578 int32_t (*chan) (int32_t,
579 const struct qpnp_adc_properties *,
580 const struct qpnp_vadc_chan_properties *,
581 struct qpnp_vadc_result *);
582};
583
584/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700585 * struct qpnp_iadc_calib - IADC channel calibration structure.
586 * @channel - Channel for which the historical offset and gain is
587 * calculated. Available channels are internal rsense,
588 * external rsense and alternate lead pairs.
589 * @offset - Offset value for the channel.
590 * @gain - Gain of the channel.
591 */
592struct qpnp_iadc_calib {
593 enum qpnp_iadc_channels channel;
594 int32_t offset;
595 int32_t gain;
596};
597
598/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700599 * struct qpnp_adc_drv - QPNP ADC device structure.
600 * @spmi - spmi device for ADC peripheral.
601 * @offset - base offset for the ADC peripheral.
602 * @adc_prop - ADC properties specific to the ADC peripheral.
603 * @amux_prop - AMUX properties representing the ADC peripheral.
604 * @adc_channels - ADC channel properties for the ADC peripheral.
605 * @adc_irq - IRQ number that is mapped to the ADC peripheral.
606 * @adc_lock - ADC lock for access to the peripheral.
607 * @adc_rslt_completion - ADC result notification after interrupt
608 * is received.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700609 * @calib - Internal rsens calibration values for gain and offset.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700610 */
611struct qpnp_adc_drv {
612 struct spmi_device *spmi;
613 uint8_t slave;
614 uint16_t offset;
615 struct qpnp_adc_properties *adc_prop;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700616 struct qpnp_adc_amux_properties *amux_prop;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700617 struct qpnp_vadc_amux *adc_channels;
618 int adc_irq;
619 struct mutex adc_lock;
620 struct completion adc_rslt_completion;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700621 struct qpnp_iadc_calib calib;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700622};
623
624/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700625 * struct qpnp_adc_amux_properties - QPNP VADC amux channel property.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700626 * @amux_channel - Refer to the qpnp_vadc_channel list.
627 * @decimation - Sampling rate supported for the channel.
628 * @mode_sel - The basic mode of operation.
629 * @hw_settle_time - The time between AMUX being configured and the
630 * start of conversion.
631 * @fast_avg_setup - Ability to provide single result from the ADC
632 * that is an average of multiple measurements.
633 * @trigger_channel - HW trigger channel for conversion sequencer.
634 * @chan_prop - Represent the channel properties of the ADC.
635 */
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700636struct qpnp_adc_amux_properties {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700637 uint32_t amux_channel;
638 uint32_t decimation;
639 uint32_t mode_sel;
640 uint32_t hw_settle_time;
641 uint32_t fast_avg_setup;
642 enum qpnp_vadc_trigger trigger_channel;
643 struct qpnp_vadc_chan_properties chan_prop[0];
644};
645
646/* Public API */
647#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \
648 || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE)
649/**
650 * qpnp_vadc_read() - Performs ADC read on the channel.
651 * @channel: Input channel to perform the ADC read.
652 * @result: Structure pointer of type adc_chan_result
653 * in which the ADC read results are stored.
654 */
655int32_t qpnp_vadc_read(enum qpnp_vadc_channels channel,
656 struct qpnp_vadc_result *result);
657
658/**
659 * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion
660 * sequencer channel.
661 * @channel: Input channel to perform the ADC read.
662 * @result: Structure pointer of type adc_chan_result
663 * in which the ADC read results are stored.
664 */
665int32_t qpnp_vadc_conv_seq_request(
666 enum qpnp_vadc_trigger trigger_channel,
667 enum qpnp_vadc_channels channel,
668 struct qpnp_vadc_result *result);
669
670/**
671 * qpnp_vadc_check_result() - Performs check on the ADC raw code.
672 * @data: Data used for verifying the range of the ADC code.
673 */
674int32_t qpnp_vadc_check_result(int32_t *data);
675
676/**
677 * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data.
678 * @spmi: spmi ADC device.
679 * @adc_qpnp: spmi device tree node structure
680 */
681int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi,
682 struct qpnp_adc_drv *adc_qpnp);
683
684/**
685 * qpnp_vadc_configure() - Configure ADC device to start conversion.
686 * @chan_prop: Individual channel properties for the AMUX channel.
687 */
688int32_t qpnp_vadc_configure(
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700689 struct qpnp_adc_amux_properties *chan_prop);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700690
691/**
692 * qpnp_adc_scale_default() - Scales the pre-calibrated digital output
693 * of an ADC to the ADC reference and compensates for the
694 * gain and offset.
695 * @adc_code: pre-calibrated digital ouput of the ADC.
696 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
697 * reference voltage.
698 * @chan_prop: Individual channel properties to compensate the i/p scaling,
699 * slope and offset.
700 * @chan_rslt: Physical result to be stored.
701 */
702int32_t qpnp_adc_scale_default(int32_t adc_code,
703 const struct qpnp_adc_properties *adc_prop,
704 const struct qpnp_vadc_chan_properties *chan_prop,
705 struct qpnp_vadc_result *chan_rslt);
Siddartha Mohanadoss336d8b12012-08-20 23:18:10 -0700706/**
707 * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
708 * of an ADC to the ADC reference and compensates for the
709 * gain and offset. Performs the AMUX out as 2mV/K and returns
710 * the temperature in milli degC.
711 * @adc_code: pre-calibrated digital ouput of the ADC.
712 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
713 * reference voltage.
714 * @chan_prop: Individual channel properties to compensate the i/p scaling,
715 * slope and offset.
716 * @chan_rslt: Physical result to be stored.
717 */
718int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
719 const struct qpnp_adc_properties *adc_prop,
720 const struct qpnp_vadc_chan_properties *chan_prop,
721 struct qpnp_vadc_result *chan_rslt);
722/**
723 * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
724 * of an ADC to the ADC reference and compensates for the
725 * gain and offset. Returns the temperature in degC.
726 * @adc_code: pre-calibrated digital ouput of the ADC.
727 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
728 * reference voltage.
729 * @chan_prop: individual channel properties to compensate the i/p scaling,
730 * slope and offset.
731 * @chan_rslt: physical result to be stored.
732 */
733int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
734 const struct qpnp_adc_properties *adc_prop,
735 const struct qpnp_vadc_chan_properties *chan_prop,
736 struct qpnp_vadc_result *chan_rslt);
737/**
738 * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output
739 * of an ADC to the ADC reference and compensates for the
740 * gain and offset.
741 * @adc_code: pre-calibrated digital ouput of the ADC.
742 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
743 * reference voltage.
744 * @chan_prop: individual channel properties to compensate the i/p scaling,
745 * slope and offset.
746 * @chan_rslt: physical result to be stored.
747 */
748int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
749 const struct qpnp_adc_properties *adc_prop,
750 const struct qpnp_vadc_chan_properties *chan_prop,
751 struct qpnp_vadc_result *chan_rslt);
752/**
753 * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
754 * of an ADC to the ADC reference and compensates for the
755 * gain and offset. Returns the temperature of the xo therm in mili
756 degC.
757 * @adc_code: pre-calibrated digital ouput of the ADC.
758 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
759 * reference voltage.
760 * @chan_prop: individual channel properties to compensate the i/p scaling,
761 * slope and offset.
762 * @chan_rslt: physical result to be stored.
763 */
764int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
765 const struct qpnp_adc_properties *adc_prop,
766 const struct qpnp_vadc_chan_properties *chan_prop,
767 struct qpnp_vadc_result *chan_rslt);
768/**
769 * qpnp_vadc_is_ready() - Clients can use this API to check if the
770 * device is ready to use.
771 * @result: 0 on success and -EPROBE_DEFER when probe for the device
772 * has not occured.
773 */
774int32_t qpnp_vadc_is_ready(void);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700775#else
776static inline int32_t qpnp_vadc_read(uint32_t channel,
777 struct qpnp_vadc_result *result)
778{ return -ENXIO; }
779static inline int32_t qpnp_vadc_conv_seq_request(
780 enum qpnp_vadc_trigger trigger_channel,
781 enum qpnp_vadc_channels channel,
782 struct qpnp_vadc_result *result)
783{ return -ENXIO; }
784static inline int32_t qpnp_adc_scale_default(int32_t adc_code,
785 const struct qpnp_adc_properties *adc_prop,
Siddartha Mohanadoss336d8b12012-08-20 23:18:10 -0700786 const struct qpnp_vadc_chan_properties *chan_prop,
787 struct qpnp_vadc_result *chan_rslt)
788{ return -ENXIO; }
789static inline int32_t qpnp_adc_scale_pmic_therm(int32_t adc_code,
790 const struct qpnp_adc_properties *adc_prop,
791 const struct qpnp_vadc_chan_properties *chan_prop,
792 struct qpnp_vadc_result *chan_rslt)
793{ return -ENXIO; }
794static inline int32_t qpnp_adc_scale_batt_therm(int32_t adc_code,
795 const struct qpnp_adc_properties *adc_prop,
796 const struct qpnp_vadc_chan_properties *chan_prop,
797 struct qpnp_vadc_result *chan_rslt)
798{ return -ENXIO; }
799static inline int32_t qpnp_adc_scale_batt_id(int32_t adc_code,
800 const struct qpnp_adc_properties *adc_prop,
801 const struct qpnp_vadc_chan_properties *chan_prop,
802 struct qpnp_vadc_result *chan_rslt)
803{ return -ENXIO; }
804static inline int32_t qpnp_adc_tdkntcg_therm(int32_t adc_code,
805 const struct qpnp_adc_properties *adc_prop,
806 const struct qpnp_vadc_chan_properties *chan_prop,
807 struct qpnp_vadc_result *chan_rslt)
808{ return -ENXIO; }
809static inline int32_t qpnp_vadc_is_read(void)
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700810{ return -ENXIO; }
811#endif
812
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700813/* Public API */
814#if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \
815 || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE)
816/**
817 * qpnp_iadc_read() - Performs ADC read on the current channel.
818 * @channel: Input channel to perform the ADC read.
819 * @result: Current across rsens in mV.
820 */
821int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
822 int32_t *result);
823/**
824 * qpnp_iadc_get_gain() - Performs gain calibration over 25mV reference
825 * across CCADC.
826 * @result: Gain result across 25mV reference.
827 */
828int32_t qpnp_iadc_get_gain(int32_t *result);
829
830/**
831 * qpnp_iadc_get_offset() - Performs offset calibration over selected
832 * channel. Channel can be internal rsense,
833 * external rsense and alternate lead pair.
834 * @result: Gain result across 25mV reference.
835 */
836int32_t qpnp_iadc_get_offset(enum qpnp_iadc_channels channel,
837 int32_t *result);
Siddartha Mohanadoss336d8b12012-08-20 23:18:10 -0700838/**
839 * qpnp_iadc_is_ready() - Clients can use this API to check if the
840 * device is ready to use.
841 * @result: 0 on success and -EPROBE_DEFER when probe for the device
842 * has not occured.
843 */
844int32_t qpnp_iadc_is_ready(void);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700845#else
846static inline int32_t qpnp_iadc_read(enum qpnp_iadc_channels channel,
847 int *result)
848{ return -ENXIO; }
849static inline int32_t qpnp_iadc_get_gain(int32_t *result)
850{ return -ENXIO; }
851static inline int32_t qpnp_iadc_get_offset(enum qpnp_iadc_channels channel,
852 int32_t *result)
853{ return -ENXIO; }
Siddartha Mohanadoss336d8b12012-08-20 23:18:10 -0700854static inline int32_t qpnp_iadc_is_read(void)
855{ return -ENXIO; }
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700856#endif
857
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700858#endif