comedi: amplc_dio200_common: Conditionally remove I/O port support

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>
This commit is contained in:
Ian Abbott 2023-09-13 18:07:11 +01:00 committed by Greg Kroah-Hartman
parent a3f2b80847
commit 88dd479774

View 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;