]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: comedi: cb_pcidas: fix trimpot_write_insn()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 20 Nov 2014 22:07:26 +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 f92ad26d38ff119e8a1b3b4ff1fc4ab124791102..d5edb5f31ef6bf4d634ce0ee342a183ad2b846cd 100644 (file)
@@ -721,38 +721,42 @@ static int trimpot_8402_write(struct comedi_device *dev, unsigned int channel,
        return 0;
 }
 
-static int cb_pcidas_trimpot_write(struct comedi_device *dev,
-                                  unsigned int channel, unsigned int value)
+static void cb_pcidas_trimpot_write(struct comedi_device *dev,
+                                   unsigned int chan, unsigned int val)
 {
        const struct cb_pcidas_board *thisboard = dev->board_ptr;
-       struct cb_pcidas_private *devpriv = dev->private;
-
-       if (devpriv->trimpot_value[channel] == value)
-               return 1;
 
-       devpriv->trimpot_value[channel] = value;
        switch (thisboard->trimpot) {
        case AD7376:
-               trimpot_7376_write(dev, value);
+               trimpot_7376_write(dev, val);
                break;
        case AD8402:
-               trimpot_8402_write(dev, channel, value);
+               trimpot_8402_write(dev, chan, val);
                break;
        default:
                dev_err(dev->class_dev, "driver bug?\n");
-               return -1;
+               break;
        }
-
-       return 1;
 }
 
-static int trimpot_write_insn(struct comedi_device *dev,
-                             struct comedi_subdevice *s,
-                             struct comedi_insn *insn, unsigned int *data)
+static int cb_pcidas_trimpot_insn_write(struct comedi_device *dev,
+                                       struct comedi_subdevice *s,
+                                       struct comedi_insn *insn,
+                                       unsigned int *data)
 {
-       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->trimpot_value[chan] != val) {
+                       cb_pcidas_trimpot_write(dev, chan, val);
+                       devpriv->trimpot_value[chan] = val;
+               }
+       }
 
-       return cb_pcidas_trimpot_write(dev, channel, data[0]);
+       return insn->n;
 }
 
 static int trimpot_read_insn(struct comedi_device *dev,
@@ -1524,9 +1528,11 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
                s->maxdata = 0xff;
        }
        s->insn_read = trimpot_read_insn;
-       s->insn_write = trimpot_write_insn;
-       for (i = 0; i < s->n_chan; i++)
+       s->insn_write = cb_pcidas_trimpot_insn_write;
+       for (i = 0; i < s->n_chan; i++) {
                cb_pcidas_trimpot_write(dev, i, s->maxdata / 2);
+               devpriv->trimpot_value[i] = s->maxdata / 2;
+       }
 
        /*  dac08 caldac */
        s = &dev->subdevices[6];