Michal Simek | 34d3512 | 2024-05-29 16:47:59 +0200 | [diff] [blame] | 1 | // 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 | */ |
| 20 | static const char versal2_family[] = "Versal Gen 2"; |
| 21 | |
| 22 | struct soc_amd_versal2_priv { |
| 23 | const char *family; |
| 24 | char revision; |
| 25 | }; |
| 26 | |
| 27 | static 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 | |
| 34 | static 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 | |
| 38 | return snprintf(buf, size, "v%d", priv->revision); |
| 39 | } |
| 40 | |
| 41 | static const struct soc_ops soc_amd_versal2_ops = { |
| 42 | .get_family = soc_amd_versal2_get_family, |
| 43 | .get_revision = soc_amd_versal2_get_revision, |
| 44 | }; |
| 45 | |
| 46 | static int soc_amd_versal2_probe(struct udevice *dev) |
| 47 | { |
| 48 | struct soc_amd_versal2_priv *priv = dev_get_priv(dev); |
| 49 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 50 | int ret; |
| 51 | |
| 52 | priv->family = versal2_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 | |
| 70 | U_BOOT_DRIVER(soc_amd_versal2) = { |
| 71 | .name = "soc_amd_versal2", |
| 72 | .id = UCLASS_SOC, |
| 73 | .ops = &soc_amd_versal2_ops, |
| 74 | .probe = soc_amd_versal2_probe, |
| 75 | .priv_auto = sizeof(struct soc_amd_versal2_priv), |
| 76 | .flags = DM_FLAG_PRE_RELOC, |
| 77 | }; |