staging: comedi: dmm32at: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:43 +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.

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

index cfe32348ff61c5959d095a7c1d3e8d4fa8bac38e..7215e09305cfcf1616e8f6d9ea83d2b47f0a04af 100644 (file)
@@ -151,15 +151,10 @@ static const struct comedi_lrange dmm32at_aoranges = {
 };
 
 struct dmm32at_private {
-
        int data;
        int ai_inuse;
        unsigned int ai_scans_left;
-
-       /* Used for AO readback */
-       unsigned int ao_readback[4];
        unsigned char dio_config;
-
 };
 
 static int dmm32at_ai_status(struct comedi_device *dev,
@@ -546,14 +541,12 @@ static int dmm32at_ao_insn_write(struct comedi_device *dev,
                                 struct comedi_insn *insn,
                                 unsigned int *data)
 {
-       struct dmm32at_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int val;
-       int ret;
        int i;
 
        for (i = 0; i < insn->n; i++) {
-               val = data[i];
+               unsigned int val = data[i];
+               int ret;
 
                /* write LSB then MSB + chan to load DAC */
                outb(val & 0xff, dev->iobase + DMM32AT_DACLSB_REG);
@@ -568,26 +561,12 @@ static int dmm32at_ao_insn_write(struct comedi_device *dev,
                /* dummy read to update DAC */
                inb(dev->iobase + DMM32AT_DACMSB_REG);
 
-               devpriv->ao_readback[chan] = val;
+               s->readback[chan] = val;
        }
 
        return insn->n;
 }
 
-static int dmm32at_ao_rinsn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data)
-{
-       struct dmm32at_private *devpriv = dev->private;
-       int i;
-       int chan = CR_CHAN(insn->chanspec);
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_readback[chan];
-
-       return i;
-}
-
 static int dmm32at_dio_insn_bits(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
                                 struct comedi_insn *insn,
@@ -761,7 +740,11 @@ static int dmm32at_attach(struct comedi_device *dev,
        s->maxdata = 0x0fff;
        s->range_table = &dmm32at_aoranges;
        s->insn_write = dmm32at_ao_insn_write;
-       s->insn_read = dmm32at_ao_rinsn;
+       s->insn_read = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        s = &dev->subdevices[2];
        /* digital i/o subdevice */