T Karthik Reddy | cb8485b | 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 | |
T Karthik Reddy | cb8485b | 2021-08-10 06:50:19 -0600 | [diff] [blame] | 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 | /* |
| 15 | * v1 -> 0x10 - ES1 |
| 16 | * v2 -> 0x20 - Production |
| 17 | */ |
| 18 | static const char versal_family[] = "Versal"; |
| 19 | |
| 20 | struct soc_xilinx_versal_priv { |
| 21 | const char *family; |
| 22 | char revision; |
| 23 | }; |
| 24 | |
| 25 | static int soc_xilinx_versal_get_family(struct udevice *dev, char *buf, int size) |
| 26 | { |
| 27 | struct soc_xilinx_versal_priv *priv = dev_get_priv(dev); |
| 28 | |
| 29 | return snprintf(buf, size, "%s", priv->family); |
| 30 | } |
| 31 | |
| 32 | static int soc_xilinx_versal_get_revision(struct udevice *dev, char *buf, int size) |
| 33 | { |
| 34 | struct soc_xilinx_versal_priv *priv = dev_get_priv(dev); |
| 35 | |
| 36 | return snprintf(buf, size, "v%d", priv->revision); |
| 37 | } |
| 38 | |
| 39 | static const struct soc_ops soc_xilinx_versal_ops = { |
| 40 | .get_family = soc_xilinx_versal_get_family, |
| 41 | .get_revision = soc_xilinx_versal_get_revision, |
| 42 | }; |
| 43 | |
| 44 | static int soc_xilinx_versal_probe(struct udevice *dev) |
| 45 | { |
| 46 | struct soc_xilinx_versal_priv *priv = dev_get_priv(dev); |
Jorge Ramirez-Ortiz | 4b19cb1 | 2022-04-16 20:15:30 +0200 | [diff] [blame] | 47 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
T Karthik Reddy | cb8485b | 2021-08-10 06:50:19 -0600 | [diff] [blame] | 48 | int ret; |
| 49 | |
| 50 | priv->family = versal_family; |
| 51 | |
| 52 | if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) { |
| 53 | ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0, |
| 54 | ret_payload); |
| 55 | if (ret) |
| 56 | return ret; |
| 57 | } else { |
| 58 | ret_payload[2] = readl(VERSAL_PS_PMC_VERSION); |
| 59 | if (!ret_payload[2]) |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
| 63 | priv->revision = ret_payload[2] >> VERSAL_PS_VER_SHIFT; |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | U_BOOT_DRIVER(soc_xilinx_versal) = { |
| 69 | .name = "soc_xilinx_versal", |
| 70 | .id = UCLASS_SOC, |
| 71 | .ops = &soc_xilinx_versal_ops, |
| 72 | .probe = soc_xilinx_versal_probe, |
| 73 | .priv_auto = sizeof(struct soc_xilinx_versal_priv), |
| 74 | .flags = DM_FLAG_PRE_RELOC, |
| 75 | }; |