]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/core/root.c
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");
40 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
41 void fix_drivers(void)
44 ll_entry_start(struct driver
, driver
);
45 const int n_ents
= ll_entry_count(struct driver
, driver
);
48 for (entry
= drv
; entry
!= drv
+ n_ents
; entry
++) {
50 entry
->of_match
= (const struct udevice_id
*)
51 ((u32
)entry
->of_match
+ gd
->reloc_off
);
53 entry
->bind
+= gd
->reloc_off
;
55 entry
->probe
+= gd
->reloc_off
;
57 entry
->remove
+= gd
->reloc_off
;
59 entry
->unbind
+= gd
->reloc_off
;
60 if (entry
->ofdata_to_platdata
)
61 entry
->ofdata_to_platdata
+= gd
->reloc_off
;
62 if (entry
->child_post_bind
)
63 entry
->child_post_bind
+= gd
->reloc_off
;
64 if (entry
->child_pre_probe
)
65 entry
->child_pre_probe
+= gd
->reloc_off
;
66 if (entry
->child_post_remove
)
67 entry
->child_post_remove
+= gd
->reloc_off
;
68 /* OPS are fixed in every uclass post_probe function */
70 entry
->ops
+= gd
->reloc_off
;
76 struct uclass_driver
*uclass
=
77 ll_entry_start(struct uclass_driver
, uclass
);
78 const int n_ents
= ll_entry_count(struct uclass_driver
, uclass
);
79 struct uclass_driver
*entry
;
81 for (entry
= uclass
; entry
!= uclass
+ n_ents
; entry
++) {
83 entry
->post_bind
+= gd
->reloc_off
;
84 if (entry
->pre_unbind
)
85 entry
->pre_unbind
+= gd
->reloc_off
;
87 entry
->pre_probe
+= gd
->reloc_off
;
88 if (entry
->post_probe
)
89 entry
->post_probe
+= gd
->reloc_off
;
90 if (entry
->pre_remove
)
91 entry
->pre_remove
+= gd
->reloc_off
;
92 if (entry
->child_post_bind
)
93 entry
->child_post_bind
+= gd
->reloc_off
;
94 if (entry
->child_pre_probe
)
95 entry
->child_pre_probe
+= gd
->reloc_off
;
97 entry
->init
+= gd
->reloc_off
;
99 entry
->destroy
+= gd
->reloc_off
;
100 /* FIXME maybe also need to fix these ops */
102 entry
->ops
+= gd
->reloc_off
;
112 dm_warn("Virtual root driver already exists!\n");
115 INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST
);
117 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
122 ret
= device_bind_by_name(NULL
, false, &root_info
, &DM_ROOT_NON_CONST
);
125 #if CONFIG_IS_ENABLED(OF_CONTROL)
126 DM_ROOT_NON_CONST
->of_offset
= 0;
128 ret
= device_probe(DM_ROOT_NON_CONST
);
137 device_remove(dm_root());
138 device_unbind(dm_root());
143 int dm_scan_platdata(bool pre_reloc_only
)
147 ret
= lists_bind_drivers(DM_ROOT_NON_CONST
, pre_reloc_only
);
148 if (ret
== -ENOENT
) {
149 dm_warn("Some drivers were not found\n");
156 #if CONFIG_IS_ENABLED(OF_CONTROL)
157 int dm_scan_fdt_node(struct udevice
*parent
, const void *blob
, int offset
,
162 for (offset
= fdt_first_subnode(blob
, offset
);
164 offset
= fdt_next_subnode(blob
, offset
)) {
165 if (pre_reloc_only
&&
166 !fdt_getprop(blob
, offset
, "u-boot,dm-pre-reloc", NULL
))
168 if (!fdtdec_get_is_enabled(blob
, offset
)) {
169 dm_dbg(" - ignoring disabled device\n");
172 err
= lists_bind_fdt(parent
, blob
, offset
, NULL
);
175 debug("%s: ret=%d\n", fdt_get_name(blob
, offset
, NULL
),
181 dm_warn("Some drivers failed to bind\n");
186 int dm_scan_fdt(const void *blob
, bool pre_reloc_only
)
188 return dm_scan_fdt_node(gd
->dm_root
, blob
, 0, pre_reloc_only
);
192 __weak
int dm_scan_other(bool pre_reloc_only
)
197 int dm_init_and_scan(bool pre_reloc_only
)
203 debug("dm_init() failed: %d\n", ret
);
206 ret
= dm_scan_platdata(pre_reloc_only
);
208 debug("dm_scan_platdata() failed: %d\n", ret
);
212 if (CONFIG_IS_ENABLED(OF_CONTROL
)) {
213 ret
= dm_scan_fdt(gd
->fdt_blob
, pre_reloc_only
);
215 debug("dm_scan_fdt() failed: %d\n", ret
);
220 ret
= dm_scan_other(pre_reloc_only
);
227 /* This is the root driver - all drivers are children of this */
228 U_BOOT_DRIVER(root_driver
) = {
229 .name
= "root_driver",
233 /* This is the root uclass */
234 UCLASS_DRIVER(root
) = {