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