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

index df1fceb3c53fd9fa07817791af3683fd6fb345fa..9ff9af6d4262f498eb0c63c70f8325869eb98019 100644 (file)
@@ -171,7 +171,6 @@ struct me_private_data {
        unsigned short control_1;       /* Mirror of CONTROL_1 register */
        unsigned short control_2;       /* Mirror of CONTROL_2 register */
        unsigned short dac_control;     /* Mirror of the DAC_CONTROL register */
-       int ao_readback[4];     /* Mirror of analog output data */
 };
 
 static inline void sleep(unsigned sec)
@@ -325,7 +324,7 @@ static int me_ao_insn_write(struct comedi_device *dev,
        struct me_private_data *dev_private = dev->private;
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int rang = CR_RANGE(insn->chanspec);
-       unsigned int val = dev_private->ao_readback[chan];
+       unsigned int val = s->readback[chan];
        int i;
 
        /* Enable all DAC */
@@ -358,7 +357,7 @@ static int me_ao_insn_write(struct comedi_device *dev,
 
                writew(val, dev->mmio + ME_DAC_DATA_A + (chan << 1));
        }
-       dev_private->ao_readback[chan] = val;
+       s->readback[chan] = val;
 
        /* Update dac with data registers */
        readw(dev->mmio + ME_DAC_UPDATE);
@@ -366,21 +365,6 @@ static int me_ao_insn_write(struct comedi_device *dev,
        return insn->n;
 }
 
-static int me_ao_insn_read(struct comedi_device *dev,
-                          struct comedi_subdevice *s,
-                          struct comedi_insn *insn,
-                          unsigned int *data)
-{
-       struct me_private_data *dev_private = dev->private;
-       unsigned int chan = CR_CHAN(insn->chanspec);
-       int i;
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = dev_private->ao_readback[chan];
-
-       return insn->n;
-}
-
 static int me2600_xilinx_download(struct comedi_device *dev,
                                  const u8 *data, size_t size,
                                  unsigned long context)
@@ -532,8 +516,12 @@ static int me_auto_attach(struct comedi_device *dev,
                s->maxdata      = 0x0fff;
                s->len_chanlist = 4;
                s->range_table  = &me_ao_range;
-               s->insn_read    = me_ao_insn_read;
                s->insn_write   = me_ao_insn_write;
+               s->insn_read    = comedi_readback_insn_read;
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }