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