blob: 4438f14e4ff175b31351b864fc46e0f4a27e43f2 [file] [log] [blame]
Lokesh Vutla029f9212018-08-27 15:59:06 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for AM654 EVM
4 *
5 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 *
8 */
9
10#include <common.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050011#include <dm.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 Glass274e0b02020-05-10 11:39:56 -060015#include <net.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050016#include <asm/arch/sys_proto.h>
17#include <asm/arch/hardware.h>
18#include <asm/gpio.h>
Lokesh Vutla029f9212018-08-27 15:59:06 +053019#include <asm/io.h>
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050020#include <asm/omap_common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060021#include <env.h>
Lokesh Vutla029f9212018-08-27 15:59:06 +053022#include <spl.h>
Lokesh Vutla79de9ef2019-03-08 11:47:35 +053023#include <asm/arch/sys_proto.h>
Lokesh Vutla029f9212018-08-27 15:59:06 +053024
Andreas Dannenberg63f5c852019-06-04 18:08:26 -050025#include "../common/board_detect.h"
26
27#define board_is_am65x_base_board() board_ti_is("AM6-COMPROCEVM")
28
29/* Daughter card presence detection signals */
30enum {
31 AM65X_EVM_APP_BRD_DET,
32 AM65X_EVM_LCD_BRD_DET,
33 AM65X_EVM_SERDES_BRD_DET,
34 AM65X_EVM_HDMI_GPMC_BRD_DET,
35 AM65X_EVM_BRD_DET_COUNT,
36};
37
38/* Max number of MAC addresses that are parsed/processed per daughter card */
39#define DAUGHTER_CARD_NO_OF_MAC_ADDR 8
40
Aswath Govindrajua698af22020-11-20 21:18:53 +053041/* Regiter that controls the SERDES0 lane and clock assignment */
42#define CTRLMMR_SERDES0_CTRL 0x00104080
43#define PCIE_LANE0 0x1
44
Lokesh Vutla029f9212018-08-27 15:59:06 +053045DECLARE_GLOBAL_DATA_PTR;
46
47int board_init(void)
48{
49 return 0;
50}
51
52int dram_init(void)
53{
54#ifdef CONFIG_PHYS_64BIT
55 gd->ram_size = 0x100000000;
56#else
57 gd->ram_size = 0x80000000;
58#endif
59
60 return 0;
61}
62
63ulong board_get_usable_ram_top(ulong total_size)
64{
65#ifdef CONFIG_PHYS_64BIT
66 /* Limit RAM used by U-Boot to the DDR low region */
67 if (gd->ram_top > 0x100000000)
68 return 0x100000000;
69#endif
70
71 return gd->ram_top;
72}
73
74int dram_init_banksize(void)
75{
76 /* Bank 0 declares the memory available in the DDR low region */
77 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
78 gd->bd->bi_dram[0].size = 0x80000000;
Jan Kiszka7ce99f72020-05-18 07:57:22 +020079 gd->ram_size = 0x80000000;
Lokesh Vutla029f9212018-08-27 15:59:06 +053080
81#ifdef CONFIG_PHYS_64BIT
82 /* Bank 1 declares the memory available in the DDR high region */
83 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
84 gd->bd->bi_dram[1].size = 0x80000000;
Jan Kiszka7ce99f72020-05-18 07:57:22 +020085 gd->ram_size = 0x100000000;
Lokesh Vutla029f9212018-08-27 15:59:06 +053086#endif
87
88 return 0;
89}
Lokesh Vutla8bfaf012018-08-27 15:59:08 +053090
91#ifdef CONFIG_SPL_LOAD_FIT
92int board_fit_config_name_match(const char *name)
93{
94#ifdef CONFIG_TARGET_AM654_A53_EVM
95 if (!strcmp(name, "k3-am654-base-board"))
96 return 0;
97#endif
98
99 return -1;
100}
101#endif
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530102
103#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900104int ft_board_setup(void *blob, struct bd_info *bd)
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530105{
106 int ret;
107
Suman Anna4a122852020-07-29 13:41:12 -0500108 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
109 if (ret < 0)
110 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
111 "sram@70000000");
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400112 if (ret) {
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530113 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400114 return ret;
115 }
116
117#if defined(CONFIG_TI_SECURE_DEVICE)
Andrew F. Davis5e7dc6c2020-06-09 15:14:22 -0400118 /* Make Crypto HW reserved for secure world use */
Suman Anna4a122852020-07-29 13:41:12 -0500119 ret = fdt_disable_node(blob, "/bus@100000/crypto@4e00000");
120 if (ret < 0)
121 ret = fdt_disable_node(blob,
122 "/interconnect@100000/crypto@4E00000");
Andrew F. Davis7e13f2c2020-01-07 18:12:40 -0500123 if (ret)
Andrew F. Davis5e7dc6c2020-06-09 15:14:22 -0400124 printf("%s: disabling SA2UL failed %d\n", __func__, ret);
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400125#endif
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530126
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400127 return 0;
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530128}
129#endif
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500130
131int do_board_detect(void)
132{
133 int ret;
134
135 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
136 CONFIG_EEPROM_CHIP_ADDRESS);
137 if (ret)
138 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
139 CONFIG_EEPROM_CHIP_ADDRESS, ret);
140
141 return ret;
142}
143
Lokesh Vutla1ffb8c12019-09-27 13:32:12 +0530144int checkboard(void)
145{
146 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
147
148 if (do_board_detect())
149 /* EEPROM not populated */
150 printf("Board: %s rev %s\n", "AM6-COMPROCEVM", "E3");
151 else
152 printf("Board: %s rev %s\n", ep->name, ep->version);
153
154 return 0;
155}
156
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500157static void setup_board_eeprom_env(void)
158{
159 char *name = "am65x";
160
161 if (do_board_detect())
162 goto invalid_eeprom;
163
164 if (board_is_am65x_base_board())
165 name = "am65x";
166 else
167 printf("Unidentified board claims %s in eeprom header\n",
168 board_ti_get_name());
169
170invalid_eeprom:
171 set_board_info_env_am6(name);
172}
173
174static int init_daughtercard_det_gpio(char *gpio_name, struct gpio_desc *desc)
175{
176 int ret;
177
178 memset(desc, 0, sizeof(*desc));
179
180 ret = dm_gpio_lookup_name(gpio_name, desc);
181 if (ret < 0)
182 return ret;
183
184 /* Request GPIO, simply re-using the name as label */
185 ret = dm_gpio_request(desc, gpio_name);
186 if (ret < 0)
187 return ret;
188
189 return dm_gpio_set_dir_flags(desc, GPIOD_IS_IN);
190}
191
192static int probe_daughtercards(void)
193{
194 struct ti_am6_eeprom ep;
195 struct gpio_desc board_det_gpios[AM65X_EVM_BRD_DET_COUNT];
196 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
197 u8 mac_addr_cnt;
198 char name_overlays[1024] = { 0 };
199 int i, j;
200 int ret;
201
202 /*
203 * Daughter card presence detection signal name to GPIO (via I2C I/O
204 * expander @ address 0x38) name and EEPROM I2C address mapping.
205 */
206 const struct {
207 char *gpio_name;
208 u8 i2c_addr;
209 } slot_map[AM65X_EVM_BRD_DET_COUNT] = {
210 { "gpio@38_0", 0x52, }, /* AM65X_EVM_APP_BRD_DET */
211 { "gpio@38_1", 0x55, }, /* AM65X_EVM_LCD_BRD_DET */
212 { "gpio@38_2", 0x54, }, /* AM65X_EVM_SERDES_BRD_DET */
213 { "gpio@38_3", 0x53, }, /* AM65X_EVM_HDMI_GPMC_BRD_DET */
214 };
215
216 /* Declaration of daughtercards to probe */
217 const struct {
218 u8 slot_index; /* Slot the card is installed */
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 } cards[] = {
223 {
224 AM65X_EVM_APP_BRD_DET,
225 "AM6-GPAPPEVM",
226 "k3-am654-gp.dtbo",
227 0,
228 },
229 {
230 AM65X_EVM_APP_BRD_DET,
231 "AM6-IDKAPPEVM",
232 "k3-am654-idk.dtbo",
233 3,
234 },
235 {
236 AM65X_EVM_SERDES_BRD_DET,
237 "SER-PCIE2LEVM",
238 "k3-am654-pcie-usb2.dtbo",
239 0,
240 },
241 {
242 AM65X_EVM_SERDES_BRD_DET,
243 "SER-PCIEUSBEVM",
244 "k3-am654-pcie-usb3.dtbo",
245 0,
246 },
247 {
248 AM65X_EVM_LCD_BRD_DET,
249 "OLDI-LCD1EVM",
250 "k3-am654-evm-oldi-lcd1evm.dtbo",
251 0,
252 },
253 };
254
255 /*
256 * Initialize GPIO used for daughtercard slot presence detection and
257 * keep the resulting handles in local array for easier access.
258 */
259 for (i = 0; i < AM65X_EVM_BRD_DET_COUNT; i++) {
260 ret = init_daughtercard_det_gpio(slot_map[i].gpio_name,
261 &board_det_gpios[i]);
262 if (ret < 0)
263 return ret;
264 }
265
266 for (i = 0; i < ARRAY_SIZE(cards); i++) {
267 /* Obtain card-specific slot index and associated I2C address */
268 u8 slot_index = cards[i].slot_index;
269 u8 i2c_addr = slot_map[slot_index].i2c_addr;
270
271 /*
272 * The presence detection signal is active-low, hence skip
273 * over this card slot if anything other than 0 is returned.
274 */
275 ret = dm_gpio_get_value(&board_det_gpios[slot_index]);
276 if (ret < 0)
277 return ret;
278 else if (ret)
279 continue;
280
281 /* Get and parse the daughter card EEPROM record */
282 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, i2c_addr,
283 &ep,
284 (char **)mac_addr,
285 DAUGHTER_CARD_NO_OF_MAC_ADDR,
286 &mac_addr_cnt);
287 if (ret) {
288 pr_err("Reading daughtercard EEPROM at 0x%02x failed %d\n",
289 i2c_addr, ret);
290 /*
291 * Even this is pretty serious let's just skip over
292 * this particular daughtercard, rather than ending
293 * the probing process altogether.
294 */
295 continue;
296 }
297
298 /* Only process the parsed data if we found a match */
299 if (strncmp(ep.name, cards[i].card_name, sizeof(ep.name)))
300 continue;
301
Lokesh Vutla1ffb8c12019-09-27 13:32:12 +0530302 printf("Detected: %s rev %s\n", ep.name, ep.version);
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500303
304 /*
305 * Populate any MAC addresses from daughtercard into the U-Boot
306 * environment, starting with a card-specific offset so we can
307 * have multiple cards contribute to the MAC pool in a well-
308 * defined manner.
309 */
310 for (j = 0; j < mac_addr_cnt; j++) {
311 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
312 continue;
313
314 eth_env_set_enetaddr_by_index("eth",
315 cards[i].eth_offset + j,
316 (uchar *)mac_addr[j]);
317 }
318
Aswath Govindrajua698af22020-11-20 21:18:53 +0530319 /*
320 * It has been observed that setting SERDES0 lane mux to USB prevents USB
321 * 2.0 operation on USB0. Setting SERDES0 lane mux to non-USB when USB0 is
322 * used in USB 2.0 only mode solves this issue. For USB3.0+2.0 operation
323 * this issue is not present.
324 *
325 * Implement this workaround by writing 1 to LANE_FUNC_SEL field in
326 * CTRLMMR_SERDES0_CTRL register.
327 */
328 if (!strncmp(ep.name, "SER-PCIE2LEVM", sizeof(ep.name)))
329 writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL);
330
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500331 /* Skip if no overlays are to be added */
332 if (!strlen(cards[i].dtbo_name))
333 continue;
334
335 /*
336 * Make sure we are not running out of buffer space by checking
337 * if we can fit the new overlay, a trailing space to be used
338 * as a separator, plus the terminating zero.
339 */
340 if (strlen(name_overlays) + strlen(cards[i].dtbo_name) + 2 >
341 sizeof(name_overlays))
342 return -ENOMEM;
343
344 /* Append to our list of overlays */
345 strcat(name_overlays, cards[i].dtbo_name);
346 strcat(name_overlays, " ");
347 }
348
349 /* Apply device tree overlay(s) to the U-Boot environment, if any */
350 if (strlen(name_overlays))
351 return env_set("name_overlays", name_overlays);
352
353 return 0;
354}
355
356int board_late_init(void)
357{
358 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
359
360 setup_board_eeprom_env();
361
362 /*
363 * The first MAC address for ethernet a.k.a. ethernet0 comes from
364 * efuse populated via the am654 gigabit eth switch subsystem driver.
365 * All the other ones are populated via EEPROM, hence continue with
366 * an index of 1.
367 */
368 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
369
370 /* Check for and probe any plugged-in daughtercards */
371 probe_daughtercards();
372
373 return 0;
374}