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

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

index 5de26745783a91400ab702a5771a0346ddbdf2ac..b98969154c6a4833d81c9a2b0fc5ff7b030d0160 100644 (file)
@@ -315,8 +315,6 @@ struct dt282x_private {
 
        unsigned int divisor;
 
-       unsigned short ao_readback[2];
-
        int dacsr;      /* software copies of registers */
        int adcsr;
        int supcsr;
@@ -826,21 +824,6 @@ static int dt282x_ai_cancel(struct comedi_device *dev,
        return 0;
 }
 
-static int dt282x_ao_insn_read(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn,
-                              unsigned int *data)
-{
-       struct dt282x_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];
-
-       return insn->n;
-}
-
 static int dt282x_ao_insn_write(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_insn *insn,
@@ -849,14 +832,14 @@ static int dt282x_ao_insn_write(struct comedi_device *dev,
        struct dt282x_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
-       unsigned int val;
        int i;
 
        devpriv->dacsr |= DT2821_DACSR_SSEL | DT2821_DACSR_YSEL(chan);
 
        for (i = 0; i < insn->n; i++) {
-               val = data[i];
-               devpriv->ao_readback[chan] = val;
+               unsigned int val = data[i];
+
+               s->readback[chan] = val;
 
                if (comedi_range_is_bipolar(s, range))
                        val = comedi_offset_munge(s, val);
@@ -1252,12 +1235,10 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                s->subdev_flags = SDF_WRITABLE;
                s->n_chan       = board->dachan;
                s->maxdata      = board->ao_maxdata;
-
                /* ranges are per-channel, set by jumpers on the board */
                s->range_table  = &dt282x_ao_range;
-
-               s->insn_read    = dt282x_ao_insn_read;
                s->insn_write   = dt282x_ao_insn_write;
+               s->insn_read    = comedi_readback_insn_read;
                if (dev->irq) {
                        dev->write_subdev = s;
                        s->subdev_flags |= SDF_CMD_WRITE;
@@ -1266,6 +1247,10 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                        s->do_cmd       = dt282x_ao_cmd;
                        s->cancel       = dt282x_ao_cancel;
                }
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
        } else {
                s->type         = COMEDI_SUBD_UNUSED;
        }