blob: 6e3c66e5107a2674ba8781272df8cf5f05338986 [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>
Aparna Patra29b9f0e2025-01-08 10:19:39 +053014#include <dm/ofnode.h>
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -050015
Andrew Davis336b0792024-05-10 15:21:24 -050016#include "../sysfw-loader.h"
17#include "../common.h"
18
Aparna Patra29b9f0e2025-01-08 10:19:39 +053019/* TISCI DEV ID for A53 Clock */
20#define AM62PX_DEV_A53SS0_CORE_0_DEV_ID 135
21
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -060022#define CTRLMMR_MCU_RST_CTRL 0x04518170
23#define RST_CTRL_ESM_ERROR_RST_EN_Z_MASK 0xFFFDFFFF
24
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -050025struct fwl_data cbass_main_fwls[] = {
26 { "FSS_DAT_REG3", 7, 8 },
27};
28
29/*
30 * This uninitialized global variable would normal end up in the .bss section,
31 * but the .bss is cleared between writing and reading this variable, so move
32 * it to the .data section.
33 */
34u32 bootindex __section(".data");
35static struct rom_extended_boot_data bootdata __section(".data");
36
37static void store_boot_info_from_rom(void)
38{
39 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
40 memcpy(&bootdata, (uintptr_t *)ROM_EXTENDED_BOOT_DATA_INFO,
41 sizeof(struct rom_extended_boot_data));
42}
43
44static void ctrl_mmr_unlock(void)
45{
46 /* Unlock all WKUP_CTRL_MMR0 module registers */
47 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
48 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
49 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
50 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
51 mmr_unlock(WKUP_CTRL_MMR0_BASE, 4);
52 mmr_unlock(WKUP_CTRL_MMR0_BASE, 5);
53 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
54 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
55
56 /* Unlock all CTRL_MMR0 module registers */
57 mmr_unlock(CTRL_MMR0_BASE, 0);
58 mmr_unlock(CTRL_MMR0_BASE, 1);
59 mmr_unlock(CTRL_MMR0_BASE, 2);
60 mmr_unlock(CTRL_MMR0_BASE, 4);
61 mmr_unlock(CTRL_MMR0_BASE, 5);
62 mmr_unlock(CTRL_MMR0_BASE, 6);
63
64 /* Unlock all MCU_CTRL_MMR0 module registers */
65 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
66 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
67 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
68 mmr_unlock(MCU_CTRL_MMR0_BASE, 3);
69 mmr_unlock(MCU_CTRL_MMR0_BASE, 4);
70 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
71
72 /* Unlock PADCFG_CTRL_MMR padconf registers */
73 mmr_unlock(PADCFG_MMR0_BASE, 1);
74 mmr_unlock(PADCFG_MMR1_BASE, 1);
75}
Aparna Patra29b9f0e2025-01-08 10:19:39 +053076
77#if CONFIG_IS_ENABLED(OF_CONTROL)
78static int get_a53_cpu_clock_index(ofnode node)
79{
80 int count, i;
81 struct ofnode_phandle_args *args;
82 ofnode clknode;
83
84 clknode = ofnode_path("/bus@f0000/system-controller@44043000/clock-controller");
85 if (!ofnode_valid(clknode))
86 return -1;
87
88 count = ofnode_count_phandle_with_args(node, "assigned-clocks", "#clock-cells", 0);
89
90 for (i = 0; i < count; i++) {
91 if (!ofnode_parse_phandle_with_args(node, "assigned-clocks",
92 "#clock-cells", 0, i, args)) {
93 if (ofnode_equal(clknode, args->node) &&
94 args->args[0] == AM62PX_DEV_A53SS0_CORE_0_DEV_ID)
95 return i;
96 }
97 }
98
99 return -1;
100}
101
102static void fixup_a53_cpu_freq_by_speed_grade(void)
103{
104 int index, size;
105 u32 *rates;
106 ofnode node;
107
108 node = ofnode_path("/a53@0");
109 if (!ofnode_valid(node))
110 return;
111
112 rates = fdt_getprop_w(ofnode_to_fdt(node), ofnode_to_offset(node),
113 "assigned-clock-rates", &size);
114
115 index = get_a53_cpu_clock_index(node);
116
117 if (!rates || index < 0 || index >= (size / sizeof(u32))) {
118 printf("Wrong A53 assigned-clocks configuration\n");
119 return;
120 }
121
122 rates[index] = cpu_to_fdt32(k3_get_a53_max_frequency());
123
124 printf("Changed A53 CPU frequency to %dHz (%c grade) in DT\n",
125 k3_get_a53_max_frequency(), k3_get_speed_grade());
126}
127#else
128static void fixup_a53_cpu_freq_by_speed_grade(void)
129{
130}
131#endif
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500132
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -0600133static __maybe_unused void enable_mcu_esm_reset(void)
134{
135 /* Set CTRLMMR_MCU_RST_CTRL:MCU_ESM_ERROR_RST_EN_Z to '0' (low active) */
136 u32 stat = readl(CTRLMMR_MCU_RST_CTRL);
137
138 stat &= RST_CTRL_ESM_ERROR_RST_EN_Z_MASK;
139 writel(stat, CTRLMMR_MCU_RST_CTRL);
140}
141
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500142void board_init_f(ulong dummy)
143{
144 struct udevice *dev;
145 int ret;
146
147 if (IS_ENABLED(CONFIG_CPU_V7R))
148 setup_k3_mpu_regions();
149
150 /*
151 * Cannot delay this further as there is a chance that
152 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
153 */
154 store_boot_info_from_rom();
155
156 ctrl_mmr_unlock();
157
158 /* Init DM early */
159 ret = spl_early_init();
160 if (ret)
161 panic("spl_early_init() failed: %d\n", ret);
162
163 /*
164 * Process pinctrl for the serial0 and serial3, aka WKUP_UART0 and
165 * MAIN_UART1 modules and continue regardless of the result of pinctrl.
166 * Do this without probing the device, but instead by searching the
167 * device that would request the given sequence number if probed. The
168 * UARTs will be used by the DM firmware and TIFS firmware images
169 * respectively and the firmware depend on SPL to initialize the pin
170 * settings.
171 */
172 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
173 if (!ret)
174 pinctrl_select_state(dev, "default");
175
176 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 3, &dev);
177 if (!ret)
178 pinctrl_select_state(dev, "default");
179
180 /*
181 * Allow establishing an early console as required for example when
182 * doing a UART-based boot. Note that this console may not "survive"
183 * through a SYSFW PM-init step and will need a re-init in some way
184 * due to changing module clock frequencies.
185 */
186 if (IS_ENABLED(CONFIG_K3_EARLY_CONS)) {
187 ret = early_console_init();
188 if (ret)
189 panic("early_console_init() failed: %d\n", ret);
190 }
191
192 /*
193 * Configure and start up system controller firmware. Provide
194 * the U-Boot console init function to the SYSFW post-PM configuration
195 * callback hook, effectively switching on (or over) the console
196 * output.
197 */
198 if (IS_ENABLED(CONFIG_K3_LOAD_SYSFW)) {
199 ret = is_rom_loaded_sysfw(&bootdata);
200 if (!ret)
201 panic("ROM has not loaded TIFS firmware\n");
202
203 k3_sysfw_loader(true, NULL, NULL);
204
205 /* Disable ROM configured firewalls */
206 remove_fwl_configs(cbass_main_fwls,
207 ARRAY_SIZE(cbass_main_fwls));
208 }
209
210 /*
211 * Force probe of clk_k3 driver here to ensure basic default clock
212 * configuration is always done.
213 */
214 if (IS_ENABLED(CONFIG_SPL_CLK_K3)) {
215 ret = uclass_get_device_by_driver(UCLASS_CLK,
216 DM_DRIVER_GET(ti_clk),
217 &dev);
218 if (ret)
219 printf("Failed to initialize clk-k3!\n");
220 }
221
222 preloader_console_init();
223
224 /* Output System Firmware version info */
225 k3_sysfw_print_ver();
226
227 if (IS_ENABLED(CONFIG_K3_AM62A_DDRSS)) {
228 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
229 if (ret)
230 panic("DRAM init failed: %d\n", ret);
231 }
232
Santhosh Kumar K0dc33cd2025-01-29 17:44:02 -0600233 if (IS_ENABLED(CONFIG_ESM_K3)) {
234 /* Probe/configure ESM0 */
235 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@420000", &dev);
236 if (ret)
237 printf("esm main init failed: %d\n", ret);
238
239 /* Probe/configure MCUESM */
240 ret = uclass_get_device_by_name(UCLASS_MISC, "esm@4100000", &dev);
241 if (ret)
242 printf("esm mcu init failed: %d\n", ret);
243
244 enable_mcu_esm_reset();
245 }
246
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500247 spl_enable_cache();
Jayesh Choudharye0535272024-11-26 12:36:12 +0530248
249 setup_qos();
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500250 debug("am62px_init: %s done\n", __func__);
Aparna Patra29b9f0e2025-01-08 10:19:39 +0530251
252 fixup_a53_cpu_freq_by_speed_grade();
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500253}
254
255u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
256{
257 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
258 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
259 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
260 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
261 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
262
263 switch (bootmode) {
264 case BOOT_DEVICE_EMMC:
Anshul Dalald8b46d12025-04-15 15:22:24 +0530265 if (IS_ENABLED(CONFIG_SUPPORT_EMMC_BOOT))
266 return MMCSD_MODE_EMMCBOOT;
267 if (IS_ENABLED(CONFIG_SPL_FS_FAT) || IS_ENABLED(CONFIG_SPL_FS_EXT4))
268 return MMCSD_MODE_FS;
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500269 return MMCSD_MODE_EMMCBOOT;
270 case BOOT_DEVICE_MMC:
271 if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_FS_RAW_MASK)
272 return MMCSD_MODE_RAW;
Andre Przywara2e295172025-03-27 15:33:08 +0000273 fallthrough;
Bryan Brattlofa4d5cc22024-03-12 15:20:24 -0500274 default:
275 return MMCSD_MODE_FS;
276 }
277}
278
279static u32 __get_backup_bootmedia(u32 devstat)
280{
281 u32 bkup_bootmode = (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >>
282 MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT;
283 u32 bkup_bootmode_cfg =
284 (devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >>
285 MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT;
286
287 switch (bkup_bootmode) {
288 case BACKUP_BOOT_DEVICE_UART:
289 return BOOT_DEVICE_UART;
290
291 case BACKUP_BOOT_DEVICE_USB:
292 return BOOT_DEVICE_USB;
293
294 case BACKUP_BOOT_DEVICE_ETHERNET:
295 return BOOT_DEVICE_ETHERNET;
296
297 case BACKUP_BOOT_DEVICE_MMC:
298 if (bkup_bootmode_cfg)
299 return BOOT_DEVICE_MMC2;
300 return BOOT_DEVICE_MMC1;
301
302 case BACKUP_BOOT_DEVICE_SPI:
303 return BOOT_DEVICE_SPI;
304
305 case BACKUP_BOOT_DEVICE_I2C:
306 return BOOT_DEVICE_I2C;
307
308 case BACKUP_BOOT_DEVICE_DFU:
309 if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK)
310 return BOOT_DEVICE_USB;
311 return BOOT_DEVICE_DFU;
312 };
313
314 return BOOT_DEVICE_RAM;
315}
316
317static u32 __get_primary_bootmedia(u32 devstat)
318{
319 u32 bootmode = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >>
320 MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT;
321 u32 bootmode_cfg = (devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >>
322 MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT;
323
324 switch (bootmode) {
325 case BOOT_DEVICE_OSPI:
326 fallthrough;
327 case BOOT_DEVICE_QSPI:
328 fallthrough;
329 case BOOT_DEVICE_XSPI:
330 fallthrough;
331 case BOOT_DEVICE_SPI:
332 return BOOT_DEVICE_SPI;
333
334 case BOOT_DEVICE_ETHERNET_RGMII:
335 fallthrough;
336 case BOOT_DEVICE_ETHERNET_RMII:
337 return BOOT_DEVICE_ETHERNET;
338
339 case BOOT_DEVICE_EMMC:
340 return BOOT_DEVICE_MMC1;
341
342 case BOOT_DEVICE_SPI_NAND:
343 return BOOT_DEVICE_SPINAND;
344
345 case BOOT_DEVICE_MMC:
346 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >>
347 MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT)
348 return BOOT_DEVICE_MMC2;
349 return BOOT_DEVICE_MMC1;
350
351 case BOOT_DEVICE_DFU:
352 if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >>
353 MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT)
354 return BOOT_DEVICE_USB;
355 return BOOT_DEVICE_DFU;
356
357 case BOOT_DEVICE_NOBOOT:
358 return BOOT_DEVICE_RAM;
359 }
360
361 return bootmode;
362}
363
364u32 spl_boot_device(void)
365{
366 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
367 u32 bootmedia;
368
369 if (bootindex == K3_PRIMARY_BOOTMODE)
370 bootmedia = __get_primary_bootmedia(devstat);
371 else
372 bootmedia = __get_backup_bootmedia(devstat);
373
374 debug("am62px_init: %s: devstat = 0x%x bootmedia = 0x%x bootindex = %d\n",
375 __func__, devstat, bootmedia, bootindex);
376 return bootmedia;
377}