staging: comedi: addi_apci_3120: tidy up timer_mode masking
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 4 Nov 2014 17:53:53 +0000 (10:53 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 7 Nov 2014 17:33:58 +0000 (09:33 -0800)
Define a macro that returns the mask of the timer_mode bits for a given
timer. Use the macro to remove the "magic" values used to clear the bits.

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
drivers/staging/comedi/drivers/addi_apci_3120.c

index 546c4c3735507a2fcab4bff9300164be5ff7f1fc..a876adae58d2ee813fa92298e532caadf52b6cdc 100644 (file)
@@ -373,7 +373,7 @@ static int apci3120_ai_insn_read(struct comedi_device *dev,
                                return -EINVAL;
 
                        /* Initialize Timer 0 mode 4 */
-                       devpriv->timer_mode &= 0xfc;
+                       devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(0);
                        devpriv->timer_mode |= APCI3120_TIMER_0_MODE_4;
                        outb(devpriv->timer_mode,
                             dev->iobase + APCI3120_TIMER_CRT1);
@@ -456,7 +456,7 @@ static int apci3120_ai_insn_read(struct comedi_device *dev,
                                return -EINVAL;
 
                        /* Initialize Timer 0 mode 2 */
-                       devpriv->timer_mode &= 0xfc;
+                       devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(0);
                        devpriv->timer_mode |= APCI3120_TIMER_0_MODE_2;
                        outb(devpriv->timer_mode,
                             dev->iobase + APCI3120_TIMER_CRT1);
@@ -755,7 +755,7 @@ static int apci3120_cyclic_ai(int mode,
        switch (mode) {
        case 1:
                /*  init timer0 in mode 2 */
-               devpriv->timer_mode &= 0xfc;
+               devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(0);
                devpriv->timer_mode |= APCI3120_TIMER_0_MODE_2;
                outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_CRT1);
 
@@ -765,7 +765,7 @@ static int apci3120_cyclic_ai(int mode,
 
        case 2:
                /*  init timer1 in mode 2 */
-               devpriv->timer_mode &= 0xf3;
+               devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(1);
                devpriv->timer_mode |= APCI3120_TIMER_1_MODE_2;
                outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_CRT1);
 
@@ -773,7 +773,7 @@ static int apci3120_cyclic_ai(int mode,
                apci3120_timer_write(dev, 1, divisor1);
 
                /*  init timer0 in mode 2 */
-               devpriv->timer_mode &= 0xfc;
+               devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(0);
                devpriv->timer_mode |= APCI3120_TIMER_0_MODE_2;
                outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_CRT1);
 
@@ -824,7 +824,7 @@ static int apci3120_cyclic_ai(int mode,
                                dev->iobase + APCI3120_WRITE_MODE_SELECT);
 
                        /* (1) Init timer 2 in mode 0 and write timer value */
-                       devpriv->timer_mode &= 0x0f;
+                       devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(2);
                        devpriv->timer_mode |= APCI3120_TIMER_2_MODE_0;
                        outb(devpriv->timer_mode,
                             dev->iobase + APCI3120_TIMER_CRT1);
@@ -1422,7 +1422,7 @@ static int apci3120_config_insn_timer(struct comedi_device *dev,
             dev->iobase + APCI3120_WRITE_MODE_SELECT);
        if (data[0] == APCI3120_TIMER) {        /* initialize timer */
                /* Set the Timer 2 in mode 2(Timer) */
-               devpriv->timer_mode &= 0x0f;
+               devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(2);
                devpriv->timer_mode |= APCI3120_TIMER_2_MODE_2;
                outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_CRT1);
 
@@ -1435,7 +1435,7 @@ static int apci3120_config_insn_timer(struct comedi_device *dev,
        } else {                        /*  Initialize Watch dog */
 
                /* Set the Timer 2 in mode 5(Watchdog) */
-               devpriv->timer_mode &= 0x0f;
+               devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(2);
                devpriv->timer_mode |= APCI3120_TIMER_2_MODE_5;
                outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_CRT1);
 
index 6882f8ee67a4d98e65c286b7a1cf69c9e98b6a23..999add3928ef05e5b7cebb9086cb84c85fe52d13 100644 (file)
@@ -20,6 +20,7 @@
 #define APCI3120_AO_REG(x)                     (0x08 + (((x) / 4) * 2))
 #define APCI3120_AO_MUX(x)                     (((x) & 0x3) << 14)
 #define APCI3120_AO_DATA(x)                    ((x) << 0)
+#define APCI3120_TIMER_MODE_MASK(_t)           (3 << ((_t) * 2))
 #define APCI3120_CTR0_REG                      0x0d
 #define APCI3120_CTR0_DO_BITS(x)               ((x) << 4)
 #define APCI3120_CTR0_TIMER_SEL(x)             ((x) << 0)