]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/iio/adc/qcom-vadc-common.h
Input: wm97xx: add new AC97 bus support
[mirror_ubuntu-focal-kernel.git] / drivers / iio / adc / qcom-vadc-common.h
CommitLineData
e932d4f0
LW
1/*
2 * Code shared between the different Qualcomm PMIC voltage ADCs
3 */
4
5#ifndef QCOM_VADC_COMMON_H
6#define QCOM_VADC_COMMON_H
7
8#define VADC_CONV_TIME_MIN_US 2000
9#define VADC_CONV_TIME_MAX_US 2100
10
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
15
16#define VADC_ABSOLUTE_RANGE_UV 625000
17#define VADC_RATIOMETRIC_RANGE 1800
18
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
24
25#define VADC_DECIMATION_MIN 512
26#define VADC_DECIMATION_MAX 4096
27
28#define VADC_HW_SETTLE_DELAY_MAX 10000
29#define VADC_AVG_SAMPLES_MAX 512
30
31#define KELVINMIL_CELSIUSMIL 273150
32
33#define PMI_CHG_SCALE_1 -138890
34#define PMI_CHG_SCALE_2 391750000000LL
35
36/**
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,
40 * resistance.
41 */
42struct vadc_map_pt {
43 s32 x;
44 s32 y;
45};
46
47/*
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
50 * calibration.
51 */
52enum vadc_calibration {
53 VADC_CALIB_ABSOLUTE = 0,
54 VADC_CALIB_RATIOMETRIC
55};
56
57/**
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.
62 *
63 * Each ADC device has different offset and gain parameters which are
64 * computed to calibrate the device.
65 */
66struct vadc_linear_graph {
67 s32 dy;
68 s32 dx;
69 s32 gnd;
70};
71
72/**
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.
76 */
77struct vadc_prescale_ratio {
78 u32 num;
79 u32 den;
80};
81
82/**
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
91 */
92enum vadc_scale_fn_type {
93 SCALE_DEFAULT = 0,
94 SCALE_THERM_100K_PULLUP,
95 SCALE_PMIC_THERM,
96 SCALE_XOTHERM,
97 SCALE_PMI_CHG_TEMP,
98};
99
100int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
101 const struct vadc_linear_graph *calib_graph,
102 const struct vadc_prescale_ratio *prescale,
103 bool absolute,
104 u16 adc_code, int *result_mdec);
105
106int qcom_vadc_decimation_from_dt(u32 value);
107
108#endif /* QCOM_VADC_COMMON_H */