blob: 301afe1966d94f331f17a4322d2f983b5f4af234 [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
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +053033#define board_is_j7200_som() (board_ti_k3_is("J7200X-PM1-SOM") || \
34 board_ti_k3_is("J7200X-PM2-SOM"))
Lokesh Vutla2cf09d72020-08-05 22:44:25 +053035
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +053036/* Max number of MAC addresses that are parsed/processed per daughter card */
37#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
38
Lokesh Vutlaf8185032019-06-13 10:29:49 +053039DECLARE_GLOBAL_DATA_PTR;
40
41int board_init(void)
42{
43 return 0;
44}
45
46int dram_init(void)
47{
48#ifdef CONFIG_PHYS_64BIT
49 gd->ram_size = 0x100000000;
50#else
51 gd->ram_size = 0x80000000;
52#endif
53
54 return 0;
55}
56
57ulong board_get_usable_ram_top(ulong total_size)
58{
59#ifdef CONFIG_PHYS_64BIT
60 /* Limit RAM used by U-Boot to the DDR low region */
61 if (gd->ram_top > 0x100000000)
62 return 0x100000000;
63#endif
64
65 return gd->ram_top;
66}
67
68int dram_init_banksize(void)
69{
70 /* Bank 0 declares the memory available in the DDR low region */
71 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
72 gd->bd->bi_dram[0].size = 0x80000000;
73 gd->ram_size = 0x80000000;
74
75#ifdef CONFIG_PHYS_64BIT
76 /* Bank 1 declares the memory available in the DDR high region */
77 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
78 gd->bd->bi_dram[1].size = 0x80000000;
79 gd->ram_size = 0x100000000;
80#endif
81
82 return 0;
83}
84
85#ifdef CONFIG_SPL_LOAD_FIT
86int board_fit_config_name_match(const char *name)
87{
88 if (!strcmp(name, "k3-j721e-common-proc-board"))
89 return 0;
90
91 return -1;
92}
93#endif
Suman Annad146af52019-06-13 10:29:50 +053094
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +053095#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
96/* Returns 1, if onboard mux is set to hyperflash */
97static void __maybe_unused detect_enable_hyperflash(void *blob)
98{
99 struct gpio_desc desc = {0};
100
101 if (dm_gpio_lookup_name("6", &desc))
102 return;
103
104 if (dm_gpio_request(&desc, "6"))
105 return;
106
107 if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
108 return;
109
110 if (dm_gpio_get_value(&desc)) {
111 int offset;
112
113 do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
114 "okay", sizeof("okay"), 0);
115 offset = fdt_node_offset_by_compatible(blob, -1,
Vignesh Raghavendra5a8a7a92020-09-17 16:48:16 +0530116 "ti,am654-ospi");
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530117 fdt_setprop(blob, offset, "status", "disabled",
118 sizeof("disabled"));
119 }
120}
121#endif
122
Vignesh Raghavendrae85382f2020-08-13 14:56:16 +0530123#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_TARGET_J7200_A72_EVM)
124void spl_perform_fixups(struct spl_image_info *spl_image)
125{
126 detect_enable_hyperflash(spl_image->fdt_addr);
127}
128#endif
129
Suman Annad146af52019-06-13 10:29:50 +0530130#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900131int ft_board_setup(void *blob, struct bd_info *bd)
Suman Annad146af52019-06-13 10:29:50 +0530132{
133 int ret;
134
Suman Anna05264602020-08-05 22:44:15 +0530135 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
136 if (ret < 0)
137 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
138 "sram@70000000");
Suman Annad146af52019-06-13 10:29:50 +0530139 if (ret)
140 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
141
Vignesh Raghavendrad2bc9872020-08-07 00:26:57 +0530142 detect_enable_hyperflash(blob);
143
Suman Annad146af52019-06-13 10:29:50 +0530144 return ret;
145}
146#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530147
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530148#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530149int do_board_detect(void)
150{
151 int ret;
152
153 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
154 CONFIG_EEPROM_CHIP_ADDRESS);
Sinthu Rajaa46c5282022-02-09 15:06:49 +0530155 if (ret) {
156 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
157 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
158 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
159 CONFIG_EEPROM_CHIP_ADDRESS + 1);
160 if (ret)
161 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
162 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
163 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530164
165 return ret;
166}
167
Lokesh Vutlac7068ab2020-01-07 13:15:55 +0530168int checkboard(void)
169{
170 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
171
172 if (do_board_detect())
173 /* EEPROM not populated */
174 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
175 else
176 printf("Board: %s rev %s\n", ep->name, ep->version);
177
178 return 0;
179}
180
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530181/*
182 * Declaration of daughtercards to probe. Note that when adding more
183 * cards they should be grouped by the 'i2c_addr' field to allow for a
184 * more efficient probing process.
185 */
186static const struct {
187 u8 i2c_addr; /* I2C address of card EEPROM */
188 char *card_name; /* EEPROM-programmed card name */
189 char *dtbo_name; /* Device tree overlay to apply */
190 u8 eth_offset; /* ethXaddr MAC address index offset */
191} ext_cards[] = {
192 {
193 0x51,
194 "J7X-BASE-CPB",
195 "", /* No dtbo for this board */
196 0,
197 },
198 {
199 0x52,
200 "J7X-INFOTAN-EXP",
201 "", /* No dtbo for this board */
202 0,
203 },
204 {
205 0x52,
206 "J7X-GESI-EXP",
207 "", /* No dtbo for this board */
208 5, /* Start populating from eth5addr */
209 },
210 {
211 0x54,
212 "J7X-VSC8514-ETH",
213 "", /* No dtbo for this board */
214 1, /* Start populating from eth1addr */
215 },
216};
217
218static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
219
220const char *board_fit_get_additionnal_images(int index, const char *type)
221{
222 int i, j;
223
224 if (strcmp(type, FIT_FDT_PROP))
225 return NULL;
226
227 j = 0;
228 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
229 if (daughter_card_detect_flags[i]) {
230 if (j == index) {
231 /*
232 * Return dtbo name only if populated,
233 * otherwise stop parsing here.
234 */
235 if (strlen(ext_cards[i].dtbo_name))
236 return ext_cards[i].dtbo_name;
237 else
238 return NULL;
239 };
240
241 j++;
242 }
243 }
244
245 return NULL;
246}
247
248static int probe_daughtercards(void)
249{
250 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
251 bool eeprom_read_success;
252 struct ti_am6_eeprom ep;
253 u8 previous_i2c_addr;
254 u8 mac_addr_cnt;
255 int i;
256 int ret;
257
258 /* Mark previous I2C address variable as not populated */
259 previous_i2c_addr = 0xff;
260
261 /* No EEPROM data was read yet */
262 eeprom_read_success = false;
263
264 /* Iterate through list of daughtercards */
265 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
266 /* Obtain card-specific I2C address */
267 u8 i2c_addr = ext_cards[i].i2c_addr;
268
269 /* Read card EEPROM if not already read previously */
270 if (i2c_addr != previous_i2c_addr) {
271 /* Store I2C address so we can avoid reading twice */
272 previous_i2c_addr = i2c_addr;
273
274 /* Get and parse the daughter card EEPROM record */
275 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
276 i2c_addr,
277 &ep,
278 (char **)mac_addr,
279 DAUGHTER_CARD_NO_OF_MAC_ADDR,
280 &mac_addr_cnt);
281 if (ret) {
282 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
283 __func__, i2c_addr, ret);
284 eeprom_read_success = false;
285 /* Skip to the next daughtercard to probe */
286 continue;
287 }
288
289 /* EEPROM read successful, okay to further process. */
290 eeprom_read_success = true;
291 }
292
293 /* Only continue processing if EEPROM data was read */
294 if (!eeprom_read_success)
295 continue;
296
297 /* Only process the parsed data if we found a match */
298 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
299 continue;
300
301 printf("Detected: %s rev %s\n", ep.name, ep.version);
302 daughter_card_detect_flags[i] = true;
303
304#ifndef CONFIG_SPL_BUILD
305 int j;
306 /*
307 * Populate any MAC addresses from daughtercard into the U-Boot
308 * environment, starting with a card-specific offset so we can
309 * have multiple ext_cards contribute to the MAC pool in a well-
310 * defined manner.
311 */
312 for (j = 0; j < mac_addr_cnt; j++) {
313 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
314 continue;
315
316 eth_env_set_enetaddr_by_index("eth",
317 ext_cards[i].eth_offset + j,
318 (uchar *)mac_addr[j]);
319 }
320#endif
321 }
322#ifndef CONFIG_SPL_BUILD
323 char name_overlays[1024] = { 0 };
324
325 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
326 if (!daughter_card_detect_flags[i])
327 continue;
328
329 /* Skip if no overlays are to be added */
330 if (!strlen(ext_cards[i].dtbo_name))
331 continue;
332
333 /*
334 * Make sure we are not running out of buffer space by checking
335 * if we can fit the new overlay, a trailing space to be used
336 * as a separator, plus the terminating zero.
337 */
338 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
339 sizeof(name_overlays))
340 return -ENOMEM;
341
342 /* Append to our list of overlays */
343 strcat(name_overlays, ext_cards[i].dtbo_name);
344 strcat(name_overlays, " ");
345 }
346
347 /* Apply device tree overlay(s) to the U-Boot environment, if any */
348 if (strlen(name_overlays))
349 return env_set("name_overlays", name_overlays);
350#endif
351
352 return 0;
353}
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530354#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530355
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530356void configure_serdes_torrent(void)
357{
358 struct udevice *dev;
359 struct phy serdes;
360 int ret;
361
362 if (!IS_ENABLED(CONFIG_PHY_CADENCE_TORRENT))
363 return;
364
365 ret = uclass_get_device_by_driver(UCLASS_PHY,
366 DM_DRIVER_GET(torrent_phy_provider),
367 &dev);
368 if (ret)
369 printf("Torrent init failed:%d\n", ret);
370
371 serdes.dev = dev;
372 serdes.id = 0;
373
374 ret = generic_phy_init(&serdes);
375 if (ret)
376 printf("phy_init failed!!\n");
377
378 ret = generic_phy_power_on(&serdes);
379 if (ret)
380 printf("phy_power_on failed !!\n");
381}
382
Aswath Govindrajub3614432022-01-28 13:41:38 +0530383void configure_serdes_sierra(void)
384{
385 struct udevice *dev, *lnk_dev;
386 struct phy serdes;
387 int ret, count, i;
388
389 if (!IS_ENABLED(CONFIG_PHY_CADENCE_SIERRA))
390 return;
391
392 ret = uclass_get_device_by_driver(UCLASS_PHY,
393 DM_DRIVER_GET(sierra_phy_provider),
394 &dev);
395 if (ret)
396 printf("Sierra init failed:%d\n", ret);
397
398 serdes.dev = dev;
399 serdes.id = 0;
400
401 count = device_get_child_count(dev);
402 for (i = 0; i < count; i++) {
403 ret = device_get_child(dev, i, &lnk_dev);
404 if (ret)
405 printf("probe of sierra child node %d failed\n", i);
406 }
407
408 ret = generic_phy_init(&serdes);
409 if (ret)
410 printf("phy_init failed!!\n");
411
412 ret = generic_phy_power_on(&serdes);
413 if (ret)
414 printf("phy_power_on failed !!\n");
415}
416
Sinthu Rajad948fc42022-02-09 15:06:48 +0530417#ifdef CONFIG_BOARD_LATE_INIT
418static void setup_board_eeprom_env(void)
419{
420 char *name = "j721e";
421
422 if (do_board_detect())
423 goto invalid_eeprom;
424
425 if (board_is_j721e_som())
426 name = "j721e";
427 else if (board_is_j7200_som())
428 name = "j7200";
429 else
430 printf("Unidentified board claims %s in eeprom header\n",
431 board_ti_get_name());
432
433invalid_eeprom:
434 set_board_info_env_am6(name);
435}
436
437static void setup_serial(void)
438{
439 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
440 unsigned long board_serial;
441 char *endp;
442 char serial_string[17] = { 0 };
443
444 if (env_get("serial#"))
445 return;
446
447 board_serial = hextoul(ep->serial, &endp);
448 if (*endp != '\0') {
449 pr_err("Error: Can't set serial# to %s\n", ep->serial);
450 return;
451 }
452
453 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
454 env_set("serial#", serial_string);
455}
456
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530457int board_late_init(void)
458{
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530459 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
460 setup_board_eeprom_env();
461 setup_serial();
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530462
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530463 /* Check for and probe any plugged-in daughtercards */
464 probe_daughtercards();
465 }
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530466
Aswath Govindraju6cfabdd2021-07-21 21:28:39 +0530467 if (board_is_j7200_som())
468 configure_serdes_torrent();
469
Aswath Govindrajub3614432022-01-28 13:41:38 +0530470 if (board_is_j721e_som())
471 configure_serdes_sierra();
472
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530473 return 0;
474}
Sinthu Rajad948fc42022-02-09 15:06:48 +0530475#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530476
477void spl_board_init(void)
478{
Tero Kristofa281f62020-02-14 11:18:19 +0200479#if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
480 struct udevice *dev;
481 int ret;
482#endif
483
Lokesh Vutlacf1d6862020-08-05 22:44:24 +0530484 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
485 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
Lokesh Vutlab29a7cd2020-08-05 22:44:14 +0530486 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
487 probe_daughtercards();
Tero Kristofa281f62020-02-14 11:18:19 +0200488
489#ifdef CONFIG_ESM_K3
490 if (board_ti_k3_is("J721EX-PM2-SOM")) {
491 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700492 DM_DRIVER_GET(k3_esm), &dev);
Tero Kristofa281f62020-02-14 11:18:19 +0200493 if (ret)
494 printf("ESM init failed: %d\n", ret);
495 }
496#endif
497
498#ifdef CONFIG_ESM_PMIC
499 if (board_ti_k3_is("J721EX-PM2-SOM")) {
500 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65e25be2020-12-28 20:34:56 -0700501 DM_DRIVER_GET(pmic_esm),
Tero Kristofa281f62020-02-14 11:18:19 +0200502 &dev);
503 if (ret)
504 printf("ESM PMIC init failed: %d\n", ret);
505 }
506#endif
Andreas Dannenberg643eb6e2020-01-07 13:15:54 +0530507}