blob: 515832031ac3b8be692fb48f2c3376626b259284 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Dinh Nguyenad51f7c2012-10-04 06:46:02 +00002/*
3 * Copyright (C) 2012 Altera Corporation <www.altera.com>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +00004 */
5
6#include <common.h>
7#include <asm/io.h>
Dinh Nguyene6a52ca2015-04-15 16:44:32 -05008#include <asm/pl310.h>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +00009#include <asm/u-boot.h>
10#include <asm/utils.h>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +000011#include <image.h>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +000012#include <asm/arch/reset_manager.h>
13#include <spl.h>
Chin Liang See70fa4e72013-09-11 11:24:48 -050014#include <asm/arch/system_manager.h>
Chin Liang See6ae44732013-12-02 12:01:39 -060015#include <asm/arch/freeze_controller.h>
Chin Liang See112cb0d2014-07-22 04:28:35 -050016#include <asm/arch/clock_manager.h>
17#include <asm/arch/scan_manager.h>
Dinh Nguyenea344582015-03-30 17:01:08 -050018#include <asm/arch/sdram.h>
Marek Vasutaf657612015-07-09 05:15:40 +020019#include <asm/arch/scu.h>
20#include <asm/arch/nic301.h>
Ley Foon Tan9db517e2017-04-26 02:44:45 +080021#include <asm/sections.h>
22#include <fdtdec.h>
23#include <watchdog.h>
24#if defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
25#include <asm/arch/pinmux.h>
26#endif
Dinh Nguyenad51f7c2012-10-04 06:46:02 +000027
28DECLARE_GLOBAL_DATA_PTR;
29
Ley Foon Tan9db517e2017-04-26 02:44:45 +080030#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Dinh Nguyene6a52ca2015-04-15 16:44:32 -050031static struct pl310_regs *const pl310 =
32 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Marek Vasutaf657612015-07-09 05:15:40 +020033static struct scu_registers *scu_regs =
34 (struct scu_registers *)SOCFPGA_MPUSCU_ADDRESS;
35static struct nic301_registers *nic301_regs =
36 (struct nic301_registers *)SOCFPGA_L3REGS_ADDRESS;
Ley Foon Tan9db517e2017-04-26 02:44:45 +080037#endif
38
39static const struct socfpga_system_manager *sysmgr_regs =
Marek Vasut46193c32015-07-21 16:11:16 +020040 (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
Marek Vasutaf657612015-07-09 05:15:40 +020041
Marek Vasut1a7728f2015-07-09 05:36:23 +020042u32 spl_boot_device(void)
43{
Marek Vasut46193c32015-07-21 16:11:16 +020044 const u32 bsel = readl(&sysmgr_regs->bootinfo);
45
Ley Foon Tan9db517e2017-04-26 02:44:45 +080046 switch (SYSMGR_GET_BOOTINFO_BSEL(bsel)) {
Marek Vasut46193c32015-07-21 16:11:16 +020047 case 0x1: /* FPGA (HPS2FPGA Bridge) */
48 return BOOT_DEVICE_RAM;
49 case 0x2: /* NAND Flash (1.8V) */
50 case 0x3: /* NAND Flash (3.0V) */
Marek Vasut796c4c22015-12-20 04:00:42 +010051 socfpga_per_reset(SOCFPGA_RESET(NAND), 0);
Marek Vasut46193c32015-07-21 16:11:16 +020052 return BOOT_DEVICE_NAND;
53 case 0x4: /* SD/MMC External Transceiver (1.8V) */
54 case 0x5: /* SD/MMC Internal Transceiver (3.0V) */
55 socfpga_per_reset(SOCFPGA_RESET(SDMMC), 0);
56 socfpga_per_reset(SOCFPGA_RESET(DMA), 0);
57 return BOOT_DEVICE_MMC1;
58 case 0x6: /* QSPI Flash (1.8V) */
59 case 0x7: /* QSPI Flash (3.0V) */
60 socfpga_per_reset(SOCFPGA_RESET(QSPI), 0);
61 return BOOT_DEVICE_SPI;
62 default:
63 printf("Invalid boot device (bsel=%08x)!\n", bsel);
64 hang();
65 }
Marek Vasut1029caf2015-07-10 00:04:23 +020066}
67
Ley Foon Tan9db517e2017-04-26 02:44:45 +080068#if defined(CONFIG_TARGET_SOCFPGA_GEN5)
Marek Vasutaf657612015-07-09 05:15:40 +020069static void socfpga_nic301_slave_ns(void)
70{
71 writel(0x1, &nic301_regs->lwhps2fpgaregs);
72 writel(0x1, &nic301_regs->hps2fpgaregs);
73 writel(0x1, &nic301_regs->acp);
74 writel(0x1, &nic301_regs->rom);
75 writel(0x1, &nic301_regs->ocram);
76 writel(0x1, &nic301_regs->sdrdata);
77}
Dinh Nguyene6a52ca2015-04-15 16:44:32 -050078
Dinh Nguyene6a52ca2015-04-15 16:44:32 -050079void board_init_f(ulong dummy)
80{
Marek Vasut1a7728f2015-07-09 05:36:23 +020081 const struct cm_config *cm_default_cfg = cm_get_default_config();
Marek Vasut1a7728f2015-07-09 05:36:23 +020082 unsigned long sdram_size;
Dinh Nguyene6a52ca2015-04-15 16:44:32 -050083 unsigned long reg;
Marek Vasut1a7728f2015-07-09 05:36:23 +020084
Dinh Nguyene6a52ca2015-04-15 16:44:32 -050085 /*
86 * First C code to run. Clear fake OCRAM ECC first as SBE
87 * and DBE might triggered during power on
88 */
89 reg = readl(&sysmgr_regs->eccgrp_ocram);
90 if (reg & SYSMGR_ECC_OCRAM_SERR)
91 writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
92 &sysmgr_regs->eccgrp_ocram);
93 if (reg & SYSMGR_ECC_OCRAM_DERR)
94 writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
95 &sysmgr_regs->eccgrp_ocram);
96
97 memset(__bss_start, 0, __bss_end - __bss_start);
98
Marek Vasutaf657612015-07-09 05:15:40 +020099 socfpga_nic301_slave_ns();
100
101 /* Configure ARM MPU SNSAC register. */
102 setbits_le32(&scu_regs->sacr, 0xfff);
103
Dinh Nguyene6a52ca2015-04-15 16:44:32 -0500104 /* Remap SDRAM to 0x0 */
Marek Vasutaf657612015-07-09 05:15:40 +0200105 writel(0x1, &nic301_regs->remap); /* remap.mpuzero */
Dinh Nguyene6a52ca2015-04-15 16:44:32 -0500106 writel(0x1, &pl310->pl310_addr_filter_start);
107
Chin Liang See6ae44732013-12-02 12:01:39 -0600108 debug("Freezing all I/O banks\n");
109 /* freeze all IO banks */
110 sys_mgr_frzctrl_freeze_req();
111
Marek Vasut8784e7e2015-07-09 05:21:02 +0200112 /* Put everything into reset but L4WD0. */
113 socfpga_per_reset_all();
114 /* Put FPGA bridges into reset too. */
115 socfpga_bridges_reset(1);
116
Marek Vasut75f6b5c2015-07-09 02:51:56 +0200117 socfpga_per_reset(SOCFPGA_RESET(SDR), 0);
118 socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
119 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
Dinh Nguyen2c6fca32015-03-30 17:01:05 -0500120
Dinh Nguyenb47180b2015-03-30 17:01:06 -0500121 timer_init();
122
Chin Liang Seecb350602014-03-04 22:13:53 -0600123 debug("Reconfigure Clock Manager\n");
124 /* reconfigure the PLLs */
Ley Foon Tanec6f8822017-04-26 02:44:33 +0800125 if (cm_basic_init(cm_default_cfg))
126 hang();
Chin Liang Seecb350602014-03-04 22:13:53 -0600127
Dinh Nguyen95a2fd32015-03-30 17:01:07 -0500128 /* Enable bootrom to configure IOs. */
Marek Vasut8306b1e2015-07-09 04:40:11 +0200129 sysmgr_config_warmrstcfgio(1);
Dinh Nguyen95a2fd32015-03-30 17:01:07 -0500130
Chin Liang See63550242014-06-10 01:17:42 -0500131 /* configure the IOCSR / IO buffer settings */
132 if (scan_mgr_configure_iocsr())
133 hang();
134
Marek Vasut6d4a4b42015-07-09 04:48:56 +0200135 sysmgr_config_warmrstcfgio(0);
136
Chin Liang See70fa4e72013-09-11 11:24:48 -0500137 /* configure the pin muxing through system manager */
Marek Vasut6d4a4b42015-07-09 04:48:56 +0200138 sysmgr_config_warmrstcfgio(1);
Chin Liang See70fa4e72013-09-11 11:24:48 -0500139 sysmgr_pinmux_init();
Marek Vasut6d4a4b42015-07-09 04:48:56 +0200140 sysmgr_config_warmrstcfgio(0);
141
Marek Vasut8784e7e2015-07-09 05:21:02 +0200142 /* De-assert reset for peripherals and bridges based on handoff */
Dinh Nguyenad51f7c2012-10-04 06:46:02 +0000143 reset_deassert_peripherals_handoff();
Marek Vasut8784e7e2015-07-09 05:21:02 +0200144 socfpga_bridges_reset(0);
Dinh Nguyenad51f7c2012-10-04 06:46:02 +0000145
Chin Liang See6ae44732013-12-02 12:01:39 -0600146 debug("Unfreezing/Thaw all I/O banks\n");
147 /* unfreeze / thaw all IO banks */
148 sys_mgr_frzctrl_thaw_req();
149
Dinh Nguyenad51f7c2012-10-04 06:46:02 +0000150 /* enable console uart printing */
151 preloader_console_init();
Dinh Nguyenea344582015-03-30 17:01:08 -0500152
153 if (sdram_mmr_init_full(0xffffffff) != 0) {
154 puts("SDRAM init failed.\n");
155 hang();
156 }
157
158 debug("SDRAM: Calibrating PHY\n");
159 /* SDRAM calibration */
160 if (sdram_calibration_full() == 0) {
161 puts("SDRAM calibration failed.\n");
162 hang();
163 }
Dinh Nguyen4b86cbb2015-03-30 17:01:09 -0500164
165 sdram_size = sdram_calculate_size();
166 debug("SDRAM: %ld MiB\n", sdram_size >> 20);
Dinh Nguyen66ea63f2015-03-30 17:01:15 -0500167
168 /* Sanity check ensure correct SDRAM size specified */
169 if (get_ram_size(0, sdram_size) != sdram_size) {
170 puts("SDRAM size check failed!\n");
171 hang();
172 }
Marek Vasut8784e7e2015-07-09 05:21:02 +0200173
174 socfpga_bridges_reset(1);
Marek Vasut1a7728f2015-07-09 05:36:23 +0200175
Marek Vasutffb8e7f2015-07-12 15:23:28 +0200176 /* Configure simple malloc base pointer into RAM. */
177 gd->malloc_base = CONFIG_SYS_TEXT_BASE + (1024 * 1024);
Dinh Nguyenad51f7c2012-10-04 06:46:02 +0000178}
Ley Foon Tan9db517e2017-04-26 02:44:45 +0800179#elif defined(CONFIG_TARGET_SOCFPGA_ARRIA10)
180void spl_board_init(void)
181{
182 /* configuring the clock based on handoff */
183 cm_basic_init(gd->fdt_blob);
184 WATCHDOG_RESET();
185
186 config_dedicated_pins(gd->fdt_blob);
187 WATCHDOG_RESET();
188
189 /* Release UART from reset */
190 socfpga_reset_uart(0);
191
192 /* enable console uart printing */
193 preloader_console_init();
194}
195
196void board_init_f(ulong dummy)
197{
198 /*
199 * Configure Clock Manager to use intosc clock instead external osc to
200 * ensure success watchdog operation. We do it as early as possible.
201 */
202 cm_use_intosc();
203
204 socfpga_watchdog_disable();
205
206 arch_early_init_r();
207
208#ifdef CONFIG_HW_WATCHDOG
209 /* release osc1 watchdog timer 0 from reset */
210 socfpga_reset_deassert_osc1wd0();
211
212 /* reconfigure and enable the watchdog */
213 hw_watchdog_init();
214 WATCHDOG_RESET();
215#endif /* CONFIG_HW_WATCHDOG */
216}
217#endif