[PATCH 41/66] staging: comedi: pcl812: tidy up the analog input (*insn_read)

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

 



For aesthetics, move this function out of the async command support
code.

For safety, the INT request (end-of-conversion flag) should be cleared
before doing each conversion and after the final data sample is read.
The driver currently does not do this.

Refactor the function a bit so it's more like the pcl818 and pcl816
drivers and use common code to clear the flag for a timeout and after
the last sample.

Do a bit of other tidying up during the move.

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

diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c
index 734226e..cf183c8 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -667,34 +667,6 @@ static int pcl812_ai_eoc(struct comedi_device *dev,
 	return -EBUSY;
 }
 
-static int pcl812_ai_insn_read(struct comedi_device *dev,
-			       struct comedi_subdevice *s,
-			       struct comedi_insn *insn, unsigned int *data)
-{
-	struct pcl812_private *devpriv = dev->private;
-	int ret = 0;
-	int n;
-
-	/* select software trigger */
-	outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE);
-	/*  select channel and renge */
-	setup_range_channel(dev, s, insn->chanspec, 1);
-	for (n = 0; n < insn->n; n++) {
-		/* start conversion */
-		outb(255, dev->iobase + PCL812_SOFTTRIG);
-		udelay(5);
-
-		ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0);
-		if (ret)
-			break;
-
-		data[n] = pcl812_ai_get_sample(dev, s);
-	}
-	outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
-
-	return ret ? ret : n;
-}
-
 static int pcl812_ai_cmdtest(struct comedi_device *dev,
 			     struct comedi_subdevice *s, struct comedi_cmd *cmd)
 {
@@ -1033,6 +1005,40 @@ static int pcl812_ai_cancel(struct comedi_device *dev,
 	return 0;
 }
 
+static int pcl812_ai_insn_read(struct comedi_device *dev,
+			       struct comedi_subdevice *s,
+			       struct comedi_insn *insn,
+			       unsigned int *data)
+{
+	struct pcl812_private *devpriv = dev->private;
+	int ret = 0;
+	int i;
+
+	/* select software trigger */
+	outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE);
+
+	/*  select channel and renge */
+	setup_range_channel(dev, s, insn->chanspec, 1);
+
+	for (i = 0; i < insn->n; i++) {
+		/* clear INT request */
+		outb(0, dev->iobase + PCL812_CLRINT);
+		/* start conversion */
+		outb(255, dev->iobase + PCL812_SOFTTRIG);
+
+		ret = comedi_timeout(dev, s, insn, pcl812_ai_eoc, 0);
+		if (ret)
+			break;
+
+		data[i] = pcl812_ai_get_sample(dev, s);
+	}
+	/* clear INT request */
+	outb(0, dev->iobase + PCL812_CLRINT);
+	outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
+
+	return ret ? ret : insn->n;
+}
+
 static int pcl812_ao_insn_write(struct comedi_device *dev,
 				struct comedi_subdevice *s,
 				struct comedi_insn *insn,
-- 
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