staging: comedi: rti800: use comedi_timeout()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 10 Feb 2014 18:49:12 +0000 (11:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 Feb 2014 17:28:44 +0000 (09:28 -0800)
Use comedi_timeout() to wait for the analog input end-of-conversion.

Change the errno returned for an overrun from -EIO 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>
drivers/staging/comedi/drivers/rti800.c

index e1f3671ac056095982922ff3697832f9ded54dbf..bd447b2add7b74e3935a755938e3342bd9f68b0a 100644 (file)
@@ -83,8 +83,6 @@
 
 #define RTI800_IOSIZE          0x10
 
-#define RTI800_AI_TIMEOUT      100
-
 static const struct comedi_lrange range_rti800_ai_10_bipolar = {
        4, {
                BIP_RANGE(10),
@@ -145,23 +143,21 @@ struct rti800_private {
        unsigned char muxgain_bits;
 };
 
-static int rti800_ai_wait_for_conversion(struct comedi_device *dev,
-                                        int timeout)
+static int rti800_ai_eoc(struct comedi_device *dev,
+                        struct comedi_subdevice *s,
+                        struct comedi_insn *insn,
+                        unsigned long context)
 {
        unsigned char status;
-       int i;
 
-       for (i = 0; i < timeout; i++) {
-               status = inb(dev->iobase + RTI800_CSR);
-               if (status & RTI800_CSR_OVERRUN) {
-                       outb(0, dev->iobase + RTI800_CLRFLAGS);
-                       return -EIO;
-               }
-               if (status & RTI800_CSR_DONE)
-                       return 0;
-               udelay(1);
+       status = inb(dev->iobase + RTI800_CSR);
+       if (status & RTI800_CSR_OVERRUN) {
+               outb(0, dev->iobase + RTI800_CLRFLAGS);
+               return -EOVERFLOW;
        }
-       return -ETIME;
+       if (status & RTI800_CSR_DONE)
+               return 0;
+       return -EBUSY;
 }
 
 static int rti800_ai_insn_read(struct comedi_device *dev,
@@ -198,7 +194,8 @@ static int rti800_ai_insn_read(struct comedi_device *dev,
 
        for (i = 0; i < insn->n; i++) {
                outb(0, dev->iobase + RTI800_CONVERT);
-               ret = rti800_ai_wait_for_conversion(dev, RTI800_AI_TIMEOUT);
+
+               ret = comedi_timeout(dev, s, insn, rti800_ai_eoc, 0);
                if (ret)
                        return ret;