Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2022 StarFive Technology Co., Ltd. |
| 4 | * Author: Yanhong Wang<yanhong.wang@starfivetech.com> |
| 5 | */ |
| 6 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 7 | #include <asm/arch/eeprom.h> |
Chanho Park | 9ca68c9 | 2023-10-31 17:56:00 +0900 | [diff] [blame] | 8 | #include <asm/arch/gpio.h> |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 9 | #include <asm/arch/regs.h> |
| 10 | #include <asm/arch/spl.h> |
| 11 | #include <asm/io.h> |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 12 | #include <dt-bindings/clock/starfive,jh7110-crg.h> |
| 13 | #include <fdt_support.h> |
| 14 | #include <linux/libfdt.h> |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 15 | #include <log.h> |
| 16 | #include <spl.h> |
| 17 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 19 | #define JH7110_CLK_CPU_ROOT_OFFSET 0x0U |
| 20 | #define JH7110_CLK_CPU_ROOT_SHIFT 24 |
| 21 | #define JH7110_CLK_CPU_ROOT_MASK GENMASK(29, 24) |
| 22 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 23 | struct starfive_vf2_pro { |
| 24 | const char *path; |
| 25 | const char *name; |
| 26 | const char *value; |
| 27 | }; |
| 28 | |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 29 | static const struct starfive_vf2_pro milk_v_mars[] = { |
| 30 | {"/soc/ethernet@16030000", "starfive,tx-use-rgmii-clk", NULL}, |
| 31 | {"/soc/ethernet@16040000", "starfive,tx-use-rgmii-clk", NULL}, |
| 32 | |
| 33 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 34 | "motorcomm,tx-clk-adj-enabled", NULL}, |
| 35 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 36 | "motorcomm,tx-clk-100-inverted", NULL}, |
| 37 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 38 | "motorcomm,tx-clk-1000-inverted", NULL}, |
| 39 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 40 | "motorcomm,rx-clk-drv-microamp", "3970"}, |
| 41 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 42 | "motorcomm,rx-data-drv-microamp", "2910"}, |
| 43 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 44 | "rx-internal-delay-ps", "1900"}, |
| 45 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 46 | "tx-internal-delay-ps", "1500"}, |
| 47 | }; |
| 48 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 49 | static const struct starfive_vf2_pro starfive_vera[] = { |
| 50 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", "rx-internal-delay-ps", |
| 51 | "1900"}, |
| 52 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", "tx-internal-delay-ps", |
| 53 | "1350"} |
| 54 | }; |
| 55 | |
| 56 | static const struct starfive_vf2_pro starfive_verb[] = { |
| 57 | {"/soc/ethernet@16030000", "starfive,tx-use-rgmii-clk", NULL}, |
| 58 | {"/soc/ethernet@16040000", "starfive,tx-use-rgmii-clk", NULL}, |
| 59 | |
| 60 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 61 | "motorcomm,tx-clk-adj-enabled", NULL}, |
| 62 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 63 | "motorcomm,tx-clk-100-inverted", NULL}, |
| 64 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 65 | "motorcomm,tx-clk-1000-inverted", NULL}, |
| 66 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
Lukasz Tekieli | a99605d | 2024-01-28 20:22:48 +0100 | [diff] [blame] | 67 | "motorcomm,rx-clk-drv-microamp", "3970"}, |
| 68 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 69 | "motorcomm,rx-data-drv-microamp", "2910"}, |
| 70 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 71 | "rx-internal-delay-ps", "1900"}, |
| 72 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 73 | "tx-internal-delay-ps", "1500"}, |
| 74 | |
| 75 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 76 | "motorcomm,tx-clk-adj-enabled", NULL}, |
| 77 | { "/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 78 | "motorcomm,tx-clk-100-inverted", NULL}, |
| 79 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
Lukasz Tekieli | a99605d | 2024-01-28 20:22:48 +0100 | [diff] [blame] | 80 | "motorcomm,rx-clk-drv-microamp", "3970"}, |
| 81 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 82 | "motorcomm,rx-data-drv-microamp", "2910"}, |
| 83 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 84 | "rx-internal-delay-ps", "0"}, |
| 85 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 86 | "tx-internal-delay-ps", "0"}, |
| 87 | }; |
| 88 | |
H Bell | 25ce7c9 | 2024-05-22 19:12:48 +0000 | [diff] [blame] | 89 | static const struct starfive_vf2_pro star64_pine64[] = { |
| 90 | {"/soc/ethernet@16030000", "starfive,tx-use-rgmii-clk", NULL}, |
| 91 | {"/soc/ethernet@16040000", "starfive,tx-use-rgmii-clk", NULL}, |
| 92 | |
| 93 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 94 | "motorcomm,tx-clk-adj-enabled", NULL}, |
| 95 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 96 | "motorcomm,tx-clk-10-inverted", NULL}, |
| 97 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 98 | "motorcomm,tx-clk-100-inverted", NULL}, |
| 99 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 100 | "motorcomm,tx-clk-1000-inverted", NULL}, |
| 101 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 102 | "motorcomm,rx-clk-drv-microamp", "2910"}, |
| 103 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 104 | "motorcomm,rx-data-drv-microamp", "2910"}, |
| 105 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 106 | "rx-internal-delay-ps", "1900"}, |
| 107 | {"/soc/ethernet@16030000/mdio/ethernet-phy@0", |
| 108 | "tx-internal-delay-ps", "1500"}, |
| 109 | |
| 110 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 111 | "motorcomm,tx-clk-adj-enabled", NULL}, |
| 112 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 113 | "motorcomm,tx-clk-10-inverted", NULL}, |
| 114 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 115 | "motorcomm,tx-clk-100-inverted", NULL}, |
| 116 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 117 | "motorcomm,rx-clk-drv-microamp", "2910"}, |
| 118 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 119 | "motorcomm,rx-data-drv-microamp", "2910"}, |
| 120 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 121 | "rx-internal-delay-ps", "0"}, |
| 122 | {"/soc/ethernet@16040000/mdio/ethernet-phy@1", |
| 123 | "tx-internal-delay-ps", "300"}, |
| 124 | }; |
| 125 | |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 126 | void spl_fdt_fixup_mars(void *fdt) |
| 127 | { |
| 128 | static const char compat[] = "milkv,mars\0starfive,jh7110"; |
| 129 | u32 phandle; |
| 130 | u8 i; |
| 131 | int offset; |
| 132 | int ret; |
| 133 | |
| 134 | fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat)); |
| 135 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", |
| 136 | "Milk-V Mars"); |
| 137 | |
| 138 | /* gmac0 */ |
| 139 | offset = fdt_path_offset(fdt, "/soc/clock-controller@17000000"); |
| 140 | phandle = fdt_get_phandle(fdt, offset); |
| 141 | offset = fdt_path_offset(fdt, "/soc/ethernet@16030000"); |
| 142 | |
| 143 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 144 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_AONCLK_GMAC0_TX); |
| 145 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 146 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 147 | JH7110_AONCLK_GMAC0_RMII_RTX); |
| 148 | |
| 149 | /* gmac1 */ |
| 150 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/soc/ethernet@16040000"), |
| 151 | "status", "disabled"); |
| 152 | |
| 153 | for (i = 0; i < ARRAY_SIZE(milk_v_mars); i++) { |
| 154 | offset = fdt_path_offset(fdt, milk_v_mars[i].path); |
| 155 | |
| 156 | if (milk_v_mars[i].value) |
| 157 | ret = fdt_setprop_u32(fdt, offset, milk_v_mars[i].name, |
| 158 | dectoul(milk_v_mars[i].value, NULL)); |
| 159 | else |
| 160 | ret = fdt_setprop_empty(fdt, offset, milk_v_mars[i].name); |
| 161 | |
| 162 | if (ret) { |
| 163 | pr_err("%s set prop %s fail.\n", __func__, milk_v_mars[i].name); |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 169 | void spl_fdt_fixup_mars_cm(void *fdt) |
| 170 | { |
| 171 | const char *compat; |
| 172 | const char *model; |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 173 | int compat_size; |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 174 | |
| 175 | spl_fdt_fixup_mars(fdt); |
| 176 | |
| 177 | if (!get_mmc_size_from_eeprom()) { |
| 178 | int offset; |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 179 | static const char |
| 180 | compat_cm_lite[] = "milkv,mars-cm-lite\0starfive,jh7110"; |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 181 | |
| 182 | model = "Milk-V Mars CM Lite"; |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 183 | compat = compat_cm_lite; |
| 184 | compat_size = sizeof(compat_cm_lite); |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 185 | |
| 186 | offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest"); |
| 187 | /* GPIOMUX(22, GPOUT_SYS_SDIO0_RST, GPOEN_ENABLE, GPI_NONE) */ |
| 188 | fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016); |
| 189 | } else { |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 190 | static const char |
| 191 | compat_cm[] = "milkv,mars-cm\0starfive,jh7110"; |
| 192 | |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 193 | model = "Milk-V Mars CM"; |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 194 | compat = compat_cm; |
| 195 | compat_size = sizeof(compat_cm); |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 196 | } |
Heinrich Schuchardt | 4487d63 | 2024-07-20 01:11:58 +0200 | [diff] [blame] | 197 | fdt_setprop(fdt, fdt_path_offset(fdt, "/"), |
| 198 | "compatible", compat, compat_size); |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 199 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model); |
| 200 | } |
| 201 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 202 | void spl_fdt_fixup_version_a(void *fdt) |
| 203 | { |
Aurelien Jarno | 5acb7c1 | 2024-01-10 21:17:44 +0100 | [diff] [blame] | 204 | static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110"; |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 205 | u32 phandle; |
| 206 | u8 i; |
| 207 | int offset; |
| 208 | int ret; |
| 209 | |
Aurelien Jarno | 5acb7c1 | 2024-01-10 21:17:44 +0100 | [diff] [blame] | 210 | fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat)); |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 211 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", |
| 212 | "StarFive VisionFive 2 v1.2A"); |
| 213 | |
| 214 | offset = fdt_path_offset(fdt, "/soc/clock-controller@13020000"); |
| 215 | phandle = fdt_get_phandle(fdt, offset); |
| 216 | offset = fdt_path_offset(fdt, "/soc/ethernet@16040000"); |
| 217 | |
| 218 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 219 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_TX); |
| 220 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 221 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_RX); |
| 222 | |
| 223 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 224 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 225 | JH7110_SYSCLK_GMAC1_RMII_RTX); |
| 226 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 227 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 228 | JH7110_SYSCLK_GMAC1_RMII_RTX); |
| 229 | |
| 230 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/soc/ethernet@16040000"), |
| 231 | "phy-mode", "rmii"); |
| 232 | |
| 233 | for (i = 0; i < ARRAY_SIZE(starfive_vera); i++) { |
| 234 | offset = fdt_path_offset(fdt, starfive_vera[i].path); |
| 235 | |
| 236 | if (starfive_vera[i].value) |
| 237 | ret = fdt_setprop_u32(fdt, offset, starfive_vera[i].name, |
| 238 | dectoul(starfive_vera[i].value, NULL)); |
| 239 | else |
| 240 | ret = fdt_setprop_empty(fdt, offset, starfive_vera[i].name); |
| 241 | |
| 242 | if (ret) { |
| 243 | pr_err("%s set prop %s fail.\n", __func__, starfive_vera[i].name); |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | void spl_fdt_fixup_version_b(void *fdt) |
| 250 | { |
Aurelien Jarno | 5acb7c1 | 2024-01-10 21:17:44 +0100 | [diff] [blame] | 251 | static const char compat[] = "starfive,visionfive-2-v1.3b\0starfive,jh7110"; |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 252 | u32 phandle; |
| 253 | u8 i; |
| 254 | int offset; |
| 255 | int ret; |
| 256 | |
Aurelien Jarno | 5acb7c1 | 2024-01-10 21:17:44 +0100 | [diff] [blame] | 257 | fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat)); |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 258 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", |
| 259 | "StarFive VisionFive 2 v1.3B"); |
| 260 | |
| 261 | /* gmac0 */ |
| 262 | offset = fdt_path_offset(fdt, "/soc/clock-controller@17000000"); |
| 263 | phandle = fdt_get_phandle(fdt, offset); |
| 264 | offset = fdt_path_offset(fdt, "/soc/ethernet@16030000"); |
| 265 | |
| 266 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 267 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_AONCLK_GMAC0_TX); |
| 268 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 269 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 270 | JH7110_AONCLK_GMAC0_RMII_RTX); |
| 271 | |
| 272 | /* gmac1 */ |
| 273 | offset = fdt_path_offset(fdt, "/soc/clock-controller@13020000"); |
| 274 | phandle = fdt_get_phandle(fdt, offset); |
| 275 | offset = fdt_path_offset(fdt, "/soc/ethernet@16040000"); |
| 276 | |
| 277 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 278 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_TX); |
| 279 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 280 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 281 | JH7110_SYSCLK_GMAC1_RMII_RTX); |
| 282 | |
| 283 | for (i = 0; i < ARRAY_SIZE(starfive_verb); i++) { |
| 284 | offset = fdt_path_offset(fdt, starfive_verb[i].path); |
| 285 | |
| 286 | if (starfive_verb[i].value) |
| 287 | ret = fdt_setprop_u32(fdt, offset, starfive_verb[i].name, |
| 288 | dectoul(starfive_verb[i].value, NULL)); |
| 289 | else |
| 290 | ret = fdt_setprop_empty(fdt, offset, starfive_verb[i].name); |
| 291 | |
| 292 | if (ret) { |
| 293 | pr_err("%s set prop %s fail.\n", __func__, starfive_verb[i].name); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
H Bell | 25ce7c9 | 2024-05-22 19:12:48 +0000 | [diff] [blame] | 299 | void spl_fdt_fixup_star64(void *fdt) |
| 300 | { |
| 301 | static const char compat[] = "pine64,star64\0starfive,jh7110"; |
| 302 | u32 phandle; |
| 303 | u8 i; |
| 304 | int offset; |
| 305 | int ret; |
| 306 | |
| 307 | fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat)); |
| 308 | fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", |
| 309 | "Pine64 Star64"); |
| 310 | |
| 311 | /* gmac0 */ |
| 312 | offset = fdt_path_offset(fdt, "/soc/clock-controller@17000000"); |
| 313 | phandle = fdt_get_phandle(fdt, offset); |
| 314 | offset = fdt_path_offset(fdt, "/soc/ethernet@16030000"); |
| 315 | |
| 316 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 317 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_AONCLK_GMAC0_TX); |
| 318 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 319 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 320 | JH7110_AONCLK_GMAC0_RMII_RTX); |
| 321 | |
| 322 | /* gmac1 */ |
| 323 | offset = fdt_path_offset(fdt, "/soc/clock-controller@13020000"); |
| 324 | phandle = fdt_get_phandle(fdt, offset); |
| 325 | offset = fdt_path_offset(fdt, "/soc/ethernet@16040000"); |
| 326 | |
| 327 | fdt_setprop_u32(fdt, offset, "assigned-clocks", phandle); |
| 328 | fdt_appendprop_u32(fdt, offset, "assigned-clocks", JH7110_SYSCLK_GMAC1_TX); |
| 329 | fdt_setprop_u32(fdt, offset, "assigned-clock-parents", phandle); |
| 330 | fdt_appendprop_u32(fdt, offset, "assigned-clock-parents", |
| 331 | JH7110_SYSCLK_GMAC1_RMII_RTX); |
| 332 | |
| 333 | for (i = 0; i < ARRAY_SIZE(star64_pine64); i++) { |
| 334 | offset = fdt_path_offset(fdt, star64_pine64[i].path); |
| 335 | |
| 336 | if (star64_pine64[i].value) |
| 337 | ret = fdt_setprop_u32(fdt, offset, star64_pine64[i].name, |
| 338 | dectoul(star64_pine64[i].value, NULL)); |
| 339 | else |
| 340 | ret = fdt_setprop_empty(fdt, offset, star64_pine64[i].name); |
| 341 | |
| 342 | if (ret) { |
| 343 | pr_err("%s set prop %s fail.\n", __func__, star64_pine64[i].name); |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 349 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 350 | { |
| 351 | u8 version; |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 352 | const char *product_id; |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 353 | |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 354 | product_id = get_product_id_from_eeprom(); |
| 355 | if (!product_id) { |
| 356 | pr_err("Can't read EEPROM\n"); |
| 357 | return; |
| 358 | } |
Heinrich Schuchardt | adaa12d | 2024-05-12 06:25:23 +0200 | [diff] [blame] | 359 | if (!strncmp(product_id, "MARC", 4)) { |
| 360 | spl_fdt_fixup_mars_cm(spl_image->fdt_addr); |
| 361 | } else if (!strncmp(product_id, "MARS", 4)) { |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 362 | spl_fdt_fixup_mars(spl_image->fdt_addr); |
| 363 | } else if (!strncmp(product_id, "VF7110", 6)) { |
| 364 | version = get_pcb_revision_from_eeprom(); |
| 365 | switch (version) { |
| 366 | case 'a': |
| 367 | case 'A': |
| 368 | spl_fdt_fixup_version_a(spl_image->fdt_addr); |
| 369 | break; |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 370 | |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 371 | case 'b': |
| 372 | case 'B': |
| 373 | default: |
| 374 | spl_fdt_fixup_version_b(spl_image->fdt_addr); |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 375 | break; |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 376 | }; |
H Bell | 25ce7c9 | 2024-05-22 19:12:48 +0000 | [diff] [blame] | 377 | } else if (!strncmp(product_id, "STAR64", 6)) { |
| 378 | spl_fdt_fixup_star64(spl_image->fdt_addr); |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 379 | } else { |
| 380 | pr_err("Unknown product %s\n", product_id); |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 381 | }; |
| 382 | |
Heinrich Schuchardt | f884173 | 2024-04-02 10:49:10 +0200 | [diff] [blame] | 383 | /* Update the memory size which read from eeprom or DT */ |
Yanhong Wang | 4e321fa | 2023-06-15 17:36:52 +0800 | [diff] [blame] | 384 | fdt_fixup_memory(spl_image->fdt_addr, 0x40000000, gd->ram_size); |
| 385 | } |
Chanho Park | 9ca68c9 | 2023-10-31 17:56:00 +0900 | [diff] [blame] | 386 | |
| 387 | static void jh7110_jtag_init(void) |
| 388 | { |
| 389 | /* nTRST: GPIO36 */ |
| 390 | SYS_IOMUX_DOEN(36, HIGH); |
| 391 | SYS_IOMUX_DIN(36, 4); |
| 392 | /* TDI: GPIO61 */ |
| 393 | SYS_IOMUX_DOEN(61, HIGH); |
| 394 | SYS_IOMUX_DIN(61, 19); |
| 395 | /* TMS: GPIO63 */ |
| 396 | SYS_IOMUX_DOEN(63, HIGH); |
| 397 | SYS_IOMUX_DIN(63, 20); |
| 398 | /* TCK: GPIO60 */ |
| 399 | SYS_IOMUX_DOEN(60, HIGH); |
| 400 | SYS_IOMUX_DIN(60, 29); |
| 401 | /* TDO: GPIO44 */ |
| 402 | SYS_IOMUX_DOEN(44, 8); |
| 403 | SYS_IOMUX_DOUT(44, 22); |
| 404 | } |
| 405 | |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 406 | int spl_board_init_f(void) |
| 407 | { |
| 408 | int ret; |
| 409 | |
Chanho Park | 9ca68c9 | 2023-10-31 17:56:00 +0900 | [diff] [blame] | 410 | jh7110_jtag_init(); |
| 411 | |
Lukas Funke | 2b62dd6 | 2024-04-24 09:43:39 +0200 | [diff] [blame] | 412 | ret = spl_dram_init(); |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 413 | if (ret) { |
Lukas Funke | 2b62dd6 | 2024-04-24 09:43:39 +0200 | [diff] [blame] | 414 | debug("JH7110 DRAM init failed: %d\n", ret); |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 415 | return ret; |
| 416 | } |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | u32 spl_boot_device(void) |
| 422 | { |
| 423 | u32 mode; |
| 424 | |
| 425 | mode = in_le32(JH7110_BOOT_MODE_SELECT_REG) |
| 426 | & JH7110_BOOT_MODE_SELECT_MASK; |
| 427 | switch (mode) { |
| 428 | case 0: |
| 429 | return BOOT_DEVICE_SPI; |
| 430 | |
| 431 | case 1: |
| 432 | return BOOT_DEVICE_MMC2; |
| 433 | |
| 434 | case 2: |
| 435 | return BOOT_DEVICE_MMC1; |
| 436 | |
| 437 | case 3: |
| 438 | return BOOT_DEVICE_UART; |
| 439 | |
| 440 | default: |
| 441 | debug("Unsupported boot device 0x%x.\n", mode); |
| 442 | return BOOT_DEVICE_NONE; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | void board_init_f(ulong dummy) |
| 447 | { |
| 448 | int ret; |
| 449 | |
| 450 | ret = spl_early_init(); |
| 451 | if (ret) |
| 452 | panic("spl_early_init() failed: %d\n", ret); |
| 453 | |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 454 | riscv_cpu_setup(); |
Yanhong Wang | 6a5a45d | 2023-03-29 11:42:17 +0800 | [diff] [blame] | 455 | preloader_console_init(); |
| 456 | |
| 457 | /* Set the parent clock of cpu_root clock to pll0, |
| 458 | * it must be initialized here |
| 459 | */ |
| 460 | clrsetbits_le32(JH7110_SYS_CRG + JH7110_CLK_CPU_ROOT_OFFSET, |
| 461 | JH7110_CLK_CPU_ROOT_MASK, |
| 462 | BIT(JH7110_CLK_CPU_ROOT_SHIFT)); |
| 463 | |
| 464 | ret = spl_board_init_f(); |
| 465 | if (ret) { |
| 466 | debug("spl_board_init_f init failed: %d\n", ret); |
| 467 | return; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | #if CONFIG_IS_ENABLED(SPL_LOAD_FIT) |
| 472 | int board_fit_config_name_match(const char *name) |
| 473 | { |
| 474 | /* boot using first FIT config */ |
| 475 | return 0; |
| 476 | } |
| 477 | #endif |