]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
staging: comedi: pcl818: tidy up the analog input (*insn_read)
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 4 Mar 2014 18:30:00 +0000 (11:30 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Mar 2014 01:06:15 +0000 (17:06 -0800)
For aesthetics, move this function out of the async command support
code.

For safety, the INT request (end-of-conversion flag) should be cleared
before doing each conversion and after the final data sample is read.
This driver already clears the flag before starting a conversion but it
does not clear the flag after the final sample.

Refactor the function a bit so that the flag is cleared for a conversion
timeout and after the last sample.

Do a bit of other tidying up during the move.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/pcl818.c

index 4918da352ac471452b1d28bc3bd7f31a17dc1788..5eea4ebbb26d20375c47786dc995f48decdfd25c 100644 (file)
@@ -443,43 +443,6 @@ static int pcl818_ai_eoc(struct comedi_device *dev,
        return -EBUSY;
 }
 
-static int pcl818_ai_insn_read(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       int ret;
-       int n;
-
-       /* software trigger, DMA and INT off */
-       outb(0, dev->iobase + PCL818_CONTROL);
-
-       /* select channel */
-       outb(muxonechan[CR_CHAN(insn->chanspec)], dev->iobase + PCL818_MUX);
-
-       /* select gain */
-       outb(CR_RANGE(insn->chanspec), dev->iobase + PCL818_RANGE);
-
-       for (n = 0; n < insn->n; n++) {
-
-               /* clear INT (conversion end) flag */
-               outb(0, dev->iobase + PCL818_CLRINT);
-
-               /* start conversion */
-               outb(0, dev->iobase + PCL818_AD_LO);
-
-               ret = comedi_timeout(dev, s, insn, pcl818_ai_eoc, 0);
-               if (ret) {
-                       /* clear INT (conversion end) flag */
-                       outb(0, dev->iobase + PCL818_CLRINT);
-                       return ret;
-               }
-
-               data[n] = pcl818_ai_get_sample(dev, s, NULL);
-       }
-
-       return n;
-}
-
 static bool pcl818_ai_dropout(struct comedi_device *dev,
                              struct comedi_subdevice *s,
                              unsigned int chan)
@@ -963,6 +926,42 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
        return 0;
 }
 
+static int pcl818_ai_insn_read(struct comedi_device *dev,
+                              struct comedi_subdevice *s,
+                              struct comedi_insn *insn,
+                              unsigned int *data)
+{
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int range = CR_RANGE(insn->chanspec);
+       int ret = 0;
+       int i;
+
+       /* software trigger, DMA and INT off */
+       outb(0, dev->iobase + PCL818_CONTROL);
+
+       /* select channel */
+       outb(muxonechan[chan], dev->iobase + PCL818_MUX);
+       /* select gain */
+       outb(range, dev->iobase + PCL818_RANGE);
+
+       for (i = 0; i < insn->n; i++) {
+               /* clear INT (conversion end) flag */
+               outb(0, dev->iobase + PCL818_CLRINT);
+               /* start conversion */
+               outb(0, dev->iobase + PCL818_AD_LO);
+
+               ret = comedi_timeout(dev, s, insn, pcl818_ai_eoc, 0);
+               if (ret)
+                       break;
+
+               data[i] = pcl818_ai_get_sample(dev, s, NULL);
+       }
+       /* clear INT (conversion end) flag */
+       outb(0, dev->iobase + PCL818_CLRINT);
+
+       return ret ? ret : insn->n;
+}
+
 static int pcl818_ao_insn_write(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_insn *insn,