blob: 8507da0bd228fa0e1c55d3e1fb50a54c3e93a005 [file] [log] [blame]
Michal Simek34d35122024-05-29 16:47:59 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * AMD Versal Gen 2 SOC driver
4 *
5 * Copyright (C) 2022 - 2024, Advanced Micro Devices, Inc.
6 */
7
8#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#include <linux/bitfield.h>
15
16/*
17 * v1 -> 0x10 - ES1
18 * v2 -> 0x20 - Production
19 */
20static const char versal2_family[] = "Versal Gen 2";
21
22struct soc_amd_versal2_priv {
23 const char *family;
24 char revision;
25};
26
27static int soc_amd_versal2_get_family(struct udevice *dev, char *buf, int size)
28{
29 struct soc_amd_versal2_priv *priv = dev_get_priv(dev);
30
31 return snprintf(buf, size, "%s", priv->family);
32}
33
34static int soc_amd_versal2_get_revision(struct udevice *dev, char *buf, int size)
35{
36 struct soc_amd_versal2_priv *priv = dev_get_priv(dev);
37
Michal Simekc70fee32025-02-18 13:43:07 +010038 return snprintf(buf, size, "v%d.%d",
39 (u32)FIELD_GET(PS_VERSION_MAJOR, priv->revision),
40 (u32)FIELD_GET(PS_VERSION_MINOR, priv->revision));
Michal Simek34d35122024-05-29 16:47:59 +020041}
42
43static const struct soc_ops soc_amd_versal2_ops = {
44 .get_family = soc_amd_versal2_get_family,
45 .get_revision = soc_amd_versal2_get_revision,
46};
47
48static int soc_amd_versal2_probe(struct udevice *dev)
49{
50 struct soc_amd_versal2_priv *priv = dev_get_priv(dev);
51 u32 ret_payload[PAYLOAD_ARG_CNT];
52 int ret;
53
54 priv->family = versal2_family;
55
56 if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
57 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
58 ret_payload);
59 if (ret)
60 return ret;
61 } else {
62 ret_payload[2] = readl(PMC_TAP_VERSION);
63 if (!ret_payload[2])
64 return -EINVAL;
65 }
66
67 priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
68
69 return 0;
70}
71
72U_BOOT_DRIVER(soc_amd_versal2) = {
73 .name = "soc_amd_versal2",
74 .id = UCLASS_SOC,
75 .ops = &soc_amd_versal2_ops,
76 .probe = soc_amd_versal2_probe,
77 .priv_auto = sizeof(struct soc_amd_versal2_priv),
78 .flags = DM_FLAG_PRE_RELOC,
79};