staging: comedi: fl512: tidy up fl512_ao_insn_write()
authorH Hartley Sweeten <hartleys@visionengravers.com>
Thu, 13 Mar 2014 17:09:59 +0000 (10:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 17 Mar 2014 21:16:16 +0000 (14:16 -0700)
Tidy up this function. Only save the last value written for readback.

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

index 8cb1f1e..90a8fd9 100644 (file)
@@ -76,20 +76,21 @@ static int fl512_ao_insn_write(struct comedi_device *dev,
                               unsigned int *data)
 {
        struct fl512_private *devpriv = dev->private;
-       int n;
-       int chan = CR_CHAN(insn->chanspec);     /* get chan to write */
-
-       for (n = 0; n < insn->n; n++) { /* write n data set */
-               /* write low byte   */
-               outb(data[n] & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
-               /* write high byte  */
-               outb((data[n] & 0xf00) >> 8,
-                    dev->iobase + FL512_AO_DATA_REG(chan));
-               inb(dev->iobase + FL512_AO_TRIG_REG(chan));
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = devpriv->ao_readback[chan];
+       int i;
+
+       for (i = 0; i < insn->n; i++) {
+               val = data[i];
 
-               devpriv->ao_readback[chan] = data[n];
+               /* write LSB, MSB then trigger conversion */
+               outb(val & 0x0ff, dev->iobase + FL512_AO_DATA_REG(chan));
+               outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
+               inb(dev->iobase + FL512_AO_TRIG_REG(chan));
        }
-       return n;
+       devpriv->ao_readback[chan] = val;
+
+       return insn->n;
 }
 
 static int fl512_ao_insn_read(struct comedi_device *dev,