blob: 35dbff01bdb82d0677a24f8514b0b798c8e55bdc [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>
Simon Glass4d72caa2020-05-10 11:40:01 -06009#include <image.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();
Michal Simeke6a9ed02015-11-20 13:17:22 +010023}
24
Michal Simek48255f52016-08-15 09:41:36 +020025static void ps_mode_reset(ulong mode)
26{
Michal Simek48255f52016-08-15 09:41:36 +020027 writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
28 &crlapb_base->boot_pin_ctrl);
29 udelay(5);
30 writel(mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_VAL_SHIFT |
31 mode << ZYNQMP_CRL_APB_BOOT_PIN_CTRL_OUT_EN_SHIFT,
32 &crlapb_base->boot_pin_ctrl);
33}
34
35/*
36 * Set default PS_MODE1 which is used for USB ULPI phy reset
37 * Also other resets can be connected to this certain pin
38 */
39#ifndef MODE_RESET
40# define MODE_RESET PS_MODE1
41#endif
42
Michal Simeke6a9ed02015-11-20 13:17:22 +010043#ifdef CONFIG_SPL_BOARD_INIT
44void spl_board_init(void)
45{
46 preloader_console_init();
Michal Simek48255f52016-08-15 09:41:36 +020047 ps_mode_reset(MODE_RESET);
Michal Simeke6a9ed02015-11-20 13:17:22 +010048 board_init();
Michal Simeke82024d2019-12-03 15:02:50 +010049 psu_post_config_data();
Michal Simeke6a9ed02015-11-20 13:17:22 +010050}
51#endif
52
Michal Simekde79ca952019-12-09 13:00:57 +010053void board_boot_order(u32 *spl_boot_list)
54{
55 spl_boot_list[0] = spl_boot_device();
56
57 if (spl_boot_list[0] == BOOT_DEVICE_MMC1)
58 spl_boot_list[1] = BOOT_DEVICE_MMC2;
59 if (spl_boot_list[0] == BOOT_DEVICE_MMC2)
60 spl_boot_list[1] = BOOT_DEVICE_MMC1;
Michal Simekf1433d02020-03-11 15:00:51 +010061
62 spl_boot_list[2] = BOOT_DEVICE_RAM;
Michal Simekde79ca952019-12-09 13:00:57 +010063}
64
Michal Simeke6a9ed02015-11-20 13:17:22 +010065u32 spl_boot_device(void)
66{
67 u32 reg = 0;
68 u8 bootmode;
69
Michal Simek7f491d72016-08-30 16:17:27 +020070#if defined(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE_ENABLED)
71 /* Change default boot mode at run-time */
Michal Simek47359a02016-10-25 11:43:02 +020072 writel(CONFIG_SPL_ZYNQMP_ALT_BOOTMODE << BOOT_MODE_ALT_SHIFT,
Michal Simek7f491d72016-08-30 16:17:27 +020073 &crlapb_base->boot_mode);
74#endif
75
Michal Simeke6a9ed02015-11-20 13:17:22 +010076 reg = readl(&crlapb_base->boot_mode);
Michal Simek47359a02016-10-25 11:43:02 +020077 if (reg >> BOOT_MODE_ALT_SHIFT)
78 reg >>= BOOT_MODE_ALT_SHIFT;
79
Michal Simeke6a9ed02015-11-20 13:17:22 +010080 bootmode = reg & BOOT_MODES_MASK;
81
82 switch (bootmode) {
83 case JTAG_MODE:
84 return BOOT_DEVICE_RAM;
85#ifdef CONFIG_SPL_MMC_SUPPORT
Michal Simeke6a9ed02015-11-20 13:17:22 +010086 case SD_MODE1:
Michal Simekb0259c82017-03-02 11:02:55 +010087 case SD1_LSHFT_MODE: /* not working on silicon v1 */
Jean-Francois Dagenaise3fdf5d2017-04-02 21:44:34 -040088 return BOOT_DEVICE_MMC2;
Jean-Francois Dagenaise3fdf5d2017-04-02 21:44:34 -040089 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 Simeke6a9ed02015-11-20 13:17:22 +0100117 return 0;
118}
119#endif
120
121#ifdef CONFIG_SPL_LOAD_FIT
122int 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
Michal Simekb4f84682019-12-09 08:39:19 +0100127 return -1;
Michal Simeke6a9ed02015-11-20 13:17:22 +0100128}
129#endif