Skip to content

Commit 3bd0ceb

Browse files
lumagjic23
authored andcommitted
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: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Link: https://lore.kernel.org/r/20201204025509.1075506-10-dmitry.baryshkov@linaro.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent bb01e26 commit 3bd0ceb

2 files changed

Lines changed: 15 additions & 40 deletions

File tree

drivers/iio/adc/qcom-vadc-common.c

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ static const struct vadc_map_pt adcmap_100k_104ef_104fb_1875_vref[] = {
101101
};
102102

103103
static const struct vadc_map_pt adcmap7_die_temp[] = {
104-
{ 433700, 1967},
105-
{ 473100, 1964},
106-
{ 512400, 1957},
107-
{ 551500, 1949},
108-
{ 590500, 1940},
109-
{ 629300, 1930},
110-
{ 667900, 1921},
111-
{ 706400, 1910},
112-
{ 744600, 1896},
113-
{ 782500, 1878},
114-
{ 820100, 1859},
115-
{ 857300, 0},
104+
{ 857300, 160000 },
105+
{ 820100, 140000 },
106+
{ 782500, 120000 },
107+
{ 744600, 100000 },
108+
{ 706400, 80000 },
109+
{ 667900, 60000 },
110+
{ 629300, 40000 },
111+
{ 590500, 20000 },
112+
{ 551500, 0 },
113+
{ 512400, -20000 },
114+
{ 473100, -40000 },
115+
{ 433700, -60000 },
116116
};
117117

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

588-
int voltage, vtemp0, temp, i;
588+
int voltage;
589589

590590
voltage = qcom_vadc_scale_code_voltage_factor(adc_code,
591591
prescale, data, 1);
592592

593-
if (adcmap7_die_temp[0].x > voltage) {
594-
*result_mdec = DIE_TEMP_ADC7_SCALE_1;
595-
return 0;
596-
}
597-
598-
if (adcmap7_die_temp[ARRAY_SIZE(adcmap7_die_temp) - 1].x <= voltage) {
599-
*result_mdec = DIE_TEMP_ADC7_MAX;
600-
return 0;
601-
}
602-
603-
for (i = 0; i < ARRAY_SIZE(adcmap7_die_temp); i++)
604-
if (adcmap7_die_temp[i].x > voltage)
605-
break;
606-
607-
vtemp0 = adcmap7_die_temp[i - 1].x;
608-
voltage = voltage - vtemp0;
609-
temp = div64_s64(voltage * DIE_TEMP_ADC7_SCALE_FACTOR,
610-
adcmap7_die_temp[i - 1].y);
611-
temp += DIE_TEMP_ADC7_SCALE_1 + (DIE_TEMP_ADC7_SCALE_2 * (i - 1));
612-
*result_mdec = temp;
613-
614-
return 0;
593+
return qcom_vadc_map_voltage_temp(adcmap7_die_temp, ARRAY_SIZE(adcmap7_die_temp),
594+
voltage, result_mdec);
615595
}
616596

617597
static int qcom_vadc_scale_hw_smb_temp(

include/linux/iio/adc/qcom-vadc-common.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@
5454
#define R_PU_100K 100000
5555
#define RATIO_MAX_ADC7 BIT(14)
5656

57-
#define DIE_TEMP_ADC7_SCALE_1 -60000
58-
#define DIE_TEMP_ADC7_SCALE_2 20000
59-
#define DIE_TEMP_ADC7_SCALE_FACTOR 1000
60-
#define DIE_TEMP_ADC7_MAX 160000
61-
6257
/*
6358
* VADC_CALIB_ABSOLUTE: uses the 625mV and 1.25V as reference channels.
6459
* VADC_CALIB_RATIOMETRIC: uses the reference voltage (1.8V) and GND for

0 commit comments

Comments
 (0)