[PATCH 3/3] staging: comedi: adl_pci9111: simplify A/D trigger selection code

H Hartley Sweeten hsweeten at visionengravers.com
Thu May 29 17:35:10 UTC 2014


The functions pci9111_trigger_source_set(), pci9111_pretrigger_set(),
and pci9111_autoscan_set() are all used to select the A/D trigger type.
They all do a read/mask/set/write of the A/D Trigger Mode Control register.

Simplify the code by removing these helper functions and combining all
the trigger bits so that a single write can be used to set the register.

Signed-off-by: H Hartley Sweeten <hsweeten at visionengravers.com>
Cc: Ian Abbott <abbotti at mev.co.uk>
Cc: Greg Kroah-Hartman <gregk at linuxfoundation.org>
---
 drivers/staging/comedi/drivers/adl_pci9111.c | 94 ++++------------------------
 1 file changed, 13 insertions(+), 81 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index 53c61de..51edfeb 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -186,68 +186,6 @@ static void pci9111_timer_set(struct comedi_device *dev)
 	i8254_write(timer_base, 1, 1, dev_private->div1);
 }
 
-enum pci9111_trigger_sources {
-	software,
-	timer_pacer,
-	external
-};
-
-static void pci9111_trigger_source_set(struct comedi_device *dev,
-				       enum pci9111_trigger_sources source)
-{
-	int flags;
-
-	/* Read the current trigger mode control bits */
-	flags = inb(dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-	/* Mask off the EITS and TPST bits */
-	flags &= 0x9;
-
-	switch (source) {
-	case software:
-		break;
-
-	case timer_pacer:
-		flags |= PCI9111_AI_TRIG_CTRL_TPST;
-		break;
-
-	case external:
-		flags |= PCI9111_AI_TRIG_CTRL_ETIS;
-		break;
-	}
-
-	outb(flags, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-}
-
-static void pci9111_pretrigger_set(struct comedi_device *dev, bool pretrigger)
-{
-	int flags;
-
-	/* Read the current trigger mode control bits */
-	flags = inb(dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-	/* Mask off the PTRG bit */
-	flags &= 0x7;
-
-	if (pretrigger)
-		flags |= PCI9111_AI_TRIG_CTRL_PTRG;
-
-	outb(flags, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-}
-
-static void pci9111_autoscan_set(struct comedi_device *dev, bool autoscan)
-{
-	int flags;
-
-	/* Read the current trigger mode control bits */
-	flags = inb(dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-	/* Mask off the ASCAN bit */
-	flags &= 0xe;
-
-	if (autoscan)
-		flags |= PCI9111_AI_TRIG_CTRL_ASCAN;
-
-	outb(flags, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
-}
-
 enum pci9111_ISC0_sources {
 	irq_on_eoc,
 	irq_on_fifo_half_full
@@ -300,9 +238,8 @@ static int pci9111_ai_cancel(struct comedi_device *dev,
 	plx9050_interrupt_control(dev_private->lcr_io_base, true, true, true,
 				  true, false);
 
-	pci9111_trigger_source_set(dev, software);
-
-	pci9111_autoscan_set(dev, false);
+	/* disable A/D triggers (software trigger mode) and auto scan off */
+	outb(0, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
 
 	pci9111_fifo_reset(dev);
 
@@ -451,20 +388,17 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
 {
 	struct pci9111_private_data *dev_private = dev->private;
 	struct comedi_cmd *cmd = &s->async->cmd;
+	unsigned int last_chan = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
+	unsigned int trig = 0;
 
 	/*  Set channel scan limit */
 	/*  PCI9111 allows only scanning from channel 0 to channel n */
 	/*  TODO: handle the case of an external multiplexer */
 
-	if (cmd->chanlist_len > 1) {
-		outb(cmd->chanlist_len - 1,
-			dev->iobase + PCI9111_AI_CHANNEL_REG);
-		pci9111_autoscan_set(dev, true);
-	} else {
-		outb(CR_CHAN(cmd->chanlist[0]),
-			dev->iobase + PCI9111_AI_CHANNEL_REG);
-		pci9111_autoscan_set(dev, false);
-	}
+	if (cmd->chanlist_len > 1)
+		trig |= PCI9111_AI_TRIG_CTRL_ASCAN;
+
+	outb(last_chan, dev->iobase + PCI9111_AI_CHANNEL_REG);
 
 	/*  Set gain */
 	/*  This is the same gain on every channel */
@@ -481,12 +415,11 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
 	/*  Set timer pacer */
 	dev_private->scan_delay = 0;
 	if (cmd->convert_src == TRIG_TIMER) {
-		pci9111_trigger_source_set(dev, software);
+		trig |= PCI9111_AI_TRIG_CTRL_TPST;
 		pci9111_timer_set(dev);
 		pci9111_fifo_reset(dev);
 		pci9111_interrupt_source_set(dev, irq_on_fifo_half_full,
 					     irq_on_timer_tick);
-		pci9111_trigger_source_set(dev, timer_pacer);
 		plx9050_interrupt_control(dev_private->lcr_io_base, true, true,
 					  false, true, true);
 
@@ -495,14 +428,14 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
 				(cmd->convert_arg * cmd->chanlist_len)) - 1;
 		}
 	} else {	/* TRIG_EXT */
-		pci9111_trigger_source_set(dev, external);
+		trig |= PCI9111_AI_TRIG_CTRL_ETIS;
 		pci9111_fifo_reset(dev);
 		pci9111_interrupt_source_set(dev, irq_on_fifo_half_full,
 					     irq_on_timer_tick);
 		plx9050_interrupt_control(dev_private->lcr_io_base, true, true,
 					  false, true, true);
-
 	}
+	outb(trig, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
 
 	dev_private->stop_counter *= (1 + dev_private->scan_delay);
 	dev_private->chunk_counter = 0;
@@ -768,9 +701,8 @@ static int pci9111_reset(struct comedi_device *dev)
 	plx9050_interrupt_control(dev_private->lcr_io_base, true, true, true,
 				  true, false);
 
-	pci9111_trigger_source_set(dev, software);
-	pci9111_pretrigger_set(dev, false);
-	pci9111_autoscan_set(dev, false);
+	/* disable A/D triggers (software trigger mode) and auto scan off */
+	outb(0, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
 
 	/* Reset 8254 chip */
 	dev_private->div1 = 0;
-- 
1.9.2



More information about the devel mailing list