Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | #include <asm/io.h> |
| 3 | #include <asm/arch/hardware.h> |
| 4 | #include <asm/arch/spl.h> |
| 5 | |
| 6 | static u32 __get_backup_bootmedia(u32 main_devstat) |
| 7 | { |
| 8 | u32 bkup_bootmode = |
| 9 | (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >> |
| 10 | MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT; |
| 11 | u32 bkup_bootmode_cfg = |
| 12 | (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >> |
| 13 | MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT; |
| 14 | |
| 15 | switch (bkup_bootmode) { |
| 16 | case BACKUP_BOOT_DEVICE_UART: |
| 17 | return BOOT_DEVICE_UART; |
| 18 | |
| 19 | case BACKUP_BOOT_DEVICE_DFU: |
| 20 | if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE_MASK) |
| 21 | return BOOT_DEVICE_USB; |
| 22 | return BOOT_DEVICE_DFU; |
| 23 | |
| 24 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 25 | return BOOT_DEVICE_ETHERNET; |
| 26 | |
| 27 | case BACKUP_BOOT_DEVICE_MMC: |
| 28 | if (bkup_bootmode_cfg) |
| 29 | return BOOT_DEVICE_MMC2; |
| 30 | return BOOT_DEVICE_MMC1; |
| 31 | |
| 32 | case BACKUP_BOOT_DEVICE_SPI: |
| 33 | return BOOT_DEVICE_SPI; |
| 34 | |
| 35 | case BACKUP_BOOT_DEVICE_I2C: |
| 36 | return BOOT_DEVICE_I2C; |
| 37 | }; |
| 38 | |
| 39 | return BOOT_DEVICE_RAM; |
| 40 | } |
| 41 | |
| 42 | static u32 __get_primary_bootmedia(u32 main_devstat) |
| 43 | { |
| 44 | u32 bootmode = (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 45 | MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 46 | u32 bootmode_cfg = |
| 47 | (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >> |
| 48 | MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT; |
| 49 | |
| 50 | switch (bootmode) { |
| 51 | case BOOT_DEVICE_OSPI: |
| 52 | fallthrough; |
| 53 | case BOOT_DEVICE_QSPI: |
| 54 | fallthrough; |
| 55 | case BOOT_DEVICE_XSPI: |
| 56 | fallthrough; |
| 57 | case BOOT_DEVICE_SPI: |
| 58 | return BOOT_DEVICE_SPI; |
| 59 | |
| 60 | case BOOT_DEVICE_ETHERNET_RGMII: |
| 61 | fallthrough; |
| 62 | case BOOT_DEVICE_ETHERNET_RMII: |
| 63 | return BOOT_DEVICE_ETHERNET; |
| 64 | |
| 65 | case BOOT_DEVICE_EMMC: |
| 66 | return BOOT_DEVICE_MMC1; |
| 67 | |
| 68 | case BOOT_DEVICE_NAND: |
| 69 | return BOOT_DEVICE_NAND; |
| 70 | |
| 71 | case BOOT_DEVICE_MMC: |
| 72 | if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >> |
| 73 | MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT) |
| 74 | return BOOT_DEVICE_MMC2; |
| 75 | return BOOT_DEVICE_MMC1; |
| 76 | |
| 77 | case BOOT_DEVICE_DFU: |
| 78 | if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE_MASK) >> |
| 79 | MAIN_DEVSTAT_PRIMARY_USB_MODE_SHIFT) |
| 80 | return BOOT_DEVICE_USB; |
| 81 | return BOOT_DEVICE_DFU; |
| 82 | |
| 83 | case BOOT_DEVICE_NOBOOT: |
| 84 | return BOOT_DEVICE_RAM; |
| 85 | } |
| 86 | |
| 87 | return bootmode; |
| 88 | } |
| 89 | |
| 90 | u32 get_boot_device(void) |
| 91 | { |
| 92 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 93 | u32 bootmode = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); |
| 94 | u32 bootmedia; |
| 95 | |
| 96 | if (bootmode == K3_PRIMARY_BOOTMODE) |
| 97 | bootmedia = __get_primary_bootmedia(devstat); |
| 98 | else |
| 99 | bootmedia = __get_backup_bootmedia(devstat); |
| 100 | |
| 101 | debug("%s: devstat = 0x%x bootmedia = 0x%x bootmode = %d\n", |
| 102 | __func__, devstat, bootmedia, bootmode); |
| 103 | |
| 104 | return bootmedia; |
| 105 | } |