From cd5d0ae4814f4f943c97c83f7f2f393a99b4d3a0 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 12 Aug 2015 13:25:46 -0700 Subject: [PATCH] staging: comedi: addi_apci_3501: use addi_tcw.h for the timer registers The APCI3501_TIMER_* register defines in this driver are that same as the ADDI_TCW_* defines with an additional offset. Add a 'tcw' (timer/counter/watchdog) member to the private data to hold the address for the iobase of the registers. Use that and the defines from addi_tcw.h to address the registers. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../comedi/drivers/addi-data/hwdrv_apci3501.c | 24 ++++++++--------- .../staging/comedi/drivers/addi_apci_3501.c | 26 ++++++++----------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c index e5209eb591f2..8ba094cc31f4 100644 --- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c +++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3501.c @@ -36,19 +36,19 @@ static int apci3501_config_insn_timer(struct comedi_device *dev, if (devpriv->timer_mode == ADDIDATA_WATCHDOG) { ctrl = 0; } else { - ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); + ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG); ctrl &= 0xfffff9fe; } - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); /* enable/disable the timer interrupt */ ctrl = (data[1] == 1) ? 0x2 : 0; - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); - outl(data[2], dev->iobase + APCI3501_TIMER_TIMEBASE_REG); - outl(data[3], dev->iobase + APCI3501_TIMER_RELOAD_REG); + outl(data[2], devpriv->tcw + ADDI_TCW_TIMEBASE_REG); + outl(data[3], devpriv->tcw + ADDI_TCW_RELOAD_REG); - ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); + ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG); if (devpriv->timer_mode == ADDIDATA_WATCHDOG) { /* Set the mode (e2->e0) NOTE: this doesn't look correct */ ctrl |= 0xfff819e0; @@ -57,7 +57,7 @@ static int apci3501_config_insn_timer(struct comedi_device *dev, ctrl &= 0xfff719e2; ctrl |= (2 << 13) | 0x10; } - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); return insn->n; } @@ -84,7 +84,7 @@ static int apci3501_write_insn_timer(struct comedi_device *dev, if (devpriv->timer_mode == ADDIDATA_WATCHDOG || devpriv->timer_mode == ADDIDATA_TIMER) { - ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); + ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG); ctrl &= 0xfffff9ff; if (data[1] == 1) { /* enable */ @@ -97,10 +97,10 @@ static int apci3501_write_insn_timer(struct comedi_device *dev, } else if (data[1] == 2) { /* trigger */ ctrl |= 0x200; } - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); } - inl(dev->iobase + APCI3501_TIMER_STATUS_REG); + inl(devpriv->tcw + ADDI_TCW_STATUS_REG); return insn->n; } @@ -125,8 +125,8 @@ static int apci3501_read_insn_timer(struct comedi_device *dev, devpriv->timer_mode != ADDIDATA_WATCHDOG) return -EINVAL; - data[0] = inl(dev->iobase + APCI3501_TIMER_STATUS_REG) & 0x1; - data[1] = inl(dev->iobase + APCI3501_TIMER_SYNC_REG); + data[0] = inl(devpriv->tcw + ADDI_TCW_STATUS_REG) & 0x1; + data[1] = inl(devpriv->tcw + ADDI_TCW_VAL_REG); return insn->n; } diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 16684c01cfd6..4faa23bcdcd5 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -27,6 +27,7 @@ #include #include "../comedi_pci.h" +#include "addi_tcw.h" #include "amcc_s5933.h" /* @@ -40,14 +41,7 @@ #define APCI3501_AO_DATA_VAL(x) ((x) << 8) #define APCI3501_AO_DATA_BIPOLAR BIT(31) #define APCI3501_AO_TRIG_SCS_REG 0x08 -#define APCI3501_TIMER_SYNC_REG 0x20 -#define APCI3501_TIMER_RELOAD_REG 0x24 -#define APCI3501_TIMER_TIMEBASE_REG 0x28 -#define APCI3501_TIMER_CTRL_REG 0x2c -#define APCI3501_TIMER_STATUS_REG 0x30 -#define APCI3501_TIMER_IRQ_REG 0x34 -#define APCI3501_TIMER_WARN_RELOAD_REG 0x38 -#define APCI3501_TIMER_WARN_TIMEBASE_REG 0x3c +#define APCI3501_TIMER_BASE 0x20 #define APCI3501_DO_REG 0x40 #define APCI3501_DI_REG 0x50 @@ -73,6 +67,7 @@ struct apci3501_private { unsigned long amcc; + unsigned long tcw; struct task_struct *tsk_Current; unsigned char timer_mode; }; @@ -266,11 +261,11 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) unsigned int ctrl; /* Disable Interrupt */ - ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); + ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG); ctrl &= 0xfffff9fd; - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); - status = inl(dev->iobase + APCI3501_TIMER_IRQ_REG) & 0x1; + status = inl(devpriv->tcw + ADDI_TCW_IRQ_REG) & 0x1; if (!status) { dev_err(dev->class_dev, "IRQ from unknown source\n"); return IRQ_NONE; @@ -278,11 +273,11 @@ static irqreturn_t apci3501_interrupt(int irq, void *d) /* Enable Interrupt Send a signal to from kernel to user space */ send_sig(SIGIO, devpriv->tsk_Current, 0); - ctrl = inl(dev->iobase + APCI3501_TIMER_CTRL_REG); + ctrl = inl(devpriv->tcw + ADDI_TCW_CTRL_REG); ctrl &= 0xfffff9fd; ctrl |= 1 << 1; - outl(ctrl, dev->iobase + APCI3501_TIMER_CTRL_REG); - inl(dev->iobase + APCI3501_TIMER_STATUS_REG); + outl(ctrl, devpriv->tcw + ADDI_TCW_CTRL_REG); + inl(devpriv->tcw + ADDI_TCW_STATUS_REG); return IRQ_HANDLED; } @@ -334,8 +329,9 @@ static int apci3501_auto_attach(struct comedi_device *dev, if (ret) return ret; - dev->iobase = pci_resource_start(pcidev, 1); devpriv->amcc = pci_resource_start(pcidev, 0); + dev->iobase = pci_resource_start(pcidev, 1); + devpriv->tcw = dev->iobase + APCI3501_TIMER_BASE; ao_n_chan = apci3501_eeprom_get_ao_n_chan(dev); -- 2.20.1