Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | dea68a7 | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Michal Simek <monstr@monstr.eu> |
| 4 | * Copyright (C) 2012 Xilinx, Inc. All rights reserved. |
Michal Simek | dea68a7 | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame^] | 7 | #include <cpu_func.h> |
Michal Simek | f31d90f | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 8 | #include <zynqpl.h> |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 9 | #include <asm/io.h> |
Soren Brinkmann | 102ad00 | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 10 | #include <asm/arch/clk.h> |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 11 | #include <asm/arch/hardware.h> |
Michal Simek | f31d90f | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 12 | #include <asm/arch/ps7_init_gpl.h> |
| 13 | #include <asm/arch/sys_proto.h> |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 14 | |
Siva Durga Prasad Paladugu | e26ef3b | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 15 | #define ZYNQ_SILICON_VER_MASK 0xF0000000 |
| 16 | #define ZYNQ_SILICON_VER_SHIFT 28 |
| 17 | |
Michal Simek | f31d90f | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 18 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 19 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
| 20 | xilinx_desc fpga = { |
| 21 | .family = xilinx_zynq, |
| 22 | .iface = devcfg, |
| 23 | .operations = &zynq_op, |
| 24 | }; |
| 25 | #endif |
| 26 | |
| 27 | static const struct { |
| 28 | u8 idcode; |
| 29 | #if defined(CONFIG_FPGA) |
| 30 | u32 fpga_size; |
| 31 | #endif |
| 32 | char *devicename; |
| 33 | } zynq_fpga_descs[] = { |
| 34 | ZYNQ_DESC(7Z007S), |
| 35 | ZYNQ_DESC(7Z010), |
| 36 | ZYNQ_DESC(7Z012S), |
| 37 | ZYNQ_DESC(7Z014S), |
| 38 | ZYNQ_DESC(7Z015), |
| 39 | ZYNQ_DESC(7Z020), |
| 40 | ZYNQ_DESC(7Z030), |
| 41 | ZYNQ_DESC(7Z035), |
| 42 | ZYNQ_DESC(7Z045), |
| 43 | ZYNQ_DESC(7Z100), |
| 44 | { /* Sentinel */ }, |
| 45 | }; |
| 46 | |
Michal Simek | d1a428f | 2013-08-22 14:52:02 +0200 | [diff] [blame] | 47 | int arch_cpu_init(void) |
| 48 | { |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 49 | zynq_slcr_unlock(); |
Michal Simek | e60148d | 2014-01-14 14:21:52 +0100 | [diff] [blame] | 50 | #ifndef CONFIG_SPL_BUILD |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 51 | /* Device config APB, unlock the PCAP */ |
| 52 | writel(0x757BDF0D, &devcfg_base->unlock); |
| 53 | writel(0xFFFFFFFF, &devcfg_base->rom_shadow); |
| 54 | |
Michal Simek | 9dc81ec | 2013-08-28 08:26:41 +0200 | [diff] [blame] | 55 | #if (CONFIG_SYS_SDRAM_BASE == 0) |
| 56 | /* remap DDR to zero, FILTERSTART */ |
| 57 | writel(0, &scu_base->filter_start); |
| 58 | |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 59 | /* OCM_CFG, Mask out the ROM, map ram into upper addresses */ |
| 60 | writel(0x1F, &slcr_base->ocm_cfg); |
| 61 | /* FPGA_RST_CTRL, clear resets on AXI fabric ports */ |
| 62 | writel(0x0, &slcr_base->fpga_rst_ctrl); |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 63 | /* Set urgent bits with register */ |
| 64 | writel(0x0, &slcr_base->ddr_urgent_sel); |
| 65 | /* Urgent write, ports S2/S3 */ |
| 66 | writel(0xC, &slcr_base->ddr_urgent); |
Michal Simek | 9dc81ec | 2013-08-28 08:26:41 +0200 | [diff] [blame] | 67 | #endif |
Michal Simek | e60148d | 2014-01-14 14:21:52 +0100 | [diff] [blame] | 68 | #endif |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 69 | zynq_slcr_lock(); |
Michal Simek | d1a428f | 2013-08-22 14:52:02 +0200 | [diff] [blame] | 70 | |
| 71 | return 0; |
Michal Simek | 6d46480 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 72 | } |
Michal Simek | dea68a7 | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 73 | |
Siva Durga Prasad Paladugu | e26ef3b | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 74 | unsigned int zynq_get_silicon_version(void) |
| 75 | { |
Masahiro Yamada | 04cfea5 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 76 | return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK) |
| 77 | >> ZYNQ_SILICON_VER_SHIFT; |
Siva Durga Prasad Paladugu | e26ef3b | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 78 | } |
| 79 | |
Michal Simek | dea68a7 | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 80 | void reset_cpu(ulong addr) |
| 81 | { |
Michal Simek | eb1dfa7 | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 82 | zynq_slcr_cpu_reset(); |
Michal Simek | dea68a7 | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 83 | while (1) |
| 84 | ; |
| 85 | } |
Michal Simek | 6026411 | 2014-01-03 09:32:35 +0100 | [diff] [blame] | 86 | |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 87 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Michal Simek | 6026411 | 2014-01-03 09:32:35 +0100 | [diff] [blame] | 88 | void enable_caches(void) |
| 89 | { |
| 90 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 91 | dcache_enable(); |
| 92 | } |
| 93 | #endif |
Michal Simek | f31d90f | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 94 | |
| 95 | static int __maybe_unused cpu_desc_id(void) |
| 96 | { |
| 97 | u32 idcode; |
| 98 | u8 i; |
| 99 | |
| 100 | idcode = zynq_slcr_get_idcode(); |
| 101 | for (i = 0; zynq_fpga_descs[i].idcode; i++) { |
| 102 | if (zynq_fpga_descs[i].idcode == idcode) |
| 103 | return i; |
| 104 | } |
| 105 | |
| 106 | return -ENODEV; |
| 107 | } |
| 108 | |
| 109 | #if defined(CONFIG_ARCH_EARLY_INIT_R) |
| 110 | int arch_early_init_r(void) |
| 111 | { |
| 112 | #if (defined(CONFIG_FPGA) && !defined(CONFIG_SPL_BUILD)) || \ |
| 113 | (defined(CONFIG_SPL_FPGA_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
| 114 | int cpu_id = cpu_desc_id(); |
| 115 | |
| 116 | if (cpu_id < 0) |
| 117 | return 0; |
| 118 | |
| 119 | fpga.size = zynq_fpga_descs[cpu_id].fpga_size; |
| 120 | fpga.name = zynq_fpga_descs[cpu_id].devicename; |
| 121 | fpga_init(); |
| 122 | fpga_add(fpga_xilinx, &fpga); |
| 123 | #endif |
| 124 | return 0; |
| 125 | } |
| 126 | #endif |
Michal Simek | f7ae6d6 | 2018-02-28 09:50:07 +0100 | [diff] [blame] | 127 | |
| 128 | #ifdef CONFIG_DISPLAY_CPUINFO |
| 129 | int print_cpuinfo(void) |
| 130 | { |
| 131 | u32 version; |
| 132 | int cpu_id = cpu_desc_id(); |
| 133 | |
| 134 | if (cpu_id < 0) |
| 135 | return 0; |
| 136 | |
| 137 | version = zynq_get_silicon_version() << 1; |
| 138 | if (version > (PCW_SILICON_VERSION_3 << 1)) |
| 139 | version += 1; |
| 140 | |
| 141 | printf("CPU: Zynq %s\n", zynq_fpga_descs[cpu_id].devicename); |
| 142 | printf("Silicon: v%d.%d\n", version >> 1, version & 1); |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |