]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
comedi: amplc_dio200_common: Refactor register access functions
authorIan Abbott <abbotti@mev.co.uk>
Wed, 13 Sep 2023 17:07:10 +0000 (18:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Oct 2023 11:34:04 +0000 (13:34 +0200)
The `dio200_read8()`, `dio200_write8()`, `dio200_read32()` and
`dio200_write32()` functions apply a right-shift to the register offset
for some devices and then perform the actual register access.  Factor
the register access part out to new functions `dio200___read8()`,
`dio200___write8()`, `dio200___read32()`, and `dio200___write32()`.
This will reduce duplicated code in a subsequent patch that will
conditionally compile support for port I/O as part of the `HAS_IOPORT`
changes.

Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Link: https://lore.kernel.org/r/20230913170712.111719-12-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/comedi/drivers/amplc_dio200_common.c

index 19166cb26f5eec7b17c694e812448c2cf5f72f7f..e6d63e89e7bf4944a5848ceb083dd1448599fb49 100644 (file)
@@ -86,6 +86,40 @@ struct dio200_subdev_intr {
        unsigned int active:1;
 };
 
+static unsigned char dio200___read8(struct comedi_device *dev,
+                                   unsigned int offset)
+{
+       if (dev->mmio)
+               return readb(dev->mmio + offset);
+       return inb(dev->iobase + offset);
+}
+
+static void dio200___write8(struct comedi_device *dev,
+                           unsigned int offset, unsigned char val)
+{
+       if (dev->mmio)
+               writeb(val, dev->mmio + offset);
+       else
+               outb(val, dev->iobase + offset);
+}
+
+static unsigned int dio200___read32(struct comedi_device *dev,
+                                   unsigned int offset)
+{
+       if (dev->mmio)
+               return readl(dev->mmio + offset);
+       return inl(dev->iobase + offset);
+}
+
+static void dio200___write32(struct comedi_device *dev,
+                            unsigned int offset, unsigned int val)
+{
+       if (dev->mmio)
+               writel(val, dev->mmio + offset);
+       else
+               outl(val, dev->iobase + offset);
+}
+
 static unsigned char dio200_read8(struct comedi_device *dev,
                                  unsigned int offset)
 {
@@ -94,9 +128,7 @@ static unsigned char dio200_read8(struct comedi_device *dev,
        if (board->is_pcie)
                offset <<= 3;
 
-       if (dev->mmio)
-               return readb(dev->mmio + offset);
-       return inb(dev->iobase + offset);
+       return dio200___read8(dev, offset);
 }
 
 static void dio200_write8(struct comedi_device *dev,
@@ -107,10 +139,7 @@ static void dio200_write8(struct comedi_device *dev,
        if (board->is_pcie)
                offset <<= 3;
 
-       if (dev->mmio)
-               writeb(val, dev->mmio + offset);
-       else
-               outb(val, dev->iobase + offset);
+       dio200___write8(dev, offset, val);
 }
 
 static unsigned int dio200_read32(struct comedi_device *dev,
@@ -121,9 +150,7 @@ static unsigned int dio200_read32(struct comedi_device *dev,
        if (board->is_pcie)
                offset <<= 3;
 
-       if (dev->mmio)
-               return readl(dev->mmio + offset);
-       return inl(dev->iobase + offset);
+       return dio200___read32(dev, offset);
 }
 
 static void dio200_write32(struct comedi_device *dev,
@@ -134,10 +161,7 @@ static void dio200_write32(struct comedi_device *dev,
        if (board->is_pcie)
                offset <<= 3;
 
-       if (dev->mmio)
-               writel(val, dev->mmio + offset);
-       else
-               outl(val, dev->iobase + offset);
+       dio200___write32(dev, offset, val);
 }
 
 static unsigned int dio200_subdev_8254_offset(struct comedi_device *dev,