staging: comedi: s526: use comedi_timeout()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 10 Feb 2014 18:49:23 +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/s526.c

index 0a93afab3dcb505e1cb873b08429c2c1f4b93c77..85d2b7a3c125eb90d0e050e7613e3be716b6a840 100644 (file)
@@ -420,15 +420,28 @@ static int s526_ai_insn_config(struct comedi_device *dev,
        return result;
 }
 
+static int s526_ai_eoc(struct comedi_device *dev,
+                      struct comedi_subdevice *s,
+                      struct comedi_insn *insn,
+                      unsigned long context)
+{
+       unsigned int status;
+
+       status = inw(dev->iobase + REG_ISR);
+       if (status & ISR_ADC_DONE)
+               return 0;
+       return -EBUSY;
+}
+
 static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
                         struct comedi_insn *insn, unsigned int *data)
 {
        struct s526_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       int n, i;
+       int n;
        unsigned short value;
        unsigned int d;
-       unsigned int status;
+       int ret;
 
        /* Set configured delay, enable channel for this channel only,
         * select "ADC read" channel, set "ADC start" bit. */
@@ -440,17 +453,12 @@ static int s526_ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
                /* trigger conversion */
                outw(value, dev->iobase + REG_ADC);
 
-#define TIMEOUT 100
                /* wait for conversion to end */
-               for (i = 0; i < TIMEOUT; i++) {
-                       status = inw(dev->iobase + REG_ISR);
-                       if (status & ISR_ADC_DONE) {
-                               outw(ISR_ADC_DONE, dev->iobase + REG_ISR);
-                               break;
-                       }
-               }
-               if (i == TIMEOUT)
-                       return -ETIMEDOUT;
+               ret = comedi_timeout(dev, s, insn, s526_ai_eoc, 0);
+               if (ret)
+                       return ret;
+
+               outw(ISR_ADC_DONE, dev->iobase + REG_ISR);
 
                /* read data */
                d = inw(dev->iobase + REG_ADD);