staging: comedi: addi_apci_3120: introduce apci3120_timer_enable()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 4 Nov 2014 17:54:02 +0000 (10:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:33:58 +0000 (09:33 -0800)
Introduce a helper function to enable/disable a timer.

The disable of timers 0 and 1 in apci3120_interrupt() is probably not needed.
For now use the helper function to make sure the devpriv->ctrl bits are cleared
correctly to disable the timers.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c

index 30606c947530f1c826c1659f43493926cafcc50b..8da1db546b194b9431cf3d7e02dd797b2cd94ff5 100644 (file)
@@ -156,6 +156,18 @@ static const struct comedi_lrange range_apci3120_ai = {
        }
 };
 
+static void apci3120_timer_enable(struct comedi_device *dev,
+                                 unsigned int timer, bool enable)
+{
+       struct apci3120_private *devpriv = dev->private;
+
+       if (enable)
+               devpriv->ctrl |= APCI3120_CTRL_GATE(timer);
+       else
+               devpriv->ctrl &= ~APCI3120_CTRL_GATE(timer);
+       outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+}
+
 static int apci3120_ai_insn_config(struct comedi_device *dev,
                                   struct comedi_subdevice *s,
                                   struct comedi_insn *insn,
@@ -329,9 +341,7 @@ static int apci3120_ai_insn_read(struct comedi_device *dev,
                        outb(devpriv->b_ModeSelectRegister,
                             dev->iobase + APCI3120_WRITE_MODE_SELECT);
 
-                       /*  Sets gate 0 */
-                       devpriv->ctrl |= APCI3120_CTRL_GATE(0);
-                       outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+                       apci3120_timer_enable(dev, 0, true);
 
                        /* Set the conversion time */
                        apci3120_timer_write(dev, 0, divisor);
@@ -402,9 +412,7 @@ static int apci3120_ai_insn_read(struct comedi_device *dev,
 
                        inw(dev->iobase + APCI3120_RD_STATUS);
 
-                       /* Sets gate 0 */
-                       devpriv->ctrl |= APCI3120_CTRL_GATE(0);
-                       outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+                       apci3120_timer_enable(dev, 0, true);
 
                        /* Start conversion */
                        outw(0, dev->iobase + APCI3120_START_CONVERSION);
@@ -887,25 +895,17 @@ static int apci3120_cyclic_ai(int mode,
        }
 
        if (devpriv->us_UseDma == APCI3120_DISABLE &&
-           cmd->stop_src == TRIG_COUNT) {
-               /*  set gate 2   to start conversion */
-               devpriv->ctrl |= APCI3120_CTRL_GATE(2);
-               outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
-       }
+           cmd->stop_src == TRIG_COUNT)
+               apci3120_timer_enable(dev, 2, true);
 
        switch (mode) {
        case 1:
-               /*  set gate 0   to start conversion */
-               devpriv->ctrl |= APCI3120_CTRL_GATE(0);
-               outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+               apci3120_timer_enable(dev, 0, true);
                break;
        case 2:
-               /*  set  gate 0 and gate 1 */
-               devpriv->ctrl |= APCI3120_CTRL_GATE(1) |
-                                APCI3120_CTRL_GATE(0);
-               outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+               apci3120_timer_enable(dev, 1, true);
+               apci3120_timer_enable(dev, 0, true);
                break;
-
        }
 
        return 0;
@@ -1234,11 +1234,8 @@ static irqreturn_t apci3120_interrupt(int irq, void *d)
                        /* do some data transfer */
                        apci3120_interrupt_dma(irq, d);
                } else {
-                       /* Stops the Timer */
-                       outw(devpriv->ctrl &
-                            ~APCI3120_CTRL_GATE(0) &
-                            ~APCI3120_CTRL_GATE(1),
-                            dev->iobase + APCI3120_WR_ADDRESS);
+                       apci3120_timer_enable(dev, 0, false);
+                       apci3120_timer_enable(dev, 1, false);
                }
 
        }
@@ -1270,9 +1267,7 @@ static int apci3120_config_insn_timer(struct comedi_device *dev,
 
        divisor = apci3120_ns_to_timer(dev, 2, data[1], CMDF_ROUND_DOWN);
 
-       /* Reset gate 2 of Timer 2 to disable it (Set Bit D14 to 0) */
-       devpriv->ctrl &= ~APCI3120_CTRL_GATE(2);
-       outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
+       apci3120_timer_enable(dev, 2, false);
 
        /*  Disable TIMER Interrupt */
        devpriv->b_ModeSelectRegister =
@@ -1381,12 +1376,9 @@ static int apci3120_write_insn_timer(struct comedi_device *dev,
                outb(devpriv->b_ModeSelectRegister,
                     dev->iobase + APCI3120_WRITE_MODE_SELECT);
 
-               if (devpriv->b_Timer2Mode == APCI3120_TIMER) {  /* start timer */
-                       /* For Timer mode is  Gate2 must be activated   timer started */
-                       devpriv->ctrl |= APCI3120_CTRL_GATE(2);
-                       outw(devpriv->ctrl, dev->iobase + APCI3120_WR_ADDRESS);
-               }
-
+               /* start timer */
+               if (devpriv->b_Timer2Mode == APCI3120_TIMER)
+                       apci3120_timer_enable(dev, 2, true);
                break;
 
        case APCI3120_STOP:
This page took 0.027382 seconds and 5 git commands to generate.