staging: comedi: multiq3: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:00 +0000 (16:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:22:30 +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.

Remove the unused private data and its allocation.

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

index e841a5a3ec4f2e1bd8457ee62d8a6a014c531368..f710c8e813202d7e37eac1f2f1a7da87ec36890c 100644 (file)
@@ -75,10 +75,6 @@ Devices: [Quanser Consulting] MultiQ-3 (multiq3)
 
 #define MULTIQ3_TIMEOUT 30
 
-struct multiq3_private {
-       unsigned int ao_readback[2];
-};
-
 static int multiq3_ai_status(struct comedi_device *dev,
                             struct comedi_subdevice *s,
                             struct comedi_insn *insn,
@@ -126,38 +122,25 @@ static int multiq3_ai_insn_read(struct comedi_device *dev,
        return n;
 }
 
-static int multiq3_ao_insn_read(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               struct comedi_insn *insn, unsigned int *data)
-{
-       struct multiq3_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 multiq3_ao_insn_write(struct comedi_device *dev,
                                 struct comedi_subdevice *s,
-                                struct comedi_insn *insn, unsigned int *data)
+                                struct comedi_insn *insn,
+                                unsigned int *data)
 {
-       struct multiq3_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = s->readback[chan];
        int i;
-       int chan = CR_CHAN(insn->chanspec);
 
        for (i = 0; i < insn->n; i++) {
+               val = data[i];
                outw(MULTIQ3_CONTROL_MUST | MULTIQ3_DA_LOAD | chan,
                     dev->iobase + MULTIQ3_CONTROL);
-               outw(data[i], dev->iobase + MULTIQ3_DAC_DATA);
+               outw(val, dev->iobase + MULTIQ3_DAC_DATA);
                outw(MULTIQ3_CONTROL_MUST, dev->iobase + MULTIQ3_CONTROL);
-
-               devpriv->ao_readback[chan] = data[i];
        }
+       s->readback[chan] = val;
 
-       return i;
+       return insn->n;
 }
 
 static int multiq3_di_insn_bits(struct comedi_device *dev,
@@ -227,7 +210,6 @@ static void encoder_reset(struct comedi_device *dev)
 static int multiq3_attach(struct comedi_device *dev,
                          struct comedi_devconfig *it)
 {
-       struct multiq3_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
@@ -239,10 +221,6 @@ static int multiq3_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        s = &dev->subdevices[0];
        /* ai subdevice */
        s->type = COMEDI_SUBD_AI;
@@ -257,10 +235,14 @@ static int multiq3_attach(struct comedi_device *dev,
        s->type = COMEDI_SUBD_AO;
        s->subdev_flags = SDF_WRITABLE;
        s->n_chan = 8;
-       s->insn_read = multiq3_ao_insn_read;
-       s->insn_write = multiq3_ao_insn_write;
        s->maxdata = 0xfff;
        s->range_table = &range_bipolar5;
+       s->insn_write = multiq3_ao_insn_write;
+       s->insn_read = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        s = &dev->subdevices[2];
        /* di subdevice */
This page took 0.025863 seconds and 5 git commands to generate.