blob: 13eb461b6b1f2e814c3aab51f7ff20e8556d833b [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>
23/**
24 * enum qpnp_vadc_channels - QPNP AMUX arbiter channels
25 */
26enum qpnp_vadc_channels {
27 USBIN = 0,
28 DCIN,
29 VCHG_SNS,
30 SPARE1_03,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080031 USB_ID_MV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070032 VCOIN,
33 VBAT_SNS,
34 VSYS,
35 DIE_TEMP,
36 REF_625MV,
37 REF_125V,
38 CHG_TEMP,
39 SPARE1,
40 SPARE2,
41 GND_REF,
42 VDD_VADC,
43 P_MUX1_1_1,
44 P_MUX2_1_1,
45 P_MUX3_1_1,
46 P_MUX4_1_1,
47 P_MUX5_1_1,
48 P_MUX6_1_1,
49 P_MUX7_1_1,
50 P_MUX8_1_1,
51 P_MUX9_1_1,
52 P_MUX10_1_1,
53 P_MUX11_1_1,
54 P_MUX12_1_1,
55 P_MUX13_1_1,
56 P_MUX14_1_1,
57 P_MUX15_1_1,
58 P_MUX16_1_1,
59 P_MUX1_1_3,
60 P_MUX2_1_3,
61 P_MUX3_1_3,
62 P_MUX4_1_3,
63 P_MUX5_1_3,
64 P_MUX6_1_3,
65 P_MUX7_1_3,
66 P_MUX8_1_3,
67 P_MUX9_1_3,
68 P_MUX10_1_3,
69 P_MUX11_1_3,
70 P_MUX12_1_3,
71 P_MUX13_1_3,
72 P_MUX14_1_3,
73 P_MUX15_1_3,
74 P_MUX16_1_3,
75 LR_MUX1_BATT_THERM,
76 LR_MUX2_BAT_ID,
77 LR_MUX3_XO_THERM,
78 LR_MUX4_AMUX_THM1,
79 LR_MUX5_AMUX_THM2,
80 LR_MUX6_AMUX_THM3,
81 LR_MUX7_HW_ID,
82 LR_MUX8_AMUX_THM4,
83 LR_MUX9_AMUX_THM5,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080084 LR_MUX10_USB_ID_LV,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -070085 AMUX_PU1,
86 AMUX_PU2,
87 LR_MUX3_BUF_XO_THERM_BUF,
Siddartha Mohanadoss2cadeba2012-11-13 18:40:27 -080088 LR_MUX1_PU1_BAT_THERM = 112,
89 LR_MUX2_PU1_BAT_ID = 113,
90 LR_MUX3_PU1_XO_THERM = 114,
91 LR_MUX4_PU1_AMUX_THM1 = 115,
92 LR_MUX5_PU1_AMUX_THM2 = 116,
93 LR_MUX6_PU1_AMUX_THM3 = 117,
94 LR_MUX7_PU1_AMUX_HW_ID = 118,
95 LR_MUX8_PU1_AMUX_THM4 = 119,
96 LR_MUX9_PU1_AMUX_THM5 = 120,
97 LR_MUX10_PU1_AMUX_USB_ID_LV = 121,
98 LR_MUX3_BUF_PU1_XO_THERM_BUF = 124,
99 LR_MUX1_PU2_BAT_THERM = 176,
100 LR_MUX2_PU2_BAT_ID = 177,
101 LR_MUX3_PU2_XO_THERM = 178,
102 LR_MUX4_PU2_AMUX_THM1 = 179,
103 LR_MUX5_PU2_AMUX_THM2 = 180,
104 LR_MUX6_PU2_AMUX_THM3 = 181,
105 LR_MUX7_PU2_AMUX_HW_ID = 182,
106 LR_MUX8_PU2_AMUX_THM4 = 183,
107 LR_MUX9_PU2_AMUX_THM5 = 184,
108 LR_MUX10_PU2_AMUX_USB_ID_LV = 185,
109 LR_MUX3_BUF_PU2_XO_THERM_BUF = 188,
110 LR_MUX1_PU1_PU2_BAT_THERM = 240,
111 LR_MUX2_PU1_PU2_BAT_ID = 241,
112 LR_MUX3_PU1_PU2_XO_THERM = 242,
113 LR_MUX4_PU1_PU2_AMUX_THM1 = 243,
114 LR_MUX5_PU1_PU2_AMUX_THM2 = 244,
115 LR_MUX6_PU1_PU2_AMUX_THM3 = 245,
116 LR_MUX7_PU1_PU2_AMUX_HW_ID = 246,
117 LR_MUX8_PU1_PU2_AMUX_THM4 = 247,
118 LR_MUX9_PU1_PU2_AMUX_THM5 = 248,
119 LR_MUX10_PU1_PU2_AMUX_USB_ID_LV = 249,
120 LR_MUX3_BUF_PU1_PU2_XO_THERM_BUF = 252,
121 ALL_OFF = 255,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700122 ADC_MAX_NUM,
123};
124
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700125/**
126 * enum qpnp_iadc_channels - QPNP IADC channel list
127 */
128enum qpnp_iadc_channels {
129 INTERNAL_RSENSE = 0,
130 EXTERNAL_RSENSE,
131 ALT_LEAD_PAIR,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700132 GAIN_CALIBRATION_17P857MV,
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700133 OFFSET_CALIBRATION_SHORT_CADC_LEADS,
134 OFFSET_CALIBRATION_CSP_CSN,
135 OFFSET_CALIBRATION_CSP2_CSN2,
136 IADC_MUX_NUM,
137};
138
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700139#define QPNP_ADC_625_UV 625000
Siddartha Mohanadoss1c218312012-11-08 11:30:43 -0800140#define QPNP_ADC_HWMON_NAME_LENGTH 64
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700141#define QPNP_MAX_PROP_NAME_LEN 32
142
143/* Structure device for qpnp vadc */
144struct qpnp_vadc_chip;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700145
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -0700146/* Structure device for qpnp iadc */
147struct qpnp_iadc_chip;
148
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -0700149/* Structure device for qpnp adc tm */
150struct qpnp_adc_tm_chip;
151
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700152/**
153 * enum qpnp_adc_decimation_type - Sampling rate supported.
154 * %DECIMATION_TYPE1: 512
155 * %DECIMATION_TYPE2: 1K
156 * %DECIMATION_TYPE3: 2K
157 * %DECIMATION_TYPE4: 4k
158 * %DECIMATION_NONE: Do not use this Sampling type.
159 *
160 * The Sampling rate is specific to each channel of the QPNP ADC arbiter.
161 */
162enum qpnp_adc_decimation_type {
163 DECIMATION_TYPE1 = 0,
164 DECIMATION_TYPE2,
165 DECIMATION_TYPE3,
166 DECIMATION_TYPE4,
167 DECIMATION_NONE,
168};
169
170/**
171 * enum qpnp_adc_calib_type - QPNP ADC Calibration type.
172 * %ADC_CALIB_ABSOLUTE: Use 625mV and 1.25V reference channels.
173 * %ADC_CALIB_RATIOMETRIC: Use reference Voltage/GND.
174 * %ADC_CALIB_CONFIG_NONE: Do not use this calibration type.
175 *
176 * Use the input reference voltage depending on the calibration type
177 * to calcluate the offset and gain parameters. The calibration is
178 * specific to each channel of the QPNP ADC.
179 */
180enum qpnp_adc_calib_type {
181 CALIB_ABSOLUTE = 0,
182 CALIB_RATIOMETRIC,
183 CALIB_NONE,
184};
185
186/**
187 * enum qpnp_adc_channel_scaling_param - pre-scaling AMUX ratio.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700188 * %CHAN_PATH_SCALING0: ratio of {1, 1}
189 * %CHAN_PATH_SCALING1: ratio of {1, 3}
190 * %CHAN_PATH_SCALING2: ratio of {1, 4}
191 * %CHAN_PATH_SCALING3: ratio of {1, 6}
192 * %CHAN_PATH_SCALING4: ratio of {1, 20}
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530193 * %CHAN_PATH_SCALING5: ratio of {1, 8}
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700194 * %CHAN_PATH_NONE: Do not use this pre-scaling ratio type.
195 *
196 * The pre-scaling is applied for signals to be within the voltage range
197 * of the ADC.
198 */
199enum qpnp_adc_channel_scaling_param {
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -0700200 PATH_SCALING0 = 0,
201 PATH_SCALING1,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700202 PATH_SCALING2,
203 PATH_SCALING3,
204 PATH_SCALING4,
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530205 PATH_SCALING5,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700206 PATH_SCALING_NONE,
207};
208
209/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800210 * enum qpnp_adc_scale_fn_type - Scaling function for pm8941 pre calibrated
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700211 * digital data relative to ADC reference.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700212 * %SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV).
213 * %SCALE_BATT_THERM: Conversion to temperature(decidegC) based on btm
214 * parameters.
215 * %SCALE_THERM_100K_PULLUP: Returns temperature in degC.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700216 * Uses a mapping table with 100K pullup.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700217 * %SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
218 * %SCALE_XOTHERM: Returns XO thermistor voltage in degree's Centigrade.
219 * %SCALE_THERM_150K_PULLUP: Returns temperature in degC.
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700220 * Uses a mapping table with 150K pullup.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700221 * %SCALE_QRD_BATT_THERM: Conversion to temperature(decidegC) based on
222 * btm parameters.
Xu Kai81c60522013-07-27 14:26:04 +0800223 * %SCALE_QRD_SKUAA_BATT_THERM: Conversion to temperature(decidegC) based on
224 * btm parametersi for SKUAA.
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +0800225 * %SCALE_QRD_SKUG_BATT_THERM: Conversion to temperature(decidegC) based on
226 * btm parametersi for SKUG.
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700227 * %SCALE_NONE: Do not use this scaling type.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700228 */
229enum qpnp_adc_scale_fn_type {
230 SCALE_DEFAULT = 0,
231 SCALE_BATT_THERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700232 SCALE_THERM_100K_PULLUP,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700233 SCALE_PMIC_THERM,
234 SCALE_XOTHERM,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -0700235 SCALE_THERM_150K_PULLUP,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -0700236 SCALE_QRD_BATT_THERM,
Xu Kai81c60522013-07-27 14:26:04 +0800237 SCALE_QRD_SKUAA_BATT_THERM,
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +0800238 SCALE_QRD_SKUG_BATT_THERM = 9,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700239 SCALE_NONE,
240};
241
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800242
243/**
244 * enum qpnp_adc_tm_rscale_fn_type - Scaling function used to convert the
245 * channels input voltage/temperature to corresponding ADC code that is
246 * applied for thresholds. Check the corresponding channels scaling to
247 * determine the appropriate temperature/voltage units that are passed
248 * to the scaling function. Example battery follows the power supply
249 * framework that needs its units to be in decidegreesC so it passes
250 * deci-degreesC. PA_THERM clients pass the temperature in degrees.
251 * The order below should match the one in the driver for
252 * adc_tm_rscale_fn[].
253 */
254enum qpnp_adc_tm_rscale_fn_type {
255 SCALE_R_VBATT = 0,
256 SCALE_RBATT_THERM,
257 SCALE_R_USB_ID,
258 SCALE_RPMIC_THERM,
259 SCALE_RSCALE_NONE,
260};
261
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700262/**
263 * enum qpnp_adc_fast_avg_ctl - Provides ability to obtain single result
264 * from the ADC that is an average of multiple measurement
265 * samples. Select number of samples for use in fast
266 * average mode (i.e. 2 ^ value).
267 * %ADC_FAST_AVG_SAMPLE_1: 0x0 = 1
268 * %ADC_FAST_AVG_SAMPLE_2: 0x1 = 2
269 * %ADC_FAST_AVG_SAMPLE_4: 0x2 = 4
270 * %ADC_FAST_AVG_SAMPLE_8: 0x3 = 8
271 * %ADC_FAST_AVG_SAMPLE_16: 0x4 = 16
272 * %ADC_FAST_AVG_SAMPLE_32: 0x5 = 32
273 * %ADC_FAST_AVG_SAMPLE_64: 0x6 = 64
274 * %ADC_FAST_AVG_SAMPLE_128: 0x7 = 128
275 * %ADC_FAST_AVG_SAMPLE_256: 0x8 = 256
276 * %ADC_FAST_AVG_SAMPLE_512: 0x9 = 512
277 */
278enum qpnp_adc_fast_avg_ctl {
279 ADC_FAST_AVG_SAMPLE_1 = 0,
280 ADC_FAST_AVG_SAMPLE_2,
281 ADC_FAST_AVG_SAMPLE_4,
282 ADC_FAST_AVG_SAMPLE_8,
283 ADC_FAST_AVG_SAMPLE_16,
284 ADC_FAST_AVG_SAMPLE_32,
285 ADC_FAST_AVG_SAMPLE_64,
286 ADC_FAST_AVG_SAMPLE_128,
287 ADC_FAST_AVG_SAMPLE_256,
288 ADC_FAST_AVG_SAMPLE_512,
289 ADC_FAST_AVG_SAMPLE_NONE,
290};
291
292/**
293 * enum qpnp_adc_hw_settle_time - Time between AMUX getting configured and
294 * the ADC starting conversion. Delay = 100us * value for
295 * value < 11 and 2ms * (value - 10) otherwise.
296 * %ADC_CHANNEL_HW_SETTLE_DELAY_0US: 0us
297 * %ADC_CHANNEL_HW_SETTLE_DELAY_100US: 100us
298 * %ADC_CHANNEL_HW_SETTLE_DELAY_200US: 200us
299 * %ADC_CHANNEL_HW_SETTLE_DELAY_300US: 300us
300 * %ADC_CHANNEL_HW_SETTLE_DELAY_400US: 400us
301 * %ADC_CHANNEL_HW_SETTLE_DELAY_500US: 500us
302 * %ADC_CHANNEL_HW_SETTLE_DELAY_600US: 600us
303 * %ADC_CHANNEL_HW_SETTLE_DELAY_700US: 700us
304 * %ADC_CHANNEL_HW_SETTLE_DELAY_800US: 800us
305 * %ADC_CHANNEL_HW_SETTLE_DELAY_900US: 900us
306 * %ADC_CHANNEL_HW_SETTLE_DELAY_1MS: 1ms
307 * %ADC_CHANNEL_HW_SETTLE_DELAY_2MS: 2ms
308 * %ADC_CHANNEL_HW_SETTLE_DELAY_4MS: 4ms
309 * %ADC_CHANNEL_HW_SETTLE_DELAY_6MS: 6ms
310 * %ADC_CHANNEL_HW_SETTLE_DELAY_8MS: 8ms
311 * %ADC_CHANNEL_HW_SETTLE_DELAY_10MS: 10ms
312 * %ADC_CHANNEL_HW_SETTLE_NONE
313 */
314enum qpnp_adc_hw_settle_time {
315 ADC_CHANNEL_HW_SETTLE_DELAY_0US = 0,
316 ADC_CHANNEL_HW_SETTLE_DELAY_100US,
317 ADC_CHANNEL_HW_SETTLE_DELAY_2000US,
318 ADC_CHANNEL_HW_SETTLE_DELAY_300US,
319 ADC_CHANNEL_HW_SETTLE_DELAY_400US,
320 ADC_CHANNEL_HW_SETTLE_DELAY_500US,
321 ADC_CHANNEL_HW_SETTLE_DELAY_600US,
322 ADC_CHANNEL_HW_SETTLE_DELAY_700US,
323 ADC_CHANNEL_HW_SETTLE_DELAY_800US,
324 ADC_CHANNEL_HW_SETTLE_DELAY_900US,
325 ADC_CHANNEL_HW_SETTLE_DELAY_1MS,
326 ADC_CHANNEL_HW_SETTLE_DELAY_2MS,
327 ADC_CHANNEL_HW_SETTLE_DELAY_4MS,
328 ADC_CHANNEL_HW_SETTLE_DELAY_6MS,
329 ADC_CHANNEL_HW_SETTLE_DELAY_8MS,
330 ADC_CHANNEL_HW_SETTLE_DELAY_10MS,
331 ADC_CHANNEL_HW_SETTLE_NONE,
332};
333
334/**
335 * enum qpnp_vadc_mode_sel - Selects the basic mode of operation.
336 * - The normal mode is used for single measurement.
337 * - The Conversion sequencer is used to trigger an
338 * ADC read when a HW trigger is selected.
339 * - The measurement interval performs a single or
340 * continous measurement at a specified interval/delay.
341 * %ADC_OP_NORMAL_MODE : Normal mode used for single measurement.
342 * %ADC_OP_CONVERSION_SEQUENCER : Conversion sequencer used to trigger
343 * an ADC read on a HW supported trigger.
344 * Refer to enum qpnp_vadc_trigger for
345 * supported HW triggers.
346 * %ADC_OP_MEASUREMENT_INTERVAL : The measurement interval performs a
347 * single or continous measurement after a specified delay.
348 * For delay look at qpnp_adc_meas_timer.
349 */
350enum qpnp_vadc_mode_sel {
351 ADC_OP_NORMAL_MODE = 0,
352 ADC_OP_CONVERSION_SEQUENCER,
353 ADC_OP_MEASUREMENT_INTERVAL,
354 ADC_OP_MODE_NONE,
355};
356
357/**
358 * enum qpnp_vadc_trigger - Select the HW trigger to be used while
359 * measuring the ADC reading.
360 * %ADC_GSM_PA_ON : GSM power amplifier on.
361 * %ADC_TX_GTR_THRES : Transmit power greater than threshold.
362 * %ADC_CAMERA_FLASH_RAMP : Flash ramp up done.
363 * %ADC_DTEST : DTEST.
364 */
365enum qpnp_vadc_trigger {
366 ADC_GSM_PA_ON = 0,
367 ADC_TX_GTR_THRES,
368 ADC_CAMERA_FLASH_RAMP,
369 ADC_DTEST,
370 ADC_SEQ_NONE,
371};
372
373/**
374 * enum qpnp_vadc_conv_seq_timeout - Select delay (0 to 15ms) from
375 * conversion request to triggering conversion sequencer
376 * hold off time.
377 */
378enum qpnp_vadc_conv_seq_timeout {
379 ADC_CONV_SEQ_TIMEOUT_0MS = 0,
380 ADC_CONV_SEQ_TIMEOUT_1MS,
381 ADC_CONV_SEQ_TIMEOUT_2MS,
382 ADC_CONV_SEQ_TIMEOUT_3MS,
383 ADC_CONV_SEQ_TIMEOUT_4MS,
384 ADC_CONV_SEQ_TIMEOUT_5MS,
385 ADC_CONV_SEQ_TIMEOUT_6MS,
386 ADC_CONV_SEQ_TIMEOUT_7MS,
387 ADC_CONV_SEQ_TIMEOUT_8MS,
388 ADC_CONV_SEQ_TIMEOUT_9MS,
389 ADC_CONV_SEQ_TIMEOUT_10MS,
390 ADC_CONV_SEQ_TIMEOUT_11MS,
391 ADC_CONV_SEQ_TIMEOUT_12MS,
392 ADC_CONV_SEQ_TIMEOUT_13MS,
393 ADC_CONV_SEQ_TIMEOUT_14MS,
394 ADC_CONV_SEQ_TIMEOUT_15MS,
395 ADC_CONV_SEQ_TIMEOUT_NONE,
396};
397
398/**
399 * enum qpnp_adc_conv_seq_holdoff - Select delay from conversion
400 * trigger signal (i.e. adc_conv_seq_trig) transition
401 * to ADC enable. Delay = 25us * (value + 1).
402 */
403enum qpnp_adc_conv_seq_holdoff {
404 ADC_SEQ_HOLD_25US = 0,
405 ADC_SEQ_HOLD_50US,
406 ADC_SEQ_HOLD_75US,
407 ADC_SEQ_HOLD_100US,
408 ADC_SEQ_HOLD_125US,
409 ADC_SEQ_HOLD_150US,
410 ADC_SEQ_HOLD_175US,
411 ADC_SEQ_HOLD_200US,
412 ADC_SEQ_HOLD_225US,
413 ADC_SEQ_HOLD_250US,
414 ADC_SEQ_HOLD_275US,
415 ADC_SEQ_HOLD_300US,
416 ADC_SEQ_HOLD_325US,
417 ADC_SEQ_HOLD_350US,
418 ADC_SEQ_HOLD_375US,
419 ADC_SEQ_HOLD_400US,
420 ADC_SEQ_HOLD_NONE,
421};
422
423/**
424 * enum qpnp_adc_conv_seq_state - Conversion sequencer operating state
425 * %ADC_CONV_SEQ_IDLE : Sequencer is in idle.
426 * %ADC_CONV_TRIG_RISE : Waiting for rising edge trigger.
427 * %ADC_CONV_TRIG_HOLDOFF : Waiting for rising trigger hold off time.
428 * %ADC_CONV_MEAS_RISE : Measuring selected ADC signal.
429 * %ADC_CONV_TRIG_FALL : Waiting for falling trigger edge.
430 * %ADC_CONV_FALL_HOLDOFF : Waiting for falling trigger hold off time.
431 * %ADC_CONV_MEAS_FALL : Measuring selected ADC signal.
432 * %ADC_CONV_ERROR : Aberrant Hardware problem.
433 */
434enum qpnp_adc_conv_seq_state {
435 ADC_CONV_SEQ_IDLE = 0,
436 ADC_CONV_TRIG_RISE,
437 ADC_CONV_TRIG_HOLDOFF,
438 ADC_CONV_MEAS_RISE,
439 ADC_CONV_TRIG_FALL,
440 ADC_CONV_FALL_HOLDOFF,
441 ADC_CONV_MEAS_FALL,
442 ADC_CONV_ERROR,
443 ADC_CONV_NONE,
444};
445
446/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800447 * enum qpnp_adc_meas_timer_1 - Selects the measurement interval time.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700448 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800449 * The timer period is used by the USB_ID. Do not set a polling rate
450 * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0
451 * appears to be limited to 1 second.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700452 * %ADC_MEAS_INTERVAL_0MS : 0ms
453 * %ADC_MEAS_INTERVAL_1P0MS : 1ms
454 * %ADC_MEAS_INTERVAL_2P0MS : 2ms
455 * %ADC_MEAS_INTERVAL_3P9MS : 3.9ms
456 * %ADC_MEAS_INTERVAL_7P8MS : 7.8ms
457 * %ADC_MEAS_INTERVAL_15P6MS : 15.6ms
458 * %ADC_MEAS_INTERVAL_31P3MS : 31.3ms
459 * %ADC_MEAS_INTERVAL_62P5MS : 62.5ms
460 * %ADC_MEAS_INTERVAL_125MS : 125ms
461 * %ADC_MEAS_INTERVAL_250MS : 250ms
462 * %ADC_MEAS_INTERVAL_500MS : 500ms
463 * %ADC_MEAS_INTERVAL_1S : 1seconds
464 * %ADC_MEAS_INTERVAL_2S : 2seconds
465 * %ADC_MEAS_INTERVAL_4S : 4seconds
466 * %ADC_MEAS_INTERVAL_8S : 8seconds
467 * %ADC_MEAS_INTERVAL_16S: 16seconds
468 */
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800469enum qpnp_adc_meas_timer_1 {
470 ADC_MEAS1_INTERVAL_0MS = 0,
471 ADC_MEAS1_INTERVAL_1P0MS,
472 ADC_MEAS1_INTERVAL_2P0MS,
473 ADC_MEAS1_INTERVAL_3P9MS,
474 ADC_MEAS1_INTERVAL_7P8MS,
475 ADC_MEAS1_INTERVAL_15P6MS,
476 ADC_MEAS1_INTERVAL_31P3MS,
477 ADC_MEAS1_INTERVAL_62P5MS,
478 ADC_MEAS1_INTERVAL_125MS,
479 ADC_MEAS1_INTERVAL_250MS,
480 ADC_MEAS1_INTERVAL_500MS,
481 ADC_MEAS1_INTERVAL_1S,
482 ADC_MEAS1_INTERVAL_2S,
483 ADC_MEAS1_INTERVAL_4S,
484 ADC_MEAS1_INTERVAL_8S,
485 ADC_MEAS1_INTERVAL_16S,
486 ADC_MEAS1_INTERVAL_NONE,
487};
488
489/**
490 * enum qpnp_adc_meas_timer_2 - Selects the measurement interval time.
491 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
492 * The timer period is used by the batt_therm. Do not set a polling rate
493 * greater than 1 second on PMIC 2.0. The max polling rate on the PMIC 2.0
494 * appears to be limited to 1 second.
495 * %ADC_MEAS_INTERVAL_0MS : 0ms
496 * %ADC_MEAS_INTERVAL_100MS : 100ms
497 * %ADC_MEAS_INTERVAL_200MS : 200ms
498 * %ADC_MEAS_INTERVAL_300MS : 300ms
499 * %ADC_MEAS_INTERVAL_400MS : 400ms
500 * %ADC_MEAS_INTERVAL_500MS : 500ms
501 * %ADC_MEAS_INTERVAL_600MS : 600ms
502 * %ADC_MEAS_INTERVAL_700MS : 700ms
503 * %ADC_MEAS_INTERVAL_800MS : 800ms
504 * %ADC_MEAS_INTERVAL_900MS : 900ms
505 * %ADC_MEAS_INTERVAL_1S: 1seconds
506 * %ADC_MEAS_INTERVAL_1P1S: 1.1seconds
507 * %ADC_MEAS_INTERVAL_1P2S: 1.2seconds
508 * %ADC_MEAS_INTERVAL_1P3S: 1.3seconds
509 * %ADC_MEAS_INTERVAL_1P4S: 1.4seconds
510 * %ADC_MEAS_INTERVAL_1P5S: 1.5seconds
511 */
512enum qpnp_adc_meas_timer_2 {
513 ADC_MEAS2_INTERVAL_0MS = 0,
514 ADC_MEAS2_INTERVAL_100MS,
515 ADC_MEAS2_INTERVAL_200MS,
516 ADC_MEAS2_INTERVAL_300MS,
517 ADC_MEAS2_INTERVAL_400MS,
518 ADC_MEAS2_INTERVAL_500MS,
519 ADC_MEAS2_INTERVAL_600MS,
520 ADC_MEAS2_INTERVAL_700MS,
521 ADC_MEAS2_INTERVAL_800MS,
522 ADC_MEAS2_INTERVAL_900MS,
523 ADC_MEAS2_INTERVAL_1S,
524 ADC_MEAS2_INTERVAL_1P1S,
525 ADC_MEAS2_INTERVAL_1P2S,
526 ADC_MEAS2_INTERVAL_1P3S,
527 ADC_MEAS2_INTERVAL_1P4S,
528 ADC_MEAS2_INTERVAL_1P5S,
529 ADC_MEAS2_INTERVAL_NONE,
530};
531
532/**
533 * enum qpnp_adc_meas_timer_3 - Selects the measurement interval time.
534 * If value = 0, use 0ms else use 2^(value + 4)/ 32768).
535 * Do not set a polling rate greater than 1 second on PMIC 2.0.
536 * The max polling rate on the PMIC 2.0 appears to be limited to 1 second.
537 * %ADC_MEAS_INTERVAL_0MS : 0ms
538 * %ADC_MEAS_INTERVAL_1S : 1seconds
539 * %ADC_MEAS_INTERVAL_2S : 2seconds
540 * %ADC_MEAS_INTERVAL_3S : 3seconds
541 * %ADC_MEAS_INTERVAL_4S : 4seconds
542 * %ADC_MEAS_INTERVAL_5S : 5seconds
543 * %ADC_MEAS_INTERVAL_6S: 6seconds
544 * %ADC_MEAS_INTERVAL_7S : 7seconds
545 * %ADC_MEAS_INTERVAL_8S : 8seconds
546 * %ADC_MEAS_INTERVAL_9S : 9seconds
547 * %ADC_MEAS_INTERVAL_10S : 10seconds
548 * %ADC_MEAS_INTERVAL_11S : 11seconds
549 * %ADC_MEAS_INTERVAL_12S : 12seconds
550 * %ADC_MEAS_INTERVAL_13S : 13seconds
551 * %ADC_MEAS_INTERVAL_14S : 14seconds
552 * %ADC_MEAS_INTERVAL_15S : 15seconds
553 */
554enum qpnp_adc_meas_timer_3 {
555 ADC_MEAS3_INTERVAL_0S = 0,
556 ADC_MEAS3_INTERVAL_1S,
557 ADC_MEAS3_INTERVAL_2S,
558 ADC_MEAS3_INTERVAL_3S,
559 ADC_MEAS3_INTERVAL_4S,
560 ADC_MEAS3_INTERVAL_5S,
561 ADC_MEAS3_INTERVAL_6S,
562 ADC_MEAS3_INTERVAL_7S,
563 ADC_MEAS3_INTERVAL_8S,
564 ADC_MEAS3_INTERVAL_9S,
565 ADC_MEAS3_INTERVAL_10S,
566 ADC_MEAS3_INTERVAL_11S,
567 ADC_MEAS3_INTERVAL_12S,
568 ADC_MEAS3_INTERVAL_13S,
569 ADC_MEAS3_INTERVAL_14S,
570 ADC_MEAS3_INTERVAL_15S,
571 ADC_MEAS3_INTERVAL_NONE,
572};
573
574/**
575 * enum qpnp_adc_meas_timer_select - Selects the timer for which
576 * the appropriate polling frequency is set.
Siddartha Mohanadoss58ffe0e2014-02-11 17:40:13 -0800577 * %ADC_MEAS_TIMER_SELECT1 - Select this timer for measurement polling interval
578 * for 1 second.
579 * %ADC_MEAS_TIMER_SELECT2 - Select this timer for 500ms measurement interval.
580 * %ADC_MEAS_TIMER_SELECT3 - Select this timer for 5 second interval.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800581 */
582enum qpnp_adc_meas_timer_select {
583 ADC_MEAS_TIMER_SELECT1 = 0,
584 ADC_MEAS_TIMER_SELECT2,
585 ADC_MEAS_TIMER_SELECT3,
586 ADC_MEAS_TIMER_NUM,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700587};
588
589/**
590 * enum qpnp_adc_meas_interval_op_ctl - Select operating mode.
591 * %ADC_MEAS_INTERVAL_OP_SINGLE : Conduct single measurement at specified time
592 * delay.
593 * %ADC_MEAS_INTERVAL_OP_CONTINUOUS : Make measurements at measurement interval
594 * times.
595 */
596enum qpnp_adc_meas_interval_op_ctl {
597 ADC_MEAS_INTERVAL_OP_SINGLE = 0,
598 ADC_MEAS_INTERVAL_OP_CONTINUOUS,
599 ADC_MEAS_INTERVAL_OP_NONE,
600};
601
602/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800603 * Channel selection registers for each of the configurable measurements
604 * Channels allotment is set at device config for a channel.
605 * The USB_ID, BATT_THERM, PMIC_THERM and VBAT channels are used by the
606 * kernel space USB, Battery and IADC drivers.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800607 * The other 3 channels are configurable for use by userspace clients.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800608 */
609enum qpnp_adc_tm_channel_select {
610 QPNP_ADC_TM_M0_ADC_CH_SEL_CTL = 0x48,
611 QPNP_ADC_TM_M1_ADC_CH_SEL_CTL = 0x68,
612 QPNP_ADC_TM_M2_ADC_CH_SEL_CTL = 0x70,
613 QPNP_ADC_TM_M3_ADC_CH_SEL_CTL = 0x78,
614 QPNP_ADC_TM_M4_ADC_CH_SEL_CTL = 0x80,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800615 QPNP_ADC_TM_M5_ADC_CH_SEL_CTL = 0x88,
616 QPNP_ADC_TM_M6_ADC_CH_SEL_CTL = 0x90,
617 QPNP_ADC_TM_M7_ADC_CH_SEL_CTL = 0x98,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800618 QPNP_ADC_TM_CH_SELECT_NONE
619};
620
Siddartha Mohanadoss71a83442013-08-29 11:43:24 -0700621/**
622 * Channel index for the corresponding index to qpnp_adc_tm_channel_selec
623 */
624enum qpnp_adc_tm_channel_num {
625 QPNP_ADC_TM_CHAN0 = 0,
626 QPNP_ADC_TM_CHAN1,
627 QPNP_ADC_TM_CHAN2,
628 QPNP_ADC_TM_CHAN3,
629 QPNP_ADC_TM_CHAN4,
630 QPNP_ADC_TM_CHAN5,
631 QPNP_ADC_TM_CHAN6,
632 QPNP_ADC_TM_CHAN7,
633 QPNP_ADC_TM_CHAN_NONE
634};
635
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -0700636enum qpnp_comp_scheme_type {
637 COMP_ID_GF = 0,
638 COMP_ID_SMIC,
639 COMP_ID_TSMC,
640 COMP_ID_NUM,
641};
642
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800643/**
644 * struct qpnp_adc_tm_config - Represent ADC Thermal Monitor configuration.
645 * @channel: ADC channel for which thermal monitoring is requested.
646 * @adc_code: The pre-calibrated digital output of a given ADC releative to the
647 * ADC reference.
648 * @high_thr_temp: Temperature at which high threshold notification is required.
649 * @low_thr_temp: Temperature at which low threshold notification is required.
650 * @low_thr_voltage : Low threshold voltage ADC code used for reverse
651 * calibration.
652 * @high_thr_voltage: High threshold voltage ADC code used for reverse
653 * calibration.
654 */
655struct qpnp_adc_tm_config {
656 int channel;
657 int adc_code;
658 int high_thr_temp;
659 int low_thr_temp;
660 int64_t high_thr_voltage;
661 int64_t low_thr_voltage;
662};
663
664/**
665 * enum qpnp_adc_tm_trip_type - Type for setting high/low temperature/voltage.
666 * %ADC_TM_TRIP_HIGH_WARM: Setting high temperature. Note that high temperature
667 * corresponds to low voltage. Driver handles this case
668 * appropriately to set high/low thresholds for voltage.
669 * threshold.
670 * %ADC_TM_TRIP_LOW_COOL: Setting low temperature.
671 */
672enum qpnp_adc_tm_trip_type {
673 ADC_TM_TRIP_HIGH_WARM = 0,
674 ADC_TM_TRIP_LOW_COOL,
675 ADC_TM_TRIP_NUM,
676};
677
678/**
679 * enum qpnp_tm_state - This lets the client know whether the threshold
680 * that was crossed was high/low.
681 * %ADC_TM_HIGH_STATE: Client is notified of crossing the requested high
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700682 * voltage threshold.
683 * %ADC_TM_COOL_STATE: Client is notified of crossing the requested cool
684 * temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800685 * %ADC_TM_LOW_STATE: Client is notified of crossing the requested low
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700686 * voltage threshold.
687 * %ADC_TM_WARM_STATE: Client is notified of crossing the requested high
688 * temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800689 */
690enum qpnp_tm_state {
691 ADC_TM_HIGH_STATE = 0,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700692 ADC_TM_COOL_STATE = ADC_TM_HIGH_STATE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800693 ADC_TM_LOW_STATE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700694 ADC_TM_WARM_STATE = ADC_TM_LOW_STATE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800695 ADC_TM_STATE_NUM,
696};
697
698/**
699 * enum qpnp_state_request - Request to enable/disable the corresponding
700 * high/low voltage/temperature thresholds.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700701 * %ADC_TM_HIGH_THR_ENABLE: Enable high voltage threshold.
702 * %ADC_TM_COOL_THR_ENABLE = Enables cool temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800703 * %ADC_TM_LOW_THR_ENABLE: Enable low voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700704 * %ADC_TM_WARM_THR_ENABLE = Enables warm temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800705 * %ADC_TM_HIGH_LOW_THR_ENABLE: Enable high and low voltage/temperature
706 * threshold.
707 * %ADC_TM_HIGH_THR_DISABLE: Disable high voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700708 * %ADC_TM_COOL_THR_ENABLE = Disables cool temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800709 * %ADC_TM_LOW_THR_DISABLE: Disable low voltage/temperature threshold.
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700710 * %ADC_TM_WARM_THR_ENABLE = Disables warm temperature threshold.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800711 * %ADC_TM_HIGH_THR_DISABLE: Disable high and low voltage/temperature
712 * threshold.
713 */
714enum qpnp_state_request {
715 ADC_TM_HIGH_THR_ENABLE = 0,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700716 ADC_TM_COOL_THR_ENABLE = ADC_TM_HIGH_THR_ENABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800717 ADC_TM_LOW_THR_ENABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700718 ADC_TM_WARM_THR_ENABLE = ADC_TM_LOW_THR_ENABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800719 ADC_TM_HIGH_LOW_THR_ENABLE,
720 ADC_TM_HIGH_THR_DISABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700721 ADC_TM_COOL_THR_DISABLE = ADC_TM_HIGH_THR_DISABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800722 ADC_TM_LOW_THR_DISABLE,
Siddartha Mohanadossb8109da2013-03-25 09:53:43 -0700723 ADC_TM_WARM_THR_DISABLE = ADC_TM_LOW_THR_DISABLE,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800724 ADC_TM_HIGH_LOW_THR_DISABLE,
725 ADC_TM_THR_NUM,
726};
727
728/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800729 * struct qpnp_adc_tm_btm_param - Represent Battery temperature threshold
730 * monitoring configuration.
731 * @high_temp: High temperature threshold for which notification is requested.
732 * @low_temp: Low temperature threshold for which notification is requested.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800733 * @high_thr_voltage: High voltage for which notification is requested.
734 * @low_thr_voltage: Low voltage for which notification is requested.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800735 * @state_request: Enable/disable the corresponding high and low temperature
736 * thresholds.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800737 * @timer_interval1: Select polling rate from qpnp_adc_meas_timer_1 type.
738 * @timer_interval2: Select polling rate from qpnp_adc_meas_timer_2 type.
739 * @timer_interval3: Select polling rate from qpnp_adc_meas_timer_3 type.
Siddartha Mohanadossd71e2402013-02-01 17:36:23 -0800740 * @btmid_ctx: A context of void type.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800741 * @threshold_notification: Notification callback once threshold are crossed.
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800742 * units to be used for High/Low temperature and voltage notification -
743 * This depends on the clients usage. Check the rscaling function
744 * for the appropriate channel nodes.
745 * @Batt therm clients temperature units is decidegreesCentigrate.
746 * @USB_ID inputs the voltage units in milli-volts.
747 * @PA_THERM inputs the units in degC.
748 * @PMIC_THERM inputs the units in millidegC.
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800749 */
750struct qpnp_adc_tm_btm_param {
751 int32_t high_temp;
752 int32_t low_temp;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800753 int32_t high_thr;
754 int32_t low_thr;
755 enum qpnp_vadc_channels channel;
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800756 enum qpnp_state_request state_request;
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800757 enum qpnp_adc_meas_timer_1 timer_interval;
758 enum qpnp_adc_meas_timer_2 timer_interval2;
759 enum qpnp_adc_meas_timer_3 timer_interval3;
Siddartha Mohanadossd71e2402013-02-01 17:36:23 -0800760 void *btm_ctx;
761 void (*threshold_notification) (enum qpnp_tm_state state,
762 void *ctx);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -0800763};
764
765/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700766 * struct qpnp_vadc_linear_graph - Represent ADC characteristics.
767 * @dy: Numerator slope to calculate the gain.
768 * @dx: Denominator slope to calculate the gain.
769 * @adc_vref: A/D word of the voltage reference used for the channel.
770 * @adc_gnd: A/D word of the ground reference used for the channel.
771 *
772 * Each ADC device has different offset and gain parameters which are computed
773 * to calibrate the device.
774 */
775struct qpnp_vadc_linear_graph {
776 int64_t dy;
777 int64_t dx;
778 int64_t adc_vref;
779 int64_t adc_gnd;
780};
781
782/**
783 * struct qpnp_vadc_map_pt - Map the graph representation for ADC channel
784 * @x: Represent the ADC digitized code.
785 * @y: Represent the physical data which can be temperature, voltage,
786 * resistance.
787 */
788struct qpnp_vadc_map_pt {
789 int32_t x;
790 int32_t y;
791};
792
793/**
794 * struct qpnp_vadc_scaling_ratio - Represent scaling ratio for adc input.
795 * @num: Numerator scaling parameter.
796 * @den: Denominator scaling parameter.
797 */
798struct qpnp_vadc_scaling_ratio {
799 int32_t num;
800 int32_t den;
801};
802
803/**
804 * struct qpnp_adc_properties - Represent the ADC properties.
805 * @adc_reference: Reference voltage for QPNP ADC.
806 * @bitresolution: ADC bit resolution for QPNP ADC.
807 * @biploar: Polarity for QPNP ADC.
808 */
809struct qpnp_adc_properties {
810 uint32_t adc_vdd_reference;
811 uint32_t bitresolution;
812 bool bipolar;
813};
814
815/**
816 * struct qpnp_vadc_chan_properties - Represent channel properties of the ADC.
817 * @offset_gain_numerator: The inverse numerator of the gain applied to the
818 * input channel.
819 * @offset_gain_denominator: The inverse denominator of the gain applied to the
820 * input channel.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800821 * @high_thr: High threshold voltage that is requested to be set.
822 * @low_thr: Low threshold voltage that is requested to be set.
823 * @timer_select: Choosen from one of the 3 timers to set the polling rate for
824 * the VADC_BTM channel.
825 * @meas_interval1: Polling rate to set for timer 1.
826 * @meas_interval2: Polling rate to set for timer 2.
827 * @tm_channel_select: BTM channel number for the 5 VADC_BTM channels.
828 * @state_request: User can select either enable or disable high/low or both
829 * activation levels based on the qpnp_state_request type.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700830 * @adc_graph: ADC graph for the channel of struct type qpnp_adc_linear_graph.
831 */
832struct qpnp_vadc_chan_properties {
833 uint32_t offset_gain_numerator;
834 uint32_t offset_gain_denominator;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800835 uint32_t high_thr;
836 uint32_t low_thr;
837 enum qpnp_adc_meas_timer_select timer_select;
838 enum qpnp_adc_meas_timer_1 meas_interval1;
839 enum qpnp_adc_meas_timer_2 meas_interval2;
840 enum qpnp_adc_tm_channel_select tm_channel_select;
841 enum qpnp_state_request state_request;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700842 struct qpnp_vadc_linear_graph adc_graph[2];
843};
844
845/**
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800846 * struct qpnp_vadc_result - Represent the result of the QPNP ADC.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700847 * @chan: The channel number of the requested conversion.
848 * @adc_code: The pre-calibrated digital output of a given ADC relative to the
849 * the ADC reference.
850 * @measurement: In units specific for a given ADC; most ADC uses reference
851 * voltage but some ADC uses reference current. This measurement
852 * here is a number relative to a reference of a given ADC.
853 * @physical: The data meaningful for each individual channel whether it is
854 * voltage, current, temperature, etc.
855 * All voltage units are represented in micro - volts.
856 * -Battery temperature units are represented as 0.1 DegC.
857 * -PA Therm temperature units are represented as DegC.
858 * -PMIC Die temperature units are represented as 0.001 DegC.
859 */
860struct qpnp_vadc_result {
861 uint32_t chan;
862 int32_t adc_code;
863 int64_t measurement;
864 int64_t physical;
865};
866
867/**
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800868 * struct qpnp_adc_amux - AMUX properties for individual channel
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700869 * @name: Channel string name.
870 * @channel_num: Channel in integer used from qpnp_adc_channels.
871 * @chan_path_prescaling: Channel scaling performed on the input signal.
872 * @adc_decimation: Sampling rate desired for the channel.
873 * adc_scale_fn: Scaling function to convert to the data meaningful for
874 * each individual channel whether it is voltage, current,
875 * temperature, etc and compensates the channel properties.
876 */
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800877struct qpnp_adc_amux {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700878 char *name;
879 enum qpnp_vadc_channels channel_num;
880 enum qpnp_adc_channel_scaling_param chan_path_prescaling;
881 enum qpnp_adc_decimation_type adc_decimation;
882 enum qpnp_adc_scale_fn_type adc_scale_fn;
883 enum qpnp_adc_fast_avg_ctl fast_avg_setup;
884 enum qpnp_adc_hw_settle_time hw_settle_time;
885};
886
887/**
888 * struct qpnp_vadc_scaling_ratio
889 *
890 */
891static const struct qpnp_vadc_scaling_ratio qpnp_vadc_amux_scaling_ratio[] = {
892 {1, 1},
893 {1, 3},
894 {1, 4},
895 {1, 6},
Dipen Parmar46f8ac62014-01-19 22:45:11 +0530896 {1, 20},
897 {1, 8}
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700898};
899
900/**
901 * struct qpnp_vadc_scale_fn - Scaling function prototype
902 * @chan: Function pointer to one of the scaling functions
903 * which takes the adc properties, channel properties,
904 * and returns the physical result
905 */
906struct qpnp_vadc_scale_fn {
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700907 int32_t (*chan) (struct qpnp_vadc_chip *, int32_t,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700908 const struct qpnp_adc_properties *,
909 const struct qpnp_vadc_chan_properties *,
910 struct qpnp_vadc_result *);
911};
912
913/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800914 * struct qpnp_adc_tm_reverse_scale_fn - Reverse scaling prototype
915 * @chan: Function pointer to one of the scaling functions
916 * which takes the adc properties, channel properties,
917 * and returns the physical result
918 */
919struct qpnp_adc_tm_reverse_scale_fn {
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -0700920 int32_t (*chan) (struct qpnp_vadc_chip *,
921 struct qpnp_adc_tm_btm_param *,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -0800922 uint32_t *, uint32_t *);
923};
924
925/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700926 * struct qpnp_iadc_calib - IADC channel calibration structure.
927 * @channel - Channel for which the historical offset and gain is
928 * calculated. Available channels are internal rsense,
929 * external rsense and alternate lead pairs.
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700930 * @offset_raw - raw Offset value for the channel.
931 * @gain_raw - raw Gain of the channel.
932 * @ideal_offset_uv - ideal offset value for the channel.
933 * @ideal_gain_nv - ideal gain for the channel.
934 * @offset_uv - converted value of offset in uV.
935 * @gain_uv - converted value of gain in uV.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700936 */
937struct qpnp_iadc_calib {
938 enum qpnp_iadc_channels channel;
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -0700939 uint16_t offset_raw;
940 uint16_t gain_raw;
941 uint32_t ideal_offset_uv;
942 uint32_t ideal_gain_nv;
943 uint32_t offset_uv;
944 uint32_t gain_uv;
945};
946
947/**
948 * struct qpnp_iadc_result - IADC read result structure.
949 * @oresult_uv - Result of ADC in uV.
950 * @result_ua - Result of ADC in uA.
951 */
952struct qpnp_iadc_result {
953 int32_t result_uv;
954 int32_t result_ua;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700955};
956
957/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700958 * struct qpnp_adc_drv - QPNP ADC device structure.
959 * @spmi - spmi device for ADC peripheral.
960 * @offset - base offset for the ADC peripheral.
961 * @adc_prop - ADC properties specific to the ADC peripheral.
962 * @amux_prop - AMUX properties representing the ADC peripheral.
963 * @adc_channels - ADC channel properties for the ADC peripheral.
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800964 * @adc_irq_eoc - End of Conversion IRQ.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800965 * @adc_irq_fifo_not_empty - Conversion sequencer request written
966 * to FIFO when not empty.
967 * @adc_irq_conv_seq_timeout - Conversion sequencer trigger timeout.
968 * @adc_high_thr_irq - Output higher than high threshold set for measurement.
969 * @adc_low_thr_irq - Output lower than low threshold set for measurement.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700970 * @adc_lock - ADC lock for access to the peripheral.
971 * @adc_rslt_completion - ADC result notification after interrupt
972 * is received.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700973 * @calib - Internal rsens calibration values for gain and offset.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700974 */
975struct qpnp_adc_drv {
976 struct spmi_device *spmi;
977 uint8_t slave;
978 uint16_t offset;
979 struct qpnp_adc_properties *adc_prop;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700980 struct qpnp_adc_amux_properties *amux_prop;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800981 struct qpnp_adc_amux *adc_channels;
Siddartha Mohanadoss12109952012-11-20 14:57:51 -0800982 int adc_irq_eoc;
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -0800983 int adc_irq_fifo_not_empty;
984 int adc_irq_conv_seq_timeout;
985 int adc_high_thr_irq;
986 int adc_low_thr_irq;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700987 struct mutex adc_lock;
988 struct completion adc_rslt_completion;
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700989 struct qpnp_iadc_calib calib;
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700990};
991
992/**
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -0700993 * struct qpnp_adc_amux_properties - QPNP VADC amux channel property.
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -0700994 * @amux_channel - Refer to the qpnp_vadc_channel list.
995 * @decimation - Sampling rate supported for the channel.
996 * @mode_sel - The basic mode of operation.
997 * @hw_settle_time - The time between AMUX being configured and the
998 * start of conversion.
999 * @fast_avg_setup - Ability to provide single result from the ADC
1000 * that is an average of multiple measurements.
1001 * @trigger_channel - HW trigger channel for conversion sequencer.
1002 * @chan_prop - Represent the channel properties of the ADC.
1003 */
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001004struct qpnp_adc_amux_properties {
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001005 uint32_t amux_channel;
1006 uint32_t decimation;
1007 uint32_t mode_sel;
1008 uint32_t hw_settle_time;
1009 uint32_t fast_avg_setup;
1010 enum qpnp_vadc_trigger trigger_channel;
1011 struct qpnp_vadc_chan_properties chan_prop[0];
1012};
1013
1014/* Public API */
1015#if defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE) \
1016 || defined(CONFIG_SENSORS_QPNP_ADC_VOLTAGE_MODULE)
1017/**
1018 * qpnp_vadc_read() - Performs ADC read on the channel.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001019 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001020 * @channel: Input channel to perform the ADC read.
1021 * @result: Structure pointer of type adc_chan_result
1022 * in which the ADC read results are stored.
1023 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001024int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev,
1025 enum qpnp_vadc_channels channel,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001026 struct qpnp_vadc_result *result);
1027
1028/**
1029 * qpnp_vadc_conv_seq_request() - Performs ADC read on the conversion
1030 * sequencer channel.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001031 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001032 * @channel: Input channel to perform the ADC read.
1033 * @result: Structure pointer of type adc_chan_result
1034 * in which the ADC read results are stored.
1035 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001036int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001037 enum qpnp_vadc_trigger trigger_channel,
1038 enum qpnp_vadc_channels channel,
1039 struct qpnp_vadc_result *result);
1040
1041/**
1042 * qpnp_vadc_check_result() - Performs check on the ADC raw code.
1043 * @data: Data used for verifying the range of the ADC code.
1044 */
1045int32_t qpnp_vadc_check_result(int32_t *data);
1046
1047/**
1048 * qpnp_adc_get_devicetree_data() - Abstracts the ADC devicetree data.
1049 * @spmi: spmi ADC device.
1050 * @adc_qpnp: spmi device tree node structure
1051 */
1052int32_t qpnp_adc_get_devicetree_data(struct spmi_device *spmi,
1053 struct qpnp_adc_drv *adc_qpnp);
1054
1055/**
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001056 * qpnp_adc_scale_default() - Scales the pre-calibrated digital output
1057 * of an ADC to the ADC reference and compensates for the
1058 * gain and offset.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001059 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001060 * @adc_code: pre-calibrated digital ouput of the ADC.
1061 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
1062 * reference voltage.
1063 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1064 * slope and offset.
1065 * @chan_rslt: Physical result to be stored.
1066 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001067int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *dev,
1068 int32_t adc_code,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001069 const struct qpnp_adc_properties *adc_prop,
1070 const struct qpnp_vadc_chan_properties *chan_prop,
1071 struct qpnp_vadc_result *chan_rslt);
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001072/**
1073 * qpnp_adc_scale_pmic_therm() - Scales the pre-calibrated digital output
1074 * of an ADC to the ADC reference and compensates for the
1075 * gain and offset. Performs the AMUX out as 2mV/K and returns
1076 * the temperature in milli degC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001077 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001078 * @adc_code: pre-calibrated digital ouput of the ADC.
1079 * @adc_prop: adc properties of the qpnp adc such as bit resolution,
1080 * reference voltage.
1081 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1082 * slope and offset.
1083 * @chan_rslt: Physical result to be stored.
1084 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001085int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *dev,
1086 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001087 const struct qpnp_adc_properties *adc_prop,
1088 const struct qpnp_vadc_chan_properties *chan_prop,
1089 struct qpnp_vadc_result *chan_rslt);
1090/**
1091 * qpnp_adc_scale_batt_therm() - Scales the pre-calibrated digital output
1092 * of an ADC to the ADC reference and compensates for the
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001093 * gain and offset. Returns the temperature in decidegC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001094 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001095 * @adc_code: pre-calibrated digital ouput of the ADC.
1096 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1097 * reference voltage.
1098 * @chan_prop: individual channel properties to compensate the i/p scaling,
1099 * slope and offset.
1100 * @chan_rslt: physical result to be stored.
1101 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001102int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *dev,
1103 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001104 const struct qpnp_adc_properties *adc_prop,
1105 const struct qpnp_vadc_chan_properties *chan_prop,
1106 struct qpnp_vadc_result *chan_rslt);
1107/**
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001108 * qpnp_adc_scale_qrd_batt_therm() - Scales the pre-calibrated digital output
1109 * of an ADC to the ADC reference and compensates for the
1110 * gain and offset. Returns the temperature in decidegC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001111 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001112 * @adc_code: pre-calibrated digital ouput of the ADC.
1113 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1114 * reference voltage.
1115 * @chan_prop: individual channel properties to compensate the i/p scaling,
1116 * slope and offset.
1117 * @chan_rslt: physical result to be stored.
1118 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001119int32_t qpnp_adc_scale_qrd_batt_therm(struct qpnp_vadc_chip *dev,
1120 int32_t adc_code,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001121 const struct qpnp_adc_properties *adc_prop,
1122 const struct qpnp_vadc_chan_properties *chan_prop,
1123 struct qpnp_vadc_result *chan_rslt);
1124/**
Xu Kai81c60522013-07-27 14:26:04 +08001125 * qpnp_adc_scale_qrd_skuaa_batt_therm() - Scales the pre-calibrated digital output
1126 * of an ADC to the ADC reference and compensates for the
1127 * gain and offset. Returns the temperature in decidegC.
1128 * @dev: Structure device for qpnp vadc
1129 * @adc_code: pre-calibrated digital ouput of the ADC.
1130 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1131 * reference voltage.
1132 * @chan_prop: individual channel properties to compensate the i/p scaling,
1133 * slope and offset.
1134 * @chan_rslt: physical result to be stored.
1135 */
1136int32_t qpnp_adc_scale_qrd_skuaa_batt_therm(struct qpnp_vadc_chip *dev,
1137 int32_t adc_code,
1138 const struct qpnp_adc_properties *adc_prop,
1139 const struct qpnp_vadc_chan_properties *chan_prop,
1140 struct qpnp_vadc_result *chan_rslt);
1141/**
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +08001142 * qpnp_adc_scale_qrd_skug_batt_therm() - Scales the pre-calibrated digital output
1143 * of an ADC to the ADC reference and compensates for the
1144 * gain and offset. Returns the temperature in decidegC.
1145 * @dev: Structure device for qpnp vadc
1146 * @adc_code: pre-calibrated digital ouput of the ADC.
1147 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1148 * reference voltage.
1149 * @chan_prop: individual channel properties to compensate the i/p scaling,
1150 * slope and offset.
1151 * @chan_rslt: physical result to be stored.
1152 */
1153int32_t qpnp_adc_scale_qrd_skug_batt_therm(struct qpnp_vadc_chip *dev,
1154 int32_t adc_code,
1155 const struct qpnp_adc_properties *adc_prop,
1156 const struct qpnp_vadc_chan_properties *chan_prop,
1157 struct qpnp_vadc_result *chan_rslt);
1158/**
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001159 * qpnp_adc_scale_batt_id() - Scales the pre-calibrated digital output
1160 * of an ADC to the ADC reference and compensates for the
1161 * gain and offset.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001162 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001163 * @adc_code: pre-calibrated digital ouput of the ADC.
1164 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1165 * reference voltage.
1166 * @chan_prop: individual channel properties to compensate the i/p scaling,
1167 * slope and offset.
1168 * @chan_rslt: physical result to be stored.
1169 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001170int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001171 const struct qpnp_adc_properties *adc_prop,
1172 const struct qpnp_vadc_chan_properties *chan_prop,
1173 struct qpnp_vadc_result *chan_rslt);
1174/**
1175 * qpnp_adc_scale_tdkntcg_therm() - Scales the pre-calibrated digital output
1176 * of an ADC to the ADC reference and compensates for the
1177 * gain and offset. Returns the temperature of the xo therm in mili
1178 degC.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001179 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001180 * @adc_code: pre-calibrated digital ouput of the ADC.
1181 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1182 * reference voltage.
1183 * @chan_prop: individual channel properties to compensate the i/p scaling,
1184 * slope and offset.
1185 * @chan_rslt: physical result to be stored.
1186 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001187int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001188 const struct qpnp_adc_properties *adc_prop,
1189 const struct qpnp_vadc_chan_properties *chan_prop,
1190 struct qpnp_vadc_result *chan_rslt);
1191/**
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001192 * qpnp_adc_scale_therm_pu1() - Scales the pre-calibrated digital output
1193 * of an ADC to the ADC reference and compensates for the
1194 * gain and offset. Returns the temperature of the therm in degC.
1195 * It uses a mapping table computed for a 150K pull-up.
1196 * Pull-up1 is an internal pull-up on the AMUX of 150K.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001197 * @dev: Structure device for qpnp vadc
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001198 * @adc_code: pre-calibrated digital ouput of the ADC.
1199 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1200 * reference voltage.
1201 * @chan_prop: individual channel properties to compensate the i/p scaling,
1202 * slope and offset.
1203 * @chan_rslt: physical result to be stored.
1204 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001205int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001206 const struct qpnp_adc_properties *adc_prop,
1207 const struct qpnp_vadc_chan_properties *chan_prop,
1208 struct qpnp_vadc_result *chan_rslt);
1209/**
1210 * qpnp_adc_scale_therm_pu2() - Scales the pre-calibrated digital output
1211 * of an ADC to the ADC reference and compensates for the
1212 * gain and offset. Returns the temperature of the therm in degC.
1213 * It uses a mapping table computed for a 100K pull-up.
1214 * Pull-up2 is an internal pull-up on the AMUX of 100K.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001215 * @dev: Structure device for qpnp vadc
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001216 * @adc_code: pre-calibrated digital ouput of the ADC.
1217 * @adc_prop: adc properties of the pm8xxx adc such as bit resolution,
1218 * reference voltage.
1219 * @chan_prop: individual channel properties to compensate the i/p scaling,
1220 * slope and offset.
1221 * @chan_rslt: physical result to be stored.
1222 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001223int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *dev, int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001224 const struct qpnp_adc_properties *adc_prop,
1225 const struct qpnp_vadc_chan_properties *chan_prop,
1226 struct qpnp_vadc_result *chan_rslt);
1227/**
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001228 * qpnp_get_vadc() - Clients need to register with the vadc using the
1229 * corresponding device instance it wants to read the channels
1230 * from. Read the bindings document on how to pass the phandle
1231 * for the corresponding vadc driver to register with.
1232 * @dev: Clients device structure
1233 * @name: Corresponding client's DT parser name. Read the DT bindings
1234 * document on how to register with the vadc
1235 * @struct qpnp_vadc_chip * - On success returns the vadc device structure
1236 * pointer that needs to be used during an ADC request.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001237 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001238struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev, const char *name);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001239/**
1240 * qpnp_adc_tm_scaler() - Performs reverse calibration.
1241 * @config: Thermal monitoring configuration.
1242 * @adc_prop: adc properties of the qpnp adc such as bit resolution and
1243 * reference voltage.
1244 * @chan_prop: Individual channel properties to compensate the i/p scaling,
1245 * slope and offset.
1246 */
1247static inline int32_t qpnp_adc_tm_scaler(struct qpnp_adc_tm_config *tm_config,
1248 const struct qpnp_adc_properties *adc_prop,
1249 const struct qpnp_vadc_chan_properties *chan_prop)
1250{ return -ENXIO; }
1251/**
1252 * qpnp_get_vadc_gain_and_offset() - Obtains the VADC gain and offset
1253 * for absolute and ratiometric calibration.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001254 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001255 * @param: The result in which the ADC offset and gain values are stored.
1256 * @type: The calibration type whether client needs the absolute or
1257 * ratiometric gain and offset values.
1258 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001259int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev,
1260 struct qpnp_vadc_linear_graph *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001261 enum qpnp_adc_calib_type calib_type);
1262/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001263 * qpnp_adc_scale_millidegc_pmic_voltage_thr() - Performs reverse calibration
1264 * on the low/high temperature threshold values passed by the
1265 * client. The function coverts milldegC to voltage threshold
1266 * and accounts for the corresponding channels scaling as (2mV/K).
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001267 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001268 * @param: The input parameters that contain the low/high temperature
1269 * values.
1270 * @low_threshold: The low threshold value that needs to be updated with
1271 * the above calibrated voltage value.
1272 * @high_threshold: The low threshold value that needs to be updated with
1273 * the above calibrated voltage value.
1274 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001275int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001276 struct qpnp_adc_tm_btm_param *param,
1277 uint32_t *low_threshold, uint32_t *high_threshold);
1278/**
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001279 * qpnp_adc_btm_scaler() - Performs reverse calibration on the low/high
1280 * temperature threshold values passed by the client.
1281 * The function maps the temperature to voltage and applies
1282 * ratiometric calibration on the voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001283 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001284 * @param: The input parameters that contain the low/high temperature
1285 * values.
1286 * @low_threshold: The low threshold value that needs to be updated with
1287 * the above calibrated voltage value.
1288 * @high_threshold: The low threshold value that needs to be updated with
1289 * the above calibrated voltage value.
1290 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001291int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev,
1292 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001293 uint32_t *low_threshold, uint32_t *high_threshold);
1294/**
1295 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1296 * and convert given temperature to voltage on supported
1297 * thermistor channels using 100k pull-up.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001298 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001299 * @param: The input temperature values.
1300 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001301int32_t qpnp_adc_tm_scale_therm_voltage_pu2(struct qpnp_vadc_chip *dev,
1302 struct qpnp_adc_tm_config *param);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001303/**
1304 * qpnp_adc_tm_scale_therm_voltage_pu2() - Performs reverse calibration
1305 * and converts the given ADC code to temperature for
1306 * thermistor channels using 100k pull-up.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001307 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001308 * @reg: The input ADC code.
1309 * @result: The physical measurement temperature on the thermistor.
1310 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001311int32_t qpnp_adc_tm_scale_voltage_therm_pu2(struct qpnp_vadc_chip *dev,
1312 uint32_t reg, int64_t *result);
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001313/**
1314 * qpnp_adc_usb_scaler() - Performs reverse calibration on the low/high
1315 * voltage threshold values passed by the client.
1316 * The function applies ratiometric calibration on the
1317 * voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001318 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001319 * @param: The input parameters that contain the low/high voltage
1320 * threshold values.
1321 * @low_threshold: The low threshold value that needs to be updated with
1322 * the above calibrated voltage value.
1323 * @high_threshold: The low threshold value that needs to be updated with
1324 * the above calibrated voltage value.
1325 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001326int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev,
1327 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001328 uint32_t *low_threshold, uint32_t *high_threshold);
1329/**
1330 * qpnp_adc_vbatt_rscaler() - Performs reverse calibration on the low/high
1331 * voltage threshold values passed by the client.
1332 * The function applies ratiometric calibration on the
1333 * voltage values.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001334 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001335 * @param: The input parameters that contain the low/high voltage
1336 * threshold values.
1337 * @low_threshold: The low threshold value that needs to be updated with
1338 * the above calibrated voltage value.
1339 * @high_threshold: The low threshold value that needs to be updated with
1340 * the above calibrated voltage value.
1341 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001342int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
1343 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001344 uint32_t *low_threshold, uint32_t *high_threshold);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001345/**
1346 * qpnp_vadc_iadc_sync_request() - Performs Voltage ADC read and
1347 * locks the peripheral. When performing simultaneous
1348 * voltage and current request the VADC peripheral is
1349 * prepared for conversion and the IADC sync conversion
1350 * is done from the IADC peripheral.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001351 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001352 * @channel: Input channel to perform the voltage ADC read.
1353 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001354int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev,
1355 enum qpnp_vadc_channels channel);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001356/**
1357 * qpnp_vadc_iadc_sync_complete_request() - Reads the ADC result and
1358 * unlocks the peripheral.
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001359 * @dev: Structure device for qpnp vadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001360 * @result: Structure pointer of type adc_chan_result
1361 * in which the ADC read results are stored.
1362 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001363int32_t qpnp_vadc_iadc_sync_complete_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001364 enum qpnp_vadc_channels channel, struct qpnp_vadc_result *result);
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001365/**
1366 * qpnp_vadc_sns_comp_result() - Compensate vbatt readings based on temperature
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001367 * @dev: Structure device for qpnp vadc
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001368 * @result: Voltage in uV that needs compensation.
1369 */
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001370int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev,
1371 int64_t *result);
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001372#else
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001373static inline int32_t qpnp_vadc_read(struct qpnp_vadc_chip *dev,
1374 uint32_t channel,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001375 struct qpnp_vadc_result *result)
1376{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001377static inline int32_t qpnp_vadc_conv_seq_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001378 enum qpnp_vadc_trigger trigger_channel,
1379 enum qpnp_vadc_channels channel,
1380 struct qpnp_vadc_result *result)
1381{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001382static inline int32_t qpnp_adc_scale_default(struct qpnp_vadc_chip *vadc,
1383 int32_t adc_code,
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001384 const struct qpnp_adc_properties *adc_prop,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001385 const struct qpnp_vadc_chan_properties *chan_prop,
1386 struct qpnp_vadc_result *chan_rslt)
1387{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001388static inline int32_t qpnp_adc_scale_pmic_therm(struct qpnp_vadc_chip *vadc,
1389 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001390 const struct qpnp_adc_properties *adc_prop,
1391 const struct qpnp_vadc_chan_properties *chan_prop,
1392 struct qpnp_vadc_result *chan_rslt)
1393{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001394static inline int32_t qpnp_adc_scale_batt_therm(struct qpnp_vadc_chip *vadc,
1395 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001396 const struct qpnp_adc_properties *adc_prop,
1397 const struct qpnp_vadc_chan_properties *chan_prop,
1398 struct qpnp_vadc_result *chan_rslt)
1399{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001400static inline int32_t qpnp_adc_scale_qrd_batt_therm(
1401 struct qpnp_vadc_chip *vadc, int32_t adc_code,
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001402 const struct qpnp_adc_properties *adc_prop,
1403 const struct qpnp_vadc_chan_properties *chan_prop,
Xu Kai81c60522013-07-27 14:26:04 +08001404 struct qpnp_vadc_result *chan_rslt)
1405{ return -ENXIO; }
1406static inline int32_t qpnp_adc_scale_qrd_skuaa_batt_therm(
1407 struct qpnp_vadc_chip *vadc, int32_t adc_code,
1408 const struct qpnp_adc_properties *adc_prop,
1409 const struct qpnp_vadc_chan_properties *chan_prop,
1410 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadossb99cfa92013-05-01 20:19:58 -07001411{ return -ENXIO; }
Wu Fenglin2c6ef8f2013-12-17 11:33:33 +08001412static inline int32_t qpnp_adc_scale_qrd_skug_batt_therm(
1413 struct qpnp_vadc_chip *vadc, int32_t adc_code,
1414 const struct qpnp_adc_properties *adc_prop,
1415 const struct qpnp_vadc_chan_properties *chan_prop,
1416 struct qpnp_vadc_result *chan_rslt)
1417{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001418static inline int32_t qpnp_adc_scale_batt_id(struct qpnp_vadc_chip *vadc,
1419 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001420 const struct qpnp_adc_properties *adc_prop,
1421 const struct qpnp_vadc_chan_properties *chan_prop,
1422 struct qpnp_vadc_result *chan_rslt)
1423{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001424static inline int32_t qpnp_adc_tdkntcg_therm(struct qpnp_vadc_chip *vadc,
1425 int32_t adc_code,
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001426 const struct qpnp_adc_properties *adc_prop,
1427 const struct qpnp_vadc_chan_properties *chan_prop,
1428 struct qpnp_vadc_result *chan_rslt)
1429{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001430static inline int32_t qpnp_adc_scale_therm_pu1(struct qpnp_vadc_chip *vadc,
1431 int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001432 const struct qpnp_adc_properties *adc_prop,
1433 const struct qpnp_vadc_chan_properties *chan_prop,
David Keitelc96dc852013-03-04 14:57:34 -08001434 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001435{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001436static inline int32_t qpnp_adc_scale_therm_pu2(struct qpnp_vadc_chip *vadc,
1437 int32_t adc_code,
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001438 const struct qpnp_adc_properties *adc_prop,
1439 const struct qpnp_vadc_chan_properties *chan_prop,
David Keitelc96dc852013-03-04 14:57:34 -08001440 struct qpnp_vadc_result *chan_rslt)
Siddartha Mohanadosse77edf12012-09-13 14:26:32 -07001441{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001442static inline struct qpnp_vadc_chip *qpnp_get_vadc(struct device *dev,
1443 const char *name)
1444{ return ERR_PTR(-ENXIO); }
1445static inline int32_t qpnp_get_vadc_gain_and_offset(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001446 struct qpnp_vadc_linear_graph *param,
1447 enum qpnp_adc_calib_type calib_type)
1448{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001449static inline int32_t qpnp_adc_usb_scaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001450 struct qpnp_adc_tm_btm_param *param,
1451 uint32_t *low_threshold, uint32_t *high_threshold)
1452{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001453static inline int32_t qpnp_adc_vbatt_rscaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001454 struct qpnp_adc_tm_btm_param *param,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001455 uint32_t *low_threshold, uint32_t *high_threshold)
1456{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001457static inline int32_t qpnp_adc_btm_scaler(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001458 struct qpnp_adc_tm_btm_param *param,
1459 uint32_t *low_threshold, uint32_t *high_threshold)
1460{ return -ENXIO; }
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001461static inline int32_t qpnp_adc_scale_millidegc_pmic_voltage_thr(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001462 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001463 struct qpnp_adc_tm_btm_param *param,
1464 uint32_t *low_threshold, uint32_t *high_threshold)
1465{ return -ENXIO; }
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001466static inline int32_t qpnp_adc_tm_scale_therm_voltage_pu2(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001467 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001468 struct qpnp_adc_tm_config *param)
1469{ return -ENXIO; }
1470static inline int32_t qpnp_adc_tm_scale_voltage_therm_pu2(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001471 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossd0f4fd12012-11-20 16:28:40 -08001472 uint32_t reg, int64_t *result)
1473{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001474static inline int32_t qpnp_vadc_iadc_sync_request(struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001475 enum qpnp_vadc_channels channel)
1476{ return -ENXIO; }
1477static inline int32_t qpnp_vadc_iadc_sync_complete_request(
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001478 struct qpnp_vadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001479 enum qpnp_vadc_channels channel,
1480 struct qpnp_vadc_result *result)
1481{ return -ENXIO; }
Siddartha Mohanadoss3cb2b6b2013-06-21 12:07:05 -07001482static inline int32_t qpnp_vbat_sns_comp_result(struct qpnp_vadc_chip *dev,
1483 int64_t *result)
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001484{ return -ENXIO; }
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001485#endif
1486
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001487/* Public API */
1488#if defined(CONFIG_SENSORS_QPNP_ADC_CURRENT) \
1489 || defined(CONFIG_SENSORS_QPNP_ADC_CURRENT_MODULE)
1490/**
1491 * qpnp_iadc_read() - Performs ADC read on the current channel.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001492 * @dev: Structure device for qpnp iadc
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001493 * @channel: Input channel to perform the ADC read.
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001494 * @result: Current across rsense in mA.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001495 * @return: 0 on success.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001496 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001497int32_t qpnp_iadc_read(struct qpnp_iadc_chip *dev,
1498 enum qpnp_iadc_channels channel,
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001499 struct qpnp_iadc_result *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001500/**
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001501 * qpnp_iadc_get_rsense() - Reads the RDS resistance value from the
1502 trim registers.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001503 * @dev: Structure device for qpnp iadc
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001504 * @rsense: RDS resistance in nOhms.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001505 * @return: 0 on success.
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001506 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001507int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *dev, int32_t *rsense);
Xiaozhe Shi767fdb62013-01-10 15:09:08 -08001508/**
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001509 * qpnp_iadc_get_gain_and_offset() - Performs gain calibration
1510 * over 17.8571mV and offset over selected
1511 * channel. Channel can be internal rsense,
1512 * external rsense and alternate lead pair.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001513 * @dev: Structure device for qpnp iadc
Siddartha Mohanadoss5e2988d2012-09-24 17:03:56 -07001514 * @result: result structure where the gain and offset is stored of
1515 * type qpnp_iadc_calib.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001516 * @return: 0 on success.
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001517 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001518int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *dev,
1519 struct qpnp_iadc_calib *result);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001520/**
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001521 * qpnp_get_iadc() - Clients need to register with the iadc with the
1522 * corresponding device instance it wants to read the channels.
1523 * Read the bindings document on how to pass the phandle for
1524 * the corresponding vadc driver to register with.
1525 * @dev: Clients device structure
1526 * @name: Corresponding client's DT parser name. Read the DT bindings
1527 * document on how to register with the iadc
1528 * @struct qpnp_iadc_chip * - On success returns the iadc device structure
1529 * pointer used everytime client makes an ADC request.
Siddartha Mohanadoss5ace1102012-08-20 23:18:10 -07001530 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001531struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev, const char *name);
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001532/**
1533 * qpnp_iadc_vadc_sync_read() - Performs synchronous VADC and IADC read.
1534 * The api is to be used only by the BMS to perform
1535 * simultaneous VADC and IADC measurement for battery voltage
1536 * and current.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001537 * @dev: Structure device for qpnp iadc
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001538 * @i_channel: Input battery current channel to perform the IADC read.
1539 * @i_result: Current across the rsense in mA.
1540 * @v_channel: Input battery voltage channel to perform VADC read.
1541 * @v_result: Voltage on the vbatt channel with units in mV.
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001542 * @return: 0 on success.
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001543 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001544int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *dev,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001545 enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result,
1546 enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result);
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001547/**
Abhijeet Dharmapurikar0ef9b5c2013-07-15 18:24:38 -07001548 * qpnp_iadc_calibrate_for_trim - Clients can use this API to re-calibrate
1549 * IADC. The offset and gain values are programmed in the trim
1550 * registers. The offset and the gain can be retrieved using
1551 * qpnp_iadc_get_gain_and_offset
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001552 * @dev: Structure device for qpnp iadc
Abhijeet Dharmapurikar0ef9b5c2013-07-15 18:24:38 -07001553 * @batfet_closed: batfet is opened or closed. The IADC chooses proper
1554 * channel (internal/external) based on batfet status
1555 * for calibration.
1556 * RETURNS: 0 on success.
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001557 */
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001558int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *dev,
1559 bool batfet_closed);
1560/**
1561 * qpnp_iadc_comp_result() - Compensates the result of the current based on
1562 * the gain and offset co-effients and rsense parameters.
1563 * @dev: Structure device for qpnp iadc
1564 * @result: Current value to perform the compensation.
1565 * @return: 0 on success.
1566 */
1567int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *dev, int64_t *result);
1568/**
1569 * qpnp_iadc_skip_calibration() - Clients can use this API to ask the driver
1570 * to skip iadc calibrations
1571 * @dev: Structure device for qpnp iadc
1572 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1573 * has not occured.
1574 */
1575int qpnp_iadc_skip_calibration(struct qpnp_iadc_chip *dev);
1576/**
1577 * qpnp_iadc_resume_calibration() - Clients can use this API to ask the driver
1578 * to resume iadc calibrations
1579 * @dev: Structure device for qpnp iadc
1580 * @result: 0 on success and -EPROBE_DEFER when probe for the device
1581 * has not occured.
1582 */
1583int qpnp_iadc_resume_calibration(struct qpnp_iadc_chip *dev);
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001584#else
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001585static inline int32_t qpnp_iadc_read(struct qpnp_iadc_chip *iadc,
1586 enum qpnp_iadc_channels channel, struct qpnp_iadc_result *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001587{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001588static inline int32_t qpnp_iadc_get_rsense(struct qpnp_iadc_chip *iadc,
1589 int32_t *rsense)
Siddartha Mohanadoss563166b2013-02-20 12:47:24 -08001590{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001591static inline int32_t qpnp_iadc_get_gain_and_offset(struct qpnp_iadc_chip *iadc,
1592 struct qpnp_iadc_calib *result)
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001593{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001594static inline struct qpnp_iadc_chip *qpnp_get_iadc(struct device *dev,
1595 const char *name)
1596{ return ERR_PTR(-ENXIO); }
1597static inline int32_t qpnp_iadc_vadc_sync_read(struct qpnp_iadc_chip *iadc,
Siddartha Mohanadossa32ea2a2013-02-12 09:58:31 -08001598 enum qpnp_iadc_channels i_channel, struct qpnp_iadc_result *i_result,
1599 enum qpnp_vadc_channels v_channel, struct qpnp_vadc_result *v_result)
1600{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001601static inline int32_t qpnp_iadc_calibrate_for_trim(struct qpnp_iadc_chip *iadc,
1602 bool batfet_closed)
Siddartha Mohanadoss06673922013-03-27 11:14:19 -07001603{ return -ENXIO; }
Siddartha Mohanadoss55d0bca2013-06-24 08:29:34 -07001604static inline int32_t qpnp_iadc_comp_result(struct qpnp_iadc_chip *iadc,
1605 int64_t *result, int32_t sign)
Siddartha Mohanadoss4e64f8c2013-04-08 15:57:32 -07001606{ return -ENXIO; }
Siddartha Mohanadossc4a6af12012-07-13 18:50:12 -07001607#endif
1608
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001609/* Public API */
1610#if defined(CONFIG_THERMAL_QPNP_ADC_TM) \
1611 || defined(CONFIG_THERMAL_QPNP_ADC_TM_MODULE)
1612/**
1613 * qpnp_adc_tm_usbid_configure() - Configures Channel 0 of VADC_BTM to
1614 * monitor USB_ID channel using 100k internal pull-up.
1615 * USB driver passes the high/low voltage threshold along
1616 * with the notification callback once the set thresholds
1617 * are crossed.
1618 * @param: Structure pointer of qpnp_adc_tm_usbid_param type.
1619 * Clients pass the low/high voltage along with the threshold
1620 * notification callback.
1621 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001622int32_t qpnp_adc_tm_usbid_configure(struct qpnp_adc_tm_chip *chip,
1623 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001624/**
1625 * qpnp_adc_tm_usbid_end() - Disables the monitoring of channel 0 thats
1626 * assigned for monitoring USB_ID. Disables the low/high
1627 * threshold activation for channel 0 as well.
1628 * @param: none.
1629 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001630int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001631/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001632 * qpnp_adc_tm_channel_measure() - Configures kernel clients a channel to
1633 * monitor the corresponding ADC channel for threshold detection.
1634 * Driver passes the high/low voltage threshold along
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001635 * with the notification callback once the set thresholds
1636 * are crossed.
1637 * @param: Structure pointer of qpnp_adc_tm_btm_param type.
1638 * Clients pass the low/high temperature along with the threshold
1639 * notification callback.
1640 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001641int32_t qpnp_adc_tm_channel_measure(struct qpnp_adc_tm_chip *chip,
1642 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001643/**
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001644 * qpnp_adc_tm_disable_chan_meas() - Disables the monitoring of channel thats
1645 * assigned for monitoring kernel clients. Disables the low/high
1646 * threshold activation for the corresponding channel.
1647 * @param: Structure pointer of qpnp_adc_tm_btm_param type.
1648 * This is used to identify the channel for which the corresponding
1649 * channels high/low threshold notification will be disabled.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001650 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001651int32_t qpnp_adc_tm_disable_chan_meas(struct qpnp_adc_tm_chip *chip,
1652 struct qpnp_adc_tm_btm_param *param);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001653/**
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001654 * qpnp_get_adc_tm() - Clients need to register with the adc_tm using the
1655 * corresponding device instance it wants to read the channels
1656 * from. Read the bindings document on how to pass the phandle
1657 * for the corresponding adc_tm driver to register with.
1658 * @name: Corresponding client's DT parser name. Read the DT bindings
1659 * document on how to register with the vadc
1660 * @struct qpnp_adc_tm_chip * - On success returns the vadc device structure
1661 * pointer that needs to be used during an ADC TM request.
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001662 */
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001663struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev, const char *name);
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001664#else
1665static inline int32_t qpnp_adc_tm_usbid_configure(
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001666 struct qpnp_adc_tm_chip *chip,
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001667 struct qpnp_adc_tm_btm_param *param)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001668{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001669static inline int32_t qpnp_adc_tm_usbid_end(struct qpnp_adc_tm_chip *chip)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001670{ return -ENXIO; }
Siddartha Mohanadossa3e35512013-02-22 17:06:07 -08001671static inline int32_t qpnp_adc_tm_channel_measure(
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001672 struct qpnp_adc_tm_chip *chip,
1673 struct qpnp_adc_tm_btm_param *param)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001674{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001675static inline int32_t qpnp_adc_tm_disable_chan_meas(
1676 struct qpnp_adc_tm_chip *chip)
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001677{ return -ENXIO; }
Siddartha Mohanadoss88a3fde2013-06-24 16:18:52 -07001678static inline struct qpnp_adc_tm_chip *qpnp_get_adc_tm(struct device *dev,
1679 const char *name)
1680{ return ERR_PTR(-ENXIO); }
Siddartha Mohanadoss31f60962012-11-27 14:11:02 -08001681#endif
1682
Siddartha Mohanadoss7b116e12012-06-05 23:27:46 -07001683#endif