blob: 7ba4148cdccb929f63420cf6a7411020b6dccabe [file] [log] [blame]
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001/*
Dipen Parmar46f8ac62014-01-19 22:45:11 +05302 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13/*
14 * Qualcomm PMIC 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>
Siddartha Mohanadoss93761842013-09-11 17:46:54 -070023#include <linux/qpnp-revid.h>
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070024/**
25 * enum qpnp_vadc_channels - QPNP AMUX arbiter channels
26 */
27enum qpnp_vadc_channels {
28 USBIN = 0,
29 DCIN,
30 VCHG_SNS,
31 SPARE1_03,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080032 USB_ID_MV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070033 VCOIN,
34 VBAT_SNS,
35 VSYS,
36 DIE_TEMP,
37 REF_625MV,
38 REF_125V,
39 CHG_TEMP,
40 SPARE1,
41 SPARE2,
42 GND_REF,
43 VDD_VADC,
44 P_MUX1_1_1,
45 P_MUX2_1_1,
46 P_MUX3_1_1,
47 P_MUX4_1_1,
48 P_MUX5_1_1,
49 P_MUX6_1_1,
50 P_MUX7_1_1,
51 P_MUX8_1_1,
52 P_MUX9_1_1,
53 P_MUX10_1_1,
54 P_MUX11_1_1,
55 P_MUX12_1_1,
56 P_MUX13_1_1,
57 P_MUX14_1_1,
58 P_MUX15_1_1,
59 P_MUX16_1_1,
60 P_MUX1_1_3,
61 P_MUX2_1_3,
62 P_MUX3_1_3,
63 P_MUX4_1_3,
64 P_MUX5_1_3,
65 P_MUX6_1_3,
66 P_MUX7_1_3,
67 P_MUX8_1_3,
68 P_MUX9_1_3,
69 P_MUX10_1_3,
70 P_MUX11_1_3,
71 P_MUX12_1_3,
72 P_MUX13_1_3,
73 P_MUX14_1_3,
74 P_MUX15_1_3,
75 P_MUX16_1_3,
76 LR_MUX1_BATT_THERM,
77 LR_MUX2_BAT_ID,
78 LR_MUX3_XO_THERM,
79 LR_MUX4_AMUX_THM1,
80 LR_MUX5_AMUX_THM2,
81 LR_MUX6_AMUX_THM3,
82 LR_MUX7_HW_ID,
83 LR_MUX8_AMUX_THM4,
84 LR_MUX9_AMUX_THM5,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080085 LR_MUX10_USB_ID_LV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070086 AMUX_PU1,
87 AMUX_PU2,
88 LR_MUX3_BUF_XO_THERM_BUF,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080089 LR_MUX1_PU1_BAT_THERM = 112,
90 LR_MUX2_PU1_BAT_ID = 113,
91 LR_MUX3_PU1_XO_THERM = 114,
92 LR_MUX4_PU1_AMUX_THM1 = 115,
93 LR_MUX5_PU1_AMUX_THM2 = 116,
94 LR_MUX6_PU1_AMUX_THM3 = 117,
95 LR_MUX7_PU1_AMUX_HW_ID = 118,
96 LR_MUX8_PU1_AMUX_THM4 = 119,
97 LR_MUX9_PU1_AMUX_THM5 = 120,
98 LR_MUX10_PU1_AMUX_USB_ID_LV = 121,
99 LR_MUX3_BUF_PU1_XO_THERM_BUF = 124,
100 LR_MUX1_PU2_BAT_THERM = 176,
101 LR_MUX2_PU2_BAT_ID = 177,
102 LR_MUX3_PU2_XO_THERM = 178,
103 LR_MUX4_PU2_AMUX_THM1 = 179,
104 LR_MUX5_PU2_AMUX_THM2 = 180,
105 LR_MUX6_PU2_AMUX_THM3 = 181,
106 LR_MUX7_PU2_AMUX_HW_ID = 182,
107 LR_MUX8_PU2_AMUX_THM4 = 183,
108 LR_MUX9_PU2_AMUX_THM5 = 184,
109 LR_MUX10_PU2_AMUX_USB_ID_LV = 185,
110 LR_MUX3_BUF_PU2_XO_THERM_BUF = 188,
111 LR_MUX1_PU1_PU2_BAT_THERM = 240,
112 LR_MUX2_PU1_PU2_BAT_ID = 241,
113 LR_MUX3_PU1_PU2_XO_THERM = 242,
114 LR_MUX4_PU1_PU2_AMUX_THM1 = 243,
115 LR_MUX5_PU1_PU2_AMUX_THM2 = 244,
116 LR_MUX6_PU1_PU2_AMUX_THM3 = 245,
117 LR_MUX7_PU1_PU2_AMUX_HW_ID = 246,
118 LR_MUX8_PU1_PU2_AMUX_THM4 = 247,
119 LR_MUX9_PU1_PU2_AMUX_THM5 = 248,
120 LR_MUX10_PU1_PU2_AMUX_USB_ID_LV = 249,
121 LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF = 252,
122 ALL_OFF = 255,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700123 ADC_MAX_NUM,
124};
125
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700126/**
127 * enum qpnp_iadc_channels - QPNP IADC channel list
128 */
129enum qpnp_iadc_channels {
130 INTERNAL_RSENSE = 0,
131 EXTERNAL_RSENSE,
132 ALT_LEAD_PAIR,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700133 GAIN_CALIBRATION_17P857MV,
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700134 OFFSET_CALIBRATION_SHORT_CADC_LEADS,
135 OFFSET_CALIBRATION_CSP_CSN,
136 OFFSET_CALIBRATION_CSP2_CSN2,
137 IADC_MUX_NUM,
138};
139
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700140#define QPNP_ADC_625_UV 625000
Siddartha Mohanadoss1c218312012-11-08 11:30:43 -0800141#define QPNP_ADC_HWMON_NAME_LENGTH 64
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700142#define QPNP_MAX_PROP_NAME_LEN 32
143
144/* Structure device for qpnp vadc */
145struct qpnp_vadc_chip;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700146
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -0700147/* Structure device for qpnp iadc */
148struct qpnp_iadc_chip;
149
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -0700150/* Structure device for qpnp adc tm */
151struct qpnp_adc_tm_chip;
152
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700153/**
154 * enum qpnp_adc_decimation_type - Sampling rate supported.
155 * %DECIMATION_TYPE1: 512
156 * %DECIMATION_TYPE2: 1K
157 * %DECIMATION_TYPE3: 2K
158 * %DECIMATION_TYPE4: 4k
159 * %DECIMATION_NONE: Do not use this Sampling type.
160 *
161 * The Sampling rate is specific to each channel of the QPNP ADC arbiter.
162 */
163enum qpnp_adc_decimation_type {
164 DECIMATION_TYPE1 = 0,
165 DECIMATION_TYPE2,
166 DECIMATION_TYPE3,
167 DECIMATION_TYPE4,
168 DECIMATION_NONE,
169};
170
171/**
172 * enum qpnp_adc_calib_type - QPNP ADC Calibration type.
173 * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels.
174 * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND.
175 * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type.
176 *
177 * Use the input reference voltage depending on the calibration type
178 * to calcluate the offset and gain parameters. The calibration is
179 * specific to each channel of the QPNP ADC.
180 */
181enum qpnp_adc_calib_type {
182 CALIB_ABSOLUTE = 0,
183 CALIB_RATIOMETRIC,
184 CALIB_NONE,
185};
186
187/**
188 * enum qpnp_adc_channel_scaling_param - pre-scaling AMUX ratio.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700189 * %CHAN_PATH_SCALING0: ratio of {1, 1}
190 * %CHAN_PATH_SCALING1: ratio of {1, 3}
191 * %CHAN_PATH_SCALING2: ratio of {1, 4}
192 * %CHAN_PATH_SCALING3: ratio of {1, 6}
193 * %CHAN_PATH_SCALING4: ratio of {1, 20}
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530194 * %CHAN_PATH_SCALING5: ratio of {1, 8}
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700195 * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type.
196 *
197 * The pre-scaling is applied for signals to be within the voltage range
198 * of the ADC.
199 */
200enum qpnp_adc_channel_scaling_param {
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700201 PATH_SCALING0 = 0,
202 PATH_SCALING1,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700203 PATH_SCALING2,
204 PATH_SCALING3,
205 PATH_SCALING4,
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530206 PATH_SCALING5,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700207 PATH_SCALING_NONE,
208};
209
210/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800211 * enum qpnp_adc_scale_fn_type - Scaling function for pm8941 pre calibrated
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700212 * digital data relative to ADC reference.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700213 * %SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV).
214 * %SCALE_BATT_THERM: Conversion to temperature(decidegC) based on btm
215 * parameters.
216 * %SCALE_THERM_100K_PULLUP: Returns temperature in degC.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700217 * Uses a mapping table with 100K pullup.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700218 * %SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
219 * %SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade.
220 * %SCALE_THERM_150K_PULLUP: Returns temperature in degC.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700221 * Uses a mapping table with 150K pullup.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700222 * %SCALE_QRD_BATT_THERM: Conversion to temperature(decidegC) based on
223 * btm parameters.
Xu Kai81c60522013-07-27 14:26:04 +0800224 * %SCALE_QRD_SKUAA_BATT_THERM: Conversion to temperature(decidegC) based on
225 * btm parametersi for SKUAA.
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +0800226 * %SCALE_QRD_SKUG_BATT_THERM: Conversion to temperature(decidegC) based on
227 * btm parametersi for SKUG.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700228 * %SCALE_NONE: Do not use this scaling type.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700229 */
230enum qpnp_adc_scale_fn_type {
231 SCALE_DEFAULT = 0,
232 SCALE_BATT_THERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700233 SCALE_THERM_100K_PULLUP,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700234 SCALE_PMIC_THERM,
235 SCALE_XOTHERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700236 SCALE_THERM_150K_PULLUP,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700237 SCALE_QRD_BATT_THERM,
Xu Kai81c60522013-07-27 14:26:04 +0800238 SCALE_QRD_SKUAA_BATT_THERM,
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +0800239 SCALE_QRD_SKUG_BATT_THERM = 9,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700240 SCALE_NONE,
241};
242
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800243
244/**
245 * enum qpnp_adc_tm_rscale_fn_type - Scaling function used to convert the
246 * channels input voltage/temperature to corresponding ADC code that is
247 * applied for thresholds. Check the corresponding channels scaling to
248 * determine the appropriate temperature/voltage units that are passed
249 * to the scaling function. Example battery follows the power supply
250 * framework that needs its units to be in decidegreesC so it passes
251 * deci-degreesC. PA_THERM clients pass the temperature in degrees.
252 * The order below should match the one in the driver for
253 * adc_tm_rscale_fn[].
254 */
255enum qpnp_adc_tm_rscale_fn_type {
256 SCALE_R_VBATT = 0,
257 SCALE_RBATT_THERM,
258 SCALE_R_USB_ID,
259 SCALE_RPMIC_THERM,
260 SCALE_RSCALE_NONE,
261};
262
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700263/**
264 * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result
265 * from the ADC that is an average of multiple measurement
266 * samples. Select number of samples for use in fast
267 * average mode (i.e. 2 ^ value).
268 * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1
269 * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2
270 * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4
271 * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8
272 * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16
273 * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32
274 * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64
275 * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128
276 * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256
277 * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512
278 */
279enum qpnp_adc_fast_avg_ctl {
280 ADC_FAST_AVG_SAMPLE_1 = 0,
281 ADC_FAST_AVG_SAMPLE_2,
282 ADC_FAST_AVG_SAMPLE_4,
283 ADC_FAST_AVG_SAMPLE_8,
284 ADC_FAST_AVG_SAMPLE_16,
285 ADC_FAST_AVG_SAMPLE_32,
286 ADC_FAST_AVG_SAMPLE_64,
287 ADC_FAST_AVG_SAMPLE_128,
288 ADC_FAST_AVG_SAMPLE_256,
289 ADC_FAST_AVG_SAMPLE_512,
290 ADC_FAST_AVG_SAMPLE_NONE,
291};
292
293/**
294 * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and
295 * the ADC starting conversion. Delay = 100us * value for
296 * value < 11 and 2ms * (value - 10) otherwise.
297 * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us
298 * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us
299 * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us
300 * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us
301 * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us
302 * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us
303 * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us
304 * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us
305 * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us
306 * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us
307 * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms
308 * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms
309 * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms
310 * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms
311 * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms
312 * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms
313 * %ADC_CHANNEL_HW_SETTLE_NONE
314 */
315enum qpnp_adc_hw_settle_time {
316 ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0,
317 ADC_CHANNEL_HW_SETTLE_DELAY_100US,
318 ADC_CHANNEL_HW_SETTLE_DELAY_2000US,
319 ADC_CHANNEL_HW_SETTLE_DELAY_300US,
320 ADC_CHANNEL_HW_SETTLE_DELAY_400US,
321 ADC_CHANNEL_HW_SETTLE_DELAY_500US,
322 ADC_CHANNEL_HW_SETTLE_DELAY_600US,
323 ADC_CHANNEL_HW_SETTLE_DELAY_700US,
324 ADC_CHANNEL_HW_SETTLE_DELAY_800US,
325 ADC_CHANNEL_HW_SETTLE_DELAY_900US,
326 ADC_CHANNEL_HW_SETTLE_DELAY_1MS,
327 ADC_CHANNEL_HW_SETTLE_DELAY_2MS,
328 ADC_CHANNEL_HW_SETTLE_DELAY_4MS,
329 ADC_CHANNEL_HW_SETTLE_DELAY_6MS,
330 ADC_CHANNEL_HW_SETTLE_DELAY_8MS,
331 ADC_CHANNEL_HW_SETTLE_DELAY_10MS,
332 ADC_CHANNEL_HW_SETTLE_NONE,
333};
334
335/**
336 * enum qpnp_vadc_mode_sel - Selects the basic mode of operation.
337 * - The normal mode is used for single measurement.
338 * - The Conversion sequencer is used to trigger an
339 * ADC read when a HW trigger is selected.
340 * - The measurement interval performs a single or
341 * continous measurement at a specified interval/delay.
342 * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement.
343 * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger
344 * an ADC read on a HW supported trigger.
345 * Refer to enum qpnp_vadc_trigger for
346 * supported HW triggers.
347 * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a
348 * single or continous measurement after a specified delay.
349 * For delay look at qpnp_adc_meas_timer.
350 */
351enum qpnp_vadc_mode_sel {
352 ADC_OP_NORMAL_MODE = 0,
353 ADC_OP_CONVERSION_SEQUENCER,
354 ADC_OP_MEASUREMENT_INTERVAL,
355 ADC_OP_MODE_NONE,
356};
357
358/**
359 * enum qpnp_vadc_trigger - Select the HW trigger to be used while
360 * measuring the ADC reading.
361 * %ADC_GSM_PA_ON : GSM power amplifier on.
362 * %ADC_TX_GTR_THRES : Transmit power greater than threshold.
363 * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done.
364 * %ADC_DTEST : DTEST.
365 */
366enum qpnp_vadc_trigger {
367 ADC_GSM_PA_ON = 0,
368 ADC_TX_GTR_THRES,
369 ADC_CAMERA_FLASH_RAMP,
370 ADC_DTEST,
371 ADC_SEQ_NONE,
372};
373
374/**
375 * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from
376 * conversion request to triggering conversion sequencer
377 * hold off time.
378 */
379enum qpnp_vadc_conv_seq_timeout {
380 ADC_CONV_SEQ_TIMEOUT_0MS = 0,
381 ADC_CONV_SEQ_TIMEOUT_1MS,
382 ADC_CONV_SEQ_TIMEOUT_2MS,
383 ADC_CONV_SEQ_TIMEOUT_3MS,
384 ADC_CONV_SEQ_TIMEOUT_4MS,
385 ADC_CONV_SEQ_TIMEOUT_5MS,
386 ADC_CONV_SEQ_TIMEOUT_6MS,
387 ADC_CONV_SEQ_TIMEOUT_7MS,
388 ADC_CONV_SEQ_TIMEOUT_8MS,
389 ADC_CONV_SEQ_TIMEOUT_9MS,
390 ADC_CONV_SEQ_TIMEOUT_10MS,
391 ADC_CONV_SEQ_TIMEOUT_11MS,
392 ADC_CONV_SEQ_TIMEOUT_12MS,
393 ADC_CONV_SEQ_TIMEOUT_13MS,
394 ADC_CONV_SEQ_TIMEOUT_14MS,
395 ADC_CONV_SEQ_TIMEOUT_15MS,
396 ADC_CONV_SEQ_TIMEOUT_NONE,
397};
398
399/**
400 * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion
401 * trigger signal (i.e. adc_conv_seq_trig) transition
402 * to ADC enable. Delay = 25us * (value + 1).
403 */
404enum qpnp_adc_conv_seq_holdoff {
405 ADC_SEQ_HOLD_25US = 0,
406 ADC_SEQ_HOLD_50US,
407 ADC_SEQ_HOLD_75US,
408 ADC_SEQ_HOLD_100US,
409 ADC_SEQ_HOLD_125US,
410 ADC_SEQ_HOLD_150US,
411 ADC_SEQ_HOLD_175US,
412 ADC_SEQ_HOLD_200US,
413 ADC_SEQ_HOLD_225US,
414 ADC_SEQ_HOLD_250US,
415 ADC_SEQ_HOLD_275US,
416 ADC_SEQ_HOLD_300US,
417 ADC_SEQ_HOLD_325US,
418 ADC_SEQ_HOLD_350US,
419 ADC_SEQ_HOLD_375US,
420 ADC_SEQ_HOLD_400US,
421 ADC_SEQ_HOLD_NONE,
422};
423
424/**
425 * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state
426 * %ADC_CONV_SEQ_IDLE : Sequencer is in idle.
427 * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger.
428 * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time.
429 * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal.
430 * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge.
431 * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time.
432 * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal.
433 * %ADC_CONV_ERROR : Aberrant Hardware problem.
434 */
435enum qpnp_adc_conv_seq_state {
436 ADC_CONV_SEQ_IDLE = 0,
437 ADC_CONV_TRIG_RISE,
438 ADC_CONV_TRIG_HOLDOFF,
439 ADC_CONV_MEAS_RISE,
440 ADC_CONV_TRIG_FALL,
441 ADC_CONV_FALL_HOLDOFF,
442 ADC_CONV_MEAS_FALL,
443 ADC_CONV_ERROR,
444 ADC_CONV_NONE,
445};
446
447/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800448 * enum qpnp_adc_meas_timer_1 - Selects the measurement interval time.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700449 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800450 * The timer period is used by the USB_ID. 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.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700453 * %ADC_MEAS_INTERVAL_0MS : 0ms
454 * %ADC_MEAS_INTERVAL_1P0MS : 1ms
455 * %ADC_MEAS_INTERVAL_2P0MS : 2ms
456 * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms
457 * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms
458 * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms
459 * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms
460 * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms
461 * %ADC_MEAS_INTERVAL_125MS : 125ms
462 * %ADC_MEAS_INTERVAL_250MS : 250ms
463 * %ADC_MEAS_INTERVAL_500MS : 500ms
464 * %ADC_MEAS_INTERVAL_1S : 1seconds
465 * %ADC_MEAS_INTERVAL_2S : 2seconds
466 * %ADC_MEAS_INTERVAL_4S : 4seconds
467 * %ADC_MEAS_INTERVAL_8S : 8seconds
468 * %ADC_MEAS_INTERVAL_16S: 16seconds
469 */
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800470enum qpnp_adc_meas_timer_1 {
471 ADC_MEAS1_INTERVAL_0MS = 0,
472 ADC_MEAS1_INTERVAL_1P0MS,
473 ADC_MEAS1_INTERVAL_2P0MS,
474 ADC_MEAS1_INTERVAL_3P9MS,
475 ADC_MEAS1_INTERVAL_7P8MS,
476 ADC_MEAS1_INTERVAL_15P6MS,
477 ADC_MEAS1_INTERVAL_31P3MS,
478 ADC_MEAS1_INTERVAL_62P5MS,
479 ADC_MEAS1_INTERVAL_125MS,
480 ADC_MEAS1_INTERVAL_250MS,
481 ADC_MEAS1_INTERVAL_500MS,
482 ADC_MEAS1_INTERVAL_1S,
483 ADC_MEAS1_INTERVAL_2S,
484 ADC_MEAS1_INTERVAL_4S,
485 ADC_MEAS1_INTERVAL_8S,
486 ADC_MEAS1_INTERVAL_16S,
487 ADC_MEAS1_INTERVAL_NONE,
488};
489
490/**
491 * enum qpnp_adc_meas_timer_2 - Selects the measurement interval time.
492 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
493 * The timer period is used by the batt_therm. Do not set a polling rate
494 * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0
495 * appears to be limited to 1 second.
496 * %ADC_MEAS_INTERVAL_0MS : 0ms
497 * %ADC_MEAS_INTERVAL_100MS : 100ms
498 * %ADC_MEAS_INTERVAL_200MS : 200ms
499 * %ADC_MEAS_INTERVAL_300MS : 300ms
500 * %ADC_MEAS_INTERVAL_400MS : 400ms
501 * %ADC_MEAS_INTERVAL_500MS : 500ms
502 * %ADC_MEAS_INTERVAL_600MS : 600ms
503 * %ADC_MEAS_INTERVAL_700MS : 700ms
504 * %ADC_MEAS_INTERVAL_800MS : 800ms
505 * %ADC_MEAS_INTERVAL_900MS : 900ms
506 * %ADC_MEAS_INTERVAL_1S: 1seconds
507 * %ADC_MEAS_INTERVAL_1P1S: 1.1seconds
508 * %ADC_MEAS_INTERVAL_1P2S: 1.2seconds
509 * %ADC_MEAS_INTERVAL_1P3S: 1.3seconds
510 * %ADC_MEAS_INTERVAL_1P4S: 1.4seconds
511 * %ADC_MEAS_INTERVAL_1P5S: 1.5seconds
512 */
513enum qpnp_adc_meas_timer_2 {
514 ADC_MEAS2_INTERVAL_0MS = 0,
515 ADC_MEAS2_INTERVAL_100MS,
516 ADC_MEAS2_INTERVAL_200MS,
517 ADC_MEAS2_INTERVAL_300MS,
518 ADC_MEAS2_INTERVAL_400MS,
519 ADC_MEAS2_INTERVAL_500MS,
520 ADC_MEAS2_INTERVAL_600MS,
521 ADC_MEAS2_INTERVAL_700MS,
522 ADC_MEAS2_INTERVAL_800MS,
523 ADC_MEAS2_INTERVAL_900MS,
524 ADC_MEAS2_INTERVAL_1S,
525 ADC_MEAS2_INTERVAL_1P1S,
526 ADC_MEAS2_INTERVAL_1P2S,
527 ADC_MEAS2_INTERVAL_1P3S,
528 ADC_MEAS2_INTERVAL_1P4S,
529 ADC_MEAS2_INTERVAL_1P5S,
530 ADC_MEAS2_INTERVAL_NONE,
531};
532
533/**
534 * enum qpnp_adc_meas_timer_3 - Selects the measurement interval time.
535 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
536 * Do not set a polling rate greater than 1 second on PMIC 2.0.
537 * The max polling rate on the PMIC 2.0 appears to be limited to 1 second.
538 * %ADC_MEAS_INTERVAL_0MS : 0ms
539 * %ADC_MEAS_INTERVAL_1S : 1seconds
540 * %ADC_MEAS_INTERVAL_2S : 2seconds
541 * %ADC_MEAS_INTERVAL_3S : 3seconds
542 * %ADC_MEAS_INTERVAL_4S : 4seconds
543 * %ADC_MEAS_INTERVAL_5S : 5seconds
544 * %ADC_MEAS_INTERVAL_6S: 6seconds
545 * %ADC_MEAS_INTERVAL_7S : 7seconds
546 * %ADC_MEAS_INTERVAL_8S : 8seconds
547 * %ADC_MEAS_INTERVAL_9S : 9seconds
548 * %ADC_MEAS_INTERVAL_10S : 10seconds
549 * %ADC_MEAS_INTERVAL_11S : 11seconds
550 * %ADC_MEAS_INTERVAL_12S : 12seconds
551 * %ADC_MEAS_INTERVAL_13S : 13seconds
552 * %ADC_MEAS_INTERVAL_14S : 14seconds
553 * %ADC_MEAS_INTERVAL_15S : 15seconds
554 */
555enum qpnp_adc_meas_timer_3 {
556 ADC_MEAS3_INTERVAL_0S = 0,
557 ADC_MEAS3_INTERVAL_1S,
558 ADC_MEAS3_INTERVAL_2S,
559 ADC_MEAS3_INTERVAL_3S,
560 ADC_MEAS3_INTERVAL_4S,
561 ADC_MEAS3_INTERVAL_5S,
562 ADC_MEAS3_INTERVAL_6S,
563 ADC_MEAS3_INTERVAL_7S,
564 ADC_MEAS3_INTERVAL_8S,
565 ADC_MEAS3_INTERVAL_9S,
566 ADC_MEAS3_INTERVAL_10S,
567 ADC_MEAS3_INTERVAL_11S,
568 ADC_MEAS3_INTERVAL_12S,
569 ADC_MEAS3_INTERVAL_13S,
570 ADC_MEAS3_INTERVAL_14S,
571 ADC_MEAS3_INTERVAL_15S,
572 ADC_MEAS3_INTERVAL_NONE,
573};
574
575/**
576 * enum qpnp_adc_meas_timer_select - Selects the timer for which
577 * the appropriate polling frequency is set.
Siddartha Mohanadoss58ffe0e2014-02-11 17:40:13 -0800578 * %ADC_MEAS_TIMER_SELECT1 - Select this timer for measurement polling interval
579 * for 1 second.
580 * %ADC_MEAS_TIMER_SELECT2 - Select this timer for 500ms measurement interval.
581 * %ADC_MEAS_TIMER_SELECT3 - Select this timer for 5 second interval.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800582 */
583enum qpnp_adc_meas_timer_select {
584 ADC_MEAS_TIMER_SELECT1 = 0,
585 ADC_MEAS_TIMER_SELECT2,
586 ADC_MEAS_TIMER_SELECT3,
587 ADC_MEAS_TIMER_NUM,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700588};
589
590/**
591 * enum qpnp_adc_meas_interval_op_ctl - Select operating mode.
592 * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time
593 * delay.
594 * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval
595 * times.
596 */
597enum qpnp_adc_meas_interval_op_ctl {
598 ADC_MEAS_INTERVAL_OP_SINGLE = 0,
599 ADC_MEAS_INTERVAL_OP_CONTINUOUS,
600 ADC_MEAS_INTERVAL_OP_NONE,
601};
602
603/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800604 * Channel selection registers for each of the configurable measurements
605 * Channels allotment is set at device config for a channel.
606 * The USB_ID, BATT_THERM, PMIC_THERM and VBAT channels are used by the
607 * kernel space USB, Battery and IADC drivers.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800608 * The other 3 channels are configurable for use by userspace clients.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800609 */
610enum qpnp_adc_tm_channel_select {
611 QPNP_ADC_TM_M0_ADC_CH_SEL_CTL = 0x48,
612 QPNP_ADC_TM_M1_ADC_CH_SEL_CTL = 0x68,
613 QPNP_ADC_TM_M2_ADC_CH_SEL_CTL = 0x70,
614 QPNP_ADC_TM_M3_ADC_CH_SEL_CTL = 0x78,
615 QPNP_ADC_TM_M4_ADC_CH_SEL_CTL = 0x80,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800616 QPNP_ADC_TM_M5_ADC_CH_SEL_CTL = 0x88,
617 QPNP_ADC_TM_M6_ADC_CH_SEL_CTL = 0x90,
618 QPNP_ADC_TM_M7_ADC_CH_SEL_CTL = 0x98,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800619 QPNP_ADC_TM_CH_SELECT_NONE
620};
621
Siddartha Mohanadoss71a83442013-08-29 11:43:24 -0700622/**
623 * Channel index for the corresponding index to qpnp_adc_tm_channel_selec
624 */
625enum qpnp_adc_tm_channel_num {
626 QPNP_ADC_TM_CHAN0 = 0,
627 QPNP_ADC_TM_CHAN1,
628 QPNP_ADC_TM_CHAN2,
629 QPNP_ADC_TM_CHAN3,
630 QPNP_ADC_TM_CHAN4,
631 QPNP_ADC_TM_CHAN5,
632 QPNP_ADC_TM_CHAN6,
633 QPNP_ADC_TM_CHAN7,
634 QPNP_ADC_TM_CHAN_NONE
635};
636
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -0700637enum qpnp_comp_scheme_type {
638 COMP_ID_GF = 0,
639 COMP_ID_SMIC,
640 COMP_ID_TSMC,
641 COMP_ID_NUM,
642};
643
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800644/**
645 * struct qpnp_adc_tm_config - Represent ADC Thermal Monitor configuration.
646 * @channel: ADC channel for which thermal monitoring is requested.
647 * @adc_code: The pre-calibrated digital output of a given ADC releative to the
648 * ADC reference.
649 * @high_thr_temp: Temperature at which high threshold notification is required.
650 * @low_thr_temp: Temperature at which low threshold notification is required.
651 * @low_thr_voltage : Low threshold voltage ADC code used for reverse
652 * calibration.
653 * @high_thr_voltage: High threshold voltage ADC code used for reverse
654 * calibration.
655 */
656struct qpnp_adc_tm_config {
657 int channel;
658 int adc_code;
659 int high_thr_temp;
660 int low_thr_temp;
661 int64_t high_thr_voltage;
662 int64_t low_thr_voltage;
663};
664
665/**
666 * enum qpnp_adc_tm_trip_type - Type for setting high/low temperature/voltage.
667 * %ADC_TM_TRIP_HIGH_WARM: Setting high temperature. Note that high temperature
668 * corresponds to low voltage. Driver handles this case
669 * appropriately to set high/low thresholds for voltage.
670 * threshold.
671 * %ADC_TM_TRIP_LOW_COOL: Setting low temperature.
672 */
673enum qpnp_adc_tm_trip_type {
674 ADC_TM_TRIP_HIGH_WARM = 0,
675 ADC_TM_TRIP_LOW_COOL,
676 ADC_TM_TRIP_NUM,
677};
678
679/**
680 * enum qpnp_tm_state - This lets the client know whether the threshold
681 * that was crossed was high/low.
682 * %ADC_TM_HIGH_STATE: Client is notified of crossing the requested high
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700683 * voltage threshold.
684 * %ADC_TM_COOL_STATE: Client is notified of crossing the requested cool
685 * temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800686 * %ADC_TM_LOW_STATE: Client is notified of crossing the requested low
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700687 * voltage threshold.
688 * %ADC_TM_WARM_STATE: Client is notified of crossing the requested high
689 * temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800690 */
691enum qpnp_tm_state {
692 ADC_TM_HIGH_STATE = 0,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700693 ADC_TM_COOL_STATE = ADC_TM_HIGH_STATE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800694 ADC_TM_LOW_STATE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700695 ADC_TM_WARM_STATE = ADC_TM_LOW_STATE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800696 ADC_TM_STATE_NUM,
697};
698
699/**
700 * enum qpnp_state_request - Request to enable/disable the corresponding
701 * high/low voltage/temperature thresholds.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700702 * %ADC_TM_HIGH_THR_ENABLE: Enable high voltage threshold.
703 * %ADC_TM_COOL_THR_ENABLE = Enables cool temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800704 * %ADC_TM_LOW_THR_ENABLE: Enable low voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700705 * %ADC_TM_WARM_THR_ENABLE = Enables warm temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800706 * %ADC_TM_HIGH_LOW_THR_ENABLE: Enable high and low voltage/temperature
707 * threshold.
708 * %ADC_TM_HIGH_THR_DISABLE: Disable high voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700709 * %ADC_TM_COOL_THR_ENABLE = Disables cool temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800710 * %ADC_TM_LOW_THR_DISABLE: Disable low voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700711 * %ADC_TM_WARM_THR_ENABLE = Disables warm temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800712 * %ADC_TM_HIGH_THR_DISABLE: Disable high and low voltage/temperature
713 * threshold.
714 */
715enum qpnp_state_request {
716 ADC_TM_HIGH_THR_ENABLE = 0,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700717 ADC_TM_COOL_THR_ENABLE = ADC_TM_HIGH_THR_ENABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800718 ADC_TM_LOW_THR_ENABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700719 ADC_TM_WARM_THR_ENABLE = ADC_TM_LOW_THR_ENABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800720 ADC_TM_HIGH_LOW_THR_ENABLE,
721 ADC_TM_HIGH_THR_DISABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700722 ADC_TM_COOL_THR_DISABLE = ADC_TM_HIGH_THR_DISABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800723 ADC_TM_LOW_THR_DISABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700724 ADC_TM_WARM_THR_DISABLE = ADC_TM_LOW_THR_DISABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800725 ADC_TM_HIGH_LOW_THR_DISABLE,
726 ADC_TM_THR_NUM,
727};
728
729/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800730 * struct qpnp_adc_tm_btm_param - Represent Battery temperature threshold
731 * monitoring configuration.
732 * @high_temp: High temperature threshold for which notification is requested.
733 * @low_temp: Low temperature threshold for which notification is requested.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800734 * @high_thr_voltage: High voltage for which notification is requested.
735 * @low_thr_voltage: Low voltage for which notification is requested.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800736 * @state_request: Enable/disable the corresponding high and low temperature
737 * thresholds.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800738 * @timer_interval1: Select polling rate from qpnp_adc_meas_timer_1 type.
739 * @timer_interval2: Select polling rate from qpnp_adc_meas_timer_2 type.
740 * @timer_interval3: Select polling rate from qpnp_adc_meas_timer_3 type.
Siddartha Mohanadossd71e2402013-02-01 17:36:23 -0800741 * @btmid_ctx: A context of void type.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800742 * @threshold_notification: Notification callback once threshold are crossed.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800743 * units to be used for High/Low temperature and voltage notification -
744 * This depends on the clients usage. Check the rscaling function
745 * for the appropriate channel nodes.
746 * @Batt therm clients temperature units is decidegreesCentigrate.
747 * @USB_ID inputs the voltage units in milli-volts.
748 * @PA_THERM inputs the units in degC.
749 * @PMIC_THERM inputs the units in millidegC.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800750 */
751struct qpnp_adc_tm_btm_param {
752 int32_t high_temp;
753 int32_t low_temp;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800754 int32_t high_thr;
755 int32_t low_thr;
756 enum qpnp_vadc_channels channel;
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800757 enum qpnp_state_request state_request;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800758 enum qpnp_adc_meas_timer_1 timer_interval;
759 enum qpnp_adc_meas_timer_2 timer_interval2;
760 enum qpnp_adc_meas_timer_3 timer_interval3;
Siddartha Mohanadossd71e2402013-02-01 17:36:23 -0800761 void *btm_ctx;
762 void (*threshold_notification) (enum qpnp_tm_state state,
763 void *ctx);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800764};
765
766/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700767 * struct qpnp_vadc_linear_graph - Represent ADC characteristics.
768 * @dy: Numerator slope to calculate the gain.
769 * @dx: Denominator slope to calculate the gain.
770 * @adc_vref: A/D word of the voltage reference used for the channel.
771 * @adc_gnd: A/D word of the ground reference used for the channel.
772 *
773 * Each ADC device has different offset and gain parameters which are computed
774 * to calibrate the device.
775 */
776struct qpnp_vadc_linear_graph {
777 int64_t dy;
778 int64_t dx;
779 int64_t adc_vref;
780 int64_t adc_gnd;
781};
782
783/**
784 * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel
785 * @x: Represent the ADC digitized code.
786 * @y: Represent the physical data which can be temperature, voltage,
787 * resistance.
788 */
789struct qpnp_vadc_map_pt {
790 int32_t x;
791 int32_t y;
792};
793
794/**
795 * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input.
796 * @num: Numerator scaling parameter.
797 * @den: Denominator scaling parameter.
798 */
799struct qpnp_vadc_scaling_ratio {
800 int32_t num;
801 int32_t den;
802};
803
804/**
805 * struct qpnp_adc_properties - Represent the ADC properties.
806 * @adc_reference: Reference voltage for QPNP ADC.
807 * @bitresolution: ADC bit resolution for QPNP ADC.
808 * @biploar: Polarity for QPNP ADC.
809 */
810struct qpnp_adc_properties {
811 uint32_t adc_vdd_reference;
812 uint32_t bitresolution;
813 bool bipolar;
814};
815
816/**
817 * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC.
818 * @offset_gain_numerator: The inverse numerator of the gain applied to the
819 * input channel.
820 * @offset_gain_denominator: The inverse denominator of the gain applied to the
821 * input channel.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800822 * @high_thr: High threshold voltage that is requested to be set.
823 * @low_thr: Low threshold voltage that is requested to be set.
824 * @timer_select: Choosen from one of the 3 timers to set the polling rate for
825 * the VADC_BTM channel.
826 * @meas_interval1: Polling rate to set for timer 1.
827 * @meas_interval2: Polling rate to set for timer 2.
828 * @tm_channel_select: BTM channel number for the 5 VADC_BTM channels.
829 * @state_request: User can select either enable or disable high/low or both
830 * activation levels based on the qpnp_state_request type.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700831 * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph.
832 */
833struct qpnp_vadc_chan_properties {
834 uint32_t offset_gain_numerator;
835 uint32_t offset_gain_denominator;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800836 uint32_t high_thr;
837 uint32_t low_thr;
838 enum qpnp_adc_meas_timer_select timer_select;
839 enum qpnp_adc_meas_timer_1 meas_interval1;
840 enum qpnp_adc_meas_timer_2 meas_interval2;
841 enum qpnp_adc_tm_channel_select tm_channel_select;
842 enum qpnp_state_request state_request;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700843 struct qpnp_vadc_linear_graph adc_graph[2];
844};
845
846/**
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800847 * struct qpnp_vadc_result - Represent the result of the QPNP ADC.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700848 * @chan: The channel number of the requested conversion.
849 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
850 * the ADC reference.
851 * @measurement: In units specific for a given ADC; most ADC uses reference
852 * voltage but some ADC uses reference current. This measurement
853 * here is a number relative to a reference of a given ADC.
854 * @physical: The data meaningful for each individual channel whether it is
855 * voltage, current, temperature, etc.
856 * All voltage units are represented in micro - volts.
857 * -Battery temperature units are represented as 0.1 DegC.
858 * -PA Therm temperature units are represented as DegC.
859 * -PMIC Die temperature units are represented as 0.001 DegC.
860 */
861struct qpnp_vadc_result {
862 uint32_t chan;
863 int32_t adc_code;
864 int64_t measurement;
865 int64_t physical;
866};
867
868/**
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800869 * struct qpnp_adc_amux - AMUX properties for individual channel
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700870 * @name: Channel string name.
871 * @channel_num: Channel in integer used from qpnp_adc_channels.
872 * @chan_path_prescaling: Channel scaling performed on the input signal.
873 * @adc_decimation: Sampling rate desired for the channel.
874 * adc_scale_fn: Scaling function to convert to the data meaningful for
875 * each individual channel whether it is voltage, current,
876 * temperature, etc and compensates the channel properties.
877 */
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800878struct qpnp_adc_amux {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700879 char *name;
880 enum qpnp_vadc_channels channel_num;
881 enum qpnp_adc_channel_scaling_param chan_path_prescaling;
882 enum qpnp_adc_decimation_type adc_decimation;
883 enum qpnp_adc_scale_fn_type adc_scale_fn;
884 enum qpnp_adc_fast_avg_ctl fast_avg_setup;
885 enum qpnp_adc_hw_settle_time hw_settle_time;
886};
887
888/**
889 * struct qpnp_vadc_scaling_ratio
890 *
891 */
892static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = {
893 {1, 1},
894 {1, 3},
895 {1, 4},
896 {1, 6},
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530897 {1, 20},
898 {1, 8}
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700899};
900
901/**
902 * struct qpnp_vadc_scale_fn - Scaling function prototype
903 * @chan: Function pointer to one of the scaling functions
904 * which takes the adc properties, channel properties,
905 * and returns the physical result
906 */
907struct qpnp_vadc_scale_fn {
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700908 int32_t (*chan) (struct qpnp_vadc_chip *, int32_t,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700909 const struct qpnp_adc_properties *,
910 const struct qpnp_vadc_chan_properties *,
911 struct qpnp_vadc_result *);
912};
913
914/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800915 * struct qpnp_adc_tm_reverse_scale_fn - Reverse scaling prototype
916 * @chan: Function pointer to one of the scaling functions
917 * which takes the adc properties, channel properties,
918 * and returns the physical result
919 */
920struct qpnp_adc_tm_reverse_scale_fn {
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700921 int32_t (*chan) (struct qpnp_vadc_chip *,
922 struct qpnp_adc_tm_btm_param *,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800923 uint32_t *, uint32_t *);
924};
925
926/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700927 * struct qpnp_iadc_calib - IADC channel calibration structure.
928 * @channel - Channel for which the historical offset and gain is
929 * calculated. Available channels are internal rsense,
930 * external rsense and alternate lead pairs.
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700931 * @offset_raw - raw Offset value for the channel.
932 * @gain_raw - raw Gain of the channel.
933 * @ideal_offset_uv - ideal offset value for the channel.
934 * @ideal_gain_nv - ideal gain for the channel.
935 * @offset_uv - converted value of offset in uV.
936 * @gain_uv - converted value of gain in uV.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700937 */
938struct qpnp_iadc_calib {
939 enum qpnp_iadc_channels channel;
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700940 uint16_t offset_raw;
941 uint16_t gain_raw;
942 uint32_t ideal_offset_uv;
943 uint32_t ideal_gain_nv;
944 uint32_t offset_uv;
945 uint32_t gain_uv;
946};
947
948/**
949 * struct qpnp_iadc_result - IADC read result structure.
950 * @oresult_uv - Result of ADC in uV.
951 * @result_ua - Result of ADC in uA.
952 */
953struct qpnp_iadc_result {
954 int32_t result_uv;
955 int32_t result_ua;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700956};
957
958/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700959 * struct qpnp_adc_drv - QPNP ADC device structure.
960 * @spmi - spmi device for ADC peripheral.
961 * @offset - base offset for the ADC peripheral.
962 * @adc_prop - ADC properties specific to the ADC peripheral.
963 * @amux_prop - AMUX properties representing the ADC peripheral.
964 * @adc_channels - ADC channel properties for the ADC peripheral.
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800965 * @adc_irq_eoc - End of Conversion IRQ.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800966 * @adc_irq_fifo_not_empty - Conversion sequencer request written
967 * to FIFO when not empty.
968 * @adc_irq_conv_seq_timeout - Conversion sequencer trigger timeout.
969 * @adc_high_thr_irq - Output higher than high threshold set for measurement.
970 * @adc_low_thr_irq - Output lower than low threshold set for measurement.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700971 * @adc_lock - ADC lock for access to the peripheral.
972 * @adc_rslt_completion - ADC result notification after interrupt
973 * is received.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700974 * @calib - Internal rsens calibration values for gain and offset.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700975 */
976struct qpnp_adc_drv {
977 struct spmi_device *spmi;
978 uint8_t slave;
979 uint16_t offset;
980 struct qpnp_adc_properties *adc_prop;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700981 struct qpnp_adc_amux_properties *amux_prop;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800982 struct qpnp_adc_amux *adc_channels;
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800983 int adc_irq_eoc;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800984 int adc_irq_fifo_not_empty;
985 int adc_irq_conv_seq_timeout;
986 int adc_high_thr_irq;
987 int adc_low_thr_irq;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700988 struct mutex adc_lock;
989 struct completion adc_rslt_completion;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700990 struct qpnp_iadc_calib calib;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700991};
992
993/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700994 * struct qpnp_adc_amux_properties - QPNP VADC amux channel property.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700995 * @amux_channel - Refer to the qpnp_vadc_channel list.
996 * @decimation - Sampling rate supported for the channel.
997 * @mode_sel - The basic mode of operation.
998 * @hw_settle_time - The time between AMUX being configured and the
999 * start of conversion.
1000 * @fast_avg_setup - Ability to provide single result from the ADC
1001 * that is an average of multiple measurements.
1002 * @trigger_channel - HW trigger channel for conversion sequencer.
1003 * @chan_prop - Represent the channel properties of the ADC.
1004 */
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001005struct qpnp_adc_amux_properties {
Siddartha Mohanadoss93761842013-09-11 17:46:54 -07001006 uint32_t amux_channel;
1007 uint32_t decimation;
1008 uint32_t mode_sel;
1009 uint32_t hw_settle_time;
1010 uint32_t fast_avg_setup;
1011 enum qpnp_vadc_trigger trigger_channel;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001012 struct qpnp_vadc_chan_properties chan_prop[0];
1013};
1014
Siddartha Mohanadoss93761842013-09-11 17:46:54 -07001015/* SW index's for PMIC type and version used by QPNP VADC and IADC */
1016#define QPNP_REV_ID_8941_3_1 1
1017#define QPNP_REV_ID_8026_1_0 2
1018#define QPNP_REV_ID_8026_2_0 3
1019#define QPNP_REV_ID_8110_1_0 4
1020#define QPNP_REV_ID_8026_2_1 5
Xiaozhe Shi80754222013-10-30 14:11:41 -07001021#define QPNP_REV_ID_8110_2_0 6
Siddartha Mohanadoss68b4e082014-01-28 10:53:13 -08001022#define QPNP_REV_ID_8026_2_2 7
Siddartha Mohanadoss8b076be2014-03-11 19:03:03 -07001023#define QPNP_REV_ID_8941_3_0 8
1024#define QPNP_REV_ID_8941_2_0 9
1025
Siddartha Mohanadoss93761842013-09-11 17:46:54 -07001026
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001027/* Public API */
1028#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \
1029 || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE)
1030/**
1031 * qpnp_vadc_read() - Performs ADC read on the channel.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001032 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001033 * @channel: Input channel to perform the ADC read.
1034 * @result: Structure pointer of type adc_chan_result
1035 * in which the ADC read results are stored.
1036 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001037int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev,
1038 enum qpnp_vadc_channels channel,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001039 struct qpnp_vadc_result *result);
1040
1041/**
1042 * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion
1043 * sequencer channel.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001044 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001045 * @channel: Input channel to perform the ADC read.
1046 * @result: Structure pointer of type adc_chan_result
1047 * in which the ADC read results are stored.
1048 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001049int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001050 enum qpnp_vadc_trigger trigger_channel,
1051 enum qpnp_vadc_channels channel,
1052 struct qpnp_vadc_result *result);
1053
1054/**
1055 * qpnp_vadc_check_result() - Performs check on the ADC raw code.
1056 * @data: Data used for verifying the range of the ADC code.
1057 */
1058int32_t qpnp_vadc_check_result(int32_t *data);
1059
1060/**
1061 * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data.
1062 * @spmi: spmi ADC device.
1063 * @adc_qpnp: spmi device tree node structure
1064 */
1065int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi,
1066 struct qpnp_adc_drv *adc_qpnp);
1067
1068/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001069 * qpnp_adc_scale_default() - Scales the pre-calibrated digital output
1070 * of an ADC to the ADC reference and compensates for the
1071 * gain and offset.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001072 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001073 * @adc_code: pre-calibrated digital ouput of the ADC.
1074 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
1075 * reference voltage.
1076 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1077 * slope and offset.
1078 * @chan_rslt: Physical result to be stored.
1079 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001080int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *dev,
1081 int32_t adc_code,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001082 const struct qpnp_adc_properties *adc_prop,
1083 const struct qpnp_vadc_chan_properties *chan_prop,
1084 struct qpnp_vadc_result *chan_rslt);
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001085/**
1086 * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
1087 * of an ADC to the ADC reference and compensates for the
1088 * gain and offset. Performs the AMUX out as 2mV/K and returns
1089 * the temperature in milli degC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001090 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001091 * @adc_code: pre-calibrated digital ouput of the ADC.
1092 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
1093 * reference voltage.
1094 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1095 * slope and offset.
1096 * @chan_rslt: Physical result to be stored.
1097 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001098int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *dev,
1099 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001100 const struct qpnp_adc_properties *adc_prop,
1101 const struct qpnp_vadc_chan_properties *chan_prop,
1102 struct qpnp_vadc_result *chan_rslt);
1103/**
1104 * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
1105 * of an ADC to the ADC reference and compensates for the
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001106 * gain and offset. Returns the temperature in decidegC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001107 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001108 * @adc_code: pre-calibrated digital ouput of the ADC.
1109 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1110 * reference voltage.
1111 * @chan_prop: individual channel properties to compensate the i/p scaling,
1112 * slope and offset.
1113 * @chan_rslt: physical result to be stored.
1114 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001115int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *dev,
1116 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001117 const struct qpnp_adc_properties *adc_prop,
1118 const struct qpnp_vadc_chan_properties *chan_prop,
1119 struct qpnp_vadc_result *chan_rslt);
1120/**
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001121 * qpnp_adc_scale_qrd_batt_therm() - Scales the pre-calibrated digital output
1122 * of an ADC to the ADC reference and compensates for the
1123 * gain and offset. Returns the temperature in decidegC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001124 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001125 * @adc_code: pre-calibrated digital ouput of the ADC.
1126 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1127 * reference voltage.
1128 * @chan_prop: individual channel properties to compensate the i/p scaling,
1129 * slope and offset.
1130 * @chan_rslt: physical result to be stored.
1131 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001132int32_t qpnp_adc_scale_qrd_batt_therm(struct qpnp_vadc_chip *dev,
1133 int32_t adc_code,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001134 const struct qpnp_adc_properties *adc_prop,
1135 const struct qpnp_vadc_chan_properties *chan_prop,
1136 struct qpnp_vadc_result *chan_rslt);
1137/**
Xu Kai81c60522013-07-27 14:26:04 +08001138 * qpnp_adc_scale_qrd_skuaa_batt_therm() - Scales the pre-calibrated digital output
1139 * of an ADC to the ADC reference and compensates for the
1140 * gain and offset. Returns the temperature in decidegC.
1141 * @dev: Structure device for qpnp vadc
1142 * @adc_code: pre-calibrated digital ouput of the ADC.
1143 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1144 * reference voltage.
1145 * @chan_prop: individual channel properties to compensate the i/p scaling,
1146 * slope and offset.
1147 * @chan_rslt: physical result to be stored.
1148 */
1149int32_t qpnp_adc_scale_qrd_skuaa_batt_therm(struct qpnp_vadc_chip *dev,
1150 int32_t adc_code,
1151 const struct qpnp_adc_properties *adc_prop,
1152 const struct qpnp_vadc_chan_properties *chan_prop,
1153 struct qpnp_vadc_result *chan_rslt);
1154/**
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +08001155 * qpnp_adc_scale_qrd_skug_batt_therm() - Scales the pre-calibrated digital output
1156 * of an ADC to the ADC reference and compensates for the
1157 * gain and offset. Returns the temperature in decidegC.
1158 * @dev: Structure device for qpnp vadc
1159 * @adc_code: pre-calibrated digital ouput of the ADC.
1160 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1161 * reference voltage.
1162 * @chan_prop: individual channel properties to compensate the i/p scaling,
1163 * slope and offset.
1164 * @chan_rslt: physical result to be stored.
1165 */
1166int32_t qpnp_adc_scale_qrd_skug_batt_therm(struct qpnp_vadc_chip *dev,
1167 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/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001172 * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output
1173 * of an ADC to the ADC reference and compensates for the
1174 * gain and offset.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001175 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001176 * @adc_code: pre-calibrated digital ouput of the ADC.
1177 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1178 * reference voltage.
1179 * @chan_prop: individual channel properties to compensate the i/p scaling,
1180 * slope and offset.
1181 * @chan_rslt: physical result to be stored.
1182 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001183int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001184 const struct qpnp_adc_properties *adc_prop,
1185 const struct qpnp_vadc_chan_properties *chan_prop,
1186 struct qpnp_vadc_result *chan_rslt);
1187/**
1188 * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
1189 * of an ADC to the ADC reference and compensates for the
1190 * gain and offset. Returns the temperature of the xo therm in mili
1191 degC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001192 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001193 * @adc_code: pre-calibrated digital ouput of the ADC.
1194 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1195 * reference voltage.
1196 * @chan_prop: individual channel properties to compensate the i/p scaling,
1197 * slope and offset.
1198 * @chan_rslt: physical result to be stored.
1199 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001200int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001201 const struct qpnp_adc_properties *adc_prop,
1202 const struct qpnp_vadc_chan_properties *chan_prop,
1203 struct qpnp_vadc_result *chan_rslt);
1204/**
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001205 * qpnp_adc_scale_therm_pu1() - Scales the pre-calibrated digital output
1206 * of an ADC to the ADC reference and compensates for the
1207 * gain and offset. Returns the temperature of the therm in degC.
1208 * It uses a mapping table computed for a 150K pull-up.
1209 * Pull-up1 is an internal pull-up on the AMUX of 150K.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001210 * @dev: Structure device for qpnp vadc
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001211 * @adc_code: pre-calibrated digital ouput of the ADC.
1212 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1213 * reference voltage.
1214 * @chan_prop: individual channel properties to compensate the i/p scaling,
1215 * slope and offset.
1216 * @chan_rslt: physical result to be stored.
1217 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001218int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001219 const struct qpnp_adc_properties *adc_prop,
1220 const struct qpnp_vadc_chan_properties *chan_prop,
1221 struct qpnp_vadc_result *chan_rslt);
1222/**
1223 * qpnp_adc_scale_therm_pu2() - Scales the pre-calibrated digital output
1224 * of an ADC to the ADC reference and compensates for the
1225 * gain and offset. Returns the temperature of the therm in degC.
1226 * It uses a mapping table computed for a 100K pull-up.
1227 * Pull-up2 is an internal pull-up on the AMUX of 100K.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001228 * @dev: Structure device for qpnp vadc
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001229 * @adc_code: pre-calibrated digital ouput of the ADC.
1230 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1231 * reference voltage.
1232 * @chan_prop: individual channel properties to compensate the i/p scaling,
1233 * slope and offset.
1234 * @chan_rslt: physical result to be stored.
1235 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001236int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001237 const struct qpnp_adc_properties *adc_prop,
1238 const struct qpnp_vadc_chan_properties *chan_prop,
1239 struct qpnp_vadc_result *chan_rslt);
1240/**
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001241 * qpnp_get_vadc() - Clients need to register with the vadc using the
1242 * corresponding device instance it wants to read the channels
1243 * from. Read the bindings document on how to pass the phandle
1244 * for the corresponding vadc driver to register with.
1245 * @dev: Clients device structure
1246 * @name: Corresponding client's DT parser name. Read the DT bindings
1247 * document on how to register with the vadc
1248 * @struct qpnp_vadc_chip * - On success returns the vadc device structure
1249 * pointer that needs to be used during an ADC request.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001250 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001251struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev, const char *name);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001252/**
1253 * qpnp_adc_tm_scaler() - Performs reverse calibration.
1254 * @config: Thermal monitoring configuration.
1255 * @adc_prop: adc properties of the qpnp adc such as bit resolution and
1256 * reference voltage.
1257 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1258 * slope and offset.
1259 */
1260static inline int32_t qpnp_adc_tm_scaler(struct qpnp_adc_tm_config *tm_config,
1261 const struct qpnp_adc_properties *adc_prop,
1262 const struct qpnp_vadc_chan_properties *chan_prop)
1263{ return -ENXIO; }
1264/**
1265 * qpnp_get_vadc_gain_and_offset() - Obtains the VADC gain and offset
1266 * for absolute and ratiometric calibration.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001267 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001268 * @param: The result in which the ADC offset and gain values are stored.
1269 * @type: The calibration type whether client needs the absolute or
1270 * ratiometric gain and offset values.
1271 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001272int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev,
1273 struct qpnp_vadc_linear_graph *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001274 enum qpnp_adc_calib_type calib_type);
1275/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001276 * qpnp_adc_scale_millidegc_pmic_voltage_thr() - Performs reverse calibration
1277 * on the low/high temperature threshold values passed by the
1278 * client. The function coverts milldegC to voltage threshold
1279 * and accounts for the corresponding channels scaling as (2mV/K).
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001280 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001281 * @param: The input parameters that contain the low/high temperature
1282 * values.
1283 * @low_threshold: The low threshold value that needs to be updated with
1284 * the above calibrated voltage value.
1285 * @high_threshold: The low threshold value that needs to be updated with
1286 * the above calibrated voltage value.
1287 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001288int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001289 struct qpnp_adc_tm_btm_param *param,
1290 uint32_t *low_threshold, uint32_t *high_threshold);
1291/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001292 * qpnp_adc_btm_scaler() - Performs reverse calibration on the low/high
1293 * temperature threshold values passed by the client.
1294 * The function maps the temperature to voltage and applies
1295 * ratiometric calibration on the voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001296 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001297 * @param: The input parameters that contain the low/high temperature
1298 * values.
1299 * @low_threshold: The low threshold value that needs to be updated with
1300 * the above calibrated voltage value.
1301 * @high_threshold: The low threshold value that needs to be updated with
1302 * the above calibrated voltage value.
1303 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001304int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev,
1305 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001306 uint32_t *low_threshold, uint32_t *high_threshold);
1307/**
1308 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1309 * and convert given temperature to voltage on supported
1310 * thermistor channels using 100k pull-up.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001311 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001312 * @param: The input temperature values.
1313 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001314int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_vadc_chip *dev,
1315 struct qpnp_adc_tm_config *param);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001316/**
1317 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1318 * and converts the given ADC code to temperature for
1319 * thermistor channels using 100k pull-up.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001320 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001321 * @reg: The input ADC code.
1322 * @result: The physical measurement temperature on the thermistor.
1323 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001324int32_t qpnp_adc_tm_scale_voltage_therm_pu2(struct qpnp_vadc_chip *dev,
1325 uint32_t reg, int64_t *result);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001326/**
1327 * qpnp_adc_usb_scaler() - Performs reverse calibration on the low/high
1328 * voltage threshold values passed by the client.
1329 * The function applies ratiometric calibration on the
1330 * voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001331 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001332 * @param: The input parameters that contain the low/high voltage
1333 * threshold values.
1334 * @low_threshold: The low threshold value that needs to be updated with
1335 * the above calibrated voltage value.
1336 * @high_threshold: The low threshold value that needs to be updated with
1337 * the above calibrated voltage value.
1338 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001339int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev,
1340 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001341 uint32_t *low_threshold, uint32_t *high_threshold);
1342/**
1343 * qpnp_adc_vbatt_rscaler() - Performs reverse calibration on the low/high
1344 * voltage threshold values passed by the client.
1345 * The function applies ratiometric calibration on the
1346 * voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001347 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001348 * @param: The input parameters that contain the low/high voltage
1349 * threshold values.
1350 * @low_threshold: The low threshold value that needs to be updated with
1351 * the above calibrated voltage value.
1352 * @high_threshold: The low threshold value that needs to be updated with
1353 * the above calibrated voltage value.
1354 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001355int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
1356 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001357 uint32_t *low_threshold, uint32_t *high_threshold);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001358/**
1359 * qpnp_vadc_iadc_sync_request() - Performs Voltage ADC read and
1360 * locks the peripheral. When performing simultaneous
1361 * voltage and current request the VADC peripheral is
1362 * prepared for conversion and the IADC sync conversion
1363 * is done from the IADC peripheral.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001364 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001365 * @channel: Input channel to perform the voltage ADC read.
1366 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001367int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev,
1368 enum qpnp_vadc_channels channel);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001369/**
1370 * qpnp_vadc_iadc_sync_complete_request() - Reads the ADC result and
1371 * unlocks the peripheral.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001372 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001373 * @result: Structure pointer of type adc_chan_result
1374 * in which the ADC read results are stored.
1375 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001376int32_t qpnp_vadc_iadc_sync_complete_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001377 enum qpnp_vadc_channels channel, struct qpnp_vadc_result *result);
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001378/**
1379 * qpnp_vadc_sns_comp_result() - Compensate vbatt readings based on temperature
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001380 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001381 * @result: Voltage in uV that needs compensation.
Xiaozhe Shi80754222013-10-30 14:11:41 -07001382 * @is_pon_ocv: Whether the reading is from a power on OCV or not
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001383 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001384int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev,
Xiaozhe Shi80754222013-10-30 14:11:41 -07001385 int64_t *result, bool is_pon_ocv);
Siddartha Mohanadoss93761842013-09-11 17:46:54 -07001386/**
1387 * qpnp_adc_get_revid_version() - Obtain the PMIC number and revision.
1388 * @dev: Structure device node.
1389 * returns internal mapped PMIC number and revision id.
1390 */
1391int qpnp_adc_get_revid_version(struct device *dev);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001392#else
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001393static inline int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev,
1394 uint32_t channel,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001395 struct qpnp_vadc_result *result)
1396{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001397static inline int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001398 enum qpnp_vadc_trigger trigger_channel,
1399 enum qpnp_vadc_channels channel,
1400 struct qpnp_vadc_result *result)
1401{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001402static inline int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *vadc,
1403 int32_t adc_code,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001404 const struct qpnp_adc_properties *adc_prop,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001405 const struct qpnp_vadc_chan_properties *chan_prop,
1406 struct qpnp_vadc_result *chan_rslt)
1407{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001408static inline int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc,
1409 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001410 const struct qpnp_adc_properties *adc_prop,
1411 const struct qpnp_vadc_chan_properties *chan_prop,
1412 struct qpnp_vadc_result *chan_rslt)
1413{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001414static inline int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *vadc,
1415 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001416 const struct qpnp_adc_properties *adc_prop,
1417 const struct qpnp_vadc_chan_properties *chan_prop,
1418 struct qpnp_vadc_result *chan_rslt)
1419{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001420static inline int32_t qpnp_adc_scale_qrd_batt_therm(
1421 struct qpnp_vadc_chip *vadc, int32_t adc_code,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001422 const struct qpnp_adc_properties *adc_prop,
1423 const struct qpnp_vadc_chan_properties *chan_prop,
Xu Kai81c60522013-07-27 14:26:04 +08001424 struct qpnp_vadc_result *chan_rslt)
1425{ return -ENXIO; }
1426static inline int32_t qpnp_adc_scale_qrd_skuaa_batt_therm(
1427 struct qpnp_vadc_chip *vadc, int32_t adc_code,
1428 const struct qpnp_adc_properties *adc_prop,
1429 const struct qpnp_vadc_chan_properties *chan_prop,
1430 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001431{ return -ENXIO; }
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +08001432static inline int32_t qpnp_adc_scale_qrd_skug_batt_therm(
1433 struct qpnp_vadc_chip *vadc, int32_t adc_code,
1434 const struct qpnp_adc_properties *adc_prop,
1435 const struct qpnp_vadc_chan_properties *chan_prop,
1436 struct qpnp_vadc_result *chan_rslt)
1437{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001438static inline int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *vadc,
1439 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001440 const struct qpnp_adc_properties *adc_prop,
1441 const struct qpnp_vadc_chan_properties *chan_prop,
1442 struct qpnp_vadc_result *chan_rslt)
1443{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001444static inline int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *vadc,
1445 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001446 const struct qpnp_adc_properties *adc_prop,
1447 const struct qpnp_vadc_chan_properties *chan_prop,
1448 struct qpnp_vadc_result *chan_rslt)
1449{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001450static inline int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *vadc,
1451 int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001452 const struct qpnp_adc_properties *adc_prop,
1453 const struct qpnp_vadc_chan_properties *chan_prop,
David Keitelc96dc852013-03-04 14:57:34 -08001454 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001455{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001456static inline int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *vadc,
1457 int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001458 const struct qpnp_adc_properties *adc_prop,
1459 const struct qpnp_vadc_chan_properties *chan_prop,
David Keitelc96dc852013-03-04 14:57:34 -08001460 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001461{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001462static inline struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev,
1463 const char *name)
1464{ return ERR_PTR(-ENXIO); }
1465static inline int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001466 struct qpnp_vadc_linear_graph *param,
1467 enum qpnp_adc_calib_type calib_type)
1468{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001469static inline int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001470 struct qpnp_adc_tm_btm_param *param,
1471 uint32_t *low_threshold, uint32_t *high_threshold)
1472{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001473static inline int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001474 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001475 uint32_t *low_threshold, uint32_t *high_threshold)
1476{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001477static inline int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001478 struct qpnp_adc_tm_btm_param *param,
1479 uint32_t *low_threshold, uint32_t *high_threshold)
1480{ return -ENXIO; }
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001481static inline int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001482 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001483 struct qpnp_adc_tm_btm_param *param,
1484 uint32_t *low_threshold, uint32_t *high_threshold)
1485{ return -ENXIO; }
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001486static inline int32_t qpnp_adc_tm_scale_therm_voltage_pu2(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001487 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001488 struct qpnp_adc_tm_config *param)
1489{ return -ENXIO; }
1490static inline int32_t qpnp_adc_tm_scale_voltage_therm_pu2(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001491 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001492 uint32_t reg, int64_t *result)
1493{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001494static inline int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001495 enum qpnp_vadc_channels channel)
1496{ return -ENXIO; }
1497static inline int32_t qpnp_vadc_iadc_sync_complete_request(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001498 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001499 enum qpnp_vadc_channels channel,
1500 struct qpnp_vadc_result *result)
1501{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001502static inline int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev,
1503 int64_t *result)
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001504{ return -ENXIO; }
Siddartha Mohanadoss93761842013-09-11 17:46:54 -07001505static inline int qpnp_adc_get_revid_version(struct device *dev)
1506{ return -ENXIO; }
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001507#endif
1508
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001509/* Public API */
1510#if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \
1511 || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE)
1512/**
1513 * qpnp_iadc_read() - Performs ADC read on the current channel.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001514 * @dev: Structure device for qpnp iadc
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001515 * @channel: Input channel to perform the ADC read.
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001516 * @result: Current across rsense in mA.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001517 * @return: 0 on success.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001518 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001519int32_t qpnp_iadc_read(struct qpnp_iadc_chip *dev,
1520 enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001521 struct qpnp_iadc_result *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001522/**
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001523 * qpnp_iadc_get_rsense() - Reads the RDS resistance value from the
1524 trim registers.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001525 * @dev: Structure device for qpnp iadc
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001526 * @rsense: RDS resistance in nOhms.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001527 * @return: 0 on success.
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001528 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001529int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *dev, int32_t *rsense);
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001530/**
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001531 * qpnp_iadc_get_gain_and_offset() - Performs gain calibration
1532 * over 17.8571mV and offset over selected
1533 * channel. Channel can be internal rsense,
1534 * external rsense and alternate lead pair.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001535 * @dev: Structure device for qpnp iadc
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001536 * @result: result structure where the gain and offset is stored of
1537 * type qpnp_iadc_calib.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001538 * @return: 0 on success.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001539 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001540int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *dev,
1541 struct qpnp_iadc_calib *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001542/**
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001543 * qpnp_get_iadc() - Clients need to register with the iadc with the
1544 * corresponding device instance it wants to read the channels.
1545 * Read the bindings document on how to pass the phandle for
1546 * the corresponding vadc driver to register with.
1547 * @dev: Clients device structure
1548 * @name: Corresponding client's DT parser name. Read the DT bindings
1549 * document on how to register with the iadc
1550 * @struct qpnp_iadc_chip * - On success returns the iadc device structure
1551 * pointer used everytime client makes an ADC request.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001552 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001553struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev, const char *name);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001554/**
1555 * qpnp_iadc_vadc_sync_read() - Performs synchronous VADC and IADC read.
1556 * The api is to be used only by the BMS to perform
1557 * simultaneous VADC and IADC measurement for battery voltage
1558 * and current.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001559 * @dev: Structure device for qpnp iadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001560 * @i_channel: Input battery current channel to perform the IADC read.
1561 * @i_result: Current across the rsense in mA.
1562 * @v_channel: Input battery voltage channel to perform VADC read.
1563 * @v_result: Voltage on the vbatt channel with units in mV.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001564 * @return: 0 on success.
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001565 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001566int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001567 enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result,
1568 enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result);
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001569/**
Abhijeet Dharmapurikar0ef9b5c2013-07-15 18:24:38 -07001570 * qpnp_iadc_calibrate_for_trim - Clients can use this API to re-calibrate
1571 * IADC. The offset and gain values are programmed in the trim
1572 * registers. The offset and the gain can be retrieved using
1573 * qpnp_iadc_get_gain_and_offset
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001574 * @dev: Structure device for qpnp iadc
Abhijeet Dharmapurikar0ef9b5c2013-07-15 18:24:38 -07001575 * @batfet_closed: batfet is opened or closed. The IADC chooses proper
1576 * channel (internal/external) based on batfet status
1577 * for calibration.
1578 * RETURNS: 0 on success.
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001579 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001580int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *dev,
1581 bool batfet_closed);
1582/**
1583 * qpnp_iadc_comp_result() - Compensates the result of the current based on
1584 * the gain and offset co-effients and rsense parameters.
1585 * @dev: Structure device for qpnp iadc
1586 * @result: Current value to perform the compensation.
1587 * @return: 0 on success.
1588 */
1589int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *dev, int64_t *result);
1590/**
1591 * qpnp_iadc_skip_calibration() - Clients can use this API to ask the driver
1592 * to skip iadc calibrations
1593 * @dev: Structure device for qpnp iadc
1594 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1595 * has not occured.
1596 */
1597int qpnp_iadc_skip_calibration(struct qpnp_iadc_chip *dev);
1598/**
1599 * qpnp_iadc_resume_calibration() - Clients can use this API to ask the driver
1600 * to resume iadc calibrations
1601 * @dev: Structure device for qpnp iadc
1602 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1603 * has not occured.
1604 */
1605int qpnp_iadc_resume_calibration(struct qpnp_iadc_chip *dev);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001606#else
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001607static inline int32_t qpnp_iadc_read(struct qpnp_iadc_chip *iadc,
1608 enum qpnp_iadc_channels channel, struct qpnp_iadc_result *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001609{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001610static inline int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *iadc,
1611 int32_t *rsense)
Siddartha Mohanadoss563166b2013-02-20 12:47:24 -08001612{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001613static inline int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *iadc,
1614 struct qpnp_iadc_calib *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001615{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001616static inline struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev,
1617 const char *name)
1618{ return ERR_PTR(-ENXIO); }
1619static inline int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *iadc,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001620 enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result,
1621 enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result)
1622{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001623static inline int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *iadc,
1624 bool batfet_closed)
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001625{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001626static inline int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *iadc,
1627 int64_t *result, int32_t sign)
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001628{ return -ENXIO; }
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001629#endif
1630
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001631/* Public API */
1632#if defined(CONFIG_THERMAL_QPNP_ADC_TM) \
1633 || defined(CONFIG_THERMAL_QPNP_ADC_TM_MODULE)
1634/**
1635 * qpnp_adc_tm_usbid_configure() - Configures Channel 0 of VADC_BTM to
1636 * monitor USB_ID channel using 100k internal pull-up.
1637 * USB driver passes the high/low voltage threshold along
1638 * with the notification callback once the set thresholds
1639 * are crossed.
1640 * @param: Structure pointer of qpnp_adc_tm_usbid_param type.
1641 * Clients pass the low/high voltage along with the threshold
1642 * notification callback.
1643 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001644int32_t qpnp_adc_tm_usbid_configure(struct qpnp_adc_tm_chip *chip,
1645 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001646/**
1647 * qpnp_adc_tm_usbid_end() - Disables the monitoring of channel 0 thats
1648 * assigned for monitoring USB_ID. Disables the low/high
1649 * threshold activation for channel 0 as well.
1650 * @param: none.
1651 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001652int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001653/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001654 * qpnp_adc_tm_channel_measure() - Configures kernel clients a channel to
1655 * monitor the corresponding ADC channel for threshold detection.
1656 * Driver passes the high/low voltage threshold along
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001657 * with the notification callback once the set thresholds
1658 * are crossed.
1659 * @param: Structure pointer of qpnp_adc_tm_btm_param type.
1660 * Clients pass the low/high temperature along with the threshold
1661 * notification callback.
1662 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001663int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip,
1664 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001665/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001666 * qpnp_adc_tm_disable_chan_meas() - Disables the monitoring of channel thats
1667 * assigned for monitoring kernel clients. Disables the low/high
1668 * threshold activation for the corresponding channel.
1669 * @param: Structure pointer of qpnp_adc_tm_btm_param type.
1670 * This is used to identify the channel for which the corresponding
1671 * channels high/low threshold notification will be disabled.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001672 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001673int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip,
1674 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001675/**
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001676 * qpnp_get_adc_tm() - Clients need to register with the adc_tm using the
1677 * corresponding device instance it wants to read the channels
1678 * from. Read the bindings document on how to pass the phandle
1679 * for the corresponding adc_tm driver to register with.
1680 * @name: Corresponding client's DT parser name. Read the DT bindings
1681 * document on how to register with the vadc
1682 * @struct qpnp_adc_tm_chip * - On success returns the vadc device structure
1683 * pointer that needs to be used during an ADC TM request.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001684 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001685struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, const char *name);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001686#else
1687static inline int32_t qpnp_adc_tm_usbid_configure(
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001688 struct qpnp_adc_tm_chip *chip,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001689 struct qpnp_adc_tm_btm_param *param)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001690{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001691static inline int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001692{ return -ENXIO; }
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001693static inline int32_t qpnp_adc_tm_channel_measure(
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001694 struct qpnp_adc_tm_chip *chip,
1695 struct qpnp_adc_tm_btm_param *param)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001696{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001697static inline int32_t qpnp_adc_tm_disable_chan_meas(
1698 struct qpnp_adc_tm_chip *chip)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001699{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001700static inline struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev,
1701 const char *name)
1702{ return ERR_PTR(-ENXIO); }
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001703#endif
1704
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001705#endif