blob: b9a9f1955222330c958a378ccfc547c8edff6f3d [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 *
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 Glassed38aef2020-05-10 11:40:03 -060011#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060012#include <fdt_support.h>
13#include <image.h>
Simon Glass6980b6b2019-11-14 12:57:45 -070014#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060016#include <net.h>
Andreas Dannenbergd036a212020-01-07 13:15:54 +053017#include <asm/arch/sys_proto.h>
18#include <asm/arch/hardware.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Andreas Dannenbergd036a212020-01-07 13:15:54 +053020#include <asm/gpio.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053021#include <asm/io.h>
22#include <spl.h>
Suman Anna8eac9e62019-06-13 10:29:50 +053023#include <asm/arch/sys_proto.h>
Tero Kristo1a2c7ba2020-02-14 11:18:19 +020024#include <dm.h>
25#include <dm/uclass-internal.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053026
Andreas Dannenbergd036a212020-01-07 13:15:54 +053027#include "../common/board_detect.h"
28
29#define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
30 board_ti_k3_is("J721EX-PM2-SOM"))
31
Lokesh Vutlae2af9662020-08-05 22:44:25 +053032#define board_is_j7200_som() board_ti_k3_is("J7200X-PM1-SOM")
33
Andreas Dannenbergd036a212020-01-07 13:15:54 +053034/* Max number of MAC addresses that are parsed/processed per daughter card */
35#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
36
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053037DECLARE_GLOBAL_DATA_PTR;
38
39int board_init(void)
40{
41 return 0;
42}
43
44int dram_init(void)
45{
46#ifdef CONFIG_PHYS_64BIT
47 gd->ram_size = 0x100000000;
48#else
49 gd->ram_size = 0x80000000;
50#endif
51
52 return 0;
53}
54
55ulong board_get_usable_ram_top(ulong total_size)
56{
57#ifdef CONFIG_PHYS_64BIT
58 /* Limit RAM used by U-Boot to the DDR low region */
59 if (gd->ram_top > 0x100000000)
60 return 0x100000000;
61#endif
62
63 return gd->ram_top;
64}
65
66int dram_init_banksize(void)
67{
68 /* Bank 0 declares the memory available in the DDR low region */
69 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
70 gd->bd->bi_dram[0].size = 0x80000000;
71 gd->ram_size = 0x80000000;
72
73#ifdef CONFIG_PHYS_64BIT
74 /* Bank 1 declares the memory available in the DDR high region */
75 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
76 gd->bd->bi_dram[1].size = 0x80000000;
77 gd->ram_size = 0x100000000;
78#endif
79
80 return 0;
81}
82
83#ifdef CONFIG_SPL_LOAD_FIT
84int board_fit_config_name_match(const char *name)
85{
86 if (!strcmp(name, "k3-j721e-common-proc-board"))
87 return 0;
88
89 return -1;
90}
91#endif
Suman Anna8eac9e62019-06-13 10:29:50 +053092
Vignesh Raghavendra685d8652020-08-07 00:26:57 +053093#if CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(OF_LIBFDT)
94/* Returns 1, if onboard mux is set to hyperflash */
95static void __maybe_unused detect_enable_hyperflash(void *blob)
96{
97 struct gpio_desc desc = {0};
98
99 if (dm_gpio_lookup_name("6", &desc))
100 return;
101
102 if (dm_gpio_request(&desc, "6"))
103 return;
104
105 if (dm_gpio_set_dir_flags(&desc, GPIOD_IS_IN))
106 return;
107
108 if (dm_gpio_get_value(&desc)) {
109 int offset;
110
111 do_fixup_by_compat(blob, "ti,am654-hbmc", "status",
112 "okay", sizeof("okay"), 0);
113 offset = fdt_node_offset_by_compatible(blob, -1,
Vignesh Raghavendra57b78362020-09-17 16:48:16 +0530114 "ti,am654-ospi");
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530115 fdt_setprop(blob, offset, "status", "disabled",
116 sizeof("disabled"));
117 }
118}
119#endif
120
Vignesh Raghavendra4c3c3d22020-08-13 14:56:16 +0530121#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_TARGET_J7200_A72_EVM)
122void spl_perform_fixups(struct spl_image_info *spl_image)
123{
124 detect_enable_hyperflash(spl_image->fdt_addr);
125}
126#endif
127
Suman Anna8eac9e62019-06-13 10:29:50 +0530128#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900129int ft_board_setup(void *blob, struct bd_info *bd)
Suman Anna8eac9e62019-06-13 10:29:50 +0530130{
131 int ret;
132
Suman Anna3ff49252020-08-05 22:44:15 +0530133 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
134 if (ret < 0)
135 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
136 "sram@70000000");
Suman Anna8eac9e62019-06-13 10:29:50 +0530137 if (ret)
138 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
139
Vignesh Raghavendra685d8652020-08-07 00:26:57 +0530140 detect_enable_hyperflash(blob);
141
Suman Anna8eac9e62019-06-13 10:29:50 +0530142 return ret;
143}
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530144#endif
145
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530146#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530147int do_board_detect(void)
148{
149 int ret;
150
151 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
152 CONFIG_EEPROM_CHIP_ADDRESS);
153 if (ret)
154 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
155 CONFIG_EEPROM_CHIP_ADDRESS, ret);
156
157 return ret;
158}
159
Lokesh Vutla1db6b642020-01-07 13:15:55 +0530160int checkboard(void)
161{
162 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
163
164 if (do_board_detect())
165 /* EEPROM not populated */
166 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
167 else
168 printf("Board: %s rev %s\n", ep->name, ep->version);
169
170 return 0;
171}
172
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530173static void setup_board_eeprom_env(void)
174{
175 char *name = "j721e";
176
177 if (do_board_detect())
178 goto invalid_eeprom;
179
180 if (board_is_j721e_som())
181 name = "j721e";
Lokesh Vutlae2af9662020-08-05 22:44:25 +0530182 else if (board_is_j7200_som())
183 name = "j7200";
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530184 else
185 printf("Unidentified board claims %s in eeprom header\n",
186 board_ti_get_name());
187
188invalid_eeprom:
189 set_board_info_env_am6(name);
190}
191
192static void setup_serial(void)
193{
194 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
195 unsigned long board_serial;
196 char *endp;
197 char serial_string[17] = { 0 };
198
199 if (env_get("serial#"))
200 return;
201
202 board_serial = simple_strtoul(ep->serial, &endp, 16);
203 if (*endp != '\0') {
204 pr_err("Error: Can't set serial# to %s\n", ep->serial);
205 return;
206 }
207
208 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
209 env_set("serial#", serial_string);
210}
211
212/*
213 * Declaration of daughtercards to probe. Note that when adding more
214 * cards they should be grouped by the 'i2c_addr' field to allow for a
215 * more efficient probing process.
216 */
217static const struct {
218 u8 i2c_addr; /* I2C address of card EEPROM */
219 char *card_name; /* EEPROM-programmed card name */
220 char *dtbo_name; /* Device tree overlay to apply */
221 u8 eth_offset; /* ethXaddr MAC address index offset */
222} ext_cards[] = {
223 {
224 0x51,
225 "J7X-BASE-CPB",
226 "", /* No dtbo for this board */
227 0,
228 },
229 {
230 0x52,
231 "J7X-INFOTAN-EXP",
232 "", /* No dtbo for this board */
233 0,
234 },
235 {
236 0x52,
237 "J7X-GESI-EXP",
238 "", /* No dtbo for this board */
239 5, /* Start populating from eth5addr */
240 },
241 {
242 0x54,
243 "J7X-VSC8514-ETH",
244 "", /* No dtbo for this board */
245 1, /* Start populating from eth1addr */
246 },
247};
248
249static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
250
251const char *board_fit_get_additionnal_images(int index, const char *type)
252{
253 int i, j;
254
255 if (strcmp(type, FIT_FDT_PROP))
256 return NULL;
257
258 j = 0;
259 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
260 if (daughter_card_detect_flags[i]) {
261 if (j == index) {
262 /*
263 * Return dtbo name only if populated,
264 * otherwise stop parsing here.
265 */
266 if (strlen(ext_cards[i].dtbo_name))
267 return ext_cards[i].dtbo_name;
268 else
269 return NULL;
270 };
271
272 j++;
273 }
274 }
275
276 return NULL;
277}
278
279static int probe_daughtercards(void)
280{
281 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
282 bool eeprom_read_success;
283 struct ti_am6_eeprom ep;
284 u8 previous_i2c_addr;
285 u8 mac_addr_cnt;
286 int i;
287 int ret;
288
289 /* Mark previous I2C address variable as not populated */
290 previous_i2c_addr = 0xff;
291
292 /* No EEPROM data was read yet */
293 eeprom_read_success = false;
294
295 /* Iterate through list of daughtercards */
296 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
297 /* Obtain card-specific I2C address */
298 u8 i2c_addr = ext_cards[i].i2c_addr;
299
300 /* Read card EEPROM if not already read previously */
301 if (i2c_addr != previous_i2c_addr) {
302 /* Store I2C address so we can avoid reading twice */
303 previous_i2c_addr = i2c_addr;
304
305 /* Get and parse the daughter card EEPROM record */
306 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
307 i2c_addr,
308 &ep,
309 (char **)mac_addr,
310 DAUGHTER_CARD_NO_OF_MAC_ADDR,
311 &mac_addr_cnt);
312 if (ret) {
313 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
314 __func__, i2c_addr, ret);
315 eeprom_read_success = false;
316 /* Skip to the next daughtercard to probe */
317 continue;
318 }
319
320 /* EEPROM read successful, okay to further process. */
321 eeprom_read_success = true;
322 }
323
324 /* Only continue processing if EEPROM data was read */
325 if (!eeprom_read_success)
326 continue;
327
328 /* Only process the parsed data if we found a match */
329 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
330 continue;
331
332 printf("Detected: %s rev %s\n", ep.name, ep.version);
333 daughter_card_detect_flags[i] = true;
334
335#ifndef CONFIG_SPL_BUILD
336 int j;
337 /*
338 * Populate any MAC addresses from daughtercard into the U-Boot
339 * environment, starting with a card-specific offset so we can
340 * have multiple ext_cards contribute to the MAC pool in a well-
341 * defined manner.
342 */
343 for (j = 0; j < mac_addr_cnt; j++) {
344 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
345 continue;
346
347 eth_env_set_enetaddr_by_index("eth",
348 ext_cards[i].eth_offset + j,
349 (uchar *)mac_addr[j]);
350 }
Suman Anna8eac9e62019-06-13 10:29:50 +0530351#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530352 }
353#ifndef CONFIG_SPL_BUILD
354 char name_overlays[1024] = { 0 };
355
356 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
357 if (!daughter_card_detect_flags[i])
358 continue;
359
360 /* Skip if no overlays are to be added */
361 if (!strlen(ext_cards[i].dtbo_name))
362 continue;
363
364 /*
365 * Make sure we are not running out of buffer space by checking
366 * if we can fit the new overlay, a trailing space to be used
367 * as a separator, plus the terminating zero.
368 */
369 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
370 sizeof(name_overlays))
371 return -ENOMEM;
372
373 /* Append to our list of overlays */
374 strcat(name_overlays, ext_cards[i].dtbo_name);
375 strcat(name_overlays, " ");
376 }
377
378 /* Apply device tree overlay(s) to the U-Boot environment, if any */
379 if (strlen(name_overlays))
380 return env_set("name_overlays", name_overlays);
381#endif
382
383 return 0;
384}
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530385#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530386
387int board_late_init(void)
388{
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530389 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
390 setup_board_eeprom_env();
391 setup_serial();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530392
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530393 /* Check for and probe any plugged-in daughtercards */
394 probe_daughtercards();
395 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530396
397 return 0;
398}
399
400void spl_board_init(void)
401{
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200402#if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
403 struct udevice *dev;
404 int ret;
405#endif
406
Lokesh Vutla046ad432020-08-05 22:44:24 +0530407 if ((IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) ||
408 IS_ENABLED(CONFIG_TARGET_J7200_A72_EVM)) &&
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530409 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
410 probe_daughtercards();
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200411
412#ifdef CONFIG_ESM_K3
413 if (board_ti_k3_is("J721EX-PM2-SOM")) {
414 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700415 DM_DRIVER_GET(k3_esm), &dev);
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200416 if (ret)
417 printf("ESM init failed: %d\n", ret);
418 }
419#endif
420
421#ifdef CONFIG_ESM_PMIC
422 if (board_ti_k3_is("J721EX-PM2-SOM")) {
423 ret = uclass_get_device_by_driver(UCLASS_MISC,
Simon Glass65130cd2020-12-28 20:34:56 -0700424 DM_DRIVER_GET(pmic_esm),
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200425 &dev);
426 if (ret)
427 printf("ESM PMIC init failed: %d\n", ret);
428 }
429#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530430}