staging: comedi: adl_pci9111: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:02 +0000 (16:04 -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.

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

index 51edfebb952ae6d83f371baa44716fd67092bf65..9ba367e27e938573327dbb2bd95cbd616e0a8808 100644 (file)
@@ -139,8 +139,6 @@ struct pci9111_private_data {
        unsigned int chunk_counter;
        unsigned int chunk_num_samples;
 
-       int ao_readback;
-
        unsigned int div1;
        unsigned int div2;
 
@@ -643,29 +641,15 @@ static int pci9111_ao_insn_write(struct comedi_device *dev,
                                 struct comedi_insn *insn,
                                 unsigned int *data)
 {
-       struct pci9111_private_data *dev_private = dev->private;
-       unsigned int val = 0;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = s->readback[chan];
        int i;
 
        for (i = 0; i < insn->n; i++) {
                val = data[i];
                outw(val, dev->iobase + PCI9111_AO_REG);
        }
-       dev_private->ao_readback = val;
-
-       return insn->n;
-}
-
-static int pci9111_ao_insn_read(struct comedi_device *dev,
-                               struct comedi_subdevice *s,
-                               struct comedi_insn *insn,
-                               unsigned int *data)
-{
-       struct pci9111_private_data *dev_private = dev->private;
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = dev_private->ao_readback;
+       s->readback[chan] = val;
 
        return insn->n;
 }
@@ -768,7 +752,11 @@ static int pci9111_auto_attach(struct comedi_device *dev,
        s->len_chanlist = 1;
        s->range_table  = &range_bipolar10;
        s->insn_write   = pci9111_ao_insn_write;
-       s->insn_read    = pci9111_ao_insn_read;
+       s->insn_read    = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        s = &dev->subdevices[2];
        s->type         = COMEDI_SUBD_DI;