arm64: zynqmp: Do not call bss init and board_init_r from board_init_f
[oweals/u-boot.git] / arch / arm / mach-zynqmp / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2015 - 2016 Xilinx, Inc.
4  *
5  * Michal Simek <michal.simek@xilinx.com>
6  */
7
8 #include <common.h>
9 #include <debug_uart.h>
10 #include <init.h>
11 #include <spl.h>
12
13 #include <asm/io.h>
14 #include <asm/spl.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/sys_proto.h>
17
18 void board_init_f(ulong dummy)
19 {
20         board_early_init_f();
21         board_early_init_r();
22
23 #ifdef CONFIG_DEBUG_UART
24         /* Uart debug for sure */
25         debug_uart_init();
26         puts("Debug uart enabled\n"); /* or printch() */
27 #endif
28         /* Delay is required for clocks to be propagated */
29         udelay(1000000);
30 }
31
32 static void ps_mode_reset(ulong mode)
33 {
34         writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
35                &crlapb_base->boot_pin_ctrl);
36         udelay(5);
37         writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_VAL_SHIFT |
38                mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
39                &crlapb_base->boot_pin_ctrl);
40 }
41
42 /*
43  * Set default PS_MODE1 which is used for USB ULPI phy reset
44  * Also other resets can be connected to this certain pin
45  */
46 #ifndef MODE_RESET
47 # define MODE_RESET     PS_MODE1
48 #endif
49
50 #ifdef CONFIG_SPL_BOARD_INIT
51 void spl_board_init(void)
52 {
53         preloader_console_init();
54         ps_mode_reset(MODE_RESET);
55         board_init();
56 }
57 #endif
58
59 u32 spl_boot_device(void)
60 {
61         u32 reg = 0;
62         u8 bootmode;
63
64 #if defined(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE_ENABLED)
65         /* Change default boot mode at run-time */
66         writel(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE << BOOT_MODE_ALT_SHIFT,
67                &crlapb_base->boot_mode);
68 #endif
69
70         reg = readl(&crlapb_base->boot_mode);
71         if (reg >> BOOT_MODE_ALT_SHIFT)
72                 reg >>= BOOT_MODE_ALT_SHIFT;
73
74         bootmode = reg & BOOT_MODES_MASK;
75
76         switch (bootmode) {
77         case JTAG_MODE:
78                 return BOOT_DEVICE_RAM;
79 #ifdef CONFIG_SPL_MMC_SUPPORT
80         case SD_MODE1:
81         case SD1_LSHFT_MODE: /* not working on silicon v1 */
82 /* if both controllers enabled, then these two are the second controller */
83 #ifdef CONFIG_SPL_ZYNQMP_TWO_SDHCI
84                 return BOOT_DEVICE_MMC2;
85 /* else, fall through, the one SDHCI controller that is enabled is number 1 */
86 #endif
87         case SD_MODE:
88         case EMMC_MODE:
89                 return BOOT_DEVICE_MMC1;
90 #endif
91 #ifdef CONFIG_SPL_DFU
92         case USB_MODE:
93                 return BOOT_DEVICE_DFU;
94 #endif
95 #ifdef CONFIG_SPL_SATA_SUPPORT
96         case SW_SATA_MODE:
97                 return BOOT_DEVICE_SATA;
98 #endif
99 #ifdef CONFIG_SPL_SPI_SUPPORT
100         case QSPI_MODE_24BIT:
101         case QSPI_MODE_32BIT:
102                 return BOOT_DEVICE_SPI;
103 #endif
104         default:
105                 printf("Invalid Boot Mode:0x%x\n", bootmode);
106                 break;
107         }
108
109         return 0;
110 }
111
112 #ifdef CONFIG_SPL_OS_BOOT
113 int spl_start_uboot(void)
114 {
115         handoff_setup();
116
117         return 0;
118 }
119 #endif
120
121 #ifdef CONFIG_SPL_LOAD_FIT
122 int board_fit_config_name_match(const char *name)
123 {
124         /* Just empty function now - can't decide what to choose */
125         debug("%s: %s\n", __func__, name);
126
127         return 0;
128 }
129 #endif