video: ivybridge: Use mtrr_set_next_var() for graphics memory
[platform/kernel/u-boot.git] / drivers / soc / soc_xilinx_versal_net.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Xilinx Versal NET SOC driver
4  *
5  * Copyright (C) 2022, Advanced Micro Devices, 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 #include <linux/bitfield.h>
16
17 /*
18  * v1 -> 0x10 - ES1
19  * v2 -> 0x20 - Production
20  */
21 static const char versal_family[] = "Versal NET";
22
23 struct soc_xilinx_versal_net_priv {
24         const char *family;
25         char revision;
26 };
27
28 static int soc_xilinx_versal_net_get_family(struct udevice *dev, char *buf, int size)
29 {
30         struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
31
32         return snprintf(buf, size, "%s", priv->family);
33 }
34
35 static int soc_xilinx_versal_net_get_revision(struct udevice *dev, char *buf, int size)
36 {
37         struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
38
39         return snprintf(buf, size, "v%d", priv->revision);
40 }
41
42 static const struct soc_ops soc_xilinx_versal_net_ops = {
43         .get_family = soc_xilinx_versal_net_get_family,
44         .get_revision = soc_xilinx_versal_net_get_revision,
45 };
46
47 static int soc_xilinx_versal_net_probe(struct udevice *dev)
48 {
49         struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
50         u32 ret_payload[PAYLOAD_ARG_CNT];
51         int ret;
52
53         priv->family = versal_family;
54
55         if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
56                 ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
57                                         ret_payload);
58                 if (ret)
59                         return ret;
60         } else {
61                 ret_payload[2] = readl(PMC_TAP_VERSION);
62                 if (!ret_payload[2])
63                         return -EINVAL;
64         }
65
66         priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
67
68         return 0;
69 }
70
71 U_BOOT_DRIVER(soc_xilinx_versal_net) = {
72         .name           = "soc_xilinx_versal_net",
73         .id             = UCLASS_SOC,
74         .ops            = &soc_xilinx_versal_net_ops,
75         .probe          = soc_xilinx_versal_net_probe,
76         .priv_auto      = sizeof(struct soc_xilinx_versal_net_priv),
77         .flags          = DM_FLAG_PRE_RELOC,
78 };