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

Remove the unused private data and its allocation.

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/dac02.c

index df46e0a..34cbe83 100644 (file)
@@ -68,10 +68,6 @@ static const struct comedi_lrange das02_ao_ranges = {
        }
 };
 
-struct dac02_private {
-       unsigned int ao_readback[2];
-};
-
 /*
  * Register I/O map
  */
@@ -83,7 +79,6 @@ static int dac02_ao_insn_write(struct comedi_device *dev,
                               struct comedi_insn *insn,
                               unsigned int *data)
 {
-       struct dac02_private *devpriv = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
        unsigned int val;
@@ -92,7 +87,7 @@ static int dac02_ao_insn_write(struct comedi_device *dev,
        for (i = 0; i < insn->n; i++) {
                val = data[i];
 
-               devpriv->ao_readback[chan] = val;
+               s->readback[chan] = val;
 
                /*
                 * Unipolar outputs are true binary encoding.
@@ -113,31 +108,11 @@ static int dac02_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static int dac02_ao_insn_read(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn,
-                             unsigned int *data)
-{
-       struct dac02_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 dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 {
-       struct dac02_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
-       if (!devpriv)
-               return -ENOMEM;
-
        ret = comedi_request_region(dev, it->options[0], 0x08);
        if (ret)
                return ret;
@@ -154,7 +129,11 @@ static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        s->maxdata      = 0x0fff;
        s->range_table  = &das02_ao_ranges;
        s->insn_write   = dac02_ao_insn_write;
-       s->insn_read    = dac02_ao_insn_read;
+       s->insn_read    = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        return 0;
 }