blob: e184ff0081b70cfc58f769ba853290615c969d2e [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{
91 if (!strcmp(name, "k3-j721e-common-proc-board"))
92 return 0;
93
94 return -1;
95}
96#endif
Suman Annad146af52019-06-13 10:29:50 +053097
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +053098#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
99/* Returns 1, if onboard mux is set to hyperflash */
100static void __maybe_unused detect_enable_hyperflash(void *blob)
101{
102 struct gpio_desc desc = {0};
103
104 if (dm_gpio_lookup_name("6", &desc))
105 return;
106
107 if (dm_gpio_request(&desc, "6"))
108 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 Raghavendra5a8a7a92020-09-17 16:48:16 +0530119 "ti,am654-ospi");
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530120 fdt_setprop(blob, offset, "status", "disabled",
121 sizeof("disabled"));
122 }
123}
124#endif
125
Vignesh Raghavendrae85382f2020-08-13 14:56:16 +0530126#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_TARGET_J7200_A72_EVM)
127void spl_perform_fixups(struct spl_image_info *spl_image)
128{
129 detect_enable_hyperflash(spl_image->fdt_addr);
130}
131#endif
132
Suman Annad146af52019-06-13 10:29:50 +0530133#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900134int ft_board_setup(void *blob, struct bd_info *bd)
Suman Annad146af52019-06-13 10:29:50 +0530135{
136 int ret;
137
Suman Anna05264602020-08-05 22:44:15 +0530138 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
139 if (ret < 0)
140 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
141 "sram@70000000");
Suman Annad146af52019-06-13 10:29:50 +0530142 if (ret)
143 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
144
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530145 detect_enable_hyperflash(blob);
146
Suman Annad146af52019-06-13 10:29:50 +0530147 return ret;
148}
149#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530150
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530151#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530152int 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);
Sinthu Rajaa46c5282022-02-09 15:06:49 +0530158 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 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530167
168 return ret;
169}
170
Lokesh Vutlac7068ab2020-01-07 13:15:55 +0530171int checkboard(void)
172{
173 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
174
175 if (do_board_detect())
176 /* EEPROM not populated */
177 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
178 else
179 printf("Board: %s rev %s\n", ep->name, ep->version);
180
181 return 0;
182}
183
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530184/*
185 * Declaration of daughtercards to probe. Note that when adding more
186 * cards they should be grouped by the 'i2c_addr' field to allow for a
187 * more efficient probing process.
188 */
189static const struct {
190 u8 i2c_addr; /* I2C address of card EEPROM */
191 char *card_name; /* EEPROM-programmed card name */
192 char *dtbo_name; /* Device tree overlay to apply */
193 u8 eth_offset; /* ethXaddr MAC address index offset */
194} ext_cards[] = {
195 {
196 0x51,
197 "J7X-BASE-CPB",
198 "", /* No dtbo for this board */
199 0,
200 },
201 {
202 0x52,
203 "J7X-INFOTAN-EXP",
204 "", /* No dtbo for this board */
205 0,
206 },
207 {
208 0x52,
209 "J7X-GESI-EXP",
210 "", /* No dtbo for this board */
211 5, /* Start populating from eth5addr */
212 },
213 {
214 0x54,
215 "J7X-VSC8514-ETH",
216 "", /* No dtbo for this board */
217 1, /* Start populating from eth1addr */
218 },
219};
220
221static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
222
223const char *board_fit_get_additionnal_images(int index, const char *type)
224{
225 int i, j;
226
227 if (strcmp(type, FIT_FDT_PROP))
228 return NULL;
229
230 j = 0;
231 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
232 if (daughter_card_detect_flags[i]) {
233 if (j == index) {
234 /*
235 * Return dtbo name only if populated,
236 * otherwise stop parsing here.
237 */
238 if (strlen(ext_cards[i].dtbo_name))
239 return ext_cards[i].dtbo_name;
240 else
241 return NULL;
242 };
243
244 j++;
245 }
246 }
247
248 return NULL;
249}
250
251static int probe_daughtercards(void)
252{
253 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
254 bool eeprom_read_success;
255 struct ti_am6_eeprom ep;
256 u8 previous_i2c_addr;
257 u8 mac_addr_cnt;
258 int i;
259 int ret;
260
261 /* Mark previous I2C address variable as not populated */
262 previous_i2c_addr = 0xff;
263
264 /* No EEPROM data was read yet */
265 eeprom_read_success = false;
266
267 /* Iterate through list of daughtercards */
268 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
269 /* Obtain card-specific I2C address */
270 u8 i2c_addr = ext_cards[i].i2c_addr;
271
272 /* Read card EEPROM if not already read previously */
273 if (i2c_addr != previous_i2c_addr) {
274 /* Store I2C address so we can avoid reading twice */
275 previous_i2c_addr = i2c_addr;
276
277 /* Get and parse the daughter card EEPROM record */
278 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
279 i2c_addr,
280 &ep,
281 (char **)mac_addr,
282 DAUGHTER_CARD_NO_OF_MAC_ADDR,
283 &mac_addr_cnt);
284 if (ret) {
285 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
286 __func__, i2c_addr, ret);
287 eeprom_read_success = false;
288 /* Skip to the next daughtercard to probe */
289 continue;
290 }
291
292 /* EEPROM read successful, okay to further process. */
293 eeprom_read_success = true;
294 }
295
296 /* Only continue processing if EEPROM data was read */
297 if (!eeprom_read_success)
298 continue;
299
300 /* Only process the parsed data if we found a match */
301 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
302 continue;
303
304 printf("Detected: %s rev %s\n", ep.name, ep.version);
305 daughter_card_detect_flags[i] = true;
306
307#ifndef CONFIG_SPL_BUILD
308 int j;
309 /*
310 * Populate any MAC addresses from daughtercard into the U-Boot
311 * environment, starting with a card-specific offset so we can
312 * have multiple ext_cards contribute to the MAC pool in a well-
313 * defined manner.
314 */
315 for (j = 0; j < mac_addr_cnt; j++) {
316 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
317 continue;
318
319 eth_env_set_enetaddr_by_index("eth",
320 ext_cards[i].eth_offset + j,
321 (uchar *)mac_addr[j]);
322 }
323#endif
324 }
325#ifndef CONFIG_SPL_BUILD
326 char name_overlays[1024] = { 0 };
327
328 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
329 if (!daughter_card_detect_flags[i])
330 continue;
331
332 /* Skip if no overlays are to be added */
333 if (!strlen(ext_cards[i].dtbo_name))
334 continue;
335
336 /*
337 * Make sure we are not running out of buffer space by checking
338 * if we can fit the new overlay, a trailing space to be used
339 * as a separator, plus the terminating zero.
340 */
341 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
342 sizeof(name_overlays))
343 return -ENOMEM;
344
345 /* Append to our list of overlays */
346 strcat(name_overlays, ext_cards[i].dtbo_name);
347 strcat(name_overlays, " ");
348 }
349
350 /* Apply device tree overlay(s) to the U-Boot environment, if any */
351 if (strlen(name_overlays))
352 return env_set("name_overlays", name_overlays);
353#endif
354
355 return 0;
356}
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530357#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530358
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530359void configure_serdes_torrent(void)
360{
361 struct udevice *dev;
362 struct phy serdes;
363 int ret;
364
365 if (!IS_ENABLED(CONFIG_PHY_CADENCE_TORRENT))
366 return;
367
368 ret = uclass_get_device_by_driver(UCLASS_PHY,
369 DM_DRIVER_GET(torrent_phy_provider),
370 &dev);
371 if (ret)
372 printf("Torrent init failed:%d\n", ret);
373
374 serdes.dev = dev;
375 serdes.id = 0;
376
377 ret = generic_phy_init(&serdes);
378 if (ret)
379 printf("phy_init failed!!\n");
380
381 ret = generic_phy_power_on(&serdes);
382 if (ret)
383 printf("phy_power_on failed !!\n");
384}
385
Aswath Govindrajub3614432022-01-28 13:41:38 +0530386void configure_serdes_sierra(void)
387{
388 struct udevice *dev, *lnk_dev;
389 struct phy serdes;
390 int ret, count, i;
391
392 if (!IS_ENABLED(CONFIG_PHY_CADENCE_SIERRA))
393 return;
394
395 ret = uclass_get_device_by_driver(UCLASS_PHY,
396 DM_DRIVER_GET(sierra_phy_provider),
397 &dev);
398 if (ret)
399 printf("Sierra init failed:%d\n", ret);
400
401 serdes.dev = dev;
402 serdes.id = 0;
403
404 count = device_get_child_count(dev);
405 for (i = 0; i < count; i++) {
406 ret = device_get_child(dev, i, &lnk_dev);
407 if (ret)
408 printf("probe of sierra child node %d failed\n", i);
409 }
410
411 ret = generic_phy_init(&serdes);
412 if (ret)
413 printf("phy_init failed!!\n");
414
415 ret = generic_phy_power_on(&serdes);
416 if (ret)
417 printf("phy_power_on failed !!\n");
418}
419
Sinthu Rajad948fc42022-02-09 15:06:48 +0530420#ifdef CONFIG_BOARD_LATE_INIT
421static void setup_board_eeprom_env(void)
422{
423 char *name = "j721e";
424
425 if (do_board_detect())
426 goto invalid_eeprom;
427
428 if (board_is_j721e_som())
429 name = "j721e";
Sinthu Rajadfb24292022-02-09 15:06:50 +0530430 else if (board_is_j721e_sk())
431 name = "j721e-sk";
Sinthu Rajad948fc42022-02-09 15:06:48 +0530432 else if (board_is_j7200_som())
433 name = "j7200";
434 else
435 printf("Unidentified board claims %s in eeprom header\n",
436 board_ti_get_name());
437
438invalid_eeprom:
439 set_board_info_env_am6(name);
440}
441
442static void setup_serial(void)
443{
444 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
445 unsigned long board_serial;
446 char *endp;
447 char serial_string[17] = { 0 };
448
449 if (env_get("serial#"))
450 return;
451
452 board_serial = hextoul(ep->serial, &endp);
453 if (*endp != '\0') {
454 pr_err("Error: Can't set serial# to %s\n", ep->serial);
455 return;
456 }
457
458 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
459 env_set("serial#", serial_string);
460}
461
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530462int board_late_init(void)
463{
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530464 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
465 setup_board_eeprom_env();
466 setup_serial();
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530467
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530468 /* Check for and probe any plugged-in daughtercards */
469 probe_daughtercards();
470 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530471
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530472 if (board_is_j7200_som())
473 configure_serdes_torrent();
474
Aswath Govindrajub3614432022-01-28 13:41:38 +0530475 if (board_is_j721e_som())
476 configure_serdes_sierra();
477
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530478 return 0;
479}
Sinthu Rajad948fc42022-02-09 15:06:48 +0530480#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530481
482void spl_board_init(void)
483{
Tero Kristofa281f62020-02-14 11:18:19 +0200484#if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
485 struct udevice *dev;
486 int ret;
487#endif
488
Lokesh Vutlacf1d6862020-08-05 22:44:24 +0530489 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
490 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530491 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
492 probe_daughtercards();
Tero Kristofa281f62020-02-14 11:18:19 +0200493
494#ifdef CONFIG_ESM_K3
495 if (board_ti_k3_is("J721EX-PM2-SOM")) {
496 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700497 DM_DRIVER_GET(k3_esm), &dev);
Tero Kristofa281f62020-02-14 11:18:19 +0200498 if (ret)
499 printf("ESM init failed: %d\n", ret);
500 }
501#endif
502
503#ifdef CONFIG_ESM_PMIC
504 if (board_ti_k3_is("J721EX-PM2-SOM")) {
505 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700506 DM_DRIVER_GET(pmic_esm),
Tero Kristofa281f62020-02-14 11:18:19 +0200507 &dev);
508 if (ret)
509 printf("ESM PMIC init failed: %d\n", ret);
510 }
511#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530512}