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 | * |
| 5 | * Copyright (C) 2021 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * David Huang <d-huang@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <env.h> |
| 12 | #include <fdt_support.h> |
| 13 | #include <generic-phy.h> |
| 14 | #include <image.h> |
| 15 | #include <init.h> |
| 16 | #include <log.h> |
| 17 | #include <net.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/arch/hardware.h> |
| 20 | #include <asm/gpio.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <spl.h> |
| 23 | #include <asm/arch/sys_proto.h> |
| 24 | #include <dm.h> |
| 25 | #include <dm/uclass-internal.h> |
Sinthu Raja | e0b4e95 | 2023-01-10 21:17:54 +0530 | [diff] [blame^] | 26 | #include <dm/root.h> |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 27 | |
| 28 | #include "../common/board_detect.h" |
| 29 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
| 32 | int board_init(void) |
| 33 | { |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | int dram_init(void) |
| 38 | { |
| 39 | #ifdef CONFIG_PHYS_64BIT |
| 40 | gd->ram_size = 0x100000000; |
| 41 | #else |
| 42 | gd->ram_size = 0x80000000; |
| 43 | #endif |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
Pali Rohár | 4f4f583 | 2022-09-09 17:32:40 +0200 | [diff] [blame] | 48 | phys_size_t board_get_usable_ram_top(phys_size_t total_size) |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 49 | { |
| 50 | #ifdef CONFIG_PHYS_64BIT |
| 51 | /* Limit RAM used by U-Boot to the DDR low region */ |
| 52 | if (gd->ram_top > 0x100000000) |
| 53 | return 0x100000000; |
| 54 | #endif |
| 55 | |
| 56 | return gd->ram_top; |
| 57 | } |
| 58 | |
| 59 | int dram_init_banksize(void) |
| 60 | { |
| 61 | /* Bank 0 declares the memory available in the DDR low region */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 62 | gd->bd->bi_dram[0].start = CFG_SYS_SDRAM_BASE; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 63 | gd->bd->bi_dram[0].size = 0x7fffffff; |
| 64 | gd->ram_size = 0x80000000; |
| 65 | |
| 66 | #ifdef CONFIG_PHYS_64BIT |
| 67 | /* Bank 1 declares the memory available in the DDR high region */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 68 | gd->bd->bi_dram[1].start = CFG_SYS_SDRAM_BASE1; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 69 | gd->bd->bi_dram[1].size = 0x37fffffff; |
| 70 | gd->ram_size = 0x400000000; |
| 71 | #endif |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 76 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
| 77 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 78 | { |
| 79 | int ret; |
| 80 | |
| 81 | ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000"); |
| 82 | if (ret < 0) |
| 83 | ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", |
| 84 | "sram@70000000"); |
| 85 | if (ret) |
| 86 | printf("%s: fixing up msmc ram failed %d\n", __func__, ret); |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
Sinthu Raja | c38cbf2 | 2023-01-10 21:17:50 +0530 | [diff] [blame] | 93 | /* |
| 94 | * Functions specific to EVM and SK designs of J721S2/AM68 family. |
| 95 | */ |
| 96 | |
| 97 | #define board_is_j721s2_som() board_ti_k3_is("J721S2X-PM1-SOM") |
| 98 | |
| 99 | #define board_is_am68_sk_som() board_ti_k3_is("AM68-SK-SOM") |
| 100 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 101 | int do_board_detect(void) |
| 102 | { |
| 103 | int ret; |
| 104 | |
Sinthu Raja | 82407f6 | 2023-01-10 21:17:52 +0530 | [diff] [blame] | 105 | if (board_ti_was_eeprom_read()) |
| 106 | return 0; |
| 107 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 108 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 109 | CONFIG_EEPROM_CHIP_ADDRESS); |
Sinthu Raja | 149ce99 | 2023-01-10 21:17:51 +0530 | [diff] [blame] | 110 | if (ret) { |
| 111 | printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n", |
| 112 | CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 113 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 114 | CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 115 | if (ret) |
| 116 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 117 | CONFIG_EEPROM_CHIP_ADDRESS + 1, ret); |
| 118 | } |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | int checkboard(void) |
| 124 | { |
| 125 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 126 | |
| 127 | if (do_board_detect()) |
| 128 | /* EEPROM not populated */ |
| 129 | printf("Board: %s rev %s\n", "J721S2X-PM1-SOM", "E1"); |
| 130 | else |
| 131 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static void setup_board_eeprom_env(void) |
| 137 | { |
| 138 | char *name = "j721s2"; |
| 139 | |
| 140 | if (do_board_detect()) |
| 141 | goto invalid_eeprom; |
| 142 | |
| 143 | if (board_is_j721s2_som()) |
| 144 | name = "j721s2"; |
Sinthu Raja | c38cbf2 | 2023-01-10 21:17:50 +0530 | [diff] [blame] | 145 | else if (board_is_am68_sk_som()) |
| 146 | name = "am68-sk"; |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 147 | else |
| 148 | printf("Unidentified board claims %s in eeprom header\n", |
| 149 | board_ti_get_name()); |
| 150 | |
| 151 | invalid_eeprom: |
| 152 | set_board_info_env_am6(name); |
| 153 | } |
| 154 | |
| 155 | static void setup_serial(void) |
| 156 | { |
| 157 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 158 | unsigned long board_serial; |
| 159 | char *endp; |
| 160 | char serial_string[17] = { 0 }; |
| 161 | |
| 162 | if (env_get("serial#")) |
| 163 | return; |
| 164 | |
| 165 | board_serial = simple_strtoul(ep->serial, &endp, 16); |
| 166 | if (*endp != '\0') { |
| 167 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 168 | return; |
| 169 | } |
| 170 | |
| 171 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 172 | env_set("serial#", serial_string); |
| 173 | } |
| 174 | #endif |
| 175 | |
Sinthu Raja | 82407f6 | 2023-01-10 21:17:52 +0530 | [diff] [blame] | 176 | /* |
| 177 | * This function chooses the right dtb based on the board name read from |
| 178 | * EEPROM if the EEPROM is programmed. Also, by default the boot chooses |
| 179 | * the EVM DTB if there is no EEPROM is programmed or not detected. |
| 180 | */ |
| 181 | #ifdef CONFIG_SPL_LOAD_FIT |
| 182 | int board_fit_config_name_match(const char *name) |
| 183 | { |
| 184 | bool eeprom_read = board_ti_was_eeprom_read(); |
| 185 | |
| 186 | if (!eeprom_read || board_is_j721s2_som()) { |
| 187 | if (!strcmp(name, "k3-j721s2-common-proc-board")) |
| 188 | return 0; |
| 189 | } else if (!eeprom_read || board_is_am68_sk_som()) { |
| 190 | if (!strcmp(name, "k3-am68-sk-base-board")) |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | return -1; |
| 195 | } |
| 196 | #endif |
| 197 | |
David Huang | d09f5fe | 2022-01-25 20:56:37 +0530 | [diff] [blame] | 198 | int board_late_init(void) |
| 199 | { |
| 200 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
| 201 | setup_board_eeprom_env(); |
| 202 | setup_serial(); |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | void spl_board_init(void) |
| 209 | { |
| 210 | } |
Sinthu Raja | e0b4e95 | 2023-01-10 21:17:54 +0530 | [diff] [blame^] | 211 | |
| 212 | /* Support for the various EVM / SK families */ |
| 213 | #if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT) |
| 214 | void do_dt_magic(void) |
| 215 | { |
| 216 | int ret, rescan, mmc_dev = -1; |
| 217 | static struct mmc *mmc; |
| 218 | |
| 219 | do_board_detect(); |
| 220 | |
| 221 | /* |
| 222 | * Board detection has been done. |
| 223 | * Let us see if another dtb wouldn't be a better match |
| 224 | * for our board |
| 225 | */ |
| 226 | if (IS_ENABLED(CONFIG_CPU_V7R)) { |
| 227 | ret = fdtdec_resetup(&rescan); |
| 228 | if (!ret && rescan) { |
| 229 | dm_uninit(); |
| 230 | dm_init_and_scan(true); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Because of multi DTB configuration, the MMC device has |
| 236 | * to be re-initialized after reconfiguring FDT inorder to |
| 237 | * boot from MMC. Do this when boot mode is MMC and ROM has |
| 238 | * not loaded SYSFW. |
| 239 | */ |
| 240 | switch (spl_boot_device()) { |
| 241 | case BOOT_DEVICE_MMC1: |
| 242 | mmc_dev = 0; |
| 243 | break; |
| 244 | case BOOT_DEVICE_MMC2: |
| 245 | case BOOT_DEVICE_MMC2_2: |
| 246 | mmc_dev = 1; |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | if (mmc_dev > 0 && !check_rom_loaded_sysfw()) { |
| 251 | ret = mmc_init_device(mmc_dev); |
| 252 | if (!ret) { |
| 253 | mmc = find_mmc_device(mmc_dev); |
| 254 | if (mmc) { |
| 255 | ret = mmc_init(mmc); |
| 256 | if (ret) |
| 257 | printf("mmc init failed with error: %d\n", ret); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | #endif |
| 263 | |
| 264 | #ifdef CONFIG_SPL_BUILD |
| 265 | void board_init_f(ulong dummy) |
| 266 | { |
| 267 | k3_spl_init(); |
| 268 | #if defined(CONFIG_SPL_OF_LIST) && defined(CONFIG_TI_I2C_BOARD_DETECT) |
| 269 | do_dt_magic(); |
| 270 | #endif |
| 271 | k3_mem_init(); |
| 272 | } |
| 273 | #endif |