1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Code shared between the different Qualcomm PMIC voltage ADCs
6 #ifndef QCOM_VADC_COMMON_H
7 #define QCOM_VADC_COMMON_H
9 #define VADC_CONV_TIME_MIN_US 2000
10 #define VADC_CONV_TIME_MAX_US 2100
12 /* Min ADC code represents 0V */
13 #define VADC_MIN_ADC_CODE 0x6000
14 /* Max ADC code represents full-scale range of 1.8V */
15 #define VADC_MAX_ADC_CODE 0xa800
17 #define VADC_ABSOLUTE_RANGE_UV 625000
18 #define VADC_RATIOMETRIC_RANGE 1800
20 #define VADC_DEF_PRESCALING 0 /* 1:1 */
21 #define VADC_DEF_DECIMATION 0 /* 512 */
22 #define VADC_DEF_HW_SETTLE_TIME 0 /* 0 us */
23 #define VADC_DEF_AVG_SAMPLES 0 /* 1 sample */
24 #define VADC_DEF_CALIB_TYPE VADC_CALIB_ABSOLUTE
26 #define VADC_DECIMATION_MIN 512
27 #define VADC_DECIMATION_MAX 4096
29 #define VADC_HW_SETTLE_DELAY_MAX 10000
30 #define VADC_AVG_SAMPLES_MAX 512
32 #define KELVINMIL_CELSIUSMIL 273150
34 #define PMI_CHG_SCALE_1 -138890
35 #define PMI_CHG_SCALE_2 391750000000LL
38 * struct vadc_map_pt - Map the graph representation for ADC channel
39 * @x: Represent the ADC digitized code.
40 * @y: Represent the physical data which can be temperature, voltage,
49 * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
50 * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for
53 enum vadc_calibration
{
54 VADC_CALIB_ABSOLUTE
= 0,
55 VADC_CALIB_RATIOMETRIC
59 * struct vadc_linear_graph - Represent ADC characteristics.
60 * @dy: numerator slope to calculate the gain.
61 * @dx: denominator slope to calculate the gain.
62 * @gnd: A/D word of the ground reference used for the channel.
64 * Each ADC device has different offset and gain parameters which are
65 * computed to calibrate the device.
67 struct vadc_linear_graph
{
74 * struct vadc_prescale_ratio - Represent scaling ratio for ADC input.
75 * @num: the inverse numerator of the gain applied to the input channel.
76 * @den: the inverse denominator of the gain applied to the input channel.
78 struct vadc_prescale_ratio
{
84 * enum vadc_scale_fn_type - Scaling function to convert ADC code to
85 * physical scaled units for the channel.
86 * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV).
87 * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC.
88 * Uses a mapping table with 100K pullup.
89 * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade.
90 * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC.
91 * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp
93 enum vadc_scale_fn_type
{
95 SCALE_THERM_100K_PULLUP
,
101 int qcom_vadc_scale(enum vadc_scale_fn_type scaletype
,
102 const struct vadc_linear_graph
*calib_graph
,
103 const struct vadc_prescale_ratio
*prescale
,
105 u16 adc_code
, int *result_mdec
);
107 int qcom_vadc_decimation_from_dt(u32 value
);
109 #endif /* QCOM_VADC_COMMON_H */