David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for J721S2 EVM |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 6 | * David Huang <d-huang@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 10 | #include <env.h> |
| 11 | #include <fdt_support.h> |
| 12 | #include <generic-phy.h> |
| 13 | #include <image.h> |
| 14 | #include <init.h> |
| 15 | #include <log.h> |
| 16 | #include <net.h> |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 17 | #include <asm/arch/hardware.h> |
| 18 | #include <asm/gpio.h> |
| 19 | #include <asm/io.h> |
| 20 | #include <spl.h> |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 21 | #include <dm.h> |
| 22 | #include <dm/uclass-internal.h> |
Sinthu Raja | e0b4e95 | 2023-01-10 21:17:54 +0530 | [diff] [blame] | 23 | #include <dm/root.h> |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 24 | |
| 25 | #include "../common/board_detect.h" |
Nishanth Menon | b704d93 | 2024-02-12 13:47:23 -0600 | [diff] [blame] | 26 | #include "../common/fdt_ops.h" |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 27 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | int board_init(void) |
| 31 | { |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | int dram_init(void) |
| 36 | { |
| 37 | #ifdef CONFIG_PHYS_64BIT |
| 38 | gd->ram_size = 0x100000000; |
| 39 | #else |
| 40 | gd->ram_size = 0x80000000; |
| 41 | #endif |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Heinrich Schuchardt | 51a9aac | 2023-08-12 20:16:58 +0200 | [diff] [blame] | 46 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 47 | { |
| 48 | #ifdef CONFIG_PHYS_64BIT |
| 49 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 50 | if (gd->ram_top > 0x100000000) |
| 51 | return 0x100000000; |
| 52 | #endif |
| 53 | |
| 54 | return gd->ram_top; |
| 55 | } |
| 56 | |
| 57 | int dram_init_banksize(void) |
| 58 | { |
| 59 | /* Bank 0 declares the memory available in the DDR low region */ |
Andrew Davis | ff64dc2 | 2023-11-30 08:49:11 -0600 | [diff] [blame] | 60 | gd->bd->bi_dram[0].start = 0x80000000; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 61 | gd->bd->bi_dram[0].size = 0x7fffffff; |
| 62 | gd->ram_size = 0x80000000; |
| 63 | |
| 64 | #ifdef CONFIG_PHYS_64BIT |
| 65 | /* Bank 1 declares the memory available in the DDR high region */ |
Andrew Davis | ff64dc2 | 2023-11-30 08:49:11 -0600 | [diff] [blame] | 66 | gd->bd->bi_dram[1].start = 0x880000000; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 67 | gd->bd->bi_dram[1].size = 0x37fffffff; |
| 68 | gd->ram_size = 0x400000000; |
| 69 | #endif |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 74 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
Sinthu Raja | c38cbf2 | 2023-01-10 21:17:50 +0530 | [diff] [blame] | 75 | /* |
| 76 | * Functions specific to EVM and SK designs of J721S2/AM68 family. |
| 77 | */ |
| 78 | |
| 79 | #define board_is_j721s2_som() board_ti_k3_is("J721S2X-PM1-SOM") |
| 80 | |
| 81 | #define board_is_am68_sk_som() board_ti_k3_is("AM68-SK-SOM") |
| 82 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 83 | int do_board_detect(void) |
| 84 | { |
| 85 | int ret; |
| 86 | |
Sinthu Raja | 82407f6 | 2023-01-10 21:17:52 +0530 | [diff] [blame] | 87 | if (board_ti_was_eeprom_read()) |
| 88 | return 0; |
| 89 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 90 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 91 | CONFIG_EEPROM_CHIP_ADDRESS); |
Sinthu Raja | 149ce99 | 2023-01-10 21:17:51 +0530 | [diff] [blame] | 92 | if (ret) { |
| 93 | printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n", |
| 94 | CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 95 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 96 | CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 97 | if (ret) |
| 98 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 99 | CONFIG_EEPROM_CHIP_ADDRESS + 1, ret); |
| 100 | } |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 101 | |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | int checkboard(void) |
| 106 | { |
| 107 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 108 | |
| 109 | if (do_board_detect()) |
| 110 | /* EEPROM not populated */ |
| 111 | printf("Board: %s rev %s\n", "J721S2X-PM1-SOM", "E1"); |
| 112 | else |
| 113 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
Nishanth Menon | b704d93 | 2024-02-12 13:47:23 -0600 | [diff] [blame] | 118 | static struct ti_fdt_map ti_j721s2_evm_fdt_map[] = { |
| 119 | {"j721s2", "k3-j721s2-common-proc-board.dtb"}, |
| 120 | {"am68-sk", "k3-am68-sk-base-board.dtb"}, |
| 121 | { /* Sentinel. */ } |
| 122 | }; |
| 123 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 124 | static void setup_board_eeprom_env(void) |
| 125 | { |
| 126 | char *name = "j721s2"; |
| 127 | |
| 128 | if (do_board_detect()) |
| 129 | goto invalid_eeprom; |
| 130 | |
| 131 | if (board_is_j721s2_som()) |
| 132 | name = "j721s2"; |
Sinthu Raja | c38cbf2 | 2023-01-10 21:17:50 +0530 | [diff] [blame] | 133 | else if (board_is_am68_sk_som()) |
| 134 | name = "am68-sk"; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 135 | else |
| 136 | printf("Unidentified board claims %s in eeprom header\n", |
| 137 | board_ti_get_name()); |
| 138 | |
| 139 | invalid_eeprom: |
| 140 | set_board_info_env_am6(name); |
Nishanth Menon | b704d93 | 2024-02-12 13:47:23 -0600 | [diff] [blame] | 141 | ti_set_fdt_env(name, ti_j721s2_evm_fdt_map); |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void setup_serial(void) |
| 145 | { |
| 146 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 147 | unsigned long board_serial; |
| 148 | char *endp; |
| 149 | char serial_string[17] = { 0 }; |
| 150 | |
| 151 | if (env_get("serial#")) |
| 152 | return; |
| 153 | |
| 154 | board_serial = simple_strtoul(ep->serial, &endp, 16); |
| 155 | if (*endp != '\0') { |
| 156 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 161 | env_set("serial#", serial_string); |
| 162 | } |
Kishon Vijay Abraham I | 83aa7eb | 2023-04-10 11:40:15 +0530 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Declaration of daughtercards to probe. Note that when adding more |
| 166 | * cards they should be grouped by the 'i2c_addr' field to allow for a |
| 167 | * more efficient probing process. |
| 168 | */ |
| 169 | static const struct { |
| 170 | u8 i2c_addr; /* I2C address of card EEPROM */ |
| 171 | char *card_name; /* EEPROM-programmed card name */ |
| 172 | char *dtbo_name; /* Device tree overlay to apply */ |
| 173 | u8 eth_offset; /* ethXaddr MAC address index offset */ |
| 174 | } ext_cards[] = { |
| 175 | { |
| 176 | 0x52, |
| 177 | "J7X-GESI-EXP", |
| 178 | "k3-j721s2-gesi-exp-board.dtbo", |
| 179 | 1, /* Start populating from eth1addr */ |
| 180 | }, |
| 181 | }; |
| 182 | |
| 183 | #define DAUGHTER_CARD_NO_OF_MAC_ADDR 5 |
| 184 | static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)]; |
| 185 | |
| 186 | static int probe_daughtercards(void) |
| 187 | { |
| 188 | char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN]; |
| 189 | bool eeprom_read_success; |
| 190 | struct ti_am6_eeprom ep; |
| 191 | u8 previous_i2c_addr; |
| 192 | u8 mac_addr_cnt; |
| 193 | int i; |
| 194 | int ret; |
| 195 | |
| 196 | /* Mark previous I2C address variable as not populated */ |
| 197 | previous_i2c_addr = 0xff; |
| 198 | |
| 199 | /* No EEPROM data was read yet */ |
| 200 | eeprom_read_success = false; |
| 201 | |
| 202 | /* Iterate through list of daughtercards */ |
| 203 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 204 | /* Obtain card-specific I2C address */ |
| 205 | u8 i2c_addr = ext_cards[i].i2c_addr; |
| 206 | |
| 207 | /* Read card EEPROM if not already read previously */ |
| 208 | if (i2c_addr != previous_i2c_addr) { |
| 209 | /* Store I2C address so we can avoid reading twice */ |
| 210 | previous_i2c_addr = i2c_addr; |
| 211 | |
| 212 | /* Get and parse the daughter card EEPROM record */ |
| 213 | ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, |
| 214 | i2c_addr, |
| 215 | &ep, |
| 216 | (char **)mac_addr, |
| 217 | DAUGHTER_CARD_NO_OF_MAC_ADDR, |
| 218 | &mac_addr_cnt); |
| 219 | if (ret) { |
| 220 | debug("%s: No daughtercard EEPROM at 0x%02x found %d\n", |
| 221 | __func__, i2c_addr, ret); |
| 222 | eeprom_read_success = false; |
| 223 | /* Skip to the next daughtercard to probe */ |
| 224 | continue; |
| 225 | } |
| 226 | |
| 227 | /* EEPROM read successful, okay to further process. */ |
| 228 | eeprom_read_success = true; |
| 229 | } |
| 230 | |
| 231 | /* Only continue processing if EEPROM data was read */ |
| 232 | if (!eeprom_read_success) |
| 233 | continue; |
| 234 | |
| 235 | /* Only process the parsed data if we found a match */ |
| 236 | if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name))) |
| 237 | continue; |
| 238 | |
| 239 | printf("Detected: %s rev %s\n", ep.name, ep.version); |
| 240 | daughter_card_detect_flags[i] = true; |
| 241 | |
| 242 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 243 | int j; |
| 244 | /* |
| 245 | * Populate any MAC addresses from daughtercard into the U-Boot |
| 246 | * environment, starting with a card-specific offset so we can |
| 247 | * have multiple ext_cards contribute to the MAC pool in a well- |
| 248 | * defined manner. |
| 249 | */ |
| 250 | for (j = 0; j < mac_addr_cnt; j++) { |
| 251 | if (!is_valid_ethaddr((u8 *)mac_addr[j])) |
| 252 | continue; |
| 253 | |
| 254 | eth_env_set_enetaddr_by_index("eth", ext_cards[i].eth_offset + j, |
| 255 | (uchar *)mac_addr[j]); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | if (!IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 261 | char name_overlays[1024] = { 0 }; |
| 262 | |
| 263 | for (i = 0; i < ARRAY_SIZE(ext_cards); i++) { |
| 264 | if (!daughter_card_detect_flags[i]) |
| 265 | continue; |
| 266 | |
| 267 | /* Skip if no overlays are to be added */ |
| 268 | if (!strlen(ext_cards[i].dtbo_name)) |
| 269 | continue; |
| 270 | |
| 271 | /* |
| 272 | * Make sure we are not running out of buffer space by checking |
| 273 | * if we can fit the new overlay, a trailing space to be used |
| 274 | * as a separator, plus the terminating zero. |
| 275 | */ |
| 276 | if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 > |
| 277 | sizeof(name_overlays)) |
| 278 | return -ENOMEM; |
| 279 | |
| 280 | /* Append to our list of overlays */ |
| 281 | strcat(name_overlays, ext_cards[i].dtbo_name); |
| 282 | strcat(name_overlays, " "); |
| 283 | } |
| 284 | |
| 285 | /* Apply device tree overlay(s) to the U-Boot environment, if any */ |
| 286 | if (strlen(name_overlays)) |
| 287 | return env_set("name_overlays", name_overlays); |
| 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 292 | #endif |
| 293 | |
Sinthu Raja | 82407f6 | 2023-01-10 21:17:52 +0530 | [diff] [blame] | 294 | /* |
| 295 | * This function chooses the right dtb based on the board name read from |
| 296 | * EEPROM if the EEPROM is programmed. Also, by default the boot chooses |
| 297 | * the EVM DTB if there is no EEPROM is programmed or not detected. |
| 298 | */ |
| 299 | #ifdef CONFIG_SPL_LOAD_FIT |
| 300 | int board_fit_config_name_match(const char *name) |
| 301 | { |
| 302 | bool eeprom_read = board_ti_was_eeprom_read(); |
| 303 | |
| 304 | if (!eeprom_read || board_is_j721s2_som()) { |
| 305 | if (!strcmp(name, "k3-j721s2-common-proc-board")) |
| 306 | return 0; |
| 307 | } else if (!eeprom_read || board_is_am68_sk_som()) { |
| 308 | if (!strcmp(name, "k3-am68-sk-base-board")) |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | return -1; |
| 313 | } |
| 314 | #endif |
| 315 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 316 | int board_late_init(void) |
| 317 | { |
| 318 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 319 | setup_board_eeprom_env(); |
| 320 | setup_serial(); |
Kishon Vijay Abraham I | 83aa7eb | 2023-04-10 11:40:15 +0530 | [diff] [blame] | 321 | probe_daughtercards(); |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | void spl_board_init(void) |
| 328 | { |
| 329 | } |