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>
13 #include <asm/arch/hardware.h>
14 #include <asm/arch/sysfw-loader.h>
15 #include <asm/arch/sys_proto.h>
18 #include <dm/uclass-internal.h>
19 #include <dm/pinctrl.h>
20 #include <linux/soc/ti/ti_sci_protocol.h>
23 #ifdef CONFIG_SPL_BUILD
24 #ifdef CONFIG_K3_LOAD_SYSFW
25 #ifdef CONFIG_TI_SECURE_DEVICE
26 struct fwl_data main_cbass_fwls[] = {
27 { "MMCSD1_CFG", 2057, 1 },
28 { "MMCSD0_CFG", 2058, 1 },
29 { "USB3SS0_SLV0", 2176, 2 },
30 { "PCIE0_SLV", 2336, 8 },
31 { "PCIE1_SLV", 2337, 8 },
32 { "PCIE0_CFG", 2688, 1 },
33 { "PCIE1_CFG", 2689, 1 },
34 }, mcu_cbass_fwls[] = {
35 { "MCU_ARMSS0_CORE0_SLV", 1024, 1 },
36 { "MCU_ARMSS0_CORE1_SLV", 1028, 1 },
37 { "MCU_FSS0_S1", 1033, 8 },
38 { "MCU_FSS0_S0", 1036, 8 },
39 { "MCU_CPSW0", 1220, 1 },
44 static void mmr_unlock(u32 base, u32 partition)
46 /* Translate the base address */
47 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
49 /* Unlock the requested partition if locked using two-step sequence */
50 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
51 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
54 static void ctrl_mmr_unlock(void)
56 /* Unlock all WKUP_CTRL_MMR0 module registers */
57 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
58 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
59 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
60 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
61 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
62 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
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, 6);
70 /* Unlock all CTRL_MMR0 module registers */
71 mmr_unlock(CTRL_MMR0_BASE, 0);
72 mmr_unlock(CTRL_MMR0_BASE, 1);
73 mmr_unlock(CTRL_MMR0_BASE, 2);
74 mmr_unlock(CTRL_MMR0_BASE, 3);
75 mmr_unlock(CTRL_MMR0_BASE, 6);
76 mmr_unlock(CTRL_MMR0_BASE, 7);
80 * This uninitialized global variable would normal end up in the .bss section,
81 * but the .bss is cleared between writing and reading this variable, so move
82 * it to the .data section.
84 u32 bootindex __attribute__((section(".data")));
86 static void store_boot_index_from_rom(void)
88 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
91 #if defined(CONFIG_K3_LOAD_SYSFW)
92 void k3_mmc_stop_clock(void)
94 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
95 struct mmc *mmc = find_mmc_device(0);
100 mmc->saved_clock = mmc->clock;
101 mmc_set_clock(mmc, 0, true);
105 void k3_mmc_restart_clock(void)
107 if (spl_boot_device() == BOOT_DEVICE_MMC1) {
108 struct mmc *mmc = find_mmc_device(0);
113 mmc_set_clock(mmc, mmc->saved_clock, false);
118 void board_init_f(ulong dummy)
120 #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS)
125 * Cannot delay this further as there is a chance that
126 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
128 store_boot_index_from_rom();
130 /* Make all control module registers accessible */
133 #ifdef CONFIG_CPU_V7R
134 disable_linefill_optimization();
135 setup_k3_mpu_regions();
138 /* Init DM early in-order to invoke system controller */
141 #ifdef CONFIG_K3_EARLY_CONS
143 * Allow establishing an early console as required for example when
144 * doing a UART-based boot. Note that this console may not "survive"
145 * through a SYSFW PM-init step and will need a re-init in some way
146 * due to changing module clock frequencies.
148 early_console_init();
151 #ifdef CONFIG_K3_LOAD_SYSFW
153 * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue
154 * regardless of the result of pinctrl. Do this without probing the
155 * device, but instead by searching the device that would request the
156 * given sequence number if probed. The UART will be used by the system
157 * firmware (SYSFW) image for various purposes and SYSFW depends on us
158 * to initialize its pin settings.
160 ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev);
162 pinctrl_select_state(dev, "default");
165 * Load, start up, and configure system controller firmware while
166 * also populating the SYSFW post-PM configuration callback hook.
168 k3_sysfw_loader(k3_mmc_stop_clock, k3_mmc_restart_clock);
170 /* Prepare console output */
171 preloader_console_init();
173 /* Disable ROM configured firewalls right after loading sysfw */
174 #ifdef CONFIG_TI_SECURE_DEVICE
175 remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls));
176 remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls));
179 /* Prepare console output */
180 preloader_console_init();
183 /* Output System Firmware version info */
184 k3_sysfw_print_ver();
186 /* Perform EEPROM-based board detection */
189 #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0)
190 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs),
193 printf("AVS init failed: %d\n", ret);
196 #ifdef CONFIG_K3_AM654_DDRSS
197 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
199 panic("DRAM init failed: %d\n", ret);
203 u32 spl_mmc_boot_mode(const u32 boot_device)
205 #if defined(CONFIG_SUPPORT_EMMC_BOOT)
206 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
208 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
209 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
211 /* eMMC boot0 mode is only supported for primary boot */
212 if (bootindex == K3_PRIMARY_BOOTMODE &&
213 bootmode == BOOT_DEVICE_MMC1)
214 return MMCSD_MODE_EMMCBOOT;
217 /* Everything else use filesystem if available */
218 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
219 return MMCSD_MODE_FS;
221 return MMCSD_MODE_RAW;
225 static u32 __get_backup_bootmedia(u32 devstat)
227 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
228 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
231 case BACKUP_BOOT_DEVICE_USB:
232 return BOOT_DEVICE_USB;
233 case BACKUP_BOOT_DEVICE_UART:
234 return BOOT_DEVICE_UART;
235 case BACKUP_BOOT_DEVICE_ETHERNET:
236 return BOOT_DEVICE_ETHERNET;
237 case BACKUP_BOOT_DEVICE_MMC2:
239 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
240 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
242 return BOOT_DEVICE_MMC1;
243 return BOOT_DEVICE_MMC2;
245 case BACKUP_BOOT_DEVICE_SPI:
246 return BOOT_DEVICE_SPI;
247 case BACKUP_BOOT_DEVICE_HYPERFLASH:
248 return BOOT_DEVICE_HYPERFLASH;
249 case BACKUP_BOOT_DEVICE_I2C:
250 return BOOT_DEVICE_I2C;
253 return BOOT_DEVICE_RAM;
256 static u32 __get_primary_bootmedia(u32 devstat)
258 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
259 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
261 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
262 bootmode = BOOT_DEVICE_SPI;
264 if (bootmode == BOOT_DEVICE_MMC2) {
265 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
266 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
268 bootmode = BOOT_DEVICE_MMC1;
269 } else if (bootmode == BOOT_DEVICE_MMC1) {
270 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
271 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
273 bootmode = BOOT_DEVICE_MMC2;
279 u32 spl_boot_device(void)
281 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
283 if (bootindex == K3_PRIMARY_BOOTMODE)
284 return __get_primary_bootmedia(devstat);
286 return __get_backup_bootmedia(devstat);
290 #ifdef CONFIG_SYS_K3_SPL_ATF
292 #define AM6_DEV_MCU_RTI0 134
293 #define AM6_DEV_MCU_RTI1 135
294 #define AM6_DEV_MCU_ARMSS0_CPU0 159
295 #define AM6_DEV_MCU_ARMSS0_CPU1 245
297 void release_resources_for_core_shutdown(void)
299 struct ti_sci_handle *ti_sci = get_ti_sci_handle();
300 struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops;
301 struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops;
305 const u32 put_device_ids[] = {
310 /* Iterate through list of devices to put (shutdown) */
311 for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) {
312 u32 id = put_device_ids[i];
314 ret = dev_ops->put_device(ti_sci, id);
316 panic("Failed to put device %u (%d)\n", id, ret);
319 const u32 put_core_ids[] = {
320 AM6_DEV_MCU_ARMSS0_CPU1,
321 AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */
324 /* Iterate through list of cores to put (shutdown) */
325 for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) {
326 u32 id = put_core_ids[i];
329 * Queue up the core shutdown request. Note that this call
330 * needs to be followed up by an actual invocation of an WFE
331 * or WFI CPU instruction.
333 ret = proc_ops->proc_shutdown_no_wait(ti_sci, id);
335 panic("Failed sending core %u shutdown message (%d)\n",