staging: comedi: daqboard2000: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:41 +0000 (16:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:22:33 +0000 (13:22 -0700)
Use the new comedi_subdevice 'readback' member and the core provided
(*insn_read) for the readback of the analog output subdevice channels.

For aesthetics, tidy up the (*insn_write) a bit.

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

index 266c434ccf39a9051411eff8e869a836dff1802f..dc299f6fa611f589556fe121c049a5647fee1687 100644 (file)
@@ -275,7 +275,6 @@ struct daqboard2000_private {
                card_daqboard_2000
        } card;
        void __iomem *plx;
-       unsigned int ao_readback[2];
 };
 
 static void writeAcqScanListEntry(struct comedi_device *dev, u16 entry)
@@ -401,21 +400,6 @@ static int daqboard2000_ai_insn_read(struct comedi_device *dev,
        return i;
 }
 
-static int daqboard2000_ao_insn_read(struct comedi_device *dev,
-                                    struct comedi_subdevice *s,
-                                    struct comedi_insn *insn,
-                                    unsigned int *data)
-{
-       struct daqboard2000_private *devpriv = dev->private;
-       int chan = CR_CHAN(insn->chanspec);
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_readback[chan];
-
-       return i;
-}
-
 static int daqboard2000_ao_eoc(struct comedi_device *dev,
                               struct comedi_subdevice *s,
                               struct comedi_insn *insn,
@@ -435,22 +419,23 @@ static int daqboard2000_ao_insn_write(struct comedi_device *dev,
                                      struct comedi_insn *insn,
                                      unsigned int *data)
 {
-       struct daqboard2000_private *devpriv = dev->private;
-       int chan = CR_CHAN(insn->chanspec);
-       int ret;
+       unsigned int chan = CR_CHAN(insn->chanspec);
        int i;
 
        for (i = 0; i < insn->n; i++) {
-               writew(data[i], dev->mmio + dacSetting(chan));
+               unsigned int val = data[i];
+               int ret;
+
+               writew(val, dev->mmio + dacSetting(chan));
 
                ret = comedi_timeout(dev, s, insn, daqboard2000_ao_eoc, 0);
                if (ret)
                        return ret;
 
-               devpriv->ao_readback[chan] = data[i];
+               s->readback[chan] = val;
        }
 
-       return i;
+       return insn->n;
 }
 
 static void daqboard2000_resetLocalBus(struct comedi_device *dev)
@@ -721,10 +706,14 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
        s->subdev_flags = SDF_WRITABLE;
        s->n_chan = 2;
        s->maxdata = 0xffff;
-       s->insn_read = daqboard2000_ao_insn_read;
        s->insn_write = daqboard2000_ao_insn_write;
+       s->insn_read = comedi_readback_insn_read;
        s->range_table = &range_bipolar10;
 
+       result = comedi_alloc_subdev_readback(s);
+       if (result)
+               return result;
+
        s = &dev->subdevices[2];
        result = subdev_8255_init(dev, s, daqboard2000_8255_cb,
                                  dioP2ExpansionIO8Bit);