OSDN Git Service

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

index 6657055..005376e 100644 (file)
@@ -100,9 +100,6 @@ struct mf6x4_private {
         * offsets -- this variable makes the access easier
         */
        void __iomem *gpioc_R;
-
-       /* DAC value cache -- used for insn_read function */
-       int ao_readback[8];
 };
 
 static int mf6x4_di_insn_bits(struct comedi_device *dev,
@@ -181,7 +178,7 @@ static int mf6x4_ao_insn_write(struct comedi_device *dev,
 {
        struct mf6x4_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
-       unsigned int val = devpriv->ao_readback[chan];
+       unsigned int val = s->readback[chan];
        uint32_t gpioc;
        int i;
 
@@ -194,21 +191,7 @@ static int mf6x4_ao_insn_write(struct comedi_device *dev,
                val = data[i];
                iowrite16(val, dev->mmio + MF6X4_DAC_R(chan));
        }
-       devpriv->ao_readback[chan] = val;
-
-       return insn->n;
-}
-
-static int mf6x4_ao_insn_read(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn, unsigned int *data)
-{
-       struct mf6x4_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];
+       s->readback[chan] = val;
 
        return insn->n;
 }
@@ -276,7 +259,11 @@ static int mf6x4_auto_attach(struct comedi_device *dev, unsigned long context)
        s->maxdata = 0x3fff; /* 14 bits DAC */
        s->range_table = &range_bipolar10;
        s->insn_write = mf6x4_ao_insn_write;
-       s->insn_read = mf6x4_ao_insn_read;
+       s->insn_read = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        /* DIN */
        s = &dev->subdevices[2];