0001
0002
0003
0004
0005
0006 #ifndef QCOM_VADC_COMMON_H
0007 #define QCOM_VADC_COMMON_H
0008
0009 #include <linux/math.h>
0010 #include <linux/types.h>
0011
0012 #define VADC_CONV_TIME_MIN_US 2000
0013 #define VADC_CONV_TIME_MAX_US 2100
0014
0015
0016 #define VADC_MIN_ADC_CODE 0x6000
0017
0018 #define VADC_MAX_ADC_CODE 0xa800
0019
0020 #define VADC_ABSOLUTE_RANGE_UV 625000
0021 #define VADC_RATIOMETRIC_RANGE 1800
0022
0023 #define VADC_DEF_PRESCALING 0
0024 #define VADC_DEF_DECIMATION 0
0025 #define VADC_DEF_HW_SETTLE_TIME 0
0026 #define VADC_DEF_AVG_SAMPLES 0
0027 #define VADC_DEF_CALIB_TYPE VADC_CALIB_ABSOLUTE
0028
0029 #define VADC_DECIMATION_MIN 512
0030 #define VADC_DECIMATION_MAX 4096
0031 #define ADC5_DEF_VBAT_PRESCALING 1
0032 #define ADC5_DECIMATION_SHORT 250
0033 #define ADC5_DECIMATION_MEDIUM 420
0034 #define ADC5_DECIMATION_LONG 840
0035
0036 #define ADC5_DECIMATION_DEFAULT 2
0037 #define ADC5_DECIMATION_SAMPLES_MAX 3
0038
0039 #define VADC_HW_SETTLE_DELAY_MAX 10000
0040 #define VADC_HW_SETTLE_SAMPLES_MAX 16
0041 #define VADC_AVG_SAMPLES_MAX 512
0042 #define ADC5_AVG_SAMPLES_MAX 16
0043
0044 #define PMIC5_CHG_TEMP_SCALE_FACTOR 377500
0045 #define PMIC5_SMB_TEMP_CONSTANT 419400
0046 #define PMIC5_SMB_TEMP_SCALE_FACTOR 356
0047
0048 #define PMI_CHG_SCALE_1 -138890
0049 #define PMI_CHG_SCALE_2 391750000000LL
0050
0051 #define VADC5_MAX_CODE 0x7fff
0052 #define ADC5_FULL_SCALE_CODE 0x70e4
0053 #define ADC5_USR_DATA_CHECK 0x8000
0054
0055 #define R_PU_100K 100000
0056 #define RATIO_MAX_ADC7 BIT(14)
0057
0058
0059
0060
0061
0062
0063 enum vadc_calibration {
0064 VADC_CALIB_ABSOLUTE = 0,
0065 VADC_CALIB_RATIOMETRIC
0066 };
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 struct vadc_linear_graph {
0078 s32 dy;
0079 s32 dx;
0080 s32 gnd;
0081 };
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 enum vadc_scale_fn_type {
0110 SCALE_DEFAULT = 0,
0111 SCALE_THERM_100K_PULLUP,
0112 SCALE_PMIC_THERM,
0113 SCALE_XOTHERM,
0114 SCALE_PMI_CHG_TEMP,
0115 SCALE_HW_CALIB_DEFAULT,
0116 SCALE_HW_CALIB_THERM_100K_PULLUP,
0117 SCALE_HW_CALIB_XOTHERM,
0118 SCALE_HW_CALIB_THERM_100K_PU_PM7,
0119 SCALE_HW_CALIB_PMIC_THERM,
0120 SCALE_HW_CALIB_PMIC_THERM_PM7,
0121 SCALE_HW_CALIB_PM5_CHG_TEMP,
0122 SCALE_HW_CALIB_PM5_SMB_TEMP,
0123 SCALE_HW_CALIB_INVALID,
0124 };
0125
0126 struct adc5_data {
0127 const u32 full_scale_code_volt;
0128 const u32 full_scale_code_cur;
0129 const struct adc5_channels *adc_chans;
0130 const struct iio_info *info;
0131 unsigned int *decimation;
0132 unsigned int *hw_settle_1;
0133 unsigned int *hw_settle_2;
0134 };
0135
0136 int qcom_vadc_scale(enum vadc_scale_fn_type scaletype,
0137 const struct vadc_linear_graph *calib_graph,
0138 const struct u32_fract *prescale,
0139 bool absolute,
0140 u16 adc_code, int *result_mdec);
0141
0142 struct qcom_adc5_scale_type {
0143 int (*scale_fn)(const struct u32_fract *prescale,
0144 const struct adc5_data *data, u16 adc_code, int *result);
0145 };
0146
0147 int qcom_adc5_hw_scale(enum vadc_scale_fn_type scaletype,
0148 unsigned int prescale_ratio,
0149 const struct adc5_data *data,
0150 u16 adc_code, int *result_mdec);
0151
0152 u16 qcom_adc_tm5_temp_volt_scale(unsigned int prescale_ratio,
0153 u32 full_scale_code_volt, int temp);
0154
0155 u16 qcom_adc_tm5_gen2_temp_res_scale(int temp);
0156
0157 int qcom_adc5_prescaling_from_dt(u32 num, u32 den);
0158
0159 int qcom_adc5_hw_settle_time_from_dt(u32 value, const unsigned int *hw_settle);
0160
0161 int qcom_adc5_avg_samples_from_dt(u32 value);
0162
0163 int qcom_adc5_decimation_from_dt(u32 value, const unsigned int *decimation);
0164
0165 int qcom_vadc_decimation_from_dt(u32 value);
0166
0167 #endif