[PATCH 04/30] staging: comedi: usbdux: clarify bipolar ai data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the comedi_range_is_bipolar() helper instead of checking the
'range' index against a magic number.

Also, use the s->maxdata to calculate the value needed to munge the
value for bipolar data instead of the magic number.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/usbdux.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index a536fa3..a81b4b1 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -1002,8 +1002,10 @@ static int usbdux_ai_insn_read(struct comedi_device *dev,
 			goto ai_read_exit;
 
 		val = le16_to_cpu(devpriv->insn_buffer[1]);
-		if (range <= 1)
-			val ^= 0x800;
+
+		/* bipolar data is two's-complement */
+		if (comedi_range_is_bipolar(s, range))
+			val ^= ((s->maxdata + 1) >> 1);
 
 		data[i] = val;
 	}
-- 
1.8.3.2

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux