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>
18 #include <linux/compiler.h>
20 struct driver *lists_driver_lookup_name(const char *name)
23 ll_entry_start(struct driver, driver);
24 const int n_ents = ll_entry_count(struct driver, driver);
33 for (entry = drv; entry != drv + n_ents; entry++) {
34 if (strncmp(name, entry->name, len))
38 if (len == strlen(entry->name))
46 struct uclass_driver *lists_uclass_lookup(enum uclass_id id)
48 struct uclass_driver *uclass =
49 ll_entry_start(struct uclass_driver, uclass);
50 const int n_ents = ll_entry_count(struct uclass_driver, uclass);
51 struct uclass_driver *entry;
53 if ((id == UCLASS_INVALID) || !uclass)
56 for (entry = uclass; entry != uclass + n_ents; entry++) {
64 int lists_bind_drivers(struct udevice *parent)
66 struct driver_info *info =
67 ll_entry_start(struct driver_info, driver_info);
68 const int n_ents = ll_entry_count(struct driver_info, driver_info);
69 struct driver_info *entry;
74 for (entry = info; entry != info + n_ents; entry++) {
75 ret = device_bind_by_name(parent, entry, &dev);
77 dm_warn("No match for driver '%s'\n", entry->name);
78 if (!result || ret != -ENOENT)
86 #ifdef CONFIG_OF_CONTROL
88 * driver_check_compatible() - Check if a driver is compatible with this node
90 * @param blob: Device tree pointer
91 * @param offset: Offset of node in device tree
92 * @param of_matchL List of compatible strings to match
93 * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
94 * does not have a compatible string, other error <0 if there is a device
97 static int driver_check_compatible(const void *blob, int offset,
98 const struct udevice_id *of_match)
105 while (of_match->compatible) {
106 ret = fdt_node_check_compatible(blob, offset,
107 of_match->compatible);
110 else if (ret == -FDT_ERR_NOTFOUND)
120 int lists_bind_fdt(struct udevice *parent, const void *blob, int offset)
122 struct driver *driver = ll_entry_start(struct driver, driver);
123 const int n_ents = ll_entry_count(struct driver, driver);
124 struct driver *entry;
130 dm_dbg("bind node %s\n", fdt_get_name(blob, offset, NULL));
131 for (entry = driver; entry != driver + n_ents; entry++) {
132 ret = driver_check_compatible(blob, offset, entry->of_match);
133 if (ret == -ENOENT) {
135 } else if (ret == -ENODEV) {
138 dm_warn("Device tree error at offset %d\n", offset);
139 if (!result || ret != -ENOENT)
144 name = fdt_get_name(blob, offset, NULL);
145 dm_dbg(" - found match at '%s'\n", entry->name);
146 ret = device_bind(parent, entry, name, NULL, offset, &dev);
148 dm_warn("No match for driver '%s'\n", entry->name);
149 if (!result || ret != -ENOENT)