]>
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
);
28 for (entry
= drv
; entry
!= drv
+ n_ents
; entry
++) {
29 if (!strcmp(name
, entry
->name
))
37 struct uclass_driver
*lists_uclass_lookup(enum uclass_id id
)
39 struct uclass_driver
*uclass
=
40 ll_entry_start(struct uclass_driver
, uclass
);
41 const int n_ents
= ll_entry_count(struct uclass_driver
, uclass
);
42 struct uclass_driver
*entry
;
44 for (entry
= uclass
; entry
!= uclass
+ n_ents
; entry
++) {
52 int lists_bind_drivers(struct udevice
*parent
, bool pre_reloc_only
)
54 struct driver_info
*info
=
55 ll_entry_start(struct driver_info
, driver_info
);
56 const int n_ents
= ll_entry_count(struct driver_info
, driver_info
);
57 struct driver_info
*entry
;
62 for (entry
= info
; entry
!= info
+ n_ents
; entry
++) {
63 ret
= device_bind_by_name(parent
, pre_reloc_only
, entry
, &dev
);
64 if (ret
&& ret
!= -EPERM
) {
65 dm_warn("No match for driver '%s'\n", entry
->name
);
66 if (!result
|| ret
!= -ENOENT
)
74 int device_bind_driver(struct udevice
*parent
, const char *drv_name
,
75 const char *dev_name
, struct udevice
**devp
)
77 return device_bind_driver_to_node(parent
, drv_name
, dev_name
, -1, devp
);
80 int device_bind_driver_to_node(struct udevice
*parent
, const char *drv_name
,
81 const char *dev_name
, int node
,
82 struct udevice
**devp
)
87 drv
= lists_driver_lookup_name(drv_name
);
89 debug("Cannot find driver '%s'\n", drv_name
);
92 ret
= device_bind(parent
, drv
, dev_name
, NULL
, node
, devp
);
94 debug("Cannot create device named '%s' (err=%d)\n",
102 #if CONFIG_IS_ENABLED(OF_CONTROL)
104 * driver_check_compatible() - Check if a driver is compatible with this node
106 * @param blob: Device tree pointer
107 * @param offset: Offset of node in device tree
108 * @param of_match: List of compatible strings to match
109 * @param of_idp: Returns the match that was found
110 * @return 0 if there is a match, -ENOENT if no match, -ENODEV if the node
111 * does not have a compatible string, other error <0 if there is a device
114 static int driver_check_compatible(const void *blob
, int offset
,
115 const struct udevice_id
*of_match
,
116 const struct udevice_id
**of_idp
)
124 while (of_match
->compatible
) {
125 ret
= fdt_node_check_compatible(blob
, offset
,
126 of_match
->compatible
);
130 } else if (ret
== -FDT_ERR_NOTFOUND
) {
132 } else if (ret
< 0) {
141 int lists_bind_fdt(struct udevice
*parent
, const void *blob
, int offset
,
142 struct udevice
**devp
)
144 struct driver
*driver
= ll_entry_start(struct driver
, driver
);
145 const int n_ents
= ll_entry_count(struct driver
, driver
);
146 const struct udevice_id
*id
;
147 struct driver
*entry
;
154 dm_dbg("bind node %s\n", fdt_get_name(blob
, offset
, NULL
));
157 for (entry
= driver
; entry
!= driver
+ n_ents
; entry
++) {
158 ret
= driver_check_compatible(blob
, offset
, entry
->of_match
,
160 name
= fdt_get_name(blob
, offset
, NULL
);
161 if (ret
== -ENOENT
) {
163 } else if (ret
== -ENODEV
) {
164 dm_dbg("Device '%s' has no compatible string\n", name
);
167 dm_warn("Device tree error at offset %d\n", offset
);
172 dm_dbg(" - found match at '%s'\n", entry
->name
);
173 ret
= device_bind(parent
, entry
, name
, NULL
, offset
, &dev
);
175 dm_warn("Error binding driver '%s'\n", entry
->name
);
178 dev
->driver_data
= id
->data
;
186 if (!found
&& !result
&& ret
!= -ENODEV
) {
187 dm_dbg("No match for node '%s'\n",
188 fdt_get_name(blob
, offset
, NULL
));