soc_xilinx_versal_net.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #include <common.h>
  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. #include <linux/bitfield.h>
  14. /*
  15. * v1 -> 0x10 - ES1
  16. * v2 -> 0x20 - Production
  17. */
  18. static const char versal_family[] = "Versal NET";
  19. struct soc_xilinx_versal_net_priv {
  20. const char *family;
  21. char revision;
  22. };
  23. static int soc_xilinx_versal_net_get_family(struct udevice *dev, char *buf, int size)
  24. {
  25. struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
  26. return snprintf(buf, size, "%s", priv->family);
  27. }
  28. static int soc_xilinx_versal_net_get_revision(struct udevice *dev, char *buf, int size)
  29. {
  30. struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
  31. return snprintf(buf, size, "v%d", priv->revision);
  32. }
  33. static const struct soc_ops soc_xilinx_versal_net_ops = {
  34. .get_family = soc_xilinx_versal_net_get_family,
  35. .get_revision = soc_xilinx_versal_net_get_revision,
  36. };
  37. static int soc_xilinx_versal_net_probe(struct udevice *dev)
  38. {
  39. struct soc_xilinx_versal_net_priv *priv = dev_get_priv(dev);
  40. u32 ret_payload[PAYLOAD_ARG_CNT];
  41. int ret;
  42. priv->family = versal_family;
  43. if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE)) {
  44. ret = xilinx_pm_request(PM_GET_CHIPID, 0, 0, 0, 0,
  45. ret_payload);
  46. if (ret)
  47. return ret;
  48. } else {
  49. ret_payload[2] = readl(PMC_TAP_VERSION);
  50. if (!ret_payload[2])
  51. return -EINVAL;
  52. }
  53. priv->revision = FIELD_GET(PS_VERSION_MASK, ret_payload[2]);
  54. return 0;
  55. }
  56. U_BOOT_DRIVER(soc_xilinx_versal_net) = {
  57. .name = "soc_xilinx_versal_net",
  58. .id = UCLASS_SOC,
  59. .ops = &soc_xilinx_versal_net_ops,
  60. .probe = soc_xilinx_versal_net_probe,
  61. .priv_auto = sizeof(struct soc_xilinx_versal_net_priv),
  62. .flags = DM_FLAG_PRE_RELOC,
  63. };