1 // SPDX-License-Identifier: GPL-2.0+
3 * K3: Architecture initialization
5 * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
12 #include <asm/arch/hardware.h>
16 #ifdef CONFIG_SPL_BUILD
17 static void mmr_unlock(u32 base, u32 partition)
19 /* Translate the base address */
20 phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE;
22 /* Unlock the requested partition if locked using two-step sequence */
23 writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0);
24 writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1);
27 static void ctrl_mmr_unlock(void)
29 /* Unlock all WKUP_CTRL_MMR0 module registers */
30 mmr_unlock(WKUP_CTRL_MMR0_BASE, 0);
31 mmr_unlock(WKUP_CTRL_MMR0_BASE, 1);
32 mmr_unlock(WKUP_CTRL_MMR0_BASE, 2);
33 mmr_unlock(WKUP_CTRL_MMR0_BASE, 3);
34 mmr_unlock(WKUP_CTRL_MMR0_BASE, 6);
35 mmr_unlock(WKUP_CTRL_MMR0_BASE, 7);
37 /* Unlock all MCU_CTRL_MMR0 module registers */
38 mmr_unlock(MCU_CTRL_MMR0_BASE, 0);
39 mmr_unlock(MCU_CTRL_MMR0_BASE, 1);
40 mmr_unlock(MCU_CTRL_MMR0_BASE, 2);
41 mmr_unlock(MCU_CTRL_MMR0_BASE, 6);
43 /* Unlock all CTRL_MMR0 module registers */
44 mmr_unlock(CTRL_MMR0_BASE, 0);
45 mmr_unlock(CTRL_MMR0_BASE, 1);
46 mmr_unlock(CTRL_MMR0_BASE, 2);
47 mmr_unlock(CTRL_MMR0_BASE, 3);
48 mmr_unlock(CTRL_MMR0_BASE, 6);
49 mmr_unlock(CTRL_MMR0_BASE, 7);
53 * This uninitialized global variable would normal end up in the .bss section,
54 * but the .bss is cleared between writing and reading this variable, so move
55 * it to the .data section.
57 u32 bootindex __attribute__((section(".data")));
59 static void store_boot_index_from_rom(void)
61 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX);
64 void board_init_f(ulong dummy)
66 #if defined(CONFIG_K3_AM654_DDRSS)
71 * Cannot delay this further as there is a chance that
72 * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section.
74 store_boot_index_from_rom();
76 /* Make all control module registers accessible */
80 setup_k3_mpu_regions();
83 /* Init DM early in-order to invoke system controller */
86 /* Prepare console output */
87 preloader_console_init();
89 #ifdef CONFIG_K3_AM654_DDRSS
90 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
92 panic("DRAM init failed: %d\n", ret);
96 u32 spl_boot_mode(const u32 boot_device)
98 #if defined(CONFIG_SUPPORT_EMMC_BOOT)
99 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
101 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
102 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
104 /* eMMC boot0 mode is only supported for primary boot */
105 if (bootindex == K3_PRIMARY_BOOTMODE &&
106 bootmode == BOOT_DEVICE_MMC1)
107 return MMCSD_MODE_EMMCBOOT;
110 /* Everything else use filesystem if available */
111 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
112 return MMCSD_MODE_FS;
114 return MMCSD_MODE_RAW;
118 static u32 __get_backup_bootmedia(u32 devstat)
120 u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >>
121 CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT;
124 case BACKUP_BOOT_DEVICE_USB:
125 return BOOT_DEVICE_USB;
126 case BACKUP_BOOT_DEVICE_UART:
127 return BOOT_DEVICE_UART;
128 case BACKUP_BOOT_DEVICE_ETHERNET:
129 return BOOT_DEVICE_ETHERNET;
130 case BACKUP_BOOT_DEVICE_MMC2:
132 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >>
133 CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT;
135 return BOOT_DEVICE_MMC1;
136 return BOOT_DEVICE_MMC2;
138 case BACKUP_BOOT_DEVICE_SPI:
139 return BOOT_DEVICE_SPI;
140 case BACKUP_BOOT_DEVICE_HYPERFLASH:
141 return BOOT_DEVICE_HYPERFLASH;
142 case BACKUP_BOOT_DEVICE_I2C:
143 return BOOT_DEVICE_I2C;
146 return BOOT_DEVICE_RAM;
149 static u32 __get_primary_bootmedia(u32 devstat)
151 u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >>
152 CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT;
154 if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI)
155 bootmode = BOOT_DEVICE_SPI;
157 if (bootmode == BOOT_DEVICE_MMC2) {
158 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >>
159 CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT;
161 bootmode = BOOT_DEVICE_MMC1;
162 } else if (bootmode == BOOT_DEVICE_MMC1) {
163 u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >>
164 CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT;
166 bootmode = BOOT_DEVICE_MMC2;
172 u32 spl_boot_device(void)
174 u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT);
176 if (bootindex == K3_PRIMARY_BOOTMODE)
177 return __get_primary_bootmedia(devstat);
179 return __get_backup_bootmedia(devstat);
183 #ifndef CONFIG_SYSRESET
184 void reset_cpu(ulong ignored)