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

index bd2ca2b371e66b50b30b55ed00bad6996ac7dca0..77bb89fee3277938f570782575cd5c95b1f26b50 100644 (file)
@@ -240,7 +240,6 @@ struct dt9812_private {
                size_t size;
        } cmd_wr, cmd_rd;
        u16 device;
-       u16 ao_shadow[2];
 };
 
 static int dt9812_read_info(struct comedi_device *dev,
@@ -546,7 +545,6 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
                break;
        }
        ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
-       devpriv->ao_shadow[channel] = value;
 
        up(&devpriv->sem);
 
@@ -609,15 +607,13 @@ static int dt9812_ao_insn_read(struct comedi_device *dev,
                               unsigned int *data)
 {
        struct dt9812_private *devpriv = dev->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       int i;
+       int ret;
 
        down(&devpriv->sem);
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_shadow[chan];
+       ret = comedi_readback_insn_read(dev, s, insn, data);
        up(&devpriv->sem);
 
-       return insn->n;
+       return ret;
 }
 
 static int dt9812_ao_insn_write(struct comedi_device *dev,
@@ -626,13 +622,17 @@ static int dt9812_ao_insn_write(struct comedi_device *dev,
                                unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
-       int ret;
        int i;
 
        for (i = 0; i < insn->n; i++) {
-               ret = dt9812_analog_out(dev, chan, data[i]);
+               unsigned int val = data[i];
+               int ret;
+
+               ret = dt9812_analog_out(dev, chan, val);
                if (ret)
                        return ret;
+
+               s->readback[chan] = val;
        }
 
        return insn->n;
@@ -769,6 +769,7 @@ static int dt9812_auto_attach(struct comedi_device *dev,
        struct comedi_subdevice *s;
        bool is_unipolar;
        int ret;
+       int i;
 
        devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
        if (!devpriv)
@@ -828,8 +829,12 @@ static int dt9812_auto_attach(struct comedi_device *dev,
        s->insn_write   = dt9812_ao_insn_write;
        s->insn_read    = dt9812_ao_insn_read;
 
-       devpriv->ao_shadow[0] = is_unipolar ? 0x0000 : 0x0800;
-       devpriv->ao_shadow[1] = is_unipolar ? 0x0000 : 0x0800;
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < s->n_chan; i++)
+               s->readback[i] = is_unipolar ? 0x0000 : 0x0800;
 
        return 0;
 }