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

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/das16m1.c

index fee5facff8ddfb2a7570ddc2c82527054be48e29..a94b7a4e495ecd7cc6d671b3cedc39affba6685e 100644 (file)
@@ -331,14 +331,27 @@ static int das16m1_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
        return 0;
 }
 
+static int das16m1_ai_eoc(struct comedi_device *dev,
+                         struct comedi_subdevice *s,
+                         struct comedi_insn *insn,
+                         unsigned long context)
+{
+       unsigned int status;
+
+       status = inb(dev->iobase + DAS16M1_CS);
+       if (status & IRQDATA)
+               return 0;
+       return -EBUSY;
+}
+
 static int das16m1_ai_rinsn(struct comedi_device *dev,
                            struct comedi_subdevice *s,
                            struct comedi_insn *insn, unsigned int *data)
 {
        struct das16m1_private_struct *devpriv = dev->private;
-       int i, n;
+       int ret;
+       int n;
        int byte;
-       const int timeout = 1000;
 
        /* disable interrupts and internal pacer */
        devpriv->control_state &= ~INTE & ~PACER_MASK;
@@ -356,14 +369,12 @@ static int das16m1_ai_rinsn(struct comedi_device *dev,
                /* trigger conversion */
                outb(0, dev->iobase);
 
-               for (i = 0; i < timeout; i++) {
-                       if (inb(dev->iobase + DAS16M1_CS) & IRQDATA)
-                               break;
-               }
-               if (i == timeout) {
+               ret = comedi_timeout(dev, s, insn, das16m1_ai_eoc, 0);
+               if (ret) {
                        comedi_error(dev, "timeout");
-                       return -ETIME;
+                       return ret;
                }
+
                data[n] = munge_sample(inw(dev->iobase));
        }