Re: [PATCH 35/48] staging: comedi: dt2814: use comedi_timeout()

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

 



On 2014-02-06 23:49, H Hartley Sweeten wrote:
Use comedi_timeout() to wait for the analog input end-of-conversion.

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

diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index abad6e4..59c3746 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -66,26 +66,35 @@ struct dt2814_private {
  #define DT2814_TIMEOUT 10
  #define DT2814_MAX_SPEED 100000	/* Arbitrary 10 khz limit */

+static int dt2814_ai_eoc(struct comedi_device *dev,
+			 struct comedi_subdevice *s,
+			 struct comedi_insn *insn,
+			 unsigned long context)
+{
+	unsigned int status;
+
+	status = inb(dev->iobase + DT2814_CSR);
+	if (status & DT2814_FINISH)
+		return 0;
+	return -EBUSY;
+}
+
  static int dt2814_ai_insn_read(struct comedi_device *dev,
  			       struct comedi_subdevice *s,
  			       struct comedi_insn *insn, unsigned int *data)
  {
-	int n, i, hi, lo;
+	int n, hi, lo;
  	int chan;
-	int status = 0;
+	int ret;

  	for (n = 0; n < insn->n; n++) {
  		chan = CR_CHAN(insn->chanspec);

  		outb(chan, dev->iobase + DT2814_CSR);
-		for (i = 0; i < DT2814_TIMEOUT; i++) {
-			status = inb(dev->iobase + DT2814_CSR);
-			udelay(10);
-			if (status & DT2814_FINISH)
-				break;
-		}
-		if (i >= DT2814_TIMEOUT)
-			return -ETIMEDOUT;
+
+		ret = comedi_timeout(dev, s, insn, dt2814_ai_eoc, 0);
+		if (ret)
+			return ret;

  		hi = inb(dev->iobase + DT2814_DATA);
  		lo = inb(dev->iobase + DT2814_DATA);
@@ -211,16 +220,15 @@ static irqreturn_t dt2814_interrupt(int irq, void *d)
  	data = (hi << 4) | (lo >> 4);

  	if (!(--devpriv->ntrig)) {
-		int i;
-
  		outb(0, dev->iobase + DT2814_CSR);
-		/* note: turning off timed mode triggers another
-		   sample. */

-		for (i = 0; i < DT2814_TIMEOUT; i++) {
-			if (inb(dev->iobase + DT2814_CSR) & DT2814_FINISH)
-				break;
-		}
+		/*
+		 * Note: turning off timed mode triggers another sample.
+		 * Wait for the conversion to finish then flush the data.
+		 * We don't have the 'insn' here but it's not needed.
+		 */
+		comedi_timeout(dev, s, NULL, dt2814_ai_eoc, 0);
+

I don't think you can't really rely on jiffies being updated while in the interrupt routine.

  		inb(dev->iobase + DT2814_DATA);
  		inb(dev->iobase + DT2814_DATA);




--
-=( Ian Abbott @ MEV Ltd.    E-mail: <abbotti@xxxxxxxxx>        )=-
-=( Tel: +44 (0)161 477 1898   FAX: +44 (0)161 718 3587         )=-
_______________________________________________
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