1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/console.h>
10 #include <linux/serial.h>
11 #include <linux/serial_8250.h>
15 #define RT288X_DL 0x28
17 /* Au1x00/RT288x UART hardware has a weird register layout */
18 static const u8 au_io_in_map[7] = {
28 static const u8 au_io_out_map[5] = {
36 static unsigned int au_serial_in(struct uart_port *p, int offset)
38 if (offset >= ARRAY_SIZE(au_io_in_map))
40 offset = au_io_in_map[offset];
42 return __raw_readl(p->membase + (offset << p->regshift));
45 static void au_serial_out(struct uart_port *p, int offset, int value)
47 if (offset >= ARRAY_SIZE(au_io_out_map))
49 offset = au_io_out_map[offset];
51 __raw_writel(value, p->membase + (offset << p->regshift));
54 /* Au1x00 haven't got a standard divisor latch */
55 static u32 au_serial_dl_read(struct uart_8250_port *up)
57 return __raw_readl(up->port.membase + RT288X_DL);
60 static void au_serial_dl_write(struct uart_8250_port *up, u32 value)
62 __raw_writel(value, up->port.membase + RT288X_DL);
65 int au_platform_setup(struct plat_serial8250_port *p)
69 p->serial_in = au_serial_in;
70 p->serial_out = au_serial_out;
71 p->dl_read = au_serial_dl_read;
72 p->dl_write = au_serial_dl_write;
76 p->bugs |= UART_BUG_NOMSR;
80 EXPORT_SYMBOL_GPL(au_platform_setup);
82 int rt288x_setup(struct uart_port *p)
84 struct uart_8250_port *up = up_to_u8250p(p);
88 p->serial_in = au_serial_in;
89 p->serial_out = au_serial_out;
90 up->dl_read = au_serial_dl_read;
91 up->dl_write = au_serial_dl_write;
95 up->bugs |= UART_BUG_NOMSR;
99 EXPORT_SYMBOL_GPL(rt288x_setup);
101 #ifdef CONFIG_SERIAL_8250_CONSOLE
102 static void au_putc(struct uart_port *port, unsigned char c)
106 au_serial_out(port, UART_TX, c);
109 status = au_serial_in(port, UART_LSR);
110 if (uart_lsr_tx_empty(status))
116 static void au_early_serial8250_write(struct console *console,
117 const char *s, unsigned int count)
119 struct earlycon_device *device = console->data;
120 struct uart_port *port = &device->port;
122 uart_console_write(port, s, count, au_putc);
125 static int __init early_au_setup(struct earlycon_device *dev, const char *opt)
127 rt288x_setup(&dev->port);
128 dev->con->write = au_early_serial8250_write;
132 OF_EARLYCON_DECLARE(palmchip, "ralink,rt2880-uart", early_au_setup);
135 MODULE_DESCRIPTION("RT288x/Au1xxx UART driver");
136 MODULE_LICENSE("GPL");