]> Git Repo - J-u-boot.git/blame - drivers/core/root.c
dm: fdt: Add a function to look up a chosen node
[J-u-boot.git] / drivers / core / root.c
CommitLineData
6494d708
SG
1/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * (C) Copyright 2012
5 * Pavel Herrmann <[email protected]>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#include <common.h>
11#include <errno.h>
12#include <malloc.h>
6a6d8fbe 13#include <libfdt.h>
6494d708
SG
14#include <dm/device.h>
15#include <dm/device-internal.h>
16#include <dm/lists.h>
17#include <dm/platdata.h>
fd536d81 18#include <dm/root.h>
6494d708
SG
19#include <dm/uclass.h>
20#include <dm/util.h>
21#include <linux/list.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
25static const struct driver_info root_info = {
26 .name = "root_driver",
27};
28
54c5d08a 29struct udevice *dm_root(void)
6494d708
SG
30{
31 if (!gd->dm_root) {
32 dm_warn("Virtual root driver does not exist!\n");
33 return NULL;
34 }
35
36 return gd->dm_root;
37}
38
39int dm_init(void)
40{
41 int ret;
42
43 if (gd->dm_root) {
44 dm_warn("Virtual root driver already exists!\n");
45 return -EINVAL;
46 }
89876a55 47 INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST);
6494d708 48
00606d7e 49 ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
7497812d
SG
50 if (ret)
51 return ret;
52 ret = device_probe(DM_ROOT_NON_CONST);
6494d708
SG
53 if (ret)
54 return ret;
55
56 return 0;
57}
58
9adbd7a1
SG
59int dm_uninit(void)
60{
61 device_remove(dm_root());
62 device_unbind(dm_root());
63
64 return 0;
65}
66
00606d7e 67int dm_scan_platdata(bool pre_reloc_only)
6494d708
SG
68{
69 int ret;
70
00606d7e 71 ret = lists_bind_drivers(DM_ROOT_NON_CONST, pre_reloc_only);
6494d708
SG
72 if (ret == -ENOENT) {
73 dm_warn("Some drivers were not found\n");
74 ret = 0;
75 }
76 if (ret)
77 return ret;
78
79 return 0;
80}
81
82#ifdef CONFIG_OF_CONTROL
1ca7e206
SG
83int dm_scan_fdt_node(struct udevice *parent, const void *blob, int offset,
84 bool pre_reloc_only)
6494d708 85{
6494d708 86 int ret = 0, err;
1ca7e206
SG
87
88 for (offset = fdt_first_subnode(blob, offset);
89 offset > 0;
90 offset = fdt_next_subnode(blob, offset)) {
91 if (pre_reloc_only &&
92 !fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
93 continue;
94 err = lists_bind_fdt(parent, blob, offset);
95 if (err && !ret)
96 ret = err;
97 }
6494d708
SG
98
99 if (ret)
100 dm_warn("Some drivers failed to bind\n");
101
102 return ret;
103}
1ca7e206
SG
104
105int dm_scan_fdt(const void *blob, bool pre_reloc_only)
106{
107 return dm_scan_fdt_node(gd->dm_root, blob, 0, pre_reloc_only);
108}
6494d708
SG
109#endif
110
bb58503d
SG
111__weak int dm_scan_other(bool pre_reloc_only)
112{
113 return 0;
114}
115
ab7cd627
SG
116int dm_init_and_scan(bool pre_reloc_only)
117{
118 int ret;
119
120 ret = dm_init();
121 if (ret) {
122 debug("dm_init() failed: %d\n", ret);
123 return ret;
124 }
125 ret = dm_scan_platdata(pre_reloc_only);
126 if (ret) {
127 debug("dm_scan_platdata() failed: %d\n", ret);
128 return ret;
129 }
130#ifdef CONFIG_OF_CONTROL
131 ret = dm_scan_fdt(gd->fdt_blob, pre_reloc_only);
132 if (ret) {
133 debug("dm_scan_fdt() failed: %d\n", ret);
134 return ret;
135 }
136#endif
bb58503d
SG
137 ret = dm_scan_other(pre_reloc_only);
138 if (ret)
139 return ret;
ab7cd627
SG
140
141 return 0;
142}
143
6494d708
SG
144/* This is the root driver - all drivers are children of this */
145U_BOOT_DRIVER(root_driver) = {
146 .name = "root_driver",
147 .id = UCLASS_ROOT,
148};
149
150/* This is the root uclass */
151UCLASS_DRIVER(root) = {
152 .name = "root",
153 .id = UCLASS_ROOT,
154};
This page took 0.075508 seconds and 4 git commands to generate.