[PATCH 09/15] staging: comedi: ni_daq_700: tidy up daq700_ai_rinsn()

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

 



For aesthetics, rename this function to follow the norm for (*insn_read)
operations.

Refactor the code to use a common local variable to set the channel
mode/range and read the A/D samples.

Use the comedi_offset_munge() helper to munge the 2's complement values
from the hardware to the offset binary values that the comedi core uses.

Change the final return to clarify that the return value is the number
of samples (insn->n).

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregk@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_daq_700.c | 49 +++++++++++++----------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c b/drivers/staging/comedi/drivers/ni_daq_700.c
index 295b14a..ad6e404 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -190,25 +190,25 @@ static int daq700_ai_eoc(struct comedi_device *dev,
 	return -EBUSY;
 }
 
-static int daq700_ai_rinsn(struct comedi_device *dev,
-			   struct comedi_subdevice *s,
-			   struct comedi_insn *insn, unsigned int *data)
+static int daq700_ai_insn_read(struct comedi_device *dev,
+			       struct comedi_subdevice *s,
+			       struct comedi_insn *insn,
+			       unsigned int *data)
 {
-	int n;
-	int d;
+	unsigned int chan = CR_CHAN(insn->chanspec);
+	unsigned int range = CR_RANGE(insn->chanspec);
+	unsigned int aref = CR_AREF(insn->chanspec);
+	unsigned int val;
 	int ret;
-	unsigned int chan	= CR_CHAN(insn->chanspec);
-	unsigned int aref	= CR_AREF(insn->chanspec);
-	unsigned int range	= CR_RANGE(insn->chanspec);
-	unsigned int r3_bits	= 0;
+	int i;
 
-	/* set channel input modes */
-	if (aref == AREF_DIFF)
-		r3_bits |= DAQ700_CMD3_DIFF;
-	/* write channel mode/range */
+	/* set channel mode/range */
 	if (range >= 1)
-		range++;        /* convert range to hardware value */
-	outb(r3_bits | DAQ700_CMD3_ARNG(range), dev->iobase + DAQ700_CMD3_REG);
+		range++;	/* convert range to hardware value */
+	val = DAQ700_CMD3_ARNG(range);
+	if (aref == AREF_DIFF)
+		val |= DAQ700_CMD3_DIFF;
+	outb(val, dev->iobase + DAQ700_CMD3_REG);
 
 	/* set multiplexer for single-channel scan */
 	outb(DAQ700_CMD1_SCANDISAB | DAQ700_CMD1_MA(chan),
@@ -216,26 +216,21 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
 	/* mux needs 2us to really settle [Fred Brooks]. */
 	udelay(2);
 
-	/* convert n samples */
-	for (n = 0; n < insn->n; n++) {
+	for (i = 0; i < insn->n; i++) {
 		daq700_ai_start_conv(dev);
 
-		/* wait for conversion to end */
 		ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
 		if (ret) {
 			daq700_ai_flush_fifo(dev);
 			return ret;
 		}
 
-		/* read data */
-		d = inw(dev->iobase + DAQ700_AI_FIFO_REG);
-		/* mangle the data as necessary */
-		/* Bipolar Offset Binary: 0 to 4095 for -10 to +10 */
-		d &= 0x0fff;
-		d ^= 0x0800;
-		data[n] = d;
+		/* get sample and munge 2's complement value to offset binary */
+		val = inw(dev->iobase + DAQ700_AI_FIFO_REG);
+		data[i] = comedi_offset_munge(s, val);
 	}
-	return n;
+
+	return insn->n;
 }
 
 /*
@@ -299,7 +294,7 @@ static int daq700_auto_attach(struct comedi_device *dev,
 	s->n_chan = 16;
 	s->maxdata = (1 << 12) - 1;
 	s->range_table = &range_daq700_ai;
-	s->insn_read = daq700_ai_rinsn;
+	s->insn_read = daq700_ai_insn_read;
 	daq700_ai_config(dev, s);
 
 	return 0;
-- 
1.9.3

_______________________________________________
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