blob: 7199d11e95c4c45dfca5145251836f3303dbae8a [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>
19#include <asm/gpio.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053020#include <asm/io.h>
21#include <spl.h>
Suman Anna8eac9e62019-06-13 10:29:50 +053022#include <asm/arch/sys_proto.h>
Tero Kristo1a2c7ba2020-02-14 11:18:19 +020023#include <dm.h>
24#include <dm/uclass-internal.h>
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053025
Andreas Dannenbergd036a212020-01-07 13:15:54 +053026#include "../common/board_detect.h"
27
28#define board_is_j721e_som() (board_ti_k3_is("J721EX-PM1-SOM") || \
29 board_ti_k3_is("J721EX-PM2-SOM"))
30
31/* Max number of MAC addresses that are parsed/processed per daughter card */
32#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
33
Lokesh Vutla1a9dd212019-06-13 10:29:49 +053034DECLARE_GLOBAL_DATA_PTR;
35
36int board_init(void)
37{
38 return 0;
39}
40
41int dram_init(void)
42{
43#ifdef CONFIG_PHYS_64BIT
44 gd->ram_size = 0x100000000;
45#else
46 gd->ram_size = 0x80000000;
47#endif
48
49 return 0;
50}
51
52ulong board_get_usable_ram_top(ulong total_size)
53{
54#ifdef CONFIG_PHYS_64BIT
55 /* Limit RAM used by U-Boot to the DDR low region */
56 if (gd->ram_top > 0x100000000)
57 return 0x100000000;
58#endif
59
60 return gd->ram_top;
61}
62
63int dram_init_banksize(void)
64{
65 /* Bank 0 declares the memory available in the DDR low region */
66 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
67 gd->bd->bi_dram[0].size = 0x80000000;
68 gd->ram_size = 0x80000000;
69
70#ifdef CONFIG_PHYS_64BIT
71 /* Bank 1 declares the memory available in the DDR high region */
72 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
73 gd->bd->bi_dram[1].size = 0x80000000;
74 gd->ram_size = 0x100000000;
75#endif
76
77 return 0;
78}
79
80#ifdef CONFIG_SPL_LOAD_FIT
81int board_fit_config_name_match(const char *name)
82{
83 if (!strcmp(name, "k3-j721e-common-proc-board"))
84 return 0;
85
86 return -1;
87}
88#endif
Suman Anna8eac9e62019-06-13 10:29:50 +053089
90#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090091int ft_board_setup(void *blob, struct bd_info *bd)
Suman Anna8eac9e62019-06-13 10:29:50 +053092{
93 int ret;
94
95 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000", "sram@70000000");
96 if (ret)
97 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
98
99 return ret;
100}
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530101#endif
102
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530103#ifdef CONFIG_TI_I2C_BOARD_DETECT
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530104int do_board_detect(void)
105{
106 int ret;
107
108 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
109 CONFIG_EEPROM_CHIP_ADDRESS);
110 if (ret)
111 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
112 CONFIG_EEPROM_CHIP_ADDRESS, ret);
113
114 return ret;
115}
116
Lokesh Vutla1db6b642020-01-07 13:15:55 +0530117int checkboard(void)
118{
119 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
120
121 if (do_board_detect())
122 /* EEPROM not populated */
123 printf("Board: %s rev %s\n", "J721EX-PM1-SOM", "E2");
124 else
125 printf("Board: %s rev %s\n", ep->name, ep->version);
126
127 return 0;
128}
129
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530130static void setup_board_eeprom_env(void)
131{
132 char *name = "j721e";
133
134 if (do_board_detect())
135 goto invalid_eeprom;
136
137 if (board_is_j721e_som())
138 name = "j721e";
139 else
140 printf("Unidentified board claims %s in eeprom header\n",
141 board_ti_get_name());
142
143invalid_eeprom:
144 set_board_info_env_am6(name);
145}
146
147static void setup_serial(void)
148{
149 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
150 unsigned long board_serial;
151 char *endp;
152 char serial_string[17] = { 0 };
153
154 if (env_get("serial#"))
155 return;
156
157 board_serial = simple_strtoul(ep->serial, &endp, 16);
158 if (*endp != '\0') {
159 pr_err("Error: Can't set serial# to %s\n", ep->serial);
160 return;
161 }
162
163 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
164 env_set("serial#", serial_string);
165}
166
167/*
168 * Declaration of daughtercards to probe. Note that when adding more
169 * cards they should be grouped by the 'i2c_addr' field to allow for a
170 * more efficient probing process.
171 */
172static const struct {
173 u8 i2c_addr; /* I2C address of card EEPROM */
174 char *card_name; /* EEPROM-programmed card name */
175 char *dtbo_name; /* Device tree overlay to apply */
176 u8 eth_offset; /* ethXaddr MAC address index offset */
177} ext_cards[] = {
178 {
179 0x51,
180 "J7X-BASE-CPB",
181 "", /* No dtbo for this board */
182 0,
183 },
184 {
185 0x52,
186 "J7X-INFOTAN-EXP",
187 "", /* No dtbo for this board */
188 0,
189 },
190 {
191 0x52,
192 "J7X-GESI-EXP",
193 "", /* No dtbo for this board */
194 5, /* Start populating from eth5addr */
195 },
196 {
197 0x54,
198 "J7X-VSC8514-ETH",
199 "", /* No dtbo for this board */
200 1, /* Start populating from eth1addr */
201 },
202};
203
204static bool daughter_card_detect_flags[ARRAY_SIZE(ext_cards)];
205
206const char *board_fit_get_additionnal_images(int index, const char *type)
207{
208 int i, j;
209
210 if (strcmp(type, FIT_FDT_PROP))
211 return NULL;
212
213 j = 0;
214 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
215 if (daughter_card_detect_flags[i]) {
216 if (j == index) {
217 /*
218 * Return dtbo name only if populated,
219 * otherwise stop parsing here.
220 */
221 if (strlen(ext_cards[i].dtbo_name))
222 return ext_cards[i].dtbo_name;
223 else
224 return NULL;
225 };
226
227 j++;
228 }
229 }
230
231 return NULL;
232}
233
234static int probe_daughtercards(void)
235{
236 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
237 bool eeprom_read_success;
238 struct ti_am6_eeprom ep;
239 u8 previous_i2c_addr;
240 u8 mac_addr_cnt;
241 int i;
242 int ret;
243
244 /* Mark previous I2C address variable as not populated */
245 previous_i2c_addr = 0xff;
246
247 /* No EEPROM data was read yet */
248 eeprom_read_success = false;
249
250 /* Iterate through list of daughtercards */
251 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
252 /* Obtain card-specific I2C address */
253 u8 i2c_addr = ext_cards[i].i2c_addr;
254
255 /* Read card EEPROM if not already read previously */
256 if (i2c_addr != previous_i2c_addr) {
257 /* Store I2C address so we can avoid reading twice */
258 previous_i2c_addr = i2c_addr;
259
260 /* Get and parse the daughter card EEPROM record */
261 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS,
262 i2c_addr,
263 &ep,
264 (char **)mac_addr,
265 DAUGHTER_CARD_NO_OF_MAC_ADDR,
266 &mac_addr_cnt);
267 if (ret) {
268 debug("%s: No daughtercard EEPROM at 0x%02x found %d\n",
269 __func__, i2c_addr, ret);
270 eeprom_read_success = false;
271 /* Skip to the next daughtercard to probe */
272 continue;
273 }
274
275 /* EEPROM read successful, okay to further process. */
276 eeprom_read_success = true;
277 }
278
279 /* Only continue processing if EEPROM data was read */
280 if (!eeprom_read_success)
281 continue;
282
283 /* Only process the parsed data if we found a match */
284 if (strncmp(ep.name, ext_cards[i].card_name, sizeof(ep.name)))
285 continue;
286
287 printf("Detected: %s rev %s\n", ep.name, ep.version);
288 daughter_card_detect_flags[i] = true;
289
290#ifndef CONFIG_SPL_BUILD
291 int j;
292 /*
293 * Populate any MAC addresses from daughtercard into the U-Boot
294 * environment, starting with a card-specific offset so we can
295 * have multiple ext_cards contribute to the MAC pool in a well-
296 * defined manner.
297 */
298 for (j = 0; j < mac_addr_cnt; j++) {
299 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
300 continue;
301
302 eth_env_set_enetaddr_by_index("eth",
303 ext_cards[i].eth_offset + j,
304 (uchar *)mac_addr[j]);
305 }
Suman Anna8eac9e62019-06-13 10:29:50 +0530306#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530307 }
308#ifndef CONFIG_SPL_BUILD
309 char name_overlays[1024] = { 0 };
310
311 for (i = 0; i < ARRAY_SIZE(ext_cards); i++) {
312 if (!daughter_card_detect_flags[i])
313 continue;
314
315 /* Skip if no overlays are to be added */
316 if (!strlen(ext_cards[i].dtbo_name))
317 continue;
318
319 /*
320 * Make sure we are not running out of buffer space by checking
321 * if we can fit the new overlay, a trailing space to be used
322 * as a separator, plus the terminating zero.
323 */
324 if (strlen(name_overlays) + strlen(ext_cards[i].dtbo_name) + 2 >
325 sizeof(name_overlays))
326 return -ENOMEM;
327
328 /* Append to our list of overlays */
329 strcat(name_overlays, ext_cards[i].dtbo_name);
330 strcat(name_overlays, " ");
331 }
332
333 /* Apply device tree overlay(s) to the U-Boot environment, if any */
334 if (strlen(name_overlays))
335 return env_set("name_overlays", name_overlays);
336#endif
337
338 return 0;
339}
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530340#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530341
342int board_late_init(void)
343{
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530344 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
345 setup_board_eeprom_env();
346 setup_serial();
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530347
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530348 /* Check for and probe any plugged-in daughtercards */
349 probe_daughtercards();
350 }
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530351
352 return 0;
353}
354
355void spl_board_init(void)
356{
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200357#if defined(CONFIG_ESM_K3) || defined(CONFIG_ESM_PMIC)
358 struct udevice *dev;
359 int ret;
360#endif
361
Lokesh Vutla5a08e652020-08-05 22:44:14 +0530362 if (IS_ENABLED(CONFIG_TARGET_J721E_A72_EVM) &&
363 IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
364 probe_daughtercards();
Tero Kristo1a2c7ba2020-02-14 11:18:19 +0200365
366#ifdef CONFIG_ESM_K3
367 if (board_ti_k3_is("J721EX-PM2-SOM")) {
368 ret = uclass_get_device_by_driver(UCLASS_MISC,
369 DM_GET_DRIVER(k3_esm), &dev);
370 if (ret)
371 printf("ESM init failed: %d\n", ret);
372 }
373#endif
374
375#ifdef CONFIG_ESM_PMIC
376 if (board_ti_k3_is("J721EX-PM2-SOM")) {
377 ret = uclass_get_device_by_driver(UCLASS_MISC,
378 DM_GET_DRIVER(pmic_esm),
379 &dev);
380 if (ret)
381 printf("ESM PMIC init failed: %d\n", ret);
382 }
383#endif
Andreas Dannenbergd036a212020-01-07 13:15:54 +0530384}