/* SPDX-License-Identifier: GPL-2.0 */ /* * Code shared between the different Qualcomm PMIC voltage ADCs */ #ifndef QCOM_VADC_COMMON_H #define QCOM_VADC_COMMON_H #include <linux/math.h> #include <linux/types.h> #define VADC_CONV_TIME_MIN_US … #define VADC_CONV_TIME_MAX_US … /* Min ADC code represents 0V */ #define VADC_MIN_ADC_CODE … /* Max ADC code represents full-scale range of 1.8V */ #define VADC_MAX_ADC_CODE … #define VADC_ABSOLUTE_RANGE_UV … #define VADC_RATIOMETRIC_RANGE … #define VADC_DEF_PRESCALING … #define VADC_DEF_DECIMATION … #define VADC_DEF_HW_SETTLE_TIME … #define VADC_DEF_AVG_SAMPLES … #define VADC_DEF_CALIB_TYPE … #define VADC_DECIMATION_MIN … #define VADC_DECIMATION_MAX … #define ADC5_DEF_VBAT_PRESCALING … #define ADC5_DECIMATION_SHORT … #define ADC5_DECIMATION_MEDIUM … #define ADC5_DECIMATION_LONG … /* Default decimation - 1024 for rev2, 840 for pmic5 */ #define ADC5_DECIMATION_DEFAULT … #define ADC5_DECIMATION_SAMPLES_MAX … #define VADC_HW_SETTLE_DELAY_MAX … #define VADC_HW_SETTLE_SAMPLES_MAX … #define VADC_AVG_SAMPLES_MAX … #define ADC5_AVG_SAMPLES_MAX … #define PMIC5_CHG_TEMP_SCALE_FACTOR … #define PMIC5_SMB_TEMP_CONSTANT … #define PMIC5_SMB_TEMP_SCALE_FACTOR … #define PMI_CHG_SCALE_1 … #define PMI_CHG_SCALE_2 … #define VADC5_MAX_CODE … #define ADC5_FULL_SCALE_CODE … #define ADC5_USR_DATA_CHECK … #define R_PU_100K … #define RATIO_MAX_ADC7 … /* * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels. * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for * calibration. */ enum vadc_calibration { … }; /** * struct vadc_linear_graph - Represent ADC characteristics. * @dy: numerator slope to calculate the gain. * @dx: denominator slope to calculate the gain. * @gnd: A/D word of the ground reference used for the channel. * * Each ADC device has different offset and gain parameters which are * computed to calibrate the device. */ struct vadc_linear_graph { … }; /** * enum vadc_scale_fn_type - Scaling function to convert ADC code to * physical scaled units for the channel. * SCALE_DEFAULT: Default scaling to convert raw adc code to voltage (uV). * SCALE_THERM_100K_PULLUP: Returns temperature in millidegC. * Uses a mapping table with 100K pullup. * SCALE_PMIC_THERM: Returns result in milli degree's Centigrade. * SCALE_XOTHERM: Returns XO thermistor voltage in millidegC. * SCALE_PMI_CHG_TEMP: Conversion for PMI CHG temp * SCALE_HW_CALIB_DEFAULT: Default scaling to convert raw adc code to * voltage (uV) with hardware applied offset/slope values to adc code. * SCALE_HW_CALIB_THERM_100K_PULLUP: Returns temperature in millidegC using * lookup table. The hardware applies offset/slope to adc code. * SCALE_HW_CALIB_XOTHERM: Returns XO thermistor voltage in millidegC using * 100k pullup. The hardware applies offset/slope to adc code. * SCALE_HW_CALIB_THERM_100K_PU_PM7: Returns temperature in millidegC using * lookup table for PMIC7. The hardware applies offset/slope to adc code. * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. * The hardware applies offset/slope to adc code. * SCALE_HW_CALIB_PMIC_THERM: Returns result in milli degree's Centigrade. * The hardware applies offset/slope to adc code. This is for PMIC7. * SCALE_HW_CALIB_PM5_CHG_TEMP: Returns result in millidegrees for PMIC5 * charger temperature. * SCALE_HW_CALIB_PM5_SMB_TEMP: Returns result in millidegrees for PMIC5 * SMB1390 temperature. */ enum vadc_scale_fn_type { … }; struct adc5_data { … }; int qcom_vadc_scale(enum vadc_scale_fn_type scaletype, const struct vadc_linear_graph *calib_graph, const struct u32_fract *prescale, bool absolute, u16 adc_code, int *result_mdec); struct qcom_adc5_scale_type { … }; int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype, unsigned int prescale_ratio, const struct adc5_data *data, u16 adc_code, int *result_mdec); u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio, u32 full_scale_code_volt, int temp); u16 qcom_adc_tm5_gen2_temp_res_scale(int temp); int qcom_adc5_prescaling_from_dt(u32 num, u32 den); int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle); int qcom_adc5_avg_samples_from_dt(u32 value); int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation); int qcom_vadc_decimation_from_dt(u32 value); #endif /* QCOM_VADC_COMMON_H */