gdsys_soc.c 1.6 KB

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