blob: 1fecfdc4f776518371ef8cd5ca50d8d6b51eda62 [file] [log] [blame]
Dinh Nguyen77754402012-10-04 06:46:02 +00001/*
2 * Copyright (C) 2012 Altera Corporation <www.altera.com>
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Dinh Nguyen77754402012-10-04 06:46:02 +00005 */
6
7#include <common.h>
8#include <asm/io.h>
Dinh Nguyen0ef44d12015-04-15 16:44:32 -05009#include <asm/pl310.h>
Dinh Nguyen77754402012-10-04 06:46:02 +000010#include <asm/u-boot.h>
11#include <asm/utils.h>
Dinh Nguyen77754402012-10-04 06:46:02 +000012#include <image.h>
Dinh Nguyen77754402012-10-04 06:46:02 +000013#include <asm/arch/reset_manager.h>
14#include <spl.h>
Chin Liang See5d649d22013-09-11 11:24:48 -050015#include <asm/arch/system_manager.h>
Chin Liang See4c544192013-12-02 12:01:39 -060016#include <asm/arch/freeze_controller.h>
Chin Liang See3ab019e2014-07-22 04:28:35 -050017#include <asm/arch/clock_manager.h>
18#include <asm/arch/scan_manager.h>
Dinh Nguyen37ef0c72015-03-30 17:01:08 -050019#include <asm/arch/sdram.h>
Dinh Nguyen77754402012-10-04 06:46:02 +000020
21DECLARE_GLOBAL_DATA_PTR;
22
Dinh Nguyen0ef44d12015-04-15 16:44:32 -050023static struct pl310_regs *const pl310 =
24 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
25
Dinh Nguyen0ef44d12015-04-15 16:44:32 -050026void board_init_f(ulong dummy)
27{
28 struct socfpga_system_manager *sysmgr_regs =
29 (struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
30 unsigned long reg;
31 /*
32 * First C code to run. Clear fake OCRAM ECC first as SBE
33 * and DBE might triggered during power on
34 */
35 reg = readl(&sysmgr_regs->eccgrp_ocram);
36 if (reg & SYSMGR_ECC_OCRAM_SERR)
37 writel(SYSMGR_ECC_OCRAM_SERR | SYSMGR_ECC_OCRAM_EN,
38 &sysmgr_regs->eccgrp_ocram);
39 if (reg & SYSMGR_ECC_OCRAM_DERR)
40 writel(SYSMGR_ECC_OCRAM_DERR | SYSMGR_ECC_OCRAM_EN,
41 &sysmgr_regs->eccgrp_ocram);
42
43 memset(__bss_start, 0, __bss_end - __bss_start);
44
45 /* Remap SDRAM to 0x0 */
46 writel(0x1, &pl310->pl310_addr_filter_start);
47
48 board_init_r(NULL, 0);
49}
50
Dinh Nguyen77754402012-10-04 06:46:02 +000051u32 spl_boot_device(void)
52{
53 return BOOT_DEVICE_RAM;
54}
55
56/*
57 * Board initialization after bss clearance
58 */
59void spl_board_init(void)
60{
Dinh Nguyen89ba8242015-03-30 17:01:09 -050061 unsigned long sdram_size;
Chin Liang See5d649d22013-09-11 11:24:48 -050062#ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET
Marek Vasut93b4abd2015-07-25 08:44:27 +020063 const struct cm_config *cm_default_cfg = cm_get_default_config();
64#endif
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060065
Chin Liang See4c544192013-12-02 12:01:39 -060066 debug("Freezing all I/O banks\n");
67 /* freeze all IO banks */
68 sys_mgr_frzctrl_freeze_req();
69
Marek Vasuta71df7a2015-07-09 02:51:56 +020070 socfpga_per_reset(SOCFPGA_RESET(SDR), 0);
71 socfpga_per_reset(SOCFPGA_RESET(UART0), 0);
72 socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0);
Dinh Nguyen0812a1d2015-03-30 17:01:05 -050073
Dinh Nguyen9fd565d2015-03-30 17:01:06 -050074 timer_init();
75
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060076 debug("Reconfigure Clock Manager\n");
77 /* reconfigure the PLLs */
Marek Vasut93b4abd2015-07-25 08:44:27 +020078 cm_basic_init(cm_default_cfg);
Chin Liang Seeddfeb0a2014-03-04 22:13:53 -060079
Dinh Nguyen08e463e2015-03-30 17:01:07 -050080 /* Enable bootrom to configure IOs. */
81 sysmgr_enable_warmrstcfgio();
82
Chin Liang Seedc4d4aa2014-06-10 01:17:42 -050083 /* configure the IOCSR / IO buffer settings */
84 if (scan_mgr_configure_iocsr())
85 hang();
86
Chin Liang See5d649d22013-09-11 11:24:48 -050087 /* configure the pin muxing through system manager */
88 sysmgr_pinmux_init();
89#endif /* CONFIG_SOCFPGA_VIRTUAL_TARGET */
90
Dinh Nguyen77754402012-10-04 06:46:02 +000091 /* de-assert reset for peripherals and bridges based on handoff */
92 reset_deassert_peripherals_handoff();
93
Chin Liang See4c544192013-12-02 12:01:39 -060094 debug("Unfreezing/Thaw all I/O banks\n");
95 /* unfreeze / thaw all IO banks */
96 sys_mgr_frzctrl_thaw_req();
97
Dinh Nguyen77754402012-10-04 06:46:02 +000098 /* enable console uart printing */
99 preloader_console_init();
Dinh Nguyen37ef0c72015-03-30 17:01:08 -0500100
101 if (sdram_mmr_init_full(0xffffffff) != 0) {
102 puts("SDRAM init failed.\n");
103 hang();
104 }
105
106 debug("SDRAM: Calibrating PHY\n");
107 /* SDRAM calibration */
108 if (sdram_calibration_full() == 0) {
109 puts("SDRAM calibration failed.\n");
110 hang();
111 }
Dinh Nguyen89ba8242015-03-30 17:01:09 -0500112
113 sdram_size = sdram_calculate_size();
114 debug("SDRAM: %ld MiB\n", sdram_size >> 20);
Dinh Nguyen9ad3a4a2015-03-30 17:01:15 -0500115
116 /* Sanity check ensure correct SDRAM size specified */
117 if (get_ram_size(0, sdram_size) != sdram_size) {
118 puts("SDRAM size check failed!\n");
119 hang();
120 }
Dinh Nguyen77754402012-10-04 06:46:02 +0000121}