blob: 7427f8432c8b8f8043e2385ae6648d28253c30bd [file] [log] [blame]
T Karthik Reddycb8485b2021-08-10 06:50:19 -06001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx Versal SOC driver
4 *
5 * Copyright (C) 2021 Xilinx, Inc.
6 */
7
T Karthik Reddycb8485b2021-08-10 06:50:19 -06008#include <dm.h>
9#include <soc.h>
10#include <zynqmp_firmware.h>
11#include <asm/io.h>
12#include <asm/arch/hardware.h>
13
14/*
15 * v1 -> 0x10 - ES1
16 * v2 -> 0x20 - Production
17 */
18static const char versal_family[] = "Versal";
19
20struct soc_xilinx_versal_priv {
21 const char *family;
22 char revision;
23};
24
25static int soc_xilinx_versal_get_family(struct udevice *dev, char *buf, int size)
26{
27 struct soc_xilinx_versal_priv *priv = dev_get_priv(dev);
28
29 return snprintf(buf, size, "%s", priv->family);
30}
31
32static int soc_xilinx_versal_get_revision(struct udevice *dev, char *buf, int size)
33{
34 struct soc_xilinx_versal_priv *priv = dev_get_priv(dev);
35
36 return snprintf(buf, size, "v%d", priv->revision);
37}
38
39static const struct soc_ops soc_xilinx_versal_ops = {
40 .get_family = soc_xilinx_versal_get_family,
41 .get_revision = soc_xilinx_versal_get_revision,
42};
43
44static int soc_xilinx_versal_probe(struct udevice *dev)
45{
46 struct soc_xilinx_versal_priv *priv = dev_get_priv(dev);
Jorge Ramirez-Ortiz4b19cb12022-04-16 20:15:30 +020047 u32 ret_payload[PAYLOAD_ARG_CNT];
T Karthik Reddycb8485b2021-08-10 06:50:19 -060048 int ret;
49
50 priv->family = versal_family;
51
52 if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
53 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
54 ret_payload);
55 if (ret)
56 return ret;
57 } else {
58 ret_payload[2] = readl(VERSAL_PS_PMC_VERSION);
59 if (!ret_payload[2])
60 return -EINVAL;
61 }
62
63 priv->revision = ret_payload[2] >> VERSAL_PS_VER_SHIFT;
64
65 return 0;
66}
67
68U_BOOT_DRIVER(soc_xilinx_versal) = {
69 .name = "soc_xilinx_versal",
70 .id = UCLASS_SOC,
71 .ops = &soc_xilinx_versal_ops,
72 .probe = soc_xilinx_versal_probe,
73 .priv_auto = sizeof(struct soc_xilinx_versal_priv),
74 .flags = DM_FLAG_PRE_RELOC,
75};