]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/core/lists.c
2 * Copyright (c) 2013 Google, Inc
5 * Marek Vasut <marex@denx.de>
7 * SPDX-License-Identifier: GPL-2.0+
12 #include <dm/device.h>
13 #include <dm/device-internal.h>
15 #include <dm/platdata.h>
16 #include <dm/uclass.h>
19 #include <linux/compiler.h>
21 struct driver
*lists_driver_lookup_name(const char *name
)
24 ll_entry_start(struct driver
, driver
);
25 const int n_ents
= ll_entry_count(struct driver
, driver
);
34 for (entry
= drv
; entry
!= drv
+ n_ents
; entry
++) {
35 if (strncmp(name
, entry
->name
, len
))
39 if (len
== strlen(entry
->name
))
47 struct uclass_driver
*lists_uclass_lookup(enum uclass_id id
)
49 struct uclass_driver
*uclass
=
50 ll_entry_start(struct uclass_driver
, uclass
);
51 const int n_ents
= ll_entry_count(struct uclass_driver
, uclass
);
52 struct uclass_driver
*entry
;
54 if ((id
== UCLASS_INVALID
) || !uclass
)
57 for (entry
= uclass
; entry
!= uclass
+ n_ents
; entry
++) {
65 int lists_bind_drivers(struct udevice
*parent
, bool pre_reloc_only
)
67 struct driver_info
*info
=
68 ll_entry_start(struct driver_info
, driver_info
);
69 const int n_ents
= ll_entry_count(struct driver_info
, driver_info
);
70 struct driver_info
*entry
;
75 for (entry
= info
; entry
!= info
+ n_ents
; entry
++) {
76 ret
= device_bind_by_name(parent
, pre_reloc_only
, entry
, &dev
);
77 if (ret
&& ret
!= -EPERM
) {
78 dm_warn("No match for driver '%s'\n", entry
->name
);
79 if (!result
|| ret
!= -ENOENT
)
87 #ifdef CONFIG_OF_CONTROL
89 * driver_check_compatible() - Check if a driver is compatible with this node
91 * @param blob: Device tree pointer
92 * @param offset: Offset of node in device tree
93 * @param of_matchL List of compatible strings to match
94 * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
95 * does not have a compatible string, other error <0 if there is a device
98 static int driver_check_compatible(const void *blob
, int offset
,
99 const struct udevice_id
*of_match
)
106 while (of_match
->compatible
) {
107 ret
= fdt_node_check_compatible(blob
, offset
,
108 of_match
->compatible
);
111 else if (ret
== -FDT_ERR_NOTFOUND
)
121 int lists_bind_fdt(struct udevice
*parent
, const void *blob
, int offset
)
123 struct driver
*driver
= ll_entry_start(struct driver
, driver
);
124 const int n_ents
= ll_entry_count(struct driver
, driver
);
125 struct driver
*entry
;
132 dm_dbg("bind node %s\n", fdt_get_name(blob
, offset
, NULL
));
133 for (entry
= driver
; entry
!= driver
+ n_ents
; entry
++) {
134 ret
= driver_check_compatible(blob
, offset
, entry
->of_match
);
135 name
= fdt_get_name(blob
, offset
, NULL
);
136 if (ret
== -ENOENT
) {
138 } else if (ret
== -ENODEV
) {
139 dm_dbg("Device '%s' has no compatible string\n", name
);
142 dm_warn("Device tree error at offset %d\n", offset
);
143 if (!result
|| ret
!= -ENOENT
)
148 dm_dbg(" - found match at '%s'\n", entry
->name
);
149 ret
= device_bind(parent
, entry
, name
, NULL
, offset
, &dev
);
151 dm_warn("Error binding driver '%s'\n", entry
->name
);
152 if (!result
|| ret
!= -ENOENT
)
160 if (!found
&& !result
&& ret
!= -ENODEV
) {
161 dm_dbg("No match for node '%s'\n",
162 fdt_get_name(blob
, offset
, NULL
));