Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Board specific initialization for AM642 EVM |
| 4 | * |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 5 | * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/ |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 6 | * Keerthy <j-keerthy@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/io.h> |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 12 | #include <dm/uclass.h> |
| 13 | #include <k3-ddrss.h> |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 14 | #include <spl.h> |
Aswath Govindraju | e910fac | 2021-08-04 18:42:44 +0530 | [diff] [blame] | 15 | #include <fdt_support.h> |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 16 | #include <asm/arch/hardware.h> |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 17 | #include <env.h> |
| 18 | |
| 19 | #include "../common/board_detect.h" |
| 20 | |
Roger Quadros | 70b26c9 | 2023-08-05 11:14:37 +0300 | [diff] [blame] | 21 | #define board_is_am64x_gpevm() (board_ti_k3_is("AM64-GPEVM") || \ |
| 22 | board_ti_k3_is("AM64-HSEVM")) |
Judith Mendez | de35c3a | 2023-04-06 11:49:01 +0530 | [diff] [blame] | 23 | |
| 24 | #define board_is_am64x_skevm() (board_ti_k3_is("AM64-SKEVM") || \ |
| 25 | board_ti_k3_is("AM64B-SKEVM")) |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
| 29 | int board_init(void) |
| 30 | { |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | int dram_init(void) |
| 35 | { |
Dave Gerlach | 88107fe | 2022-03-17 12:03:40 -0500 | [diff] [blame] | 36 | s32 ret; |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 37 | |
Dave Gerlach | 88107fe | 2022-03-17 12:03:40 -0500 | [diff] [blame] | 38 | ret = fdtdec_setup_mem_size_base(); |
| 39 | if (ret) |
| 40 | printf("Error setting up mem size and base. %d\n", ret); |
| 41 | |
| 42 | return ret; |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | int dram_init_banksize(void) |
| 46 | { |
Dave Gerlach | 88107fe | 2022-03-17 12:03:40 -0500 | [diff] [blame] | 47 | s32 ret; |
| 48 | |
| 49 | ret = fdtdec_setup_memory_banksize(); |
| 50 | if (ret) |
| 51 | printf("Error setting up memory banksize. %d\n", ret); |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 52 | |
Dave Gerlach | 88107fe | 2022-03-17 12:03:40 -0500 | [diff] [blame] | 53 | return ret; |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | #if defined(CONFIG_SPL_LOAD_FIT) |
| 57 | int board_fit_config_name_match(const char *name) |
| 58 | { |
Lokesh Vutla | 8af2b69 | 2021-05-06 16:44:51 +0530 | [diff] [blame] | 59 | bool eeprom_read = board_ti_was_eeprom_read(); |
| 60 | |
| 61 | if (!eeprom_read || board_is_am64x_gpevm()) { |
| 62 | if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm")) |
| 63 | return 0; |
| 64 | } else if (board_is_am64x_skevm()) { |
| 65 | if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk")) |
| 66 | return 0; |
| 67 | } |
Dave Gerlach | 3dc33f1 | 2021-04-23 11:27:42 -0500 | [diff] [blame] | 68 | |
| 69 | return -1; |
| 70 | } |
| 71 | #endif |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 72 | |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 73 | #if defined(CONFIG_SPL_BUILD) |
| 74 | #if CONFIG_IS_ENABLED(USB_STORAGE) |
Aswath Govindraju | e910fac | 2021-08-04 18:42:44 +0530 | [diff] [blame] | 75 | static int fixup_usb_boot(const void *fdt_blob) |
| 76 | { |
| 77 | int ret = 0; |
| 78 | |
| 79 | switch (spl_boot_device()) { |
| 80 | case BOOT_DEVICE_USB: |
| 81 | /* |
| 82 | * If the boot mode is host, fixup the dr_mode to host |
| 83 | * before cdns3 bind takes place |
| 84 | */ |
| 85 | ret = fdt_find_and_setprop((void *)fdt_blob, |
| 86 | "/bus@f4000/cdns-usb@f900000/usb@f400000", |
| 87 | "dr_mode", "host", 5, 0); |
| 88 | if (ret) |
| 89 | printf("%s: fdt_find_and_setprop() failed:%d\n", |
| 90 | __func__, ret); |
| 91 | fallthrough; |
| 92 | default: |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | return ret; |
| 97 | } |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | #if defined(CONFIG_K3_AM64_DDRSS) |
| 101 | static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image) |
| 102 | { |
| 103 | struct udevice *dev; |
| 104 | int ret; |
| 105 | |
| 106 | dram_init_banksize(); |
| 107 | |
| 108 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
| 109 | if (ret) |
| 110 | panic("Cannot get RAM device for ddr size fixup: %d\n", ret); |
| 111 | |
| 112 | ret = k3_ddrss_ddr_fdt_fixup(dev, spl_image->fdt_addr, gd->bd); |
| 113 | if (ret) |
| 114 | printf("Error fixing up ddr node for ECC use! %d\n", ret); |
| 115 | } |
| 116 | #else |
| 117 | static void fixup_memory_node(struct spl_image_info *spl_image) |
| 118 | { |
| 119 | u64 start[CONFIG_NR_DRAM_BANKS]; |
| 120 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 121 | int bank; |
| 122 | int ret; |
| 123 | |
| 124 | dram_init(); |
| 125 | dram_init_banksize(); |
| 126 | |
| 127 | for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) { |
| 128 | start[bank] = gd->bd->bi_dram[bank].start; |
| 129 | size[bank] = gd->bd->bi_dram[bank].size; |
| 130 | } |
| 131 | |
| 132 | /* dram_init functions use SPL fdt, and we must fixup u-boot fdt */ |
| 133 | ret = fdt_fixup_memory_banks(spl_image->fdt_addr, start, size, CONFIG_NR_DRAM_BANKS); |
| 134 | if (ret) |
| 135 | printf("Error fixing up memory node! %d\n", ret); |
| 136 | } |
| 137 | #endif |
Aswath Govindraju | e910fac | 2021-08-04 18:42:44 +0530 | [diff] [blame] | 138 | |
| 139 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 140 | { |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 141 | #if defined(CONFIG_K3_AM64_DDRSS) |
| 142 | fixup_ddr_driver_for_ecc(spl_image); |
| 143 | #else |
| 144 | fixup_memory_node(spl_image); |
| 145 | #endif |
| 146 | |
| 147 | #if CONFIG_IS_ENABLED(USB_STORAGE) |
Aswath Govindraju | e910fac | 2021-08-04 18:42:44 +0530 | [diff] [blame] | 148 | fixup_usb_boot(spl_image->fdt_addr); |
Dave Gerlach | 10498d1 | 2022-03-17 12:03:44 -0500 | [diff] [blame] | 149 | #endif |
Aswath Govindraju | e910fac | 2021-08-04 18:42:44 +0530 | [diff] [blame] | 150 | } |
| 151 | #endif |
| 152 | |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 153 | #ifdef CONFIG_TI_I2C_BOARD_DETECT |
| 154 | int do_board_detect(void) |
| 155 | { |
| 156 | int ret; |
| 157 | |
| 158 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 159 | CONFIG_EEPROM_CHIP_ADDRESS); |
| 160 | if (ret) { |
| 161 | printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n", |
| 162 | CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 163 | ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS, |
| 164 | CONFIG_EEPROM_CHIP_ADDRESS + 1); |
| 165 | if (ret) |
| 166 | pr_err("Reading on-board EEPROM at 0x%02x failed %d\n", |
| 167 | CONFIG_EEPROM_CHIP_ADDRESS + 1, ret); |
| 168 | } |
| 169 | |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | int checkboard(void) |
| 174 | { |
| 175 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 176 | |
| 177 | if (!do_board_detect()) |
| 178 | printf("Board: %s rev %s\n", ep->name, ep->version); |
| 179 | |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | #ifdef CONFIG_BOARD_LATE_INIT |
| 184 | static void setup_board_eeprom_env(void) |
| 185 | { |
| 186 | char *name = "am64x_gpevm"; |
| 187 | |
| 188 | if (do_board_detect()) |
| 189 | goto invalid_eeprom; |
| 190 | |
| 191 | if (board_is_am64x_gpevm()) |
| 192 | name = "am64x_gpevm"; |
| 193 | else if (board_is_am64x_skevm()) |
| 194 | name = "am64x_skevm"; |
| 195 | else |
| 196 | printf("Unidentified board claims %s in eeprom header\n", |
| 197 | board_ti_get_name()); |
| 198 | |
| 199 | invalid_eeprom: |
| 200 | set_board_info_env_am6(name); |
| 201 | } |
| 202 | |
| 203 | static void setup_serial(void) |
| 204 | { |
| 205 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 206 | unsigned long board_serial; |
| 207 | char *endp; |
| 208 | char serial_string[17] = { 0 }; |
| 209 | |
| 210 | if (env_get("serial#")) |
| 211 | return; |
| 212 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 213 | board_serial = hextoul(ep->serial, &endp); |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 214 | if (*endp != '\0') { |
| 215 | pr_err("Error: Can't set serial# to %s\n", ep->serial); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial); |
| 220 | env_set("serial#", serial_string); |
| 221 | } |
| 222 | #endif |
| 223 | #endif |
| 224 | |
| 225 | #ifdef CONFIG_BOARD_LATE_INIT |
| 226 | int board_late_init(void) |
| 227 | { |
| 228 | if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) { |
Vignesh Raghavendra | 3349e21 | 2021-05-10 23:44:22 +0530 | [diff] [blame] | 229 | struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA; |
| 230 | |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 231 | setup_board_eeprom_env(); |
| 232 | setup_serial(); |
Vignesh Raghavendra | 3349e21 | 2021-05-10 23:44:22 +0530 | [diff] [blame] | 233 | /* |
| 234 | * The first MAC address for ethernet a.k.a. ethernet0 comes from |
| 235 | * efuse populated via the am654 gigabit eth switch subsystem driver. |
| 236 | * All the other ones are populated via EEPROM, hence continue with |
| 237 | * an index of 1. |
| 238 | */ |
| 239 | board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt); |
Lokesh Vutla | 01032a4 | 2021-05-06 16:44:49 +0530 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | #endif |
Aswath Govindraju | cb962f9 | 2021-06-04 22:00:34 +0530 | [diff] [blame] | 245 | |
| 246 | #define CTRLMMR_USB0_PHY_CTRL 0x43004008 |
| 247 | #define CORE_VOLTAGE 0x80000000 |
| 248 | |
| 249 | #ifdef CONFIG_SPL_BOARD_INIT |
| 250 | void spl_board_init(void) |
| 251 | { |
| 252 | u32 val; |
| 253 | /* Set USB PHY core voltage to 0.85V */ |
| 254 | val = readl(CTRLMMR_USB0_PHY_CTRL); |
| 255 | val &= ~(CORE_VOLTAGE); |
| 256 | writel(val, CTRLMMR_USB0_PHY_CTRL); |
Vignesh Raghavendra | dfcda51 | 2021-12-24 12:55:31 +0530 | [diff] [blame] | 257 | |
| 258 | /* Init DRAM size for R5/A53 SPL */ |
| 259 | dram_init_banksize(); |
Aswath Govindraju | cb962f9 | 2021-06-04 22:00:34 +0530 | [diff] [blame] | 260 | } |
| 261 | #endif |