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

index ed271ca4d9ec112917d2cf3326739c0ec4cdfe5e..2b730794b9187384a41f62d54080ea40ef6d95f3 100644 (file)
@@ -138,7 +138,6 @@ struct atmio16d_private {
        enum { dac_internal, dac_external } dac0_reference, dac1_reference;
        enum { dac_2comp, dac_straight } dac0_coding, dac1_coding;
        const struct comedi_lrange *ao_range_type_list[2];
-       unsigned int ao_readback[2];
        unsigned int com_reg_1_state; /* current state of command register 1 */
        unsigned int com_reg_2_state; /* current state of command register 2 */
 };
@@ -496,18 +495,6 @@ static int atmio16d_ai_insn_read(struct comedi_device *dev,
        return i;
 }
 
-static int atmio16d_ao_insn_read(struct comedi_device *dev,
-                                struct comedi_subdevice *s,
-                                struct comedi_insn *insn, unsigned int *data)
-{
-       struct atmio16d_private *devpriv = dev->private;
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_readback[CR_CHAN(insn->chanspec)];
-       return i;
-}
-
 static int atmio16d_ao_insn_write(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
                                  struct comedi_insn *insn,
@@ -527,7 +514,7 @@ static int atmio16d_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 (munge)
                        val ^= 0x800;
@@ -686,8 +673,6 @@ static int atmio16d_attach(struct comedi_device *dev,
        s->type = COMEDI_SUBD_AO;
        s->subdev_flags = SDF_WRITABLE;
        s->n_chan = 2;
-       s->insn_read = atmio16d_ao_insn_read;
-       s->insn_write = atmio16d_ao_insn_write;
        s->maxdata = 0xfff;     /* 4095 decimal */
        s->range_table_list = devpriv->ao_range_type_list;
        switch (devpriv->dac0_range) {
@@ -706,6 +691,12 @@ static int atmio16d_attach(struct comedi_device *dev,
                devpriv->ao_range_type_list[1] = &range_unipolar10;
                break;
        }
+       s->insn_write = atmio16d_ao_insn_write;
+       s->insn_read = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        /* Digital I/O */
        s = &dev->subdevices[2];