serial: 8250_exar: Add ->unregister_gpio() callback

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>
This commit is contained in:
Andy Shevchenko 2021-07-13 12:58:21 +03:00 committed by Greg Kroah-Hartman
parent e94159dfba
commit 33969db7ab

View file

@ -114,6 +114,7 @@ struct exar8250;
struct exar8250_platform { struct exar8250_platform {
int (*rs485_config)(struct uart_port *, struct serial_rs485 *); int (*rs485_config)(struct uart_port *, struct serial_rs485 *);
int (*register_gpio)(struct pci_dev *, struct uart_8250_port *); 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); writeb(0x00, p + UART_EXAR_MPIOOD_15_8);
} }
static void * static struct platform_device *__xr17v35x_register_gpio(struct pci_dev *pcidev,
__xr17v35x_register_gpio(struct pci_dev *pcidev, const struct software_node *node)
const struct software_node *node)
{ {
struct platform_device *pdev; struct platform_device *pdev;
@ -374,6 +374,12 @@ __xr17v35x_register_gpio(struct pci_dev *pcidev,
return pdev; 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[] = { static const struct property_entry exar_gpio_properties[] = {
PROPERTY_ENTRY_U32("exar,first-pin", 0), PROPERTY_ENTRY_U32("exar,first-pin", 0),
PROPERTY_ENTRY_U32("ngpios", 16), PROPERTY_ENTRY_U32("ngpios", 16),
@ -384,8 +390,7 @@ static const struct software_node exar_gpio_node = {
.properties = exar_gpio_properties, .properties = exar_gpio_properties,
}; };
static int xr17v35x_register_gpio(struct pci_dev *pcidev, static int xr17v35x_register_gpio(struct pci_dev *pcidev, struct uart_8250_port *port)
struct uart_8250_port *port)
{ {
if (pcidev->vendor == PCI_VENDOR_ID_EXAR) if (pcidev->vendor == PCI_VENDOR_ID_EXAR)
port->port.private_data = port->port.private_data =
@ -394,6 +399,15 @@ static int xr17v35x_register_gpio(struct pci_dev *pcidev,
return 0; 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, static int generic_rs485_config(struct uart_port *port,
struct serial_rs485 *rs485) 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 = { static const struct exar8250_platform exar8250_default_platform = {
.register_gpio = xr17v35x_register_gpio, .register_gpio = xr17v35x_register_gpio,
.unregister_gpio = xr17v35x_unregister_gpio,
.rs485_config = generic_rs485_config, .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 = { static const struct exar8250_platform iot2040_platform = {
.rs485_config = iot2040_rs485_config, .rs485_config = iot2040_rs485_config,
.register_gpio = iot2040_register_gpio, .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) 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 exar8250 *priv = pci_get_drvdata(pcidev);
struct uart_8250_port *port = serial8250_get_port(priv->line[0]); struct uart_8250_port *port = serial8250_get_port(priv->line[0]);
struct platform_device *pdev;
pdev = port->port.private_data; platform->unregister_gpio(port);
if (!pdev)
return;
device_remove_software_node(&pdev->dev);
platform_device_unregister(pdev);
port->port.private_data = NULL;
} }
static inline void exar_misc_clear(struct exar8250 *priv) static inline void exar_misc_clear(struct exar8250 *priv)