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