Dave Gerlach | 96571ec | 2021-04-23 11:27:32 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * AM642: SoC specific initialization |
| 4 | * |
| 5 | * Copyright (C) 2020-2021 Texas Instruments Incorporated - https://www.ti.com/ |
| 6 | * Keerthy <j-keerthy@ti.com> |
| 7 | * Dave Gerlach <d-gerlach@ti.com> |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <spl.h> |
| 12 | #include <asm/io.h> |
Keerthy | 05d670e | 2021-04-23 11:27:33 -0500 | [diff] [blame^] | 13 | #include <asm/arch/hardware.h> |
Dave Gerlach | 96571ec | 2021-04-23 11:27:32 -0500 | [diff] [blame] | 14 | #include "common.h" |
| 15 | |
| 16 | #if defined(CONFIG_SPL_BUILD) |
| 17 | |
| 18 | void board_init_f(ulong dummy) |
| 19 | { |
| 20 | #if defined(CONFIG_CPU_V7R) |
| 21 | setup_k3_mpu_regions(); |
| 22 | #endif |
| 23 | |
| 24 | /* Init DM early */ |
| 25 | spl_early_init(); |
| 26 | |
| 27 | preloader_console_init(); |
| 28 | } |
Keerthy | 05d670e | 2021-04-23 11:27:33 -0500 | [diff] [blame^] | 29 | |
| 30 | u32 spl_boot_mode(const u32 boot_device) |
| 31 | { |
| 32 | switch (boot_device) { |
| 33 | case BOOT_DEVICE_MMC1: |
| 34 | return MMCSD_MODE_EMMCBOOT; |
| 35 | |
| 36 | case BOOT_DEVICE_MMC2: |
| 37 | return MMCSD_MODE_FS; |
| 38 | |
| 39 | default: |
| 40 | return MMCSD_MODE_RAW; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | static u32 __get_backup_bootmedia(u32 main_devstat) |
| 45 | { |
| 46 | u32 bkup_bootmode = |
| 47 | (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_MASK) >> |
| 48 | MAIN_DEVSTAT_BACKUP_BOOTMODE_SHIFT; |
| 49 | u32 bkup_bootmode_cfg = |
| 50 | (main_devstat & MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_MASK) >> |
| 51 | MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG_SHIFT; |
| 52 | |
| 53 | switch (bkup_bootmode) { |
| 54 | case BACKUP_BOOT_DEVICE_UART: |
| 55 | return BOOT_DEVICE_UART; |
| 56 | |
| 57 | case BACKUP_BOOT_DEVICE_USB: |
| 58 | return BOOT_DEVICE_USB; |
| 59 | |
| 60 | case BACKUP_BOOT_DEVICE_ETHERNET: |
| 61 | return BOOT_DEVICE_ETHERNET; |
| 62 | |
| 63 | case BACKUP_BOOT_DEVICE_MMC: |
| 64 | if (bkup_bootmode_cfg) |
| 65 | return BOOT_DEVICE_MMC2; |
| 66 | return BOOT_DEVICE_MMC1; |
| 67 | |
| 68 | case BACKUP_BOOT_DEVICE_SPI: |
| 69 | return BOOT_DEVICE_SPI; |
| 70 | |
| 71 | case BACKUP_BOOT_DEVICE_I2C: |
| 72 | return BOOT_DEVICE_I2C; |
| 73 | }; |
| 74 | |
| 75 | return BOOT_DEVICE_RAM; |
| 76 | } |
| 77 | |
| 78 | static u32 __get_primary_bootmedia(u32 main_devstat) |
| 79 | { |
| 80 | u32 bootmode = (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK) >> |
| 81 | MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT; |
| 82 | u32 bootmode_cfg = |
| 83 | (main_devstat & MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_MASK) >> |
| 84 | MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG_SHIFT; |
| 85 | |
| 86 | switch (bootmode) { |
| 87 | case BOOT_DEVICE_OSPI: |
| 88 | fallthrough; |
| 89 | case BOOT_DEVICE_QSPI: |
| 90 | fallthrough; |
| 91 | case BOOT_DEVICE_XSPI: |
| 92 | fallthrough; |
| 93 | case BOOT_DEVICE_SPI: |
| 94 | return BOOT_DEVICE_SPI; |
| 95 | |
| 96 | case BOOT_DEVICE_ETHERNET_RGMII: |
| 97 | fallthrough; |
| 98 | case BOOT_DEVICE_ETHERNET_RMII: |
| 99 | return BOOT_DEVICE_ETHERNET; |
| 100 | |
| 101 | case BOOT_DEVICE_EMMC: |
| 102 | return BOOT_DEVICE_MMC1; |
| 103 | |
| 104 | case BOOT_DEVICE_MMC: |
| 105 | if ((bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT_MASK) >> |
| 106 | MAIN_DEVSTAT_PRIMARY_MMC_PORT_SHIFT) |
| 107 | return BOOT_DEVICE_MMC2; |
| 108 | return BOOT_DEVICE_MMC1; |
| 109 | |
| 110 | case BOOT_DEVICE_NOBOOT: |
| 111 | return BOOT_DEVICE_RAM; |
| 112 | } |
| 113 | |
| 114 | return bootmode; |
| 115 | } |
| 116 | |
| 117 | u32 spl_boot_device(void) |
| 118 | { |
| 119 | u32 devstat = readl(CTRLMMR_MAIN_DEVSTAT); |
| 120 | |
| 121 | if (bootindex == K3_PRIMARY_BOOTMODE) |
| 122 | return __get_primary_bootmedia(devstat); |
| 123 | else |
| 124 | return __get_backup_bootmedia(devstat); |
| 125 | } |
Dave Gerlach | 96571ec | 2021-04-23 11:27:32 -0500 | [diff] [blame] | 126 | #endif |