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