2 * Copyright (c) 2013 Google, Inc
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0+
15 #include <dm/device.h>
16 #include <dm/device-internal.h>
18 #include <dm/platdata.h>
20 #include <dm/uclass.h>
22 #include <linux/list.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 static const struct driver_info root_info = {
27 .name = "root_driver",
30 struct udevice *dm_root(void)
33 dm_warn("Virtual root driver does not exist!\n");
45 dm_warn("Virtual root driver already exists!\n");
48 INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
50 ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
53 #ifdef CONFIG_OF_CONTROL
54 DM_ROOT_NON_CONST->of_offset = 0;
56 ret = device_probe(DM_ROOT_NON_CONST);
65 device_remove(dm_root());
66 device_unbind(dm_root());
71 int dm_scan_platdata(bool pre_reloc_only)
75 ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only);
77 dm_warn("Some drivers were not found\n");
84 #ifdef CONFIG_OF_CONTROL
85 int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset,
90 for (offset = fdt_first_subnode(blob, offset);
92 offset = fdt_next_subnode(blob, offset)) {
94 !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
96 if (!fdtdec_get_is_enabled(blob, offset)) {
97 dm_dbg(" - ignoring disabled device\n");
100 err = lists_bind_fdt(parent, blob, offset, NULL);
106 dm_warn("Some drivers failed to bind\n");
111 int dm_scan_fdt(const void *blob, bool pre_reloc_only)
113 return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
117 __weak int dm_scan_other(bool pre_reloc_only)
122 int dm_init_and_scan(bool pre_reloc_only)
128 debug("dm_init() failed: %d\n", ret);
131 ret = dm_scan_platdata(pre_reloc_only);
133 debug("dm_scan_platdata() failed: %d\n", ret);
136 #ifdef CONFIG_OF_CONTROL
137 ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only);
139 debug("dm_scan_fdt() failed: %d\n", ret);
143 ret = dm_scan_other(pre_reloc_only);
150 /* This is the root driver - all drivers are children of this */
151 U_BOOT_DRIVER(root_driver) = {
152 .name = "root_driver",
156 /* This is the root uclass */
157 UCLASS_DRIVER(root) = {