diff options
| author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-12-09 15:30:40 -0700 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-12-17 10:01:50 -0800 |
| commit | 5fde07640cc9905f961afd5b78d2269e157eea7c (patch) | |
| tree | 33438cfd0162e0b2dac4ac4238bdb9abbf6b3cc5 | |
| parent | f9ec4efd3c5ffd9b9ea58fe85b395c54600006b6 (diff) | |
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: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/staging/comedi/drivers/pcmmio.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c index 9394782fb74b..eb6139570f3e 100644 --- a/drivers/staging/comedi/drivers/pcmmio.c +++ b/drivers/staging/comedi/drivers/pcmmio.c @@ -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); unsigned char command_byte = 0; unsigned iooffset = 0; - unsigned short sample, adc_adjust = 0; + unsigned int val; if (chan > 7) chan -= 8, iooffset = 4; /* @@ -800,14 +800,6 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, * 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) { command_byte |= 1 << 6; /* @@ -835,12 +827,16 @@ static int ai_rinsn(struct comedi_device *dev, struct comedi_subdevice *s, adc_wait_ready(iobase + iooffset); /* read data lo byte */ - sample = inb(iobase + iooffset + 0); + val = inb(iobase + iooffset + 0); /* read data hi byte */ - sample |= inb(iobase + iooffset + 1) << 8; - sample += adc_adjust; /* adjustment .. munge data */ - data[n] = sample; + val |= inb(iobase + iooffset + 1) << 8; + + /* 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 n; |
