[PATCH 07/15] staging: comedi: hwdrv_apci3501: refactor apci3501_config_insn_timer()

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

 



The handling for the watchdog and timer modes is very similar. Refactor
this function to use a common code path for both modes.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 .../comedi/drivers/addi-data/hwdrv_apci3501.c      | 59 +++++++++-------------
 1 file changed, 23 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
index 47c6bc1..e5209eb 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c
@@ -22,55 +22,42 @@ static int apci3501_config_insn_timer(struct comedi_device *dev,
 				      unsigned int *data)
 {
 	struct apci3501_private *devpriv = dev->private;
-	unsigned int ctrl = 0;
+	unsigned int ctrl;
+
+	if (data[0] != ADDIDATA_WATCHDOG &&
+	    data[0] != ADDIDATA_TIMER)
+		return -EINVAL;
 
 	devpriv->tsk_Current = current;
-	if (data[0] == ADDIDATA_WATCHDOG) {
-
-		devpriv->timer_mode = ADDIDATA_WATCHDOG;
-		/* Disable the watchdog */
-		outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
-
-		if (data[1] == 1) {
-			/* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
-			outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
-		} else {
-			/* disable Timer interrupt */
-			outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
-		}
 
-		outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
-		outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
+	devpriv->timer_mode = data[0];
 
-		/* Set the mode (e2->e0) */
+	/* first, disable the watchdog or stop the timer */
+	if (devpriv->timer_mode == ADDIDATA_WATCHDOG) {
+		ctrl = 0;
+	} else {
 		ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
-		ctrl |= 0xfff819e0;
-		outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
+		ctrl &= 0xfffff9fe;
 	}
+	outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
 
-	else if (data[0] == ADDIDATA_TIMER) {
-		/* First Stop The Timer */
-		ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
-		ctrl &= 0xfffff9fe;
-		outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
-		devpriv->timer_mode = ADDIDATA_TIMER;
-		if (data[1] == 1) {
-			/* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
-			outl(0x02, dev->iobase + APCI3501_TIMER_CTRL_REG);
-		} else {
-			/* disable Timer interrupt */
-			outl(0x0, dev->iobase + APCI3501_TIMER_CTRL_REG);
-		}
+	/* enable/disable the timer interrupt */
+	ctrl = (data[1] == 1) ? 0x2 : 0;
+	outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
 
-		outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
-		outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
+	outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG);
+	outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG);
 
+	ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
+	if (devpriv->timer_mode == ADDIDATA_WATCHDOG) {
+		/* Set the mode (e2->e0) NOTE: this doesn't look correct */
+		ctrl |= 0xfff819e0;
+	} else {
 		/* mode 2 */
-		ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG);
 		ctrl &= 0xfff719e2;
 		ctrl |= (2 << 13) | 0x10;
-		outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
 	}
+	outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG);
 
 	return insn->n;
 }
-- 
2.4.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