Commit 898fb5cb authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b38d6494
...@@ -510,34 +510,32 @@ static int atmio16d_ao_insn_read(struct comedi_device *dev, ...@@ -510,34 +510,32 @@ static int atmio16d_ao_insn_read(struct comedi_device *dev,
static int atmio16d_ao_insn_write(struct comedi_device *dev, static int atmio16d_ao_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn,
unsigned int *data)
{ {
struct atmio16d_private *devpriv = dev->private; 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 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++) { for (i = 0; i < insn->n; i++) {
d = data[i]; unsigned int val = data[i];
switch (chan) {
case 0: devpriv->ao_readback[chan] = val;
if (devpriv->dac0_coding == dac_2comp)
d ^= 0x800; if (munge)
outw(d, dev->iobase + DAC0_REG); val ^= 0x800;
break;
case 1: outw(val, dev->iobase + reg);
if (devpriv->dac1_coding == dac_2comp)
d ^= 0x800;
outw(d, dev->iobase + DAC1_REG);
break;
default:
return -EINVAL;
}
devpriv->ao_readback[chan] = data[i];
} }
return i;
return insn->n;
} }
static int atmio16d_dio_insn_bits(struct comedi_device *dev, static int atmio16d_dio_insn_bits(struct comedi_device *dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment