Commit 03ff5898 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_atmio16d: use comedi_timeout()

Use comedi_timeout() to wait for the analog input end-of-conversion.

Change the errno returned when the conversion overflows from -ETIME
to -EOVERFLOW.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 33a6d44b
...@@ -96,7 +96,6 @@ Devices: [National Instruments] AT-MIO-16 (atmio16), AT-MIO-16D (atmio16d) ...@@ -96,7 +96,6 @@ Devices: [National Instruments] AT-MIO-16 (atmio16), AT-MIO-16D (atmio16d)
#define CLOCK_100_HZ 0x8F25 #define CLOCK_100_HZ 0x8F25
/* Other miscellaneous defines */ /* Other miscellaneous defines */
#define ATMIO16D_SIZE 32 /* bus address range */ #define ATMIO16D_SIZE 32 /* bus address range */
#define ATMIO16D_TIMEOUT 10
struct atmio16_board_t { struct atmio16_board_t {
...@@ -448,16 +447,32 @@ static int atmio16d_ai_cancel(struct comedi_device *dev, ...@@ -448,16 +447,32 @@ static int atmio16d_ai_cancel(struct comedi_device *dev,
return 0; return 0;
} }
/* Mode 0 is used to get a single conversion on demand */ static int atmio16d_ai_eoc(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned long context)
{
unsigned int status;
status = inw(dev->iobase + STAT_REG);
if (status & STAT_AD_CONVAVAIL)
return 0;
if (status & STAT_AD_OVERFLOW) {
outw(0, dev->iobase + AD_CLEAR_REG);
return -EOVERFLOW;
}
return -EBUSY;
}
static int atmio16d_ai_insn_read(struct comedi_device *dev, static int atmio16d_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
{ {
struct atmio16d_private *devpriv = dev->private; struct atmio16d_private *devpriv = dev->private;
int i, t; int i;
int chan; int chan;
int gain; int gain;
int status; int ret;
chan = CR_CHAN(insn->chanspec); chan = CR_CHAN(insn->chanspec);
gain = CR_RANGE(insn->chanspec); gain = CR_RANGE(insn->chanspec);
...@@ -473,26 +488,17 @@ static int atmio16d_ai_insn_read(struct comedi_device *dev, ...@@ -473,26 +488,17 @@ static int atmio16d_ai_insn_read(struct comedi_device *dev,
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
/* start the conversion */ /* start the conversion */
outw(0, dev->iobase + START_CONVERT_REG); outw(0, dev->iobase + START_CONVERT_REG);
/* wait for it to finish */ /* wait for it to finish */
for (t = 0; t < ATMIO16D_TIMEOUT; t++) { ret = comedi_timeout(dev, s, insn, atmio16d_ai_eoc, 0);
/* check conversion status */ if (ret)
status = inw(dev->iobase + STAT_REG); return ret;
if (status & STAT_AD_CONVAVAIL) {
/* read the data now */ /* read the data now */
data[i] = inw(dev->iobase + AD_FIFO_REG); data[i] = inw(dev->iobase + AD_FIFO_REG);
/* change to two's complement if need be */ /* change to two's complement if need be */
if (devpriv->adc_coding == adc_2comp) if (devpriv->adc_coding == adc_2comp)
data[i] ^= 0x800; data[i] ^= 0x800;
break;
}
if (status & STAT_AD_OVERFLOW) {
outw(0, dev->iobase + AD_CLEAR_REG);
return -ETIME;
}
}
/* end waiting, now check if it timed out */
if (t == ATMIO16D_TIMEOUT)
return -ETIME;
} }
return i; return i;
......
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