Commit 3bd0ceb5 authored by Dmitry Baryshkov's avatar Dmitry Baryshkov Committed by Jonathan Cameron
Browse files

iio: adc: qcom-vadc-common: rewrite vadc7 die temp calculation



qcom_vadc7_scale_hw_calib_die_temp() uses a table format different from
the rest of volt/temp conversion functions in this file. Also the
conversion functions results in non-monothonic values conversion, which
seems wrong.

Rewrite qcom_vadc7_scale_hw_calib_die_temp() to use
qcom_vadc_map_voltage_temp() directly, like the rest of conversion
functions do.

Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20201204025509.1075506-10-dmitry.baryshkov@linaro.org


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent bb01e263
Loading
Loading
Loading
Loading
+15 −35
Original line number Diff line number Diff line
@@ -101,18 +101,18 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
};

static const struct vadc_map_pt adcmap7_die_temp[] = {
	{ 433700, 1967},
	{ 473100, 1964},
	{ 512400, 1957},
	{ 551500, 1949},
	{ 590500, 1940},
	{ 629300, 1930},
	{ 667900, 1921},
	{ 706400, 1910},
	{ 744600, 1896},
	{ 782500, 1878},
	{ 820100, 1859},
	{ 857300, 0},
	{ 857300, 160000 },
	{ 820100, 140000 },
	{ 782500, 120000 },
	{ 744600, 100000 },
	{ 706400, 80000 },
	{ 667900, 60000 },
	{ 629300, 40000 },
	{ 590500, 20000 },
	{ 551500, 0 },
	{ 512400, -20000 },
	{ 473100, -40000 },
	{ 433700, -60000 },
};

/*
@@ -585,33 +585,13 @@ static int qcom_vadc7_scale_hw_calib_die_temp(
				u16 adc_code, int *result_mdec)
{

	int voltage, vtemp0, temp, i;
	int voltage;

	voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
				prescale, data, 1);

	if (adcmap7_die_temp[0].x > voltage) {
		*result_mdec = DIE_TEMP_ADC7_SCALE_1;
		return 0;
	}

	if (adcmap7_die_temp[ARRAY_SIZE(adcmap7_die_temp) - 1].x <= voltage) {
		*result_mdec = DIE_TEMP_ADC7_MAX;
		return 0;
	}

	for (i = 0; i < ARRAY_SIZE(adcmap7_die_temp); i++)
		if (adcmap7_die_temp[i].x > voltage)
			break;

	vtemp0 = adcmap7_die_temp[i - 1].x;
	voltage = voltage - vtemp0;
	temp = div64_s64(voltage * DIE_TEMP_ADC7_SCALE_FACTOR,
		adcmap7_die_temp[i - 1].y);
	temp += DIE_TEMP_ADC7_SCALE_1 + (DIE_TEMP_ADC7_SCALE_2 * (i - 1));
	*result_mdec = temp;

	return 0;
	return qcom_vadc_map_voltage_temp(adcmap7_die_temp, ARRAY_SIZE(adcmap7_die_temp),
			voltage, result_mdec);
}

static int qcom_vadc_scale_hw_smb_temp(
+0 −5
Original line number Diff line number Diff line
@@ -54,11 +54,6 @@
#define R_PU_100K				100000
#define RATIO_MAX_ADC7				BIT(14)

#define DIE_TEMP_ADC7_SCALE_1			-60000
#define DIE_TEMP_ADC7_SCALE_2			20000
#define DIE_TEMP_ADC7_SCALE_FACTOR		1000
#define DIE_TEMP_ADC7_MAX			160000

/*
 * VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
 * VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for