Skip to content

Commit d4f5195

Browse files
ldesrochesjic23
authored andcommitted
iio: adc: at91: don't use the last converted data register
If touchscreen mode is enabled and a conversion is requested on another channel, the result in the last converted data register can be a touchscreen relative value. Starting a conversion involves to do a conversion for all active channel. It starts with ADC channels and ends with touchscreen channels. Then if ADC_LCD register is not read quickly, its content may be a touchscreen conversion. To remove this temporal constraint, the conversion value is taken from the channel data register. Signed-off-by: Ludovic Desroches <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Acked-by: Nicolas Ferre <[email protected]> Cc: [email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 1887e72 commit d4f5195

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/iio/adc/at91_adc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ struct at91_adc_state {
196196
bool done;
197197
int irq;
198198
u16 last_value;
199+
int chnb;
199200
struct mutex lock;
200201
u8 num_channels;
201202
void __iomem *reg_base;
@@ -274,7 +275,7 @@ void handle_adc_eoc_trigger(int irq, struct iio_dev *idev)
274275
disable_irq_nosync(irq);
275276
iio_trigger_poll(idev->trig);
276277
} else {
277-
st->last_value = at91_adc_readl(st, AT91_ADC_LCDR);
278+
st->last_value = at91_adc_readl(st, AT91_ADC_CHAN(st, st->chnb));
278279
st->done = true;
279280
wake_up_interruptible(&st->wq_data_avail);
280281
}
@@ -351,7 +352,7 @@ static irqreturn_t at91_adc_rl_interrupt(int irq, void *private)
351352
unsigned int reg;
352353

353354
status &= at91_adc_readl(st, AT91_ADC_IMR);
354-
if (status & st->registers->drdy_mask)
355+
if (status & GENMASK(st->num_channels - 1, 0))
355356
handle_adc_eoc_trigger(irq, idev);
356357

357358
if (status & AT91RL_ADC_IER_PEN) {
@@ -418,7 +419,7 @@ static irqreturn_t at91_adc_9x5_interrupt(int irq, void *private)
418419
AT91_ADC_IER_YRDY |
419420
AT91_ADC_IER_PRDY;
420421

421-
if (status & st->registers->drdy_mask)
422+
if (status & GENMASK(st->num_channels - 1, 0))
422423
handle_adc_eoc_trigger(irq, idev);
423424

424425
if (status & AT91_ADC_IER_PEN) {
@@ -689,9 +690,10 @@ static int at91_adc_read_raw(struct iio_dev *idev,
689690
case IIO_CHAN_INFO_RAW:
690691
mutex_lock(&st->lock);
691692

693+
st->chnb = chan->channel;
692694
at91_adc_writel(st, AT91_ADC_CHER,
693695
AT91_ADC_CH(chan->channel));
694-
at91_adc_writel(st, AT91_ADC_IER, st->registers->drdy_mask);
696+
at91_adc_writel(st, AT91_ADC_IER, BIT(chan->channel));
695697
at91_adc_writel(st, AT91_ADC_CR, AT91_ADC_START);
696698

697699
ret = wait_event_interruptible_timeout(st->wq_data_avail,
@@ -708,7 +710,7 @@ static int at91_adc_read_raw(struct iio_dev *idev,
708710

709711
at91_adc_writel(st, AT91_ADC_CHDR,
710712
AT91_ADC_CH(chan->channel));
711-
at91_adc_writel(st, AT91_ADC_IDR, st->registers->drdy_mask);
713+
at91_adc_writel(st, AT91_ADC_IDR, BIT(chan->channel));
712714

713715
st->last_value = 0;
714716
st->done = false;

0 commit comments

Comments
 (0)