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

staging: comedi: pcmmio: use core helpers to munge bipolar ai data

Use the comedi_range_is_bipolar() and comedi_offset_munge() helpers to
munge the bipolar analog input data.
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 f9ec4efd
...@@ -785,7 +785,7 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -785,7 +785,7 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
CR_RANGE(insn->chanspec), aref = CR_AREF(insn->chanspec); CR_RANGE(insn->chanspec), aref = CR_AREF(insn->chanspec);
unsigned char command_byte = 0; unsigned char command_byte = 0;
unsigned iooffset = 0; unsigned iooffset = 0;
unsigned short sample, adc_adjust = 0; unsigned int val;
if (chan > 7) if (chan > 7)
chan -= 8, iooffset = 4; /* chan -= 8, iooffset = 4; /*
...@@ -800,14 +800,6 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -800,14 +800,6 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
* single-ended * single-ended
*/ */
} }
if (range < 2)
adc_adjust = 0x8000; /*
* bipolar ranges
* (-5,5 .. -10,10 need to be
* adjusted -- that is.. they
* need to wrap around by
* adding 0x8000
*/
if (chan % 2) { if (chan % 2) {
command_byte |= 1 << 6; /* command_byte |= 1 << 6; /*
...@@ -835,12 +827,16 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -835,12 +827,16 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
adc_wait_ready(iobase + iooffset); adc_wait_ready(iobase + iooffset);
/* read data lo byte */ /* read data lo byte */
sample = inb(iobase + iooffset + 0); val = inb(iobase + iooffset + 0);
/* read data hi byte */ /* read data hi byte */
sample |= inb(iobase + iooffset + 1) << 8; val |= inb(iobase + iooffset + 1) << 8;
sample += adc_adjust; /* adjustment .. munge data */
data[n] = sample; /* bipolar data is two's complement */
if (comedi_range_is_bipolar(s, range))
val = comedi_offset_munge(s, val);
data[n] = val;
} }
/* return the number of samples read/written */ /* return the number of samples read/written */
return n; return n;
......
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