blob: ac595ee0a27118b4d85db008be1da825fee10b1e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simekdea68a72012-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 Simekdea68a72012-09-13 20:23:35 +00005 */
6#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Michal Simekf31d90f2018-01-17 10:56:22 -03009#include <zynqpl.h>
Simon Glass274e0b02020-05-10 11:39:56 -060010#include <asm/cache.h>
Michal Simek6d464802013-02-04 12:42:25 +010011#include <asm/io.h>
Soren Brinkmann102ad002013-11-21 13:38:54 -080012#include <asm/arch/clk.h>
Michal Simek6d464802013-02-04 12:42:25 +010013#include <asm/arch/hardware.h>
Michal Simekf31d90f2018-01-17 10:56:22 -030014#include <asm/arch/ps7_init_gpl.h>
15#include <asm/arch/sys_proto.h>
Michal Simek6d464802013-02-04 12:42:25 +010016
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053017#define ZYNQ_SILICON_VER_MASK 0xF0000000
18#define ZYNQ_SILICON_VER_SHIFT 28
19
Michal Simek1aab1142020-09-09 14:41:56 +020020#if CONFIG_IS_ENABLED(FPGA)
Michal Simekf31d90f2018-01-17 10:56:22 -030021xilinx_desc fpga = {
22 .family = xilinx_zynq,
23 .iface = devcfg,
24 .operations = &zynq_op,
Oleksandr Suvorovdae95a42022-07-22 17:16:04 +030025 .flags = FPGA_LEGACY,
Michal Simekf31d90f2018-01-17 10:56:22 -030026};
27#endif
28
29static const struct {
30 u8 idcode;
31#if defined(CONFIG_FPGA)
32 u32 fpga_size;
33#endif
34 char *devicename;
35} zynq_fpga_descs[] = {
36 ZYNQ_DESC(7Z007S),
37 ZYNQ_DESC(7Z010),
38 ZYNQ_DESC(7Z012S),
39 ZYNQ_DESC(7Z014S),
40 ZYNQ_DESC(7Z015),
41 ZYNQ_DESC(7Z020),
42 ZYNQ_DESC(7Z030),
43 ZYNQ_DESC(7Z035),
44 ZYNQ_DESC(7Z045),
45 ZYNQ_DESC(7Z100),
46 { /* Sentinel */ },
47};
48
Michal Simekd1a428f2013-08-22 14:52:02 +020049int arch_cpu_init(void)
50{
Michal Simek6d464802013-02-04 12:42:25 +010051 zynq_slcr_unlock();
Michal Simeke60148d2014-01-14 14:21:52 +010052#ifndef CONFIG_SPL_BUILD
Michal Simek6d464802013-02-04 12:42:25 +010053 /* Device config APB, unlock the PCAP */
54 writel(0x757BDF0D, &devcfg_base->unlock);
55 writel(0xFFFFFFFF, &devcfg_base->rom_shadow);
56
Michal Simek9dc81ec2013-08-28 08:26:41 +020057#if (CONFIG_SYS_SDRAM_BASE == 0)
58 /* remap DDR to zero, FILTERSTART */
59 writel(0, &scu_base->filter_start);
60
Michal Simek6d464802013-02-04 12:42:25 +010061 /* OCM_CFG, Mask out the ROM, map ram into upper addresses */
62 writel(0x1F, &slcr_base->ocm_cfg);
63 /* FPGA_RST_CTRL, clear resets on AXI fabric ports */
64 writel(0x0, &slcr_base->fpga_rst_ctrl);
Michal Simek6d464802013-02-04 12:42:25 +010065 /* Set urgent bits with register */
66 writel(0x0, &slcr_base->ddr_urgent_sel);
67 /* Urgent write, ports S2/S3 */
68 writel(0xC, &slcr_base->ddr_urgent);
Michal Simek9dc81ec2013-08-28 08:26:41 +020069#endif
Michal Simeke60148d2014-01-14 14:21:52 +010070#endif
Michal Simek6d464802013-02-04 12:42:25 +010071 zynq_slcr_lock();
Michal Simekd1a428f2013-08-22 14:52:02 +020072
73 return 0;
Michal Simek6d464802013-02-04 12:42:25 +010074}
Michal Simekdea68a72012-09-13 20:23:35 +000075
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053076unsigned int zynq_get_silicon_version(void)
77{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090078 return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK)
79 >> ZYNQ_SILICON_VER_SHIFT;
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053080}
81
Harald Seiler6f14d5f2020-12-15 16:47:52 +010082void reset_cpu(void)
Michal Simekdea68a72012-09-13 20:23:35 +000083{
Michal Simekeb1dfa72013-02-04 12:38:59 +010084 zynq_slcr_cpu_reset();
Michal Simekdea68a72012-09-13 20:23:35 +000085 while (1)
86 ;
87}
Michal Simek60264112014-01-03 09:32:35 +010088
Trevor Woerner43ec7e02019-05-03 09:41:00 -040089#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Michal Simek60264112014-01-03 09:32:35 +010090void enable_caches(void)
91{
92 /* Enable D-cache. I-cache is already enabled in start.S */
93 dcache_enable();
94}
95#endif
Michal Simekf31d90f2018-01-17 10:56:22 -030096
97static int __maybe_unused cpu_desc_id(void)
98{
99 u32 idcode;
100 u8 i;
101
102 idcode = zynq_slcr_get_idcode();
103 for (i = 0; zynq_fpga_descs[i].idcode; i++) {
104 if (zynq_fpga_descs[i].idcode == idcode)
105 return i;
106 }
107
108 return -ENODEV;
109}
110
111#if defined(CONFIG_ARCH_EARLY_INIT_R)
112int arch_early_init_r(void)
113{
Michal Simek1aab1142020-09-09 14:41:56 +0200114#if CONFIG_IS_ENABLED(FPGA)
Michal Simekf31d90f2018-01-17 10:56:22 -0300115 int cpu_id = cpu_desc_id();
116
117 if (cpu_id < 0)
118 return 0;
119
120 fpga.size = zynq_fpga_descs[cpu_id].fpga_size;
121 fpga.name = zynq_fpga_descs[cpu_id].devicename;
122 fpga_init();
123 fpga_add(fpga_xilinx, &fpga);
124#endif
125 return 0;
126}
127#endif
Michal Simekf7ae6d62018-02-28 09:50:07 +0100128
129#ifdef CONFIG_DISPLAY_CPUINFO
130int print_cpuinfo(void)
131{
132 u32 version;
133 int cpu_id = cpu_desc_id();
134
135 if (cpu_id < 0)
136 return 0;
137
138 version = zynq_get_silicon_version() << 1;
139 if (version > (PCW_SILICON_VERSION_3 << 1))
140 version += 1;
141
142 printf("CPU: Zynq %s\n", zynq_fpga_descs[cpu_id].devicename);
143 printf("Silicon: v%d.%d\n", version >> 1, version & 1);
144 return 0;
145}
146#endif