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