]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
comedi: amplc_dio200_common: Conditionally remove I/O port support
authorIan Abbott <abbotti@mev.co.uk>
Wed, 13 Sep 2023 17:07:11 +0000 (18:07 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Oct 2023 11:34:04 +0000 (13:34 +0200)
In a future patch, the port I/O functions (`inb()`, `outb()`, and
friends will only be declared in the `HAS_IOPORT` configuration option
is enabled.

The amplc_dio200_common module is used by the amplc_dio200 module (for
ISA cards) and the amplc_dio200_pci module (for PCI and PCI Express
cards).  It supports both port I/O and memory-mapped I/O.

Port I/O and memory-mapped I/O is confined to the `dio200___read8()`,
`dio200___read32()`, `dio200___write8()` and `dio200___write32()`
functions.  Conditionally compile two versions of those functions.  If
the `CONFIG_HAS_IOPORT` macro is defined, call either the port I/O or
memory mapped I/O functions depending on the `mmio` member of the
`struct comedi_device`.  If the `CONFIG_HAS_IOPORT` macro is undefined
only call the memory-mapped I/O functions.

Add a run-time check to `amplc_dio200_common_attach()` to return an
error if the device wants to use port I/O when the `CONFIG_HAS_IOPORT`
macro is undefined.

The changes allow the module to be built even if the port I/O functions
have not been declared.

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-13-abbotti@mev.co.uk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/comedi/drivers/amplc_dio200_common.c

index e6d63e89e7bf4944a5848ceb083dd1448599fb49..b1a9b4c4a185da97412bb93f5503a56c280b0dbe 100644 (file)
@@ -86,6 +86,8 @@ struct dio200_subdev_intr {
        unsigned int active:1;
 };
 
+#ifdef CONFIG_HAS_IOPORT
+
 static unsigned char dio200___read8(struct comedi_device *dev,
                                    unsigned int offset)
 {
@@ -120,6 +122,34 @@ static void dio200___write32(struct comedi_device *dev,
                outl(val, dev->iobase + offset);
 }
 
+#else /* CONFIG_HAS_IOPORT */
+
+static unsigned char dio200___read8(struct comedi_device *dev,
+                                   unsigned int offset)
+{
+       return readb(dev->mmio + offset);
+}
+
+static void dio200___write8(struct comedi_device *dev,
+                           unsigned int offset, unsigned char val)
+{
+       writeb(val, dev->mmio + offset);
+}
+
+static unsigned int dio200___read32(struct comedi_device *dev,
+                                   unsigned int offset)
+{
+       return readl(dev->mmio + offset);
+}
+
+static void dio200___write32(struct comedi_device *dev,
+                            unsigned int offset, unsigned int val)
+{
+       writel(val, dev->mmio + offset);
+}
+
+#endif /* CONFIG_HAS_IOPORT */
+
 static unsigned char dio200_read8(struct comedi_device *dev,
                                  unsigned int offset)
 {
@@ -803,6 +833,12 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq,
        unsigned int n;
        int ret;
 
+       if (!IS_ENABLED(CONFIG_HAS_IOPORT) && !dev->mmio) {
+               dev_err(dev->class_dev,
+                       "error! need I/O port support\n");
+               return -ENXIO;
+       }
+
        ret = comedi_alloc_subdevices(dev, board->n_subdevs);
        if (ret)
                return ret;