Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 38b343d | 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 | 38b343d | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Michal Simek | 4aba5fb | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 9 | #include <zynqpl.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 10 | #include <asm/cache.h> |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 11 | #include <asm/io.h> |
Soren Brinkmann | 6c3e61d | 2013-11-21 13:38:54 -0800 | [diff] [blame] | 12 | #include <asm/arch/clk.h> |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 13 | #include <asm/arch/hardware.h> |
Michal Simek | 4aba5fb | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 14 | #include <asm/arch/ps7_init_gpl.h> |
| 15 | #include <asm/arch/sys_proto.h> |
Michal Simek | 38b343d | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 16 | |
Siva Durga Prasad Paladugu | 96a2859 | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 17 | #define ZYNQ_SILICON_VER_MASK 0xF0000000 |
| 18 | #define ZYNQ_SILICON_VER_SHIFT 28 |
| 19 | |
Michal Simek | 29bd8ad | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 20 | #if CONFIG_IS_ENABLED(FPGA) |
Michal Simek | 4aba5fb | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 21 | xilinx_desc fpga = { |
| 22 | .family = xilinx_zynq, |
| 23 | .iface = devcfg, |
| 24 | .operations = &zynq_op, |
| 25 | }; |
| 26 | #endif |
| 27 | |
| 28 | static const struct { |
| 29 | u8 idcode; |
| 30 | #if defined(CONFIG_FPGA) |
| 31 | u32 fpga_size; |
| 32 | #endif |
| 33 | char *devicename; |
| 34 | } zynq_fpga_descs[] = { |
| 35 | ZYNQ_DESC(7Z007S), |
| 36 | ZYNQ_DESC(7Z010), |
| 37 | ZYNQ_DESC(7Z012S), |
| 38 | ZYNQ_DESC(7Z014S), |
| 39 | ZYNQ_DESC(7Z015), |
| 40 | ZYNQ_DESC(7Z020), |
| 41 | ZYNQ_DESC(7Z030), |
| 42 | ZYNQ_DESC(7Z035), |
| 43 | ZYNQ_DESC(7Z045), |
| 44 | ZYNQ_DESC(7Z100), |
| 45 | { /* Sentinel */ }, |
| 46 | }; |
| 47 | |
Michal Simek | 262f08d | 2013-08-22 14:52:02 +0200 | [diff] [blame] | 48 | int arch_cpu_init(void) |
| 49 | { |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 50 | zynq_slcr_unlock(); |
Michal Simek | d7e269c | 2014-01-14 14:21:52 +0100 | [diff] [blame] | 51 | #ifndef CONFIG_SPL_BUILD |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 52 | /* Device config APB, unlock the PCAP */ |
| 53 | writel(0x757BDF0D, &devcfg_base->unlock); |
| 54 | writel(0xFFFFFFFF, &devcfg_base->rom_shadow); |
| 55 | |
Michal Simek | c1824ea | 2013-08-28 08:26:41 +0200 | [diff] [blame] | 56 | #if (CONFIG_SYS_SDRAM_BASE == 0) |
| 57 | /* remap DDR to zero, FILTERSTART */ |
| 58 | writel(0, &scu_base->filter_start); |
| 59 | |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 60 | /* OCM_CFG, Mask out the ROM, map ram into upper addresses */ |
| 61 | writel(0x1F, &slcr_base->ocm_cfg); |
| 62 | /* FPGA_RST_CTRL, clear resets on AXI fabric ports */ |
| 63 | writel(0x0, &slcr_base->fpga_rst_ctrl); |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 64 | /* Set urgent bits with register */ |
| 65 | writel(0x0, &slcr_base->ddr_urgent_sel); |
| 66 | /* Urgent write, ports S2/S3 */ |
| 67 | writel(0xC, &slcr_base->ddr_urgent); |
Michal Simek | c1824ea | 2013-08-28 08:26:41 +0200 | [diff] [blame] | 68 | #endif |
Michal Simek | d7e269c | 2014-01-14 14:21:52 +0100 | [diff] [blame] | 69 | #endif |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 70 | zynq_slcr_lock(); |
Michal Simek | 262f08d | 2013-08-22 14:52:02 +0200 | [diff] [blame] | 71 | |
| 72 | return 0; |
Michal Simek | 00ed345 | 2013-02-04 12:42:25 +0100 | [diff] [blame] | 73 | } |
Michal Simek | 38b343d | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 74 | |
Siva Durga Prasad Paladugu | 96a2859 | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 75 | unsigned int zynq_get_silicon_version(void) |
| 76 | { |
Masahiro Yamada | 63a7578 | 2016-09-06 22:17:38 +0900 | [diff] [blame] | 77 | return (readl(&devcfg_base->mctrl) & ZYNQ_SILICON_VER_MASK) |
| 78 | >> ZYNQ_SILICON_VER_SHIFT; |
Siva Durga Prasad Paladugu | 96a2859 | 2013-11-29 19:01:25 +0530 | [diff] [blame] | 79 | } |
| 80 | |
Michal Simek | 38b343d | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 81 | void reset_cpu(ulong addr) |
| 82 | { |
Michal Simek | 59c651f | 2013-02-04 12:38:59 +0100 | [diff] [blame] | 83 | zynq_slcr_cpu_reset(); |
Michal Simek | 38b343d | 2012-09-13 20:23:35 +0000 | [diff] [blame] | 84 | while (1) |
| 85 | ; |
| 86 | } |
Michal Simek | 673ba27 | 2014-01-03 09:32:35 +0100 | [diff] [blame] | 87 | |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 88 | #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Michal Simek | 673ba27 | 2014-01-03 09:32:35 +0100 | [diff] [blame] | 89 | void enable_caches(void) |
| 90 | { |
| 91 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 92 | dcache_enable(); |
| 93 | } |
| 94 | #endif |
Michal Simek | 4aba5fb | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 95 | |
| 96 | static int __maybe_unused cpu_desc_id(void) |
| 97 | { |
| 98 | u32 idcode; |
| 99 | u8 i; |
| 100 | |
| 101 | idcode = zynq_slcr_get_idcode(); |
| 102 | for (i = 0; zynq_fpga_descs[i].idcode; i++) { |
| 103 | if (zynq_fpga_descs[i].idcode == idcode) |
| 104 | return i; |
| 105 | } |
| 106 | |
| 107 | return -ENODEV; |
| 108 | } |
| 109 | |
| 110 | #if defined(CONFIG_ARCH_EARLY_INIT_R) |
| 111 | int arch_early_init_r(void) |
| 112 | { |
Michal Simek | 29bd8ad | 2020-09-09 14:41:56 +0200 | [diff] [blame] | 113 | #if CONFIG_IS_ENABLED(FPGA) |
Michal Simek | 4aba5fb | 2018-01-17 10:56:22 -0300 | [diff] [blame] | 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 | 0b4b82a | 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 |