Commit 8305aac3 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_at_ao: tidy up atao_ao_winsn()

For aesthetics, rename this function to help with greps.

For channel 0, register group 1 only needs to be selected before
writing the values and restored to group 0 when the writes are
finished. Move the code out of the for () loop.

Use the comedi_ffset_munge() helper to handle the offset binary to
two's complement munging.
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 a7d3d419
...@@ -135,25 +135,32 @@ static void atao_select_reg_group(struct comedi_device *dev, int group) ...@@ -135,25 +135,32 @@ static void atao_select_reg_group(struct comedi_device *dev, int group)
outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG); outw(devpriv->cfg1, dev->iobase + ATAO_CFG1_REG);
} }
static int atao_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s, static int atao_ao_insn_write(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{ {
struct atao_private *devpriv = dev->private; struct atao_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int val;
int i; int i;
int chan = CR_CHAN(insn->chanspec);
short bits; if (chan == 0)
atao_select_reg_group(dev, 1);
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
bits = data[i] - 0x800; val = data[i];
if (chan == 0) devpriv->ao_readback[chan] = val;
atao_select_reg_group(dev, 1);
outw(bits, dev->iobase + ATAO_AO_REG(chan)); /* munge offset binary (unsigned) to two's complement */
if (chan == 0) val = comedi_offset_munge(s, val);
atao_select_reg_group(dev, 0); outw(val, dev->iobase + ATAO_AO_REG(chan));
devpriv->ao_readback[chan] = data[i];
} }
return i; if (chan == 0)
atao_select_reg_group(dev, 0);
return insn->n;
} }
static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, static int atao_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
...@@ -358,7 +365,7 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -358,7 +365,7 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->range_table = &range_unipolar10; s->range_table = &range_unipolar10;
else else
s->range_table = &range_bipolar10; s->range_table = &range_bipolar10;
s->insn_write = &atao_ao_winsn; s->insn_write = atao_ao_insn_write;
s->insn_read = &atao_ao_rinsn; s->insn_read = &atao_ao_rinsn;
s = &dev->subdevices[1]; s = &dev->subdevices[1];
......
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