diff options
| author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2015-10-06 01:33:08 +0300 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-10-13 07:18:33 +0300 |
| commit | 5affcdc236f1685122a6fdcb1a3c698f96f145ce (patch) | |
| tree | 6e026ea3f20e03acbea2df3b0d5298d2af609d85 | |
| parent | d8e66cfd55d2e4e41f2832a9400b142beed95e75 (diff) | |
| download | linux-5affcdc236f1685122a6fdcb1a3c698f96f145ce.tar.xz | |
staging: comedi: multiq3: tidy up multiq3_ai_insn_read()
For aesthetics, use the proper symbol when reading the A/D data register
to get the 16-bit sample data.
Use the comedi_offset_munge() to do the 2's complement to offset binary
munging of the sample data.
Tidy up the function a bit.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
| -rw-r--r-- | drivers/staging/comedi/drivers/multiq3.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c index 42ef1a6684e6..fabc321a1b1c 100644 --- a/drivers/staging/comedi/drivers/multiq3.c +++ b/drivers/staging/comedi/drivers/multiq3.c @@ -100,14 +100,14 @@ static int multiq3_ai_status(struct comedi_device *dev, static int multiq3_ai_insn_read(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - int n; - int chan; - unsigned int hi, lo; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val; int ret; + int i; - chan = CR_CHAN(insn->chanspec); outw(MULTIQ3_CONTROL_MUST | MULTIQ3_AD_MUX_EN | (chan << 3), dev->iobase + MULTIQ3_CONTROL); @@ -116,7 +116,7 @@ static int multiq3_ai_insn_read(struct comedi_device *dev, if (ret) return ret; - for (n = 0; n < insn->n; n++) { + for (i = 0; i < insn->n; i++) { outw(0, dev->iobase + MULTIQ3_AD_CS); ret = comedi_timeout(dev, s, insn, multiq3_ai_status, @@ -124,12 +124,16 @@ static int multiq3_ai_insn_read(struct comedi_device *dev, if (ret) return ret; - hi = inb(dev->iobase + MULTIQ3_AD_CS); - lo = inb(dev->iobase + MULTIQ3_AD_CS); - data[n] = (((hi << 8) | lo) + 0x1000) & 0x1fff; + /* get a 16-bit sample; mask it to the subdevice resolution */ + val = inb(dev->iobase + MULTIQ3_AD_DATA) << 8; + val |= inb(dev->iobase + MULTIQ3_AD_DATA); + val &= s->maxdata; + + /* munge the 2's complement value to offset binary */ + data[i] = comedi_offset_munge(s, val); } - return n; + return insn->n; } static int multiq3_ao_insn_write(struct comedi_device *dev, |
