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