root.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/uclass.h>
  18. #include <dm/util.h>
  19. #include <linux/list.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. static const struct driver_info root_info = {
  22. .name = "root_driver",
  23. };
  24. struct udevice *dm_root(void)
  25. {
  26. if (!gd->dm_root) {
  27. dm_warn("Virtual root driver does not exist!\n");
  28. return NULL;
  29. }
  30. return gd->dm_root;
  31. }
  32. int dm_init(void)
  33. {
  34. int ret;
  35. if (gd->dm_root) {
  36. dm_warn("Virtual root driver already exists!\n");
  37. return -EINVAL;
  38. }
  39. INIT_LIST_HEAD(&gd->uclass_root);
  40. ret = device_bind_by_name(NULL, &root_info, &gd->dm_root);
  41. if (ret)
  42. return ret;
  43. return 0;
  44. }
  45. int dm_scan_platdata(void)
  46. {
  47. int ret;
  48. ret = lists_bind_drivers(gd->dm_root);
  49. if (ret == -ENOENT) {
  50. dm_warn("Some drivers were not found\n");
  51. ret = 0;
  52. }
  53. if (ret)
  54. return ret;
  55. return 0;
  56. }
  57. #ifdef CONFIG_OF_CONTROL
  58. int dm_scan_fdt(const void *blob)
  59. {
  60. int offset = 0;
  61. int ret = 0, err;
  62. int depth = 0;
  63. do {
  64. offset = fdt_next_node(blob, offset, &depth);
  65. if (offset > 0 && depth == 1) {
  66. err = lists_bind_fdt(gd->dm_root, blob, offset);
  67. if (err && !ret)
  68. ret = err;
  69. }
  70. } while (offset > 0);
  71. if (ret)
  72. dm_warn("Some drivers failed to bind\n");
  73. return ret;
  74. }
  75. #endif
  76. /* This is the root driver - all drivers are children of this */
  77. U_BOOT_DRIVER(root_driver) = {
  78. .name = "root_driver",
  79. .id = UCLASS_ROOT,
  80. };
  81. /* This is the root uclass */
  82. UCLASS_DRIVER(root) = {
  83. .name = "root",
  84. .id = UCLASS_ROOT,
  85. };