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

index c93b47bcca51d79bbedcba41c119f062af67e702..7a60713226aeac7e2990c33ca55a885a8c1d219c 100644 (file)
@@ -118,9 +118,6 @@ struct atao_private {
        unsigned short cfg1;
        unsigned short cfg3;
 
-       /* Used for AO readback */
-       unsigned int ao_readback[10];
-
        /* Used for caldac readback */
        unsigned char caldac[21];
 };
@@ -141,9 +138,8 @@ static int atao_ao_insn_write(struct comedi_device *dev,
                              struct comedi_insn *insn,
                              unsigned int *data)
 {
-       struct atao_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int val;
+       unsigned int val = s->readback[chan];
        int i;
 
        if (chan == 0)
@@ -151,12 +147,12 @@ static int atao_ao_insn_write(struct comedi_device *dev,
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
-               devpriv->ao_readback[chan] = val;
 
-               /* munge offset binary (unsigned) to two's complement */
-               val = comedi_offset_munge(s, val);
-               outw(val, dev->iobase + ATAO_AO_REG(chan));
+               /* the hardware expects two's complement values */
+               outw(comedi_offset_munge(s, val),
+                    dev->iobase + ATAO_AO_REG(chan));
        }
+       s->readback[chan] = val;
 
        if (chan == 0)
                atao_select_reg_group(dev, 0);
@@ -164,21 +160,6 @@ static int atao_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static int atao_ao_insn_read(struct comedi_device *dev,
-                            struct comedi_subdevice *s,
-                            struct comedi_insn *insn,
-                            unsigned int *data)
-{
-       struct atao_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 atao_dio_insn_bits(struct comedi_device *dev,
                              struct comedi_subdevice *s,
                              struct comedi_insn *insn,
@@ -363,7 +344,11 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->maxdata      = 0x0fff;
        s->range_table  = it->options[3] ? &range_unipolar10 : &range_bipolar10;
        s->insn_write   = atao_ao_insn_write;
-       s->insn_read    = atao_ao_insn_read;
+       s->insn_read    = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        /* Digital I/O subdevice */
        s = &dev->subdevices[1];