blob: d64fc366a6d10b12152e25e3aacfd7618406685c [file] [log] [blame]
Michal Simekafcb6402022-11-16 16:36:35 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Xilinx Versal NET SOC driver
4 *
5 * Copyright (C) 2022, Advanced Micro Devices, Inc.
6 */
7
Michal Simekafcb6402022-11-16 16:36:35 +01008#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 versal_family[] = "Versal NET";
21
22struct soc_xilinx_versal_net_priv {
23 const char *family;
24 char revision;
25};
26
27static int soc_xilinx_versal_net_get_family(struct udevice *dev, char *buf, int size)
28{
29 struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
30
31 return snprintf(buf, size, "%s", priv->family);
32}
33
34static int soc_xilinx_versal_net_get_revision(struct udevice *dev, char *buf, int size)
35{
36 struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
37
38 return snprintf(buf, size, "v%d", priv->revision);
39}
40
41static const struct soc_ops soc_xilinx_versal_net_ops = {
42 .get_family = soc_xilinx_versal_net_get_family,
43 .get_revision = soc_xilinx_versal_net_get_revision,
44};
45
46static int soc_xilinx_versal_net_probe(struct udevice *dev)
47{
48 struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
49 u32 ret_payload[PAYLOAD_ARG_CNT];
50 int ret;
51
52 priv->family = versal_family;
53
54 if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
55 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
56 ret_payload);
57 if (ret)
58 return ret;
59 } else {
60 ret_payload[2] = readl(PMC_TAP_VERSION);
61 if (!ret_payload[2])
62 return -EINVAL;
63 }
64
65 priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
66
67 return 0;
68}
69
70U_BOOT_DRIVER(soc_xilinx_versal_net) = {
71 .name = "soc_xilinx_versal_net",
72 .id = UCLASS_SOC,
73 .ops = &soc_xilinx_versal_net_ops,
74 .probe = soc_xilinx_versal_net_probe,
75 .priv_auto = sizeof(struct soc_xilinx_versal_net_priv),
76 .flags = DM_FLAG_PRE_RELOC,
77};