serial: 8250_pci: Add serial8250_pci_setup_port definition in 8250_pcilib.c
authorKumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
Tue, 7 Feb 2023 16:48:11 +0000 (22:18 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Feb 2023 12:10:15 +0000 (13:10 +0100)
Move implementation of setup_port func() to serial8250_pci_setup_port.

Co-developed-by: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Signed-off-by: Tharun Kumar P <tharunkumar.pasumarthi@microchip.com>
Signed-off-by: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230207164814.3104605-2-kumaravel.thiagarajan@microchip.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_pci.c
drivers/tty/serial/8250/8250_pcilib.c [new file with mode: 0644]
drivers/tty/serial/8250/8250_pcilib.h [new file with mode: 0644]
drivers/tty/serial/8250/Kconfig
drivers/tty/serial/8250/Makefile

index 8e9f247590bd4da1a0d7044f048d461e099f7958..c55be6fda0cab1fb9cedc6014fb8b90e5094a492 100644 (file)
@@ -24,6 +24,7 @@
 #include <asm/io.h>
 
 #include "8250.h"
+#include "8250_pcilib.h"
 
 /*
  * init function returns:
@@ -89,28 +90,7 @@ static int
 setup_port(struct serial_private *priv, struct uart_8250_port *port,
           u8 bar, unsigned int offset, int regshift)
 {
-       struct pci_dev *dev = priv->dev;
-
-       if (bar >= PCI_STD_NUM_BARS)
-               return -EINVAL;
-
-       if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
-               if (!pcim_iomap(dev, bar, 0) && !pcim_iomap_table(dev))
-                       return -ENOMEM;
-
-               port->port.iotype = UPIO_MEM;
-               port->port.iobase = 0;
-               port->port.mapbase = pci_resource_start(dev, bar) + offset;
-               port->port.membase = pcim_iomap_table(dev)[bar] + offset;
-               port->port.regshift = regshift;
-       } else {
-               port->port.iotype = UPIO_PORT;
-               port->port.iobase = pci_resource_start(dev, bar) + offset;
-               port->port.mapbase = 0;
-               port->port.membase = NULL;
-               port->port.regshift = 0;
-       }
-       return 0;
+       return serial8250_pci_setup_port(priv->dev, port, bar, offset, regshift);
 }
 
 /*
@@ -5757,3 +5737,4 @@ module_pci_driver(serial_pci_driver);
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Generic 8250/16x50 PCI serial probe module");
 MODULE_DEVICE_TABLE(pci, serial_pci_tbl);
+MODULE_IMPORT_NS(SERIAL_8250_PCI);
diff --git a/drivers/tty/serial/8250/8250_pcilib.c b/drivers/tty/serial/8250/8250_pcilib.c
new file mode 100644 (file)
index 0000000..d234e91
--- /dev/null
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * 8250 PCI library.
+ *
+ * Copyright (C) 2001 Russell King, All Rights Reserved.
+ */
+#include <linux/errno.h>
+#include <linux/ioport.h>
+#include <linux/pci.h>
+#include <linux/types.h>
+
+#include "8250.h"
+#include "8250_pcilib.h"
+
+int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port,
+                  u8 bar, unsigned int offset, int regshift)
+{
+       if (bar >= PCI_STD_NUM_BARS)
+               return -EINVAL;
+
+       if (pci_resource_flags(dev, bar) & IORESOURCE_MEM) {
+               if (!pcim_iomap(dev, bar, 0) && !pcim_iomap_table(dev))
+                       return -ENOMEM;
+
+               port->port.iotype = UPIO_MEM;
+               port->port.iobase = 0;
+               port->port.mapbase = pci_resource_start(dev, bar) + offset;
+               port->port.membase = pcim_iomap_table(dev)[bar] + offset;
+               port->port.regshift = regshift;
+       } else {
+               port->port.iotype = UPIO_PORT;
+               port->port.iobase = pci_resource_start(dev, bar) + offset;
+               port->port.mapbase = 0;
+               port->port.membase = NULL;
+               port->port.regshift = 0;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_NS_GPL(serial8250_pci_setup_port, SERIAL_8250_PCI);
+MODULE_LICENSE("GPL");
diff --git a/drivers/tty/serial/8250/8250_pcilib.h b/drivers/tty/serial/8250/8250_pcilib.h
new file mode 100644 (file)
index 0000000..1aaf1b5
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * 8250 PCI library header file.
+ *
+ * Copyright (C) 2001 Russell King, All Rights Reserved.
+ */
+
+#include <linux/types.h>
+
+struct pci_dev;
+
+struct uart_8250_port;
+
+int serial8250_pci_setup_port(struct pci_dev *dev, struct uart_8250_port *port, u8 bar,
+                  unsigned int offset, int regshift);
index 020ef532940de4aba0dc1fe88da6948d8c68bf54..9b3ba28cc562fae9889e9c2217f98635ec1eaea7 100644 (file)
@@ -129,9 +129,13 @@ config SERIAL_8250_DMA
          This builds DMA support that can be used with 8250/16650
          compatible UART controllers that support DMA signaling.
 
+config SERIAL_8250_PCILIB
+       bool
+
 config SERIAL_8250_PCI
        tristate "8250/16550 PCI device support"
        depends on SERIAL_8250 && PCI
+       select SERIAL_8250_PCILIB
        default SERIAL_8250
        help
          This builds standard PCI serial support. You may be able to
index 4e1a3281268346178514370b934a038a5535cf8c..ce63a250da3bbbcf7c9d6efb9d83f9c5ba2e94c4 100644 (file)
@@ -12,6 +12,7 @@ obj-$(CONFIG_SERIAL_8250)             += 8250.o 8250_base.o
 8250_base-$(CONFIG_SERIAL_8250_DMA)    += 8250_dma.o
 8250_base-$(CONFIG_SERIAL_8250_DWLIB)  += 8250_dwlib.o
 8250_base-$(CONFIG_SERIAL_8250_FINTEK) += 8250_fintek.o
+8250_base-$(CONFIG_SERIAL_8250_PCILIB) += 8250_pcilib.o
 obj-$(CONFIG_SERIAL_8250_PARISC)       += 8250_parisc.o
 obj-$(CONFIG_SERIAL_8250_PCI)          += 8250_pci.o
 obj-$(CONFIG_SERIAL_8250_EXAR)         += 8250_exar.o