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