blob: a2d5b82fd34d1c6968c76fc9e484490f66420108 [file] [log] [blame]
T Karthik Reddy501c2062021-08-10 06:50:18 -06001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx ZynqMP SOC driver
4 *
5 * Copyright (C) 2021 Xilinx, Inc.
Michal Simeka8c94362023-07-10 14:35:49 +02006 * Michal Simek <michal.simek@amd.com>
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +02007 *
8 * Copyright (C) 2022 Weidmüller Interface GmbH & Co. KG
9 * Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
T Karthik Reddy501c2062021-08-10 06:50:18 -060010 */
11
T Karthik Reddy501c2062021-08-10 06:50:18 -060012#include <dm.h>
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020013#include <dm/device_compat.h>
T Karthik Reddy501c2062021-08-10 06:50:18 -060014#include <asm/cache.h>
15#include <soc.h>
16#include <zynqmp_firmware.h>
17#include <asm/arch/sys_proto.h>
18#include <asm/arch/hardware.h>
19
20/*
21 * Zynqmp has 4 silicon revisions
22 * v0 -> 0(XCZU9EG-ES1)
23 * v1 -> 1(XCZU3EG-ES1, XCZU15EG-ES1)
24 * v2 -> 2(XCZU7EV-ES1, XCZU9EG-ES2, XCZU19EG-ES1)
25 * v3 -> 3(Production Level)
26 */
27static const char zynqmp_family[] = "ZynqMP";
28
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020029#define EFUSE_VCU_DIS_SHIFT 8
30#define EFUSE_VCU_DIS_MASK BIT(EFUSE_VCU_DIS_SHIFT)
31#define EFUSE_GPU_DIS_SHIFT 5
32#define EFUSE_GPU_DIS_MASK BIT(EFUSE_GPU_DIS_SHIFT)
33#define IDCODE_DEV_TYPE_MASK GENMASK(27, 0)
34#define IDCODE2_PL_INIT_SHIFT 9
35#define IDCODE2_PL_INIT_MASK BIT(IDCODE2_PL_INIT_SHIFT)
36
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +053037#define ZYNQMP_VERSION_SIZE 10
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020038
39enum {
40 ZYNQMP_VARIANT_EG = BIT(0),
41 ZYNQMP_VARIANT_EV = BIT(1),
42 ZYNQMP_VARIANT_CG = BIT(2),
43 ZYNQMP_VARIANT_DR = BIT(3),
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +053044 ZYNQMP_VARIANT_DR_SE = BIT(4),
45 ZYNQMP_VARIANT_EG_SE = BIT(5),
Venkatesh Yadav Abbarapu2175b042024-04-02 19:53:14 +053046 ZYNQMP_VARIANT_TEG = BIT(6),
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020047};
48
49struct zynqmp_device {
50 u32 id;
51 u8 device;
52 u8 variants;
53};
54
T Karthik Reddy501c2062021-08-10 06:50:18 -060055struct soc_xilinx_zynqmp_priv {
56 const char *family;
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020057 char machine[ZYNQMP_VERSION_SIZE];
T Karthik Reddy501c2062021-08-10 06:50:18 -060058 char revision;
59};
60
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020061static const struct zynqmp_device zynqmp_devices[] = {
62 {
63 .id = 0x04688093,
64 .device = 1,
65 .variants = ZYNQMP_VARIANT_EG,
66 },
67 {
68 .id = 0x04711093,
69 .device = 2,
70 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
71 },
72 {
73 .id = 0x04710093,
74 .device = 3,
75 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
76 },
77 {
Venkatesh Yadav Abbarapu2175b042024-04-02 19:53:14 +053078 .id = 0x04718093,
79 .device = 3,
80 .variants = ZYNQMP_VARIANT_TEG,
81 },
82 {
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +020083 .id = 0x04721093,
84 .device = 4,
85 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
86 ZYNQMP_VARIANT_EV,
87 },
88 {
89 .id = 0x04720093,
90 .device = 5,
91 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
92 ZYNQMP_VARIANT_EV,
93 },
94 {
95 .id = 0x04739093,
96 .device = 6,
97 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
98 },
99 {
100 .id = 0x04730093,
101 .device = 7,
102 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG |
103 ZYNQMP_VARIANT_EV,
104 },
105 {
106 .id = 0x04738093,
107 .device = 9,
108 .variants = ZYNQMP_VARIANT_EG | ZYNQMP_VARIANT_CG,
109 },
110 {
111 .id = 0x04740093,
112 .device = 11,
113 .variants = ZYNQMP_VARIANT_EG,
114 },
115 {
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530116 .id = 0x04741093,
117 .device = 11,
118 .variants = ZYNQMP_VARIANT_EG_SE,
119 },
120 {
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200121 .id = 0x04750093,
122 .device = 15,
123 .variants = ZYNQMP_VARIANT_EG,
124 },
125 {
126 .id = 0x04759093,
127 .device = 17,
128 .variants = ZYNQMP_VARIANT_EG,
129 },
130 {
131 .id = 0x04758093,
132 .device = 19,
133 .variants = ZYNQMP_VARIANT_EG,
134 },
135 {
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530136 .id = 0x0475C093,
137 .device = 19,
138 .variants = ZYNQMP_VARIANT_EG_SE,
139 },
140 {
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200141 .id = 0x047E1093,
142 .device = 21,
143 .variants = ZYNQMP_VARIANT_DR,
144 },
145 {
146 .id = 0x047E3093,
147 .device = 23,
148 .variants = ZYNQMP_VARIANT_DR,
149 },
150 {
151 .id = 0x047E5093,
152 .device = 25,
153 .variants = ZYNQMP_VARIANT_DR,
154 },
155 {
156 .id = 0x047E4093,
157 .device = 27,
158 .variants = ZYNQMP_VARIANT_DR,
159 },
160 {
161 .id = 0x047E0093,
162 .device = 28,
163 .variants = ZYNQMP_VARIANT_DR,
164 },
165 {
166 .id = 0x047E2093,
167 .device = 29,
168 .variants = ZYNQMP_VARIANT_DR,
169 },
170 {
171 .id = 0x047E6093,
172 .device = 39,
173 .variants = ZYNQMP_VARIANT_DR,
174 },
175 {
176 .id = 0x047FD093,
177 .device = 43,
178 .variants = ZYNQMP_VARIANT_DR,
179 },
180 {
181 .id = 0x047F8093,
182 .device = 46,
183 .variants = ZYNQMP_VARIANT_DR,
184 },
185 {
186 .id = 0x047FF093,
187 .device = 47,
188 .variants = ZYNQMP_VARIANT_DR,
189 },
190 {
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530191 .id = 0x047FA093,
192 .device = 47,
193 .variants = ZYNQMP_VARIANT_DR_SE,
194 },
195 {
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200196 .id = 0x047FB093,
197 .device = 48,
198 .variants = ZYNQMP_VARIANT_DR,
199 },
200 {
201 .id = 0x047FE093,
202 .device = 49,
203 .variants = ZYNQMP_VARIANT_DR,
204 },
205 {
206 .id = 0x046d0093,
207 .device = 67,
208 .variants = ZYNQMP_VARIANT_DR,
209 },
210 {
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530211 .id = 0x046d7093,
212 .device = 67,
213 .variants = ZYNQMP_VARIANT_DR_SE,
214 },
215 {
Michal Simek67a5efa2023-01-18 09:25:26 +0100216 .id = 0x04712093,
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200217 .device = 24,
218 .variants = 0,
219 },
220 {
221 .id = 0x04724093,
222 .device = 26,
223 .variants = 0,
224 },
225};
226
227static const struct zynqmp_device *zynqmp_get_device(u32 idcode)
228{
229 idcode &= IDCODE_DEV_TYPE_MASK;
230
231 for (int i = 0; i < ARRAY_SIZE(zynqmp_devices); i++) {
232 if (zynqmp_devices[i].id == idcode)
233 return &zynqmp_devices[i];
234 }
235
236 return NULL;
237}
238
239static int soc_xilinx_zynqmp_detect_machine(struct udevice *dev, u32 idcode,
240 u32 idcode2)
241{
242 struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
243 const struct zynqmp_device *device;
244 int ret;
245
246 device = zynqmp_get_device(idcode);
247 if (!device)
248 return 0;
249
250 /* Add device prefix to the name */
251 ret = snprintf(priv->machine, sizeof(priv->machine), "%s%d",
252 device->variants ? "zu" : "xck", device->device);
253 if (ret < 0)
254 return ret;
255
256 if (device->variants & ZYNQMP_VARIANT_EV) {
257 /* Devices with EV variant might be EG/CG/EV family */
258 if (idcode2 & IDCODE2_PL_INIT_MASK) {
259 u32 family = ((idcode2 & EFUSE_VCU_DIS_MASK) >>
260 EFUSE_VCU_DIS_SHIFT) << 1 |
261 ((idcode2 & EFUSE_GPU_DIS_MASK) >>
262 EFUSE_GPU_DIS_SHIFT);
263
264 /*
265 * Get family name based on extended idcode values as
266 * determined on UG1087, EXTENDED_IDCODE register
267 * description
268 */
269 switch (family) {
270 case 0x00:
271 strlcat(priv->machine, "ev",
272 sizeof(priv->machine));
273 break;
274 case 0x10:
275 strlcat(priv->machine, "eg",
276 sizeof(priv->machine));
277 break;
278 case 0x11:
279 strlcat(priv->machine, "cg",
280 sizeof(priv->machine));
281 break;
282 default:
283 /* Do not append family name*/
284 break;
285 }
286 } else {
287 /*
288 * When PL powered down the VCU Disable efuse cannot be
289 * read. So, ignore the bit and just findout if it is CG
290 * or EG/EV variant.
291 */
292 strlcat(priv->machine, (idcode2 & EFUSE_GPU_DIS_MASK) ?
293 "cg" : "e", sizeof(priv->machine));
294 }
295 } else if (device->variants & ZYNQMP_VARIANT_CG) {
296 /* Devices with CG variant might be EG or CG family */
297 strlcat(priv->machine, (idcode2 & EFUSE_GPU_DIS_MASK) ?
298 "cg" : "eg", sizeof(priv->machine));
299 } else if (device->variants & ZYNQMP_VARIANT_EG) {
300 strlcat(priv->machine, "eg", sizeof(priv->machine));
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530301 } else if (device->variants & ZYNQMP_VARIANT_EG_SE) {
302 strlcat(priv->machine, "eg_SE", sizeof(priv->machine));
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200303 } else if (device->variants & ZYNQMP_VARIANT_DR) {
304 strlcat(priv->machine, "dr", sizeof(priv->machine));
Venkatesh Yadav Abbarapu55136382024-01-23 10:27:15 +0530305 } else if (device->variants & ZYNQMP_VARIANT_DR_SE) {
306 strlcat(priv->machine, "dr_SE", sizeof(priv->machine));
Venkatesh Yadav Abbarapu2175b042024-04-02 19:53:14 +0530307 } else if (device->variants & ZYNQMP_VARIANT_TEG) {
308 strlcat(priv->machine, "teg", sizeof(priv->machine));
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200309 }
310
311 return 0;
312}
313
T Karthik Reddy501c2062021-08-10 06:50:18 -0600314static int soc_xilinx_zynqmp_get_family(struct udevice *dev, char *buf, int size)
315{
316 struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
317
318 return snprintf(buf, size, "%s", priv->family);
319}
320
Venkatesh Yadav Abbarapuf35f9572022-10-04 11:22:01 +0530321static int soc_xilinx_zynqmp_get_machine(struct udevice *dev, char *buf, int size)
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200322{
323 struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
324 const char *machine = priv->machine;
325
326 if (!machine[0])
327 machine = "unknown";
328
329 return snprintf(buf, size, "%s", machine);
330}
331
T Karthik Reddy501c2062021-08-10 06:50:18 -0600332static int soc_xilinx_zynqmp_get_revision(struct udevice *dev, char *buf, int size)
333{
334 struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
335
336 return snprintf(buf, size, "v%d", priv->revision);
337}
338
339static const struct soc_ops soc_xilinx_zynqmp_ops = {
340 .get_family = soc_xilinx_zynqmp_get_family,
341 .get_revision = soc_xilinx_zynqmp_get_revision,
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200342 .get_machine = soc_xilinx_zynqmp_get_machine,
T Karthik Reddy501c2062021-08-10 06:50:18 -0600343};
344
345static int soc_xilinx_zynqmp_probe(struct udevice *dev)
346{
347 struct soc_xilinx_zynqmp_priv *priv = dev_get_priv(dev);
Michal Simekab51e372022-04-20 09:39:04 +0200348 u32 ret_payload[PAYLOAD_ARG_CNT];
T Karthik Reddy501c2062021-08-10 06:50:18 -0600349 int ret;
350
351 priv->family = zynqmp_family;
352
Stefan Herbrechtsmeier4f2aeb42022-06-20 18:36:42 +0200353 if (!IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE))
T Karthik Reddy501c2062021-08-10 06:50:18 -0600354 ret = zynqmp_mmio_read(ZYNQMP_PS_VERSION, &ret_payload[2]);
355 else
356 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
357 ret_payload);
358 if (ret < 0)
359 return ret;
360
361 priv->revision = ret_payload[2] & ZYNQMP_PS_VER_MASK;
362
Stefan Herbrechtsmeier3ff3bd42022-06-20 18:36:43 +0200363 if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
364 /*
365 * Firmware returns:
366 * payload[0][31:0] = status of the operation
367 * payload[1] = IDCODE
368 * payload[2][19:0] = Version
369 * payload[2][28:20] = EXTENDED_IDCODE
370 * payload[2][29] = PL_INIT
371 */
372 u32 idcode = ret_payload[1];
373 u32 idcode2 = ret_payload[2] >>
374 ZYNQMP_CSU_VERSION_EMPTY_SHIFT;
375 dev_dbg(dev, "IDCODE: 0x%0x, IDCODE2: 0x%0x\n", idcode,
376 idcode2);
377
378 ret = soc_xilinx_zynqmp_detect_machine(dev, idcode, idcode2);
379 if (ret)
380 return ret;
381 }
382
T Karthik Reddy501c2062021-08-10 06:50:18 -0600383 return 0;
384}
385
386U_BOOT_DRIVER(soc_xilinx_zynqmp) = {
387 .name = "soc_xilinx_zynqmp",
388 .id = UCLASS_SOC,
389 .ops = &soc_xilinx_zynqmp_ops,
390 .probe = soc_xilinx_zynqmp_probe,
391 .priv_auto = sizeof(struct soc_xilinx_zynqmp_priv),
392 .flags = DM_FLAG_PRE_RELOC,
393};