Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4ac3015 authored by Jishnu Prakash's avatar Jishnu Prakash
Browse files

iio: adc: Correct smb1398 scaling function



Correct scaling function for SMB1398 to ensure
temperature is calculated accurately.

Change-Id: I7ec497ef9d1171da7a08a97730912727c583830a
Signed-off-by: default avatarJishnu Prakash <jprakash@codeaurora.org>
parent 9eaefd97
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -909,9 +909,26 @@ static int qcom_vadc_scale_hw_smb1398_temp(
				const struct adc5_data *data,
				u16 adc_code, int *result_mdec)
{
	*result_mdec = qcom_vadc_scale_code_voltage_factor(adc_code * 100,
			prescale, data, PMIC5_SMB1398_TEMP_SCALE_FACTOR);
	*result_mdec = PMIC5_SMB1398_TEMP_CONSTANT - *result_mdec;
	s64 voltage = 0, adc_vdd_ref_mv = 1875;
	u64 temp;

	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) {
		temp = voltage * prescale->den;
		temp *= 100;
		do_div(temp, prescale->num * PMIC5_SMB1398_TEMP_SCALE_FACTOR);
		voltage = temp;
	} else {
		voltage = 0;
	}

	voltage = voltage - PMIC5_SMB1398_TEMP_CONSTANT;
	*result_mdec = voltage;

	return 0;
}