]>
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>
14 #include <dm/platdata.h>
15 #include <dm/uclass.h>
17 #include <linux/compiler.h>
19 struct driver
*lists_driver_lookup_name(const char *name
)
22 ll_entry_start(struct driver
, driver
);
23 const int n_ents
= ll_entry_count(struct driver
, driver
);
32 for (entry
= drv
; entry
!= drv
+ n_ents
; entry
++) {
33 if (strncmp(name
, entry
->name
, len
))
37 if (len
== strlen(entry
->name
))
45 struct uclass_driver
*lists_uclass_lookup(enum uclass_id id
)
47 struct uclass_driver
*uclass
=
48 ll_entry_start(struct uclass_driver
, uclass
);
49 const int n_ents
= ll_entry_count(struct uclass_driver
, uclass
);
50 struct uclass_driver
*entry
;
52 if ((id
== UCLASS_INVALID
) || !uclass
)
55 for (entry
= uclass
; entry
!= uclass
+ n_ents
; entry
++) {
63 int lists_bind_drivers(struct udevice
*parent
)
65 struct driver_info
*info
=
66 ll_entry_start(struct driver_info
, driver_info
);
67 const int n_ents
= ll_entry_count(struct driver_info
, driver_info
);
68 struct driver_info
*entry
;
73 for (entry
= info
; entry
!= info
+ n_ents
; entry
++) {
74 ret
= device_bind_by_name(parent
, entry
, &dev
);
76 dm_warn("No match for driver '%s'\n", entry
->name
);
77 if (!result
|| ret
!= -ENOENT
)
85 #ifdef CONFIG_OF_CONTROL
87 * driver_check_compatible() - Check if a driver is compatible with this node
89 * @param blob: Device tree pointer
90 * @param offset: Offset of node in device tree
91 * @param of_matchL List of compatible strings to match
92 * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
93 * does not have a compatible string, other error <0 if there is a device
96 static int driver_check_compatible(const void *blob
, int offset
,
97 const struct udevice_id
*of_match
)
104 while (of_match
->compatible
) {
105 ret
= fdt_node_check_compatible(blob
, offset
,
106 of_match
->compatible
);
109 else if (ret
== -FDT_ERR_NOTFOUND
)
119 int lists_bind_fdt(struct udevice
*parent
, const void *blob
, int offset
)
121 struct driver
*driver
= ll_entry_start(struct driver
, driver
);
122 const int n_ents
= ll_entry_count(struct driver
, driver
);
123 struct driver
*entry
;
129 dm_dbg("bind node %s\n", fdt_get_name(blob
, offset
, NULL
));
130 for (entry
= driver
; entry
!= driver
+ n_ents
; entry
++) {
131 ret
= driver_check_compatible(blob
, offset
, entry
->of_match
);
132 if (ret
== -ENOENT
) {
134 } else if (ret
== -ENODEV
) {
137 dm_warn("Device tree error at offset %d\n", offset
);
138 if (!result
|| ret
!= -ENOENT
)
143 name
= fdt_get_name(blob
, offset
, NULL
);
144 dm_dbg(" - found match at '%s'\n", entry
->name
);
145 ret
= device_bind(parent
, entry
, name
, NULL
, offset
, &dev
);
147 dm_warn("No match for driver '%s'\n", entry
->name
);
148 if (!result
|| ret
!= -ENOENT
)