From 898fb5cb5c174dfcdb87e8b1d49b11ecd77678b9 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 25 Aug 2014 16:04:26 -0700 Subject: [PATCH] staging: comedi: ni_atmio16d: cleanup atmio16d_ao_insn_write() The comedi core validates the insn->chanspec and data values before calling the (*insn_write) functions. The 'chan' will always be valid. Tidy up this function up a bit and remove the unnecessary code. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/ni_atmio16d.c | 40 ++++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c index f1acca6cd12f..ed271ca4d9ec 100644 --- a/drivers/staging/comedi/drivers/ni_atmio16d.c +++ b/drivers/staging/comedi/drivers/ni_atmio16d.c @@ -510,34 +510,32 @@ static int atmio16d_ao_insn_read(struct comedi_device *dev, static int atmio16d_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { struct atmio16d_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int reg = (chan) ? DAC1_REG : DAC0_REG; + bool munge = false; int i; - int chan; - int d; - chan = CR_CHAN(insn->chanspec); + if (chan == 0 && devpriv->dac0_coding == dac_2comp) + munge = true; + if (chan == 1 && devpriv->dac1_coding == dac_2comp) + munge = true; for (i = 0; i < insn->n; i++) { - d = data[i]; - switch (chan) { - case 0: - if (devpriv->dac0_coding == dac_2comp) - d ^= 0x800; - outw(d, dev->iobase + DAC0_REG); - break; - case 1: - if (devpriv->dac1_coding == dac_2comp) - d ^= 0x800; - outw(d, dev->iobase + DAC1_REG); - break; - default: - return -EINVAL; - } - devpriv->ao_readback[chan] = data[i]; + unsigned int val = data[i]; + + devpriv->ao_readback[chan] = val; + + if (munge) + val ^= 0x800; + + outw(val, dev->iobase + reg); } - return i; + + return insn->n; } static int atmio16d_dio_insn_bits(struct comedi_device *dev, -- 2.30.2