From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Aaron Sierra , Matt Schulte , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 076/161] tty: serial: exar: Relocate sleep wake-up handling Date: Mon, 9 Apr 2018 00:20:48 +0000 Message-ID: <20180409001936.162706-76-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: From: Aaron Sierra [ Upstream commit c7e1b4059075c9e8eed101d7cc5da43e95eb5e18 ] Exar sleep wake-up handling has been done on a per-channel basis by virtue of INT0 being accessible from each channel's address space. I believe this was initially done out of necessity, but now that Exar devices have their own driver, we can do things more efficiently by registering a dedicated INT0 handler at the PCI device level. I see this change providing the following benefits: 1. If more than one port is active, eliminates the redundant bus cycles for reading INT0 on every interrupt. 2. This note associated with hooking in the per-channel handler in 8250_port.c is resolved: /* Fixme: probably not the best place for this */ Cc: Matt Schulte Signed-off-by: Aaron Sierra Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_exar.c | 34 ++++++++++++++++++++++++++++++---= - drivers/tty/serial/8250/8250_port.c | 26 -------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/tty/serial/8250/8250_exar.c b/drivers/tty/serial/8250/= 8250_exar.c index c55624703fdf..e0aa5f03004c 100644 --- a/drivers/tty/serial/8250/8250_exar.c +++ b/drivers/tty/serial/8250/8250_exar.c @@ -37,6 +37,7 @@ #define PCI_DEVICE_ID_EXAR_XR17V4358 0x4358 #define PCI_DEVICE_ID_EXAR_XR17V8358 0x8358 =20 +#define UART_EXAR_INT0 0x80 #define UART_EXAR_8XMODE 0x88 /* 8X sampling rate select */ =20 #define UART_EXAR_FCTR 0x08 /* Feature Control Register */ @@ -124,6 +125,7 @@ struct exar8250_board { struct exar8250 { unsigned int nr; struct exar8250_board *board; + void __iomem *virt; int line[0]; }; =20 @@ -134,12 +136,9 @@ static int default_setup(struct exar8250 *priv, struct= pci_dev *pcidev, const struct exar8250_board *board =3D priv->board; unsigned int bar =3D 0; =20 - if (!pcim_iomap_table(pcidev)[bar] && !pcim_iomap(pcidev, bar, 0)) - return -ENOMEM; - port->port.iotype =3D UPIO_MEM; port->port.mapbase =3D pci_resource_start(pcidev, bar) + offset; - port->port.membase =3D pcim_iomap_table(pcidev)[bar] + offset; + port->port.membase =3D priv->virt + offset; port->port.regshift =3D board->reg_shift; =20 return 0; @@ -423,6 +422,25 @@ static void pci_xr17v35x_exit(struct pci_dev *pcidev) port->port.private_data =3D NULL; } =20 +/* + * These Exar UARTs have an extra interrupt indicator that could fire for = a + * few interrupts that are not presented/cleared through IIR. One of whic= h is + * a wakeup interrupt when coming out of sleep. These interrupts are only + * cleared by reading global INT0 or INT1 registers as interrupts are + * associated with channel 0. The INT[3:0] registers _are_ accessible from= each + * channel's address space, but for the sake of bus efficiency we register= a + * dedicated handler at the PCI device level to handle them. + */ +static irqreturn_t exar_misc_handler(int irq, void *data) +{ + struct exar8250 *priv =3D data; + + /* Clear all PCI interrupts by reading INT0. No effect on IIR */ + ioread8(priv->virt + UART_EXAR_INT0); + + return IRQ_HANDLED; +} + static int exar_pci_probe(struct pci_dev *pcidev, const struct pci_device_id *ent) { @@ -451,6 +469,9 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pci= _device_id *ent) return -ENOMEM; =20 priv->board =3D board; + priv->virt =3D pcim_iomap(pcidev, bar, 0); + if (!priv->virt) + return -ENOMEM; =20 pci_set_master(pcidev); =20 @@ -464,6 +485,11 @@ exar_pci_probe(struct pci_dev *pcidev, const struct pc= i_device_id *ent) uart.port.irq =3D pci_irq_vector(pcidev, 0); uart.port.dev =3D &pcidev->dev; =20 + rc =3D devm_request_irq(&pcidev->dev, uart.port.irq, exar_misc_handler, + IRQF_SHARED, "exar_uart", priv); + if (rc) + return rc; + for (i =3D 0; i < nr_ports && i < maxnr; i++) { rc =3D board->setup(priv, pcidev, &uart, i); if (rc) { diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index 8dcfd4978a03..e9d4420869dd 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -445,7 +445,6 @@ static void io_serial_out(struct uart_port *p, int offs= et, int value) } =20 static int serial8250_default_handle_irq(struct uart_port *port); -static int exar_handle_irq(struct uart_port *port); =20 static void set_io_from_upio(struct uart_port *p) { @@ -1890,26 +1889,6 @@ static int serial8250_default_handle_irq(struct uart= _port *port) return ret; } =20 -/* - * These Exar UARTs have an extra interrupt indicator that could - * fire for a few unimplemented interrupts. One of which is a - * wakeup event when coming out of sleep. Put this here just - * to be on the safe side that these interrupts don't go unhandled. - */ -static int exar_handle_irq(struct uart_port *port) -{ - unsigned int iir =3D serial_port_in(port, UART_IIR); - int ret =3D 0; - - if (((port->type =3D=3D PORT_XR17V35X) || (port->type =3D=3D PORT_XR17D15= X)) && - serial_port_in(port, UART_EXAR_INT0) !=3D 0) - ret =3D 1; - - ret |=3D serial8250_handle_irq(port, iir); - - return ret; -} - /* * Newer 16550 compatible parts such as the SC16C650 & Altera 16550 Soft I= P * have a programmable TX threshold that triggers the THRE interrupt in @@ -3074,11 +3053,6 @@ static void serial8250_config_port(struct uart_port = *port, int flags) if (port->type =3D=3D PORT_UNKNOWN) serial8250_release_std_resource(up); =20 - /* Fixme: probably not the best place for this */ - if ((port->type =3D=3D PORT_XR17V35X) || - (port->type =3D=3D PORT_XR17D15X)) - port->handle_irq =3D exar_handle_irq; - register_dev_spec_attr_grp(up); up->fcr =3D uart_config[up->port.type].fcr; } --=20 2.15.1