staging: comedi: ni_at_ao: use subdevice readback for 'caldac'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 20 Nov 2014 22:07:30 +0000 (15:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2014 23:39:17 +0000 (15:39 -0800)
Use the comedi_subdevice 'readback' member and the core provided (*insn_read)
to handle the readback of the write-only caldac subdevice. Remove the then unused
'caldac' member from the private data.

Tidy up atao_calib_insn_write().

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 5fb40cd13b4ddc50a24bcbf31a1ef2fccfb95f89..05370a4a74a5a2ca58f1820c8deb4c12656b0a96 100644 (file)
@@ -244,47 +244,31 @@ static int atao_calib_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 bitstring;
-       unsigned int val;
-       int bit;
 
-       if (insn->n == 0)
-               return 0;
+       if (insn->n) {
+               unsigned int val = data[insn->n - 1];
+               unsigned int bitstring = ((chan & 0x7) << 8) | val;
+               unsigned int bits;
+               int bit;
 
-       devpriv->caldac[chan] = data[insn->n - 1] & s->maxdata;
+               /* write the channel and last data value to the caldac */
+               /* clock the bitstring to the caldac; MSB -> LSB */
+               for (bit = 1 << 10; bit; bit >>= 1) {
+                       bits = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
 
-       /* write the channel and last data value to the caldac */
-       bitstring = ((chan & 0x7) << 8) | devpriv->caldac[chan];
+                       outw(bits, dev->iobase + ATAO_CFG2_REG);
+                       outw(bits | ATAO_CFG2_SCLK,
+                            dev->iobase + ATAO_CFG2_REG);
+               }
 
-       /* clock the bitstring to the caldac; MSB -> LSB */
-       for (bit = 1 << 10; bit; bit >>= 1) {
-               val = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
+               /* strobe the caldac to load the value */
+               outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
+               outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
 
-               outw(val, dev->iobase + ATAO_CFG2_REG);
-               outw(val | ATAO_CFG2_SCLK, dev->iobase + ATAO_CFG2_REG);
+               s->readback[chan] = val;
        }
 
-       /* strobe the caldac to load the value */
-       outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
-       outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
-
-       return insn->n;
-}
-
-static int atao_calib_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->caldac[chan];
-
        return insn->n;
 }
 
@@ -365,9 +349,12 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
        s->n_chan       = (board->n_ao_chans * 2) + 1;
        s->maxdata      = 0xff;
-       s->insn_read    = atao_calib_insn_read;
        s->insn_write   = atao_calib_insn_write;
 
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
+
        /* EEPROM subdevice */
        s = &dev->subdevices[3];
        s->type         = COMEDI_SUBD_UNUSED;
This page took 0.025731 seconds and 5 git commands to generate.