Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 - 2016 Xilinx, Inc. |
| 4 | * |
Michal Simek | a8c9436 | 2023-07-10 14:35:49 +0200 | [diff] [blame] | 5 | * Michal Simek <michal.simek@amd.com> |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 9 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Sean Anderson | f081e88 | 2024-02-22 15:05:11 -0500 | [diff] [blame] | 12 | #include <semihosting.h> |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 15 | |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/spl.h> |
| 18 | #include <asm/arch/hardware.h> |
Jorge Ramirez-Ortiz | 3545696 | 2021-06-13 20:55:53 +0200 | [diff] [blame] | 19 | #include <asm/arch/ecc_spl_init.h> |
Michal Simek | ef95501 | 2019-12-03 15:02:50 +0100 | [diff] [blame] | 20 | #include <asm/arch/psu_init_gpl.h> |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 21 | #include <asm/arch/sys_proto.h> |
| 22 | |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 23 | #if defined(CONFIG_DEBUG_UART_BOARD_INIT) |
| 24 | void board_debug_uart_init(void) |
| 25 | { |
| 26 | psu_uboot_init(); |
| 27 | } |
| 28 | #endif |
| 29 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 30 | void board_init_f(ulong dummy) |
| 31 | { |
Michal Simek | e5710e3 | 2022-02-17 14:28:42 +0100 | [diff] [blame] | 32 | #if !defined(CONFIG_DEBUG_UART_BOARD_INIT) |
| 33 | psu_uboot_init(); |
| 34 | #endif |
| 35 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 36 | board_early_init_r(); |
Jorge Ramirez-Ortiz | 3545696 | 2021-06-13 20:55:53 +0200 | [diff] [blame] | 37 | #ifdef CONFIG_SPL_ZYNQMP_DRAM_ECC_INIT |
| 38 | zynqmp_ecc_init(); |
| 39 | #endif |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Michal Simek | 3eb32de | 2016-08-15 09:41:36 +0200 | [diff] [blame] | 42 | static void ps_mode_reset(ulong mode) |
| 43 | { |
Michal Simek | 3eb32de | 2016-08-15 09:41:36 +0200 | [diff] [blame] | 44 | writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT, |
| 45 | &crlapb_base->boot_pin_ctrl); |
| 46 | udelay(5); |
| 47 | writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_VAL_SHIFT | |
| 48 | mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT, |
| 49 | &crlapb_base->boot_pin_ctrl); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Set default PS_MODE1 which is used for USB ULPI phy reset |
| 54 | * Also other resets can be connected to this certain pin |
| 55 | */ |
| 56 | #ifndef MODE_RESET |
| 57 | # define MODE_RESET PS_MODE1 |
| 58 | #endif |
| 59 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 60 | #ifdef CONFIG_SPL_BOARD_INIT |
| 61 | void spl_board_init(void) |
| 62 | { |
| 63 | preloader_console_init(); |
Michal Simek | 3eb32de | 2016-08-15 09:41:36 +0200 | [diff] [blame] | 64 | ps_mode_reset(MODE_RESET); |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 65 | board_init(); |
Michal Simek | ef95501 | 2019-12-03 15:02:50 +0100 | [diff] [blame] | 66 | psu_post_config_data(); |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 67 | } |
| 68 | #endif |
| 69 | |
Sean Anderson | f081e88 | 2024-02-22 15:05:11 -0500 | [diff] [blame] | 70 | static u32 jtag_boot_device(void) |
| 71 | { |
| 72 | return semihosting_enabled() ? BOOT_DEVICE_SMH : BOOT_DEVICE_RAM; |
| 73 | } |
| 74 | |
Michal Simek | 6d651d9 | 2019-12-09 13:00:57 +0100 | [diff] [blame] | 75 | void board_boot_order(u32 *spl_boot_list) |
| 76 | { |
| 77 | spl_boot_list[0] = spl_boot_device(); |
| 78 | |
| 79 | if (spl_boot_list[0] == BOOT_DEVICE_MMC1) |
| 80 | spl_boot_list[1] = BOOT_DEVICE_MMC2; |
| 81 | if (spl_boot_list[0] == BOOT_DEVICE_MMC2) |
| 82 | spl_boot_list[1] = BOOT_DEVICE_MMC1; |
Michal Simek | 2642eb7 | 2020-03-11 15:00:51 +0100 | [diff] [blame] | 83 | |
Sean Anderson | f081e88 | 2024-02-22 15:05:11 -0500 | [diff] [blame] | 84 | spl_boot_list[2] = jtag_boot_device(); |
Michal Simek | 6d651d9 | 2019-12-09 13:00:57 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 87 | u32 spl_boot_device(void) |
| 88 | { |
| 89 | u32 reg = 0; |
| 90 | u8 bootmode; |
| 91 | |
Michal Simek | 94ddcaa | 2016-08-30 16:17:27 +0200 | [diff] [blame] | 92 | #if defined(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE_ENABLED) |
| 93 | /* Change default boot mode at run-time */ |
Michal Simek | 833e0c4 | 2016-10-25 11:43:02 +0200 | [diff] [blame] | 94 | writel(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE << BOOT_MODE_ALT_SHIFT, |
Michal Simek | 94ddcaa | 2016-08-30 16:17:27 +0200 | [diff] [blame] | 95 | &crlapb_base->boot_mode); |
| 96 | #endif |
| 97 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 98 | reg = readl(&crlapb_base->boot_mode); |
Michal Simek | 833e0c4 | 2016-10-25 11:43:02 +0200 | [diff] [blame] | 99 | if (reg >> BOOT_MODE_ALT_SHIFT) |
| 100 | reg >>= BOOT_MODE_ALT_SHIFT; |
| 101 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 102 | bootmode = reg & BOOT_MODES_MASK; |
| 103 | |
| 104 | switch (bootmode) { |
| 105 | case JTAG_MODE: |
Sean Anderson | f081e88 | 2024-02-22 15:05:11 -0500 | [diff] [blame] | 106 | return jtag_boot_device(); |
Simon Glass | b58bfe0 | 2021-08-08 12:20:09 -0600 | [diff] [blame] | 107 | #ifdef CONFIG_SPL_MMC |
Jean-Francois Dagenais | 865778a | 2017-04-02 21:44:34 -0400 | [diff] [blame] | 108 | case SD_MODE1: |
Michal Simek | a889620 | 2017-03-02 11:02:55 +0100 | [diff] [blame] | 109 | case SD1_LSHFT_MODE: /* not working on silicon v1 */ |
Jean-Francois Dagenais | 865778a | 2017-04-02 21:44:34 -0400 | [diff] [blame] | 110 | return BOOT_DEVICE_MMC2; |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 111 | case SD_MODE: |
Jean-Francois Dagenais | 865778a | 2017-04-02 21:44:34 -0400 | [diff] [blame] | 112 | case EMMC_MODE: |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 113 | return BOOT_DEVICE_MMC1; |
| 114 | #endif |
Andrew F. Davis | 6d932e6 | 2019-01-17 13:43:02 -0600 | [diff] [blame] | 115 | #ifdef CONFIG_SPL_DFU |
Michal Simek | 12398ea | 2016-08-19 14:14:52 +0200 | [diff] [blame] | 116 | case USB_MODE: |
| 117 | return BOOT_DEVICE_DFU; |
| 118 | #endif |
Simon Glass | 081a45a | 2021-08-08 12:20:17 -0600 | [diff] [blame] | 119 | #ifdef CONFIG_SPL_SATA |
Michal Simek | 2740d37 | 2016-10-26 09:24:32 +0200 | [diff] [blame] | 120 | case SW_SATA_MODE: |
| 121 | return BOOT_DEVICE_SATA; |
| 122 | #endif |
Simon Glass | a582047 | 2021-08-08 12:20:14 -0600 | [diff] [blame] | 123 | #ifdef CONFIG_SPL_SPI |
Michal Simek | 1b19a6f | 2017-11-02 09:15:05 +0100 | [diff] [blame] | 124 | case QSPI_MODE_24BIT: |
| 125 | case QSPI_MODE_32BIT: |
| 126 | return BOOT_DEVICE_SPI; |
| 127 | #endif |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 128 | default: |
| 129 | printf("Invalid Boot Mode:0x%x\n", bootmode); |
| 130 | break; |
| 131 | } |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_SPL_OS_BOOT |
| 137 | int spl_start_uboot(void) |
| 138 | { |
Michal Simek | 72536fd | 2015-11-20 13:17:22 +0100 | [diff] [blame] | 139 | return 0; |
| 140 | } |
| 141 | #endif |