blob: aab99aa0c958f84de7f181932f2e0cf4df0f01ef [file] [log] [blame]
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -05001// SPDX-License-Identifier: GPL-2.0
2/*
3 * AM62P5: 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 "sysfw-loader.h"
12#include "common.h"
13#include <dm.h>
14#include <dm/uclass-internal.h>
15#include <dm/pinctrl.h>
16
17struct fwl_data cbass_main_fwls[] = {
18 { "FSS_DAT_REG3", 7, 8 },
19};
20
21/*
22 * This uninitialized global variable would normal end up in the .bss section,
23 * but the .bss is cleared between writing and reading this variable, so move
24 * it to the .data section.
25 */
26u32 bootindex __section(".data");
27static struct rom_extended_boot_data bootdata __section(".data");
28
29static void store_boot_info_from_rom(void)
30{
31 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
32 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
33 sizeof(struct rom_extended_boot_data));
34}
35
36static void ctrl_mmr_unlock(void)
37{
38 /* Unlock all WKUP_CTRL_MMR0 module registers */
39 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
40 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
41 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
42 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
43 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
44 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
45 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
46 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
47
48 /* Unlock all CTRL_MMR0 module registers */
49 mmr_unlock(CTRL_MMR0_BASE, 0);
50 mmr_unlock(CTRL_MMR0_BASE, 1);
51 mmr_unlock(CTRL_MMR0_BASE, 2);
52 mmr_unlock(CTRL_MMR0_BASE, 4);
53 mmr_unlock(CTRL_MMR0_BASE, 5);
54 mmr_unlock(CTRL_MMR0_BASE, 6);
55
56 /* Unlock all MCU_CTRL_MMR0 module registers */
57 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
58 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
59 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
60 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
61 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
62 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
63
64 /* Unlock PADCFG_CTRL_MMR padconf registers */
65 mmr_unlock(PADCFG_MMR0_BASE, 1);
66 mmr_unlock(PADCFG_MMR1_BASE, 1);
67}
68
69void board_init_f(ulong dummy)
70{
71 struct udevice *dev;
72 int ret;
73
74 if (IS_ENABLED(CONFIG_CPU_V7R))
75 setup_k3_mpu_regions();
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 ret = spl_early_init();
87 if (ret)
88 panic("spl_early_init() failed: %d\n", ret);
89
90 /*
91 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
92 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
93 * Do this without probing the device, but instead by searching the
94 * device that would request the given sequence number if probed. The
95 * UARTs will be used by the DM firmware and TIFS firmware images
96 * respectively and the firmware depend on SPL to initialize the pin
97 * settings.
98 */
99 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
100 if (!ret)
101 pinctrl_select_state(dev, "default");
102
103 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
104 if (!ret)
105 pinctrl_select_state(dev, "default");
106
107 /*
108 * Allow establishing an early console as required for example when
109 * doing a UART-based boot. Note that this console may not "survive"
110 * through a SYSFW PM-init step and will need a re-init in some way
111 * due to changing module clock frequencies.
112 */
113 if (IS_ENABLED(CONFIG_K3_EARLY_CONS)) {
114 ret = early_console_init();
115 if (ret)
116 panic("early_console_init() failed: %d\n", ret);
117 }
118
119 /*
120 * Configure and start up system controller firmware. Provide
121 * the U-Boot console init function to the SYSFW post-PM configuration
122 * callback hook, effectively switching on (or over) the console
123 * output.
124 */
125 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
126 ret = is_rom_loaded_sysfw(&bootdata);
127 if (!ret)
128 panic("ROM has not loaded TIFS firmware\n");
129
130 k3_sysfw_loader(true, NULL, NULL);
131
132 /* Disable ROM configured firewalls */
133 remove_fwl_configs(cbass_main_fwls,
134 ARRAY_SIZE(cbass_main_fwls));
135 }
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 preloader_console_init();
150
151 /* Output System Firmware version info */
152 k3_sysfw_print_ver();
153
154 if (IS_ENABLED(CONFIG_K3_AM62A_DDRSS)) {
155 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
156 if (ret)
157 panic("DRAM init failed: %d\n", ret);
158 }
159
160 spl_enable_cache();
161 debug("am62px_init: %s done\n", __func__);
162}
163
164u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
165{
166 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
167 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
168 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
169 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
170 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
171
172 switch (bootmode) {
173 case BOOT_DEVICE_EMMC:
174 return MMCSD_MODE_EMMCBOOT;
175 case BOOT_DEVICE_MMC:
176 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
177 return MMCSD_MODE_RAW;
178 default:
179 return MMCSD_MODE_FS;
180 }
181}
182
183static u32 __get_backup_bootmedia(u32 devstat)
184{
185 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
186 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
187 u32 bkup_bootmode_cfg =
188 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
189 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
190
191 switch (bkup_bootmode) {
192 case BACKUP_BOOT_DEVICE_UART:
193 return BOOT_DEVICE_UART;
194
195 case BACKUP_BOOT_DEVICE_USB:
196 return BOOT_DEVICE_USB;
197
198 case BACKUP_BOOT_DEVICE_ETHERNET:
199 return BOOT_DEVICE_ETHERNET;
200
201 case BACKUP_BOOT_DEVICE_MMC:
202 if (bkup_bootmode_cfg)
203 return BOOT_DEVICE_MMC2;
204 return BOOT_DEVICE_MMC1;
205
206 case BACKUP_BOOT_DEVICE_SPI:
207 return BOOT_DEVICE_SPI;
208
209 case BACKUP_BOOT_DEVICE_I2C:
210 return BOOT_DEVICE_I2C;
211
212 case BACKUP_BOOT_DEVICE_DFU:
213 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
214 return BOOT_DEVICE_USB;
215 return BOOT_DEVICE_DFU;
216 };
217
218 return BOOT_DEVICE_RAM;
219}
220
221static u32 __get_primary_bootmedia(u32 devstat)
222{
223 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
224 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
225 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
226 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
227
228 switch (bootmode) {
229 case BOOT_DEVICE_OSPI:
230 fallthrough;
231 case BOOT_DEVICE_QSPI:
232 fallthrough;
233 case BOOT_DEVICE_XSPI:
234 fallthrough;
235 case BOOT_DEVICE_SPI:
236 return BOOT_DEVICE_SPI;
237
238 case BOOT_DEVICE_ETHERNET_RGMII:
239 fallthrough;
240 case BOOT_DEVICE_ETHERNET_RMII:
241 return BOOT_DEVICE_ETHERNET;
242
243 case BOOT_DEVICE_EMMC:
244 return BOOT_DEVICE_MMC1;
245
246 case BOOT_DEVICE_SPI_NAND:
247 return BOOT_DEVICE_SPINAND;
248
249 case BOOT_DEVICE_MMC:
250 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
251 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
252 return BOOT_DEVICE_MMC2;
253 return BOOT_DEVICE_MMC1;
254
255 case BOOT_DEVICE_DFU:
256 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
257 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
258 return BOOT_DEVICE_USB;
259 return BOOT_DEVICE_DFU;
260
261 case BOOT_DEVICE_NOBOOT:
262 return BOOT_DEVICE_RAM;
263 }
264
265 return bootmode;
266}
267
268u32 spl_boot_device(void)
269{
270 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
271 u32 bootmedia;
272
273 if (bootindex == K3_PRIMARY_BOOTMODE)
274 bootmedia = __get_primary_bootmedia(devstat);
275 else
276 bootmedia = __get_backup_bootmedia(devstat);
277
278 debug("am62px_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
279 __func__, devstat, bootmedia, bootindex);
280 return bootmedia;
281}