Commit 04227f95 authored by Claudiu Beznea's avatar Claudiu Beznea Committed by Jonathan Cameron

iio: adc: at91-sama5d2_adc: update trackx on emr

Add support for updating trackx bits of EMR register. Having different
values of EMR.TRACKX when measuring temperature give a better accuracy.
Signed-off-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
Link: https://lore.kernel.org/r/20220803102855.2191070-14-claudiu.beznea@microchip.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 426b6475
...@@ -145,6 +145,10 @@ struct at91_adc_reg_layout { ...@@ -145,6 +145,10 @@ struct at91_adc_reg_layout {
#define AT91_SAMA5D2_EMR_OSR_64SAMPLES 3 #define AT91_SAMA5D2_EMR_OSR_64SAMPLES 3
#define AT91_SAMA5D2_EMR_OSR_256SAMPLES 4 #define AT91_SAMA5D2_EMR_OSR_256SAMPLES 4
/* Extended Mode Register - TRACKX */
#define AT91_SAMA5D2_TRACKX_MASK GENMASK(23, 22)
#define AT91_SAMA5D2_TRACKX(x) (((x) << 22) & \
AT91_SAMA5D2_TRACKX_MASK)
/* Extended Mode Register - Averaging on single trigger event */ /* Extended Mode Register - Averaging on single trigger event */
#define AT91_SAMA5D2_EMR_ASTE(V) ((V) << 20) #define AT91_SAMA5D2_EMR_ASTE(V) ((V) << 20)
...@@ -746,7 +750,7 @@ static void at91_adc_eoc_ena(struct at91_adc_state *st, unsigned int channel) ...@@ -746,7 +750,7 @@ static void at91_adc_eoc_ena(struct at91_adc_state *st, unsigned int channel)
} }
static int at91_adc_config_emr(struct at91_adc_state *st, static int at91_adc_config_emr(struct at91_adc_state *st,
u32 oversampling_ratio) u32 oversampling_ratio, u32 trackx)
{ {
/* configure the extended mode register */ /* configure the extended mode register */
unsigned int emr = at91_adc_readl(st, EMR); unsigned int emr = at91_adc_readl(st, EMR);
...@@ -765,7 +769,7 @@ static int at91_adc_config_emr(struct at91_adc_state *st, ...@@ -765,7 +769,7 @@ static int at91_adc_config_emr(struct at91_adc_state *st,
emr |= AT91_SAMA5D2_EMR_ASTE(1); emr |= AT91_SAMA5D2_EMR_ASTE(1);
/* delete leftover content if it's the case */ /* delete leftover content if it's the case */
emr &= ~osr_mask; emr &= ~(osr_mask | AT91_SAMA5D2_TRACKX_MASK);
/* select oversampling ratio from configuration */ /* select oversampling ratio from configuration */
switch (oversampling_ratio) { switch (oversampling_ratio) {
...@@ -791,6 +795,8 @@ static int at91_adc_config_emr(struct at91_adc_state *st, ...@@ -791,6 +795,8 @@ static int at91_adc_config_emr(struct at91_adc_state *st,
break; break;
} }
/* Update trackx. */
emr |= AT91_SAMA5D2_TRACKX(trackx);
at91_adc_writel(st, EMR, emr); at91_adc_writel(st, EMR, emr);
st->oversampling_ratio = oversampling_ratio; st->oversampling_ratio = oversampling_ratio;
...@@ -1706,7 +1712,7 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev, ...@@ -1706,7 +1712,7 @@ static int at91_adc_write_raw(struct iio_dev *indio_dev,
return ret; return ret;
mutex_lock(&st->lock); mutex_lock(&st->lock);
/* update ratio */ /* update ratio */
ret = at91_adc_config_emr(st, val); ret = at91_adc_config_emr(st, val, 0);
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
iio_device_release_direct_mode(indio_dev); iio_device_release_direct_mode(indio_dev);
return ret; return ret;
...@@ -1904,7 +1910,7 @@ static void at91_adc_hw_init(struct iio_dev *indio_dev) ...@@ -1904,7 +1910,7 @@ static void at91_adc_hw_init(struct iio_dev *indio_dev)
at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate); at91_adc_setup_samp_freq(indio_dev, st->soc_info.min_sample_rate);
/* configure extended mode register */ /* configure extended mode register */
at91_adc_config_emr(st, st->oversampling_ratio); at91_adc_config_emr(st, st->oversampling_ratio, 0);
} }
static ssize_t at91_adc_get_fifo_state(struct device *dev, static ssize_t at91_adc_get_fifo_state(struct device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment