Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * K3: Architecture initialization |
| 4 | * |
| 5 | * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 10 | #include <asm/io.h> |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 11 | #include <spl.h> |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 12 | #include <asm/arch/hardware.h> |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 13 | #include <asm/arch/sysfw-loader.h> |
Andreas Dannenberg | 03facc7 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 14 | #include <asm/arch/sys_proto.h> |
Lokesh Vutla | 23f7b1a | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 15 | #include "common.h" |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 16 | #include <dm.h> |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 17 | #include <dm/uclass-internal.h> |
| 18 | #include <dm/pinctrl.h> |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 19 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 20 | |
| 21 | #ifdef CONFIG_SPL_BUILD |
Andreas Dannenberg | c68721d | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 22 | static void mmr_unlock(u32 base, u32 partition) |
| 23 | { |
| 24 | /* Translate the base address */ |
| 25 | phys_addr_t part_base = base + partition * CTRL_MMR0_PARTITION_SIZE; |
| 26 | |
| 27 | /* Unlock the requested partition if locked using two-step sequence */ |
| 28 | writel(CTRLMMR_LOCK_KICK0_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK0); |
| 29 | writel(CTRLMMR_LOCK_KICK1_UNLOCK_VAL, part_base + CTRLMMR_LOCK_KICK1); |
| 30 | } |
| 31 | |
| 32 | static void ctrl_mmr_unlock(void) |
| 33 | { |
| 34 | /* Unlock all WKUP_CTRL_MMR0 module registers */ |
| 35 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 0); |
| 36 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 1); |
| 37 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 2); |
| 38 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 3); |
| 39 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 6); |
| 40 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 7); |
| 41 | |
| 42 | /* Unlock all MCU_CTRL_MMR0 module registers */ |
| 43 | mmr_unlock(MCU_CTRL_MMR0_BASE, 0); |
| 44 | mmr_unlock(MCU_CTRL_MMR0_BASE, 1); |
| 45 | mmr_unlock(MCU_CTRL_MMR0_BASE, 2); |
| 46 | mmr_unlock(MCU_CTRL_MMR0_BASE, 6); |
| 47 | |
| 48 | /* Unlock all CTRL_MMR0 module registers */ |
| 49 | mmr_unlock(CTRL_MMR0_BASE, 0); |
| 50 | mmr_unlock(CTRL_MMR0_BASE, 1); |
| 51 | mmr_unlock(CTRL_MMR0_BASE, 2); |
| 52 | mmr_unlock(CTRL_MMR0_BASE, 3); |
| 53 | mmr_unlock(CTRL_MMR0_BASE, 6); |
| 54 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 55 | } |
| 56 | |
Andrew F. Davis | 407a219 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 57 | /* |
| 58 | * This uninitialized global variable would normal end up in the .bss section, |
| 59 | * but the .bss is cleared between writing and reading this variable, so move |
| 60 | * it to the .data section. |
| 61 | */ |
| 62 | u32 bootindex __attribute__((section(".data"))); |
| 63 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 64 | static void store_boot_index_from_rom(void) |
| 65 | { |
Andrew F. Davis | 407a219 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 66 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 67 | } |
| 68 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 69 | void board_init_f(ulong dummy) |
| 70 | { |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 71 | #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS) |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 72 | struct udevice *dev; |
| 73 | int ret; |
| 74 | #endif |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 75 | /* |
| 76 | * Cannot delay this further as there is a chance that |
| 77 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
| 78 | */ |
| 79 | store_boot_index_from_rom(); |
| 80 | |
Andreas Dannenberg | c68721d | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 81 | /* Make all control module registers accessible */ |
| 82 | ctrl_mmr_unlock(); |
| 83 | |
Lokesh Vutla | 23f7b1a | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 84 | #ifdef CONFIG_CPU_V7R |
| 85 | setup_k3_mpu_regions(); |
| 86 | #endif |
| 87 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 88 | /* Init DM early in-order to invoke system controller */ |
| 89 | spl_early_init(); |
| 90 | |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 91 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 92 | /* |
| 93 | * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue |
| 94 | * regardless of the result of pinctrl. Do this without probing the |
| 95 | * device, but instead by searching the device that would request the |
| 96 | * given sequence number if probed. The UART will be used by the system |
| 97 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 98 | * to initialize its pin settings. |
| 99 | */ |
| 100 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, true, &dev); |
| 101 | if (!ret) |
| 102 | pinctrl_select_state(dev, "default"); |
| 103 | |
| 104 | /* |
| 105 | * Load, start up, and configure system controller firmware. Provide |
| 106 | * the U-Boot console init function to the SYSFW post-PM configuration |
| 107 | * callback hook, effectively switching on (or over) the console |
| 108 | * output. |
| 109 | */ |
| 110 | k3_sysfw_loader(preloader_console_init); |
| 111 | #else |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 112 | /* Prepare console output */ |
| 113 | preloader_console_init(); |
Andreas Dannenberg | c222e3d | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 114 | #endif |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 115 | |
Andreas Dannenberg | 03facc7 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 116 | /* Perform EEPROM-based board detection */ |
| 117 | do_board_detect(); |
| 118 | |
Keerthy | 27380cb | 2019-10-24 15:00:52 +0530 | [diff] [blame] | 119 | #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) |
| 120 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(k3_avs), |
| 121 | &dev); |
| 122 | if (ret) |
| 123 | printf("AVS init failed: %d\n", ret); |
| 124 | #endif |
| 125 | |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 126 | #ifdef CONFIG_K3_AM654_DDRSS |
| 127 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
Andreas Dannenberg | 3e9b9c1 | 2019-03-11 15:15:43 -0500 | [diff] [blame] | 128 | if (ret) |
| 129 | panic("DRAM init failed: %d\n", ret); |
Lokesh Vutla | 59ebf4a | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 130 | #endif |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 131 | } |
| 132 | |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 133 | u32 spl_boot_mode(const u32 boot_device) |
| 134 | { |
| 135 | #if defined(CONFIG_SUPPORT_EMMC_BOOT) |
| 136 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 137 | |
| 138 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 139 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
| 140 | |
| 141 | /* eMMC boot0 mode is only supported for primary boot */ |
| 142 | if (bootindex == K3_PRIMARY_BOOTMODE && |
| 143 | bootmode == BOOT_DEVICE_MMC1) |
| 144 | return MMCSD_MODE_EMMCBOOT; |
| 145 | #endif |
| 146 | |
| 147 | /* Everything else use filesystem if available */ |
Tien Fong Chee | f4b4092 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 148 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Andrew F. Davis | 81089a5 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 149 | return MMCSD_MODE_FS; |
| 150 | #else |
| 151 | return MMCSD_MODE_RAW; |
| 152 | #endif |
| 153 | } |
| 154 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 155 | static u32 __get_backup_bootmedia(u32 devstat) |
| 156 | { |
| 157 | u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 158 | CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 159 | |
| 160 | switch (bkup_boot) { |
| 161 | case BACKUP_BOOT_DEVICE_USB: |
| 162 | return BOOT_DEVICE_USB; |
| 163 | case BACKUP_BOOT_DEVICE_UART: |
| 164 | return BOOT_DEVICE_UART; |
| 165 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 166 | return BOOT_DEVICE_ETHERNET; |
| 167 | case BACKUP_BOOT_DEVICE_MMC2: |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 168 | { |
| 169 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 170 | CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 171 | if (port == 0x0) |
| 172 | return BOOT_DEVICE_MMC1; |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 173 | return BOOT_DEVICE_MMC2; |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 174 | } |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 175 | case BACKUP_BOOT_DEVICE_SPI: |
| 176 | return BOOT_DEVICE_SPI; |
| 177 | case BACKUP_BOOT_DEVICE_HYPERFLASH: |
| 178 | return BOOT_DEVICE_HYPERFLASH; |
| 179 | case BACKUP_BOOT_DEVICE_I2C: |
| 180 | return BOOT_DEVICE_I2C; |
| 181 | }; |
| 182 | |
| 183 | return BOOT_DEVICE_RAM; |
| 184 | } |
| 185 | |
| 186 | static u32 __get_primary_bootmedia(u32 devstat) |
| 187 | { |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 188 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 189 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 190 | |
| 191 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI) |
| 192 | bootmode = BOOT_DEVICE_SPI; |
| 193 | |
Andrew F. Davis | b5700ef | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 194 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 195 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >> |
| 196 | CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT; |
| 197 | if (port == 0x0) |
| 198 | bootmode = BOOT_DEVICE_MMC1; |
| 199 | } else if (bootmode == BOOT_DEVICE_MMC1) { |
| 200 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >> |
| 201 | CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT; |
| 202 | if (port == 0x1) |
| 203 | bootmode = BOOT_DEVICE_MMC2; |
| 204 | } |
| 205 | |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 206 | return bootmode; |
| 207 | } |
| 208 | |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 209 | u32 spl_boot_device(void) |
| 210 | { |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 211 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Lokesh Vutla | e006460 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 212 | |
| 213 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 214 | return __get_primary_bootmedia(devstat); |
| 215 | else |
| 216 | return __get_backup_bootmedia(devstat); |
Lokesh Vutla | ed0e605 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 217 | } |
| 218 | #endif |
| 219 | |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 220 | #ifdef CONFIG_SYS_K3_SPL_ATF |
| 221 | |
| 222 | #define AM6_DEV_MCU_RTI0 134 |
| 223 | #define AM6_DEV_MCU_RTI1 135 |
| 224 | #define AM6_DEV_MCU_ARMSS0_CPU0 159 |
| 225 | #define AM6_DEV_MCU_ARMSS0_CPU1 245 |
| 226 | |
| 227 | void release_resources_for_core_shutdown(void) |
| 228 | { |
Lokesh Vutla | 78e5121 | 2019-09-09 12:47:38 +0530 | [diff] [blame] | 229 | struct ti_sci_handle *ti_sci = get_ti_sci_handle(); |
| 230 | struct ti_sci_dev_ops *dev_ops = &ti_sci->ops.dev_ops; |
| 231 | struct ti_sci_proc_ops *proc_ops = &ti_sci->ops.proc_ops; |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 232 | int ret; |
| 233 | u32 i; |
| 234 | |
| 235 | const u32 put_device_ids[] = { |
| 236 | AM6_DEV_MCU_RTI0, |
| 237 | AM6_DEV_MCU_RTI1, |
| 238 | }; |
| 239 | |
Andreas Dannenberg | f9380a7 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 240 | /* Iterate through list of devices to put (shutdown) */ |
| 241 | for (i = 0; i < ARRAY_SIZE(put_device_ids); i++) { |
| 242 | u32 id = put_device_ids[i]; |
| 243 | |
| 244 | ret = dev_ops->put_device(ti_sci, id); |
| 245 | if (ret) |
| 246 | panic("Failed to put device %u (%d)\n", id, ret); |
| 247 | } |
| 248 | |
| 249 | const u32 put_core_ids[] = { |
| 250 | AM6_DEV_MCU_ARMSS0_CPU1, |
| 251 | AM6_DEV_MCU_ARMSS0_CPU0, /* Handle CPU0 after CPU1 */ |
| 252 | }; |
| 253 | |
| 254 | /* Iterate through list of cores to put (shutdown) */ |
| 255 | for (i = 0; i < ARRAY_SIZE(put_core_ids); i++) { |
| 256 | u32 id = put_core_ids[i]; |
| 257 | |
| 258 | /* |
| 259 | * Queue up the core shutdown request. Note that this call |
| 260 | * needs to be followed up by an actual invocation of an WFE |
| 261 | * or WFI CPU instruction. |
| 262 | */ |
| 263 | ret = proc_ops->proc_shutdown_no_wait(ti_sci, id); |
| 264 | if (ret) |
| 265 | panic("Failed sending core %u shutdown message (%d)\n", |
| 266 | id, ret); |
| 267 | } |
| 268 | } |
| 269 | #endif |