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