2 * Copyright (c) 2013 Google, Inc
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0+
14 #include <dm/device.h>
15 #include <dm/device-internal.h>
17 #include <dm/platdata.h>
19 #include <dm/uclass.h>
21 #include <linux/list.h>
23 DECLARE_GLOBAL_DATA_PTR;
25 static const struct driver_info root_info = {
26 .name = "root_driver",
29 struct udevice *dm_root(void)
32 dm_warn("Virtual root driver does not exist!\n");
44 dm_warn("Virtual root driver already exists!\n");
47 INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
49 ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
52 ret = device_probe(DM_ROOT_NON_CONST);
61 device_remove(dm_root());
62 device_unbind(dm_root());
67 int dm_scan_platdata(bool pre_reloc_only)
71 ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only);
73 dm_warn("Some drivers were not found\n");
82 #ifdef CONFIG_OF_CONTROL
83 int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset,
88 for (offset = fdt_first_subnode(blob, offset);
90 offset = fdt_next_subnode(blob, offset)) {
92 !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
94 err = lists_bind_fdt(parent, blob, offset);
100 dm_warn("Some drivers failed to bind\n");
105 int dm_scan_fdt(const void *blob, bool pre_reloc_only)
107 return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
111 __weak int dm_scan_other(bool pre_reloc_only)
116 int dm_init_and_scan(bool pre_reloc_only)
122 debug("dm_init() failed: %d\n", ret);
125 ret = dm_scan_platdata(pre_reloc_only);
127 debug("dm_scan_platdata() failed: %d\n", ret);
130 #ifdef CONFIG_OF_CONTROL
131 ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only);
133 debug("dm_scan_fdt() failed: %d\n", ret);
137 ret = dm_scan_other(pre_reloc_only);
144 /* This is the root driver - all drivers are children of this */
145 U_BOOT_DRIVER(root_driver) = {
146 .name = "root_driver",
150 /* This is the root uclass */
151 UCLASS_DRIVER(root) = {