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