Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[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 <image.h>
10 #include <init.h>
11 #include <log.h>
12 #include <spl.h>
13 #include <linux/delay.h>
14
15 #include <asm/io.h>
16 #include <asm/spl.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/psu_init_gpl.h>
19 #include <asm/arch/sys_proto.h>
20
21 void board_init_f(ulong dummy)
22 {
23         board_early_init_f();
24         board_early_init_r();
25 }
26
27 static void ps_mode_reset(ulong mode)
28 {
29         writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
30                &crlapb_base->boot_pin_ctrl);
31         udelay(5);
32         writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_VAL_SHIFT |
33                mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
34                &crlapb_base->boot_pin_ctrl);
35 }
36
37 /*
38  * Set default PS_MODE1 which is used for USB ULPI phy reset
39  * Also other resets can be connected to this certain pin
40  */
41 #ifndef MODE_RESET
42 # define MODE_RESET     PS_MODE1
43 #endif
44
45 #ifdef CONFIG_SPL_BOARD_INIT
46 void spl_board_init(void)
47 {
48         preloader_console_init();
49         ps_mode_reset(MODE_RESET);
50         board_init();
51         psu_post_config_data();
52 }
53 #endif
54
55 void board_boot_order(u32 *spl_boot_list)
56 {
57         spl_boot_list[0] = spl_boot_device();
58
59         if (spl_boot_list[0] == BOOT_DEVICE_MMC1)
60                 spl_boot_list[1] = BOOT_DEVICE_MMC2;
61         if (spl_boot_list[0] == BOOT_DEVICE_MMC2)
62                 spl_boot_list[1] = BOOT_DEVICE_MMC1;
63
64         spl_boot_list[2] = BOOT_DEVICE_RAM;
65 }
66
67 u32 spl_boot_device(void)
68 {
69         u32 reg = 0;
70         u8 bootmode;
71
72 #if defined(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE_ENABLED)
73         /* Change default boot mode at run-time */
74         writel(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE << BOOT_MODE_ALT_SHIFT,
75                &crlapb_base->boot_mode);
76 #endif
77
78         reg = readl(&crlapb_base->boot_mode);
79         if (reg >> BOOT_MODE_ALT_SHIFT)
80                 reg >>= BOOT_MODE_ALT_SHIFT;
81
82         bootmode = reg & BOOT_MODES_MASK;
83
84         switch (bootmode) {
85         case JTAG_MODE:
86                 return BOOT_DEVICE_RAM;
87 #ifdef CONFIG_SPL_MMC_SUPPORT
88         case SD_MODE1:
89         case SD1_LSHFT_MODE: /* not working on silicon v1 */
90                 return BOOT_DEVICE_MMC2;
91         case SD_MODE:
92         case EMMC_MODE:
93                 return BOOT_DEVICE_MMC1;
94 #endif
95 #ifdef CONFIG_SPL_DFU
96         case USB_MODE:
97                 return BOOT_DEVICE_DFU;
98 #endif
99 #ifdef CONFIG_SPL_SATA_SUPPORT
100         case SW_SATA_MODE:
101                 return BOOT_DEVICE_SATA;
102 #endif
103 #ifdef CONFIG_SPL_SPI_SUPPORT
104         case QSPI_MODE_24BIT:
105         case QSPI_MODE_32BIT:
106                 return BOOT_DEVICE_SPI;
107 #endif
108         default:
109                 printf("Invalid Boot Mode:0x%x\n", bootmode);
110                 break;
111         }
112
113         return 0;
114 }
115
116 #ifdef CONFIG_SPL_OS_BOOT
117 int spl_start_uboot(void)
118 {
119         return 0;
120 }
121 #endif
122
123 #ifdef CONFIG_SPL_LOAD_FIT
124 int board_fit_config_name_match(const char *name)
125 {
126         /* Just empty function now - can't decide what to choose */
127         debug("%s: %s\n", __func__, name);
128
129         return -1;
130 }
131 #endif