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

staging: comedi: me_daq: cleanup me_ai_insn_read()

Fix the use of insn->chanspec with the CR_CHAN, CR_RANGE, and CR_AREF
macros. insn->chanspec is an unsigned int not an array.

Cleanup the comments when creating the 'val' to write to the channel
list fifo so that the code is a bit more readable.

Use the 'val' variable when getting the value from the ADC fifo and
then munging the data. This cleans up the goofy line breaks.

This function still does not follow the expectations of the comedi core.
It is supposed to read insn->n values from the channel and return those
values. Currently it only reads a single value.
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 ec6521a2
...@@ -267,24 +267,16 @@ static int me_dio_insn_bits(struct comedi_device *dev, ...@@ -267,24 +267,16 @@ static int me_dio_insn_bits(struct comedi_device *dev,
return insn->n; return insn->n;
} }
/*
* ------------------------------------------------------------------
*
* ANALOG INPUT SECTION
*
* ------------------------------------------------------------------
*/
/* Analog instant input */
static int me_ai_insn_read(struct comedi_device *dev, static int me_ai_insn_read(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;
unsigned short value; unsigned int chan = CR_CHAN(insn->chanspec);
int chan = CR_CHAN((&insn->chanspec)[0]); unsigned int rang = CR_RANGE(insn->chanspec);
int rang = CR_RANGE((&insn->chanspec)[0]); unsigned int aref = CR_AREF(insn->chanspec);
int aref = CR_AREF((&insn->chanspec)[0]); unsigned short val;
int i; int i;
/* stop any running conversion */ /* stop any running conversion */
...@@ -303,15 +295,11 @@ static int me_ai_insn_read(struct comedi_device *dev, ...@@ -303,15 +295,11 @@ static int me_ai_insn_read(struct comedi_device *dev,
writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2); writew(dev_private->control_2, dev_private->me_regbase + ME_CONTROL_2);
/* write to channel list fifo */ /* write to channel list fifo */
/* b3:b0 are the channel number */ val = chan & 0x0f; /* b3:b0 channel */
value = chan & 0x0f; val |= (rang & 0x03) << 4; /* b5:b4 gain */
/* b5:b4 are the channel gain */ val |= (rang & 0x04) << 4; /* b6 polarity */
value |= (rang & 0x03) << 4; val |= ((aref & AREF_DIFF) ? 0x80 : 0); /* b7 differential */
/* b6 channel polarity */ writew(val & 0xff, dev_private->me_regbase + ME_CHANNEL_LIST);
value |= (rang & 0x04) << 4;
/* b7 single or differential */
value |= ((aref & AREF_DIFF) ? 0x80 : 0);
writew(value & 0xff, dev_private->me_regbase + ME_CHANNEL_LIST);
/* set ADC mode to software trigger */ /* set ADC mode to software trigger */
dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC; dev_private->control_1 |= SOFTWARE_TRIGGERED_ADC;
...@@ -327,9 +315,9 @@ static int me_ai_insn_read(struct comedi_device *dev, ...@@ -327,9 +315,9 @@ static int me_ai_insn_read(struct comedi_device *dev,
/* get value from ADC fifo */ /* get value from ADC fifo */
if (i) { if (i) {
data[0] = val = readw(dev_private->me_regbase + ME_READ_AD_FIFO);
(readw(dev_private->me_regbase + val = (val ^ 0x800) & 0x0fff;
ME_READ_AD_FIFO) ^ 0x800) & 0x0FFF; data[0] = val;
} else { } else {
dev_err(dev->class_dev, "Cannot get single value\n"); dev_err(dev->class_dev, "Cannot get single value\n");
return -EIO; return -EIO;
......
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