Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH] tty: serial: sh-sci: Fix transmit end interrupt handler
@ 2023-03-16 16:01 Biju Das
  2023-03-16 16:13 ` Geert Uytterhoeven
  0 siblings, 1 reply; 26+ messages in thread
From: Biju Das @ 2023-03-16 16:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Biju Das, Jiri Slaby, Yoshihiro Shimoda, Geert Uytterhoeven,
	Stephen Boyd, linux-serial, Prabhakar Mahadev Lad,
	linux-renesas-soc

The RZ SCI/ RZ/A1 SCIF has only 4 interrupts. The fourth interrupt
is transmit end interrupt, so shuffle the interrupts to fix the
transmit end interrupt handler for these IPs.

Fixes: 392fb8df528b ("serial: sh-sci: Use platform_get_irq_optional() for optional interrupts")
Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
Tested the SCI0 interface on RZ/G2UL by connecting to PMOD USBUART.
 39:          0     GICv3 437 Level     1004d000.serial:rx err
 40:         12     GICv3 438 Edge      1004d000.serial:rx full
 41:         70     GICv3 439 Edge      1004d000.serial:tx empty
 42:         18     GICv3 440 Level     1004d000.serial:tx end
---
 drivers/tty/serial/sh-sci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 7bd080720929..9b07b45a6948 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -31,6 +31,7 @@
 #include <linux/ioport.h>
 #include <linux/ktime.h>
 #include <linux/major.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/of.h>
@@ -2841,6 +2842,7 @@ static int sci_init_single(struct platform_device *dev,
 	struct uart_port *port = &sci_port->port;
 	const struct resource *res;
 	unsigned int i;
+	int irq_cnt;
 	int ret;
 
 	sci_port->cfg	= p;
@@ -2864,6 +2866,14 @@ static int sci_init_single(struct platform_device *dev,
 			sci_port->irqs[i] = platform_get_irq(dev, i);
 	}
 
+	/*
+	 * RZ SCI/ RZ/A1 SCIF has only 4 interrupts. The fourth interrupt
+	 * is transmit end interrupt, so shuffle the interrupts.
+	 */
+	irq_cnt = platform_irq_count(dev);
+	if (irq_cnt == 4)
+		swap(sci_port->irqs[SCIx_BRI_IRQ], sci_port->irqs[SCIx_TEI_IRQ]);
+
 	/* The SCI generates several interrupts. They can be muxed together or
 	 * connected to different interrupt lines. In the muxed case only one
 	 * interrupt resource is specified as there is only one interrupt ID.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread
* [PATCH] tty: serial: sh-sci: Fix transmit end interrupt handler
@ 2023-04-11 10:08 Biju Das
  2023-04-11 14:14 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 26+ messages in thread
From: Biju Das @ 2023-04-11 10:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Biju Das, Jiri Slaby, linux-serial, Geert Uytterhoeven,
	Niklas Söderlund, Prabhakar Mahadev Lad, linux-renesas-soc,
	stable

commit b43a18647f03c87e77d50d6fe74904b61b96323e upstream.

The fourth interrupt on SCI port is transmit end interrupt compared to
the break interrupt on other port types. So, shuffle the interrupts to fix
the transmit end interrupt handler.

Fixes: e1d0be616186 ("sh-sci: Add h8300 SCI")
Cc: stable <stable@kernel.org>
Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230317150403.154094-1-biju.das.jz@bp.renesas.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[biju: manually fixed the conflicts]
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
Resending to 4.14 with confilcts [1] fixed.
[1] https://lore.kernel.org/stable/2023041046-synthetic-urgent-3126@gregkh/T/#u
---
 drivers/tty/serial/sh-sci.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index f7dd843a3eff..7cf95ffad4c9 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -37,6 +37,7 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/major.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/of.h>
@@ -2775,6 +2776,13 @@ static int sci_init_single(struct platform_device *dev,
 	for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i)
 		sci_port->irqs[i] = platform_get_irq(dev, i);
 
+	/*
+	 * The fourth interrupt on SCI port is transmit end interrupt, so
+	 * shuffle the interrupts.
+	 */
+	if (p->type == PORT_SCI)
+		swap(sci_port->irqs[SCIx_BRI_IRQ], sci_port->irqs[SCIx_TEI_IRQ]);
+
 	/* The SCI generates several interrupts. They can be muxed together or
 	 * connected to different interrupt lines. In the muxed case only one
 	 * interrupt resource is specified. In the non-muxed case three or four
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2023-04-12  6:52 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-16 16:01 [PATCH] tty: serial: sh-sci: Fix transmit end interrupt handler Biju Das
2023-03-16 16:13 ` Geert Uytterhoeven
2023-03-16 16:34   ` Biju Das
2023-03-16 17:54     ` Geert Uytterhoeven
2023-03-17  7:59       ` Biju Das
2023-03-17  8:05         ` Geert Uytterhoeven
2023-03-17  8:08           ` Biju Das
2023-03-17  9:00             ` Biju Das
2023-03-17  9:05               ` Geert Uytterhoeven
2023-03-17  9:07               ` Wolfram Sang
2023-03-17  9:16                 ` Wolfram Sang
2023-03-17  9:21                 ` Biju Das
2023-03-17  9:04             ` Geert Uytterhoeven
2023-03-17  9:15               ` Biju Das
2023-03-17  9:38                 ` Geert Uytterhoeven
2023-03-17 13:47                   ` Biju Das
2023-03-17 14:30                     ` Geert Uytterhoeven
2023-03-17 14:40                       ` Biju Das
  -- strict thread matches above, loose matches on Subject: below --
2023-04-11 10:08 Biju Das
2023-04-11 14:14 ` Greg Kroah-Hartman
2023-04-11 14:24   ` Biju Das
2023-04-11 14:40     ` Biju Das
2023-04-11 14:56       ` Greg Kroah-Hartman
2023-04-11 15:36         ` Biju Das
2023-04-12  6:37           ` Greg Kroah-Hartman
2023-04-12  6:52             ` Biju Das

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox