root.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2013 Google, Inc
  3. *
  4. * (C) Copyright 2012
  5. * Pavel Herrmann <morpheus.ibis@gmail.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <errno.h>
  11. #include <malloc.h>
  12. #include <libfdt.h>
  13. #include <dm/device.h>
  14. #include <dm/device-internal.h>
  15. #include <dm/lists.h>
  16. #include <dm/platdata.h>
  17. #include <dm/root.h>
  18. #include <dm/uclass.h>
  19. #include <dm/util.h>
  20. #include <linux/list.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. static const struct driver_info root_info = {
  23. .name = "root_driver",
  24. };
  25. struct udevice *dm_root(void)
  26. {
  27. if (!gd->dm_root) {
  28. dm_warn("Virtual root driver does not exist!\n");
  29. return NULL;
  30. }
  31. return gd->dm_root;
  32. }
  33. int dm_init(void)
  34. {
  35. int ret;
  36. if (gd->dm_root) {
  37. dm_warn("Virtual root driver already exists!\n");
  38. return -EINVAL;
  39. }
  40. INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
  41. ret = device_bind_by_name(NULL, &root_info, &DM_ROOT_NON_CONST);
  42. if (ret)
  43. return ret;
  44. return 0;
  45. }
  46. int dm_scan_platdata(void)
  47. {
  48. int ret;
  49. ret = lists_bind_drivers(DM_ROOT_NON_CONST);
  50. if (ret == -ENOENT) {
  51. dm_warn("Some drivers were not found\n");
  52. ret = 0;
  53. }
  54. if (ret)
  55. return ret;
  56. return 0;
  57. }
  58. #ifdef CONFIG_OF_CONTROL
  59. int dm_scan_fdt(const void *blob)
  60. {
  61. int offset = 0;
  62. int ret = 0, err;
  63. int depth = 0;
  64. do {
  65. offset = fdt_next_node(blob, offset, &depth);
  66. if (offset > 0 && depth == 1) {
  67. err = lists_bind_fdt(gd->dm_root, blob, offset);
  68. if (err && !ret)
  69. ret = err;
  70. }
  71. } while (offset > 0);
  72. if (ret)
  73. dm_warn("Some drivers failed to bind\n");
  74. return ret;
  75. }
  76. #endif
  77. /* This is the root driver - all drivers are children of this */
  78. U_BOOT_DRIVER(root_driver) = {
  79. .name = "root_driver",
  80. .id = UCLASS_ROOT,
  81. };
  82. /* This is the root uclass */
  83. UCLASS_DRIVER(root) = {
  84. .name = "root",
  85. .id = UCLASS_ROOT,
  86. };