blob: 527646875a9d6378b9dac1eddddb320f6c2e6caf [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simeke6a9ed02015-11-20 13:17:22 +01002/*
3 * Copyright 2015 - 2016 Xilinx, Inc.
4 *
5 * Michal Simek <michal.simek@xilinx.com>
Michal Simeke6a9ed02015-11-20 13:17:22 +01006 */
7
8#include <common.h>
9#include <debug_uart.h>
Simon Glass52559322019-11-14 12:57:46 -070010#include <init.h>
Michal Simeke6a9ed02015-11-20 13:17:22 +010011#include <spl.h>
12
13#include <asm/io.h>
14#include <asm/spl.h>
15#include <asm/arch/hardware.h>
Michal Simeke82024d2019-12-03 15:02:50 +010016#include <asm/arch/psu_init_gpl.h>
Michal Simeke6a9ed02015-11-20 13:17:22 +010017#include <asm/arch/sys_proto.h>
18
19void board_init_f(ulong dummy)
20{
Michal Simek55de0922017-07-12 13:08:41 +020021 board_early_init_f();
Michal Simeke6a9ed02015-11-20 13:17:22 +010022 board_early_init_r();
23
24#ifdef CONFIG_DEBUG_UART
25 /* Uart debug for sure */
26 debug_uart_init();
27 puts("Debug uart enabled\n"); /* or printch() */
28#endif
29 /* Delay is required for clocks to be propagated */
30 udelay(1000000);
Michal Simeke6a9ed02015-11-20 13:17:22 +010031}
32
Michal Simek48255f52016-08-15 09:41:36 +020033static void ps_mode_reset(ulong mode)
34{
Michal Simek48255f52016-08-15 09:41:36 +020035 writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
36 &crlapb_base->boot_pin_ctrl);
37 udelay(5);
38 writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_VAL_SHIFT |
39 mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
40 &crlapb_base->boot_pin_ctrl);
41}
42
43/*
44 * Set default PS_MODE1 which is used for USB ULPI phy reset
45 * Also other resets can be connected to this certain pin
46 */
47#ifndef MODE_RESET
48# define MODE_RESET PS_MODE1
49#endif
50
Michal Simeke6a9ed02015-11-20 13:17:22 +010051#ifdef CONFIG_SPL_BOARD_INIT
52void spl_board_init(void)
53{
54 preloader_console_init();
Michal Simek48255f52016-08-15 09:41:36 +020055 ps_mode_reset(MODE_RESET);
Michal Simeke6a9ed02015-11-20 13:17:22 +010056 board_init();
Michal Simeke82024d2019-12-03 15:02:50 +010057 psu_post_config_data();
Michal Simeke6a9ed02015-11-20 13:17:22 +010058}
59#endif
60
61u32 spl_boot_device(void)
62{
63 u32 reg = 0;
64 u8 bootmode;
65
Michal Simek7f491d72016-08-30 16:17:27 +020066#if defined(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE_ENABLED)
67 /* Change default boot mode at run-time */
Michal Simek47359a02016-10-25 11:43:02 +020068 writel(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE << BOOT_MODE_ALT_SHIFT,
Michal Simek7f491d72016-08-30 16:17:27 +020069 &crlapb_base->boot_mode);
70#endif
71
Michal Simeke6a9ed02015-11-20 13:17:22 +010072 reg = readl(&crlapb_base->boot_mode);
Michal Simek47359a02016-10-25 11:43:02 +020073 if (reg >> BOOT_MODE_ALT_SHIFT)
74 reg >>= BOOT_MODE_ALT_SHIFT;
75
Michal Simeke6a9ed02015-11-20 13:17:22 +010076 bootmode = reg & BOOT_MODES_MASK;
77
78 switch (bootmode) {
79 case JTAG_MODE:
80 return BOOT_DEVICE_RAM;
81#ifdef CONFIG_SPL_MMC_SUPPORT
Michal Simeke6a9ed02015-11-20 13:17:22 +010082 case SD_MODE1:
Michal Simekb0259c82017-03-02 11:02:55 +010083 case SD1_LSHFT_MODE: /* not working on silicon v1 */
Jean-Francois Dagenaise3fdf5d2017-04-02 21:44:34 -040084/* if both controllers enabled, then these two are the second controller */
Luca Ceresoli350cfe72019-04-15 16:18:18 +020085#ifdef CONFIG_SPL_ZYNQMP_TWO_SDHCI
Jean-Francois Dagenaise3fdf5d2017-04-02 21:44:34 -040086 return BOOT_DEVICE_MMC2;
87/* else, fall through, the one SDHCI controller that is enabled is number 1 */
88#endif
89 case SD_MODE:
90 case EMMC_MODE:
Michal Simeke6a9ed02015-11-20 13:17:22 +010091 return BOOT_DEVICE_MMC1;
92#endif
Andrew F. Davis6536ca42019-01-17 13:43:02 -060093#ifdef CONFIG_SPL_DFU
Michal Simekd58fc122016-08-19 14:14:52 +020094 case USB_MODE:
95 return BOOT_DEVICE_DFU;
96#endif
Michal Simek26610812016-10-26 09:24:32 +020097#ifdef CONFIG_SPL_SATA_SUPPORT
98 case SW_SATA_MODE:
99 return BOOT_DEVICE_SATA;
100#endif
Michal Simek40d1f8a2017-11-02 09:15:05 +0100101#ifdef CONFIG_SPL_SPI_SUPPORT
102 case QSPI_MODE_24BIT:
103 case QSPI_MODE_32BIT:
104 return BOOT_DEVICE_SPI;
105#endif
Michal Simeke6a9ed02015-11-20 13:17:22 +0100106 default:
107 printf("Invalid Boot Mode:0x%x\n", bootmode);
108 break;
109 }
110
111 return 0;
112}
113
Michal Simeke6a9ed02015-11-20 13:17:22 +0100114#ifdef CONFIG_SPL_OS_BOOT
115int spl_start_uboot(void)
116{
Michal Simek509d4b92017-01-09 10:05:16 +0100117 handoff_setup();
118
Michal Simeke6a9ed02015-11-20 13:17:22 +0100119 return 0;
120}
121#endif
122
123#ifdef CONFIG_SPL_LOAD_FIT
124int 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 0;
130}
131#endif