T Karthik Reddy | 42e20f5 | 2021-08-10 06:50:19 -0600 | [diff] [blame] | 1 | // 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 | */ |
| 19 | static const char versal_family[] = "Versal"; |
| 20 | |
| 21 | struct soc_xilinx_versal_priv { |
| 22 | const char *family; |
| 23 | char revision; |
| 24 | }; |
| 25 | |
| 26 | static 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 | |
| 33 | static 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 | |
| 40 | static 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 | |
| 45 | static int soc_xilinx_versal_probe(struct udevice *dev) |
| 46 | { |
| 47 | struct soc_xilinx_versal_priv *priv = dev_get_priv(dev); |
Jorge Ramirez-Ortiz | 9b31e10 | 2022-04-16 20:15:30 +0200 | [diff] [blame] | 48 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
T Karthik Reddy | 42e20f5 | 2021-08-10 06:50:19 -0600 | [diff] [blame] | 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 | |
| 69 | U_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 | }; |