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);
31 for (entry = drv; entry != drv + n_ents; entry++) {
32 if (!strcmp(name, entry->name))
40 struct uclass_driver *lists_uclass_lookup(enum uclass_id id)
42 struct uclass_driver *uclass =
43 ll_entry_start(struct uclass_driver, uclass);
44 const int n_ents = ll_entry_count(struct uclass_driver, uclass);
45 struct uclass_driver *entry;
47 if ((id == UCLASS_INVALID) || !uclass)
50 for (entry = uclass; entry != uclass + n_ents; entry++) {
58 int lists_bind_drivers(struct udevice *parent, bool pre_reloc_only)
60 struct driver_info *info =
61 ll_entry_start(struct driver_info, driver_info);
62 const int n_ents = ll_entry_count(struct driver_info, driver_info);
63 struct driver_info *entry;
68 for (entry = info; entry != info + n_ents; entry++) {
69 ret = device_bind_by_name(parent, pre_reloc_only, entry, &dev);
70 if (ret && ret != -EPERM) {
71 dm_warn("No match for driver '%s'\n", entry->name);
72 if (!result || ret != -ENOENT)
80 #ifdef CONFIG_OF_CONTROL
82 * driver_check_compatible() - Check if a driver is compatible with this node
84 * @param blob: Device tree pointer
85 * @param offset: Offset of node in device tree
86 * @param of_match: List of compatible strings to match
87 * @param of_idp: Returns the match that was found
88 * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
89 * does not have a compatible string, other error <0 if there is a device
92 static int driver_check_compatible(const void *blob, int offset,
93 const struct udevice_id *of_match,
94 const struct udevice_id **of_idp)
102 while (of_match->compatible) {
103 ret = fdt_node_check_compatible(blob, offset,
104 of_match->compatible);
108 } else if (ret == -FDT_ERR_NOTFOUND) {
110 } else if (ret < 0) {
119 int lists_bind_fdt(struct udevice *parent, const void *blob, int offset,
120 struct udevice **devp)
122 struct driver *driver = ll_entry_start(struct driver, driver);
123 const int n_ents = ll_entry_count(struct driver, driver);
124 const struct udevice_id *id;
125 struct driver *entry;
132 dm_dbg("bind node %s\n", fdt_get_name(blob, offset, NULL));
135 for (entry = driver; entry != driver + n_ents; entry++) {
136 ret = driver_check_compatible(blob, offset, entry->of_match,
138 name = fdt_get_name(blob, offset, NULL);
139 if (ret == -ENOENT) {
141 } else if (ret == -ENODEV) {
142 dm_dbg("Device '%s' has no compatible string\n", name);
145 dm_warn("Device tree error at offset %d\n", offset);
146 if (!result || ret != -ENOENT)
151 dm_dbg(" - found match at '%s'\n", entry->name);
152 ret = device_bind(parent, entry, name, NULL, offset, &dev);
154 dm_warn("Error binding driver '%s'\n", entry->name);
165 if (!found && !result && ret != -ENODEV) {
166 dm_dbg("No match for node '%s'\n",
167 fdt_get_name(blob, offset, NULL));