blob: b144c84bd4998200e9fa3a082291ec6d846e079b [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
2 * Copyright (c) 2013-2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08005 */
6
Soren Brinkmann76fcae32016-03-06 20:16:27 -08007#include <debug.h>
Soren Brinkmanne5bdcaa2016-06-22 09:02:56 -07008#include <generic_delay_timer.h>
Soren Brinkmann76fcae32016-03-06 20:16:27 -08009#include <mmio.h>
Soren Brinkmann76fcae32016-03-06 20:16:27 -080010#include <platform.h>
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053011#include <stdbool.h>
12#include <string.h>
Soren Brinkmann76fcae32016-03-06 20:16:27 -080013#include <xlat_tables.h>
14#include "../zynqmp_private.h"
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +053015#include "pm_api_sys.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080016
17/*
18 * Table of regions to map using the MMU.
19 * This doesn't include TZRAM as the 'mem_layout' argument passed to
20 * configure_mmu_elx() will give the available subset of that,
21 */
22const mmap_region_t plat_arm_mmap[] = {
23 { DEVICE0_BASE, DEVICE0_BASE, DEVICE0_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
24 { DEVICE1_BASE, DEVICE1_BASE, DEVICE1_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
25 { CRF_APB_BASE, CRF_APB_BASE, CRF_APB_SIZE, MT_DEVICE | MT_RW | MT_SECURE },
26 {0}
27};
28
29static unsigned int zynqmp_get_silicon_ver(void)
30{
Soren Brinkmann85863992016-09-16 10:34:47 -070031 static unsigned int ver;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080032
Soren Brinkmann85863992016-09-16 10:34:47 -070033 if (!ver) {
34 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR +
35 ZYNQMP_CSU_VERSION_OFFSET);
36 ver &= ZYNQMP_SILICON_VER_MASK;
37 ver >>= ZYNQMP_SILICON_VER_SHIFT;
38 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -080039
40 return ver;
41}
42
43unsigned int zynqmp_get_uart_clk(void)
44{
45 unsigned int ver = zynqmp_get_silicon_ver();
46
47 switch (ver) {
48 case ZYNQMP_CSU_VERSION_VELOCE:
49 return 48000;
50 case ZYNQMP_CSU_VERSION_EP108:
51 return 25000000;
52 case ZYNQMP_CSU_VERSION_QEMU:
53 return 133000000;
Jonathan Wrightff957ed2018-03-14 15:24:00 +000054 default:
55 /* Do nothing in default case */
56 break;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080057 }
58
59 return 100000000;
60}
61
Soren Brinkmann76fcae32016-03-06 20:16:27 -080062#if LOG_LEVEL >= LOG_LEVEL_NOTICE
63static const struct {
64 unsigned int id;
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053065 unsigned int ver;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080066 char *name;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053067 bool evexists;
Soren Brinkmann76fcae32016-03-06 20:16:27 -080068} zynqmp_devices[] = {
69 {
70 .id = 0x10,
71 .name = "3EG",
72 },
73 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053074 .id = 0x10,
75 .ver = 0x2c,
76 .name = "3CG",
77 },
78 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080079 .id = 0x11,
80 .name = "2EG",
81 },
82 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053083 .id = 0x11,
84 .ver = 0x2c,
85 .name = "2CG",
86 },
87 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -080088 .id = 0x20,
89 .name = "5EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053090 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -080091 },
92 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053093 .id = 0x20,
94 .ver = 0x100,
95 .name = "5EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +053096 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +053097 },
98 {
99 .id = 0x20,
100 .ver = 0x12c,
101 .name = "5CG",
102 },
103 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800104 .id = 0x21,
105 .name = "4EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530106 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800107 },
108 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530109 .id = 0x21,
110 .ver = 0x100,
111 .name = "4EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530112 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530113 },
114 {
115 .id = 0x21,
116 .ver = 0x12c,
117 .name = "4CG",
118 },
119 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800120 .id = 0x30,
121 .name = "7EV",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530122 .evexists = true,
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800123 },
124 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530125 .id = 0x30,
126 .ver = 0x100,
127 .name = "7EG",
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530128 .evexists = true,
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530129 },
130 {
131 .id = 0x30,
132 .ver = 0x12c,
133 .name = "7CG",
134 },
135 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800136 .id = 0x38,
137 .name = "9EG",
138 },
139 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530140 .id = 0x38,
141 .ver = 0x2c,
142 .name = "9CG",
143 },
144 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800145 .id = 0x39,
146 .name = "6EG",
147 },
148 {
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530149 .id = 0x39,
150 .ver = 0x2c,
151 .name = "6CG",
152 },
153 {
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800154 .id = 0x40,
155 .name = "11EG",
156 },
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530157 { /* For testing purpose only */
158 .id = 0x50,
159 .ver = 0x2c,
160 .name = "15CG",
161 },
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800162 {
163 .id = 0x50,
164 .name = "15EG",
165 },
166 {
167 .id = 0x58,
168 .name = "19EG",
169 },
170 {
171 .id = 0x59,
172 .name = "17EG",
173 },
Siva Durga Prasad Paladugu19d69c02017-06-06 12:54:52 +0530174 {
175 .id = 0x60,
176 .name = "28DR",
177 },
178 {
179 .id = 0x61,
180 .name = "21DR",
181 },
182 {
183 .id = 0x62,
184 .name = "29DR",
185 },
186 {
187 .id = 0x63,
188 .name = "23DR",
189 },
190 {
191 .id = 0x64,
192 .name = "27DR",
193 },
194 {
195 .id = 0x65,
196 .name = "25DR",
197 },
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800198};
199
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530200#define ZYNQMP_PL_STATUS_BIT 9
201#define ZYNQMP_PL_STATUS_MASK BIT(ZYNQMP_PL_STATUS_BIT)
202#define ZYNQMP_CSU_VERSION_MASK ~(ZYNQMP_PL_STATUS_MASK)
203
204static char *zynqmp_get_silicon_idcode_name(void)
Soren Brinkmanncb366812016-09-22 12:21:11 -0700205{
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530206 uint32_t id, ver, chipid[2];
207 size_t i, j, len;
208 enum pm_ret_status ret;
209 const char *name = "EG/EV";
Soren Brinkmanncb366812016-09-22 12:21:11 -0700210
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530211 ret = pm_get_chipid(chipid);
212 if (ret)
213 return "UNKN";
Soren Brinkmanncb366812016-09-22 12:21:11 -0700214
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530215 id = chipid[0] & (ZYNQMP_CSU_IDCODE_DEVICE_CODE_MASK |
216 ZYNQMP_CSU_IDCODE_SVD_MASK);
Soren Brinkmanncb366812016-09-22 12:21:11 -0700217 id >>= ZYNQMP_CSU_IDCODE_SVD_SHIFT;
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530218 ver = chipid[1] >> ZYNQMP_EFUSE_IPDISABLE_SHIFT;
Soren Brinkmanncb366812016-09-22 12:21:11 -0700219
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530220 for (i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
221 if (zynqmp_devices[i].id == id &&
222 zynqmp_devices[i].ver == (ver & ZYNQMP_CSU_VERSION_MASK))
223 break;
224 }
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530225
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530226 if (i >= ARRAY_SIZE(zynqmp_devices))
227 return "UNKN";
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530228
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530229 if (!zynqmp_devices[i].evexists)
230 return zynqmp_devices[i].name;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800231
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530232 if (ver & ZYNQMP_PL_STATUS_MASK)
233 return zynqmp_devices[i].name;
Siva Durga Prasad Paladugu83e37252018-05-01 11:10:25 +0530234
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530235 len = strlen(zynqmp_devices[i].name) - 2;
236 for (j = 0; j < strlen(name); j++) {
237 zynqmp_devices[i].name[len] = name[j];
238 len++;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800239 }
Siva Durga Prasad Paladugub76656d2018-03-05 18:47:15 +0530240 zynqmp_devices[i].name[len] = '\0';
241
242 return zynqmp_devices[i].name;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800243}
244
245static unsigned int zynqmp_get_rtl_ver(void)
246{
247 uint32_t ver;
248
249 ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
250 ver &= ZYNQMP_RTL_VER_MASK;
251 ver >>= ZYNQMP_RTL_VER_SHIFT;
252
253 return ver;
254}
255
256static char *zynqmp_print_silicon_idcode(void)
257{
258 uint32_t id, maskid, tmp;
259
260 id = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_IDCODE_OFFSET);
261
262 tmp = id;
263 tmp &= ZYNQMP_CSU_IDCODE_XILINX_ID_MASK |
Soren Brinkmann31114132016-05-20 07:05:00 -0700264 ZYNQMP_CSU_IDCODE_FAMILY_MASK;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800265 maskid = ZYNQMP_CSU_IDCODE_XILINX_ID << ZYNQMP_CSU_IDCODE_XILINX_ID_SHIFT |
Soren Brinkmann31114132016-05-20 07:05:00 -0700266 ZYNQMP_CSU_IDCODE_FAMILY << ZYNQMP_CSU_IDCODE_FAMILY_SHIFT;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800267 if (tmp != maskid) {
268 ERROR("Incorrect XILINX IDCODE 0x%x, maskid 0x%x\n", id, maskid);
269 return "UNKN";
270 }
271 VERBOSE("Xilinx IDCODE 0x%x\n", id);
272 return zynqmp_get_silicon_idcode_name();
273}
274
275static unsigned int zynqmp_get_ps_ver(void)
276{
277 uint32_t ver = mmio_read_32(ZYNQMP_CSU_BASEADDR + ZYNQMP_CSU_VERSION_OFFSET);
278
279 ver &= ZYNQMP_PS_VER_MASK;
280 ver >>= ZYNQMP_PS_VER_SHIFT;
281
282 return ver + 1;
283}
284
285static void zynqmp_print_platform_name(void)
286{
287 unsigned int ver = zynqmp_get_silicon_ver();
288 unsigned int rtl = zynqmp_get_rtl_ver();
289 char *label = "Unknown";
290
291 switch (ver) {
292 case ZYNQMP_CSU_VERSION_VELOCE:
293 label = "VELOCE";
294 break;
295 case ZYNQMP_CSU_VERSION_EP108:
296 label = "EP108";
297 break;
298 case ZYNQMP_CSU_VERSION_QEMU:
299 label = "QEMU";
300 break;
301 case ZYNQMP_CSU_VERSION_SILICON:
302 label = "silicon";
303 break;
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000304 default:
305 /* Do nothing in default case */
306 break;
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800307 }
308
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530309 NOTICE("ATF running on XCZU%s/%s v%d/RTL%d.%d at 0x%x\n",
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800310 zynqmp_print_silicon_idcode(), label, zynqmp_get_ps_ver(),
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530311 (rtl & 0xf0) >> 4, rtl & 0xf, BL31_BASE);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800312}
313#else
314static inline void zynqmp_print_platform_name(void) { }
315#endif
316
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700317unsigned int zynqmp_get_bootmode(void)
318{
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530319 uint32_t r;
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530320 unsigned int ret;
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530321
Siva Durga Prasad Paladugu40808bc2018-04-30 19:43:03 +0530322 ret = pm_mmio_read(CRL_APB_BOOT_MODE_USER, &r);
323
324 if (ret != PM_RET_SUCCESS)
Siva Durga Prasad Paladugu00ae6c52017-02-20 17:55:50 +0530325 r = mmio_read_32(CRL_APB_BOOT_MODE_USER);
Soren Brinkmannb43d9432016-04-18 11:49:42 -0700326
327 return r & CRL_APB_BOOT_MODE_MASK;
328}
329
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800330void zynqmp_config_setup(void)
331{
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800332 zynqmp_print_platform_name();
Soren Brinkmanne5bdcaa2016-06-22 09:02:56 -0700333 generic_delay_timer_init();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800334}
335
Antonio Nino Diaze82e29c2016-05-19 10:00:28 +0100336unsigned int plat_get_syscnt_freq2(void)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800337{
Soren Brinkmanncfcb1a22016-09-16 10:31:06 -0700338 unsigned int ver = zynqmp_get_silicon_ver();
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800339
Soren Brinkmanncfcb1a22016-09-16 10:31:06 -0700340 switch (ver) {
341 case ZYNQMP_CSU_VERSION_VELOCE:
342 return 10000;
343 case ZYNQMP_CSU_VERSION_EP108:
344 return 4000000;
345 case ZYNQMP_CSU_VERSION_QEMU:
346 return 50000000;
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000347 default:
348 /* Do nothing in default case */
349 break;
Soren Brinkmanncfcb1a22016-09-16 10:31:06 -0700350 }
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800351
Soren Brinkmanncfcb1a22016-09-16 10:31:06 -0700352 return mmio_read_32(IOU_SCNTRS_BASEFREQ);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800353}