From 0c3dfdc2d9a913c227a71f8cf728a70316c3abb4 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 29 Jul 2014 15:01:45 -0700 Subject: [PATCH] staging: comedi: amplc_dio200: use the comedi_device 'mmio' member The amplc_dio200_common module currently uses a union in the private data to determine if the hardware uses port or memory mapped I/O. Use the new 'mmio' member in the comedi_device for the ioremap'ed base address and remove all the union code. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/amplc_dio200.c | 3 +- drivers/staging/comedi/drivers/amplc_dio200.h | 13 -------- .../comedi/drivers/amplc_dio200_common.c | 30 +++++++++---------- .../staging/comedi/drivers/amplc_dio200_pci.c | 14 ++++----- 4 files changed, 20 insertions(+), 40 deletions(-) diff --git a/drivers/staging/comedi/drivers/amplc_dio200.c b/drivers/staging/comedi/drivers/amplc_dio200.c index dc1dee79fc16..17d2e20663cb 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.c +++ b/drivers/staging/comedi/drivers/amplc_dio200.c @@ -278,8 +278,7 @@ static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it) ret = comedi_request_region(dev, it->options[0], thisboard->mainsize); if (ret) return ret; - devpriv->io.u.iobase = dev->iobase; - devpriv->io.regtype = io_regtype; + return amplc_dio200_common_attach(dev, irq, 0); } diff --git a/drivers/staging/comedi/drivers/amplc_dio200.h b/drivers/staging/comedi/drivers/amplc_dio200.h index 43160b9944bb..e0afe2cee2d6 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200.h +++ b/drivers/staging/comedi/drivers/amplc_dio200.h @@ -27,18 +27,6 @@ #define DIO200_IO_SIZE 0x20 #define DIO200_PCIE_IO_SIZE 0x4000 -/* - * Register region. - */ -enum dio200_regtype { no_regtype = 0, io_regtype, mmio_regtype }; -struct dio200_region { - union { - unsigned long iobase; /* I/O base address */ - unsigned char __iomem *membase; /* mapped MMIO base address */ - } u; - enum dio200_regtype regtype; -}; - /* * Subdevice types. */ @@ -75,7 +63,6 @@ struct dio200_board { * Comedi device private data. */ struct dio200_private { - struct dio200_region io; /* Register region */ int intr_sd; }; diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c index 4cf9e9ed71d4..f0d709e0dafc 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c @@ -151,13 +151,12 @@ static unsigned char dio200_read8(struct comedi_device *dev, unsigned int offset) { const struct dio200_board *thisboard = comedi_board(dev); - struct dio200_private *devpriv = dev->private; offset <<= thisboard->mainshift; - if (devpriv->io.regtype == io_regtype) - return inb(devpriv->io.u.iobase + offset); - return readb(devpriv->io.u.membase + offset); + if (dev->mmio) + return readb(dev->mmio + offset); + return inb(dev->iobase + offset); } /* @@ -167,13 +166,13 @@ static void dio200_write8(struct comedi_device *dev, unsigned int offset, unsigned char val) { const struct dio200_board *thisboard = comedi_board(dev); - struct dio200_private *devpriv = dev->private; offset <<= thisboard->mainshift; - if (devpriv->io.regtype == io_regtype) - outb(val, devpriv->io.u.iobase + offset); + + if (dev->mmio) + writeb(val, dev->mmio + offset); else - writeb(val, devpriv->io.u.membase + offset); + outb(val, dev->iobase + offset); } /* @@ -183,13 +182,12 @@ static unsigned int dio200_read32(struct comedi_device *dev, unsigned int offset) { const struct dio200_board *thisboard = comedi_board(dev); - struct dio200_private *devpriv = dev->private; offset <<= thisboard->mainshift; - if (devpriv->io.regtype == io_regtype) - return inl(devpriv->io.u.iobase + offset); - return readl(devpriv->io.u.membase + offset); + if (dev->mmio) + return readl(dev->mmio + offset); + return inl(dev->iobase + offset); } /* @@ -199,13 +197,13 @@ static void dio200_write32(struct comedi_device *dev, unsigned int offset, unsigned int val) { const struct dio200_board *thisboard = comedi_board(dev); - struct dio200_private *devpriv = dev->private; offset <<= thisboard->mainshift; - if (devpriv->io.regtype == io_regtype) - outl(val, devpriv->io.u.iobase + offset); + + if (dev->mmio) + writel(val, dev->mmio + offset); else - writel(val, devpriv->io.u.membase + offset); + outl(val, dev->iobase + offset); } /* diff --git a/drivers/staging/comedi/drivers/amplc_dio200_pci.c b/drivers/staging/comedi/drivers/amplc_dio200_pci.c index 1954c1bd23db..fbf05687347f 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_pci.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_pci.c @@ -387,16 +387,14 @@ static int dio200_pci_auto_attach(struct comedi_device *dev, return -EINVAL; } if (pci_resource_flags(pci_dev, bar) & IORESOURCE_MEM) { - devpriv->io.u.membase = pci_ioremap_bar(pci_dev, bar); - if (!devpriv->io.u.membase) { + dev->mmio = pci_ioremap_bar(pci_dev, bar); + if (!dev->mmio) { dev_err(dev->class_dev, "error! cannot remap registers\n"); return -ENOMEM; } - devpriv->io.regtype = mmio_regtype; } else { - devpriv->io.u.iobase = pci_resource_start(pci_dev, bar); - devpriv->io.regtype = io_regtype; + dev->iobase = pci_resource_start(pci_dev, bar); } switch (context_model) { case pcie215_model: @@ -414,11 +412,9 @@ static int dio200_pci_auto_attach(struct comedi_device *dev, static void dio200_pci_detach(struct comedi_device *dev) { - struct dio200_private *devpriv = dev->private; - amplc_dio200_common_detach(dev); - if (devpriv && devpriv->io.regtype == mmio_regtype) - iounmap(devpriv->io.u.membase); + if (dev->mmio) + iounmap(dev->mmio); comedi_pci_disable(dev); } -- 2.20.1