[PATCH v2 04/17] staging: comedi: quatech_daqp_cs: tidy up daqp_ai_set_one_scanlist_entry()

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

 



Clarify the scan list programming a bit by refactoring this function to program
the entire scan list instead of just a single entry. Move the necessary reset
of the scan list into this function. Rename the function.

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

diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index 7c8f081..de28224 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -243,25 +243,31 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static void daqp_ai_set_one_scanlist_entry(struct comedi_device *dev,
-					   unsigned int chanspec,
-					   int start)
+static void daqp_ai_set_scanlist(struct comedi_device *dev,
+				 unsigned int *chanspec, int len)
 {
-	unsigned int chan = CR_CHAN(chanspec);
-	unsigned int range = CR_RANGE(chanspec);
-	unsigned int aref = CR_AREF(chanspec);
-	unsigned int val;
+	int i;
+
+	/* Reset scan list queue */
+	outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
 
-	val = DAQP_SCANLIST_CHANNEL(chan) | DAQP_SCANLIST_GAIN(range);
+	for (i = 0; i < len; i++) {
+		unsigned int chan = CR_CHAN(chanspec[i]);
+		unsigned int range = CR_RANGE(chanspec[i]);
+		unsigned int aref = CR_AREF(chanspec[i]);
+		unsigned int val;
 
-	if (aref == AREF_DIFF)
-		val |= DAQP_SCANLIST_DIFFERENTIAL;
+		val = DAQP_SCANLIST_CHANNEL(chan) | DAQP_SCANLIST_GAIN(range);
 
-	if (start)
-		val |= DAQP_SCANLIST_START;
+		if (aref == AREF_DIFF)
+			val |= DAQP_SCANLIST_DIFFERENTIAL;
 
-	outb(val & 0xff, dev->iobase + DAQP_SCANLIST);
-	outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST);
+		if (i == 0)
+			val |= DAQP_SCANLIST_START;
+
+		outb(val & 0xff, dev->iobase + DAQP_SCANLIST);
+		outb((val >> 8) & 0xff, dev->iobase + DAQP_SCANLIST);
+	}
 }
 
 /* One-shot analog data acquisition routine */
@@ -283,11 +289,8 @@ static int daqp_ai_insn_read(struct comedi_device *dev,
 
 	outb(0, dev->iobase + DAQP_AUX);
 
-	/* Reset scan list queue */
-	outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
-
 	/* Program one scan list entry */
-	daqp_ai_set_one_scanlist_entry(dev, insn->chanspec, 1);
+	daqp_ai_set_scanlist(dev, &insn->chanspec, 1);
 
 	/* Reset data FIFO (see page 28 of DAQP User's Manual) */
 
@@ -438,7 +441,6 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 	struct comedi_cmd *cmd = &s->async->cmd;
 	int counter;
 	int threshold;
-	int i;
 	int v;
 
 	if (devpriv->stop)
@@ -449,20 +451,13 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
 
 	outb(0, dev->iobase + DAQP_AUX);
 
-	/* Reset scan list queue */
-	outb(DAQP_COMMAND_RSTQ, dev->iobase + DAQP_COMMAND);
-
 	/* Program pacer clock */
 	outb(devpriv->pacer_div & 0xff, dev->iobase + DAQP_PACER_LOW);
 	outb((devpriv->pacer_div >> 8) & 0xff, dev->iobase + DAQP_PACER_MID);
 	outb((devpriv->pacer_div >> 16) & 0xff, dev->iobase + DAQP_PACER_HIGH);
 
 	/* Program scan list */
-	for (i = 0; i < cmd->chanlist_len; i++) {
-		int start = (i == 0);
-
-		daqp_ai_set_one_scanlist_entry(dev, cmd->chanlist[i], start);
-	}
+	daqp_ai_set_scanlist(dev, cmd->chanlist, cmd->chanlist_len);
 
 	/* Now it's time to program the FIFO threshold, basically the
 	 * number of samples the card will buffer before it interrupts
-- 
2.5.1

_______________________________________________
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