Skip to contentSkip to conversation

serial: Separate RT288x/Au1xxx code into own file

PATCH Superseded Ilpo Järvinen 2 participants 6 messages Jan 5, 2023 – Jan 6, 2023

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover serial: Separate RT288x/Au1xxx code into own file

A non-trivial amount of RT288x/Au1xxx code is encapsulated into ifdeffery in 8250_port / 8250_early and some if/switch UPIO_AU blocks. Create a separate file from them and do a few additional cleanups.

I kept the Kconfig entry as bool because the code has somewhat tricky dependency chain (mips arch code and 8250_of driver). It would be nice to make it tristate but I don't know how blocking some invalid =m + =y combinations would be best addressed. It should probably be best done on top of this series independent of the split itself anyway.

UPIO_AU could now be removed because it's same as UPIO_MEM for the remaining code path but I'm unsure if that's allowed (is the port iotype part of stable ABI or not)?

v2:
- Define register map array lengths explicitly to avoid creating declaration trap.

Ilpo Järvinen (3):
serial: 8250: RT288x/Au1xxx code away from core
serial: 8250_rt288x: Name non-standard divisor latch reg
serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED

 arch/mips/alchemy/common/platform.c   |  10 +-
 drivers/tty/serial/8250/8250_core.c   |   4 +
 drivers/tty/serial/8250/8250_early.c  |  21 ----
 drivers/tty/serial/8250/8250_of.c     |   4 +-
 drivers/tty/serial/8250/8250_port.c   |  78 ---------------
 drivers/tty/serial/8250/8250_rt288x.c | 135 ++++++++++++++++++++++++++
 drivers/tty/serial/8250/Makefile      |   1 +
 include/linux/serial_8250.h           |  14 ++-
 8 files changed, 163 insertions(+), 104 deletions(-)
 create mode 100644 drivers/tty/serial/8250/8250_rt288x.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/3 serial: 8250: RT288x/Au1xxx code away from core

A non-trivial amount of RT288x/Au1xxx code is encapsulated into ifdeffery in 8250_port / 8250_early and some if UPIO_AU blocks.

Create a separate file from them. Add mapsize, bugs, and divisor latch read/write functions into plat_serial8250_port to carry the setup necessary for these devices over to uart port.

Also handle errors properly in the cases where RT288x/Au1xxx code is not configured.

It seems that 0x1000 mapsize is likely overkill but I've kept it the same as previously (the value was shrunk to that value in b2b13cdfd05e ("SERIAL 8250: Fixes for Alchemy UARTs.")). Seemingly, the driver only needs to access register at 0x28 for the divisor latch.

---
 arch/mips/alchemy/common/platform.c   |  10 +-
 drivers/tty/serial/8250/8250_core.c   |   4 +
 drivers/tty/serial/8250/8250_early.c  |  21 ----
 drivers/tty/serial/8250/8250_of.c     |   4 +-
 drivers/tty/serial/8250/8250_port.c   |  78 --------------
 drivers/tty/serial/8250/8250_rt288x.c | 141 ++++++++++++++++++++++++++
 drivers/tty/serial/8250/Makefile      |   1 +
 include/linux/serial_8250.h           |  14 ++-
 8 files changed, 169 insertions(+), 104 deletions(-)
 create mode 100644 drivers/tty/serial/8250/8250_rt288x.c
arch/mips/alchemy/common/platform.c +8 -2
index b8f3397c59c9..d4ab34b3b404 100644
@@ -51,9 +51,9 @@ static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
 #define PORT(_base, _irq)					\
 	{							\
 		.mapbase	= _base,			\
+		.mapsize	= 0x1000,			\
 		.irq		= _irq,				\
 		.regshift	= 2,				\
-		.iotype		= UPIO_AU,			\
 		.flags		= UPF_SKIP_TEST | UPF_IOREMAP | \
 				  UPF_FIXED_TYPE,		\
 		.type		= PORT_16550A,			\
@@ -124,8 +124,14 @@ static void __init alchemy_setup_uarts(int ctype)
 	au1xx0_uart_device.dev.platform_data = ports;
 
 	/* Fill up uartclk. */
-	for (s = 0; s < c; s++)
+	for (s = 0; s < c; s++) {
 		ports[s].uartclk = uartclk;
+		if (au_platform_setup(&ports[s]) < 0) {
+			kfree(ports);
+			printk(KERN_INFO "Alchemy: missing support for UARTs\n");
+			return;
+		}
+	}
 	if (platform_device_register(&au1xx0_uart_device))
 		printk(KERN_INFO "Alchemy: failed to register UARTs\n");
 }
drivers/tty/serial/8250/8250_core.c +4 -0
index ab63c308be0a..a5cc3dcb7572 100644
@@ -822,12 +822,16 @@ static int serial8250_probe(struct platform_device *dev)
 		uart.port.iotype	= p->iotype;
 		uart.port.flags		= p->flags;
 		uart.port.mapbase	= p->mapbase;
