root.c 1.7 KB

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