Commit 14d09f79 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: me_daq: fix me_ao_insn_write()

This function is supposed to write to a single analog output channel.
The channel number is packed in insn->chanspec, which is an unsigned
int, and unpacked using the CR_CHAN() macro.

Currently this function is trying to use the chanspec as an array.
This works only if a single value is written.

Fix the function so that the desired channel is determined and all
the data is written to that channel.

Also, fix the return. The comedi core expects insn_read functions to
return the number of data values (insn->n).
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 91b0da57
...@@ -409,22 +409,14 @@ static int me_ai_do_cmd(struct comedi_device *dev, ...@@ -409,22 +409,14 @@ static int me_ai_do_cmd(struct comedi_device *dev,
return 0; return 0;
} }
/*
* ------------------------------------------------------------------
*
* ANALOG OUTPUT SECTION
*
* ------------------------------------------------------------------
*/
/* Analog instant output */
static int me_ao_insn_write(struct comedi_device *dev, static int me_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 me_private_data *dev_private = dev->private; struct me_private_data *dev_private = dev->private;
int chan; unsigned int chan = CR_CHAN(insn->chanspec);
int rang; unsigned int rang = CR_RANGE(insn->chanspec);
int i; int i;
/* Enable all DAC */ /* Enable all DAC */
...@@ -437,9 +429,6 @@ static int me_ao_insn_write(struct comedi_device *dev, ...@@ -437,9 +429,6 @@ static int me_ao_insn_write(struct comedi_device *dev,
/* Set dac-control register */ /* Set dac-control register */
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
chan = CR_CHAN((&insn->chanspec)[i]);
rang = CR_RANGE((&insn->chanspec)[i]);
/* clear bits for this channel */ /* clear bits for this channel */
dev_private->dac_control &= ~(0x0880 >> chan); dev_private->dac_control &= ~(0x0880 >> chan);
if (rang == 0) if (rang == 0)
...@@ -457,7 +446,6 @@ static int me_ao_insn_write(struct comedi_device *dev, ...@@ -457,7 +446,6 @@ static int me_ao_insn_write(struct comedi_device *dev,
/* Set data register */ /* Set data register */
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
chan = CR_CHAN((&insn->chanspec)[i]);
writew((data[0] & s->maxdata), writew((data[0] & s->maxdata),
dev_private->me_regbase + ME_DAC_DATA_A + (chan << 1)); dev_private->me_regbase + ME_DAC_DATA_A + (chan << 1));
dev_private->ao_readback[chan] = (data[0] & s->maxdata); dev_private->ao_readback[chan] = (data[0] & s->maxdata);
...@@ -466,7 +454,7 @@ static int me_ao_insn_write(struct comedi_device *dev, ...@@ -466,7 +454,7 @@ static int me_ao_insn_write(struct comedi_device *dev,
/* Update dac with data registers */ /* Update dac with data registers */
readw(dev_private->me_regbase + ME_DAC_UPDATE); readw(dev_private->me_regbase + ME_DAC_UPDATE);
return i; return insn->n;
} }
static int me_ao_insn_read(struct comedi_device *dev, static int me_ao_insn_read(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