blob: 8373c768f189332d0cf1a6b9512af3658f77aabc [file] [log] [blame]
Dave Gerlach3dc33f12021-04-23 11:27:42 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Board specific initialization for AM642 EVM
4 *
5 * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/
6 * Keerthy <j-keerthy@ti.com>
7 *
8 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <spl.h>
Aswath Govindrajue910fac2021-08-04 18:42:44 +053013#include <fdt_support.h>
Lokesh Vutla01032a42021-05-06 16:44:49 +053014#include <asm/arch/hardware.h>
15#include <asm/arch/sys_proto.h>
16#include <env.h>
17
18#include "../common/board_detect.h"
19
20#define board_is_am64x_gpevm() board_ti_k3_is("AM64-GPEVM")
21#define board_is_am64x_skevm() board_ti_k3_is("AM64-SKEVM")
Dave Gerlach3dc33f12021-04-23 11:27:42 -050022
23DECLARE_GLOBAL_DATA_PTR;
24
25int board_init(void)
26{
27 return 0;
28}
29
30int dram_init(void)
31{
32 gd->ram_size = 0x80000000;
33
34 return 0;
35}
36
37int dram_init_banksize(void)
38{
39 /* Bank 0 declares the memory available in the DDR low region */
40 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
41 gd->bd->bi_dram[0].size = 0x80000000;
42 gd->ram_size = 0x80000000;
43
44 return 0;
45}
46
47#if defined(CONFIG_SPL_LOAD_FIT)
48int board_fit_config_name_match(const char *name)
49{
Lokesh Vutla8af2b692021-05-06 16:44:51 +053050 bool eeprom_read = board_ti_was_eeprom_read();
51
52 if (!eeprom_read || board_is_am64x_gpevm()) {
53 if (!strcmp(name, "k3-am642-r5-evm") || !strcmp(name, "k3-am642-evm"))
54 return 0;
55 } else if (board_is_am64x_skevm()) {
56 if (!strcmp(name, "k3-am642-r5-sk") || !strcmp(name, "k3-am642-sk"))
57 return 0;
58 }
Dave Gerlach3dc33f12021-04-23 11:27:42 -050059
60 return -1;
61}
62#endif
Lokesh Vutla01032a42021-05-06 16:44:49 +053063
Aswath Govindrajue910fac2021-08-04 18:42:44 +053064#if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USB_STORAGE)
65static int fixup_usb_boot(const void *fdt_blob)
66{
67 int ret = 0;
68
69 switch (spl_boot_device()) {
70 case BOOT_DEVICE_USB:
71 /*
72 * If the boot mode is host, fixup the dr_mode to host
73 * before cdns3 bind takes place
74 */
75 ret = fdt_find_and_setprop((void *)fdt_blob,
76 "/bus@f4000/cdns-usb@f900000/usb@f400000",
77 "dr_mode", "host", 5, 0);
78 if (ret)
79 printf("%s: fdt_find_and_setprop() failed:%d\n",
80 __func__, ret);
81 fallthrough;
82 default:
83 break;
84 }
85
86 return ret;
87}
88
89void spl_perform_fixups(struct spl_image_info *spl_image)
90{
91 fixup_usb_boot(spl_image->fdt_addr);
92}
93#endif
94
Lokesh Vutla01032a42021-05-06 16:44:49 +053095#ifdef CONFIG_TI_I2C_BOARD_DETECT
96int do_board_detect(void)
97{
98 int ret;
99
100 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
101 CONFIG_EEPROM_CHIP_ADDRESS);
102 if (ret) {
103 printf("EEPROM not available at 0x%02x, trying to read at 0x%02x\n",
104 CONFIG_EEPROM_CHIP_ADDRESS, CONFIG_EEPROM_CHIP_ADDRESS + 1);
105 ret = ti_i2c_eeprom_am6_get_base(CONFIG_EEPROM_BUS_ADDRESS,
106 CONFIG_EEPROM_CHIP_ADDRESS + 1);
107 if (ret)
108 pr_err("Reading on-board EEPROM at 0x%02x failed %d\n",
109 CONFIG_EEPROM_CHIP_ADDRESS + 1, ret);
110 }
111
112 return ret;
113}
114
115int checkboard(void)
116{
117 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
118
119 if (!do_board_detect())
120 printf("Board: %s rev %s\n", ep->name, ep->version);
121
122 return 0;
123}
124
125#ifdef CONFIG_BOARD_LATE_INIT
126static void setup_board_eeprom_env(void)
127{
128 char *name = "am64x_gpevm";
129
130 if (do_board_detect())
131 goto invalid_eeprom;
132
133 if (board_is_am64x_gpevm())
134 name = "am64x_gpevm";
135 else if (board_is_am64x_skevm())
136 name = "am64x_skevm";
137 else
138 printf("Unidentified board claims %s in eeprom header\n",
139 board_ti_get_name());
140
141invalid_eeprom:
142 set_board_info_env_am6(name);
143}
144
145static void setup_serial(void)
146{
147 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
148 unsigned long board_serial;
149 char *endp;
150 char serial_string[17] = { 0 };
151
152 if (env_get("serial#"))
153 return;
154
Simon Glass3ff49ec2021-07-24 09:03:29 -0600155 board_serial = hextoul(ep->serial, &endp);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530156 if (*endp != '\0') {
157 pr_err("Error: Can't set serial# to %s\n", ep->serial);
158 return;
159 }
160
161 snprintf(serial_string, sizeof(serial_string), "%016lx", board_serial);
162 env_set("serial#", serial_string);
163}
164#endif
165#endif
166
167#ifdef CONFIG_BOARD_LATE_INIT
168int board_late_init(void)
169{
170 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT)) {
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530171 struct ti_am6_eeprom *ep = TI_AM6_EEPROM_DATA;
172
Lokesh Vutla01032a42021-05-06 16:44:49 +0530173 setup_board_eeprom_env();
174 setup_serial();
Vignesh Raghavendra3349e212021-05-10 23:44:22 +0530175 /*
176 * The first MAC address for ethernet a.k.a. ethernet0 comes from
177 * efuse populated via the am654 gigabit eth switch subsystem driver.
178 * All the other ones are populated via EEPROM, hence continue with
179 * an index of 1.
180 */
181 board_ti_am6_set_ethaddr(1, ep->mac_addr_cnt);
Lokesh Vutla01032a42021-05-06 16:44:49 +0530182 }
183
184 return 0;
185}
186#endif
Aswath Govindrajucb962f92021-06-04 22:00:34 +0530187
188#define CTRLMMR_USB0_PHY_CTRL 0x43004008
189#define CORE_VOLTAGE 0x80000000
190
191#ifdef CONFIG_SPL_BOARD_INIT
192void spl_board_init(void)
193{
194 u32 val;
195 /* Set USB PHY core voltage to 0.85V */
196 val = readl(CTRLMMR_USB0_PHY_CTRL);
197 val &= ~(CORE_VOLTAGE);
198 writel(val, CTRLMMR_USB0_PHY_CTRL);
Vignesh Raghavendradfcda512021-12-24 12:55:31 +0530199
200 /* Init DRAM size for R5/A53 SPL */
201 dram_init_banksize();
Aswath Govindrajucb962f92021-06-04 22:00:34 +0530202}
203#endif