serial: 8250_exar: Add ->unregister_gpio() callback
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 13 Jul 2021 09:58:21 +0000 (12:58 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Jul 2021 10:48:47 +0000 (12:48 +0200)
For the sake of reducing layering violation add ->unregister_gpio()
callback and use it in the ->exit() one.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20210713095821.7834-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_exar.c

index 3ffeedc..d502240 100644 (file)
@@ -114,6 +114,7 @@ struct exar8250;
 struct exar8250_platform {
        int (*rs485_config)(struct uart_port *, struct serial_rs485 *);
        int (*register_gpio)(struct pci_dev *, struct uart_8250_port *);
+       void (*unregister_gpio)(struct uart_8250_port *);
 };
 
 /**
@@ -352,9 +353,8 @@ static void setup_gpio(struct pci_dev *pcidev, u8 __iomem *p)
        writeb(0x00, p + UART_EXAR_MPIOOD_15_8);
 }
 
-static void *
-__xr17v35x_register_gpio(struct pci_dev *pcidev,
-                        const struct software_node *node)
+static struct platform_device *__xr17v35x_register_gpio(struct pci_dev *pcidev,
+                                                       const struct software_node *node)
 {
        struct platform_device *pdev;
 
@@ -374,6 +374,12 @@ __xr17v35x_register_gpio(struct pci_dev *pcidev,
        return pdev;
 }
 
+static void __xr17v35x_unregister_gpio(struct platform_device *pdev)
+{
+       device_remove_software_node(&pdev->dev);
+       platform_device_unregister(pdev);
+}
+
 static const struct property_entry exar_gpio_properties[] = {
        PROPERTY_ENTRY_U32("exar,first-pin", 0),
        PROPERTY_ENTRY_U32("ngpios", 16),
@@ -384,8 +390,7 @@ static const struct software_node exar_gpio_node = {
        .properties = exar_gpio_properties,
 };
 
-static int xr17v35x_register_gpio(struct pci_dev *pcidev,
-                                 struct uart_8250_port *port)
+static int xr17v35x_register_gpio(struct pci_dev *pcidev, struct uart_8250_port *port)
 {
        if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
                port->port.private_data =
@@ -394,6 +399,15 @@ static int xr17v35x_register_gpio(struct pci_dev *pcidev,
        return 0;
 }
 
+static void xr17v35x_unregister_gpio(struct uart_8250_port *port)
+{
+       if (!port->port.private_data)
+               return;
+
+       __xr17v35x_unregister_gpio(port->port.private_data);
+       port->port.private_data = NULL;
+}
+
 static int generic_rs485_config(struct uart_port *port,
                                struct serial_rs485 *rs485)
 {
@@ -419,6 +433,7 @@ static int generic_rs485_config(struct uart_port *port,
 
 static const struct exar8250_platform exar8250_default_platform = {
        .register_gpio = xr17v35x_register_gpio,
+       .unregister_gpio = xr17v35x_unregister_gpio,
        .rs485_config = generic_rs485_config,
 };
 
@@ -484,6 +499,7 @@ static int iot2040_register_gpio(struct pci_dev *pcidev,
 static const struct exar8250_platform iot2040_platform = {
        .rs485_config = iot2040_rs485_config,
        .register_gpio = iot2040_register_gpio,
+       .unregister_gpio = xr17v35x_unregister_gpio,
 };
 
 /*
@@ -555,17 +571,11 @@ pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,
 
 static void pci_xr17v35x_exit(struct pci_dev *pcidev)
 {
+       const struct exar8250_platform *platform = exar_get_platform();
        struct exar8250 *priv = pci_get_drvdata(pcidev);
        struct uart_8250_port *port = serial8250_get_port(priv->line[0]);
-       struct platform_device *pdev;
 
-       pdev = port->port.private_data;
-       if (!pdev)
-               return;
-
-       device_remove_software_node(&pdev->dev);
-       platform_device_unregister(pdev);
-       port->port.private_data = NULL;
+       platform->unregister_gpio(port);
 }
 
 static inline void exar_misc_clear(struct exar8250 *priv)