Skip to content

Commit

Permalink
staging: comedi: dt2814: Call dt2814_ai_clear() during initialization
Browse files Browse the repository at this point in the history
The Comedi "attach" handler `dt2814_attach()` writes to the Control
register to turn off the timer enable 'ENB' bit, which triggers a
conversion.  It then sleeps awhile and checks the Status register,
returning an error if the ERR bit is set.  However, the ERR bit could
have been set due to the conversion being triggered while the A/D
converter was busy (unlikely) or due to the conversion being triggered
before some previous sample had been read from the A/D Data register.

Replace the existing code with a call to `dt2814_ai_clear()` which waits
for any conversion to finish and then clears any unread data or error
condition.  A non-zero return value from `dt2814_ai_clear()` indicates a
time-out while waiting for the A/D converter to become non-busy.  Return
an error in that case.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20210301165757.243065-4-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ian-abbott authored and gregkh committed Mar 10, 2021
1 parent 46ffba0 commit 5fc336c
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions drivers/staging/comedi/drivers/dt2814.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,10 @@ static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it)
return ret;

outb(0, dev->iobase + DT2814_CSR);
usleep_range(100, 200);
if (inb(dev->iobase + DT2814_CSR) & DT2814_ERR) {
if (dt2814_ai_clear(dev)) {
dev_err(dev->class_dev, "reset error (fatal)\n");
return -EIO;
}
inb(dev->iobase + DT2814_DATA);
inb(dev->iobase + DT2814_DATA);

if (it->options[1]) {
ret = request_irq(it->options[1], dt2814_interrupt, 0,
Expand Down

0 comments on commit 5fc336c

Please sign in to comment.