fdtbus.c revision 1.30 1 1.30 jmcneill /* $NetBSD: fdtbus.c,v 1.30 2019/10/01 23:32:52 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.1 jmcneill * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
8 1.1 jmcneill * modification, are permitted provided that the following conditions
9 1.1 jmcneill * are met:
10 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
11 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
12 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
14 1.1 jmcneill * documentation and/or other materials provided with the distribution.
15 1.1 jmcneill *
16 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 jmcneill * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 jmcneill * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 jmcneill * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 jmcneill * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 jmcneill * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 jmcneill * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 jmcneill * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 jmcneill * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 jmcneill * SUCH DAMAGE.
27 1.1 jmcneill */
28 1.1 jmcneill
29 1.1 jmcneill #include <sys/cdefs.h>
30 1.30 jmcneill __KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.30 2019/10/01 23:32:52 jmcneill Exp $");
31 1.1 jmcneill
32 1.1 jmcneill #include <sys/param.h>
33 1.1 jmcneill #include <sys/systm.h>
34 1.1 jmcneill #include <sys/device.h>
35 1.1 jmcneill #include <sys/kmem.h>
36 1.1 jmcneill
37 1.1 jmcneill #include <sys/bus.h>
38 1.1 jmcneill
39 1.1 jmcneill #include <dev/ofw/openfirm.h>
40 1.1 jmcneill
41 1.1 jmcneill #include <dev/fdt/fdtvar.h>
42 1.1 jmcneill
43 1.14 jmcneill #include <libfdt.h>
44 1.14 jmcneill
45 1.9 jmcneill #include "locators.h"
46 1.9 jmcneill
47 1.4 jmcneill #define FDT_MAX_PATH 256
48 1.4 jmcneill
49 1.7 jmcneill struct fdt_node {
50 1.8 jmcneill device_t n_bus;
51 1.7 jmcneill device_t n_dev;
52 1.7 jmcneill int n_phandle;
53 1.21 jmcneill const char *n_name;
54 1.21 jmcneill struct fdt_attach_args n_faa;
55 1.28 jmcneill cfdata_t n_cf;
56 1.7 jmcneill
57 1.8 jmcneill u_int n_order;
58 1.8 jmcneill
59 1.30 jmcneill bool n_pinctrl_init;
60 1.30 jmcneill
61 1.7 jmcneill TAILQ_ENTRY(fdt_node) n_nodes;
62 1.7 jmcneill };
63 1.7 jmcneill
64 1.8 jmcneill static TAILQ_HEAD(, fdt_node) fdt_nodes =
65 1.8 jmcneill TAILQ_HEAD_INITIALIZER(fdt_nodes);
66 1.21 jmcneill static bool fdt_need_rescan = false;
67 1.8 jmcneill
68 1.7 jmcneill struct fdt_softc {
69 1.7 jmcneill device_t sc_dev;
70 1.7 jmcneill int sc_phandle;
71 1.7 jmcneill struct fdt_attach_args sc_faa;
72 1.7 jmcneill };
73 1.7 jmcneill
74 1.1 jmcneill static int fdt_match(device_t, cfdata_t, void *);
75 1.1 jmcneill static void fdt_attach(device_t, device_t, void *);
76 1.24 jmcneill static int fdt_rescan(device_t, const char *, const int *);
77 1.24 jmcneill static void fdt_childdet(device_t, device_t);
78 1.24 jmcneill
79 1.9 jmcneill static int fdt_scan_submatch(device_t, cfdata_t, const int *, void *);
80 1.28 jmcneill static cfdata_t fdt_scan_best(struct fdt_softc *, struct fdt_node *);
81 1.9 jmcneill static void fdt_scan(struct fdt_softc *, int);
82 1.8 jmcneill static void fdt_add_node(struct fdt_node *);
83 1.8 jmcneill static u_int fdt_get_order(int);
84 1.30 jmcneill static void fdt_pre_attach(struct fdt_node *);
85 1.30 jmcneill static void fdt_post_attach(struct fdt_node *);
86 1.8 jmcneill
87 1.7 jmcneill static const char * const fdtbus_compatible[] =
88 1.27 jmcneill { "simple-bus", NULL };
89 1.1 jmcneill
90 1.24 jmcneill CFATTACH_DECL2_NEW(simplebus, sizeof(struct fdt_softc),
91 1.24 jmcneill fdt_match, fdt_attach, NULL, NULL, fdt_rescan, fdt_childdet);
92 1.1 jmcneill
93 1.1 jmcneill static int
94 1.1 jmcneill fdt_match(device_t parent, cfdata_t cf, void *aux)
95 1.1 jmcneill {
96 1.1 jmcneill const struct fdt_attach_args *faa = aux;
97 1.14 jmcneill const int phandle = faa->faa_phandle;
98 1.6 jmcneill int match;
99 1.1 jmcneill
100 1.14 jmcneill /* Check compatible string */
101 1.14 jmcneill match = of_match_compatible(phandle, fdtbus_compatible);
102 1.6 jmcneill if (match)
103 1.6 jmcneill return match;
104 1.6 jmcneill
105 1.15 jmcneill /* Some nodes have no compatible string */
106 1.15 jmcneill if (!of_hasprop(phandle, "compatible")) {
107 1.15 jmcneill if (OF_finddevice("/clocks") == phandle)
108 1.15 jmcneill return 1;
109 1.15 jmcneill if (OF_finddevice("/chosen") == phandle)
110 1.15 jmcneill return 1;
111 1.15 jmcneill }
112 1.14 jmcneill
113 1.14 jmcneill /* Always match the root node */
114 1.14 jmcneill return OF_finddevice("/") == phandle;
115 1.1 jmcneill }
116 1.1 jmcneill
117 1.1 jmcneill static void
118 1.1 jmcneill fdt_attach(device_t parent, device_t self, void *aux)
119 1.1 jmcneill {
120 1.7 jmcneill struct fdt_softc *sc = device_private(self);
121 1.1 jmcneill const struct fdt_attach_args *faa = aux;
122 1.1 jmcneill const int phandle = faa->faa_phandle;
123 1.22 jmcneill const char *descr;
124 1.7 jmcneill
125 1.7 jmcneill sc->sc_dev = self;
126 1.8 jmcneill sc->sc_phandle = phandle;
127 1.7 jmcneill sc->sc_faa = *faa;
128 1.1 jmcneill
129 1.1 jmcneill aprint_naive("\n");
130 1.22 jmcneill
131 1.22 jmcneill descr = fdtbus_get_string(phandle, "model");
132 1.22 jmcneill if (descr)
133 1.22 jmcneill aprint_normal(": %s\n", descr);
134 1.21 jmcneill else
135 1.1 jmcneill aprint_normal("\n");
136 1.1 jmcneill
137 1.21 jmcneill /* Find all child nodes */
138 1.21 jmcneill fdt_add_bus(self, phandle, &sc->sc_faa);
139 1.7 jmcneill
140 1.7 jmcneill /* Only the root bus should scan for devices */
141 1.7 jmcneill if (OF_finddevice("/") != faa->faa_phandle)
142 1.7 jmcneill return;
143 1.7 jmcneill
144 1.8 jmcneill /* Scan devices */
145 1.24 jmcneill fdt_rescan(self, NULL, NULL);
146 1.24 jmcneill }
147 1.24 jmcneill
148 1.24 jmcneill static int
149 1.24 jmcneill fdt_rescan(device_t self, const char *ifattr, const int *locs)
150 1.24 jmcneill {
151 1.24 jmcneill struct fdt_softc *sc = device_private(self);
152 1.28 jmcneill struct fdt_node *node;
153 1.24 jmcneill int pass;
154 1.24 jmcneill
155 1.28 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes)
156 1.28 jmcneill node->n_cf = fdt_scan_best(sc, node);
157 1.28 jmcneill
158 1.21 jmcneill pass = 0;
159 1.21 jmcneill fdt_need_rescan = false;
160 1.21 jmcneill do {
161 1.9 jmcneill fdt_scan(sc, pass);
162 1.21 jmcneill if (fdt_need_rescan == true) {
163 1.21 jmcneill pass = 0;
164 1.28 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
165 1.28 jmcneill if (node->n_dev == NULL)
166 1.28 jmcneill node->n_cf = fdt_scan_best(sc, node);
167 1.28 jmcneill }
168 1.21 jmcneill fdt_need_rescan = false;
169 1.21 jmcneill } else {
170 1.21 jmcneill pass++;
171 1.21 jmcneill }
172 1.21 jmcneill } while (pass <= FDTCF_PASS_DEFAULT);
173 1.24 jmcneill
174 1.24 jmcneill return 0;
175 1.24 jmcneill }
176 1.24 jmcneill
177 1.24 jmcneill static void
178 1.24 jmcneill fdt_childdet(device_t parent, device_t child)
179 1.24 jmcneill {
180 1.24 jmcneill struct fdt_node *node;
181 1.24 jmcneill
182 1.24 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes)
183 1.24 jmcneill if (node->n_dev == child) {
184 1.24 jmcneill node->n_dev = NULL;
185 1.24 jmcneill break;
186 1.24 jmcneill }
187 1.8 jmcneill }
188 1.7 jmcneill
189 1.8 jmcneill static void
190 1.21 jmcneill fdt_init_attach_args(const struct fdt_attach_args *faa_tmpl, struct fdt_node *node,
191 1.9 jmcneill bool quiet, struct fdt_attach_args *faa)
192 1.8 jmcneill {
193 1.21 jmcneill *faa = *faa_tmpl;
194 1.8 jmcneill faa->faa_phandle = node->n_phandle;
195 1.8 jmcneill faa->faa_name = node->n_name;
196 1.9 jmcneill faa->faa_quiet = quiet;
197 1.1 jmcneill }
198 1.1 jmcneill
199 1.23 jmcneill static bool
200 1.23 jmcneill fdt_add_bus_stdmatch(void *arg, int child)
201 1.23 jmcneill {
202 1.23 jmcneill return fdtbus_status_okay(child);
203 1.23 jmcneill }
204 1.23 jmcneill
205 1.21 jmcneill void
206 1.21 jmcneill fdt_add_bus(device_t bus, const int phandle, struct fdt_attach_args *faa)
207 1.21 jmcneill {
208 1.23 jmcneill fdt_add_bus_match(bus, phandle, faa, fdt_add_bus_stdmatch, NULL);
209 1.23 jmcneill }
210 1.23 jmcneill
211 1.23 jmcneill void
212 1.23 jmcneill fdt_add_bus_match(device_t bus, const int phandle, struct fdt_attach_args *faa,
213 1.23 jmcneill bool (*fn)(void *, int), void *fnarg)
214 1.23 jmcneill {
215 1.21 jmcneill int child;
216 1.21 jmcneill
217 1.21 jmcneill for (child = OF_child(phandle); child; child = OF_peer(child)) {
218 1.23 jmcneill if (fn && !fn(fnarg, child))
219 1.21 jmcneill continue;
220 1.21 jmcneill
221 1.25 jmcneill fdt_add_child(bus, child, faa, fdt_get_order(child));
222 1.25 jmcneill }
223 1.25 jmcneill }
224 1.21 jmcneill
225 1.25 jmcneill void
226 1.25 jmcneill fdt_add_child(device_t bus, const int child, struct fdt_attach_args *faa,
227 1.25 jmcneill u_int order)
228 1.25 jmcneill {
229 1.25 jmcneill struct fdt_node *node;
230 1.25 jmcneill
231 1.25 jmcneill /* Add the node to our device list */
232 1.25 jmcneill node = kmem_alloc(sizeof(*node), KM_SLEEP);
233 1.25 jmcneill node->n_bus = bus;
234 1.25 jmcneill node->n_dev = NULL;
235 1.25 jmcneill node->n_phandle = child;
236 1.25 jmcneill node->n_name = fdtbus_get_string(child, "name");
237 1.25 jmcneill node->n_order = order;
238 1.25 jmcneill node->n_faa = *faa;
239 1.25 jmcneill node->n_faa.faa_phandle = child;
240 1.25 jmcneill node->n_faa.faa_name = node->n_name;
241 1.25 jmcneill
242 1.25 jmcneill fdt_add_node(node);
243 1.25 jmcneill fdt_need_rescan = true;
244 1.21 jmcneill }
245 1.21 jmcneill
246 1.9 jmcneill static int
247 1.9 jmcneill fdt_scan_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux)
248 1.9 jmcneill {
249 1.9 jmcneill if (locs[FDTCF_PASS] != FDTCF_PASS_DEFAULT &&
250 1.9 jmcneill locs[FDTCF_PASS] != cf->cf_loc[FDTCF_PASS])
251 1.9 jmcneill return 0;
252 1.9 jmcneill
253 1.9 jmcneill return config_stdsubmatch(parent, cf, locs, aux);
254 1.9 jmcneill }
255 1.9 jmcneill
256 1.20 jmcneill static cfdata_t
257 1.20 jmcneill fdt_scan_best(struct fdt_softc *sc, struct fdt_node *node)
258 1.20 jmcneill {
259 1.20 jmcneill struct fdt_attach_args faa;
260 1.20 jmcneill cfdata_t cf, best_cf;
261 1.20 jmcneill int match, best_match;
262 1.20 jmcneill
263 1.20 jmcneill best_cf = NULL;
264 1.20 jmcneill best_match = 0;
265 1.20 jmcneill
266 1.20 jmcneill for (int pass = 0; pass <= FDTCF_PASS_DEFAULT; pass++) {
267 1.20 jmcneill const int locs[FDTCF_NLOCS] = {
268 1.20 jmcneill [FDTCF_PASS] = pass
269 1.20 jmcneill };
270 1.21 jmcneill fdt_init_attach_args(&sc->sc_faa, node, true, &faa);
271 1.20 jmcneill cf = config_search_loc(fdt_scan_submatch, node->n_bus, "fdt", locs, &faa);
272 1.20 jmcneill if (cf == NULL)
273 1.20 jmcneill continue;
274 1.20 jmcneill match = config_match(node->n_bus, cf, &faa);
275 1.20 jmcneill if (match > best_match) {
276 1.20 jmcneill best_match = match;
277 1.20 jmcneill best_cf = cf;
278 1.20 jmcneill }
279 1.20 jmcneill }
280 1.20 jmcneill
281 1.20 jmcneill return best_cf;
282 1.20 jmcneill }
283 1.20 jmcneill
284 1.8 jmcneill static void
285 1.9 jmcneill fdt_scan(struct fdt_softc *sc, int pass)
286 1.8 jmcneill {
287 1.8 jmcneill struct fdt_node *node;
288 1.8 jmcneill struct fdt_attach_args faa;
289 1.9 jmcneill const int locs[FDTCF_NLOCS] = {
290 1.9 jmcneill [FDTCF_PASS] = pass
291 1.9 jmcneill };
292 1.9 jmcneill bool quiet = pass != FDTCF_PASS_DEFAULT;
293 1.22 jmcneill prop_dictionary_t dict;
294 1.22 jmcneill char buf[FDT_MAX_PATH];
295 1.8 jmcneill
296 1.8 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
297 1.29 jmcneill if (node->n_dev != NULL)
298 1.8 jmcneill continue;
299 1.8 jmcneill
300 1.21 jmcneill fdt_init_attach_args(&sc->sc_faa, node, quiet, &faa);
301 1.1 jmcneill
302 1.29 jmcneill if (quiet) {
303 1.29 jmcneill /*
304 1.29 jmcneill * No match for this device, skip it.
305 1.29 jmcneill */
306 1.29 jmcneill if (node->n_cf == NULL)
307 1.29 jmcneill continue;
308 1.29 jmcneill
309 1.29 jmcneill /*
310 1.29 jmcneill * Make sure we don't attach before a better match in a later pass.
311 1.29 jmcneill */
312 1.29 jmcneill cfdata_t cf_pass =
313 1.29 jmcneill config_search_loc(fdt_scan_submatch, node->n_bus, "fdt", locs, &faa);
314 1.29 jmcneill if (node->n_cf != cf_pass)
315 1.29 jmcneill continue;
316 1.29 jmcneill
317 1.29 jmcneill /*
318 1.29 jmcneill * Attach the device.
319 1.29 jmcneill */
320 1.30 jmcneill fdt_pre_attach(node);
321 1.29 jmcneill node->n_dev = config_attach_loc(node->n_bus, cf_pass, locs,
322 1.29 jmcneill &faa, fdtbus_print);
323 1.30 jmcneill if (node->n_dev != NULL)
324 1.30 jmcneill fdt_post_attach(node);
325 1.29 jmcneill } else {
326 1.29 jmcneill /*
327 1.29 jmcneill * Default pass.
328 1.29 jmcneill */
329 1.30 jmcneill fdt_pre_attach(node);
330 1.29 jmcneill node->n_dev = config_found_sm_loc(node->n_bus, "fdt", locs,
331 1.29 jmcneill &faa, fdtbus_print, fdt_scan_submatch);
332 1.30 jmcneill if (node->n_dev != NULL)
333 1.30 jmcneill fdt_post_attach(node);
334 1.29 jmcneill }
335 1.20 jmcneill
336 1.22 jmcneill if (node->n_dev) {
337 1.22 jmcneill dict = device_properties(node->n_dev);
338 1.22 jmcneill if (fdtbus_get_path(node->n_phandle, buf, sizeof(buf)))
339 1.22 jmcneill prop_dictionary_set_cstring(dict, "fdt-path", buf);
340 1.22 jmcneill }
341 1.8 jmcneill }
342 1.8 jmcneill }
343 1.8 jmcneill
344 1.8 jmcneill static void
345 1.30 jmcneill fdt_pre_attach(struct fdt_node *node)
346 1.30 jmcneill {
347 1.30 jmcneill const char *cfgname;
348 1.30 jmcneill int error;
349 1.30 jmcneill
350 1.30 jmcneill node->n_pinctrl_init = fdtbus_pinctrl_has_config(node->n_phandle, "init");
351 1.30 jmcneill
352 1.30 jmcneill cfgname = node->n_pinctrl_init ? "init" : "default";
353 1.30 jmcneill
354 1.30 jmcneill aprint_debug_dev(node->n_bus, "set %s config for %s\n", cfgname, node->n_name);
355 1.30 jmcneill
356 1.30 jmcneill error = fdtbus_pinctrl_set_config(node->n_phandle, cfgname);
357 1.30 jmcneill if (error != 0 && error != ENOENT)
358 1.30 jmcneill aprint_debug_dev(node->n_bus,
359 1.30 jmcneill "failed to set %s config on %s: %d\n",
360 1.30 jmcneill cfgname, node->n_name, error);
361 1.30 jmcneill }
362 1.30 jmcneill
363 1.30 jmcneill static void
364 1.30 jmcneill fdt_post_attach(struct fdt_node *node)
365 1.30 jmcneill {
366 1.30 jmcneill int error;
367 1.30 jmcneill
368 1.30 jmcneill if (node->n_pinctrl_init) {
369 1.30 jmcneill aprint_debug_dev(node->n_bus, "set default config for %s\n", node->n_name);
370 1.30 jmcneill error = fdtbus_pinctrl_set_config(node->n_phandle, "default");
371 1.30 jmcneill if (error != 0 && error != ENOENT)
372 1.30 jmcneill aprint_debug_dev(node->n_bus,
373 1.30 jmcneill "failed to set default config on %s: %d\n",
374 1.30 jmcneill node->n_name, error);
375 1.30 jmcneill }
376 1.30 jmcneill }
377 1.30 jmcneill
378 1.30 jmcneill static void
379 1.8 jmcneill fdt_add_node(struct fdt_node *new_node)
380 1.8 jmcneill {
381 1.8 jmcneill struct fdt_node *node;
382 1.8 jmcneill
383 1.8 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes)
384 1.8 jmcneill if (node->n_order > new_node->n_order) {
385 1.8 jmcneill TAILQ_INSERT_BEFORE(node, new_node, n_nodes);
386 1.8 jmcneill return;
387 1.7 jmcneill }
388 1.8 jmcneill TAILQ_INSERT_TAIL(&fdt_nodes, new_node, n_nodes);
389 1.8 jmcneill }
390 1.8 jmcneill
391 1.16 bouyer void
392 1.16 bouyer fdt_remove_byhandle(int phandle)
393 1.16 bouyer {
394 1.16 bouyer struct fdt_node *node;
395 1.16 bouyer
396 1.16 bouyer TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
397 1.16 bouyer if (node->n_phandle == phandle) {
398 1.16 bouyer TAILQ_REMOVE(&fdt_nodes, node, n_nodes);
399 1.16 bouyer return;
400 1.16 bouyer }
401 1.16 bouyer }
402 1.16 bouyer }
403 1.16 bouyer
404 1.16 bouyer void
405 1.16 bouyer fdt_remove_bycompat(const char *compatible[])
406 1.16 bouyer {
407 1.16 bouyer struct fdt_node *node, *next;
408 1.16 bouyer
409 1.16 bouyer TAILQ_FOREACH_SAFE(node, &fdt_nodes, n_nodes, next) {
410 1.16 bouyer if (of_match_compatible(node->n_phandle, compatible)) {
411 1.16 bouyer TAILQ_REMOVE(&fdt_nodes, node, n_nodes);
412 1.16 bouyer }
413 1.16 bouyer }
414 1.16 bouyer }
415 1.16 bouyer
416 1.26 jmcneill int
417 1.26 jmcneill fdt_find_with_property(const char *prop, int *pindex)
418 1.26 jmcneill {
419 1.26 jmcneill struct fdt_node *node;
420 1.26 jmcneill int index = 0;
421 1.26 jmcneill
422 1.26 jmcneill TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
423 1.27 jmcneill if (index++ < *pindex)
424 1.26 jmcneill continue;
425 1.26 jmcneill if (of_hasprop(node->n_phandle, prop)) {
426 1.26 jmcneill *pindex = index;
427 1.26 jmcneill return node->n_phandle;
428 1.26 jmcneill }
429 1.26 jmcneill }
430 1.26 jmcneill
431 1.26 jmcneill return -1;
432 1.26 jmcneill }
433 1.26 jmcneill
434 1.8 jmcneill static u_int
435 1.8 jmcneill fdt_get_order(int phandle)
436 1.8 jmcneill {
437 1.8 jmcneill u_int val = UINT_MAX;
438 1.8 jmcneill int child;
439 1.8 jmcneill
440 1.8 jmcneill of_getprop_uint32(phandle, "phandle", &val);
441 1.8 jmcneill
442 1.8 jmcneill for (child = OF_child(phandle); child; child = OF_peer(child)) {
443 1.8 jmcneill u_int child_val = fdt_get_order(child);
444 1.8 jmcneill if (child_val < val)
445 1.8 jmcneill val = child_val;
446 1.1 jmcneill }
447 1.8 jmcneill
448 1.8 jmcneill return val;
449 1.1 jmcneill }
450 1.1 jmcneill
451 1.12 jmcneill int
452 1.12 jmcneill fdtbus_print(void *aux, const char *pnp)
453 1.1 jmcneill {
454 1.1 jmcneill const struct fdt_attach_args * const faa = aux;
455 1.4 jmcneill char buf[FDT_MAX_PATH];
456 1.4 jmcneill const char *name = buf;
457 1.14 jmcneill int len;
458 1.1 jmcneill
459 1.10 jmcneill if (pnp && faa->faa_quiet)
460 1.9 jmcneill return QUIET;
461 1.9 jmcneill
462 1.5 jmcneill /* Skip "not configured" for nodes w/o compatible property */
463 1.10 jmcneill if (pnp && OF_getproplen(faa->faa_phandle, "compatible") <= 0)
464 1.5 jmcneill return QUIET;
465 1.5 jmcneill
466 1.10 jmcneill if (!fdtbus_get_path(faa->faa_phandle, buf, sizeof(buf)))
467 1.10 jmcneill name = faa->faa_name;
468 1.10 jmcneill
469 1.14 jmcneill if (pnp) {
470 1.4 jmcneill aprint_normal("%s at %s", name, pnp);
471 1.14 jmcneill const char *compat = fdt_getprop(fdtbus_get_data(),
472 1.14 jmcneill fdtbus_phandle2offset(faa->faa_phandle), "compatible",
473 1.14 jmcneill &len);
474 1.14 jmcneill while (len > 0) {
475 1.14 jmcneill aprint_debug(" <%s>", compat);
476 1.14 jmcneill len -= (strlen(compat) + 1);
477 1.14 jmcneill compat += (strlen(compat) + 1);
478 1.14 jmcneill }
479 1.14 jmcneill } else
480 1.19 thorpej aprint_debug(" (%s)", name);
481 1.1 jmcneill
482 1.1 jmcneill return UNCONF;
483 1.1 jmcneill }
484