Commit 4085e93b authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 2b1a3fcf
......@@ -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);
}
}
}
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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 {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment