blob: 5c27f1984eff6b1f0bbb77c4bf9a645a14b5d158 [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/*
Ley Foon Tanb149f2b2017-04-26 02:44:36 +08003 * Copyright (C) 2012-2017 Altera Corporation <www.altera.com>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +00004 */
5
6#include <common.h>
7#include <asm/io.h>
Dinh Nguyen8ed66612015-08-01 03:42:10 +02008#include <errno.h>
Marek Vasutf3f8fe22015-07-25 19:33:56 +02009#include <fdtdec.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Pavel Machekc7213802014-09-08 14:08:45 +020011#include <altera.h>
Pavel Machekce340e92014-07-14 14:14:17 +020012#include <miiphy.h>
13#include <netdev.h>
Stefan Roese3bfb5912014-12-19 13:49:10 +010014#include <watchdog.h>
Ley Foon Tanb149f2b2017-04-26 02:44:36 +080015#include <asm/arch/misc.h>
Pavel Machek56a00ab2014-09-09 14:03:28 +020016#include <asm/arch/reset_manager.h>
Dinh Nguyen8ed66612015-08-01 03:42:10 +020017#include <asm/arch/scan_manager.h>
Pavel Machek57d75eb2014-09-08 14:08:45 +020018#include <asm/arch/system_manager.h>
Marek Vasut56916e42014-09-15 03:58:22 +020019#include <asm/arch/nic301.h>
Pavel Macheke918e332014-09-08 14:08:45 +020020#include <asm/arch/scu.h>
Marek Vasut56916e42014-09-15 03:58:22 +020021#include <asm/pl310.h>
Dinh Nguyenad51f7c2012-10-04 06:46:02 +000022
23DECLARE_GLOBAL_DATA_PTR;
24
Ley Foon Tanb149f2b2017-04-26 02:44:36 +080025static const struct pl310_regs *const pl310 =
Marek Vasut56916e42014-09-15 03:58:22 +020026 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Ley Foon Tanb149f2b2017-04-26 02:44:36 +080027
28struct bsel bsel_str[] = {
29 { "rsvd", "Reserved", },
30 { "fpga", "FPGA (HPS2FPGA Bridge)", },
31 { "nand", "NAND Flash (1.8V)", },
32 { "nand", "NAND Flash (3.0V)", },
33 { "sd", "SD/MMC External Transceiver (1.8V)", },
34 { "sd", "SD/MMC Internal Transceiver (3.0V)", },
35 { "qspi", "QSPI Flash (1.8V)", },
36 { "qspi", "QSPI Flash (3.0V)", },
37};
Pavel Machek57d75eb2014-09-08 14:08:45 +020038
Dinh Nguyenad51f7c2012-10-04 06:46:02 +000039int dram_init(void)
40{
41 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
42 return 0;
43}
Pavel Machek57d75eb2014-09-08 14:08:45 +020044
Marek Vasutd5157942014-09-21 13:57:40 +020045void enable_caches(void)
46{
47#ifndef CONFIG_SYS_ICACHE_OFF
48 icache_enable();
49#endif
50#ifndef CONFIG_SYS_DCACHE_OFF
51 dcache_enable();
52#endif
53}
54
Dinh Nguyene89ff702015-10-15 10:13:36 -050055void v7_outer_cache_enable(void)
56{
Marek Vasut9f7b30d2015-12-20 04:00:09 +010057 /* Disable the L2 cache */
58 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Dinh Nguyene89ff702015-10-15 10:13:36 -050059
60 /* enable BRESP, instruction and data prefetch, full line of zeroes */
61 setbits_le32(&pl310->pl310_aux_ctrl,
62 L310_AUX_CTRL_DATA_PREFETCH_MASK |
63 L310_AUX_CTRL_INST_PREFETCH_MASK |
64 L310_SHARED_ATT_OVERRIDE_ENABLE);
Marek Vasut9f7b30d2015-12-20 04:00:09 +010065
66 /* Enable the L2 cache */
67 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
68}
69
70void v7_outer_cache_disable(void)
71{
72 /* Disable the L2 cache */
73 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Dinh Nguyene89ff702015-10-15 10:13:36 -050074}
75
Chin Liang Seebff262c2014-06-10 02:23:45 -050076#if defined(CONFIG_SYS_CONSOLE_IS_IN_ENV) && \
77defined(CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE)
78int overwrite_console(void)
79{
80 return 0;
81}
82#endif
83
Pavel Machekc7213802014-09-08 14:08:45 +020084#ifdef CONFIG_FPGA
85/*
86 * FPGA programming support for SoC FPGA Cyclone V
87 */
88static Altera_desc altera_fpga[] = {
89 {
90 /* Family */
91 Altera_SoCFPGA,
92 /* Interface type */
93 fast_passive_parallel,
94 /* No limitation as additional data will be ignored */
95 -1,
96 /* No device function table */
97 NULL,
98 /* Base interface address specified in driver */
99 NULL,
100 /* No cookie implementation */
101 0
102 },
103};
104
105/* add device descriptor to FPGA device table */
Ley Foon Tanb149f2b2017-04-26 02:44:36 +0800106void socfpga_fpga_add(void)
Pavel Machekc7213802014-09-08 14:08:45 +0200107{
108 int i;
109 fpga_init();
110 for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
111 fpga_add(fpga_altera, &altera_fpga[i]);
112}
Pavel Machekc7213802014-09-08 14:08:45 +0200113#endif
114
Pavel Machek56a00ab2014-09-09 14:03:28 +0200115int arch_cpu_init(void)
116{
Stefan Roese3bfb5912014-12-19 13:49:10 +0100117#ifdef CONFIG_HW_WATCHDOG
118 /*
119 * In case the watchdog is enabled, make sure to (re-)configure it
120 * so that the defined timeout is valid. Otherwise the SPL (Perloader)
121 * timeout value is still active which might too short for Linux
122 * booting.
123 */
124 hw_watchdog_init();
125#else
Pavel Machek56a00ab2014-09-09 14:03:28 +0200126 /*
127 * If the HW watchdog is NOT enabled, make sure it is not running,
128 * for example because it was enabled in the preloader. This might
129 * trigger a watchdog-triggered reboot of Linux kernel later.
Marek Vasut75f6b5c2015-07-09 02:51:56 +0200130 * Toggle watchdog reset, so watchdog in not running state.
Pavel Machek56a00ab2014-09-09 14:03:28 +0200131 */
Marek Vasut75f6b5c2015-07-09 02:51:56 +0200132 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 1);
133 socfpga_per_reset(SOCFPGA_RESET(L4WD0), 0);
Pavel Machek56a00ab2014-09-09 14:03:28 +0200134#endif
Stefan Roese3bfb5912014-12-19 13:49:10 +0100135
Pavel Machek56a00ab2014-09-09 14:03:28 +0200136 return 0;
137}