blob: 00eff9027505c3dbfa65df9e7b7ce8996cd9b78c [file] [log] [blame]
Dinh Nguyen77754402012-10-04 06:46:02 +00001/*
Ley Foon Tand1c559a2017-04-26 02:44:36 +08002 * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
Dinh Nguyen77754402012-10-04 06:46:02 +00003 *
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 Nguyenbd48c062015-08-01 03:42:10 +02009#include <errno.h>
Marek Vasut6ab00db2015-07-25 19:33:56 +020010#include <fdtdec.h>
11#include <libfdt.h>
Pavel Machek230fe9b2014-09-08 14:08:45 +020012#include <altera.h>
Pavel Machek99b97102014-07-14 14:14:17 +020013#include <miiphy.h>
14#include <netdev.h>
Stefan Roesed0e932d2014-12-19 13:49:10 +010015#include <watchdog.h>
Ley Foon Tand1c559a2017-04-26 02:44:36 +080016#include <asm/arch/misc.h>
Pavel Machekde6da922014-09-09 14:03:28 +020017#include <asm/arch/reset_manager.h>
Dinh Nguyenbd48c062015-08-01 03:42:10 +020018#include <asm/arch/scan_manager.h>
Pavel Machek45d6e672014-09-08 14:08:45 +020019#include <asm/arch/system_manager.h>
Marek Vasut60d804c2014-09-15 03:58:22 +020020#include <asm/arch/nic301.h>
Pavel Machek13e81d42014-09-08 14:08:45 +020021#include <asm/arch/scu.h>
Marek Vasut60d804c2014-09-15 03:58:22 +020022#include <asm/pl310.h>
Dinh Nguyen77754402012-10-04 06:46:02 +000023
24DECLARE_GLOBAL_DATA_PTR;
25
Ley Foon Tand1c559a2017-04-26 02:44:36 +080026static const struct pl310_regs *const pl310 =
Marek Vasut60d804c2014-09-15 03:58:22 +020027 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Ley Foon Tand1c559a2017-04-26 02:44:36 +080028
29struct bsel bsel_str[] = {
30 { "rsvd", "Reserved", },
31 { "fpga", "FPGA (HPS2FPGA Bridge)", },
32 { "nand", "NAND Flash (1.8V)", },
33 { "nand", "NAND Flash (3.0V)", },
34 { "sd", "SD/MMC External Transceiver (1.8V)", },
35 { "sd", "SD/MMC Internal Transceiver (3.0V)", },
36 { "qspi", "QSPI Flash (1.8V)", },
37 { "qspi", "QSPI Flash (3.0V)", },
38};
Pavel Machek45d6e672014-09-08 14:08:45 +020039
Dinh Nguyen77754402012-10-04 06:46:02 +000040int dram_init(void)
41{
42 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
43 return 0;
44}
Chin Liang See23f23f22014-06-10 02:23:45 -050045
Marek Vasut4ab333b2014-09-21 13:57:40 +020046void enable_caches(void)
47{
48#ifndef CONFIG_SYS_ICACHE_OFF
49 icache_enable();
50#endif
51#ifndef CONFIG_SYS_DCACHE_OFF
52 dcache_enable();
53#endif
54}
55
Dinh Nguyen8d8e13e2015-10-15 10:13:36 -050056void v7_outer_cache_enable(void)
57{
Marek Vasut07806972015-12-20 04:00:09 +010058 /* Disable the L2 cache */
59 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Dinh Nguyen8d8e13e2015-10-15 10:13:36 -050060
61 /* enable BRESP, instruction and data prefetch, full line of zeroes */
62 setbits_le32(&pl310->pl310_aux_ctrl,
63 L310_AUX_CTRL_DATA_PREFETCH_MASK |
64 L310_AUX_CTRL_INST_PREFETCH_MASK |
65 L310_SHARED_ATT_OVERRIDE_ENABLE);
Marek Vasut07806972015-12-20 04:00:09 +010066
67 /* Enable the L2 cache */
68 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
69}
70
71void v7_outer_cache_disable(void)
72{
73 /* Disable the L2 cache */
74 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Dinh Nguyen8d8e13e2015-10-15 10:13:36 -050075}
76
Chin Liang See23f23f22014-06-10 02:23:45 -050077#if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
78defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
79int overwrite_console(void)
80{
81 return 0;
82}
83#endif
84
Pavel Machek230fe9b2014-09-08 14:08:45 +020085#ifdef CONFIG_FPGA
86/*
87 * FPGA programming support for SoC FPGA Cyclone V
88 */
89static Altera_desc altera_fpga[] = {
90 {
91 /* Family */
92 Altera_SoCFPGA,
93 /* Interface type */
94 fast_passive_parallel,
95 /* No limitation as additional data will be ignored */
96 -1,
97 /* No device function table */
98 NULL,
99 /* Base interface address specified in driver */
100 NULL,
101 /* No cookie implementation */
102 0
103 },
104};
105
106/* add device descriptor to FPGA device table */
Ley Foon Tand1c559a2017-04-26 02:44:36 +0800107void socfpga_fpga_add(void)
Pavel Machek230fe9b2014-09-08 14:08:45 +0200108{
109 int i;
110 fpga_init();
111 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
112 fpga_add(fpga_altera, &altera_fpga[i]);
113}
Pavel Machek230fe9b2014-09-08 14:08:45 +0200114#endif
115
Pavel Machekde6da922014-09-09 14:03:28 +0200116int arch_cpu_init(void)
117{
Stefan Roesed0e932d2014-12-19 13:49:10 +0100118#ifdef CONFIG_HW_WATCHDOG
119 /*
120 * In case the watchdog is enabled, make sure to (re-)configure it
121 * so that the defined timeout is valid. Otherwise the SPL (Perloader)
122 * timeout value is still active which might too short for Linux
123 * booting.
124 */
125 hw_watchdog_init();
126#else
Pavel Machekde6da922014-09-09 14:03:28 +0200127 /*
128 * If the HW watchdog is NOT enabled, make sure it is not running,
129 * for example because it was enabled in the preloader. This might
130 * trigger a watchdog-triggered reboot of Linux kernel later.
Marek Vasuta71df7a2015-07-09 02:51:56 +0200131 * Toggle watchdog reset, so watchdog in not running state.
Pavel Machekde6da922014-09-09 14:03:28 +0200132 */
Marek Vasuta71df7a2015-07-09 02:51:56 +0200133 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
134 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
Pavel Machekde6da922014-09-09 14:03:28 +0200135#endif
Stefan Roesed0e932d2014-12-19 13:49:10 +0100136
Pavel Machekde6da922014-09-09 14:03:28 +0200137 return 0;
138}