staging: comedi: cb_pcimdas: cleanup cb_pcimdas_ao_winsn()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:46 +0000 (16:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:22:34 +0000 (13:22 -0700)
The comedi core validates the insn->chanspec and data values before
calling the (*insn_write) functions. The 'chan' will always be valid
and the data values do not need to be masked.

Tidy up this function and remove the unnecessary code.

For aesthetics, rename the function.

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

index f1c0dafb98dd5730a3987f98e241904be3a4bf10..18e1801698ee4810a56c58e3fffd26953df06602 100644 (file)
@@ -159,32 +159,24 @@ static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
        return n;
 }
 
-static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
+static int cb_pcimdas_ao_insn_write(struct comedi_device *dev,
+                                   struct comedi_subdevice *s,
+                                   struct comedi_insn *insn,
+                                   unsigned int *data)
 {
        struct cb_pcimdas_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = devpriv->ao_readback[chan];
+       unsigned int reg = (chan) ? DAC1_OFFSET : DAC0_OFFSET;
        int i;
-       int chan = CR_CHAN(insn->chanspec);
 
-       /* Writing a list of values to an AO channel is probably not
-        * very useful, but that's how the interface is defined. */
        for (i = 0; i < insn->n; i++) {
-               switch (chan) {
-               case 0:
-                       outw(data[i] & 0x0FFF, devpriv->daqio + DAC0_OFFSET);
-                       break;
-               case 1:
-                       outw(data[i] & 0x0FFF, devpriv->daqio + DAC1_OFFSET);
-                       break;
-               default:
-                       return -1;
-               }
-               devpriv->ao_readback[chan] = data[i];
+               val = data[i];
+               outw(val, devpriv->daqio + reg);
        }
+       devpriv->ao_readback[chan] = val;
 
-       /* return the number of samples read/written */
-       return i;
+       return insn->n;
 }
 
 /* AO subdevices should have a read insn as well as a write insn.
@@ -247,7 +239,7 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
        s->maxdata = 0xfff;
        /* ranges are hardware settable, but not software readable. */
        s->range_table = &range_unknown;
-       s->insn_write = &cb_pcimdas_ao_winsn;
+       s->insn_write = cb_pcimdas_ao_insn_write;
        s->insn_read = &cb_pcimdas_ao_rinsn;
 
        s = &dev->subdevices[2];