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> |
Faiz Abbas | 3385a86 | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 10 | #include <fdt_support.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 13 | #include <asm/io.h> |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 14 | #include <spl.h> |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 15 | #include <asm/arch/hardware.h> |
Andrew Davis | f179985 | 2023-04-06 11:38:16 -0500 | [diff] [blame^] | 16 | #include "sysfw-loader.h" |
Andreas Dannenberg | 63f5c85 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
Lokesh Vutla | c1e60e8 | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 18 | #include "common.h" |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 19 | #include <dm.h> |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 20 | #include <dm/uclass-internal.h> |
| 21 | #include <dm/pinctrl.h> |
Andreas Dannenberg | 31175f8 | 2019-06-07 19:24:42 +0530 | [diff] [blame] | 22 | #include <linux/soc/ti/ti_sci_protocol.h> |
Faiz Abbas | fe1217e | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 23 | #include <log.h> |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 24 | #include <mmc.h> |
Faiz Abbas | fe1217e | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 25 | #include <stdlib.h> |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 26 | |
Faiz Abbas | 3385a86 | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 29 | #ifdef CONFIG_K3_LOAD_SYSFW |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 30 | struct fwl_data main_cbass_fwls[] = { |
| 31 | { "MMCSD1_CFG", 2057, 1 }, |
| 32 | { "MMCSD0_CFG", 2058, 1 }, |
| 33 | { "USB3SS0_SLV0", 2176, 2 }, |
| 34 | { "PCIE0_SLV", 2336, 8 }, |
| 35 | { "PCIE1_SLV", 2337, 8 }, |
| 36 | { "PCIE0_CFG", 2688, 1 }, |
| 37 | { "PCIE1_CFG", 2689, 1 }, |
| 38 | }, mcu_cbass_fwls[] = { |
| 39 | { "MCU_ARMSS0_CORE0_SLV", 1024, 1 }, |
| 40 | { "MCU_ARMSS0_CORE1_SLV", 1028, 1 }, |
| 41 | { "MCU_FSS0_S1", 1033, 8 }, |
| 42 | { "MCU_FSS0_S0", 1036, 8 }, |
| 43 | { "MCU_CPSW0", 1220, 1 }, |
| 44 | }; |
| 45 | #endif |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 46 | |
Andreas Dannenberg | 1c855c1 | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 47 | static void ctrl_mmr_unlock(void) |
| 48 | { |
| 49 | /* Unlock all WKUP_CTRL_MMR0 module registers */ |
| 50 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 0); |
| 51 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 1); |
| 52 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 2); |
| 53 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 3); |
| 54 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 6); |
| 55 | mmr_unlock(WKUP_CTRL_MMR0_BASE, 7); |
| 56 | |
| 57 | /* Unlock all MCU_CTRL_MMR0 module registers */ |
| 58 | mmr_unlock(MCU_CTRL_MMR0_BASE, 0); |
| 59 | mmr_unlock(MCU_CTRL_MMR0_BASE, 1); |
| 60 | mmr_unlock(MCU_CTRL_MMR0_BASE, 2); |
| 61 | mmr_unlock(MCU_CTRL_MMR0_BASE, 6); |
| 62 | |
| 63 | /* Unlock all CTRL_MMR0 module registers */ |
| 64 | mmr_unlock(CTRL_MMR0_BASE, 0); |
| 65 | mmr_unlock(CTRL_MMR0_BASE, 1); |
| 66 | mmr_unlock(CTRL_MMR0_BASE, 2); |
| 67 | mmr_unlock(CTRL_MMR0_BASE, 3); |
| 68 | mmr_unlock(CTRL_MMR0_BASE, 6); |
| 69 | mmr_unlock(CTRL_MMR0_BASE, 7); |
| 70 | } |
| 71 | |
Andrew F. Davis | 9ffea34 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 72 | /* |
| 73 | * This uninitialized global variable would normal end up in the .bss section, |
| 74 | * but the .bss is cleared between writing and reading this variable, so move |
| 75 | * it to the .data section. |
| 76 | */ |
Marek BehĂșn | 4bebdd3 | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 77 | u32 bootindex __section(".data"); |
Andrew F. Davis | 9ffea34 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 78 | |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 79 | static void store_boot_index_from_rom(void) |
| 80 | { |
Andrew F. Davis | 9ffea34 | 2019-04-12 12:54:42 -0400 | [diff] [blame] | 81 | bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 82 | } |
| 83 | |
Faiz Abbas | b4372bf | 2020-08-03 11:35:08 +0530 | [diff] [blame] | 84 | #if defined(CONFIG_K3_LOAD_SYSFW) && CONFIG_IS_ENABLED(DM_MMC) |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 85 | void k3_mmc_stop_clock(void) |
| 86 | { |
| 87 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 88 | struct mmc *mmc = find_mmc_device(0); |
| 89 | |
| 90 | if (!mmc) |
| 91 | return; |
| 92 | |
| 93 | mmc->saved_clock = mmc->clock; |
| 94 | mmc_set_clock(mmc, 0, true); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void k3_mmc_restart_clock(void) |
| 99 | { |
| 100 | if (spl_boot_device() == BOOT_DEVICE_MMC1) { |
| 101 | struct mmc *mmc = find_mmc_device(0); |
| 102 | |
| 103 | if (!mmc) |
| 104 | return; |
| 105 | |
| 106 | mmc_set_clock(mmc, mmc->saved_clock, false); |
| 107 | } |
| 108 | } |
Faiz Abbas | b4372bf | 2020-08-03 11:35:08 +0530 | [diff] [blame] | 109 | #else |
| 110 | void k3_mmc_stop_clock(void) {} |
| 111 | void k3_mmc_restart_clock(void) {} |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 112 | #endif |
Faiz Abbas | 3385a86 | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 113 | #if CONFIG_IS_ENABLED(DFU) || CONFIG_IS_ENABLED(USB_STORAGE) |
| 114 | #define CTRLMMR_SERDES0_CTRL 0x00104080 |
| 115 | #define PCIE_LANE0 0x1 |
| 116 | static int fixup_usb_boot(void) |
| 117 | { |
| 118 | int ret; |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 119 | |
Faiz Abbas | 3385a86 | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 120 | switch (spl_boot_device()) { |
| 121 | case BOOT_DEVICE_USB: |
| 122 | /* |
| 123 | * If bootmode is Host bootmode, fixup the dr_mode to host |
| 124 | * before the dwc3 bind takes place |
| 125 | */ |
| 126 | ret = fdt_find_and_setprop((void *)gd->fdt_blob, |
Aswath Govindraju | 271d76e | 2022-05-18 16:49:13 +0530 | [diff] [blame] | 127 | "/bus@100000/dwc3@4000000/usb@10000", |
| 128 | "dr_mode", "host", 5, 0); |
Faiz Abbas | 3385a86 | 2020-08-03 11:35:09 +0530 | [diff] [blame] | 129 | if (ret) |
| 130 | printf("%s: fdt_find_and_setprop() failed:%d\n", __func__, |
| 131 | ret); |
| 132 | fallthrough; |
| 133 | case BOOT_DEVICE_DFU: |
| 134 | /* |
| 135 | * The serdes mux between PCIe and USB3 needs to be set to PCIe for |
| 136 | * accessing the interface at USB 2.0 |
| 137 | */ |
| 138 | writel(PCIE_LANE0, CTRLMMR_SERDES0_CTRL); |
| 139 | default: |
| 140 | break; |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
| 146 | int fdtdec_board_setup(const void *fdt_blob) |
| 147 | { |
| 148 | return fixup_usb_boot(); |
| 149 | } |
| 150 | #endif |
Roger Quadros | 768e667 | 2021-09-08 15:28:59 -0500 | [diff] [blame] | 151 | |
| 152 | static void setup_am654_navss_northbridge(void) |
| 153 | { |
| 154 | /* |
| 155 | * NB0 is bridge to SRAM and NB1 is bridge to DDR. |
| 156 | * To ensure that SRAM transfers are not stalled due to |
| 157 | * delays during DDR refreshes, SRAM traffic should be higher |
| 158 | * priority (threadmap=2) than DDR traffic (threadmap=0). |
| 159 | */ |
| 160 | writel(0x2, NAVSS0_NBSS_NB0_CFG_BASE + NAVSS_NBSS_THREADMAP); |
| 161 | writel(0x0, NAVSS0_NBSS_NB1_CFG_BASE + NAVSS_NBSS_THREADMAP); |
| 162 | } |
| 163 | |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 164 | void board_init_f(ulong dummy) |
| 165 | { |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 166 | #if defined(CONFIG_K3_LOAD_SYSFW) || defined(CONFIG_K3_AM654_DDRSS) |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 167 | struct udevice *dev; |
Faiz Abbas | fe1217e | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 168 | size_t pool_size; |
| 169 | void *pool_addr; |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 170 | int ret; |
| 171 | #endif |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 172 | /* |
| 173 | * Cannot delay this further as there is a chance that |
| 174 | * K3_BOOT_PARAM_TABLE_INDEX can be over written by SPL MALLOC section. |
| 175 | */ |
| 176 | store_boot_index_from_rom(); |
| 177 | |
Andreas Dannenberg | 1c855c1 | 2018-08-27 15:57:12 +0530 | [diff] [blame] | 178 | /* Make all control module registers accessible */ |
| 179 | ctrl_mmr_unlock(); |
| 180 | |
Roger Quadros | 768e667 | 2021-09-08 15:28:59 -0500 | [diff] [blame] | 181 | setup_am654_navss_northbridge(); |
| 182 | |
Lokesh Vutla | c1e60e8 | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 183 | #ifdef CONFIG_CPU_V7R |
Lokesh Vutla | 5fbd6fe | 2019-12-31 15:49:55 +0530 | [diff] [blame] | 184 | disable_linefill_optimization(); |
Lokesh Vutla | c1e60e8 | 2018-11-02 19:51:03 +0530 | [diff] [blame] | 185 | setup_k3_mpu_regions(); |
| 186 | #endif |
| 187 | |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 188 | /* Init DM early in-order to invoke system controller */ |
| 189 | spl_early_init(); |
| 190 | |
Andreas Dannenberg | b45d2cd | 2018-12-04 22:29:47 -0600 | [diff] [blame] | 191 | #ifdef CONFIG_K3_EARLY_CONS |
| 192 | /* |
| 193 | * Allow establishing an early console as required for example when |
| 194 | * doing a UART-based boot. Note that this console may not "survive" |
| 195 | * through a SYSFW PM-init step and will need a re-init in some way |
| 196 | * due to changing module clock frequencies. |
| 197 | */ |
| 198 | early_console_init(); |
| 199 | #endif |
| 200 | |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 201 | #ifdef CONFIG_K3_LOAD_SYSFW |
| 202 | /* |
Faiz Abbas | fe1217e | 2020-08-03 11:35:06 +0530 | [diff] [blame] | 203 | * Initialize an early full malloc environment. Do so by allocating a |
| 204 | * new malloc area inside the currently active pre-relocation "first" |
| 205 | * malloc pool of which we use all that's left. |
| 206 | */ |
| 207 | pool_size = CONFIG_VAL(SYS_MALLOC_F_LEN) - gd->malloc_ptr; |
| 208 | pool_addr = malloc(pool_size); |
| 209 | if (!pool_addr) |
| 210 | panic("ERROR: Can't allocate full malloc pool!\n"); |
| 211 | |
| 212 | mem_malloc_init((ulong)pool_addr, (ulong)pool_size); |
| 213 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
| 214 | debug("%s: initialized an early full malloc pool at 0x%08lx of 0x%lx bytes\n", |
| 215 | __func__, (unsigned long)pool_addr, (unsigned long)pool_size); |
| 216 | /* |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 217 | * Process pinctrl for the serial0 a.k.a. WKUP_UART0 module and continue |
| 218 | * regardless of the result of pinctrl. Do this without probing the |
| 219 | * device, but instead by searching the device that would request the |
| 220 | * given sequence number if probed. The UART will be used by the system |
| 221 | * firmware (SYSFW) image for various purposes and SYSFW depends on us |
| 222 | * to initialize its pin settings. |
| 223 | */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 224 | ret = uclass_find_device_by_seq(UCLASS_SERIAL, 0, &dev); |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 225 | if (!ret) |
| 226 | pinctrl_select_state(dev, "default"); |
| 227 | |
| 228 | /* |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 229 | * Load, start up, and configure system controller firmware while |
| 230 | * also populating the SYSFW post-PM configuration callback hook. |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 231 | */ |
Lokesh Vutla | 17951b7 | 2020-08-05 22:44:18 +0530 | [diff] [blame] | 232 | k3_sysfw_loader(false, k3_mmc_stop_clock, k3_mmc_restart_clock); |
Faiz Abbas | 6839321 | 2020-02-26 13:44:36 +0530 | [diff] [blame] | 233 | |
| 234 | /* Prepare console output */ |
| 235 | preloader_console_init(); |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 236 | |
| 237 | /* Disable ROM configured firewalls right after loading sysfw */ |
Andrew F. Davis | f0bcb66 | 2020-01-10 14:35:21 -0500 | [diff] [blame] | 238 | remove_fwl_configs(main_cbass_fwls, ARRAY_SIZE(main_cbass_fwls)); |
| 239 | remove_fwl_configs(mcu_cbass_fwls, ARRAY_SIZE(mcu_cbass_fwls)); |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 240 | #else |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 241 | /* Prepare console output */ |
| 242 | preloader_console_init(); |
Andreas Dannenberg | ea91da1 | 2019-06-04 17:55:50 -0500 | [diff] [blame] | 243 | #endif |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 244 | |
Lokesh Vutla | 5fafe44 | 2020-03-10 16:50:58 +0530 | [diff] [blame] | 245 | /* Output System Firmware version info */ |
| 246 | k3_sysfw_print_ver(); |
| 247 | |
Christian Gmeiner | cae1ae8 | 2023-03-03 20:16:28 +0100 | [diff] [blame] | 248 | if (IS_ENABLED(CONFIG_K3_BOARD_DETECT)) |
Christian Gmeiner | 955bc4f | 2022-02-15 07:47:55 +0100 | [diff] [blame] | 249 | do_board_detect(); |
Andreas Dannenberg | 63f5c85 | 2019-06-04 18:08:26 -0500 | [diff] [blame] | 250 | |
Keerthy | 2cd5097 | 2019-10-24 15:00:52 +0530 | [diff] [blame] | 251 | #if defined(CONFIG_CPU_V7R) && defined(CONFIG_K3_AVS0) |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 252 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(k3_avs), |
Keerthy | 2cd5097 | 2019-10-24 15:00:52 +0530 | [diff] [blame] | 253 | &dev); |
| 254 | if (ret) |
| 255 | printf("AVS init failed: %d\n", ret); |
| 256 | #endif |
| 257 | |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 258 | #ifdef CONFIG_K3_AM654_DDRSS |
| 259 | ret = uclass_get_device(UCLASS_RAM, 0, &dev); |
Andreas Dannenberg | 7f6b62e | 2019-03-11 15:15:43 -0500 | [diff] [blame] | 260 | if (ret) |
| 261 | panic("DRAM init failed: %d\n", ret); |
Lokesh Vutla | 2c69d5c | 2018-11-02 19:51:06 +0530 | [diff] [blame] | 262 | #endif |
Jan Kiszka | 7ce99f7 | 2020-05-18 07:57:22 +0200 | [diff] [blame] | 263 | spl_enable_dcache(); |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 264 | } |
| 265 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 266 | u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Andrew F. Davis | c516146 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 267 | { |
| 268 | #if defined(CONFIG_SUPPORT_EMMC_BOOT) |
| 269 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Andrew F. Davis | c516146 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 270 | |
| 271 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 272 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
| 273 | |
| 274 | /* eMMC boot0 mode is only supported for primary boot */ |
| 275 | if (bootindex == K3_PRIMARY_BOOTMODE && |
| 276 | bootmode == BOOT_DEVICE_MMC1) |
| 277 | return MMCSD_MODE_EMMCBOOT; |
| 278 | #endif |
| 279 | |
| 280 | /* Everything else use filesystem if available */ |
Tien Fong Chee | 6091dd1 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 281 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Andrew F. Davis | c516146 | 2018-10-03 10:03:23 -0500 | [diff] [blame] | 282 | return MMCSD_MODE_FS; |
| 283 | #else |
| 284 | return MMCSD_MODE_RAW; |
| 285 | #endif |
| 286 | } |
| 287 | |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 288 | static u32 __get_backup_bootmedia(u32 devstat) |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 289 | { |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 290 | u32 bkup_boot = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_MASK) >> |
| 291 | CTRLMMR_MAIN_DEVSTAT_BKUP_BOOTMODE_SHIFT; |
| 292 | |
| 293 | switch (bkup_boot) { |
| 294 | case BACKUP_BOOT_DEVICE_USB: |
| 295 | return BOOT_DEVICE_USB; |
| 296 | case BACKUP_BOOT_DEVICE_UART: |
| 297 | return BOOT_DEVICE_UART; |
| 298 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 299 | return BOOT_DEVICE_ETHERNET; |
| 300 | case BACKUP_BOOT_DEVICE_MMC2: |
Andrew F. Davis | f515cf0 | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 301 | { |
| 302 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_MASK) >> |
| 303 | CTRLMMR_MAIN_DEVSTAT_BKUP_MMC_PORT_SHIFT; |
| 304 | if (port == 0x0) |
| 305 | return BOOT_DEVICE_MMC1; |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 306 | return BOOT_DEVICE_MMC2; |
Andrew F. Davis | f515cf0 | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 307 | } |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 308 | case BACKUP_BOOT_DEVICE_SPI: |
| 309 | return BOOT_DEVICE_SPI; |
| 310 | case BACKUP_BOOT_DEVICE_HYPERFLASH: |
| 311 | return BOOT_DEVICE_HYPERFLASH; |
| 312 | case BACKUP_BOOT_DEVICE_I2C: |
| 313 | return BOOT_DEVICE_I2C; |
| 314 | }; |
| 315 | |
Lokesh Vutla | 3288644 | 2018-08-27 15:57:09 +0530 | [diff] [blame] | 316 | return BOOT_DEVICE_RAM; |
| 317 | } |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 318 | |
| 319 | static u32 __get_primary_bootmedia(u32 devstat) |
| 320 | { |
Andrew F. Davis | f515cf0 | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 321 | u32 bootmode = (devstat & CTRLMMR_MAIN_DEVSTAT_BOOTMODE_MASK) >> |
| 322 | CTRLMMR_MAIN_DEVSTAT_BOOTMODE_SHIFT; |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 323 | |
| 324 | if (bootmode == BOOT_DEVICE_OSPI || bootmode == BOOT_DEVICE_QSPI) |
| 325 | bootmode = BOOT_DEVICE_SPI; |
| 326 | |
Andrew F. Davis | f515cf0 | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 327 | if (bootmode == BOOT_DEVICE_MMC2) { |
| 328 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_MMC_PORT_MASK) >> |
| 329 | CTRLMMR_MAIN_DEVSTAT_MMC_PORT_SHIFT; |
| 330 | if (port == 0x0) |
| 331 | bootmode = BOOT_DEVICE_MMC1; |
| 332 | } else if (bootmode == BOOT_DEVICE_MMC1) { |
| 333 | u32 port = (devstat & CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_MASK) >> |
| 334 | CTRLMMR_MAIN_DEVSTAT_EMMC_PORT_SHIFT; |
| 335 | if (port == 0x1) |
| 336 | bootmode = BOOT_DEVICE_MMC2; |
Faiz Abbas | 0ae20ed | 2020-08-03 11:35:10 +0530 | [diff] [blame] | 337 | } else if (bootmode == BOOT_DEVICE_DFU) { |
| 338 | u32 mode = (devstat & CTRLMMR_MAIN_DEVSTAT_USB_MODE_MASK) >> |
| 339 | CTRLMMR_MAIN_DEVSTAT_USB_MODE_SHIFT; |
| 340 | if (mode == 0x2) |
| 341 | bootmode = BOOT_DEVICE_USB; |
Andrew F. Davis | f515cf0 | 2018-10-03 10:03:22 -0500 | [diff] [blame] | 342 | } |
| 343 | |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 344 | return bootmode; |
| 345 | } |
| 346 | |
| 347 | u32 spl_boot_device(void) |
| 348 | { |
| 349 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
Lokesh Vutla | c7bfb85 | 2018-08-27 15:57:11 +0530 | [diff] [blame] | 350 | |
| 351 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 352 | return __get_primary_bootmedia(devstat); |
| 353 | else |
| 354 | return __get_backup_bootmedia(devstat); |
| 355 | } |