Skip to content

Commit 7276e5a

Browse files
committed
iio: adc: at91-sama5d2_adc: align temperature formula w/ latest documentation
Align temperature computation formula with the one in the latest documentation. Along with it s/mili/milli/g. Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
1 parent 4f88a6c commit 7276e5a

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -472,13 +472,11 @@ struct at91_adc_platform {
472472
* @p1: P1 calibration temperature
473473
* @p4: P4 calibration voltage
474474
* @p6: P6 calibration voltage
475-
* @offset: calibration offset
476475
*/
477476
struct at91_adc_temp_sensor_clb {
478477
u32 p1;
479478
u32 p4;
480479
u32 p6;
481-
u32 offset;
482480
};
483481

484482
/**
@@ -495,10 +493,8 @@ enum at91_adc_ts_clb_idx {
495493
AT91_ADC_TS_CLB_IDX_MAX = OTP_PKT_SAMA7G5_TEMP_CALIB_LEN / 4,
496494
};
497495

498-
/* Temperature sensor calibration - temperature sensor gain. */
499-
#define AT91_ADC_TS_CLB_TSG (2080U)
500-
/* Temperature sensor calibration - ADC Full Scale @256 oversampling rate. */
501-
#define AT91_ADC_TS_CLB_FS (65536U)
496+
/* Temperature sensor calibration - Vtemp voltage sensitivity to temperature. */
497+
#define AT91_ADC_TS_VTEMP_DT (2080U)
502498

503499
/**
504500
* struct at91_adc_soc_info - at91-sama5d2 soc information struct
@@ -1841,16 +1837,14 @@ static int at91_adc_read_temp(struct iio_dev *indio_dev,
18411837
return ret;
18421838

18431839
/*
1844-
* Temp[mili] = p1[mili] + (vref * (vtemp * clb->p6 - clb->p4 * vbg))/
1845-
* ((clb->offset * clb->p6)
1840+
* Temp[milli] = p1[milli] + (vtemp * clb->p6 - clb->p4 * vbg)/
1841+
* (vbg * AT91_ADC_TS_VTEMP_DT)
18461842
*/
1847-
div1 = DIV_ROUND_CLOSEST_ULL(((u64)st->vref_uv * vtemp * clb->p6),
1848-
clb->p6);
1849-
div1 = DIV_ROUND_CLOSEST_ULL((div1 * 1000), clb->offset);
1850-
div2 = DIV_ROUND_CLOSEST_ULL(((u64)st->vref_uv * clb->p4 * vbg),
1851-
clb->p6);
1852-
div2 = DIV_ROUND_CLOSEST_ULL((div2 * 1000), clb->offset);
1853-
*val = clb->p1 * 1000 + (int)div1 - (int)div2;
1843+
div1 = DIV_ROUND_CLOSEST_ULL(((u64)vtemp * clb->p6), vbg);
1844+
div1 = DIV_ROUND_CLOSEST_ULL((div1 * 1000), AT91_ADC_TS_VTEMP_DT);
1845+
div2 = DIV_ROUND_CLOSEST_ULL((u64)clb->p4, AT91_ADC_TS_VTEMP_DT);
1846+
div2 *= 1000;
1847+
*val = clb->p1 + (int)div1 - (int)div2;
18541848

18551849
return ret;
18561850
}
@@ -2228,7 +2222,13 @@ static void at91_adc_temp_sensor_init(struct at91_adc_state *st,
22282222
clb->p1 = buf[AT91_ADC_TS_CLB_IDX_P1];
22292223
clb->p4 = buf[AT91_ADC_TS_CLB_IDX_P4];
22302224
clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6];
2231-
clb->offset = AT91_ADC_TS_CLB_TSG * AT91_ADC_TS_CLB_FS;
2225+
2226+
/*
2227+
* We prepare here the conversion to milli and also add constant
2228+
* factor (5 degrees Celsius) to p1 here to avoid doing it on
2229+
* hotpath.
2230+
*/
2231+
clb->p1 = clb->p1 * 1000 + 5000;
22322232

22332233
st->temp_st.init = true;
22342234

0 commit comments

Comments
 (0)