From: H Hartley Sweeten Date: Mon, 12 Oct 2015 19:16:35 +0000 (-0700) Subject: staging: comedi: aio_aio12_8: fix ai (*insn_read) X-Git-Tag: microblaze-4.7-rc1~1132^2~717 X-Git-Url: http://git.monstr.eu/?a=commitdiff_plain;h=ee4c7709fbb29860c3200b1296a18adff01d2307;p=linux-2.6-microblaze.git staging: comedi: aio_aio12_8: fix ai (*insn_read) According to the user manual, analog input bipolar data is 2's complement and unipolar is straight binry. Use the core helpers to munge the data appropriately. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index 2262da0d21b4..e76a1309a168 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -120,13 +120,15 @@ static int aio_aio12_8_ai_eoc(struct comedi_device *dev, static int aio_aio12_8_ai_read(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); + unsigned int val; unsigned char control; int ret; - int n; + int i; /* * Setup the control byte for internal 2MHz clock, 3uS conversion, @@ -138,7 +140,7 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev, /* Read status to clear EOC latch */ inb(dev->iobase + AIO12_8_STATUS_REG); - for (n = 0; n < insn->n; n++) { + for (i = 0; i < insn->n; i++) { /* Setup and start conversion */ outb(control, dev->iobase + AIO12_8_ADC_REG); @@ -147,7 +149,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev, if (ret) return ret; - data[n] = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata; + val = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata; + + /* munge bipolar 2's complement data to offset binary */ + if (comedi_range_is_bipolar(s, range)) + val = comedi_offset_munge(s, val); + + data[i] = val; } return insn->n;