blob: f8bcd9ab404d4561e7b7a0f2a31bea40a5f791bb [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);
48 u32 ret_payload[4];
49 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};