diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2014-08-12 18:41:28 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-08-16 19:23:26 (GMT) |
commit | 5c19084bbd4ef7c0a10e5b01145b940edf872a63 (patch) | |
tree | 846edb1456a00e9a471e29370f63bdee79bff1dc /drivers | |
parent | 9067983867516a425d3382cb2eeeb234a2e8e3b6 (diff) | |
download | linux-5c19084bbd4ef7c0a10e5b01145b940edf872a63.tar.xz |
staging: comedi: 8255: handle memory mapped io
The drivers that use this module with memory mapped io all have the
ioremap'ed base address stored in the comedi_device 'mmio' member.
Introduce a default (*io) function that does 8-bit memory mapped io.
Modify subdev_8255_init() so that it takes a flag parameter indicating
if the io is port or memory mapped. Make the function static and rename
it to __subdev_8255_init().
Introduce two exported wrappers for __subdev_8255_init():
subdev_8255_init() - for drivers that do 8-bit port io
subdev_8255_mm_init() - for drivers that do 8-bit memory mapped io
Use subdev_8255_mm_init() in the drivers that do 8-bit memory mapped io
and remove the private (*io) functions.
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/8255.c | 43 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/8255.h | 7 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/8255_pci.c | 19 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/cb_pcidas64.c | 14 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/ni_labpc.c | 14 |
5 files changed, 50 insertions, 47 deletions
diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index 456c07b..be56e16 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -107,6 +107,16 @@ static int subdev_8255_io(struct comedi_device *dev, return inb(dev->iobase + regbase + port); } +static int subdev_8255_mmio(struct comedi_device *dev, + int dir, int port, int data, unsigned long regbase) +{ + if (dir) { + writeb(data, dev->mmio + regbase + port); + return 0; + } + return readb(dev->mmio + regbase + port); +} + static int subdev_8255_insn(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -186,10 +196,12 @@ static int subdev_8255_insn_config(struct comedi_device *dev, return insn->n; } -int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, - int (*io)(struct comedi_device *, - int, int, int, unsigned long), - unsigned long regbase) +static int __subdev_8255_init(struct comedi_device *dev, + struct comedi_subdevice *s, + int (*io)(struct comedi_device *, + int, int, int, unsigned long), + unsigned long regbase, + bool is_mmio) { struct subdev_8255_private *spriv; @@ -197,8 +209,13 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, if (!spriv) return -ENOMEM; + if (io) + spriv->io = io; + else if (is_mmio) + spriv->io = subdev_8255_mmio; + else + spriv->io = subdev_8255_io; spriv->regbase = regbase; - spriv->io = io ? io : subdev_8255_io; s->type = COMEDI_SUBD_DIO; s->subdev_flags = SDF_READABLE | SDF_WRITABLE; @@ -212,8 +229,24 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, return 0; } + +int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, + int (*io)(struct comedi_device *, + int, int, int, unsigned long), + unsigned long regbase) +{ + return __subdev_8255_init(dev, s, io, regbase, false); +} EXPORT_SYMBOL_GPL(subdev_8255_init); +int subdev_8255_mm_init(struct comedi_device *dev, struct comedi_subdevice *s, + int (*io)(struct comedi_device *, + int, int, int, unsigned long), + unsigned long regbase) +{ + return __subdev_8255_init(dev, s, io, regbase, true); +} +EXPORT_SYMBOL_GPL(subdev_8255_mm_init); /* Start of the 8255 standalone device diff --git a/drivers/staging/comedi/drivers/8255.h b/drivers/staging/comedi/drivers/8255.h index 3084897..c7c6dee 100644 --- a/drivers/staging/comedi/drivers/8255.h +++ b/drivers/staging/comedi/drivers/8255.h @@ -21,9 +21,14 @@ #include "../comedidev.h" -int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, +int subdev_8255_init(struct comedi_device *, struct comedi_subdevice *, int (*io)(struct comedi_device *, int, int, int, unsigned long), unsigned long regbase); +int subdev_8255_mm_init(struct comedi_device *, struct comedi_subdevice *, + int (*io)(struct comedi_device *, + int, int, int, unsigned long), + unsigned long regbase); + #endif diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c index 15e85b6..eb1ca0e 100644 --- a/drivers/staging/comedi/drivers/8255_pci.c +++ b/drivers/staging/comedi/drivers/8255_pci.c @@ -190,23 +190,12 @@ static int pci_8255_mite_init(struct pci_dev *pcidev) return 0; } -static int pci_8255_mmio(struct comedi_device *dev, - int dir, int port, int data, unsigned long iobase) -{ - if (dir) { - writeb(data, dev->mmio + iobase + port); - return 0; - } - return readb(dev->mmio + iobase + port); -} - static int pci_8255_auto_attach(struct comedi_device *dev, unsigned long context) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); const struct pci_8255_boardinfo *board = NULL; struct comedi_subdevice *s; - bool is_mmio; int ret; int i; @@ -227,9 +216,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev, return ret; } - is_mmio = (pci_resource_flags(pcidev, board->dio_badr) & - IORESOURCE_MEM) != 0; - if (is_mmio) { + if ((pci_resource_flags(pcidev, board->dio_badr) & IORESOURCE_MEM)) { dev->mmio = pci_ioremap_bar(pcidev, board->dio_badr); if (!dev->mmio) return -ENOMEM; @@ -248,8 +235,8 @@ static int pci_8255_auto_attach(struct comedi_device *dev, for (i = 0; i < board->n_8255; i++) { s = &dev->subdevices[i]; - if (is_mmio) - ret = subdev_8255_init(dev, s, pci_8255_mmio, i * 4); + if (dev->mmio) + ret = subdev_8255_mm_init(dev, s, NULL, i * 4); else ret = subdev_8255_init(dev, s, NULL, i * 4); if (ret) diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c index e3bfbd4c..77b0284 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas64.c +++ b/drivers/staging/comedi/drivers/cb_pcidas64.c @@ -3369,16 +3369,6 @@ static int ao_cancel(struct comedi_device *dev, struct comedi_subdevice *s) return 0; } -static int dio_callback(struct comedi_device *dev, - int dir, int port, int data, unsigned long iobase) -{ - if (dir) { - writeb(data, dev->mmio + iobase + port); - return 0; - } - return readb(dev->mmio + iobase + port); -} - static int dio_callback_4020(struct comedi_device *dev, int dir, int port, int data, unsigned long iobase) { @@ -3842,8 +3832,8 @@ static int setup_subdevices(struct comedi_device *dev) ret = subdev_8255_init(dev, s, dio_callback_4020, I8255_4020_REG); } else { - ret = subdev_8255_init(dev, s, dio_callback, - DIO_8255_OFFSET); + ret = subdev_8255_mm_init(dev, s, NULL, + DIO_8255_OFFSET); } if (ret) return ret; diff --git a/drivers/staging/comedi/drivers/ni_labpc.c b/drivers/staging/comedi/drivers/ni_labpc.c index 8f914de..c9c090e 100644 --- a/drivers/staging/comedi/drivers/ni_labpc.c +++ b/drivers/staging/comedi/drivers/ni_labpc.c @@ -1035,17 +1035,6 @@ static int labpc_ao_insn_read(struct comedi_device *dev, return 1; } -static int labpc_8255_mmio(struct comedi_device *dev, - int dir, int port, int data, unsigned long iobase) -{ - if (dir) { - writeb(data, dev->mmio + iobase + port); - return 0; - } - - return readb(dev->mmio + iobase + port); -} - /* lowlevel write to eeprom/dac */ static void labpc_serial_out(struct comedi_device *dev, unsigned int value, unsigned int value_width) @@ -1402,8 +1391,7 @@ int labpc_common_attach(struct comedi_device *dev, /* 8255 dio */ s = &dev->subdevices[2]; if (dev->mmio) { - ret = subdev_8255_init(dev, s, labpc_8255_mmio, - DIO_BASE_REG); + ret = subdev_8255_mm_init(dev, s, NULL, DIO_BASE_REG); } else { ret = subdev_8255_init(dev, s, NULL, DIO_BASE_REG); } |