1 // SPDX-License-Identifier: GPL-2.0-only
4 * Early intialization code for the Realtek RTL838X SoC
6 * based on the original BSP by
7 * Copyright (C) 2006-2012 Tony Wu (tonywu@realtek.com)
8 * Copyright (C) 2020 B. Koblitz
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/string.h>
15 #include <linux/of_fdt.h>
16 #include <linux/libfdt.h>
17 #include <asm/bootinfo.h>
18 #include <asm/addrspace.h>
22 #include <mach-rtl838x.h>
24 extern char arcs_cmdline
[];
26 extern const char __appended_dtb
;
28 void prom_console_init(void)
30 /* UART 16550A is initialized by the bootloader */
33 #ifdef CONFIG_EARLY_PRINTK
34 #define rtl838x_r8(reg) __raw_readb(reg)
35 #define rtl838x_w8(val, reg) __raw_writeb(val, reg)
37 void unregister_prom_console(void)
42 void disable_early_printk(void)
47 void prom_putchar(char c
)
49 unsigned int retry
= 0;
52 if (retry
++ >= 30000) {
54 rtl838x_w8(TXRST
| CHAR_TRIGGER_14
, UART0_FCR
);
57 } while ((rtl838x_r8(UART0_LSR
) & LSR_THRE
) == TxCHAR_AVAIL
);
60 rtl838x_w8(c
, UART0_THR
);
63 char prom_getchar(void)
69 const char *get_system_type(void)
75 void __init
prom_free_prom_memory(void)
80 void __init
device_tree_init(void)
82 pr_info("%s called\r\n", __func__
);
83 if (!fdt_check_header(&__appended_dtb
)) {
84 fdt
= &__appended_dtb
;
85 pr_info("Using appended Device Tree.\n");
87 initial_boot_params
= (void *)fdt
;
88 unflatten_and_copy_device_tree();
91 static void __init
prom_init_cmdline(void)
94 char **argv
= (char **) KSEG1ADDR(fw_arg1
);
97 arcs_cmdline
[0] = '\0';
99 for (i
= 0; i
< argc
; i
++) {
100 char *p
= (char *) KSEG1ADDR(argv
[i
]);
102 if (CPHYSADDR(p
) && *p
) {
103 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
104 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
107 pr_info("Kernel command line: %s\n", arcs_cmdline
);
110 /* Do basic initialization */
111 void __init
prom_init(void)
115 pr_info("%s called\n", __func__
);
116 soc_info
.sw_base
= RTL838X_SW_BASE
;
118 model
= sw_r32(RTL838X_MODEL_NAME_INFO
);
119 pr_info("RTL838X model is %x\n", model
);
120 model
= model
>> 16 & 0xFFFF;
122 if ((model
!= 0x8328) && (model
!= 0x8330) && (model
!= 0x8332)
123 && (model
!= 0x8380) && (model
!= 0x8382)) {
124 model
= sw_r32(RTL839X_MODEL_NAME_INFO
);
125 pr_info("RTL839X model is %x\n", model
);
126 model
= model
>> 16 & 0xFFFF;
133 soc_info
.name
= "RTL8328";
134 soc_info
.family
= RTL8328_FAMILY_ID
;
137 soc_info
.name
= "RTL8332";
138 soc_info
.family
= RTL8380_FAMILY_ID
;
141 soc_info
.name
= "RTL8380";
142 soc_info
.family
= RTL8380_FAMILY_ID
;
145 soc_info
.name
= "RTL8382";
146 soc_info
.family
= RTL8380_FAMILY_ID
;
149 soc_info
.name
= "RTL8390";
150 soc_info
.family
= RTL8390_FAMILY_ID
;
153 soc_info
.name
= "RTL8391";
154 soc_info
.family
= RTL8390_FAMILY_ID
;
157 soc_info
.name
= "RTL8392";
158 soc_info
.family
= RTL8390_FAMILY_ID
;
161 soc_info
.name
= "RTL8393";
162 soc_info
.family
= RTL8390_FAMILY_ID
;
165 soc_info
.name
= "DEFAULT";
168 pr_info("SoC Type: %s\n", get_system_type());