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

index 605a31d702e01b318f6ea6bb1664e6012940c19f..c81b01c40f126e3781ad88400c4923e5f92a132b 100644 (file)
@@ -45,24 +45,8 @@ struct rti802_private {
                dac_2comp, dac_straight
        } dac_coding[8];
        const struct comedi_lrange *range_type_list[8];
-       unsigned int ao_readback[8];
 };
 
-static int rti802_ao_insn_read(struct comedi_device *dev,
-                              struct comedi_subdevice *s,
-                              struct comedi_insn *insn,
-                              unsigned int *data)
-{
-       struct rti802_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 rti802_ao_insn_write(struct comedi_device *dev,
                                struct comedi_subdevice *s,
                                struct comedi_insn *insn,
@@ -70,15 +54,14 @@ static int rti802_ao_insn_write(struct comedi_device *dev,
 {
        struct rti802_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int val;
        int i;
 
        outb(chan, dev->iobase + RTI802_SELECT);
 
        for (i = 0; i < insn->n; i++) {
-               val = data[i];
+               unsigned int val = data[i];
 
-               devpriv->ao_readback[chan] = val;
+               s->readback[chan] = val;
 
                /* munge offset binary to two's complement if needed */
                if (devpriv->dac_coding[chan] == dac_2comp)
@@ -116,10 +99,14 @@ static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->subdev_flags = SDF_WRITABLE;
        s->maxdata      = 0xfff;
        s->n_chan       = 8;
-       s->insn_read    = rti802_ao_insn_read;
        s->insn_write   = rti802_ao_insn_write;
-       s->range_table_list = devpriv->range_type_list;
+       s->insn_read    = comedi_readback_insn_read;
 
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
+
+       s->range_table_list = devpriv->range_type_list;
        for (i = 0; i < 8; i++) {
                devpriv->dac_coding[i] = (it->options[3 + 2 * i])
                        ? (dac_straight) : (dac_2comp);