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

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

index 4e410f3b0e24c08ed8028032b6813c4dafc22d79..5a1e3c8fc01c1be670b69cdd706a65bbe70824e0 100644 (file)
 #define FL512_AO_DATA_REG(x)           (0x04 + ((x) * 2))
 #define FL512_AO_TRIG_REG(x)           (0x04 + ((x) * 2))
 
-struct fl512_private {
-       unsigned short ao_readback[2];
-};
-
 static const struct comedi_lrange range_fl512 = {
        4, {
                BIP_RANGE(0.5),
@@ -92,9 +88,8 @@ static int fl512_ao_insn_write(struct comedi_device *dev,
                               struct comedi_insn *insn,
                               unsigned int *data)
 {
-       struct fl512_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int val = devpriv->ao_readback[chan];
+       unsigned int val = s->readback[chan];
        int i;
 
        for (i = 0; i < insn->n; i++) {
@@ -105,29 +100,13 @@ static int fl512_ao_insn_write(struct comedi_device *dev,
                outb((val >> 8) & 0xf, dev->iobase + FL512_AO_DATA_REG(chan));
                inb(dev->iobase + FL512_AO_TRIG_REG(chan));
        }
-       devpriv->ao_readback[chan] = val;
-
-       return insn->n;
-}
-
-static int fl512_ao_insn_read(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn,
-                             unsigned int *data)
-{
-       struct fl512_private *devpriv = dev->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_readback[chan];
+       s->readback[chan] = val;
 
        return insn->n;
 }
 
 static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
-       struct fl512_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
@@ -135,10 +114,6 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        if (ret)
                return ret;
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_alloc_subdevices(dev, 2);
        if (ret)
                return ret;
@@ -160,7 +135,11 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->maxdata      = 0x0fff;
        s->range_table  = &range_fl512;
        s->insn_write   = fl512_ao_insn_write;
-       s->insn_read    = fl512_ao_insn_read;
+       s->insn_read    = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        return 0;
 }