mirror of https://gitee.com/openkylin/linux.git
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: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
33a6d44bbd
commit
03ff5898c7
|
@ -96,7 +96,6 @@ Devices: [National Instruments] AT-MIO-16 (atmio16), AT-MIO-16D (atmio16d)
|
|||
#define CLOCK_100_HZ 0x8F25
|
||||
/* Other miscellaneous defines */
|
||||
#define ATMIO16D_SIZE 32 /* bus address range */
|
||||
#define ATMIO16D_TIMEOUT 10
|
||||
|
||||
struct atmio16_board_t {
|
||||
|
||||
|
@ -448,16 +447,32 @@ static int atmio16d_ai_cancel(struct comedi_device *dev,
|
|||
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,
|
||||
struct comedi_subdevice *s,
|
||||
struct comedi_insn *insn, unsigned int *data)
|
||||
{
|
||||
struct atmio16d_private *devpriv = dev->private;
|
||||
int i, t;
|
||||
int i;
|
||||
int chan;
|
||||
int gain;
|
||||
int status;
|
||||
int ret;
|
||||
|
||||
chan = CR_CHAN(insn->chanspec);
|
||||
gain = CR_RANGE(insn->chanspec);
|
||||
|
@ -473,26 +488,17 @@ static int atmio16d_ai_insn_read(struct comedi_device *dev,
|
|||
for (i = 0; i < insn->n; i++) {
|
||||
/* start the conversion */
|
||||
outw(0, dev->iobase + START_CONVERT_REG);
|
||||
|
||||
/* wait for it to finish */
|
||||
for (t = 0; t < ATMIO16D_TIMEOUT; t++) {
|
||||
/* check conversion status */
|
||||
status = inw(dev->iobase + STAT_REG);
|
||||
if (status & STAT_AD_CONVAVAIL) {
|
||||
/* read the data now */
|
||||
data[i] = inw(dev->iobase + AD_FIFO_REG);
|
||||
/* change to two's complement if need be */
|
||||
if (devpriv->adc_coding == adc_2comp)
|
||||
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;
|
||||
ret = comedi_timeout(dev, s, insn, atmio16d_ai_eoc, 0);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* read the data now */
|
||||
data[i] = inw(dev->iobase + AD_FIFO_REG);
|
||||
/* change to two's complement if need be */
|
||||
if (devpriv->adc_coding == adc_2comp)
|
||||
data[i] ^= 0x800;
|
||||
}
|
||||
|
||||
return i;
|
||||
|
|
Loading…
Reference in New Issue