From f01620914699679a26212affa358e5bbc5ede63e Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 12 Aug 2014 11:41:29 -0700 Subject: [PATCH] staging: comedi: 8255: provide common defines for registers There are a couple comedi drivers that duplicate some of the register defines used by the 8255 module. Move these defines into the header so the duplication can be removed. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/8255.c | 42 +++++++------------ drivers/staging/comedi/drivers/8255.h | 14 +++++++ drivers/staging/comedi/drivers/8255_pci.c | 4 +- drivers/staging/comedi/drivers/adv_pci_dio.c | 3 +- .../comedi/drivers/amplc_dio200_common.c | 35 +++++++--------- drivers/staging/comedi/drivers/cb_pcidda.c | 2 +- drivers/staging/comedi/drivers/pcl724.c | 6 +-- drivers/staging/comedi/drivers/pcm3724.c | 26 ++++-------- 8 files changed, 56 insertions(+), 76 deletions(-) diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index be56e167cfd5..34d4d8b5f31e 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -79,19 +79,6 @@ I/O port base address can be found in the output of 'lspci -v'. #include "comedi_fc.h" #include "8255.h" -#define _8255_SIZE 4 - -#define _8255_DATA 0 -#define _8255_CR 3 - -#define CR_C_LO_IO 0x01 -#define CR_B_IO 0x02 -#define CR_B_MODE 0x04 -#define CR_C_HI_IO 0x08 -#define CR_A_IO 0x10 -#define CR_A_MODE(a) ((a)<<5) -#define CR_CW 0x80 - struct subdev_8255_private { unsigned long regbase; int (*io)(struct comedi_device *, int, int, int, unsigned long); @@ -130,18 +117,19 @@ static int subdev_8255_insn(struct comedi_device *dev, mask = comedi_dio_update_state(s, data); if (mask) { if (mask & 0xff) - spriv->io(dev, 1, _8255_DATA, s->state & 0xff, regbase); + spriv->io(dev, 1, I8255_DATA_A_REG, + s->state & 0xff, regbase); if (mask & 0xff00) - spriv->io(dev, 1, _8255_DATA + 1, + spriv->io(dev, 1, I8255_DATA_B_REG, (s->state >> 8) & 0xff, regbase); if (mask & 0xff0000) - spriv->io(dev, 1, _8255_DATA + 2, + spriv->io(dev, 1, I8255_DATA_C_REG, (s->state >> 16) & 0xff, regbase); } - v = spriv->io(dev, 0, _8255_DATA, 0, regbase); - v |= (spriv->io(dev, 0, _8255_DATA + 1, 0, regbase) << 8); - v |= (spriv->io(dev, 0, _8255_DATA + 2, 0, regbase) << 16); + v = spriv->io(dev, 0, I8255_DATA_A_REG, 0, regbase); + v |= (spriv->io(dev, 0, I8255_DATA_B_REG, 0, regbase) << 8); + v |= (spriv->io(dev, 0, I8255_DATA_C_REG, 0, regbase) << 16); data[1] = v; @@ -155,18 +143,18 @@ static void subdev_8255_do_config(struct comedi_device *dev, unsigned long regbase = spriv->regbase; int config; - config = CR_CW; + config = I8255_CTRL_CW; /* 1 in io_bits indicates output, 1 in config indicates input */ if (!(s->io_bits & 0x0000ff)) - config |= CR_A_IO; + config |= I8255_CTRL_A_IO; if (!(s->io_bits & 0x00ff00)) - config |= CR_B_IO; + config |= I8255_CTRL_B_IO; if (!(s->io_bits & 0x0f0000)) - config |= CR_C_LO_IO; + config |= I8255_CTRL_C_LO_IO; if (!(s->io_bits & 0xf00000)) - config |= CR_C_HI_IO; + config |= I8255_CTRL_C_HI_IO; - spriv->io(dev, 1, _8255_CR, config, regbase); + spriv->io(dev, 1, I8255_CTRL_REG, config, regbase); } static int subdev_8255_insn_config(struct comedi_device *dev, @@ -286,7 +274,7 @@ static int dev_8255_attach(struct comedi_device *dev, * comedi_config, the 'iobase' is the actual I/O port * base address of the chip. */ - ret = __comedi_request_region(dev, iobase, _8255_SIZE); + ret = __comedi_request_region(dev, iobase, I8255_SIZE); if (ret) { s->type = COMEDI_SUBD_UNUSED; } else { @@ -309,7 +297,7 @@ static void dev_8255_detach(struct comedi_device *dev) s = &dev->subdevices[i]; if (s->type != COMEDI_SUBD_UNUSED) { spriv = s->private; - release_region(spriv->regbase, _8255_SIZE); + release_region(spriv->regbase, I8255_SIZE); } } } diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h index c7c6deeed026..5985c8e0330f 100644 --- a/drivers/staging/comedi/drivers/8255.h +++ b/drivers/staging/comedi/drivers/8255.h @@ -21,6 +21,20 @@ #include "../comedidev.h" +#define I8255_SIZE 0x04 + +#define I8255_DATA_A_REG 0x00 +#define I8255_DATA_B_REG 0x01 +#define I8255_DATA_C_REG 0x02 +#define I8255_CTRL_REG 0x03 +#define I8255_CTRL_C_LO_IO (1 << 0) +#define I8255_CTRL_B_IO (1 << 1) +#define I8255_CTRL_B_MODE (1 << 2) +#define I8255_CTRL_C_HI_IO (1 << 3) +#define I8255_CTRL_A_IO (1 << 4) +#define I8255_CTRL_A_MODE(x) ((x) << 5) +#define I8255_CTRL_CW (1 << 7) + int subdev_8255_init(struct comedi_device *, struct comedi_subdevice *, int (*io)(struct comedi_device *, int, int, int, unsigned long), diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index eb1ca0e85912..8bcb1e0e6a71 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -236,9 +236,9 @@ static int pci_8255_auto_attach(struct comedi_device *dev, for (i = 0; i < board->n_8255; i++) { s = &dev->subdevices[i]; if (dev->mmio) - ret = subdev_8255_mm_init(dev, s, NULL, i * 4); + ret = subdev_8255_mm_init(dev, s, NULL, i * I8255_SIZE); else - ret = subdev_8255_init(dev, s, NULL, i * 4); + ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE); if (ret) return ret; } diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c index 596d17c832e0..f3e2268d4fee 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -66,7 +66,6 @@ enum hw_io_access { * subdevice) */ #define SIZE_8254 4 /* 8254 IO space length */ -#define SIZE_8255 4 /* 8255 IO space length */ #define PCIDIO_MAINREG 2 /* main I/O region for all Advantech cards? */ @@ -1133,7 +1132,7 @@ static int pci_dio_auto_attach(struct comedi_device *dev, s = &dev->subdevices[subdev]; ret = subdev_8255_init(dev, s, NULL, this_board->sdio[i].addr + - SIZE_8255 * j); + j * I8255_SIZE); if (ret) return ret; subdev++; diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c index 87c01692d800..6cadf7e19c94 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c @@ -27,15 +27,7 @@ #include "amplc_dio200.h" #include "comedi_fc.h" #include "8253.h" - -/* 8255 control register bits */ -#define CR_C_LO_IO 0x01 -#define CR_B_IO 0x02 -#define CR_B_MODE 0x04 -#define CR_C_HI_IO 0x08 -#define CR_A_IO 0x10 -#define CR_A_MODE(a) ((a)<<5) -#define CR_CW 0x80 +#include "8255.h" /* only for register defines */ /* 200 series registers */ #define DIO200_IO_SIZE 0x20 @@ -815,17 +807,17 @@ static void dio200_subdev_8255_set_dir(struct comedi_device *dev, struct dio200_subdev_8255 *subpriv = s->private; int config; - config = CR_CW; + config = I8255_CTRL_CW; /* 1 in io_bits indicates output, 1 in config indicates input */ if (!(s->io_bits & 0x0000ff)) - config |= CR_A_IO; + config |= I8255_CTRL_A_IO; if (!(s->io_bits & 0x00ff00)) - config |= CR_B_IO; + config |= I8255_CTRL_B_IO; if (!(s->io_bits & 0x0f0000)) - config |= CR_C_LO_IO; + config |= I8255_CTRL_C_LO_IO; if (!(s->io_bits & 0xf00000)) - config |= CR_C_HI_IO; - dio200_write8(dev, subpriv->ofs + 3, config); + config |= I8255_CTRL_C_HI_IO; + dio200_write8(dev, subpriv->ofs + I8255_CTRL_REG, config); } static int dio200_subdev_8255_bits(struct comedi_device *dev, @@ -840,18 +832,19 @@ static int dio200_subdev_8255_bits(struct comedi_device *dev, mask = comedi_dio_update_state(s, data); if (mask) { if (mask & 0xff) - dio200_write8(dev, subpriv->ofs, s->state & 0xff); + dio200_write8(dev, subpriv->ofs + I8255_DATA_A_REG, + s->state & 0xff); if (mask & 0xff00) - dio200_write8(dev, subpriv->ofs + 1, + dio200_write8(dev, subpriv->ofs + I8255_DATA_B_REG, (s->state >> 8) & 0xff); if (mask & 0xff0000) - dio200_write8(dev, subpriv->ofs + 2, + dio200_write8(dev, subpriv->ofs + I8255_DATA_C_REG, (s->state >> 16) & 0xff); } - val = dio200_read8(dev, subpriv->ofs); - val |= dio200_read8(dev, subpriv->ofs + 1) << 8; - val |= dio200_read8(dev, subpriv->ofs + 2) << 16; + val = dio200_read8(dev, subpriv->ofs + I8255_DATA_A_REG); + val |= dio200_read8(dev, subpriv->ofs + I8255_DATA_B_REG) << 8; + val |= dio200_read8(dev, subpriv->ofs + I8255_DATA_C_REG) << 16; data[1] = val; diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index 2ffb9ca17995..91ba90b5ceae 100644 --- a/drivers/staging/comedi/drivers/cb_pcidda.c +++ b/drivers/staging/comedi/drivers/cb_pcidda.c @@ -378,7 +378,7 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev, /* two 8255 digital io subdevices */ for (i = 0; i < 2; i++) { s = &dev->subdevices[1 + i]; - ret = subdev_8255_init(dev, s, NULL, i * 4); + ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE); if (ret) return ret; } diff --git a/drivers/staging/comedi/drivers/pcl724.c b/drivers/staging/comedi/drivers/pcl724.c index 3acbbc65ca64..84c768fefffb 100644 --- a/drivers/staging/comedi/drivers/pcl724.c +++ b/drivers/staging/comedi/drivers/pcl724.c @@ -32,8 +32,6 @@ #include "8255.h" -#define SIZE_8255 4 - struct pcl724_board { const char *name; unsigned int io_range; @@ -85,7 +83,7 @@ static int pcl724_8255mapped_io(struct comedi_device *dev, int dir, int port, int data, unsigned long iobase) { - int movport = SIZE_8255 * (iobase >> 12); + int movport = I8255_SIZE * (iobase >> 12); iobase &= 0x0fff; @@ -133,7 +131,7 @@ static int pcl724_attach(struct comedi_device *dev, ret = subdev_8255_init(dev, s, pcl724_8255mapped_io, iobase); } else { - ret = subdev_8255_init(dev, s, NULL, i * SIZE_8255); + ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE); } if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c index f6acf5de59bf..6176dfa24801 100644 --- a/drivers/staging/comedi/drivers/pcm3724.c +++ b/drivers/staging/comedi/drivers/pcm3724.c @@ -33,8 +33,6 @@ Copy/pasted/hacked from pcm724.c #include "8255.h" -#define SIZE_8255 4 - #define BUF_C0 0x1 #define BUF_B0 0x2 #define BUF_A0 0x4 @@ -49,16 +47,6 @@ Copy/pasted/hacked from pcm724.c #define GATE_B1 0x10 #define GATE_C1 0x8 -/* from 8255.c */ -#define CR_CW 0x80 -#define _8255_CR 3 -#define CR_B_IO 0x02 -#define CR_B_MODE 0x04 -#define CR_C_IO 0x09 -#define CR_A_IO 0x10 -#define CR_A_MODE(a) ((a)<<5) -#define CR_CW 0x80 - /* used to track configured dios */ struct priv_pcm3724 { int dio_1; @@ -98,26 +86,26 @@ static void do_3724_config(struct comedi_device *dev, int buffer_config; unsigned long port_8255_cfg; - config = CR_CW; + config = I8255_CTRL_CW; buffer_config = 0; /* 1 in io_bits indicates output, 1 in config indicates input */ if (!(s->io_bits & 0x0000ff)) - config |= CR_A_IO; + config |= I8255_CTRL_A_IO; if (!(s->io_bits & 0x00ff00)) - config |= CR_B_IO; + config |= I8255_CTRL_B_IO; if (!(s->io_bits & 0xff0000)) - config |= CR_C_IO; + config |= I8255_CTRL_C_HI_IO | I8255_CTRL_C_LO_IO; buffer_config = compute_buffer(0, 0, s_dio1); buffer_config = compute_buffer(buffer_config, 1, s_dio2); if (s == s_dio1) - port_8255_cfg = dev->iobase + _8255_CR; + port_8255_cfg = dev->iobase + I8255_CTRL_REG; else - port_8255_cfg = dev->iobase + SIZE_8255 + _8255_CR; + port_8255_cfg = dev->iobase + I8255_SIZE + I8255_CTRL_REG; outb(buffer_config, dev->iobase + 8); /* update buffer register */ @@ -211,7 +199,7 @@ static int pcm3724_attach(struct comedi_device *dev, for (i = 0; i < dev->n_subdevices; i++) { s = &dev->subdevices[i]; - ret = subdev_8255_init(dev, s, NULL, i * SIZE_8255); + ret = subdev_8255_init(dev, s, NULL, i * I8255_SIZE); if (ret) return ret; s->insn_config = subdev_3724_insn_config; -- 2.39.5