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