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

staging: comedi: usbduxsigma: tidy up usbdux_ai_insn_read()

Rename the function so it has namespace associated with the driver.
Rename the local variable used for the private data pointer.

Return -EBUSY if an asynchronous command is running and the read cannot
be completed.

Propagate the errno if the receive_dux_command() fails.

Tidy up the function to make it more concise.
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 44d3fcae
...@@ -791,67 +791,61 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -791,67 +791,61 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
/* Mode 0 is used to get a single conversion on demand */ static int usbduxsigma_ai_insn_read(struct comedi_device *dev,
static int usbdux_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_subdevice *s, struct comedi_insn *insn,
struct comedi_insn *insn, unsigned int *data) unsigned int *data)
{ {
struct usbduxsigma_private *this_usbduxsub = dev->private; struct usbduxsigma_private *devpriv = dev->private;
int i; unsigned int chan = CR_CHAN(insn->chanspec);
int32_t one = 0;
int chan;
int err;
uint8_t muxsg0 = 0; uint8_t muxsg0 = 0;
uint8_t muxsg1 = 0; uint8_t muxsg1 = 0;
uint8_t sysred = 0; uint8_t sysred = 0;
int ret;
int i;
down(&this_usbduxsub->sem); down(&devpriv->sem);
if (this_usbduxsub->ai_cmd_running) { if (devpriv->ai_cmd_running) {
up(&this_usbduxsub->sem); up(&devpriv->sem);
return 0; return -EBUSY;
} }
/* sample one channel */
/* CONFIG0: chopper on */
this_usbduxsub->dux_commands[1] = 0x16;
/* CONFIG1: 2kHz sampling rate */
this_usbduxsub->dux_commands[2] = 0x80;
/* CONFIG3: differential channels off */
this_usbduxsub->dux_commands[3] = 0x00;
chan = CR_CHAN(insn->chanspec);
create_adc_command(chan, &muxsg0, &muxsg1); create_adc_command(chan, &muxsg0, &muxsg1);
this_usbduxsub->dux_commands[4] = muxsg0; /* Mode 0 is used to get a single conversion on demand */
this_usbduxsub->dux_commands[5] = muxsg1; devpriv->dux_commands[1] = 0x16; /* CONFIG0: chopper on */
this_usbduxsub->dux_commands[6] = sysred; devpriv->dux_commands[2] = 0x80; /* CONFIG1: 2kHz sampling rate */
devpriv->dux_commands[3] = 0x00; /* CONFIG3: diff. channels off */
devpriv->dux_commands[4] = muxsg0;
devpriv->dux_commands[5] = muxsg1;
devpriv->dux_commands[6] = sysred;
/* adc commands */ /* adc commands */
err = send_dux_commands(dev, SENDSINGLEAD); ret = send_dux_commands(dev, SENDSINGLEAD);
if (err < 0) { if (ret < 0) {
up(&this_usbduxsub->sem); up(&devpriv->sem);
return err; return ret;
} }
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
err = receive_dux_commands(dev, SENDSINGLEAD); int32_t val;
if (err < 0) {
up(&this_usbduxsub->sem); ret = receive_dux_commands(dev, SENDSINGLEAD);
return 0; if (ret < 0) {
up(&devpriv->sem);
return ret;
} }
/* 32 bits big endian from the A/D converter */ /* 32 bits big endian from the A/D converter */
one = be32_to_cpu(*((int32_t *) val = be32_to_cpu(*((int32_t *)((devpriv->insnBuffer) + 1)));
((this_usbduxsub->insnBuffer)+1))); val &= 0x00ffffff; /* strip status byte */
/* mask out the status byte */ val ^= 0x00800000; /* convert to unsigned */
one = one & 0x00ffffff;
/* turn it into an unsigned integer */ data[i] = val;
one = one ^ 0x00800000;
data[i] = one;
} }
up(&this_usbduxsub->sem); up(&devpriv->sem);
return i;
return insn->n;
} }
static int usbduxsigma_ao_insn_read(struct comedi_device *dev, static int usbduxsigma_ao_insn_read(struct comedi_device *dev,
...@@ -1453,7 +1447,7 @@ static int usbduxsigma_attach_common(struct comedi_device *dev) ...@@ -1453,7 +1447,7 @@ static int usbduxsigma_attach_common(struct comedi_device *dev)
s->len_chanlist = NUMCHANNELS; s->len_chanlist = NUMCHANNELS;
s->maxdata = 0x00ffffff; s->maxdata = 0x00ffffff;
s->range_table = &range_usbdux_ai_range; s->range_table = &range_usbdux_ai_range;
s->insn_read = usbdux_ai_insn_read; s->insn_read = usbduxsigma_ai_insn_read;
s->do_cmdtest = usbdux_ai_cmdtest; s->do_cmdtest = usbdux_ai_cmdtest;
s->do_cmd = usbdux_ai_cmd; s->do_cmd = usbdux_ai_cmd;
s->cancel = usbdux_ai_cancel; s->cancel = usbdux_ai_cancel;
......
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