1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2016-2018 Intel Corporation <www.intel.com>
8 #include <asm/u-boot.h>
11 #include <debug_uart.h>
14 #include <asm/arch/clock_manager.h>
15 #include <asm/arch/firewall_s10.h>
16 #include <asm/arch/mailbox_s10.h>
17 #include <asm/arch/misc.h>
18 #include <asm/arch/reset_manager.h>
19 #include <asm/arch/system_manager.h>
21 #include <dm/uclass.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 u32 spl_boot_device(void)
27 /* TODO: Get from SDM or handoff */
28 return BOOT_DEVICE_MMC1;
31 #ifdef CONFIG_SPL_MMC_SUPPORT
32 u32 spl_boot_mode(const u32 boot_device)
34 #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
37 return MMCSD_MODE_RAW;
42 void spl_disable_firewall_l4_per(void)
44 const struct socfpga_firwall_l4_per *firwall_l4_per_base =
45 (struct socfpga_firwall_l4_per *)SOCFPGA_FIREWALL_L4_PER;
48 &firwall_l4_per_base->nand,
49 &firwall_l4_per_base->nand_data,
50 &firwall_l4_per_base->usb0,
51 &firwall_l4_per_base->usb1,
52 &firwall_l4_per_base->spim0,
53 &firwall_l4_per_base->spim1,
54 &firwall_l4_per_base->emac0,
55 &firwall_l4_per_base->emac1,
56 &firwall_l4_per_base->emac2,
57 &firwall_l4_per_base->sdmmc,
58 &firwall_l4_per_base->gpio0,
59 &firwall_l4_per_base->gpio1,
60 &firwall_l4_per_base->i2c0,
61 &firwall_l4_per_base->i2c1,
62 &firwall_l4_per_base->i2c2,
63 &firwall_l4_per_base->i2c3,
64 &firwall_l4_per_base->i2c4,
65 &firwall_l4_per_base->timer0,
66 &firwall_l4_per_base->timer1,
67 &firwall_l4_per_base->uart0,
68 &firwall_l4_per_base->uart1
72 * The following lines of code will enable non-secure access
73 * to nand, usb, spi, emac, sdmmc, gpio, i2c, timers and uart. This
74 * is needed as most OS run in non-secure mode. Thus we need to
75 * enable non-secure access to these peripherals in order for the
76 * OS to use these peripherals.
78 for (i = 0; i < ARRAY_SIZE(addr); i++)
79 writel(FIREWALL_L4_DISABLE_ALL, addr[i]);
82 void spl_disable_firewall_l4_sys(void)
84 const struct socfpga_firwall_l4_sys *firwall_l4_sys_base =
85 (struct socfpga_firwall_l4_sys *)SOCFPGA_FIREWALL_L4_SYS;
88 &firwall_l4_sys_base->dma_ecc,
89 &firwall_l4_sys_base->emac0rx_ecc,
90 &firwall_l4_sys_base->emac0tx_ecc,
91 &firwall_l4_sys_base->emac1rx_ecc,
92 &firwall_l4_sys_base->emac1tx_ecc,
93 &firwall_l4_sys_base->emac2rx_ecc,
94 &firwall_l4_sys_base->emac2tx_ecc,
95 &firwall_l4_sys_base->nand_ecc,
96 &firwall_l4_sys_base->nand_read_ecc,
97 &firwall_l4_sys_base->nand_write_ecc,
98 &firwall_l4_sys_base->ocram_ecc,
99 &firwall_l4_sys_base->sdmmc_ecc,
100 &firwall_l4_sys_base->usb0_ecc,
101 &firwall_l4_sys_base->usb1_ecc,
102 &firwall_l4_sys_base->clock_manager,
103 &firwall_l4_sys_base->io_manager,
104 &firwall_l4_sys_base->reset_manager,
105 &firwall_l4_sys_base->system_manager,
106 &firwall_l4_sys_base->watchdog0,
107 &firwall_l4_sys_base->watchdog1,
108 &firwall_l4_sys_base->watchdog2,
109 &firwall_l4_sys_base->watchdog3
112 for (i = 0; i < ARRAY_SIZE(addr); i++)
113 writel(FIREWALL_L4_DISABLE_ALL, addr[i]);
116 void board_init_f(ulong dummy)
118 const struct cm_config *cm_default_cfg = cm_get_default_config();
121 ret = spl_early_init();
125 socfpga_get_managers_addr();
127 #ifdef CONFIG_HW_WATCHDOG
128 /* Ensure watchdog is paused when debugging is happening */
129 writel(SYSMGR_WDDBG_PAUSE_ALL_CPU,
130 socfpga_get_sysmgr_addr() + SYSMGR_S10_WDDBG);
132 /* Enable watchdog before initializing the HW */
133 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
134 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
138 /* ensure all processors are not released prior Linux boot */
139 writeq(0, CPU_RELEASE_ADDR);
141 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
144 sysmgr_pinmux_init();
146 /* configuring the HPS clocks */
147 cm_basic_init(cm_default_cfg);
149 #ifdef CONFIG_DEBUG_UART
150 socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
154 preloader_console_init();
155 cm_print_clock_quick_summary();
157 /* enable non-secure interface to DMA330 DMA and peripherals */
158 writel(SYSMGR_DMA_IRQ_NS | SYSMGR_DMA_MGR_NS,
159 socfpga_get_sysmgr_addr() + SYSMGR_S10_DMA);
160 writel(SYSMGR_DMAPERIPH_ALL_NS,
161 socfpga_get_sysmgr_addr() + SYSMGR_S10_DMA_PERIPH);
163 spl_disable_firewall_l4_per();
165 spl_disable_firewall_l4_sys();
167 /* disable lwsocf2fpga and soc2fpga bridge security */
168 writel(FIREWALL_BRIDGE_DISABLE_ALL, SOCFPGA_FIREWALL_SOC2FPGA);
169 writel(FIREWALL_BRIDGE_DISABLE_ALL, SOCFPGA_FIREWALL_LWSOC2FPGA);
171 /* disable SMMU security */
172 writel(FIREWALL_L4_DISABLE_ALL, SOCFPGA_FIREWALL_TCU);
174 /* disable ocram security at CCU for non secure access */
175 clrbits_le32(CCU_REG_ADDR(CCU_CPU0_MPRT_ADMASK_MEM_RAM0),
176 CCU_ADMASK_P_MASK | CCU_ADMASK_NS_MASK);
177 clrbits_le32(CCU_REG_ADDR(CCU_IOM_MPRT_ADMASK_MEM_RAM0),
178 CCU_ADMASK_P_MASK | CCU_ADMASK_NS_MASK);
180 #if CONFIG_IS_ENABLED(ALTERA_SDRAM)
183 ret = uclass_get_device(UCLASS_RAM, 0, &dev);
185 debug("DRAM init failed: %d\n", ret);
192 #ifdef CONFIG_CADENCE_QSPI