]> Git Repo - J-u-boot.git/blame - board/ti/am64x/evm.c
Merge tag 'u-boot-imx-master-20250127' of https://gitlab.denx.de/u-boot/custodians...
[J-u-boot.git] / board / ti / am64x / evm.c
CommitLineData
33b72589
DG
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for AM642 EVM
4 *
7ffcff27 5 * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/
33b72589
DG
6 * Keerthy <[email protected]>
7 *
8 */
9
5b84d2de 10#include <efi_loader.h>
33b72589 11#include <asm/io.h>
7ffcff27
DG
12#include <dm/uclass.h>
13#include <k3-ddrss.h>
33b72589 14#include <spl.h>
3d16b335 15#include <fdt_support.h>
2ee76314 16#include <asm/arch/hardware.h>
2ee76314 17#include <env.h>
bc078518 18#include <asm/arch/k3-ddr.h>
2ee76314
LV
19
20#include "../common/board_detect.h"
f2c1205f 21#include "../common/fdt_ops.h"
2ee76314 22
d3c83022 23#define board_is_am64x_gpevm() (board_ti_k3_is("AM64-GPEVM") || \
9ba8187a 24 board_ti_k3_is("AM64-EVM") || \
d3c83022 25 board_ti_k3_is("AM64-HSEVM"))
8774e45e
JM
26
27#define board_is_am64x_skevm() (board_ti_k3_is("AM64-SKEVM") || \
28 board_ti_k3_is("AM64B-SKEVM"))
33b72589
DG
29
30DECLARE_GLOBAL_DATA_PTR;
31
5b84d2de
JH
32struct efi_fw_image fw_images[] = {
33 {
34 .image_type_id = AM64X_SK_TIBOOT3_IMAGE_GUID,
35 .fw_name = u"AM64X_SK_TIBOOT3",
36 .image_index = 1,
37 },
38 {
39 .image_type_id = AM64X_SK_SPL_IMAGE_GUID,
40 .fw_name = u"AM64X_SK_SPL",
41 .image_index = 2,
42 },
43 {
44 .image_type_id = AM64X_SK_UBOOT_IMAGE_GUID,
45 .fw_name = u"AM64X_SK_UBOOT",
46 .image_index = 3,
47 }
48};
49
50struct efi_capsule_update_info update_info = {
51 .dfu_string = "sf 0:0=tiboot3.bin raw 0 100000;"
52 "tispl.bin raw 100000 200000;u-boot.img raw 300000 400000",
53 .num_images = ARRAY_SIZE(fw_images),
54 .images = fw_images,
55};
56
57#if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO)
58void set_dfu_alt_info(char *interface, char *devstr)
59{
60 if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT))
61 env_set("dfu_alt_info", update_info.dfu_string);
62}
63#endif
64
33b72589
DG
65int board_init(void)
66{
67 return 0;
68}
69
33b72589
DG
70#if defined(CONFIG_SPL_LOAD_FIT)
71int board_fit_config_name_match(const char *name)
72{
63d825e9
LV
73 bool eeprom_read = board_ti_was_eeprom_read();
74
75 if (!eeprom_read || board_is_am64x_gpevm()) {
76 if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
77 return 0;
78 } else if (board_is_am64x_skevm()) {
79 if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
80 return 0;
81 }
33b72589
DG
82
83 return -1;
84}
85#endif
2ee76314 86
dac3ce97 87#if defined(CONFIG_XPL_BUILD)
7ffcff27 88#if CONFIG_IS_ENABLED(USB_STORAGE)
3d16b335
AG
89static int fixup_usb_boot(const void *fdt_blob)
90{
91 int ret = 0;
92
93 switch (spl_boot_device()) {
94 case BOOT_DEVICE_USB:
95 /*
96 * If the boot mode is host, fixup the dr_mode to host
97 * before cdns3 bind takes place
98 */
99 ret = fdt_find_and_setprop((void *)fdt_blob,
100 "/bus@f4000/cdns-usb@f900000/usb@f400000",
101 "dr_mode", "host", 5, 0);
102 if (ret)
103 printf("%s: fdt_find_and_setprop() failed:%d\n",
104 __func__, ret);
105 fallthrough;
106 default:
107 break;
108 }
109
110 return ret;
111}
7ffcff27
DG
112#endif
113
3d16b335
AG
114void spl_perform_fixups(struct spl_image_info *spl_image)
115{
bc078518
SK
116 if (IS_ENABLED(CONFIG_K3_DDRSS)) {
117 if (IS_ENABLED(CONFIG_K3_INLINE_ECC))
118 fixup_ddr_driver_for_ecc(spl_image);
119 } else {
120 fixup_memory_node(spl_image);
121 }
7ffcff27
DG
122
123#if CONFIG_IS_ENABLED(USB_STORAGE)
3d16b335 124 fixup_usb_boot(spl_image->fdt_addr);
7ffcff27 125#endif
3d16b335
AG
126}
127#endif
128
2ee76314
LV
129#ifdef CONFIG_TI_I2C_BOARD_DETECT
130int do_board_detect(void)
131{
132 int ret;
133
134 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
135 CONFIG_EEPROM_CHIP_ADDRESS);
136 if (ret) {
137 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
138 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
139 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
140 CONFIG_EEPROM_CHIP_ADDRESS + 1);
141 if (ret)
142 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
143 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
144 }
145
146 return ret;
147}
148
149int checkboard(void)
150{
151 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
152
153 if (!do_board_detect())
154 printf("Board: %s rev %s\n", ep->name, ep->version);
155
156 return 0;
157}
158
159#ifdef CONFIG_BOARD_LATE_INIT
f2c1205f 160static struct ti_fdt_map ti_am64_evm_fdt_map[] = {
9057a48a
AS
161 {"am64x_gpevm", "ti/k3-am642-evm.dtb"},
162 {"am64x_skevm", "ti/k3-am642-sk.dtb"},
f2c1205f
NM
163 { /* Sentinel. */ }
164};
165
2ee76314
LV
166static void setup_board_eeprom_env(void)
167{
168 char *name = "am64x_gpevm";
169
170 if (do_board_detect())
171 goto invalid_eeprom;
172
173 if (board_is_am64x_gpevm())
174 name = "am64x_gpevm";
175 else if (board_is_am64x_skevm())
176 name = "am64x_skevm";
177 else
178 printf("Unidentified board claims %s in eeprom header\n",
179 board_ti_get_name());
180
181invalid_eeprom:
182 set_board_info_env_am6(name);
f2c1205f 183 ti_set_fdt_env(name, ti_am64_evm_fdt_map);
2ee76314
LV
184}
185
186static void setup_serial(void)
187{
188 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
189 unsigned long board_serial;
190 char *endp;
191 char serial_string[17] = { 0 };
192
193 if (env_get("serial#"))
194 return;
195
7e5f460e 196 board_serial = hextoul(ep->serial, &endp);
2ee76314
LV
197 if (*endp != '\0') {
198 pr_err("Error: Can't set serial# to %s\n", ep->serial);
199 return;
200 }
201
202 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
203 env_set("serial#", serial_string);
204}
205#endif
206#endif
207
208#ifdef CONFIG_BOARD_LATE_INIT
209int board_late_init(void)
210{
211 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
ec658e7e
VR
212 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
213
2ee76314
LV
214 setup_board_eeprom_env();
215 setup_serial();
ec658e7e
VR
216 /*
217 * The first MAC address for ethernet a.k.a. ethernet0 comes from
218 * efuse populated via the am654 gigabit eth switch subsystem driver.
219 * All the other ones are populated via EEPROM, hence continue with
220 * an index of 1.
221 */
222 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
2ee76314
LV
223 }
224
225 return 0;
226}
227#endif
397d7b0f
AG
228
229#define CTRLMMR_USB0_PHY_CTRL 0x43004008
230#define CORE_VOLTAGE 0x80000000
231
232#ifdef CONFIG_SPL_BOARD_INIT
233void spl_board_init(void)
234{
235 u32 val;
236 /* Set USB PHY core voltage to 0.85V */
237 val = readl(CTRLMMR_USB0_PHY_CTRL);
238 val &= ~(CORE_VOLTAGE);
239 writel(val, CTRLMMR_USB0_PHY_CTRL);
70bcd249
VR
240
241 /* Init DRAM size for R5/A53 SPL */
242 dram_init_banksize();
397d7b0f
AG
243}
244#endif
This page took 0.207617 seconds and 5 git commands to generate.