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
;
27 //extern int __init rtl838x_serial_init(void);
29 void prom_console_init(void)
31 /* UART 16550A is initialized by the bootloader */
34 #ifdef CONFIG_EARLY_PRINTK
35 #define rtl838x_r8(reg) __raw_readb(reg)
36 #define rtl838x_w8(val, reg) __raw_writeb(val, reg)
38 void unregister_prom_console(void)
43 void disable_early_printk(void)
48 void prom_putchar(char c
)
50 unsigned int retry
= 0;
53 if (retry
++ >= 30000) {
55 rtl838x_w8(TXRST
| CHAR_TRIGGER_14
, UART0_FCR
);
58 } while ((rtl838x_r8(UART0_LSR
) & LSR_THRE
) == TxCHAR_AVAIL
);
61 rtl838x_w8(c
, UART0_THR
);
64 char prom_getchar(void)
70 struct rtl838x_soc_info soc_info
;
72 const char *get_system_type(void)
78 void __init
prom_free_prom_memory(void)
83 void __init
device_tree_init(void)
85 pr_info("%s called\r\n", __func__
);
86 if (!fdt_check_header(&__appended_dtb
)) {
87 fdt
= &__appended_dtb
;
88 pr_info("Using appended Device Tree.\n");
90 initial_boot_params
= (void *)fdt
;
91 unflatten_and_copy_device_tree();
94 static void __init
prom_init_cmdline(void)
97 char **argv
= (char **) KSEG1ADDR(fw_arg1
);
100 arcs_cmdline
[0] = '\0';
102 for (i
= 0; i
< argc
; i
++) {
103 char *p
= (char *) KSEG1ADDR(argv
[i
]);
105 if (CPHYSADDR(p
) && *p
) {
106 strlcat(arcs_cmdline
, p
, sizeof(arcs_cmdline
));
107 strlcat(arcs_cmdline
, " ", sizeof(arcs_cmdline
));
110 pr_info("Kernel command line: %s\n", arcs_cmdline
);
113 /* Do basic initialization */
114 void __init
prom_init(void)
118 pr_info("%s called\n", __func__
);
119 soc_info
.sw_base
= RTL838X_SW_BASE
;
121 model
= sw_r32(RTL838X_MODEL_NAME_INFO
);
122 pr_info("RTL838X model is %x\n", model
);
123 model
= model
>> 16 & 0xFFFF;
125 if ((model
!= 0x8328) && (model
!= 0x8330) && (model
!= 0x8332)
126 && (model
!= 0x8380) && (model
!= 0x8382)) {
127 model
= sw_r32(RTL839X_MODEL_NAME_INFO
);
128 pr_info("RTL839X model is %x\n", model
);
129 model
= model
>> 16 & 0xFFFF;
136 soc_info
.name
= "RTL8328";
137 soc_info
.family
= RTL8328_FAMILY_ID
;
140 soc_info
.name
= "RTL8332";
141 soc_info
.family
= RTL8380_FAMILY_ID
;
144 soc_info
.name
= "RTL8380";
145 soc_info
.family
= RTL8380_FAMILY_ID
;
148 soc_info
.name
= "RTL8382";
149 soc_info
.family
= RTL8380_FAMILY_ID
;
152 soc_info
.name
= "RTL8390";
153 soc_info
.family
= RTL8390_FAMILY_ID
;
156 soc_info
.name
= "RTL8391";
157 soc_info
.family
= RTL8390_FAMILY_ID
;
160 soc_info
.name
= "RTL8392";
161 soc_info
.family
= RTL8390_FAMILY_ID
;
164 soc_info
.name
= "RTL8393";
165 soc_info
.family
= RTL8390_FAMILY_ID
;
168 soc_info
.name
= "DEFAULT";
171 pr_info("SoC Type: %s\n", get_system_type());