[PATCH 18/21] staging: comedi: c6xdigio: use comedi_offset_munge()

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

 



The value read from the encoders is in two's complement format. Use
the comedi_offset_munge() helper to convert the value to offset binary.

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

diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c
index 3937e64..20a5dfe 100644
--- a/drivers/staging/comedi/drivers/c6xdigio.c
+++ b/drivers/staging/comedi/drivers/c6xdigio.c
@@ -153,7 +153,7 @@ static int c6xdigio_encoder_read(struct comedi_device *dev,
 
 	c6xdigio_write_data(dev, 0x00, 0x80);
 
-	return val ^ 0x800000;
+	return val;
 }
 
 static int c6xdigio_pwm_insn_write(struct comedi_device *dev,
@@ -177,12 +177,17 @@ static int c6xdigio_encoder_insn_read(struct comedi_device *dev,
 				      unsigned int *data)
 {
 	unsigned int chan = CR_CHAN(insn->chanspec);
-	int n;
+	unsigned int val;
+	int i;
 
-	for (n = 0; n < insn->n; n++)
-		data[n] = (c6xdigio_encoder_read(dev, chan) & 0xffffff);
+	for (i = 0; i < insn->n; i++) {
+		val = c6xdigio_encoder_read(dev, chan);
+
+		/* munge two's complement value to offset binary */
+		data[i] = comedi_offset_munge(s, val);
+	}
 
-	return n;
+	return insn->n;
 }
 
 static void c6xdigio_init(struct comedi_device *dev)
-- 
1.8.5.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