blob: 36063b11383dd96ffd322b26aa40f9ffc20968a6 [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
Lokesh Vutla029f9212018-08-27 15:59:06 +053041DECLARE_GLOBAL_DATA_PTR;
42
43int board_init(void)
44{
45 return 0;
46}
47
48int dram_init(void)
49{
50#ifdef CONFIG_PHYS_64BIT
51 gd->ram_size = 0x100000000;
52#else
53 gd->ram_size = 0x80000000;
54#endif
55
56 return 0;
57}
58
59ulong board_get_usable_ram_top(ulong total_size)
60{
61#ifdef CONFIG_PHYS_64BIT
62 /* Limit RAM used by U-Boot to the DDR low region */
63 if (gd->ram_top > 0x100000000)
64 return 0x100000000;
65#endif
66
67 return gd->ram_top;
68}
69
70int dram_init_banksize(void)
71{
72 /* Bank 0 declares the memory available in the DDR low region */
73 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
74 gd->bd->bi_dram[0].size = 0x80000000;
Jan Kiszka7ce99f72020-05-18 07:57:22 +020075 gd->ram_size = 0x80000000;
Lokesh Vutla029f9212018-08-27 15:59:06 +053076
77#ifdef CONFIG_PHYS_64BIT
78 /* Bank 1 declares the memory available in the DDR high region */
79 gd->bd->bi_dram[1].start = CONFIG_SYS_SDRAM_BASE1;
80 gd->bd->bi_dram[1].size = 0x80000000;
Jan Kiszka7ce99f72020-05-18 07:57:22 +020081 gd->ram_size = 0x100000000;
Lokesh Vutla029f9212018-08-27 15:59:06 +053082#endif
83
84 return 0;
85}
Lokesh Vutla8bfaf012018-08-27 15:59:08 +053086
87#ifdef CONFIG_SPL_LOAD_FIT
88int board_fit_config_name_match(const char *name)
89{
90#ifdef CONFIG_TARGET_AM654_A53_EVM
91 if (!strcmp(name, "k3-am654-base-board"))
92 return 0;
93#endif
94
95 return -1;
96}
97#endif
Lokesh Vutla79de9ef2019-03-08 11:47:35 +053098
99#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900100int ft_board_setup(void *blob, struct bd_info *bd)
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530101{
102 int ret;
103
Suman Anna4a122852020-07-29 13:41:12 -0500104 ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
105 if (ret < 0)
106 ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
107 "sram@70000000");
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400108 if (ret) {
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530109 printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400110 return ret;
111 }
112
113#if defined(CONFIG_TI_SECURE_DEVICE)
Andrew F. Davis5e7dc6c2020-06-09 15:14:22 -0400114 /* Make Crypto HW reserved for secure world use */
Suman Anna4a122852020-07-29 13:41:12 -0500115 ret = fdt_disable_node(blob, "/bus@100000/crypto@4e00000");
116 if (ret < 0)
117 ret = fdt_disable_node(blob,
118 "/interconnect@100000/crypto@4E00000");
Andrew F. Davis7e13f2c2020-01-07 18:12:40 -0500119 if (ret)
Andrew F. Davis5e7dc6c2020-06-09 15:14:22 -0400120 printf("%s: disabling SA2UL failed %d\n", __func__, ret);
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400121#endif
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530122
Andrew F. Davis6c43b522019-09-17 17:15:40 -0400123 return 0;
Lokesh Vutla79de9ef2019-03-08 11:47:35 +0530124}
125#endif
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500126
127int do_board_detect(void)
128{
129 int ret;
130
131 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
132 CONFIG_EEPROM_CHIP_ADDRESS);
133 if (ret)
134 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
135 CONFIG_EEPROM_CHIP_ADDRESS, ret);
136
137 return ret;
138}
139
Lokesh Vutla1ffb8c12019-09-27 13:32:12 +0530140int checkboard(void)
141{
142 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
143
144 if (do_board_detect())
145 /* EEPROM not populated */
146 printf("Board: %s rev %s\n", "AM6-COMPROCEVM", "E3");
147 else
148 printf("Board: %s rev %s\n", ep->name, ep->version);
149
150 return 0;
151}
152
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500153static void setup_board_eeprom_env(void)
154{
155 char *name = "am65x";
156
157 if (do_board_detect())
158 goto invalid_eeprom;
159
160 if (board_is_am65x_base_board())
161 name = "am65x";
162 else
163 printf("Unidentified board claims %s in eeprom header\n",
164 board_ti_get_name());
165
166invalid_eeprom:
167 set_board_info_env_am6(name);
168}
169
170static int init_daughtercard_det_gpio(char *gpio_name, struct gpio_desc *desc)
171{
172 int ret;
173
174 memset(desc, 0, sizeof(*desc));
175
176 ret = dm_gpio_lookup_name(gpio_name, desc);
177 if (ret < 0)
178 return ret;
179
180 /* Request GPIO, simply re-using the name as label */
181 ret = dm_gpio_request(desc, gpio_name);
182 if (ret < 0)
183 return ret;
184
185 return dm_gpio_set_dir_flags(desc, GPIOD_IS_IN);
186}
187
188static int probe_daughtercards(void)
189{
190 struct ti_am6_eeprom ep;
191 struct gpio_desc board_det_gpios[AM65X_EVM_BRD_DET_COUNT];
192 char mac_addr[DAUGHTER_CARD_NO_OF_MAC_ADDR][TI_EEPROM_HDR_ETH_ALEN];
193 u8 mac_addr_cnt;
194 char name_overlays[1024] = { 0 };
195 int i, j;
196 int ret;
197
198 /*
199 * Daughter card presence detection signal name to GPIO (via I2C I/O
200 * expander @ address 0x38) name and EEPROM I2C address mapping.
201 */
202 const struct {
203 char *gpio_name;
204 u8 i2c_addr;
205 } slot_map[AM65X_EVM_BRD_DET_COUNT] = {
206 { "gpio@38_0", 0x52, }, /* AM65X_EVM_APP_BRD_DET */
207 { "gpio@38_1", 0x55, }, /* AM65X_EVM_LCD_BRD_DET */
208 { "gpio@38_2", 0x54, }, /* AM65X_EVM_SERDES_BRD_DET */
209 { "gpio@38_3", 0x53, }, /* AM65X_EVM_HDMI_GPMC_BRD_DET */
210 };
211
212 /* Declaration of daughtercards to probe */
213 const struct {
214 u8 slot_index; /* Slot the card is installed */
215 char *card_name; /* EEPROM-programmed card name */
216 char *dtbo_name; /* Device tree overlay to apply */
217 u8 eth_offset; /* ethXaddr MAC address index offset */
218 } cards[] = {
219 {
220 AM65X_EVM_APP_BRD_DET,
221 "AM6-GPAPPEVM",
222 "k3-am654-gp.dtbo",
223 0,
224 },
225 {
226 AM65X_EVM_APP_BRD_DET,
227 "AM6-IDKAPPEVM",
228 "k3-am654-idk.dtbo",
229 3,
230 },
231 {
232 AM65X_EVM_SERDES_BRD_DET,
233 "SER-PCIE2LEVM",
234 "k3-am654-pcie-usb2.dtbo",
235 0,
236 },
237 {
238 AM65X_EVM_SERDES_BRD_DET,
239 "SER-PCIEUSBEVM",
240 "k3-am654-pcie-usb3.dtbo",
241 0,
242 },
243 {
244 AM65X_EVM_LCD_BRD_DET,
245 "OLDI-LCD1EVM",
246 "k3-am654-evm-oldi-lcd1evm.dtbo",
247 0,
248 },
249 };
250
251 /*
252 * Initialize GPIO used for daughtercard slot presence detection and
253 * keep the resulting handles in local array for easier access.
254 */
255 for (i = 0; i < AM65X_EVM_BRD_DET_COUNT; i++) {
256 ret = init_daughtercard_det_gpio(slot_map[i].gpio_name,
257 &board_det_gpios[i]);
258 if (ret < 0)
259 return ret;
260 }
261
262 for (i = 0; i < ARRAY_SIZE(cards); i++) {
263 /* Obtain card-specific slot index and associated I2C address */
264 u8 slot_index = cards[i].slot_index;
265 u8 i2c_addr = slot_map[slot_index].i2c_addr;
266
267 /*
268 * The presence detection signal is active-low, hence skip
269 * over this card slot if anything other than 0 is returned.
270 */
271 ret = dm_gpio_get_value(&board_det_gpios[slot_index]);
272 if (ret < 0)
273 return ret;
274 else if (ret)
275 continue;
276
277 /* Get and parse the daughter card EEPROM record */
278 ret = ti_i2c_eeprom_am6_get(CONFIG_EEPROM_BUS_ADDRESS, i2c_addr,
279 &ep,
280 (char **)mac_addr,
281 DAUGHTER_CARD_NO_OF_MAC_ADDR,
282 &mac_addr_cnt);
283 if (ret) {
284 pr_err("Reading daughtercard EEPROM at 0x%02x failed %d\n",
285 i2c_addr, ret);
286 /*
287 * Even this is pretty serious let's just skip over
288 * this particular daughtercard, rather than ending
289 * the probing process altogether.
290 */
291 continue;
292 }
293
294 /* Only process the parsed data if we found a match */
295 if (strncmp(ep.name, cards[i].card_name, sizeof(ep.name)))
296 continue;
297
Lokesh Vutla1ffb8c12019-09-27 13:32:12 +0530298 printf("Detected: %s rev %s\n", ep.name, ep.version);
Andreas Dannenberg63f5c852019-06-04 18:08:26 -0500299
300 /*
301 * Populate any MAC addresses from daughtercard into the U-Boot
302 * environment, starting with a card-specific offset so we can
303 * have multiple cards contribute to the MAC pool in a well-
304 * defined manner.
305 */
306 for (j = 0; j < mac_addr_cnt; j++) {
307 if (!is_valid_ethaddr((u8 *)mac_addr[j]))
308 continue;
309
310 eth_env_set_enetaddr_by_index("eth",
311 cards[i].eth_offset + j,
312 (uchar *)mac_addr[j]);
313 }
314
315 /* Skip if no overlays are to be added */
316 if (!strlen(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(cards[i].dtbo_name) + 2 >
325 sizeof(name_overlays))
326 return -ENOMEM;
327
328 /* Append to our list of overlays */
329 strcat(name_overlays, 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
337 return 0;
338}
339
340int board_late_init(void)
341{
342 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
343
344 setup_board_eeprom_env();
345
346 /*
347 * The first MAC address for ethernet a.k.a. ethernet0 comes from
348 * efuse populated via the am654 gigabit eth switch subsystem driver.
349 * All the other ones are populated via EEPROM, hence continue with
350 * an index of 1.
351 */
352 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
353
354 /* Check for and probe any plugged-in daughtercards */
355 probe_daughtercards();
356
357 return 0;
358}