1 // SPDX-License-Identifier: GPL-2.0+
3 * AM6: SoC specific initialization
5 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
10 #include <fdt_support.h>
12 #include <asm/global_data.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/sysfw-loader.h>
17 #include <asm/arch/sys_proto.h>
20 #include <dm/uclass-internal.h>
21 #include <dm/pinctrl.h>
22 #include <linux/soc/ti/ti_sci_protocol.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 #ifdef CONFIG_K3_LOAD_SYSFW
30 #ifdef CONFIG_TI_SECURE_DEVICE
31 struct fwl_data main_cbass_fwls[] = {
32 { "MMCSD1_CFG", 2057, 1 },
33 { "MMCSD0_CFG", 2058, 1 },
34 { "USB3SS0_SLV0", 2176, 2 },
35 { "PCIE0_SLV", 2336, 8 },
36 { "PCIE1_SLV", 2337, 8 },
37 { "PCIE0_CFG", 2688, 1 },
38 { "PCIE1_CFG", 2689, 1 },
39 }, mcu_cbass_fwls[] = {
40 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
41 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
42 { "MCU_FSS0_S1", 1033, 8 },
43 { "MCU_FSS0_S0", 1036, 8 },
44 { "MCU_CPSW0", 1220, 1 },
49 static void ctrl_mmr_unlock(void)
51 /* Unlock all WKUP_CTRL_MMR0 module registers */
52 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
53 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
54 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
55 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
56 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
57 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
59 /* Unlock all MCU_CTRL_MMR0 module registers */
60 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
61 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
62 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
63 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
65 /* Unlock all CTRL_MMR0 module registers */
66 mmr_unlock(CTRL_MMR0_BASE, 0);
67 mmr_unlock(CTRL_MMR0_BASE, 1);
68 mmr_unlock(CTRL_MMR0_BASE, 2);
69 mmr_unlock(CTRL_MMR0_BASE, 3);
70 mmr_unlock(CTRL_MMR0_BASE, 6);
71 mmr_unlock(CTRL_MMR0_BASE, 7);
75 * This uninitialized global variable would normal end up in the .bss section,
76 * but the .bss is cleared between writing and reading this variable, so move
77 * it to the .data section.
79 u32 bootindex __section(".data");
81 static void store_boot_index_from_rom(void)
83 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
86 #if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC)
87 void k3_mmc_stop_clock(void)
89 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
90 struct mmc *mmc = find_mmc_device(0);
95 mmc->saved_clock = mmc->clock;
96 mmc_set_clock(mmc, 0, true);
100 void k3_mmc_restart_clock(void)
102 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
103 struct mmc *mmc = find_mmc_device(0);
108 mmc_set_clock(mmc, mmc->saved_clock, false);
112 void k3_mmc_stop_clock(void) {}
113 void k3_mmc_restart_clock(void) {}
115 #if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE)
116 #define CTRLMMR_SERDES0_CTRL 0x00104080
117 #define PCIE_LANE0 0x1
118 static int fixup_usb_boot(void)
122 switch (spl_boot_device()) {
123 case BOOT_DEVICE_USB:
125 * If bootmode is Host bootmode, fixup the dr_mode to host
126 * before the dwc3 bind takes place
128 ret = fdt_find_and_setprop((void *)gd->fdt_blob,
129 "/bus@100000/dwc3@4000000/usb@10000",
130 "dr_mode", "host", 5, 0);
132 printf("%s: fdt_find_and_setprop() failed:%d\n", __func__,
135 case BOOT_DEVICE_DFU:
137 * The serdes mux between PCIe and USB3 needs to be set to PCIe for
138 * accessing the interface at USB 2.0
140 writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL);
148 int fdtdec_board_setup(const void *fdt_blob)
150 return fixup_usb_boot();
154 static void setup_am654_navss_northbridge(void)
157 * NB0 is bridge to SRAM and NB1 is bridge to DDR.
158 * To ensure that SRAM transfers are not stalled due to
159 * delays during DDR refreshes, SRAM traffic should be higher
160 * priority (threadmap=2) than DDR traffic (threadmap=0).
162 writel(0x2, NAVSS0_NBSS_NB0_CFG_BASE + NAVSS_NBSS_THREADMAP);
163 writel(0x0, NAVSS0_NBSS_NB1_CFG_BASE + NAVSS_NBSS_THREADMAP);
166 void board_init_f(ulong dummy)
168 #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
175 * Cannot delay this further as there is a chance that
176 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
178 store_boot_index_from_rom();
180 /* Make all control module registers accessible */
183 setup_am654_navss_northbridge();
185 #ifdef CONFIG_CPU_V7R
186 disable_linefill_optimization();
187 setup_k3_mpu_regions();
190 /* Init DM early in-order to invoke system controller */
193 #ifdef CONFIG_K3_EARLY_CONS
195 * Allow establishing an early console as required for example when
196 * doing a UART-based boot. Note that this console may not "survive"
197 * through a SYSFW PM-init step and will need a re-init in some way
198 * due to changing module clock frequencies.
200 early_console_init();
203 #ifdef CONFIG_K3_LOAD_SYSFW
205 * Initialize an early full malloc environment. Do so by allocating a
206 * new malloc area inside the currently active pre-relocation "first"
207 * malloc pool of which we use all that's left.
209 pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr;
210 pool_addr = malloc(pool_size);
212 panic("ERROR: Can't allocate full malloc pool!\n");
214 mem_malloc_init((ulong)pool_addr, (ulong)pool_size);
215 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
216 debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n",
217 __func__, (unsigned long)pool_addr, (unsigned long)pool_size);
219 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
220 * regardless of the result of pinctrl. Do this without probing the
221 * device, but instead by searching the device that would request the
222 * given sequence number if probed. The UART will be used by the system
223 * firmware (SYSFW) image for various purposes and SYSFW depends on us
224 * to initialize its pin settings.
226 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev);
228 pinctrl_select_state(dev, "default");
231 * Load, start up, and configure system controller firmware while
232 * also populating the SYSFW post-PM configuration callback hook.
234 k3_sysfw_loader(false, k3_mmc_stop_clock, k3_mmc_restart_clock);
236 /* Prepare console output */
237 preloader_console_init();
239 /* Disable ROM configured firewalls right after loading sysfw */
240 #ifdef CONFIG_TI_SECURE_DEVICE
241 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
242 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
245 /* Prepare console output */
246 preloader_console_init();
249 /* Output System Firmware version info */
250 k3_sysfw_print_ver();
252 /* Perform EEPROM-based board detection */
253 if (IS_ENABLED(CONFIG_TI_I2C_BOARD_DETECT))
256 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
257 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs),
260 printf("AVS init failed: %d\n", ret);
263 #ifdef CONFIG_K3_AM654_DDRSS
264 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
266 panic("DRAM init failed: %d\n", ret);
271 u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
273 #if defined(CONFIG_SUPPORT_EMMC_BOOT)
274 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
276 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
277 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
279 /* eMMC boot0 mode is only supported for primary boot */
280 if (bootindex == K3_PRIMARY_BOOTMODE &&
281 bootmode == BOOT_DEVICE_MMC1)
282 return MMCSD_MODE_EMMCBOOT;
285 /* Everything else use filesystem if available */
286 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
287 return MMCSD_MODE_FS;
289 return MMCSD_MODE_RAW;
293 static u32 __get_backup_bootmedia(u32 devstat)
295 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
296 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
299 case BACKUP_BOOT_DEVICE_USB:
300 return BOOT_DEVICE_USB;
301 case BACKUP_BOOT_DEVICE_UART:
302 return BOOT_DEVICE_UART;
303 case BACKUP_BOOT_DEVICE_ETHERNET:
304 return BOOT_DEVICE_ETHERNET;
305 case BACKUP_BOOT_DEVICE_MMC2:
307 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
308 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
310 return BOOT_DEVICE_MMC1;
311 return BOOT_DEVICE_MMC2;
313 case BACKUP_BOOT_DEVICE_SPI:
314 return BOOT_DEVICE_SPI;
315 case BACKUP_BOOT_DEVICE_HYPERFLASH:
316 return BOOT_DEVICE_HYPERFLASH;
317 case BACKUP_BOOT_DEVICE_I2C:
318 return BOOT_DEVICE_I2C;
321 return BOOT_DEVICE_RAM;
324 static u32 __get_primary_bootmedia(u32 devstat)
326 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
327 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
329 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
330 bootmode = BOOT_DEVICE_SPI;
332 if (bootmode == BOOT_DEVICE_MMC2) {
333 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
334 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
336 bootmode = BOOT_DEVICE_MMC1;
337 } else if (bootmode == BOOT_DEVICE_MMC1) {
338 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
339 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
341 bootmode = BOOT_DEVICE_MMC2;
342 } else if (bootmode == BOOT_DEVICE_DFU) {
343 u32 mode = (devstat & CTRLMMR_MAIN_DEVSTAT_USB_MODE_MASK) >>
344 CTRLMMR_MAIN_DEVSTAT_USB_MODE_SHIFT;
346 bootmode = BOOT_DEVICE_USB;
352 u32 spl_boot_device(void)
354 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
356 if (bootindex == K3_PRIMARY_BOOTMODE)
357 return __get_primary_bootmedia(devstat);
359 return __get_backup_bootmedia(devstat);
362 #ifdef CONFIG_SYS_K3_SPL_ATF
364 #define AM6_DEV_MCU_RTI0 134
365 #define AM6_DEV_MCU_RTI1 135
366 #define AM6_DEV_MCU_ARMSS0_CPU0 159
367 #define AM6_DEV_MCU_ARMSS0_CPU1 245
369 void release_resources_for_core_shutdown(void)
371 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
372 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
373 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
377 const u32 put_device_ids[] = {
382 /* Iterate through list of devices to put (shutdown) */
383 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
384 u32 id = put_device_ids[i];
386 ret = dev_ops->put_device(ti_sci, id);
388 panic("Failed to put device %u (%d)\n", id, ret);
391 const u32 put_core_ids[] = {
392 AM6_DEV_MCU_ARMSS0_CPU1,
393 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
396 /* Iterate through list of cores to put (shutdown) */
397 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
398 u32 id = put_core_ids[i];
401 * Queue up the core shutdown request. Note that this call
402 * needs to be followed up by an actual invocation of an WFE
403 * or WFI CPU instruction.
405 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
407 panic("Failed sending core %u shutdown message (%d)\n",