b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | /* |
| 3 | * prom.c |
| 4 | * Early intialization code for the Realtek RTL838X SoC |
| 5 | * |
| 6 | * based on the original BSP by |
| 7 | * Copyright (C) 2006-2012 Tony Wu (tonywu@realtek.com) |
| 8 | * Copyright (C) 2020 B. Koblitz |
| 9 | * |
| 10 | */ |
| 11 | |
| 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> |
| 19 | #include <asm/page.h> |
| 20 | #include <asm/cpu.h> |
| 21 | |
| 22 | #include <mach-rtl83xx.h> |
| 23 | |
| 24 | extern char arcs_cmdline[]; |
| 25 | extern const char __appended_dtb; |
| 26 | |
| 27 | struct rtl83xx_soc_info soc_info; |
| 28 | const void *fdt; |
| 29 | |
| 30 | const char *get_system_type(void) |
| 31 | { |
| 32 | return soc_info.name; |
| 33 | } |
| 34 | |
| 35 | void __init prom_free_prom_memory(void) |
| 36 | { |
| 37 | |
| 38 | } |
| 39 | |
| 40 | void __init device_tree_init(void) |
| 41 | { |
| 42 | if (!fdt_check_header(&__appended_dtb)) { |
| 43 | fdt = &__appended_dtb; |
| 44 | pr_info("Using appended Device Tree.\n"); |
| 45 | } |
| 46 | initial_boot_params = (void *)fdt; |
| 47 | unflatten_and_copy_device_tree(); |
| 48 | } |
| 49 | |
| 50 | static void __init prom_init_cmdline(void) |
| 51 | { |
| 52 | int argc = fw_arg0; |
| 53 | char **argv = (char **) KSEG1ADDR(fw_arg1); |
| 54 | int i; |
| 55 | |
| 56 | arcs_cmdline[0] = '\0'; |
| 57 | |
| 58 | for (i = 0; i < argc; i++) { |
| 59 | char *p = (char *) KSEG1ADDR(argv[i]); |
| 60 | |
| 61 | if (CPHYSADDR(p) && *p) { |
| 62 | strlcat(arcs_cmdline, p, sizeof(arcs_cmdline)); |
| 63 | strlcat(arcs_cmdline, " ", sizeof(arcs_cmdline)); |
| 64 | } |
| 65 | } |
| 66 | pr_info("Kernel command line: %s\n", arcs_cmdline); |
| 67 | } |
| 68 | |
| 69 | void __init identify_rtl9302(void) |
| 70 | { |
| 71 | switch (sw_r32(RTL93XX_MODEL_NAME_INFO) & 0xfffffff0) { |
| 72 | case 0x93020810: |
| 73 | soc_info.name = "RTL9302A 12x2.5G"; |
| 74 | break; |
| 75 | case 0x93021010: |
| 76 | soc_info.name = "RTL9302B 8x2.5G"; |
| 77 | break; |
| 78 | case 0x93021810: |
| 79 | soc_info.name = "RTL9302C 16x2.5G"; |
| 80 | break; |
| 81 | case 0x93022010: |
| 82 | soc_info.name = "RTL9302D 24x2.5G"; |
| 83 | break; |
| 84 | case 0x93020800: |
| 85 | soc_info.name = "RTL9302A"; |
| 86 | break; |
| 87 | case 0x93021000: |
| 88 | soc_info.name = "RTL9302B"; |
| 89 | break; |
| 90 | case 0x93021800: |
| 91 | soc_info.name = "RTL9302C"; |
| 92 | break; |
| 93 | case 0x93022000: |
| 94 | soc_info.name = "RTL9302D"; |
| 95 | break; |
| 96 | case 0x93023001: |
| 97 | soc_info.name = "RTL9302F"; |
| 98 | break; |
| 99 | default: |
| 100 | soc_info.name = "RTL9302"; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void __init prom_init(void) |
| 105 | { |
| 106 | uint32_t model; |
| 107 | |
| 108 | /* uart0 */ |
| 109 | setup_8250_early_printk_port(0xb8002000, 2, 0); |
| 110 | |
| 111 | model = sw_r32(RTL838X_MODEL_NAME_INFO); |
| 112 | pr_info("RTL838X model is %x\n", model); |
| 113 | model = model >> 16 & 0xFFFF; |
| 114 | |
| 115 | if ((model != 0x8328) && (model != 0x8330) && (model != 0x8332) |
| 116 | && (model != 0x8380) && (model != 0x8382)) { |
| 117 | model = sw_r32(RTL839X_MODEL_NAME_INFO); |
| 118 | pr_info("RTL839X model is %x\n", model); |
| 119 | model = model >> 16 & 0xFFFF; |
| 120 | } |
| 121 | |
| 122 | if ((model & 0x8390) != 0x8380 && (model & 0x8390) != 0x8390) { |
| 123 | model = sw_r32(RTL93XX_MODEL_NAME_INFO); |
| 124 | pr_info("RTL93XX model is %x\n", model); |
| 125 | model = model >> 16 & 0xFFFF; |
| 126 | } |
| 127 | |
| 128 | soc_info.id = model; |
| 129 | |
| 130 | switch (model) { |
| 131 | case 0x8328: |
| 132 | soc_info.name = "RTL8328"; |
| 133 | soc_info.family = RTL8328_FAMILY_ID; |
| 134 | break; |
| 135 | case 0x8332: |
| 136 | soc_info.name = "RTL8332"; |
| 137 | soc_info.family = RTL8380_FAMILY_ID; |
| 138 | break; |
| 139 | case 0x8380: |
| 140 | soc_info.name = "RTL8380"; |
| 141 | soc_info.family = RTL8380_FAMILY_ID; |
| 142 | break; |
| 143 | case 0x8382: |
| 144 | soc_info.name = "RTL8382"; |
| 145 | soc_info.family = RTL8380_FAMILY_ID; |
| 146 | break; |
| 147 | case 0x8390: |
| 148 | soc_info.name = "RTL8390"; |
| 149 | soc_info.family = RTL8390_FAMILY_ID; |
| 150 | break; |
| 151 | case 0x8391: |
| 152 | soc_info.name = "RTL8391"; |
| 153 | soc_info.family = RTL8390_FAMILY_ID; |
| 154 | break; |
| 155 | case 0x8392: |
| 156 | soc_info.name = "RTL8392"; |
| 157 | soc_info.family = RTL8390_FAMILY_ID; |
| 158 | break; |
| 159 | case 0x8393: |
| 160 | soc_info.name = "RTL8393"; |
| 161 | soc_info.family = RTL8390_FAMILY_ID; |
| 162 | break; |
| 163 | case 0x9301: |
| 164 | soc_info.name = "RTL9301"; |
| 165 | soc_info.family = RTL9300_FAMILY_ID; |
| 166 | break; |
| 167 | case 0x9302: |
| 168 | identify_rtl9302(); |
| 169 | soc_info.family = RTL9300_FAMILY_ID; |
| 170 | break; |
| 171 | case 0x9313: |
| 172 | soc_info.name = "RTL9313"; |
| 173 | soc_info.family = RTL9310_FAMILY_ID; |
| 174 | break; |
| 175 | default: |
| 176 | soc_info.name = "DEFAULT"; |
| 177 | soc_info.family = 0; |
| 178 | } |
| 179 | |
| 180 | pr_info("SoC Type: %s\n", get_system_type()); |
| 181 | |
| 182 | prom_init_cmdline(); |
| 183 | } |