blob: 2d35a7ce77ec73224a0bc08ff5b964b2ae7a5ed2 [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();
Jayesh Choudharye0535272024-11-26 12:36:12 +0530162
163 setup_qos();
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500164 debug("am62px_init: %s done\n", __func__);
165}
166
167u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
168{
169 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
170 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
171 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
172 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
173 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
174
175 switch (bootmode) {
176 case BOOT_DEVICE_EMMC:
177 return MMCSD_MODE_EMMCBOOT;
178 case BOOT_DEVICE_MMC:
179 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
180 return MMCSD_MODE_RAW;
181 default:
182 return MMCSD_MODE_FS;
183 }
184}
185
186static u32 __get_backup_bootmedia(u32 devstat)
187{
188 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
189 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
190 u32 bkup_bootmode_cfg =
191 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
192 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
193
194 switch (bkup_bootmode) {
195 case BACKUP_BOOT_DEVICE_UART:
196 return BOOT_DEVICE_UART;
197
198 case BACKUP_BOOT_DEVICE_USB:
199 return BOOT_DEVICE_USB;
200
201 case BACKUP_BOOT_DEVICE_ETHERNET:
202 return BOOT_DEVICE_ETHERNET;
203
204 case BACKUP_BOOT_DEVICE_MMC:
205 if (bkup_bootmode_cfg)
206 return BOOT_DEVICE_MMC2;
207 return BOOT_DEVICE_MMC1;
208
209 case BACKUP_BOOT_DEVICE_SPI:
210 return BOOT_DEVICE_SPI;
211
212 case BACKUP_BOOT_DEVICE_I2C:
213 return BOOT_DEVICE_I2C;
214
215 case BACKUP_BOOT_DEVICE_DFU:
216 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
217 return BOOT_DEVICE_USB;
218 return BOOT_DEVICE_DFU;
219 };
220
221 return BOOT_DEVICE_RAM;
222}
223
224static u32 __get_primary_bootmedia(u32 devstat)
225{
226 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
227 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
228 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
229 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
230
231 switch (bootmode) {
232 case BOOT_DEVICE_OSPI:
233 fallthrough;
234 case BOOT_DEVICE_QSPI:
235 fallthrough;
236 case BOOT_DEVICE_XSPI:
237 fallthrough;
238 case BOOT_DEVICE_SPI:
239 return BOOT_DEVICE_SPI;
240
241 case BOOT_DEVICE_ETHERNET_RGMII:
242 fallthrough;
243 case BOOT_DEVICE_ETHERNET_RMII:
244 return BOOT_DEVICE_ETHERNET;
245
246 case BOOT_DEVICE_EMMC:
247 return BOOT_DEVICE_MMC1;
248
249 case BOOT_DEVICE_SPI_NAND:
250 return BOOT_DEVICE_SPINAND;
251
252 case BOOT_DEVICE_MMC:
253 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
254 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
255 return BOOT_DEVICE_MMC2;
256 return BOOT_DEVICE_MMC1;
257
258 case BOOT_DEVICE_DFU:
259 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
260 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
261 return BOOT_DEVICE_USB;
262 return BOOT_DEVICE_DFU;
263
264 case BOOT_DEVICE_NOBOOT:
265 return BOOT_DEVICE_RAM;
266 }
267
268 return bootmode;
269}
270
271u32 spl_boot_device(void)
272{
273 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
274 u32 bootmedia;
275
276 if (bootindex == K3_PRIMARY_BOOTMODE)
277 bootmedia = __get_primary_bootmedia(devstat);
278 else
279 bootmedia = __get_backup_bootmedia(devstat);
280
281 debug("am62px_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
282 __func__, devstat, bootmedia, bootindex);
283 return bootmedia;
284}