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