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