staging: comedi: cb_pcidas: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:50 +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/cb_pcidas.c

index f372b0306b387f7385ca7df57906da6c61b25221..b2be8f3251e13eaa58b91476d19eab19c8275b48 100644 (file)
@@ -360,8 +360,6 @@ struct cb_pcidas_private {
        unsigned int ao_divisor2;
        /* number of analog output samples remaining */
        unsigned int ao_count;
-       /* cached values for readback */
-       unsigned short ao_value[2];
        unsigned int caldac_value[NUM_CHANNELS_8800];
        unsigned int trimpot_value[NUM_CHANNELS_8402];
        unsigned int dac08_value;
@@ -484,7 +482,7 @@ static int cb_pcidas_ao_nofifo_winsn(struct comedi_device *dev,
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /* remember value for readback */
-       devpriv->ao_value[chan] = data[0];
+       s->readback[chan] = data[0];
 
        /* send data */
        outw(data[0], devpriv->ao_registers + DAC_DATA_REG(chan));
@@ -515,7 +513,7 @@ static int cb_pcidas_ao_fifo_winsn(struct comedi_device *dev,
        spin_unlock_irqrestore(&dev->spinlock, flags);
 
        /* remember value for readback */
-       devpriv->ao_value[chan] = data[0];
+       s->readback[chan] = data[0];
 
        /* send data */
        outw(data[0], devpriv->ao_registers + DACDATA);
@@ -523,18 +521,6 @@ static int cb_pcidas_ao_fifo_winsn(struct comedi_device *dev,
        return insn->n;
 }
 
-static int cb_pcidas_ao_readback_insn(struct comedi_device *dev,
-                                     struct comedi_subdevice *s,
-                                     struct comedi_insn *insn,
-                                     unsigned int *data)
-{
-       struct cb_pcidas_private *devpriv = dev->private;
-
-       data[0] = devpriv->ao_value[CR_CHAN(insn->chanspec)];
-
-       return 1;
-}
-
 static int wait_for_nvram_ready(unsigned long s5933_base_addr)
 {
        static const int timeout = 1000;
@@ -1511,16 +1497,22 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
                 */
                s->maxdata = (1 << thisboard->ai_bits) - 1;
                s->range_table = &cb_pcidas_ao_ranges;
-               s->insn_read = cb_pcidas_ao_readback_insn;
+               /* default to no fifo (*insn_write) */
+               s->insn_write = cb_pcidas_ao_nofifo_winsn;
+               s->insn_read = comedi_readback_insn_read;
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
+
                if (thisboard->has_ao_fifo) {
                        dev->write_subdev = s;
                        s->subdev_flags |= SDF_CMD_WRITE;
+                       /* use fifo (*insn_write) instead */
                        s->insn_write = cb_pcidas_ao_fifo_winsn;
                        s->do_cmdtest = cb_pcidas_ao_cmdtest;
                        s->do_cmd = cb_pcidas_ao_cmd;
                        s->cancel = cb_pcidas_ao_cancel;
-               } else {
-                       s->insn_write = cb_pcidas_ao_nofifo_winsn;
                }
        } else {
                s->type = COMEDI_SUBD_UNUSED;