From 9c034da124d08237fe973ca0073f5f70297b20fb Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 20 Nov 2014 15:07:28 -0700 Subject: [PATCH] staging: comedi: cb_pcidas: tidy up dac08_write_insn() For consistency with the other calib subdevices, refactor this (*insn_write) function so that it only writes the final data value to the hardware., For aesthetics, rename the function so it has namespace associated with the driver. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/cb_pcidas.c | 48 +++++++++++----------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index 86e3d200bb21..04b6d39d1051 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -631,34 +631,35 @@ static int cb_pcidas_caldac_insn_write(struct comedi_device *dev, static void dac08_write(struct comedi_device *dev, unsigned int value) { struct cb_pcidas_private *devpriv = dev->private; - unsigned long cal_reg; - if (devpriv->dac08_value != value) { - devpriv->dac08_value = value; + value &= 0xff; + value |= cal_enable_bits(dev); - cal_reg = devpriv->control_status + CALIBRATION_REG; - - value &= 0xff; - value |= cal_enable_bits(dev); - - /* latch the new value into the caldac */ - outw(value, cal_reg); - udelay(1); - outw(value | SELECT_DAC08_BIT, cal_reg); - udelay(1); - outw(value, cal_reg); - udelay(1); - } + /* latch the new value into the caldac */ + outw(value, devpriv->control_status + CALIBRATION_REG); + udelay(1); + outw(value | SELECT_DAC08_BIT, + devpriv->control_status + CALIBRATION_REG); + udelay(1); + outw(value, devpriv->control_status + CALIBRATION_REG); + udelay(1); } -static int dac08_write_insn(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) +static int cb_pcidas_dac08_insn_write(struct comedi_device *dev, + struct comedi_subdevice *s, + struct comedi_insn *insn, + unsigned int *data) { - int i; + struct cb_pcidas_private *devpriv = dev->private; + + if (insn->n) { + unsigned int val = data[insn->n - 1]; - for (i = 0; i < insn->n; i++) - dac08_write(dev, data[i]); + if (devpriv->dac08_value != val) { + dac08_write(dev, val); + devpriv->dac08_value = val; + } + } return insn->n; } @@ -1531,9 +1532,10 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; s->n_chan = NUM_CHANNELS_DAC08; s->insn_read = dac08_read_insn; - s->insn_write = dac08_write_insn; + s->insn_write = cb_pcidas_dac08_insn_write; s->maxdata = 0xff; dac08_write(dev, s->maxdata / 2); + devpriv->dac08_value = s->maxdata / 2; } else s->type = COMEDI_SUBD_UNUSED; -- 2.34.1