blob: f479197e722be74aba4e1d7b7ccb419c1b3ec89c [file] [log] [blame]
Lokesh Vutlaf8185032019-06-13 10:29:49 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for J721E EVM
4 *
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 *
8 */
9
10#include <common.h>
Simon Glass09140112020-05-10 11:40:03 -060011#include <env.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060012#include <fdt_support.h>
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +053013#include <generic-phy.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060014#include <image.h>
Simon Glass67c4e9f2019-11-14 12:57:45 -070015#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060016#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060017#include <net.h>
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +053018#include <asm/arch/sys_proto.h>
19#include <asm/arch/hardware.h>
Simon Glass401d1c42020-10-30 21:38:53 -060020#include <asm/global_data.h>
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +053021#include <asm/gpio.h>
Lokesh Vutlaf8185032019-06-13 10:29:49 +053022#include <asm/io.h>
23#include <spl.h>
Suman Annad146af52019-06-13 10:29:50 +053024#include <asm/arch/sys_proto.h>
Tero Kristofa281f62020-02-14 11:18:19 +020025#include <dm.h>
26#include <dm/uclass-internal.h>
Lokesh Vutlaf8185032019-06-13 10:29:49 +053027
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +053028#include "../common/board_detect.h"
29
30#define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
31 board_ti_k3_is("J721EX-PM2-SOM"))
32
Sinthu Rajadfb24292022-02-09 15:06:50 +053033#define board_is_j721e_sk() (board_ti_k3_is("J721EX-EAIK") || \
34 board_ti_k3_is("J721EX-SK"))
35
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +053036#define board_is_j7200_som() (board_ti_k3_is("J7200X-PM1-SOM") || \
37 board_ti_k3_is("J7200X-PM2-SOM"))
Lokesh Vutla2cf09d72020-08-05 22:44:25 +053038
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +053039/* Max number of MAC addresses that are parsed/processed per daughter card */
40#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
41
Lokesh Vutlaf8185032019-06-13 10:29:49 +053042DECLARE_GLOBAL_DATA_PTR;
43
44int board_init(void)
45{
46 return 0;
47}
48
49int dram_init(void)
50{
51#ifdef CONFIG_PHYS_64BIT
52 gd->ram_size = 0x100000000;
53#else
54 gd->ram_size = 0x80000000;
55#endif
56
57 return 0;
58}
59
60ulong board_get_usable_ram_top(ulong total_size)
61{
62#ifdef CONFIG_PHYS_64BIT
63 /* Limit RAM used by U-Boot to the DDR low region */
64 if (gd->ram_top > 0x100000000)
65 return 0x100000000;
66#endif
67
68 return gd->ram_top;
69}
70
71int dram_init_banksize(void)
72{
73 /* Bank 0 declares the memory available in the DDR low region */
74 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
75 gd->bd->bi_dram[0].size = 0x80000000;
76 gd->ram_size = 0x80000000;
77
78#ifdef CONFIG_PHYS_64BIT
79 /* Bank 1 declares the memory available in the DDR high region */
80 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
81 gd->bd->bi_dram[1].size = 0x80000000;
82 gd->ram_size = 0x100000000;
83#endif
84
85 return 0;
86}
87
88#ifdef CONFIG_SPL_LOAD_FIT
89int board_fit_config_name_match(const char *name)
90{
Sinthu Rajad8004912022-02-09 15:06:52 +053091 bool eeprom_read = board_ti_was_eeprom_read();
92
93 if (!eeprom_read || board_is_j721e_som()) {
94 if (!strcmp(name, "k3-j721e-common-proc-board") ||
95 !strcmp(name, "k3-j721e-r5-common-proc-board"))
96 return 0;
97 } else if (board_is_j721e_sk()) {
98 if (!strcmp(name, "k3-j721e-sk") ||
99 !strcmp(name, "k3-j721e-r5-sk"))
100 return 0;
101 }
Lokesh Vutlaf8185032019-06-13 10:29:49 +0530102
103 return -1;
104}
105#endif
Suman Annad146af52019-06-13 10:29:50 +0530106
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530107#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
108/* Returns 1, if onboard mux is set to hyperflash */
109static void __maybe_unused detect_enable_hyperflash(void *blob)
110{
111 struct gpio_desc desc = {0};
112
113 if (dm_gpio_lookup_name("6", &desc))
114 return;
115
116 if (dm_gpio_request(&desc, "6"))
117 return;
118
119 if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
120 return;
121
122 if (dm_gpio_get_value(&desc)) {
123 int offset;
124
125 do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
126 "okay", sizeof("okay"), 0);
127 offset = fdt_node_offset_by_compatible(blob, -1,
Vignesh Raghavendra5a8a7a92020-09-17 16:48:16 +0530128 "ti,am654-ospi");
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530129 fdt_setprop(blob, offset, "status", "disabled",
130 sizeof("disabled"));
131 }
132}
133#endif
134
Vignesh Raghavendrae85382f2020-08-13 14:56:16 +0530135#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_TARGET_J7200_A72_EVM)
136void spl_perform_fixups(struct spl_image_info *spl_image)
137{
138 detect_enable_hyperflash(spl_image->fdt_addr);
139}
140#endif
141
Suman Annad146af52019-06-13 10:29:50 +0530142#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900143int ft_board_setup(void *blob, struct bd_info *bd)
Suman Annad146af52019-06-13 10:29:50 +0530144{
145 int ret;
146
Suman Anna05264602020-08-05 22:44:15 +0530147 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
148 if (ret < 0)
149 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
150 "sram@70000000");
Suman Annad146af52019-06-13 10:29:50 +0530151 if (ret)
152 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
153
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530154 detect_enable_hyperflash(blob);
155
Suman Annad146af52019-06-13 10:29:50 +0530156 return ret;
157}
158#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530159
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530160#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530161int do_board_detect(void)
162{
163 int ret;
164
Sinthu Rajad8004912022-02-09 15:06:52 +0530165 if (board_ti_was_eeprom_read())
166 return 0;
167
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530168 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
169 CONFIG_EEPROM_CHIP_ADDRESS);
Sinthu Rajaa46c5282022-02-09 15:06:49 +0530170 if (ret) {
171 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
172 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
173 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
174 CONFIG_EEPROM_CHIP_ADDRESS + 1);
175 if (ret)
176 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
177 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
178 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530179
180 return ret;
181}
182
Lokesh Vutlac7068ab2020-01-07 13:15:55 +0530183int checkboard(void)
184{
185 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
186
187 if (do_board_detect())
188 /* EEPROM not populated */
189 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
190 else
191 printf("Board: %s rev %s\n", ep->name, ep->version);
192
193 return 0;
194}
195
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530196/*
197 * Declaration of daughtercards to probe. Note that when adding more
198 * cards they should be grouped by the 'i2c_addr' field to allow for a
199 * more efficient probing process.
200 */
201static const struct {
202 u8 i2c_addr; /* I2C address of card EEPROM */
203 char *card_name; /* EEPROM-programmed card name */
204 char *dtbo_name; /* Device tree overlay to apply */
205 u8 eth_offset; /* ethXaddr MAC address index offset */
206} ext_cards[] = {
207 {
208 0x51,
209 "J7X-BASE-CPB",
210 "", /* No dtbo for this board */
211 0,
212 },
213 {
214 0x52,
215 "J7X-INFOTAN-EXP",
216 "", /* No dtbo for this board */
217 0,
218 },
219 {
220 0x52,
221 "J7X-GESI-EXP",
222 "", /* No dtbo for this board */
223 5, /* Start populating from eth5addr */
224 },
225 {
226 0x54,
227 "J7X-VSC8514-ETH",
228 "", /* No dtbo for this board */
229 1, /* Start populating from eth1addr */
230 },
231};
232
233static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
234
235const char *board_fit_get_additionnal_images(int index, const char *type)
236{
237 int i, j;
238
239 if (strcmp(type, FIT_FDT_PROP))
240 return NULL;
241
242 j = 0;
243 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
244 if (daughter_card_detect_flags[i]) {
245 if (j == index) {
246 /*
247 * Return dtbo name only if populated,
248 * otherwise stop parsing here.
249 */
250 if (strlen(ext_cards[i].dtbo_name))
251 return ext_cards[i].dtbo_name;
252 else
253 return NULL;
254 };
255
256 j++;
257 }
258 }
259
260 return NULL;
261}
262
263static int probe_daughtercards(void)
264{
265 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
266 bool eeprom_read_success;
267 struct ti_am6_eeprom ep;
268 u8 previous_i2c_addr;
269 u8 mac_addr_cnt;
270 int i;
271 int ret;
272
273 /* Mark previous I2C address variable as not populated */
274 previous_i2c_addr = 0xff;
275
276 /* No EEPROM data was read yet */
277 eeprom_read_success = false;
278
279 /* Iterate through list of daughtercards */
280 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
281 /* Obtain card-specific I2C address */
282 u8 i2c_addr = ext_cards[i].i2c_addr;
283
284 /* Read card EEPROM if not already read previously */
285 if (i2c_addr != previous_i2c_addr) {
286 /* Store I2C address so we can avoid reading twice */
287 previous_i2c_addr = i2c_addr;
288
289 /* Get and parse the daughter card EEPROM record */
290 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
291 i2c_addr,
292 &ep,
293 (char **)mac_addr,
294 DAUGHTER_CARD_NO_OF_MAC_ADDR,
295 &mac_addr_cnt);
296 if (ret) {
297 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
298 __func__, i2c_addr, ret);
299 eeprom_read_success = false;
300 /* Skip to the next daughtercard to probe */
301 continue;
302 }
303
304 /* EEPROM read successful, okay to further process. */
305 eeprom_read_success = true;
306 }
307
308 /* Only continue processing if EEPROM data was read */
309 if (!eeprom_read_success)
310 continue;
311
312 /* Only process the parsed data if we found a match */
313 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
314 continue;
315
316 printf("Detected: %s rev %s\n", ep.name, ep.version);
317 daughter_card_detect_flags[i] = true;
318
319#ifndef CONFIG_SPL_BUILD
320 int j;
321 /*
322 * Populate any MAC addresses from daughtercard into the U-Boot
323 * environment, starting with a card-specific offset so we can
324 * have multiple ext_cards contribute to the MAC pool in a well-
325 * defined manner.
326 */
327 for (j = 0; j < mac_addr_cnt; j++) {
328 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
329 continue;
330
331 eth_env_set_enetaddr_by_index("eth",
332 ext_cards[i].eth_offset + j,
333 (uchar *)mac_addr[j]);
334 }
335#endif
336 }
337#ifndef CONFIG_SPL_BUILD
338 char name_overlays[1024] = { 0 };
339
340 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
341 if (!daughter_card_detect_flags[i])
342 continue;
343
344 /* Skip if no overlays are to be added */
345 if (!strlen(ext_cards[i].dtbo_name))
346 continue;
347
348 /*
349 * Make sure we are not running out of buffer space by checking
350 * if we can fit the new overlay, a trailing space to be used
351 * as a separator, plus the terminating zero.
352 */
353 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
354 sizeof(name_overlays))
355 return -ENOMEM;
356
357 /* Append to our list of overlays */
358 strcat(name_overlays, ext_cards[i].dtbo_name);
359 strcat(name_overlays, " ");
360 }
361
362 /* Apply device tree overlay(s) to the U-Boot environment, if any */
363 if (strlen(name_overlays))
364 return env_set("name_overlays", name_overlays);
365#endif
366
367 return 0;
368}
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530369#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530370
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530371void configure_serdes_torrent(void)
372{
373 struct udevice *dev;
374 struct phy serdes;
375 int ret;
376
377 if (!IS_ENABLED(CONFIG_PHY_CADENCE_TORRENT))
378 return;
379
380 ret = uclass_get_device_by_driver(UCLASS_PHY,
381 DM_DRIVER_GET(torrent_phy_provider),
382 &dev);
383 if (ret)
384 printf("Torrent init failed:%d\n", ret);
385
386 serdes.dev = dev;
387 serdes.id = 0;
388
389 ret = generic_phy_init(&serdes);
390 if (ret)
391 printf("phy_init failed!!\n");
392
393 ret = generic_phy_power_on(&serdes);
394 if (ret)
395 printf("phy_power_on failed !!\n");
396}
397
Aswath Govindrajub3614432022-01-28 13:41:38 +0530398void configure_serdes_sierra(void)
399{
400 struct udevice *dev, *lnk_dev;
401 struct phy serdes;
402 int ret, count, i;
403
404 if (!IS_ENABLED(CONFIG_PHY_CADENCE_SIERRA))
405 return;
406
407 ret = uclass_get_device_by_driver(UCLASS_PHY,
408 DM_DRIVER_GET(sierra_phy_provider),
409 &dev);
410 if (ret)
411 printf("Sierra init failed:%d\n", ret);
412
413 serdes.dev = dev;
414 serdes.id = 0;
415
416 count = device_get_child_count(dev);
417 for (i = 0; i < count; i++) {
418 ret = device_get_child(dev, i, &lnk_dev);
419 if (ret)
420 printf("probe of sierra child node %d failed\n", i);
421 }
422
423 ret = generic_phy_init(&serdes);
424 if (ret)
425 printf("phy_init failed!!\n");
426
427 ret = generic_phy_power_on(&serdes);
428 if (ret)
429 printf("phy_power_on failed !!\n");
430}
431
Sinthu Rajad948fc42022-02-09 15:06:48 +0530432#ifdef CONFIG_BOARD_LATE_INIT
433static void setup_board_eeprom_env(void)
434{
435 char *name = "j721e";
436
437 if (do_board_detect())
438 goto invalid_eeprom;
439
440 if (board_is_j721e_som())
441 name = "j721e";
Sinthu Rajadfb24292022-02-09 15:06:50 +0530442 else if (board_is_j721e_sk())
443 name = "j721e-sk";
Sinthu Rajad948fc42022-02-09 15:06:48 +0530444 else if (board_is_j7200_som())
445 name = "j7200";
446 else
447 printf("Unidentified board claims %s in eeprom header\n",
448 board_ti_get_name());
449
450invalid_eeprom:
451 set_board_info_env_am6(name);
452}
453
454static void setup_serial(void)
455{
456 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
457 unsigned long board_serial;
458 char *endp;
459 char serial_string[17] = { 0 };
460
461 if (env_get("serial#"))
462 return;
463
464 board_serial = hextoul(ep->serial, &endp);
465 if (*endp != '\0') {
466 pr_err("Error: Can't set serial# to %s\n", ep->serial);
467 return;
468 }
469
470 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
471 env_set("serial#", serial_string);
472}
473
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530474int board_late_init(void)
475{
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530476 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
477 setup_board_eeprom_env();
478 setup_serial();
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530479
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530480 /* Check for and probe any plugged-in daughtercards */
Sinthu Rajaee59fa42022-02-09 15:06:51 +0530481 if (board_is_j721e_som() || board_is_j7200_som())
482 probe_daughtercards();
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530483 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530484
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530485 if (board_is_j7200_som())
486 configure_serdes_torrent();
487
Aswath Govindrajub3614432022-01-28 13:41:38 +0530488 if (board_is_j721e_som())
489 configure_serdes_sierra();
490
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530491 return 0;
492}
Sinthu Rajad948fc42022-02-09 15:06:48 +0530493#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530494
495void spl_board_init(void)
496{
Tero Kristofa281f62020-02-14 11:18:19 +0200497#if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
498 struct udevice *dev;
499 int ret;
500#endif
501
Lokesh Vutlacf1d6862020-08-05 22:44:24 +0530502 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
503 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
Sinthu Rajaee59fa42022-02-09 15:06:51 +0530504 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
505 if (!board_is_j721e_sk())
506 probe_daughtercards();
507 }
Tero Kristofa281f62020-02-14 11:18:19 +0200508
509#ifdef CONFIG_ESM_K3
510 if (board_ti_k3_is("J721EX-PM2-SOM")) {
511 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700512 DM_DRIVER_GET(k3_esm), &dev);
Tero Kristofa281f62020-02-14 11:18:19 +0200513 if (ret)
514 printf("ESM init failed: %d\n", ret);
515 }
516#endif
517
518#ifdef CONFIG_ESM_PMIC
519 if (board_ti_k3_is("J721EX-PM2-SOM")) {
520 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700521 DM_DRIVER_GET(pmic_esm),
Tero Kristofa281f62020-02-14 11:18:19 +0200522 &dev);
523 if (ret)
524 printf("ESM PMIC init failed: %d\n", ret);
525 }
526#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530527}