blob: 8c4b3491b141171c1f40f955db89588bd36f109c [file] [log] [blame]
Suman Anna27fa4122022-05-25 13:38:42 +05301// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM625: SoC specific initialization
4 *
5 * Copyright (C) 2020-2022 Texas Instruments Incorporated - https://www.ti.com/
6 * Suman Anna <s-anna@ti.com>
7 */
8
9#include <spl.h>
10#include <asm/io.h>
11#include <asm/arch/hardware.h>
12#include <asm/arch/sysfw-loader.h>
13#include "common.h"
14#include <dm.h>
15#include <dm/uclass-internal.h>
16#include <dm/pinctrl.h>
17
Suman Anna27fa4122022-05-25 13:38:42 +053018/*
19 * This uninitialized global variable would normal end up in the .bss section,
20 * but the .bss is cleared between writing and reading this variable, so move
21 * it to the .data section.
22 */
23u32 bootindex __section(".data");
24static struct rom_extended_boot_data bootdata __section(".data");
25
26static void store_boot_info_from_rom(void)
27{
28 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
29 memcpy(&bootdata, (uintptr_t *)ROM_ENTENDED_BOOT_DATA_INFO,
30 sizeof(struct rom_extended_boot_data));
31}
32
33static void ctrl_mmr_unlock(void)
34{
35 /* Unlock all WKUP_CTRL_MMR0 module registers */
36 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
37 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
38 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
41 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
44
45 /* Unlock all CTRL_MMR0 module registers */
46 mmr_unlock(CTRL_MMR0_BASE, 0);
47 mmr_unlock(CTRL_MMR0_BASE, 1);
48 mmr_unlock(CTRL_MMR0_BASE, 2);
49 mmr_unlock(CTRL_MMR0_BASE, 4);
50 mmr_unlock(CTRL_MMR0_BASE, 6);
51
52 /* Unlock all MCU_CTRL_MMR0 module registers */
53 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
54 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
55 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
56 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
57 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
59
60 /* Unlock PADCFG_CTRL_MMR padconf registers */
61 mmr_unlock(PADCFG_MMR0_BASE, 1);
62 mmr_unlock(PADCFG_MMR1_BASE, 1);
63}
64
Julien Panis01b00d42022-07-01 14:30:11 +020065static __maybe_unused void enable_mcu_esm_reset(void)
66{
67 /* Set CTRLMMR_MCU_RST_CTRL:MCU_ESM_ERROR_RST_EN_Z to '0' (low active) */
68 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
69
70 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
71 writel(stat, CTRLMMR_MCU_RST_CTRL);
72}
73
Suman Anna27fa4122022-05-25 13:38:42 +053074void board_init_f(ulong dummy)
75{
76 struct udevice *dev;
77 int ret;
78
79#if defined(CONFIG_CPU_V7R)
80 setup_k3_mpu_regions();
81#endif
82
83 /*
84 * Cannot delay this further as there is a chance that
85 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
86 */
87 store_boot_info_from_rom();
88
89 ctrl_mmr_unlock();
90
91 /* Init DM early */
92 spl_early_init();
93
94 /*
95 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
96 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
97 * Do this without probing the device, but instead by searching the
98 * device that would request the given sequence number if probed. The
99 * UARTs will be used by the DM firmware and TIFS firmware images
100 * respectively and the firmware depend on SPL to initialize the pin
101 * settings.
102 */
103 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
104 if (!ret)
105 pinctrl_select_state(dev, "default");
106
107 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
108 if (!ret)
109 pinctrl_select_state(dev, "default");
110
111 preloader_console_init();
112
113#ifdef CONFIG_K3_EARLY_CONS
114 /*
115 * Allow establishing an early console as required for example when
116 * doing a UART-based boot. Note that this console may not "survive"
117 * through a SYSFW PM-init step and will need a re-init in some way
118 * due to changing module clock frequencies.
119 */
120 early_console_init();
121#endif
122
123#if defined(CONFIG_K3_LOAD_SYSFW)
124 /*
125 * Configure and start up system controller firmware. Provide
126 * the U-Boot console init function to the SYSFW post-PM configuration
127 * callback hook, effectively switching on (or over) the console
128 * output.
129 */
130 ret = is_rom_loaded_sysfw(&bootdata);
131 if (!ret)
132 panic("ROM has not loaded TIFS firmware\n");
133
134 k3_sysfw_loader(true, NULL, NULL);
135#endif
136
137 /*
138 * Force probe of clk_k3 driver here to ensure basic default clock
139 * configuration is always done.
140 */
141 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
142 ret = uclass_get_device_by_driver(UCLASS_CLK,
143 DM_DRIVER_GET(ti_clk),
144 &dev);
145 if (ret)
146 printf("Failed to initialize clk-k3!\n");
147 }
148
149 /* Output System Firmware version info */
150 k3_sysfw_print_ver();
151
Julien Panis01b00d42022-07-01 14:30:11 +0200152 if (IS_ENABLED(CONFIG_ESM_K3)) {
153 /* Probe/configure ESM0 */
154 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
155 if (ret)
156 printf("esm main init failed: %d\n", ret);
157
158 /* Probe/configure MCUESM */
159 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
160 if (ret)
161 printf("esm mcu init failed: %d\n", ret);
162
163 enable_mcu_esm_reset();
164 }
165
Suman Anna27fa4122022-05-25 13:38:42 +0530166#if defined(CONFIG_K3_AM64_DDRSS)
167 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
168 if (ret)
169 panic("DRAM init failed: %d\n", ret);
170#endif
171}
172
173u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
174{
175 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
176 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
177 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
178
179 switch (boot_device) {
180 case BOOT_DEVICE_MMC1:
181 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK) >>
182 MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_SHIFT)
183 return MMCSD_MODE_EMMCBOOT;
184 return MMCSD_MODE_FS;
185
186 case BOOT_DEVICE_MMC2:
187 return MMCSD_MODE_FS;
188
189 default:
190 return MMCSD_MODE_RAW;
191 }
192}
193
194static u32 __get_backup_bootmedia(u32 devstat)
195{
196 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
197 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
198 u32 bkup_bootmode_cfg =
199 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
200 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
201
202 switch (bkup_bootmode) {
203 case BACKUP_BOOT_DEVICE_UART:
204 return BOOT_DEVICE_UART;
205
206 case BACKUP_BOOT_DEVICE_USB:
207 return BOOT_DEVICE_USB;
208
209 case BACKUP_BOOT_DEVICE_ETHERNET:
210 return BOOT_DEVICE_ETHERNET;
211
212 case BACKUP_BOOT_DEVICE_MMC:
213 if (bkup_bootmode_cfg)
214 return BOOT_DEVICE_MMC2;
215 return BOOT_DEVICE_MMC1;
216
217 case BACKUP_BOOT_DEVICE_SPI:
218 return BOOT_DEVICE_SPI;
219
220 case BACKUP_BOOT_DEVICE_I2C:
221 return BOOT_DEVICE_I2C;
222
223 case BACKUP_BOOT_DEVICE_DFU:
224 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
225 return BOOT_DEVICE_USB;
226 return BOOT_DEVICE_DFU;
227 };
228
229 return BOOT_DEVICE_RAM;
230}
231
232static u32 __get_primary_bootmedia(u32 devstat)
233{
234 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
235 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
236 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
237 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
238
239 switch (bootmode) {
240 case BOOT_DEVICE_OSPI:
241 fallthrough;
242 case BOOT_DEVICE_QSPI:
243 fallthrough;
244 case BOOT_DEVICE_XSPI:
245 fallthrough;
246 case BOOT_DEVICE_SPI:
247 return BOOT_DEVICE_SPI;
248
249 case BOOT_DEVICE_ETHERNET_RGMII:
250 fallthrough;
251 case BOOT_DEVICE_ETHERNET_RMII:
252 return BOOT_DEVICE_ETHERNET;
253
254 case BOOT_DEVICE_EMMC:
255 return BOOT_DEVICE_MMC1;
256
257 case BOOT_DEVICE_MMC:
258 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
259 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
260 return BOOT_DEVICE_MMC2;
261 return BOOT_DEVICE_MMC1;
262
263 case BOOT_DEVICE_DFU:
264 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
265 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
266 return BOOT_DEVICE_USB;
267 return BOOT_DEVICE_DFU;
268
269 case BOOT_DEVICE_NOBOOT:
270 return BOOT_DEVICE_RAM;
271 }
272
273 return bootmode;
274}
275
276u32 spl_boot_device(void)
277{
278 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
279 u32 bootmedia;
280
281 if (bootindex == K3_PRIMARY_BOOTMODE)
282 bootmedia = __get_primary_bootmedia(devstat);
283 else
284 bootmedia = __get_backup_bootmedia(devstat);
285
286 debug("am625_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
287 __func__, devstat, bootmedia, bootindex);
288
289 return bootmedia;
290}