gdsys_soc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2017
  4. * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <log.h>
  9. #include <dm/lists.h>
  10. #include "gdsys_soc.h"
  11. /**
  12. * struct gdsys_soc_priv - Private data for gdsys soc bus
  13. * @fpga: The gdsys IHS FPGA this bus is associated with
  14. */
  15. struct gdsys_soc_priv {
  16. struct udevice *fpga;
  17. };
  18. static const struct udevice_id gdsys_soc_ids[] = {
  19. { .compatible = "gdsys,soc" },
  20. { /* sentinel */ }
  21. };
  22. int gdsys_soc_get_fpga(struct udevice *child, struct udevice **fpga)
  23. {
  24. struct gdsys_soc_priv *bus_priv;
  25. if (!child->parent) {
  26. debug("%s: Invalid parent\n", child->name);
  27. return -EINVAL;
  28. }
  29. if (!device_is_compatible(child->parent, "gdsys,soc")) {
  30. debug("%s: Not child of a gdsys soc\n", child->name);
  31. return -EINVAL;
  32. }
  33. bus_priv = dev_get_priv(child->parent);
  34. *fpga = bus_priv->fpga;
  35. return 0;
  36. }
  37. static int gdsys_soc_probe(struct udevice *dev)
  38. {
  39. struct gdsys_soc_priv *priv = dev_get_priv(dev);
  40. struct udevice *fpga;
  41. int res = uclass_get_device_by_phandle(UCLASS_MISC, dev, "fpga",
  42. &fpga);
  43. if (res == -ENOENT) {
  44. debug("%s: Could not find 'fpga' phandle\n", dev->name);
  45. return -EINVAL;
  46. }
  47. if (res == -ENODEV) {
  48. debug("%s: Could not get FPGA device\n", dev->name);
  49. return -EINVAL;
  50. }
  51. priv->fpga = fpga;
  52. return 0;
  53. }
  54. U_BOOT_DRIVER(gdsys_soc_bus) = {
  55. .name = "gdsys_soc_bus",
  56. .id = UCLASS_SIMPLE_BUS,
  57. .of_match = gdsys_soc_ids,
  58. .probe = gdsys_soc_probe,
  59. .priv_auto_alloc_size = sizeof(struct gdsys_soc_priv),
  60. };