staging: comedi: aio_aio12_8: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:03:57 +0000 (16:03 -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.

For aesthetics, rename the (*insn_write) function and tidy it up.

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

index 848b95decabeab8947c5f3bb8ef520ffd01a203d..61cdd2549ff85e2cbd49581fa2f6fa8cb65ea7f5 100644 (file)
@@ -97,10 +97,6 @@ static const struct aio12_8_boardtype board_types[] = {
        },
 };
 
-struct aio12_8_private {
-       unsigned int ao_readback[4];
-};
-
 static int aio_aio12_8_ai_eoc(struct comedi_device *dev,
                              struct comedi_subdevice *s,
                              struct comedi_insn *insn,
@@ -149,28 +145,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
        return insn->n;
 }
 
-static int aio_aio12_8_ao_read(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
-{
-       struct aio12_8_private *devpriv = dev->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       int val = devpriv->ao_readback[chan];
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = val;
-       return insn->n;
-}
-
-static int aio_aio12_8_ao_write(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               struct comedi_insn *insn, unsigned int *data)
+static int aio_aio12_8_ao_insn_write(struct comedi_device *dev,
+                                    struct comedi_subdevice *s,
+                                    struct comedi_insn *insn,
+                                    unsigned int *data)
 {
-       struct aio12_8_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned long port = dev->iobase + AIO12_8_DAC_REG(chan);
-       unsigned int val = 0;
+       unsigned int val = s->readback[chan];
        int i;
 
        /* enable DACs */
@@ -178,10 +159,9 @@ static int aio_aio12_8_ao_write(struct comedi_device *dev,
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               outw(val, port);
+               outw(val, dev->iobase + AIO12_8_DAC_REG(chan));
        }
-
-       devpriv->ao_readback[chan] = val;
+       s->readback[chan] = val;
 
        return insn->n;
 }
@@ -199,7 +179,6 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
                              struct comedi_devconfig *it)
 {
        const struct aio12_8_boardtype *board = comedi_board(dev);
-       struct aio12_8_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
@@ -207,10 +186,6 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_alloc_subdevices(dev, 4);
        if (ret)
                return ret;
@@ -236,8 +211,12 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
                s->n_chan       = 4;
                s->maxdata      = 0x0fff;
                s->range_table  = &range_aio_aio12_8;
-               s->insn_read    = aio_aio12_8_ao_read;
-               s->insn_write   = aio_aio12_8_ao_write;
+               s->insn_write   = aio_aio12_8_ao_insn_write;
+               s->insn_read    = comedi_readback_insn_read;
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
This page took 0.026831 seconds and 5 git commands to generate.