blob: 74dddc259889c553a2d131f800b4da0efe397b45 [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 */
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.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>
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <linux/errno.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <asm/cache.h>
Michal Simek6d464802013-02-04 12:42:25 +010012#include <asm/io.h>
Soren Brinkmann102ad002013-11-21 13:38:54 -080013#include <asm/arch/clk.h>
Michal Simek6d464802013-02-04 12:42:25 +010014#include <asm/arch/hardware.h>
Michal Simekf31d90f2018-01-17 10:56:22 -030015#include <asm/arch/ps7_init_gpl.h>
16#include <asm/arch/sys_proto.h>
Michal Simek6d464802013-02-04 12:42:25 +010017
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053018#define ZYNQ_SILICON_VER_MASK 0xF0000000
19#define ZYNQ_SILICON_VER_SHIFT 28
20
Michal Simek1aab1142020-09-09 14:41:56 +020021#if CONFIG_IS_ENABLED(FPGA)
Michal Simekf31d90f2018-01-17 10:56:22 -030022xilinx_desc fpga = {
23 .family = xilinx_zynq,
24 .iface = devcfg,
25 .operations = &zynq_op,
Oleksandr Suvorovdae95a42022-07-22 17:16:04 +030026 .flags = FPGA_LEGACY,
Michal Simekf31d90f2018-01-17 10:56:22 -030027};
28#endif
29
30static const struct {
31 u8 idcode;
32#if defined(CONFIG_FPGA)
33 u32 fpga_size;
34#endif
35 char *devicename;
36} zynq_fpga_descs[] = {
37 ZYNQ_DESC(7Z007S),
38 ZYNQ_DESC(7Z010),
Michal Simek47d40532024-07-30 15:50:17 +020039 ZYNQ_DESC(7Z010_LR),
Michal Simekf31d90f2018-01-17 10:56:22 -030040 ZYNQ_DESC(7Z012S),
41 ZYNQ_DESC(7Z014S),
42 ZYNQ_DESC(7Z015),
Michal Simek47d40532024-07-30 15:50:17 +020043 ZYNQ_DESC(7Z020_LR),
Michal Simekf31d90f2018-01-17 10:56:22 -030044 ZYNQ_DESC(7Z020),
45 ZYNQ_DESC(7Z030),
46 ZYNQ_DESC(7Z035),
47 ZYNQ_DESC(7Z045),
48 ZYNQ_DESC(7Z100),
49 { /* Sentinel */ },
50};
51
Michal Simekd1a428f2013-08-22 14:52:02 +020052int arch_cpu_init(void)
53{
Michal Simek6d464802013-02-04 12:42:25 +010054 zynq_slcr_unlock();
Simon Glass85ed77d2024-09-29 19:49:46 -060055#ifndef CONFIG_XPL_BUILD
Michal Simek6d464802013-02-04 12:42:25 +010056 /* Device config APB, unlock the PCAP */
57 writel(0x757BDF0D, &devcfg_base->unlock);
58 writel(0xFFFFFFFF, &devcfg_base->rom_shadow);
59
Tom Rinibb4dd962022-11-16 13:10:37 -050060#if (CFG_SYS_SDRAM_BASE == 0)
Michal Simek9dc81ec2013-08-28 08:26:41 +020061 /* remap DDR to zero, FILTERSTART */
62 writel(0, &scu_base->filter_start);
63
Michal Simek6d464802013-02-04 12:42:25 +010064 /* OCM_CFG, Mask out the ROM, map ram into upper addresses */
65 writel(0x1F, &slcr_base->ocm_cfg);
66 /* FPGA_RST_CTRL, clear resets on AXI fabric ports */
67 writel(0x0, &slcr_base->fpga_rst_ctrl);
Michal Simek6d464802013-02-04 12:42:25 +010068 /* Set urgent bits with register */
69 writel(0x0, &slcr_base->ddr_urgent_sel);
70 /* Urgent write, ports S2/S3 */
71 writel(0xC, &slcr_base->ddr_urgent);
Michal Simek9dc81ec2013-08-28 08:26:41 +020072#endif
Michal Simeke60148d2014-01-14 14:21:52 +010073#endif
Michal Simek6d464802013-02-04 12:42:25 +010074 zynq_slcr_lock();
Michal Simekd1a428f2013-08-22 14:52:02 +020075
76 return 0;
Michal Simek6d464802013-02-04 12:42:25 +010077}
Michal Simekdea68a72012-09-13 20:23:35 +000078
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053079unsigned int zynq_get_silicon_version(void)
80{
Masahiro Yamada04cfea52016-09-06 22:17:38 +090081 return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK)
82 >> ZYNQ_SILICON_VER_SHIFT;
Siva Durga Prasad Paladugue26ef3b2013-11-29 19:01:25 +053083}
84
Harald Seiler6f14d5f2020-12-15 16:47:52 +010085void reset_cpu(void)
Michal Simekdea68a72012-09-13 20:23:35 +000086{
Michal Simekeb1dfa72013-02-04 12:38:59 +010087 zynq_slcr_cpu_reset();
Michal Simekdea68a72012-09-13 20:23:35 +000088 while (1)
89 ;
90}
Michal Simek60264112014-01-03 09:32:35 +010091
Trevor Woerner43ec7e02019-05-03 09:41:00 -040092#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Michal Simek60264112014-01-03 09:32:35 +010093void enable_caches(void)
94{
95 /* Enable D-cache. I-cache is already enabled in start.S */
96 dcache_enable();
97}
98#endif
Michal Simekf31d90f2018-01-17 10:56:22 -030099
100static int __maybe_unused cpu_desc_id(void)
101{
102 u32 idcode;
103 u8 i;
104
105 idcode = zynq_slcr_get_idcode();
106 for (i = 0; zynq_fpga_descs[i].idcode; i++) {
107 if (zynq_fpga_descs[i].idcode == idcode)
108 return i;
109 }
110
111 return -ENODEV;
112}
113
114#if defined(CONFIG_ARCH_EARLY_INIT_R)
115int arch_early_init_r(void)
116{
Michal Simek1aab1142020-09-09 14:41:56 +0200117#if CONFIG_IS_ENABLED(FPGA)
Michal Simekf31d90f2018-01-17 10:56:22 -0300118 int cpu_id = cpu_desc_id();
119
120 if (cpu_id < 0)
121 return 0;
122
123 fpga.size = zynq_fpga_descs[cpu_id].fpga_size;
124 fpga.name = zynq_fpga_descs[cpu_id].devicename;
125 fpga_init();
126 fpga_add(fpga_xilinx, &fpga);
127#endif
128 return 0;
129}
130#endif
Michal Simekf7ae6d62018-02-28 09:50:07 +0100131
132#ifdef CONFIG_DISPLAY_CPUINFO
133int print_cpuinfo(void)
134{
135 u32 version;
136 int cpu_id = cpu_desc_id();
137
138 if (cpu_id < 0)
139 return 0;
140
141 version = zynq_get_silicon_version() << 1;
142 if (version > (PCW_SILICON_VERSION_3 << 1))
143 version += 1;
144
145 printf("CPU: Zynq %s\n", zynq_fpga_descs[cpu_id].devicename);
146 printf("Silicon: v%d.%d\n", version >> 1, version & 1);
147 return 0;
148}
149#endif