+		uart.port.mapsize	= p->mapsize;
 		uart.port.hub6		= p->hub6;
 		uart.port.has_sysrq	= p->has_sysrq;
 		uart.port.private_data	= p->private_data;
 		uart.port.type		= p->type;
+		uart.bugs		= p->bugs;
 		uart.port.serial_in	= p->serial_in;
 		uart.port.serial_out	= p->serial_out;
+		uart.dl_read		= p->dl_read;
+		uart.dl_write		= p->dl_write;
 		uart.port.handle_irq	= p->handle_irq;
 		uart.port.handle_break	= p->handle_break;
 		uart.port.set_termios	= p->set_termios;
drivers/tty/serial/8250/8250_early.c +0 -21
index f271becfc46c..77a2e4441920 100644
@@ -36,7 +36,6 @@
 
 static unsigned int serial8250_early_in(struct uart_port *port, int offset)
 {
-	int reg_offset = offset;
 	offset <<= port->regshift;
 
 	switch (port->iotype) {
@@ -50,8 +49,6 @@ static unsigned int serial8250_early_in(struct uart_port *port, int offset)
 		return ioread32be(port->membase + offset);
 	case UPIO_PORT:
 		return inb(port->iobase + offset);
-	case UPIO_AU:
-		return port->serial_in(port, reg_offset);
 	default:
 		return 0;
 	}
@@ -59,7 +56,6 @@ static unsigned int serial8250_early_in(struct uart_port *port, int offset)
 
 static void serial8250_early_out(struct uart_port *port, int offset, int value)
 {
-	int reg_offset = offset;
 	offset <<= port->regshift;
 
 	switch (port->iotype) {
@@ -78,9 +74,6 @@ static void serial8250_early_out(struct uart_port *port, int offset, int value)
 	case UPIO_PORT:
 		outb(value, port->iobase + offset);
 		break;
-	case UPIO_AU:
-		port->serial_out(port, reg_offset, value);
-		break;
 	}
 }
 
@@ -199,17 +192,3 @@ OF_EARLYCON_DECLARE(omap8250, "ti,omap3-uart", early_omap8250_setup);
 OF_EARLYCON_DECLARE(omap8250, "ti,omap4-uart", early_omap8250_setup);
 
 #endif
-
-#ifdef CONFIG_SERIAL_8250_RT288X
-
-static int __init early_au_setup(struct earlycon_device *dev, const char *opt)
-{
-	dev->port.serial_in = au_serial_in;
-	dev->port.serial_out = au_serial_out;
-	dev->port.iotype = UPIO_AU;
-	dev->con->write = early_serial8250_write;
-	return 0;
-}
-OF_EARLYCON_DECLARE(palmchip, "ralink,rt2880-uart", early_au_setup);
-
-#endif
drivers/tty/serial/8250/8250_of.c +3 -1
index 1b461fba15a3..c9f6bd7a7038 100644
@@ -171,7 +171,9 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 
 	switch (type) {
 	case PORT_RT2880:
-		port->iotype = UPIO_AU;
+		ret = rt288x_setup(port);
+		if (ret)
+			goto err_unprepare;
 		break;
 	}
 
drivers/tty/serial/8250/8250_port.c +0 -78

102 lines not on this page · raw message

drivers/tty/serial/8250/8250_rt288x.c new file +141 -0

141 lines not on this page · raw message

drivers/tty/serial/8250/Makefile +1 -0
index 1615bfdde2a0..7ac162c1c79b 100644
@@ -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_RT288X)	+= 8250_rt288x.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
include/linux/serial_8250.h +12 -2
index 19376bee9667..66318658f8bc 100644
@@ -7,10 +7,13 @@
 #ifndef _LINUX_SERIAL_8250_H
 #define _LINUX_SERIAL_8250_H
 
+#include <linux/errno.h>
 #include <linux/serial_core.h>
 #include <linux/serial_reg.h>
 #include <linux/platform_device.h>
 
+struct uart_8250_port;
+
 /*
  * This is the platform device platform_data structure
  */
