1 // SPDX-License-Identifier: GPL-2.0-only
3 * 8250 serial console setup for the Realtek RTL838X SoC
5 * based on the original BSP by
6 * Copyright (C) 2006-2012 Tony Wu (tonywu@realtek.com)
8 * Copyright (C) 2020 B. Koblitz
12 #include <linux/types.h>
13 #include <linux/ctype.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/version.h>
17 #include <linux/serial.h>
18 #include <linux/serial_core.h>
19 #include <linux/serial_8250.h>
20 #include <linux/serial_reg.h>
21 #include <linux/tty.h>
22 #include <linux/clk.h>
24 #include <asm/mach-rtl838x/mach-rtl838x.h>
26 extern char arcs_cmdline
[];
27 extern struct rtl838x_soc_info soc_info
;
29 int __init
rtl838x_serial_init(void)
31 #ifdef CONFIG_SERIAL_8250
34 unsigned long baud
= 0;
36 char parity
= '\0', bits
= '\0', flow
= '\0';
38 struct device_node
*dn
;
40 dn
= of_find_compatible_node(NULL
, NULL
, "ns16550a");
42 pr_info("Found NS16550a: %s (%s)\n", dn
->name
, dn
->full_name
);
43 dn
= of_find_compatible_node(dn
, NULL
, "ns16550a");
44 if (dn
&& of_device_is_available(dn
) && soc_info
.family
== RTL8380_FAMILY_ID
) {
45 /* Enable UART1 on RTL838x */
46 pr_info("Enabling uart1\n");
47 sw_w32(0x10, RTL838X_GMII_INTF_SEL
);
50 pr_err("No NS16550a UART found!");
54 s
= strstr(arcs_cmdline
, "console=ttyS0,");
57 baud
= kstrtoul(s
, 10, &baud
);
78 pr_warn("Using default baud rate: %lu\n", baud
);
80 if (parity
!= 'n' && parity
!= 'o' && parity
!= 'e')
82 if (bits
!= '7' && bits
!= '8')
85 memset(&p
, 0, sizeof(p
));
88 p
.membase
= (unsigned char *) RTL838X_UART0_BASE
;
89 p
.irq
= RTL838X_UART0_IRQ
;
90 p
.uartclk
= SYSTEM_FREQ
- (24 * baud
);
91 p
.flags
= UPF_SKIP_TEST
| UPF_LOW_LATENCY
| UPF_FIXED_TYPE
;
96 /* Call early_serial_setup() here, to set up 8250 console driver */
97 if (early_serial_setup(&p
) != 0)