Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Altera Corporation <www.altera.com> |
| 3 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
Dinh Nguyen | 0ef44d1 | 2015-04-15 16:44:32 -0500 | [diff] [blame] | 9 | #include <asm/pl310.h> |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 10 | #include <asm/u-boot.h> |
| 11 | #include <asm/utils.h> |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 12 | #include <image.h> |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 13 | #include <asm/arch/reset_manager.h> |
| 14 | #include <spl.h> |
Chin Liang See | 5d649d2 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 15 | #include <asm/arch/system_manager.h> |
Chin Liang See | 4c54419 | 2013-12-02 12:01:39 -0600 | [diff] [blame] | 16 | #include <asm/arch/freeze_controller.h> |
Chin Liang See | 3ab019e | 2014-07-22 04:28:35 -0500 | [diff] [blame] | 17 | #include <asm/arch/clock_manager.h> |
| 18 | #include <asm/arch/scan_manager.h> |
Dinh Nguyen | 37ef0c7 | 2015-03-30 17:01:08 -0500 | [diff] [blame] | 19 | #include <asm/arch/sdram.h> |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Dinh Nguyen | 0ef44d1 | 2015-04-15 16:44:32 -0500 | [diff] [blame] | 23 | static struct pl310_regs *const pl310 = |
| 24 | (struct pl310_regs *)CONFIG_SYS_PL310_BASE; |
| 25 | |
Dinh Nguyen | 0ef44d1 | 2015-04-15 16:44:32 -0500 | [diff] [blame] | 26 | void 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 Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 51 | u32 spl_boot_device(void) |
| 52 | { |
| 53 | return BOOT_DEVICE_RAM; |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Board initialization after bss clearance |
| 58 | */ |
| 59 | void spl_board_init(void) |
| 60 | { |
Dinh Nguyen | 89ba824 | 2015-03-30 17:01:09 -0500 | [diff] [blame] | 61 | unsigned long sdram_size; |
Chin Liang See | 5d649d2 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 62 | #ifndef CONFIG_SOCFPGA_VIRTUAL_TARGET |
Marek Vasut | 93b4abd | 2015-07-25 08:44:27 +0200 | [diff] [blame] | 63 | const struct cm_config *cm_default_cfg = cm_get_default_config(); |
| 64 | #endif |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 65 | |
Chin Liang See | 4c54419 | 2013-12-02 12:01:39 -0600 | [diff] [blame] | 66 | debug("Freezing all I/O banks\n"); |
| 67 | /* freeze all IO banks */ |
| 68 | sys_mgr_frzctrl_freeze_req(); |
| 69 | |
Marek Vasut | a71df7a | 2015-07-09 02:51:56 +0200 | [diff] [blame] | 70 | socfpga_per_reset(SOCFPGA_RESET(SDR), 0); |
| 71 | socfpga_per_reset(SOCFPGA_RESET(UART0), 0); |
| 72 | socfpga_per_reset(SOCFPGA_RESET(OSC1TIMER0), 0); |
Dinh Nguyen | 0812a1d | 2015-03-30 17:01:05 -0500 | [diff] [blame] | 73 | |
Dinh Nguyen | 9fd565d | 2015-03-30 17:01:06 -0500 | [diff] [blame] | 74 | timer_init(); |
| 75 | |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 76 | debug("Reconfigure Clock Manager\n"); |
| 77 | /* reconfigure the PLLs */ |
Marek Vasut | 93b4abd | 2015-07-25 08:44:27 +0200 | [diff] [blame] | 78 | cm_basic_init(cm_default_cfg); |
Chin Liang See | ddfeb0a | 2014-03-04 22:13:53 -0600 | [diff] [blame] | 79 | |
Dinh Nguyen | 08e463e | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 80 | /* Enable bootrom to configure IOs. */ |
Marek Vasut | 40687b4 | 2015-07-09 04:40:11 +0200 | [diff] [blame^] | 81 | sysmgr_config_warmrstcfgio(1); |
Dinh Nguyen | 08e463e | 2015-03-30 17:01:07 -0500 | [diff] [blame] | 82 | |
Chin Liang See | dc4d4aa | 2014-06-10 01:17:42 -0500 | [diff] [blame] | 83 | /* configure the IOCSR / IO buffer settings */ |
| 84 | if (scan_mgr_configure_iocsr()) |
| 85 | hang(); |
| 86 | |
Chin Liang See | 5d649d2 | 2013-09-11 11:24:48 -0500 | [diff] [blame] | 87 | /* configure the pin muxing through system manager */ |
| 88 | sysmgr_pinmux_init(); |
| 89 | #endif /* CONFIG_SOCFPGA_VIRTUAL_TARGET */ |
| 90 | |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 91 | /* de-assert reset for peripherals and bridges based on handoff */ |
| 92 | reset_deassert_peripherals_handoff(); |
| 93 | |
Chin Liang See | 4c54419 | 2013-12-02 12:01:39 -0600 | [diff] [blame] | 94 | debug("Unfreezing/Thaw all I/O banks\n"); |
| 95 | /* unfreeze / thaw all IO banks */ |
| 96 | sys_mgr_frzctrl_thaw_req(); |
| 97 | |
Dinh Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 98 | /* enable console uart printing */ |
| 99 | preloader_console_init(); |
Dinh Nguyen | 37ef0c7 | 2015-03-30 17:01:08 -0500 | [diff] [blame] | 100 | |
| 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 Nguyen | 89ba824 | 2015-03-30 17:01:09 -0500 | [diff] [blame] | 112 | |
| 113 | sdram_size = sdram_calculate_size(); |
| 114 | debug("SDRAM: %ld MiB\n", sdram_size >> 20); |
Dinh Nguyen | 9ad3a4a | 2015-03-30 17:01:15 -0500 | [diff] [blame] | 115 | |
| 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 Nguyen | 7775440 | 2012-10-04 06:46:02 +0000 | [diff] [blame] | 121 | } |