blob: a3422cd5cf2c059e7d91b1e6a6526b193dd959e2 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek38b343d2012-09-13 20:23:35 +00002/*
3 * Copyright (C) 2012 Michal Simek <monstr@monstr.eu>
4 * Copyright (C) 2012 Xilinx, Inc. All rights reserved.
Michal Simek38b343d2012-09-13 20:23:35 +00005 */
6#include <common.h>
Michal Simek4aba5fb2018-01-17 10:56:22 -03007#include <zynqpl.h>
Michal Simek00ed3452013-02-04 12:42:25 +01008#include <asm/io.h>
Soren Brinkmann6c3e61d2013-11-21 13:38:54 -08009#include <asm/arch/clk.h>
Michal Simek00ed3452013-02-04 12:42:25 +010010#include <asm/arch/hardware.h>
Michal Simek4aba5fb2018-01-17 10:56:22 -030011#include <asm/arch/ps7_init_gpl.h>
12#include <asm/arch/sys_proto.h>
Michal Simek38b343d2012-09-13 20:23:35 +000013
Siva Durga Prasad Paladugu96a28592013-11-29 19:01:25 +053014#define ZYNQ_SILICON_VER_MASK 0xF0000000
15#define ZYNQ_SILICON_VER_SHIFT 28
16
Michal Simek4aba5fb2018-01-17 10:56:22 -030017#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
18 (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
19xilinx_desc fpga = {
20 .family = xilinx_zynq,
21 .iface = devcfg,
22 .operations = &zynq_op,
23};
24#endif
25
26static const struct {
27 u8 idcode;
28#if defined(CONFIG_FPGA)
29 u32 fpga_size;
30#endif
31 char *devicename;
32} zynq_fpga_descs[] = {
33 ZYNQ_DESC(7Z007S),
34 ZYNQ_DESC(7Z010),
35 ZYNQ_DESC(7Z012S),
36 ZYNQ_DESC(7Z014S),
37 ZYNQ_DESC(7Z015),
38 ZYNQ_DESC(7Z020),
39 ZYNQ_DESC(7Z030),
40 ZYNQ_DESC(7Z035),
41 ZYNQ_DESC(7Z045),
42 ZYNQ_DESC(7Z100),
43 { /* Sentinel */ },
44};
45
Michal Simek262f08d2013-08-22 14:52:02 +020046int arch_cpu_init(void)
47{
Michal Simek00ed3452013-02-04 12:42:25 +010048 zynq_slcr_unlock();
Michal Simekd7e269c2014-01-14 14:21:52 +010049#ifndef CONFIG_SPL_BUILD
Michal Simek00ed3452013-02-04 12:42:25 +010050 /* Device config APB, unlock the PCAP */
51 writel(0x757BDF0D, &devcfg_base->unlock);
52 writel(0xFFFFFFFF, &devcfg_base->rom_shadow);
53
Michal Simekc1824ea2013-08-28 08:26:41 +020054#if (CONFIG_SYS_SDRAM_BASE == 0)
55 /* remap DDR to zero, FILTERSTART */
56 writel(0, &scu_base->filter_start);
57
Michal Simek00ed3452013-02-04 12:42:25 +010058 /* OCM_CFG, Mask out the ROM, map ram into upper addresses */
59 writel(0x1F, &slcr_base->ocm_cfg);
60 /* FPGA_RST_CTRL, clear resets on AXI fabric ports */
61 writel(0x0, &slcr_base->fpga_rst_ctrl);
Michal Simek00ed3452013-02-04 12:42:25 +010062 /* Set urgent bits with register */
63 writel(0x0, &slcr_base->ddr_urgent_sel);
64 /* Urgent write, ports S2/S3 */
65 writel(0xC, &slcr_base->ddr_urgent);
Michal Simekc1824ea2013-08-28 08:26:41 +020066#endif
Michal Simekd7e269c2014-01-14 14:21:52 +010067#endif
Michal Simek00ed3452013-02-04 12:42:25 +010068 zynq_slcr_lock();
Michal Simek262f08d2013-08-22 14:52:02 +020069
70 return 0;
Michal Simek00ed3452013-02-04 12:42:25 +010071}
Michal Simek38b343d2012-09-13 20:23:35 +000072
Siva Durga Prasad Paladugu96a28592013-11-29 19:01:25 +053073unsigned int zynq_get_silicon_version(void)
74{
Masahiro Yamada63a75782016-09-06 22:17:38 +090075 return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK)
76 >> ZYNQ_SILICON_VER_SHIFT;
Siva Durga Prasad Paladugu96a28592013-11-29 19:01:25 +053077}
78
Michal Simek38b343d2012-09-13 20:23:35 +000079void reset_cpu(ulong addr)
80{
Michal Simek59c651f2013-02-04 12:38:59 +010081 zynq_slcr_cpu_reset();
Michal Simek38b343d2012-09-13 20:23:35 +000082 while (1)
83 ;
84}
Michal Simek673ba272014-01-03 09:32:35 +010085
86#ifndef CONFIG_SYS_DCACHE_OFF
87void enable_caches(void)
88{
89 /* Enable D-cache. I-cache is already enabled in start.S */
90 dcache_enable();
91}
92#endif
Michal Simek4aba5fb2018-01-17 10:56:22 -030093
94static int __maybe_unused cpu_desc_id(void)
95{
96 u32 idcode;
97 u8 i;
98
99 idcode = zynq_slcr_get_idcode();
100 for (i = 0; zynq_fpga_descs[i].idcode; i++) {
101 if (zynq_fpga_descs[i].idcode == idcode)
102 return i;
103 }
104
105 return -ENODEV;
106}
107
108#if defined(CONFIG_ARCH_EARLY_INIT_R)
109int arch_early_init_r(void)
110{
111#if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \
112 (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD))
113 int cpu_id = cpu_desc_id();
114
115 if (cpu_id < 0)
116 return 0;
117
118 fpga.size = zynq_fpga_descs[cpu_id].fpga_size;
119 fpga.name = zynq_fpga_descs[cpu_id].devicename;
120 fpga_init();
121 fpga_add(fpga_xilinx, &fpga);
122#endif
123 return 0;
124}
125#endif
Michal Simek0b4b82a2018-02-28 09:50:07 +0100126
127#ifdef CONFIG_DISPLAY_CPUINFO
128int print_cpuinfo(void)
129{
130 u32 version;
131 int cpu_id = cpu_desc_id();
132
133 if (cpu_id < 0)
134 return 0;
135
136 version = zynq_get_silicon_version() << 1;
137 if (version > (PCW_SILICON_VERSION_3 << 1))
138 version += 1;
139
140 printf("CPU: Zynq %s\n", zynq_fpga_descs[cpu_id].devicename);
141 printf("Silicon: v%d.%d\n", version >> 1, version & 1);
142 return 0;
143}
144#endif