@@ -18,6 +21,7 @@ struct plat_serial8250_port {
 	unsigned long	iobase;		/* io base address */
 	void __iomem	*membase;	/* ioremap cookie or NULL */
 	resource_size_t	mapbase;	/* resource base */
+	resource_size_t	mapsize;
 	unsigned int	irq;		/* interrupt number */
 	unsigned long	irqflags;	/* request_irq flags */
 	unsigned int	uartclk;	/* UART clock rate */
@@ -28,8 +32,11 @@ struct plat_serial8250_port {
 	unsigned char	has_sysrq;	/* supports magic SysRq */
 	upf_t		flags;		/* UPF_* flags */
 	unsigned int	type;		/* If UPF_FIXED_TYPE */
+	unsigned short	bugs;		/* port bugs */
 	unsigned int	(*serial_in)(struct uart_port *, int);
 	void		(*serial_out)(struct uart_port *, int, int);
+	int		(*dl_read)(struct uart_8250_port *);
+	void		(*dl_write)(struct uart_8250_port *, int);
 	void		(*set_termios)(struct uart_port *,
 			               struct ktermios *new,
 			               const struct ktermios *old);
@@ -188,8 +195,11 @@ extern void serial8250_set_isa_configurator(void (*v)
 						u32 *capabilities));
 
 #ifdef CONFIG_SERIAL_8250_RT288X
-unsigned int au_serial_in(struct uart_port *p, int offset);
-void au_serial_out(struct uart_port *p, int offset, int value);
+int rt288x_setup(struct uart_port *p);
+int au_platform_setup(struct plat_serial8250_port *p);
+#else
+static inline int rt288x_setup(struct uart_port *p) { return -ENODEV; }
+static inline int au_platform_setup(struct plat_serial8250_port *p) { return -ENODEV; }
 #endif
 
 #endif
Signature · 1 line
2.30.2
maintainer
#2 lore raw

Re: [PATCH v2 1/3] serial: 8250: RT288x/Au1xxx code away from core

Quoted 16 lines · Ilpo Järvinen

A non-trivial amount of RT288x/Au1xxx code is encapsulated into ifdeffery in 8250_port / 8250_early and some if UPIO_AU blocks.

Create a separate file from them. Add mapsize, bugs, and divisor latch read/write functions into plat_serial8250_port to carry the setup necessary for these devices over to uart port.

Also handle errors properly in the cases where RT288x/Au1xxx code is not configured.

It seems that 0x1000 mapsize is likely overkill but I've kept it the same as previously (the value was shrunk to that value in b2b13cdfd05e ("SERIAL 8250: Fixes for Alchemy UARTs.")). Seemingly, the driver only needs to access register at 0x28 for the divisor latch.

...

Quoted 2 lines
include/linux/serial_8250.h +0 -0

...

include/linux/serial_8250.h struct plat_serial8250_port { · line 39

Quoted 9 lines
include/linux/serial_8250.h +3 -0
@@ -28,8 +32,11 @@ struct plat_serial8250_port {
  	unsigned char	has_sysrq;	/* supports magic SysRq */
  	upf_t		flags;		/* UPF_* flags */
  	unsigned int	type;		/* If UPF_FIXED_TYPE */
+	unsigned short	bugs;		/* port bugs */
  	unsigned int	(*serial_in)(struct uart_port *, int);
  	void		(*serial_out)(struct uart_port *, int, int);
+	int		(*dl_read)(struct uart_8250_port *);
+	void		(*dl_write)(struct uart_8250_port *, int);

int sounds very weird in the write-to-HW context. Even though both the others and the original are ints. They all should be simply u32.

include/linux/serial_8250.h struct plat_serial8250_port { · line 42

Quoted 3 lines
include/linux/serial_8250.h +0 -0
  	void		(*set_termios)(struct uart_port *,
  			               struct ktermios *new,
  			               const struct ktermios *old);

Could you document the new ones in the kernel-doc manner above the structure (but so far without the kernel-doc tag /**). So that:
1) they are documented
2) once someone decides to document them all, they can simply stick the kernel-doc tag and document only the rest.

thanks,

Signature · 2 lines
js
suse labs
#3 lore raw

PATCH v2 2/3 serial: 8250_rt288x: Name non-standard divisor latch reg

In reply to Ilpo Järvinen

Instead of a literal, add proper name for the non-standard divisor latch register.

---
 drivers/tty/serial/8250/8250_rt288x.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_rt288x.c +4 -2
index cb9a86bd3a07..3015afb99722 100644
@@ -12,6 +12,8 @@
 
 #include "8250.h"
 
+#define RT288X_DL	0x28
+
 #define UART_REG_UNMAPPED	-1
 
 /* Au1x00/RT288x UART hardware has a weird register layout */
@@ -60,12 +62,12 @@ static void au_serial_out(struct uart_port *p, int offset, int value)
 /* Au1x00 haven't got a standard divisor latch */
 static int au_serial_dl_read(struct uart_8250_port *up)
 {
-	return __raw_readl(up->port.membase + 0x28);
+	return __raw_readl(up->port.membase + RT288X_DL);
 }
 
 static void au_serial_dl_write(struct uart_8250_port *up, int value)
 {
-	__raw_writel(value, up->port.membase + 0x28);
+	__raw_writel(value, up->port.membase + RT288X_DL);
 }
 
 int au_platform_setup(struct plat_serial8250_port *p)
Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 3/3 serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED

In reply to Ilpo Järvinen

As unmapped registers are at the tail of the array, the ARRAY_SIZE() condition will catch them just fine. No need to define special value for them.

---
 drivers/tty/serial/8250/8250_rt288x.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/tty/serial/8250/8250_rt288x.c +4 -12
index 3015afb99722..7399fea6dfc1 100644
@@ -14,10 +14,8 @@
 
 #define RT288X_DL	0x28
 
-#define UART_REG_UNMAPPED	-1
-
 /* Au1x00/RT288x UART hardware has a weird register layout */
-static const s8 au_io_in_map[8] = {
+static const s8 au_io_in_map[7] = {
 	[UART_RX]	= 0,
 	[UART_IER]	= 2,
 	[UART_IIR]	= 3,
@@ -25,18 +23,14 @@ static const s8 au_io_in_map[8] = {
 	[UART_MCR]	= 6,
 	[UART_LSR]	= 7,
 	[UART_MSR]	= 8,
-	[UART_SCR]	= UART_REG_UNMAPPED,
 };
 
-static const s8 au_io_out_map[8] = {
+static const s8 au_io_out_map[5] = {
 	[UART_TX]	= 1,
 	[UART_IER]	= 2,
 	[UART_FCR]	= 4,
 	[UART_LCR]	= 5,
 	[UART_MCR]	= 6,
-	[UART_LSR]	= UART_REG_UNMAPPED,
-	[UART_MSR]	= UART_REG_UNMAPPED,
-	[UART_SCR]	= UART_REG_UNMAPPED,
 };
 
 static unsigned int au_serial_in(struct uart_port *p, int offset)
@@ -44,8 +38,7 @@ static unsigned int au_serial_in(struct uart_port *p, int offset)
 	if (offset >= ARRAY_SIZE(au_io_in_map))
 		return UINT_MAX;
 	offset = au_io_in_map[offset];
-	if (offset == UART_REG_UNMAPPED)
-		return UINT_MAX;
+
 	return __raw_readl(p->membase + (offset << p->regshift));
 }
 
@@ -54,8 +47,7 @@ static void au_serial_out(struct uart_port *p, int offset, int value)
 	if (offset >= ARRAY_SIZE(au_io_out_map))
 		return;
 	offset = au_io_out_map[offset];
-	if (offset == UART_REG_UNMAPPED)
-		return;
+
 	__raw_writel(value, p->membase + (offset << p->regshift));
 }
 
Signature · 1 line
2.30.2
maintainer
#5 lore raw

Re: [PATCH v2 3/3] serial: 8250_rt288x: Remove unnecessary UART_REG_UNMAPPED

Quoted 26 lines · Ilpo Järvinen

As unmapped registers are at the tail of the array, the ARRAY_SIZE() condition will catch them just fine. No need to define special value for them.

---
  drivers/tty/serial/8250/8250_rt288x.c | 16 ++++------------
  1 file changed, 4 insertions(+), 12 deletions(-)
drivers/tty/serial/8250/8250_rt288x.c +1 -3
index 3015afb99722..7399fea6dfc1 100644
@@ -14,10 +14,8 @@
 
  #define RT288X_DL	0x28
 
-#define UART_REG_UNMAPPED	-1
-
  /* Au1x00/RT288x UART hardware has a weird register layout */
-static const s8 au_io_in_map[8] = {
+static const s8 au_io_in_map[7] = {
  	[UART_RX]	= 0,
  	[UART_IER]	= 2,
  	[UART_IIR]	= 3,

drivers/tty/serial/8250/8250_rt288x.c static const s8 au_io_in_map[8] = { · line 28

Quoted 8 lines
drivers/tty/serial/8250/8250_rt288x.c +1 -2
@@ -25,18 +23,14 @@ static const s8 au_io_in_map[8] = {
  	[UART_MCR]	= 6,
  	[UART_LSR]	= 7,
  	[UART_MSR]	= 8,
-	[UART_SCR]	= UART_REG_UNMAPPED,
  };
 
-static const s8 au_io_out_map[8] = {
+static const s8 au_io_out_map[5] = {

And what about making them u8 at last?

drivers/tty/serial/8250/8250_rt288x.c static const s8 au_io_in_map[8] = { · line 39

Quoted 8 lines
drivers/tty/serial/8250/8250_rt288x.c +0 -3
  	[UART_TX]	= 1,
  	[UART_IER]	= 2,
  	[UART_FCR]	= 4,
  	[UART_LCR]	= 5,
  	[UART_MCR]	= 6,
-	[UART_LSR]	= UART_REG_UNMAPPED,
-	[UART_MSR]	= UART_REG_UNMAPPED,
-	[UART_SCR]	= UART_REG_UNMAPPED,

thanks,

Signature · 2 lines
js
suse labs