Skip to content

Commit c169135

Browse files
committed
Merge branch 'linux-5.15-trunk/at91/adc' into linux-5.15-mchp
2 parents 50cccdf + c055d78 commit c169135

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

drivers/iio/adc/at91-sama5d2_adc.c

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct at91_adc_reg_layout {
8383
#define AT91_SAMA5D2_MR_ANACH BIT(23)
8484
/* Tracking Time */
8585
#define AT91_SAMA5D2_MR_TRACKTIM(v) ((v) << 24)
86+
#define AT91_SAMA5D2_MR_TRACKTIM_TS 6
8687
#define AT91_SAMA5D2_MR_TRACKTIM_MAX 0xf
8788
/* Transfer Time */
8889
#define AT91_SAMA5D2_MR_TRANSFER(v) ((v) << 28)
@@ -469,36 +470,32 @@ struct at91_adc_platform {
469470
/**
470471
* struct at91_adc_temp_sensor_clb - at91-sama5d2 temperature sensor
471472
* calibration data structure
472-
* @t3: OTP_T3 calibration temperature
473-
* @vtemp: OTP_VTEMP calibration voltage
474-
* @vbg2: OTP_VBG2 calibration voltage
475-
* @offset: calibration offset
473+
* @p1: P1 calibration temperature
474+
* @p4: P4 calibration voltage
475+
* @p6: P6 calibration voltage
476476
*/
477477
struct at91_adc_temp_sensor_clb {
478-
u32 t3;
479-
u32 vtemp;
480-
u32 vbg2;
481-
u32 offset;
478+
u32 p1;
479+
u32 p4;
480+
u32 p6;
482481
};
483482

484483
/**
485484
* enum at91_adc_ts_clb_idx - calibration indexes in NVMEM buffer
486-
* @AT91_ADC_TS_CLB_IDX_OTP_T3: index for OTP_T3
487-
* @AT91_ADC_TS_CLB_IDX_OTP_VTEMP: index for OTP_VTEMP
488-
* @AT91_ADC_TS_CLB_IDX_OTP_VBG2: index for OTP_VBG2
485+
* @AT91_ADC_TS_CLB_IDX_P1: index for P1
486+
* @AT91_ADC_TS_CLB_IDX_P4: index for P4
487+
* @AT91_ADC_TS_CLB_IDX_P6: index for P6
489488
* @AT91_ADC_TS_CLB_IDX_MAX: max index for temperature calibration packet in OTP
490489
*/
491490
enum at91_adc_ts_clb_idx {
492-
AT91_ADC_TS_CLB_IDX_OTP_T3 = 2,
493-
AT91_ADC_TS_CLB_IDX_OTP_VTEMP = 5,
494-
AT91_ADC_TS_CLB_IDX_OTP_VBG2 = 7,
491+
AT91_ADC_TS_CLB_IDX_P1 = 2,
492+
AT91_ADC_TS_CLB_IDX_P4 = 5,
493+
AT91_ADC_TS_CLB_IDX_P6 = 7,
495494
AT91_ADC_TS_CLB_IDX_MAX = OTP_PKT_SAMA7G5_TEMP_CALIB_LEN / 4,
496495
};
497496

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)
497+
/* Temperature sensor calibration - Vtemp voltage sensitivity to temperature. */
498+
#define AT91_ADC_TS_VTEMP_DT (2080U)
502499

503500
/**
504501
* struct at91_adc_soc_info - at91-sama5d2 soc information struct
@@ -1783,7 +1780,7 @@ static void at91_adc_temp_sensor_configure(struct at91_adc_state *st,
17831780
sample_rate = 10000000U;
17841781
oversampling_ratio = AT91_OSR_256SAMPLES;
17851782
startup_time = AT91_SAMA5D2_MR_STARTUP_TS_MIN;
1786-
tracktim = AT91_SAMA5D2_MR_TRACKTIM_MAX;
1783+
tracktim = AT91_SAMA5D2_MR_TRACKTIM_TS;
17871784
trackx = AT91_SAMA5D2_TRACKX_TS;
17881785

17891786
st->temp_st.saved_sample_rate = st->current_sample_rate;
@@ -1841,16 +1838,14 @@ static int at91_adc_read_temp(struct iio_dev *indio_dev,
18411838
return ret;
18421839

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

18551850
return ret;
18561851
}
@@ -2225,10 +2220,16 @@ static void at91_adc_temp_sensor_init(struct at91_adc_state *st,
22252220
}
22262221

22272222
/* Store calibration data for later use. */
2228-
clb->t3 = buf[AT91_ADC_TS_CLB_IDX_OTP_T3];
2229-
clb->vtemp = buf[AT91_ADC_TS_CLB_IDX_OTP_VTEMP];
2230-
clb->vbg2 = buf[AT91_ADC_TS_CLB_IDX_OTP_VBG2];
2231-
clb->offset = AT91_ADC_TS_CLB_TSG * AT91_ADC_TS_CLB_FS;
2223+
clb->p1 = buf[AT91_ADC_TS_CLB_IDX_P1];
2224+
clb->p4 = buf[AT91_ADC_TS_CLB_IDX_P4];
2225+
clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6];
2226+
2227+
/*
2228+
* We prepare here the conversion to milli and also add constant
2229+
* factor (5 degrees Celsius) to p1 here to avoid doing it on
2230+
* hotpath.
2231+
*/
2232+
clb->p1 = clb->p1 * 1000 + 5000;
22322233

22332234
st->temp_st.init = true;
22342235

0 commit comments

Comments
 (0)