blob: 609e5cf6d51f7c010a72c2b00c94296fc6fb0127 [file] [log] [blame]
Dave Gerlach3dc33f12021-04-23 11:27:42 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for AM642 EVM
4 *
Dave Gerlach10498d12022-03-17 12:03:44 -05005 * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/
Dave Gerlach3dc33f12021-04-23 11:27:42 -05006 * Keerthy <j-keerthy@ti.com>
7 *
8 */
9
Jonathan Humphreyse347ac02024-06-14 11:35:31 -050010#include <efi_loader.h>
Dave Gerlach3dc33f12021-04-23 11:27:42 -050011#include <asm/io.h>
Dave Gerlach10498d12022-03-17 12:03:44 -050012#include <dm/uclass.h>
13#include <k3-ddrss.h>
Dave Gerlach3dc33f12021-04-23 11:27:42 -050014#include <spl.h>
Aswath Govindrajue910fac2021-08-04 18:42:44 +053015#include <fdt_support.h>
Lokesh Vutla01032a42021-05-06 16:44:49 +053016#include <asm/arch/hardware.h>
Lokesh Vutla01032a42021-05-06 16:44:49 +053017#include <env.h>
18
19#include "../common/board_detect.h"
Nishanth Menon0822cd62024-02-12 13:47:20 -060020#include "../common/fdt_ops.h"
Lokesh Vutla01032a42021-05-06 16:44:49 +053021
Roger Quadros70b26c92023-08-05 11:14:37 +030022#define board_is_am64x_gpevm() (board_ti_k3_is("AM64-GPEVM") || \
Roger Quadros81ed4c82024-01-08 15:16:50 +020023 board_ti_k3_is("AM64-EVM") || \
Roger Quadros70b26c92023-08-05 11:14:37 +030024 board_ti_k3_is("AM64-HSEVM"))
Judith Mendezde35c3a2023-04-06 11:49:01 +053025
26#define board_is_am64x_skevm() (board_ti_k3_is("AM64-SKEVM") || \
27 board_ti_k3_is("AM64B-SKEVM"))
Dave Gerlach3dc33f12021-04-23 11:27:42 -050028
29DECLARE_GLOBAL_DATA_PTR;
30
Jonathan Humphreyse347ac02024-06-14 11:35:31 -050031struct efi_fw_image fw_images[] = {
32 {
33 .image_type_id = AM64X_SK_TIBOOT3_IMAGE_GUID,
34 .fw_name = u"AM64X_SK_TIBOOT3",
35 .image_index = 1,
36 },
37 {
38 .image_type_id = AM64X_SK_SPL_IMAGE_GUID,
39 .fw_name = u"AM64X_SK_SPL",
40 .image_index = 2,
41 },
42 {
43 .image_type_id = AM64X_SK_UBOOT_IMAGE_GUID,
44 .fw_name = u"AM64X_SK_UBOOT",
45 .image_index = 3,
46 }
47};
48
49struct efi_capsule_update_info update_info = {
50 .dfu_string = "sf 0:0=tiboot3.bin raw 0 100000;"
51 "tispl.bin raw 100000 200000;u-boot.img raw 300000 400000",
52 .num_images = ARRAY_SIZE(fw_images),
53 .images = fw_images,
54};
55
56#if IS_ENABLED(CONFIG_SET_DFU_ALT_INFO)
57void set_dfu_alt_info(char *interface, char *devstr)
58{
59 if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT))
60 env_set("dfu_alt_info", update_info.dfu_string);
61}
62#endif
63
Dave Gerlach3dc33f12021-04-23 11:27:42 -050064int board_init(void)
65{
66 return 0;
67}
68
69int dram_init(void)
70{
Dave Gerlach88107fe2022-03-17 12:03:40 -050071 s32 ret;
Dave Gerlach3dc33f12021-04-23 11:27:42 -050072
Dave Gerlach88107fe2022-03-17 12:03:40 -050073 ret = fdtdec_setup_mem_size_base();
74 if (ret)
75 printf("Error setting up mem size and base. %d\n", ret);
76
77 return ret;
Dave Gerlach3dc33f12021-04-23 11:27:42 -050078}
79
80int dram_init_banksize(void)
81{
Dave Gerlach88107fe2022-03-17 12:03:40 -050082 s32 ret;
83
84 ret = fdtdec_setup_memory_banksize();
85 if (ret)
86 printf("Error setting up memory banksize. %d\n", ret);
Dave Gerlach3dc33f12021-04-23 11:27:42 -050087
Dave Gerlach88107fe2022-03-17 12:03:40 -050088 return ret;
Dave Gerlach3dc33f12021-04-23 11:27:42 -050089}
90
91#if defined(CONFIG_SPL_LOAD_FIT)
92int board_fit_config_name_match(const char *name)
93{
Lokesh Vutla8af2b692021-05-06 16:44:51 +053094 bool eeprom_read = board_ti_was_eeprom_read();
95
96 if (!eeprom_read || board_is_am64x_gpevm()) {
97 if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
98 return 0;
99 } else if (board_is_am64x_skevm()) {
100 if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
101 return 0;
102 }
Dave Gerlach3dc33f12021-04-23 11:27:42 -0500103
104 return -1;
105}
106#endif
Lokesh Vutla01032a42021-05-06 16:44:49 +0530107
Dave Gerlach10498d12022-03-17 12:03:44 -0500108#if defined(CONFIG_SPL_BUILD)
109#if CONFIG_IS_ENABLED(USB_STORAGE)
Aswath Govindrajue910fac2021-08-04 18:42:44 +0530110static int fixup_usb_boot(const void *fdt_blob)
111{
112 int ret = 0;
113
114 switch (spl_boot_device()) {
115 case BOOT_DEVICE_USB:
116 /*
117 * If the boot mode is host, fixup the dr_mode to host
118 * before cdns3 bind takes place
119 */
120 ret = fdt_find_and_setprop((void *)fdt_blob,
121 "/bus@f4000/cdns-usb@f900000/usb@f400000",
122 "dr_mode", "host", 5, 0);
123 if (ret)
124 printf("%s: fdt_find_and_setprop() failed:%d\n",
125 __func__, ret);
126 fallthrough;
127 default:
128 break;
129 }
130
131 return ret;
132}
Dave Gerlach10498d12022-03-17 12:03:44 -0500133#endif
134
135#if defined(CONFIG_K3_AM64_DDRSS)
136static void fixup_ddr_driver_for_ecc(struct spl_image_info *spl_image)
137{
138 struct udevice *dev;
139 int ret;
140
141 dram_init_banksize();
142
143 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
144 if (ret)
145 panic("Cannot get RAM device for ddr size fixup: %d\n", ret);
146
147 ret = k3_ddrss_ddr_fdt_fixup(dev, spl_image->fdt_addr, gd->bd);
148 if (ret)
149 printf("Error fixing up ddr node for ECC use! %d\n", ret);
150}
151#else
152static void fixup_memory_node(struct spl_image_info *spl_image)
153{
154 u64 start[CONFIG_NR_DRAM_BANKS];
155 u64 size[CONFIG_NR_DRAM_BANKS];
156 int bank;
157 int ret;
158
159 dram_init();
160 dram_init_banksize();
161
162 for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
163 start[bank] = gd->bd->bi_dram[bank].start;
164 size[bank] = gd->bd->bi_dram[bank].size;
165 }
166
167 /* dram_init functions use SPL fdt, and we must fixup u-boot fdt */
168 ret = fdt_fixup_memory_banks(spl_image->fdt_addr, start, size, CONFIG_NR_DRAM_BANKS);
169 if (ret)
170 printf("Error fixing up memory node! %d\n", ret);
171}
172#endif
Aswath Govindrajue910fac2021-08-04 18:42:44 +0530173
174void spl_perform_fixups(struct spl_image_info *spl_image)
175{
Dave Gerlach10498d12022-03-17 12:03:44 -0500176#if defined(CONFIG_K3_AM64_DDRSS)
177 fixup_ddr_driver_for_ecc(spl_image);
178#else
179 fixup_memory_node(spl_image);
180#endif
181
182#if CONFIG_IS_ENABLED(USB_STORAGE)
Aswath Govindrajue910fac2021-08-04 18:42:44 +0530183 fixup_usb_boot(spl_image->fdt_addr);
Dave Gerlach10498d12022-03-17 12:03:44 -0500184#endif
Aswath Govindrajue910fac2021-08-04 18:42:44 +0530185}
186#endif
187
Lokesh Vutla01032a42021-05-06 16:44:49 +0530188#ifdef CONFIG_TI_I2C_BOARD_DETECT
189int do_board_detect(void)
190{
191 int ret;
192
193 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
194 CONFIG_EEPROM_CHIP_ADDRESS);
195 if (ret) {
196 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
197 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
198 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
199 CONFIG_EEPROM_CHIP_ADDRESS + 1);
200 if (ret)
201 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
202 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
203 }
204
205 return ret;
206}
207
208int checkboard(void)
209{
210 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
211
212 if (!do_board_detect())
213 printf("Board: %s rev %s\n", ep->name, ep->version);
214
215 return 0;
216}
217
218#ifdef CONFIG_BOARD_LATE_INIT
Nishanth Menon0822cd62024-02-12 13:47:20 -0600219static struct ti_fdt_map ti_am64_evm_fdt_map[] = {
220 {"am64x_gpevm", "k3-am642-evm.dtb"},
221 {"am64x_skevm", "k3-am642-sk.dtb"},
222 { /* Sentinel. */ }
223};
224
Lokesh Vutla01032a42021-05-06 16:44:49 +0530225static void setup_board_eeprom_env(void)
226{
227 char *name = "am64x_gpevm";
228
229 if (do_board_detect())
230 goto invalid_eeprom;
231
232 if (board_is_am64x_gpevm())
233 name = "am64x_gpevm";
234 else if (board_is_am64x_skevm())
235 name = "am64x_skevm";
236 else
237 printf("Unidentified board claims %s in eeprom header\n",
238 board_ti_get_name());
239
240invalid_eeprom:
241 set_board_info_env_am6(name);
Nishanth Menon0822cd62024-02-12 13:47:20 -0600242 ti_set_fdt_env(name, ti_am64_evm_fdt_map);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530243}
244
245static void setup_serial(void)
246{
247 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
248 unsigned long board_serial;
249 char *endp;
250 char serial_string[17] = { 0 };
251
252 if (env_get("serial#"))
253 return;
254
Simon Glass3ff49ec2021-07-24 09:03:29 -0600255 board_serial = hextoul(ep->serial, &endp);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530256 if (*endp != '\0') {
257 pr_err("Error: Can't set serial# to %s\n", ep->serial);
258 return;
259 }
260
261 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
262 env_set("serial#", serial_string);
263}
264#endif
265#endif
266
267#ifdef CONFIG_BOARD_LATE_INIT
268int board_late_init(void)
269{
270 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530271 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
272
Lokesh Vutla01032a42021-05-06 16:44:49 +0530273 setup_board_eeprom_env();
274 setup_serial();
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530275 /*
276 * The first MAC address for ethernet a.k.a. ethernet0 comes from
277 * efuse populated via the am654 gigabit eth switch subsystem driver.
278 * All the other ones are populated via EEPROM, hence continue with
279 * an index of 1.
280 */
281 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530282 }
283
284 return 0;
285}
286#endif
Aswath Govindrajucb962f92021-06-04 22:00:34 +0530287
288#define CTRLMMR_USB0_PHY_CTRL 0x43004008
289#define CORE_VOLTAGE 0x80000000
290
291#ifdef CONFIG_SPL_BOARD_INIT
292void spl_board_init(void)
293{
294 u32 val;
295 /* Set USB PHY core voltage to 0.85V */
296 val = readl(CTRLMMR_USB0_PHY_CTRL);
297 val &= ~(CORE_VOLTAGE);
298 writel(val, CTRLMMR_USB0_PHY_CTRL);
Vignesh Raghavendradfcda512021-12-24 12:55:31 +0530299
300 /* Init DRAM size for R5/A53 SPL */
301 dram_init_banksize();
Aswath Govindrajucb962f92021-06-04 22:00:34 +0530302}
303#endif