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