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

index 01ec65a5b5d16cde210c1658ef548d84fa770b93..4df979e519f01c05a0a7dd32186359eb6a08a555 100644 (file)
@@ -137,7 +137,6 @@ struct rti800_private {
        bool adc_2comp;
        bool dac_2comp[2];
        const struct comedi_lrange *ao_range_type_list[2];
-       unsigned int ao_readback[2];
        unsigned char muxgain_bits;
 };
 
@@ -207,21 +206,6 @@ static int rti800_ai_insn_read(struct comedi_device *dev,
        return insn->n;
 }
 
-static int rti800_ao_insn_read(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn,
-                              unsigned int *data)
-{
-       struct rti800_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 rti800_ao_insn_write(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_insn *insn,
@@ -236,7 +220,7 @@ static int rti800_ao_insn_write(struct comedi_device *dev,
        for (i = 0; i < insn->n; i++) {
                unsigned int val = data[i];
 
-               devpriv->ao_readback[chan] = val;
+               s->readback[chan] = val;
 
                if (devpriv->dac_2comp[chan])
                        val ^= 0x800;
@@ -318,8 +302,6 @@ static int rti800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                s->type         = COMEDI_SUBD_AO;
                s->subdev_flags = SDF_WRITABLE;
                s->n_chan       = 2;
-               s->insn_read    = rti800_ao_insn_read;
-               s->insn_write   = rti800_ao_insn_write;
                s->maxdata      = 0x0fff;
                s->range_table_list = devpriv->ao_range_type_list;
                devpriv->ao_range_type_list[0] =
@@ -330,6 +312,12 @@ static int rti800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                        (it->options[7] < ARRAY_SIZE(rti800_ao_ranges))
                                ? rti800_ao_ranges[it->options[7]]
                                : &range_unknown;
+               s->insn_write   = rti800_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;
        }