diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2014-08-12 11:41:26 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-08-16 12:23:26 -0700 |
commit | 4085e93b9fecfad454159694c19efc36e7ac1cdf (patch) | |
tree | e53ed74de9d0b56b77c95019c1cab3d2128cd07f | |
parent | 2b1a3fcfdf4067290cafffb5bc348c158e170fd7 (diff) |
staging: comedi: 8255: refactor how the (*io) function works
Currently, all users of is module that use the default (*io) function
pass an 'iobase' to subdev_8255_init() of the form:
dev->iobase + OFFSET_TO_8255_BASE_REG
Now that the (*io) callback includes the comedi_device 'dev' pointer
the 'dev->iobase' does not need to be included.
Modify the default (*io) function, subdev_8255_io(), to automatically
add the dev->iobase to the address when reading/writing the port.
For aesthetics, rename the subdevice private data member to 'regbase'.
Also, rename the local variables in this module that are used to
access this member.
Add a comment in dev_8255_attach() about the 'iobase' that is passed
to subdev_8255_init(). For manually attached 8255 devices the io
region is requested with __comedi_request_region() which does not
set dev->iobase. For these devices the 'regbase' is actually the
'iobase'.
Remove the, now unnecessary, dev->iobase from all the callers of
subdev_8255_init(). There are a couple drivers that only passed the
dev->iobase. For those drivers pass a 'regbase' of 0x00.
Note that the das16m1 driver is a bit goofy. The devpriv->extra_iobase
is requested using __comedi_request_region() which does not set the
dev->iobase. But the starting address passed is dev->iobase + DAS16M1_82C55
so a 'regbase' of DAS16M1_82C55 is passed to subdev_8255_init().
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>
19 files changed, 49 insertions, 55 deletions
diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index 212e547ba77f..39cf12eeabc9 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -93,29 +93,29 @@ I/O port base address can be found in the output of 'lspci -v'. #define CR_CW 0x80 struct subdev_8255_private { - unsigned long iobase; + unsigned long regbase; int (*io)(struct comedi_device *, int, int, int, unsigned long); }; static int subdev_8255_io(struct comedi_device *dev, - int dir, int port, int data, unsigned long iobase) + int dir, int port, int data, unsigned long regbase) { if (dir) { - outb(data, iobase + port); + outb(data, dev->iobase + regbase + port); return 0; } - return inb(iobase + port); + return inb(dev->iobase + regbase + port); } void subdev_8255_interrupt(struct comedi_device *dev, struct comedi_subdevice *s) { struct subdev_8255_private *spriv = s->private; - unsigned long iobase = spriv->iobase; + unsigned long regbase = spriv->regbase; unsigned short d; - d = spriv->io(dev, 0, _8255_DATA, 0, iobase); - d |= (spriv->io(dev, 0, _8255_DATA + 1, 0, iobase) << 8); + d = spriv->io(dev, 0, _8255_DATA, 0, regbase); + d |= (spriv->io(dev, 0, _8255_DATA + 1, 0, regbase) << 8); comedi_buf_put(s, d); s->async->events |= COMEDI_CB_EOS; @@ -130,25 +130,25 @@ static int subdev_8255_insn(struct comedi_device *dev, unsigned int *data) { struct subdev_8255_private *spriv = s->private; - unsigned long iobase = spriv->iobase; + unsigned long regbase = spriv->regbase; unsigned int mask; unsigned int v; mask = comedi_dio_update_state(s, data); if (mask) { if (mask & 0xff) - spriv->io(dev, 1, _8255_DATA, s->state & 0xff, iobase); + spriv->io(dev, 1, _8255_DATA, s->state & 0xff, regbase); if (mask & 0xff00) spriv->io(dev, 1, _8255_DATA + 1, - (s->state >> 8) & 0xff, iobase); + (s->state >> 8) & 0xff, regbase); if (mask & 0xff0000) spriv->io(dev, 1, _8255_DATA + 2, - (s->state >> 16) & 0xff, iobase); + (s->state >> 16) & 0xff, regbase); } - v = spriv->io(dev, 0, _8255_DATA, 0, iobase); - v |= (spriv->io(dev, 0, _8255_DATA + 1, 0, iobase) << 8); - v |= (spriv->io(dev, 0, _8255_DATA + 2, 0, iobase) << 16); + 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); data[1] = v; @@ -159,7 +159,7 @@ static void subdev_8255_do_config(struct comedi_device *dev, struct comedi_subdevice *s) { struct subdev_8255_private *spriv = s->private; - unsigned long iobase = spriv->iobase; + unsigned long regbase = spriv->regbase; int config; config = CR_CW; @@ -173,7 +173,7 @@ static void subdev_8255_do_config(struct comedi_device *dev, if (!(s->io_bits & 0xf00000)) config |= CR_C_HI_IO; - spriv->io(dev, 1, _8255_CR, config, iobase); + spriv->io(dev, 1, _8255_CR, config, regbase); } static int subdev_8255_insn_config(struct comedi_device *dev, @@ -264,7 +264,7 @@ static int subdev_8255_cancel(struct comedi_device *dev, int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, int (*io)(struct comedi_device *, int, int, int, unsigned long), - unsigned long iobase) + unsigned long regbase) { struct subdev_8255_private *spriv; @@ -272,7 +272,7 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, if (!spriv) return -ENOMEM; - spriv->iobase = iobase; + spriv->regbase = regbase; spriv->io = io ? io : subdev_8255_io; s->type = COMEDI_SUBD_DIO; @@ -292,11 +292,11 @@ EXPORT_SYMBOL_GPL(subdev_8255_init); int subdev_8255_init_irq(struct comedi_device *dev, struct comedi_subdevice *s, int (*io)(struct comedi_device *, int, int, int, unsigned long), - unsigned long iobase) + unsigned long regbase) { int ret; - ret = subdev_8255_init(dev, s, io, iobase); + ret = subdev_8255_init(dev, s, io, regbase); if (ret) return ret; @@ -319,8 +319,8 @@ static int dev_8255_attach(struct comedi_device *dev, struct comedi_devconfig *it) { struct comedi_subdevice *s; - int ret; unsigned long iobase; + int ret; int i; for (i = 0; i < COMEDI_NDEVCONFOPTS; i++) { @@ -341,6 +341,13 @@ static int dev_8255_attach(struct comedi_device *dev, s = &dev->subdevices[i]; iobase = it->options[i]; + /* + * __comedi_request_region() does not set dev->iobase. + * + * For 8255 devices that are manually attached using + * comedi_config, the 'iobase' is the actual I/O port + * base address of the chip. + */ ret = __comedi_request_region(dev, iobase, _8255_SIZE); if (ret) { s->type = COMEDI_SUBD_UNUSED; @@ -364,7 +371,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->iobase, _8255_SIZE); + release_region(spriv->regbase, _8255_SIZE); } } } diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h index c2c20db2f1d0..978f0a7f8c1f 100644 --- a/drivers/staging/comedi/drivers/8255.h +++ b/drivers/staging/comedi/drivers/8255.h @@ -24,11 +24,11 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, int (*io)(struct comedi_device *, int, int, int, unsigned long), - unsigned long iobase); + unsigned long regbase); int subdev_8255_init_irq(struct comedi_device *dev, struct comedi_subdevice *s, int (*io)(struct comedi_device *, int, int, int, unsigned long), - unsigned long iobase); + unsigned long regbase); void subdev_8255_interrupt(struct comedi_device *dev, struct comedi_subdevice *s); diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index 1a3deec57381..15e85b6e67bd 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -247,15 +247,11 @@ static int pci_8255_auto_attach(struct comedi_device *dev, return ret; for (i = 0; i < board->n_8255; i++) { - unsigned long iobase; - s = &dev->subdevices[i]; - if (is_mmio) { + if (is_mmio) ret = subdev_8255_init(dev, s, pci_8255_mmio, i * 4); - } else { - iobase = dev->iobase + (i * 4); - ret = subdev_8255_init(dev, s, NULL, iobase); - } + else + ret = subdev_8255_init(dev, s, NULL, i * 4); 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 b8c7d9145a54..596d17c832e0 100644 --- a/drivers/staging/comedi/drivers/adv_pci_dio.c +++ b/drivers/staging/comedi/drivers/adv_pci_dio.c @@ -1132,7 +1132,6 @@ static int pci_dio_auto_attach(struct comedi_device *dev, for (j = 0; j < this_board->sdio[i].regs; j++) { s = &dev->subdevices[subdev]; ret = subdev_8255_init(dev, s, NULL, - dev->iobase + this_board->sdio[i].addr + SIZE_8255 * j); if (ret) diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c index 324746b14931..848b95decabe 100644 --- a/drivers/staging/comedi/drivers/aio_aio12_8.c +++ b/drivers/staging/comedi/drivers/aio_aio12_8.c @@ -244,8 +244,7 @@ static int aio_aio12_8_attach(struct comedi_device *dev, s = &dev->subdevices[2]; /* 8255 Digital i/o subdevice */ - ret = subdev_8255_init(dev, s, NULL, - dev->iobase + AIO12_8_8255_BASE_REG); + ret = subdev_8255_init(dev, s, NULL, AIO12_8_8255_BASE_REG); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/amplc_pc236_common.c b/drivers/staging/comedi/drivers/amplc_pc236_common.c index 18e237cca419..974b72392d0a 100644 --- a/drivers/staging/comedi/drivers/amplc_pc236_common.c +++ b/drivers/staging/comedi/drivers/amplc_pc236_common.c @@ -160,7 +160,7 @@ int amplc_pc236_common_attach(struct comedi_device *dev, unsigned long iobase, s = &dev->subdevices[0]; /* digital i/o subdevice (8255) */ - ret = subdev_8255_init(dev, s, NULL, iobase); + ret = subdev_8255_init(dev, s, NULL, 0x00); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c index 7b56f68b3b4f..0fd212f5fa2a 100644 --- a/drivers/staging/comedi/drivers/amplc_pci230.c +++ b/drivers/staging/comedi/drivers/amplc_pci230.c @@ -2794,8 +2794,7 @@ static int pci230_attach_common(struct comedi_device *dev, s = &dev->subdevices[2]; /* digital i/o subdevice */ if (thisboard->have_dio) { - rc = subdev_8255_init(dev, s, NULL, - dev->iobase + PCI230_PPI_X_BASE); + rc = subdev_8255_init(dev, s, NULL, PCI230_PPI_X_BASE); if (rc) return rc; } else { diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index b48540b3b66c..f372b0306b38 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -1528,7 +1528,7 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev, /* 8255 */ s = &dev->subdevices[2]; - ret = subdev_8255_init(dev, s, NULL, dev->iobase + DIO_8255); + ret = subdev_8255_init(dev, s, NULL, DIO_8255); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/cb_pcidda.c b/drivers/staging/comedi/drivers/cb_pcidda.c index 9c9c58049e01..2ffb9ca17995 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, dev->iobase + (i * 4)); + ret = subdev_8255_init(dev, s, NULL, i * 4); if (ret) return ret; } diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c index d049a7f27239..f1c0dafb98dd 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdas.c +++ b/drivers/staging/comedi/drivers/cb_pcimdas.c @@ -252,7 +252,7 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev, s = &dev->subdevices[2]; /* digital i/o subdevice */ - ret = subdev_8255_init(dev, s, NULL, dev->iobase); + ret = subdev_8255_init(dev, s, NULL, 0x00); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/cb_pcimdda.c b/drivers/staging/comedi/drivers/cb_pcimdda.c index 4a2b200de01b..49b24d032436 100644 --- a/drivers/staging/comedi/drivers/cb_pcimdda.c +++ b/drivers/staging/comedi/drivers/cb_pcimdda.c @@ -182,8 +182,7 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev, s = &dev->subdevices[1]; /* digital i/o subdevice */ - ret = subdev_8255_init(dev, s, NULL, - dev->iobase + PCIMDDA_8255_BASE_REG); + ret = subdev_8255_init(dev, s, NULL, PCIMDDA_8255_BASE_REG); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c index fcf916a80c8d..03b2c71df8f8 100644 --- a/drivers/staging/comedi/drivers/das08.c +++ b/drivers/staging/comedi/drivers/das08.c @@ -536,8 +536,7 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase) s = &dev->subdevices[4]; /* 8255 */ if (thisboard->i8255_offset != 0) { - ret = subdev_8255_init(dev, s, NULL, - dev->iobase + thisboard->i8255_offset); + ret = subdev_8255_init(dev, s, NULL, thisboard->i8255_offset); if (ret) return ret; } else { diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c index 057bc16f8ddc..a347bcdff29c 100644 --- a/drivers/staging/comedi/drivers/das16.c +++ b/drivers/staging/comedi/drivers/das16.c @@ -1191,8 +1191,7 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it) /* 8255 Digital I/O subdevice */ if (board->has_8255) { s = &dev->subdevices[4]; - ret = subdev_8255_init(dev, s, NULL, - dev->iobase + board->i8255_offset); + ret = subdev_8255_init(dev, s, NULL, board->i8255_offset); if (ret) return ret; } diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c index 5b6998b54060..1bf5be8c0313 100644 --- a/drivers/staging/comedi/drivers/das16m1.c +++ b/drivers/staging/comedi/drivers/das16m1.c @@ -608,7 +608,7 @@ static int das16m1_attach(struct comedi_device *dev, s = &dev->subdevices[3]; /* 8255 */ - ret = subdev_8255_init(dev, s, NULL, devpriv->extra_iobase); + ret = subdev_8255_init(dev, s, NULL, DAS16M1_82C55); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c index 9c08da9508f4..f1acca6cd12f 100644 --- a/drivers/staging/comedi/drivers/ni_atmio16d.c +++ b/drivers/staging/comedi/drivers/ni_atmio16d.c @@ -722,7 +722,7 @@ static int atmio16d_attach(struct comedi_device *dev, /* 8255 subdevice */ s = &dev->subdevices[3]; if (board->has_8255) { - ret = subdev_8255_init(dev, s, NULL, dev->iobase); + ret = subdev_8255_init(dev, s, NULL, 0x00); if (ret) return ret; } else { diff --git a/drivers/staging/comedi/drivers/ni_daq_dio24.c b/drivers/staging/comedi/drivers/ni_daq_dio24.c index 925e82c65b2d..8cfabdbaa30c 100644 --- a/drivers/staging/comedi/drivers/ni_daq_dio24.c +++ b/drivers/staging/comedi/drivers/ni_daq_dio24.c @@ -59,7 +59,7 @@ static int dio24_auto_attach(struct comedi_device *dev, /* 8255 dio */ s = &dev->subdevices[0]; - ret = subdev_8255_init(dev, s, NULL, dev->iobase); + ret = subdev_8255_init(dev, s, NULL, 0x00); if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 15ead2715926..8f914de1c153 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -1405,8 +1405,7 @@ int labpc_common_attach(struct comedi_device *dev, ret = subdev_8255_init(dev, s, labpc_8255_mmio, DIO_BASE_REG); } else { - ret = subdev_8255_init(dev, s, NULL, - dev->iobase + DIO_BASE_REG); + ret = subdev_8255_init(dev, s, NULL, DIO_BASE_REG); } if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/pcl724.c b/drivers/staging/comedi/drivers/pcl724.c index 946b058eee6f..3acbbc65ca64 100644 --- a/drivers/staging/comedi/drivers/pcl724.c +++ b/drivers/staging/comedi/drivers/pcl724.c @@ -133,8 +133,7 @@ static int pcl724_attach(struct comedi_device *dev, ret = subdev_8255_init(dev, s, pcl724_8255mapped_io, iobase); } else { - iobase = dev->iobase + (i * SIZE_8255); - ret = subdev_8255_init(dev, s, NULL, iobase); + ret = subdev_8255_init(dev, s, NULL, i * SIZE_8255); } if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/pcm3724.c b/drivers/staging/comedi/drivers/pcm3724.c index 6e0d78f6095b..f6acf5de59bf 100644 --- a/drivers/staging/comedi/drivers/pcm3724.c +++ b/drivers/staging/comedi/drivers/pcm3724.c @@ -211,8 +211,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, - dev->iobase + SIZE_8255 * i); + ret = subdev_8255_init(dev, s, NULL, i * SIZE_8255); if (ret) return ret; s->insn_config = subdev_3724_insn_config; |