From 2e2e74e17a315d376292764b323e54ec21daa18e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 4 Nov 2014 10:53:49 -0700 Subject: [PATCH] staging: comedi: addi_apci_3120: tidy up CTR0 register defines Define the CTR0 register in the main driver source file and remove all the old defines in hwrdv_apci3120.c. For aesthetics, save the raw digital output state (devpriv->do_bits) in the digital output (*insn_bits) function and use a macro to set them when reading/writing a timer. Use the CTR0 register define in the digital output (*insn_bits) function and remove the current register define. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/hwdrv_apci3120.c | 38 +++++++--------------- drivers/staging/comedi/drivers/addi_apci_3120.c | 2 ++ 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c index 7335a64..93b1725 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c @@ -86,16 +86,9 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY #define APCI3120_EOS_MODE 2 #define APCI3120_DMA_MODE 3 -/* DIGITAL INPUT-OUTPUT DEFINE */ - -#define APCI3120_DIGITAL_OUTPUT 0x0d #define APCI3120_RD_STATUS 0x02 #define APCI3120_RD_FIFO 0x00 -/* digital output insn_write ON /OFF selection */ -#define APCI3120_SET4DIGITALOUTPUTON 1 -#define APCI3120_SET4DIGITALOUTPUTOFF 0 - /* Enable external trigger bit in nWrAddress */ #define APCI3120_ENABLE_EXT_TRIGGER 0x8000 @@ -110,7 +103,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY #define APCI3120_RESET_FIFO 0x0c #define APCI3120_TIMER_0_MODE_2 0x01 #define APCI3120_TIMER_0_MODE_4 0x2 -#define APCI3120_SELECT_TIMER_0_WORD 0x00 #define APCI3120_ENABLE_TIMER0 0x1000 #define APCI3120_CLEAR_PR 0xf0ff #define APCI3120_CLEAR_PA 0xfff0 @@ -148,8 +140,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY #define APCI3120_ENABLE_TIMER_INT 0x04 #define APCI3120_DISABLE_TIMER_INT (~APCI3120_ENABLE_TIMER_INT) #define APCI3120_WRITE_MODE_SELECT 0x0e -#define APCI3120_SELECT_TIMER_0_WORD 0x00 -#define APCI3120_SELECT_TIMER_1_WORD 0x01 #define APCI3120_TIMER_1_MODE_2 0x4 /* $$ BIT FOR MODE IN nCsTimerCtr1 */ @@ -157,11 +147,6 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY #define APCI3120_TIMER_2_MODE_2 0x10 #define APCI3120_TIMER_2_MODE_5 0x30 -/* $$ BIT FOR MODE IN nCsTimerCtr0 */ -#define APCI3120_SELECT_TIMER_2_LOW_WORD 0x02 -#define APCI3120_SELECT_TIMER_2_HIGH_WORD 0x03 - -#define APCI3120_TIMER_CRT0 0x0d #define APCI3120_TIMER_CRT1 0x0c #define APCI3120_TIMER_VALUE 0x04 @@ -206,16 +191,16 @@ static void apci3120_timer_write(struct comedi_device *dev, struct apci3120_private *devpriv = dev->private; /* write 16-bit value to timer (lower 16-bits of timer 2) */ - outb(((devpriv->do_bits) & 0xF0) | + outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) | APCI3120_CTR0_TIMER_SEL(timer), - dev->iobase + APCI3120_TIMER_CRT0); + dev->iobase + APCI3120_CTR0_REG); outw(val & 0xffff, dev->iobase + APCI3120_TIMER_VALUE); if (timer == 2) { /* write upper 16-bits to timer 2 */ - outb(((devpriv->do_bits) & 0xF0) | + outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) | APCI3120_CTR0_TIMER_SEL(timer + 1), - dev->iobase + APCI3120_TIMER_CRT0); + dev->iobase + APCI3120_CTR0_REG); outw((val >> 16) & 0xffff, dev->iobase + APCI3120_TIMER_VALUE); } } @@ -227,16 +212,16 @@ static unsigned int apci3120_timer_read(struct comedi_device *dev, unsigned int val; /* read 16-bit value from timer (lower 16-bits of timer 2) */ - outb(((devpriv->do_bits) & 0xF0) | + outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) | APCI3120_CTR0_TIMER_SEL(timer), - dev->iobase + APCI3120_TIMER_CRT0); + dev->iobase + APCI3120_CTR0_REG); val = inw(dev->iobase + APCI3120_TIMER_VALUE); if (timer == 2) { /* read upper 16-bits from timer 2 */ - outb(((devpriv->do_bits) & 0xF0) | + outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) | APCI3120_CTR0_TIMER_SEL(timer + 1), - dev->iobase + APCI3120_TIMER_CRT0); + dev->iobase + APCI3120_CTR0_REG); val |= (inw(dev->iobase + APCI3120_TIMER_VALUE) << 16); } @@ -1693,10 +1678,9 @@ static int apci3120_do_insn_bits(struct comedi_device *dev, struct apci3120_private *devpriv = dev->private; if (comedi_dio_update_state(s, data)) { - /* The do channels are bits 7:4 of the do register */ - devpriv->do_bits = s->state << 4; - - outb(devpriv->do_bits, dev->iobase + APCI3120_DIGITAL_OUTPUT); + devpriv->do_bits = s->state; + outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits), + dev->iobase + APCI3120_CTR0_REG); } data[1] = s->state; diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c index 6819cc0..51637e1 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3120.c +++ b/drivers/staging/comedi/drivers/addi_apci_3120.c @@ -19,6 +19,8 @@ #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_CTR0_REG 0x0d +#define APCI3120_CTR0_DO_BITS(x) ((x) << 4) #define APCI3120_CTR0_TIMER_SEL(x) ((x) << 0) /* -- 2.7.4