iio: adc: spmi-adc5: Add support for PM2250 S3 die temp channel

Add support for reading S3 die_temp channel on PM2250 by
specifying the scaling function.

Change-Id: I1e8fcba0058851a540bc39adc7606d4f0ad8f6db
Signed-off-by: Jishnu Prakash <jprakash@codeaurora.org>
This commit is contained in:
Jishnu Prakash 2020-07-20 15:15:37 +05:30
parent d7bfd382cf
commit adb1d2c74c
2 changed files with 38 additions and 0 deletions

View file

@ -1208,6 +1208,35 @@ static int qcom_vadc_scale_hw_smb1398_temp(
return 0;
}
static int qcom_vadc_scale_hw_pm2250_s3_die_temp(
const struct vadc_prescale_ratio *prescale,
const struct adc_data *data,
u16 adc_code, int *result_mdec)
{
s64 voltage = 0, adc_vdd_ref_mv = 1875;
if (adc_code > VADC5_MAX_CODE)
adc_code = 0;
/* (ADC code * vref_vadc (1.875V)) / full_scale_code */
voltage = (s64) adc_code * adc_vdd_ref_mv * 1000;
voltage = div64_s64(voltage, data->full_scale_code_volt);
if (voltage > 0) {
voltage *= prescale->den;
voltage = div64_s64(voltage, prescale->num);
} else {
voltage = 0;
}
voltage = PMIC5_PM2250_S3_DIE_TEMP_CONSTANT - voltage;
voltage *= 100000;
voltage = div64_s64(voltage, PMIC5_PM2250_S3_DIE_TEMP_SCALE_FACTOR);
*result_mdec = voltage;
return 0;
}
static int qcom_vadc_scale_hw_chg5_temp(
const struct vadc_prescale_ratio *prescale,
const struct adc_data *data,
@ -1329,6 +1358,9 @@ int qcom_vadc_hw_scale(enum vadc_scale_fn_type scaletype,
case SCALE_HW_CALIB_PM5_SMB1398_TEMP:
return qcom_vadc_scale_hw_smb1398_temp(prescale, data,
adc_code, result);
case SCALE_HW_CALIB_PM2250_S3_DIE_TEMP:
return qcom_vadc_scale_hw_pm2250_s3_die_temp(prescale, data,
adc_code, result);
case SCALE_HW_CALIB_THERM_100K_PU_PM7:
return qcom_vadc7_scale_hw_calib_therm(prescale, data,
adc_code, result);

View file

@ -47,6 +47,9 @@
#define PMIC5_SMB1398_TEMP_SCALE_FACTOR 340
#define PMIC5_SMB1398_TEMP_CONSTANT 268235
#define PMIC5_PM2250_S3_DIE_TEMP_SCALE_FACTOR 187263
#define PMIC5_PM2250_S3_DIE_TEMP_CONSTANT 720100
#define PMI_CHG_SCALE_1 -138890
#define PMI_CHG_SCALE_2 391750000000LL
@ -172,6 +175,8 @@ struct vadc_prescale_ratio {
* SCALE_HW_CALIB_BATT_THERM_400K: Returns battery thermistor voltage in
* decidegC using 400k pullup. The hardware applies offset/slope to adc
* code.
* SCALE_HW_CALIB_PM2250_S3_DIE_TEMP: Returns result in millidegrees for
* S3 die temperature channel on PM2250.
*/
enum vadc_scale_fn_type {
SCALE_DEFAULT = 0,
@ -190,6 +195,7 @@ enum vadc_scale_fn_type {
SCALE_HW_CALIB_BATT_THERM_30K,
SCALE_HW_CALIB_BATT_THERM_400K,
SCALE_HW_CALIB_PM5_SMB1398_TEMP,
SCALE_HW_CALIB_PM2250_S3_DIE_TEMP,
SCALE_HW_CALIB_THERM_100K_PU_PM7,
SCALE_HW_CALIB_PMIC_THERM_PM7,
SCALE_HW_CALIB_MAX,