blob: b77cffc5ef568f7edef51a5245684b7ee74925fc [file] [log] [blame]
Lokesh Vutla1a9dd212019-06-13 10:29:49 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for J721E EVM
4 *
Nishanth Menoneaa39c62023-11-01 15:56:03 -05005 * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/
Lokesh Vutla1a9dd212019-06-13 10:29:49 +05306 * Lokesh Vutla <lokeshvutla@ti.com>
7 *
8 */
9
Aswath Govindraju1e2b4202021-07-21 21:28:39 +053010#include <generic-phy.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060011#include <image.h>
Simon Glass274e0b02020-05-10 11:39:56 -060012#include <net.h>
Andreas Dannenbergd036a212020-01-07 13:15:54 +053013#include <asm/arch/hardware.h>
14#include <asm/gpio.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053015#include <spl.h>
Tero Kristo1a2c7ba2020-02-14 11:18:19 +020016#include <dm.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053017
Andreas Dannenbergd036a212020-01-07 13:15:54 +053018#include "../common/board_detect.h"
19
20#define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
21 board_ti_k3_is("J721EX-PM2-SOM"))
22
Sinthu Raja1c24ab42022-02-09 15:06:50 +053023#define board_is_j721e_sk() (board_ti_k3_is("J721EX-EAIK") || \
24 board_ti_k3_is("J721EX-SK"))
25
Aswath Govindraju1e2b4202021-07-21 21:28:39 +053026#define board_is_j7200_som() (board_ti_k3_is("J7200X-PM1-SOM") || \
27 board_ti_k3_is("J7200X-PM2-SOM"))
Lokesh Vutlae2af9662020-08-05 22:44:25 +053028
Andreas Dannenbergd036a212020-01-07 13:15:54 +053029/* Max number of MAC addresses that are parsed/processed per daughter card */
30#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
31
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053032DECLARE_GLOBAL_DATA_PTR;
33
34int board_init(void)
35{
36 return 0;
37}
38
39int dram_init(void)
40{
41#ifdef CONFIG_PHYS_64BIT
42 gd->ram_size = 0x100000000;
43#else
44 gd->ram_size = 0x80000000;
45#endif
46
47 return 0;
48}
49
Heinrich Schuchardt51a9aac2023-08-12 20:16:58 +020050phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053051{
52#ifdef CONFIG_PHYS_64BIT
53 /* Limit RAM used by U-Boot to the DDR low region */
54 if (gd->ram_top > 0x100000000)
55 return 0x100000000;
56#endif
57
58 return gd->ram_top;
59}
60
61int dram_init_banksize(void)
62{
63 /* Bank 0 declares the memory available in the DDR low region */
Andrew Davisff64dc22023-11-30 08:49:11 -060064 gd->bd->bi_dram[0].start = 0x80000000;
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053065 gd->bd->bi_dram[0].size = 0x80000000;
66 gd->ram_size = 0x80000000;
67
68#ifdef CONFIG_PHYS_64BIT
69 /* Bank 1 declares the memory available in the DDR high region */
Andrew Davisff64dc22023-11-30 08:49:11 -060070 gd->bd->bi_dram[1].start = 0x880000000;
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053071 gd->bd->bi_dram[1].size = 0x80000000;
72 gd->ram_size = 0x100000000;
73#endif
74
75 return 0;
76}
77
78#ifdef CONFIG_SPL_LOAD_FIT
79int board_fit_config_name_match(const char *name)
80{
Sinthu Raja944ff632022-02-09 15:06:52 +053081 bool eeprom_read = board_ti_was_eeprom_read();
82
83 if (!eeprom_read || board_is_j721e_som()) {
84 if (!strcmp(name, "k3-j721e-common-proc-board") ||
85 !strcmp(name, "k3-j721e-r5-common-proc-board"))
86 return 0;
87 } else if (board_is_j721e_sk()) {
88 if (!strcmp(name, "k3-j721e-sk") ||
89 !strcmp(name, "k3-j721e-r5-sk"))
90 return 0;
91 }
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053092
93 return -1;
94}
95#endif
Suman Anna8eac9e62019-06-13 10:29:50 +053096
Vignesh Raghavendra685d8652020-08-07 00:26:57 +053097#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
98/* Returns 1, if onboard mux is set to hyperflash */
99static void __maybe_unused detect_enable_hyperflash(void *blob)
100{
101 struct gpio_desc desc = {0};
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530102 char *hypermux_sel_gpio = (board_is_j721e_som()) ? "8" : "6";
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530103
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530104 if (dm_gpio_lookup_name(hypermux_sel_gpio, &desc))
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530105 return;
106
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530107 if (dm_gpio_request(&desc, hypermux_sel_gpio))
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530108 return;
109
110 if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
111 return;
112
113 if (dm_gpio_get_value(&desc)) {
114 int offset;
115
116 do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
117 "okay", sizeof("okay"), 0);
118 offset = fdt_node_offset_by_compatible(blob, -1,
Vignesh Raghavendra57b78362020-09-17 16:48:16 +0530119 "ti,am654-ospi");
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530120 fdt_setprop(blob, offset, "status", "disabled",
121 sizeof("disabled"));
122 }
123}
124#endif
125
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530126#if defined(CONFIG_SPL_BUILD) && (defined(CONFIG_TARGET_J7200_A72_EVM) || defined(CONFIG_TARGET_J7200_R5_EVM) || \
127 defined(CONFIG_TARGET_J721E_A72_EVM) || defined(CONFIG_TARGET_J721E_R5_EVM))
Vignesh Raghavendra4c3c3d22020-08-13 14:56:16 +0530128void spl_perform_fixups(struct spl_image_info *spl_image)
129{
130 detect_enable_hyperflash(spl_image->fdt_addr);
131}
132#endif
133
Suman Anna8eac9e62019-06-13 10:29:50 +0530134#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900135int ft_board_setup(void *blob, struct bd_info *bd)
Suman Anna8eac9e62019-06-13 10:29:50 +0530136{
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530137 detect_enable_hyperflash(blob);
138
Andrew Davisb1c29792023-04-06 11:38:10 -0500139 return 0;
Suman Anna8eac9e62019-06-13 10:29:50 +0530140}
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530141#endif
142
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530143#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530144int do_board_detect(void)
145{
146 int ret;
147
Sinthu Raja944ff632022-02-09 15:06:52 +0530148 if (board_ti_was_eeprom_read())
149 return 0;
150
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530151 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
152 CONFIG_EEPROM_CHIP_ADDRESS);
Sinthu Raja812364f2022-02-09 15:06:49 +0530153 if (ret) {
154 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
155 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
156 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
157 CONFIG_EEPROM_CHIP_ADDRESS + 1);
158 if (ret)
159 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
160 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
161 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530162
163 return ret;
164}
165
Lokesh Vutla1db6b642020-01-07 13:15:55 +0530166int checkboard(void)
167{
168 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
169
170 if (do_board_detect())
171 /* EEPROM not populated */
172 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
173 else
174 printf("Board: %s rev %s\n", ep->name, ep->version);
175
176 return 0;
177}
178
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530179/*
180 * Declaration of daughtercards to probe. Note that when adding more
181 * cards they should be grouped by the 'i2c_addr' field to allow for a
182 * more efficient probing process.
183 */
184static const struct {
185 u8 i2c_addr; /* I2C address of card EEPROM */
186 char *card_name; /* EEPROM-programmed card name */
187 char *dtbo_name; /* Device tree overlay to apply */
188 u8 eth_offset; /* ethXaddr MAC address index offset */
189} ext_cards[] = {
190 {
191 0x51,
192 "J7X-BASE-CPB",
193 "", /* No dtbo for this board */
194 0,
195 },
196 {
197 0x52,
198 "J7X-INFOTAN-EXP",
199 "", /* No dtbo for this board */
200 0,
201 },
202 {
203 0x52,
204 "J7X-GESI-EXP",
205 "", /* No dtbo for this board */
206 5, /* Start populating from eth5addr */
207 },
208 {
209 0x54,
210 "J7X-VSC8514-ETH",
211 "", /* No dtbo for this board */
212 1, /* Start populating from eth1addr */
213 },
214};
215
216static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
217
218const char *board_fit_get_additionnal_images(int index, const char *type)
219{
220 int i, j;
221
222 if (strcmp(type, FIT_FDT_PROP))
223 return NULL;
224
225 j = 0;
226 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
227 if (daughter_card_detect_flags[i]) {
228 if (j == index) {
229 /*
230 * Return dtbo name only if populated,
231 * otherwise stop parsing here.
232 */
233 if (strlen(ext_cards[i].dtbo_name))
234 return ext_cards[i].dtbo_name;
235 else
236 return NULL;
237 };
238
239 j++;
240 }
241 }
242
243 return NULL;
244}
245
246static int probe_daughtercards(void)
247{
248 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
249 bool eeprom_read_success;
250 struct ti_am6_eeprom ep;
251 u8 previous_i2c_addr;
252 u8 mac_addr_cnt;
253 int i;
254 int ret;
255
256 /* Mark previous I2C address variable as not populated */
257 previous_i2c_addr = 0xff;
258
259 /* No EEPROM data was read yet */
260 eeprom_read_success = false;
261
262 /* Iterate through list of daughtercards */
263 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
264 /* Obtain card-specific I2C address */
265 u8 i2c_addr = ext_cards[i].i2c_addr;
266
267 /* Read card EEPROM if not already read previously */
268 if (i2c_addr != previous_i2c_addr) {
269 /* Store I2C address so we can avoid reading twice */
270 previous_i2c_addr = i2c_addr;
271
272 /* Get and parse the daughter card EEPROM record */
273 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
274 i2c_addr,
275 &ep,
276 (char **)mac_addr,
277 DAUGHTER_CARD_NO_OF_MAC_ADDR,
278 &mac_addr_cnt);
279 if (ret) {
280 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
281 __func__, i2c_addr, ret);
282 eeprom_read_success = false;
283 /* Skip to the next daughtercard to probe */
284 continue;
285 }
286
287 /* EEPROM read successful, okay to further process. */
288 eeprom_read_success = true;
289 }
290
291 /* Only continue processing if EEPROM data was read */
292 if (!eeprom_read_success)
293 continue;
294
295 /* Only process the parsed data if we found a match */
296 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
297 continue;
298
299 printf("Detected: %s rev %s\n", ep.name, ep.version);
300 daughter_card_detect_flags[i] = true;
301
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500302 if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
303 int j;
304 /*
305 * Populate any MAC addresses from daughtercard into the U-Boot
306 * environment, starting with a card-specific offset so we can
307 * have multiple ext_cards contribute to the MAC pool in a well-
308 * defined manner.
309 */
310 for (j = 0; j < mac_addr_cnt; j++) {
311 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
312 continue;
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530313
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500314 eth_env_set_enetaddr_by_index("eth",
315 ext_cards[i].eth_offset + j,
316 (uchar *)mac_addr[j]);
317 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530318 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530319 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530320
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500321 if (!IS_ENABLED(CONFIG_SPL_BUILD)) {
322 char name_overlays[1024] = { 0 };
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530323
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500324 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
325 if (!daughter_card_detect_flags[i])
326 continue;
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530327
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500328 /* Skip if no overlays are to be added */
329 if (!strlen(ext_cards[i].dtbo_name))
330 continue;
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530331
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500332 /*
333 * Make sure we are not running out of buffer space by checking
334 * if we can fit the new overlay, a trailing space to be used
335 * as a separator, plus the terminating zero.
336 */
337 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
338 sizeof(name_overlays))
339 return -ENOMEM;
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530340
Nishanth Menon4f4c9d82023-11-04 02:21:41 -0500341 /* Append to our list of overlays */
342 strcat(name_overlays, ext_cards[i].dtbo_name);
343 strcat(name_overlays, " ");
344 }
345
346 /* Apply device tree overlay(s) to the U-Boot environment, if any */
347 if (strlen(name_overlays))
348 return env_set("name_overlays", name_overlays);
349 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530350
351 return 0;
352}
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530353#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530354
Sinthu Rajae861aa92022-02-09 15:06:48 +0530355#ifdef CONFIG_BOARD_LATE_INIT
356static void setup_board_eeprom_env(void)
357{
358 char *name = "j721e";
359
360 if (do_board_detect())
361 goto invalid_eeprom;
362
363 if (board_is_j721e_som())
364 name = "j721e";
Sinthu Raja1c24ab42022-02-09 15:06:50 +0530365 else if (board_is_j721e_sk())
366 name = "j721e-sk";
Sinthu Rajae861aa92022-02-09 15:06:48 +0530367 else if (board_is_j7200_som())
368 name = "j7200";
369 else
370 printf("Unidentified board claims %s in eeprom header\n",
371 board_ti_get_name());
372
373invalid_eeprom:
374 set_board_info_env_am6(name);
375}
376
377static void setup_serial(void)
378{
379 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
380 unsigned long board_serial;
381 char *endp;
382 char serial_string[17] = { 0 };
383
384 if (env_get("serial#"))
385 return;
386
387 board_serial = hextoul(ep->serial, &endp);
388 if (*endp != '\0') {
389 pr_err("Error: Can't set serial# to %s\n", ep->serial);
390 return;
391 }
392
393 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
394 env_set("serial#", serial_string);
395}
396
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530397int board_late_init(void)
398{
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530399 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
400 setup_board_eeprom_env();
401 setup_serial();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530402
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530403 /* Check for and probe any plugged-in daughtercards */
Sinthu Raja9a4fa302022-02-09 15:06:51 +0530404 if (board_is_j721e_som() || board_is_j7200_som())
405 probe_daughtercards();
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530406 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530407
408 return 0;
409}
Sinthu Rajae861aa92022-02-09 15:06:48 +0530410#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530411
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530412static int __maybe_unused detect_SW3_1_state(void)
413{
414 if (IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM) || IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM)) {
415 struct gpio_desc desc = {0};
416 int ret;
417 char *hypermux_sel_gpio = (board_is_j721e_som()) ? "8" : "6";
418
419 ret = dm_gpio_lookup_name(hypermux_sel_gpio, &desc);
420 if (ret) {
421 printf("error getting GPIO lookup name: %d\n", ret);
422 return ret;
423 }
424
425 ret = dm_gpio_request(&desc, hypermux_sel_gpio);
426 if (ret) {
427 printf("error requesting GPIO: %d\n", ret);
428 goto err_free_gpio;
429 }
430
431 ret = dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN);
432 if (ret) {
433 printf("error setting direction flag of GPIO: %d\n", ret);
434 goto err_free_gpio;
435 }
436
437 ret = dm_gpio_get_value(&desc);
438 if (ret < 0)
439 printf("error getting value of GPIO: %d\n", ret);
440
441err_free_gpio:
442 dm_gpio_free(desc.dev, &desc);
443 return ret;
444 }
445}
446
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530447void spl_board_init(void)
448{
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200449 struct udevice *dev;
450 int ret;
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200451
Lokesh Vutla046ad432020-08-05 22:44:24 +0530452 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
453 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
Sinthu Raja9a4fa302022-02-09 15:06:51 +0530454 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
455 if (!board_is_j721e_sk())
456 probe_daughtercards();
457 }
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200458
Nishanth Menon591443e2023-11-04 02:21:40 -0500459 if (IS_ENABLED(CONFIG_ESM_K3)) {
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200460 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700461 DM_DRIVER_GET(k3_esm), &dev);
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200462 if (ret)
463 printf("ESM init failed: %d\n", ret);
464 }
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200465
Nishanth Menon591443e2023-11-04 02:21:40 -0500466 if (IS_ENABLED(CONFIG_ESM_PMIC)) {
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200467 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700468 DM_DRIVER_GET(pmic_esm),
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200469 &dev);
470 if (ret)
471 printf("ESM PMIC init failed: %d\n", ret);
472 }
Vaishnav Achathb8b17442022-05-09 11:50:16 +0530473 if ((IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM) || IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM)) &&
474 IS_ENABLED(CONFIG_HBMC_AM654)) {
475 struct udevice *dev;
476 int ret;
477
478 ret = detect_SW3_1_state();
479 if (ret == 1) {
480 ret = uclass_get_device_by_driver(UCLASS_MTD,
481 DM_DRIVER_GET(hbmc_am654),
482 &dev);
483 if (ret)
484 debug("Failed to probe hyperflash\n");
485 }
486 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530487}