staging: comedi: cb_pcidas: fix caldac_write_insn()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 20 Nov 2014 22:07:24 +0000 (15:07 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2014 23:39:16 +0000 (15:39 -0800)
The comedi core expects the (*insn_write) functions to write 'insn->n'
values to the hardware and return the number of values written. Currently
this function only writes the first value. For this subdevice it only makes
sense to write the final data value.

Fix the function to work like the core expects. For aesthetics, rename the
function so it has namespace associated with the driver.

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 1296ccd8a798d00241bb1e2d30d4b57897b965d8..d33b37c83ee83b46ec6f182ec05f5af0a5725911 100644 (file)
@@ -592,19 +592,14 @@ static void write_calibration_bitstream(struct comedi_device *dev,
        }
 }
 
-static int caldac_8800_write(struct comedi_device *dev, unsigned int address,
-                            uint8_t value)
+static void caldac_8800_write(struct comedi_device *dev,
+                             unsigned int chan, uint8_t val)
 {
        struct cb_pcidas_private *devpriv = dev->private;
        static const int bitstream_length = 11;
-       unsigned int bitstream = ((address & 0x7) << 8) | value;
+       unsigned int bitstream = ((chan & 0x7) << 8) | val;
        static const int caldac_8800_udelay = 1;
 
-       if (value == devpriv->caldac_value[address])
-               return 1;
-
-       devpriv->caldac_value[address] = value;
-
        write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream,
                                    bitstream_length);
 
@@ -613,17 +608,26 @@ static int caldac_8800_write(struct comedi_device *dev, unsigned int address,
             devpriv->control_status + CALIBRATION_REG);
        udelay(caldac_8800_udelay);
        outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG);
-
-       return 1;
 }
 
-static int caldac_write_insn(struct comedi_device *dev,
-                            struct comedi_subdevice *s,
-                            struct comedi_insn *insn, unsigned int *data)
+static int cb_pcidas_caldac_insn_write(struct comedi_device *dev,
+                                      struct comedi_subdevice *s,
+                                      struct comedi_insn *insn,
+                                      unsigned int *data)
 {
-       const unsigned int channel = CR_CHAN(insn->chanspec);
+       struct cb_pcidas_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+
+       if (insn->n) {
+               unsigned int val = data[insn->n - 1];
+
+               if (devpriv->caldac_value[chan] != val) {
+                       caldac_8800_write(dev, chan, val);
+                       devpriv->caldac_value[chan] = val;
+               }
+       }
 
-       return caldac_8800_write(dev, channel, data[0]);
+       return insn->n;
 }
 
 static int caldac_read_insn(struct comedi_device *dev,
@@ -1511,9 +1515,11 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
        s->n_chan = NUM_CHANNELS_8800;
        s->maxdata = 0xff;
        s->insn_read = caldac_read_insn;
-       s->insn_write = caldac_write_insn;
-       for (i = 0; i < s->n_chan; i++)
+       s->insn_write = cb_pcidas_caldac_insn_write;
+       for (i = 0; i < s->n_chan; i++) {
                caldac_8800_write(dev, i, s->maxdata / 2);
+               devpriv->caldac_value[i] = s->maxdata / 2;
+       }
 
        /*  trim potentiometer */
        s = &dev->subdevices[5];
This page took 0.026155 seconds and 5 git commands to generate.