1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2013 Google, Inc
8 * Pavel Herrmann <morpheus.ibis@gmail.com>
15 #include <asm/global_data.h>
19 #include <fdt_support.h>
21 #include <asm/cache.h>
22 #include <dm/device.h>
23 #include <dm/device-internal.h>
25 #include <dm/of_access.h>
26 #include <dm/pinctrl.h>
27 #include <dm/platdata.h>
29 #include <dm/uclass.h>
30 #include <dm/uclass-internal.h>
33 #include <linux/err.h>
34 #include <linux/list.h>
35 #include <power-domain.h>
37 DECLARE_GLOBAL_DATA_PTR;
39 static int device_bind_common(struct udevice *parent, const struct driver *drv,
40 const char *name, void *plat,
41 ulong driver_data, ofnode node,
42 uint of_plat_size, struct udevice **devp)
50 if (CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND))
58 ret = uclass_get(drv->id, &uc);
60 debug("Missing uclass for driver %s\n", drv->name);
64 dev = calloc(1, sizeof(struct udevice));
68 INIT_LIST_HEAD(&dev->sibling_node);
69 INIT_LIST_HEAD(&dev->child_head);
70 INIT_LIST_HEAD(&dev->uclass_node);
71 #if CONFIG_IS_ENABLED(DEVRES)
72 INIT_LIST_HEAD(&dev->devres_head);
74 dev_set_plat(dev, plat);
75 dev->driver_data = driver_data;
77 dev_set_ofnode(dev, node);
83 if (CONFIG_IS_ENABLED(DM_SEQ_ALIAS) &&
84 (uc->uc_drv->flags & DM_UC_FLAG_SEQ_ALIAS)) {
86 * Some devices, such as a SPI bus, I2C bus and serial ports
87 * are numbered using aliases.
89 if (CONFIG_IS_ENABLED(OF_CONTROL) &&
90 !CONFIG_IS_ENABLED(OF_PLATDATA)) {
91 if (uc->uc_drv->name && ofnode_valid(node)) {
92 if (!dev_read_alias_seq(dev, &dev->seq_)) {
94 log_debug(" - seq=%d\n", dev->seq_);
99 if (auto_seq && !(uc->uc_drv->flags & DM_UC_FLAG_NO_AUTO_SEQ))
100 dev->seq_ = uclass_find_next_free_seq(uc);
102 /* Check if we need to allocate plat */
103 if (drv->plat_auto) {
107 * For of-platdata, we try use the existing data, but if
108 * plat_auto is larger, we must allocate a new space
110 if (CONFIG_IS_ENABLED(OF_PLATDATA)) {
112 dev_or_flags(dev, DM_FLAG_OF_PLATDATA);
113 if (of_plat_size < drv->plat_auto)
117 dev_or_flags(dev, DM_FLAG_ALLOC_PDATA);
118 ptr = calloc(1, drv->plat_auto);
125 * For of-platdata, copy the old plat into the new
128 if (CONFIG_IS_ENABLED(OF_PLATDATA) && plat)
129 memcpy(ptr, plat, of_plat_size);
130 dev_set_plat(dev, ptr);
134 size = uc->uc_drv->per_device_plat_auto;
136 dev_or_flags(dev, DM_FLAG_ALLOC_UCLASS_PDATA);
137 ptr = calloc(1, size);
142 dev_set_uclass_plat(dev, ptr);
146 size = parent->driver->per_child_plat_auto;
148 size = parent->uclass->uc_drv->per_child_plat_auto;
150 dev_or_flags(dev, DM_FLAG_ALLOC_PARENT_PDATA);
151 ptr = calloc(1, size);
156 dev_set_parent_plat(dev, ptr);
158 /* put dev into parent's successor list */
159 list_add_tail(&dev->sibling_node, &parent->child_head);
162 ret = uclass_bind_device(dev);
164 goto fail_uclass_bind;
166 /* if we fail to bind we remove device from successors and free it */
168 ret = drv->bind(dev);
172 if (parent && parent->driver->child_post_bind) {
173 ret = parent->driver->child_post_bind(dev);
175 goto fail_child_post_bind;
177 if (uc->uc_drv->post_bind) {
178 ret = uc->uc_drv->post_bind(dev);
180 goto fail_uclass_post_bind;
184 pr_debug("Bound device %s to %s\n", dev->name, parent->name);
188 dev_or_flags(dev, DM_FLAG_BOUND);
192 fail_uclass_post_bind:
193 /* There is no child unbind() method, so no clean-up required */
194 fail_child_post_bind:
195 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
196 if (drv->unbind && drv->unbind(dev)) {
197 dm_warn("unbind() method failed on dev '%s' on error path\n",
203 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
204 if (uclass_unbind_device(dev)) {
205 dm_warn("Failed to unbind dev '%s' on error path\n",
210 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
211 list_del(&dev->sibling_node);
212 if (dev_get_flags(dev) & DM_FLAG_ALLOC_PARENT_PDATA) {
213 free(dev_get_parent_plat(dev));
214 dev_set_parent_plat(dev, NULL);
218 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
219 if (dev_get_flags(dev) & DM_FLAG_ALLOC_UCLASS_PDATA) {
220 free(dev_get_uclass_plat(dev));
221 dev_set_uclass_plat(dev, NULL);
225 if (CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)) {
226 if (dev_get_flags(dev) & DM_FLAG_ALLOC_PDATA) {
227 free(dev_get_plat(dev));
228 dev_set_plat(dev, NULL);
232 devres_release_all(dev);
239 int device_bind_with_driver_data(struct udevice *parent,
240 const struct driver *drv, const char *name,
241 ulong driver_data, ofnode node,
242 struct udevice **devp)
244 return device_bind_common(parent, drv, name, NULL, driver_data, node,
248 int device_bind(struct udevice *parent, const struct driver *drv,
249 const char *name, void *plat, ofnode node,
250 struct udevice **devp)
252 return device_bind_common(parent, drv, name, plat, 0, node, 0,
256 int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
257 const struct driver_info *info, struct udevice **devp)
263 drv = lists_driver_lookup_name(info->name);
266 if (pre_reloc_only && !(drv->flags & DM_FLAG_PRE_RELOC))
269 #if CONFIG_IS_ENABLED(OF_PLATDATA)
270 plat_size = info->plat_size;
272 ret = device_bind_common(parent, drv, info->name, (void *)info->plat, 0,
273 ofnode_null(), plat_size, devp);
280 int device_reparent(struct udevice *dev, struct udevice *new_parent)
282 struct udevice *pos, *n;
287 device_foreach_child_safe(pos, n, dev->parent) {
288 if (pos->driver != dev->driver)
291 list_del(&dev->sibling_node);
292 list_add_tail(&dev->sibling_node, &new_parent->child_head);
293 dev->parent = new_parent;
301 static void *alloc_priv(int size, uint flags)
305 if (flags & DM_FLAG_ALLOC_PRIV_DMA) {
306 size = ROUND(size, ARCH_DMA_MINALIGN);
307 priv = memalign(ARCH_DMA_MINALIGN, size);
309 memset(priv, '\0', size);
312 * Ensure that the zero bytes are flushed to memory.
313 * This prevents problems if the driver uses this as
314 * both an input and an output buffer:
316 * 1. Zeroes written to buffer (here) and sit in the
318 * 2. Driver issues a read command to DMA
319 * 3. CPU runs out of cache space and evicts some cache
320 * data in the buffer, writing zeroes to RAM from
323 * 5. Buffer now has some DMA data and some zeroes
324 * 6. Data being read is now incorrect
326 * To prevent this, ensure that the cache is clean
327 * within this range at the start. The driver can then
328 * use normal flush-after-write, invalidate-before-read
331 flush_dcache_range((ulong)priv, (ulong)priv + size);
334 priv = calloc(1, size);
341 * device_alloc_priv() - Allocate priv/plat data required by the device
343 * @dev: Device to process
344 * Return: 0 if OK, -ENOMEM if out of memory
346 static int device_alloc_priv(struct udevice *dev)
348 const struct driver *drv;
355 /* Allocate private data if requested and not reentered */
356 if (drv->priv_auto && !dev_get_priv(dev)) {
357 ptr = alloc_priv(drv->priv_auto, drv->flags);
360 dev_set_priv(dev, ptr);
363 /* Allocate private data if requested and not reentered */
364 size = dev->uclass->uc_drv->per_device_auto;
365 if (size && !dev_get_uclass_priv(dev)) {
366 ptr = alloc_priv(size, dev->uclass->uc_drv->flags);
369 dev_set_uclass_priv(dev, ptr);
372 /* Allocate parent data for this child */
374 size = dev->parent->driver->per_child_auto;
376 size = dev->parent->uclass->uc_drv->per_child_auto;
377 if (size && !dev_get_parent_priv(dev)) {
378 ptr = alloc_priv(size, drv->flags);
381 dev_set_parent_priv(dev, ptr);
388 int device_of_to_plat(struct udevice *dev)
390 const struct driver *drv;
396 if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
400 * This is not needed if binding is disabled, since data is allocated
403 if (!CONFIG_IS_ENABLED(OF_PLATDATA_NO_BIND)) {
404 /* Ensure all parents have ofdata */
406 ret = device_of_to_plat(dev->parent);
411 * The device might have already been probed during
412 * the call to device_probe() on its parent device
413 * (e.g. PCI bridge devices). Test the flags again
414 * so that we don't mess up the device.
416 if (dev_get_flags(dev) & DM_FLAG_PLATDATA_VALID)
420 ret = device_alloc_priv(dev);
427 if (drv->of_to_plat &&
428 (CONFIG_IS_ENABLED(OF_PLATDATA) || dev_has_ofnode(dev))) {
429 ret = drv->of_to_plat(dev);
434 dev_or_flags(dev, DM_FLAG_PLATDATA_VALID);
444 * device_get_dma_constraints() - Populate device's DMA constraints
446 * Gets a device's DMA constraints from firmware. This information is later
447 * used by drivers to translate physcal addresses to the device's bus address
448 * space. For now only device-tree is supported.
450 * @dev: Pointer to target device
451 * Return: 0 if OK or if no DMA constraints were found, error otherwise
453 static int device_get_dma_constraints(struct udevice *dev)
455 struct udevice *parent = dev->parent;
461 if (!CONFIG_IS_ENABLED(DM_DMA) || !parent || !dev_has_ofnode(parent))
465 * We start parsing for dma-ranges from the device's bus node. This is
466 * specially important on nested buses.
468 ret = dev_get_dma_range(parent, &cpu, &bus, &size);
469 /* Don't return an error if no 'dma-ranges' were found */
470 if (ret && ret != -ENOENT) {
471 dm_warn("%s: failed to get DMA range, %d\n", dev->name, ret);
475 dev_set_dma_offset(dev, cpu - bus);
480 int device_probe(struct udevice *dev)
482 const struct driver *drv;
488 if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
491 ret = device_notify(dev, EVT_DM_PRE_PROBE);
498 ret = device_of_to_plat(dev);
502 /* Ensure all parents are probed */
504 ret = device_probe(dev->parent);
509 * The device might have already been probed during
510 * the call to device_probe() on its parent device
511 * (e.g. PCI bridge devices). Test the flags again
512 * so that we don't mess up the device.
514 if (dev_get_flags(dev) & DM_FLAG_ACTIVATED)
518 dev_or_flags(dev, DM_FLAG_ACTIVATED);
520 if (CONFIG_IS_ENABLED(POWER_DOMAIN) && dev->parent &&
521 (device_get_uclass_id(dev) != UCLASS_POWER_DOMAIN) &&
522 !(drv->flags & DM_FLAG_DEFAULT_PD_CTRL_OFF)) {
523 ret = dev_power_domain_on(dev);
529 * Process pinctrl for everything except the root device, and
530 * continue regardless of the result of pinctrl. Don't process pinctrl
531 * settings for pinctrl devices since the device may not yet be
534 * This call can produce some non-intuitive results. For example, on an
535 * x86 device where dev is the main PCI bus, the pinctrl device may be
536 * child or grandchild of that bus, meaning that the child will be
537 * probed here. If the child happens to be the P2SB and the pinctrl
538 * device is a child of that, then both the pinctrl and P2SB will be
539 * probed by this call. This works because the DM_FLAG_ACTIVATED flag
540 * is set just above. However, the PCI bus' probe() method and
541 * associated uclass methods have not yet been called.
543 if (dev->parent && device_get_uclass_id(dev) != UCLASS_PINCTRL) {
544 ret = pinctrl_select_state(dev, "default");
545 if (ret && ret != -ENOSYS)
546 log_debug("Device '%s' failed to configure default pinctrl: %d (%s)\n",
547 dev->name, ret, errno_str(ret));
550 if (CONFIG_IS_ENABLED(IOMMU) && dev->parent &&
551 (device_get_uclass_id(dev) != UCLASS_IOMMU)) {
552 ret = dev_iommu_enable(dev);
557 ret = device_get_dma_constraints(dev);
561 ret = uclass_pre_probe_device(dev);
565 if (dev->parent && dev->parent->driver->child_pre_probe) {
566 ret = dev->parent->driver->child_pre_probe(dev);
571 /* Only handle devices that have a valid ofnode */
572 if (dev_has_ofnode(dev)) {
574 * Process 'assigned-{clocks/clock-parents/clock-rates}'
577 ret = clk_set_defaults(dev, CLK_DEFAULTS_PRE);
583 ret = drv->probe(dev);
588 ret = uclass_post_probe_device(dev);
592 if (dev->parent && device_get_uclass_id(dev) == UCLASS_PINCTRL) {
593 ret = pinctrl_select_state(dev, "default");
594 if (ret && ret != -ENOSYS)
595 log_debug("Device '%s' failed to configure default pinctrl: %d (%s)\n",
596 dev->name, ret, errno_str(ret));
599 ret = device_notify(dev, EVT_DM_POST_PROBE);
605 if (device_remove(dev, DM_REMOVE_NORMAL)) {
606 dm_warn("%s: Device '%s' failed to remove on error path\n",
607 __func__, dev->name);
610 dev_bic_flags(dev, DM_FLAG_ACTIVATED);
617 void *dev_get_plat(const struct udevice *dev)
620 dm_warn("%s: null device\n", __func__);
624 return dm_priv_to_rw(dev->plat_);
627 void *dev_get_parent_plat(const struct udevice *dev)
630 dm_warn("%s: null device\n", __func__);
634 return dm_priv_to_rw(dev->parent_plat_);
637 void *dev_get_uclass_plat(const struct udevice *dev)
640 dm_warn("%s: null device\n", __func__);
644 return dm_priv_to_rw(dev->uclass_plat_);
647 void *dev_get_priv(const struct udevice *dev)
650 dm_warn("%s: null device\n", __func__);
654 return dm_priv_to_rw(dev->priv_);
657 /* notrace is needed as this is called by timer_get_rate() */
658 notrace void *dev_get_uclass_priv(const struct udevice *dev)
661 dm_warn("%s: null device\n", __func__);
665 return dm_priv_to_rw(dev->uclass_priv_);
668 void *dev_get_parent_priv(const struct udevice *dev)
671 dm_warn("%s: null device\n", __func__);
675 return dm_priv_to_rw(dev->parent_priv_);
678 void *dev_get_attach_ptr(const struct udevice *dev, enum dm_tag_t tag)
682 return dev_get_plat(dev);
683 case DM_TAG_PARENT_PLAT:
684 return dev_get_parent_plat(dev);
686 return dev_get_uclass_plat(dev);
688 return dev_get_priv(dev);
689 case DM_TAG_PARENT_PRIV:
690 return dev_get_parent_priv(dev);
692 return dev_get_uclass_priv(dev);
698 int dev_get_attach_size(const struct udevice *dev, enum dm_tag_t tag)
700 const struct udevice *parent = dev_get_parent(dev);
701 const struct uclass *uc = dev->uclass;
702 const struct uclass_driver *uc_drv = uc->uc_drv;
703 const struct driver *parent_drv = NULL;
707 parent_drv = parent->driver;
711 size = dev->driver->plat_auto;
713 case DM_TAG_PARENT_PLAT:
715 size = parent_drv->per_child_plat_auto;
717 size = parent->uclass->uc_drv->per_child_plat_auto;
721 size = uc_drv->per_device_plat_auto;
724 size = dev->driver->priv_auto;
726 case DM_TAG_PARENT_PRIV:
728 size = parent_drv->per_child_auto;
730 size = parent->uclass->uc_drv->per_child_auto;
734 size = uc_drv->per_device_auto;
743 static int device_get_device_tail(struct udevice *dev, int ret,
744 struct udevice **devp)
749 ret = device_probe(dev);
758 #if CONFIG_IS_ENABLED(OF_REAL)
760 * device_find_by_ofnode() - Return device associated with given ofnode
762 * The returned device is *not* activated.
764 * @node: The ofnode for which a associated device should be looked up
765 * @devp: Pointer to structure to hold the found device
766 * Return: 0 if OK, -ve on error
768 static int device_find_by_ofnode(ofnode node, struct udevice **devp)
774 list_for_each_entry(uc, gd->uclass_root, sibling_node) {
775 ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node,
787 int device_get_child(const struct udevice *parent, int index,
788 struct udevice **devp)
792 device_foreach_child(dev, parent) {
794 return device_get_device_tail(dev, 0, devp);
800 int device_get_child_count(const struct udevice *parent)
805 device_foreach_child(dev, parent)
811 int device_get_decendent_count(const struct udevice *parent)
813 const struct udevice *dev;
816 device_foreach_child(dev, parent)
817 count += device_get_decendent_count(dev);
822 int device_find_child_by_seq(const struct udevice *parent, int seq,
823 struct udevice **devp)
829 device_foreach_child(dev, parent) {
830 if (dev->seq_ == seq) {
839 int device_get_child_by_seq(const struct udevice *parent, int seq,
840 struct udevice **devp)
846 ret = device_find_child_by_seq(parent, seq, &dev);
848 return device_get_device_tail(dev, ret, devp);
851 int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
852 struct udevice **devp)
858 device_foreach_child(dev, parent) {
859 if (dev_of_offset(dev) == of_offset) {
868 int device_get_child_by_of_offset(const struct udevice *parent, int node,
869 struct udevice **devp)
875 ret = device_find_child_by_of_offset(parent, node, &dev);
876 return device_get_device_tail(dev, ret, devp);
879 static struct udevice *_device_find_global_by_ofnode(struct udevice *parent,
882 struct udevice *dev, *found;
884 if (ofnode_equal(dev_ofnode(parent), ofnode))
887 device_foreach_child(dev, parent) {
888 found = _device_find_global_by_ofnode(dev, ofnode);
896 int device_find_global_by_ofnode(ofnode ofnode, struct udevice **devp)
898 *devp = _device_find_global_by_ofnode(gd->dm_root, ofnode);
900 return *devp ? 0 : -ENOENT;
903 int device_get_global_by_ofnode(ofnode ofnode, struct udevice **devp)
907 dev = _device_find_global_by_ofnode(gd->dm_root, ofnode);
908 return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
911 #if CONFIG_IS_ENABLED(OF_PLATDATA)
912 int device_get_by_ofplat_idx(uint idx, struct udevice **devp)
916 if (CONFIG_IS_ENABLED(OF_PLATDATA_INST)) {
917 struct udevice *base = ll_entry_start(struct udevice, udevice);
921 struct driver_rt *drt = gd_dm_driver_rt() + idx;
927 return device_get_device_tail(dev, dev ? 0 : -ENOENT, devp);
931 int device_find_first_child(const struct udevice *parent, struct udevice **devp)
933 if (list_empty(&parent->child_head)) {
936 *devp = list_first_entry(&parent->child_head, struct udevice,
943 int device_find_next_child(struct udevice **devp)
945 struct udevice *dev = *devp;
946 struct udevice *parent = dev->parent;
948 if (list_is_last(&dev->sibling_node, &parent->child_head)) {
951 *devp = list_entry(dev->sibling_node.next, struct udevice,
958 int device_find_first_inactive_child(const struct udevice *parent,
959 enum uclass_id uclass_id,
960 struct udevice **devp)
965 device_foreach_child(dev, parent) {
966 if (!device_active(dev) &&
967 device_get_uclass_id(dev) == uclass_id) {
976 int device_find_first_child_by_uclass(const struct udevice *parent,
977 enum uclass_id uclass_id,
978 struct udevice **devp)
983 device_foreach_child(dev, parent) {
984 if (device_get_uclass_id(dev) == uclass_id) {
993 int device_find_child_by_namelen(const struct udevice *parent, const char *name,
994 int len, struct udevice **devp)
1000 device_foreach_child(dev, parent) {
1001 if (!strncmp(dev->name, name, len) &&
1002 strlen(dev->name) == len) {
1011 int device_find_child_by_name(const struct udevice *parent, const char *name,
1012 struct udevice **devp)
1014 return device_find_child_by_namelen(parent, name, strlen(name), devp);
1017 int device_first_child_err(struct udevice *parent, struct udevice **devp)
1019 struct udevice *dev;
1021 device_find_first_child(parent, &dev);
1025 return device_get_device_tail(dev, 0, devp);
1028 int device_next_child_err(struct udevice **devp)
1030 struct udevice *dev = *devp;
1032 device_find_next_child(&dev);
1036 return device_get_device_tail(dev, 0, devp);
1039 int device_first_child_ofdata_err(struct udevice *parent, struct udevice **devp)
1041 struct udevice *dev;
1044 device_find_first_child(parent, &dev);
1048 ret = device_of_to_plat(dev);
1057 int device_next_child_ofdata_err(struct udevice **devp)
1059 struct udevice *dev = *devp;
1062 device_find_next_child(&dev);
1066 ret = device_of_to_plat(dev);
1075 struct udevice *dev_get_parent(const struct udevice *child)
1077 return child->parent;
1080 ulong dev_get_driver_data(const struct udevice *dev)
1082 return dev->driver_data;
1085 const void *dev_get_driver_ops(const struct udevice *dev)
1087 if (!dev || !dev->driver->ops)
1090 return dev->driver->ops;
1093 enum uclass_id device_get_uclass_id(const struct udevice *dev)
1095 return dev->uclass->uc_drv->id;
1098 const char *dev_get_uclass_name(const struct udevice *dev)
1103 return dev->uclass->uc_drv->name;
1106 bool device_has_children(const struct udevice *dev)
1108 return !list_empty(&dev->child_head);
1111 bool device_has_active_children(const struct udevice *dev)
1113 struct udevice *child;
1115 for (device_find_first_child(dev, &child);
1117 device_find_next_child(&child)) {
1118 if (device_active(child))
1125 bool device_is_last_sibling(const struct udevice *dev)
1127 struct udevice *parent = dev->parent;
1131 return list_is_last(&dev->sibling_node, &parent->child_head);
1134 void device_set_name_alloced(struct udevice *dev)
1136 dev_or_flags(dev, DM_FLAG_NAME_ALLOCED);
1139 int device_set_name(struct udevice *dev, const char *name)
1141 name = strdup(name);
1145 device_set_name_alloced(dev);
1150 void dev_set_priv(struct udevice *dev, void *priv)
1155 void dev_set_parent_priv(struct udevice *dev, void *parent_priv)
1157 dev->parent_priv_ = parent_priv;
1160 void dev_set_uclass_priv(struct udevice *dev, void *uclass_priv)
1162 dev->uclass_priv_ = uclass_priv;
1165 void dev_set_plat(struct udevice *dev, void *plat)
1170 void dev_set_parent_plat(struct udevice *dev, void *parent_plat)
1172 dev->parent_plat_ = parent_plat;
1175 void dev_set_uclass_plat(struct udevice *dev, void *uclass_plat)
1177 dev->uclass_plat_ = uclass_plat;
1180 #if CONFIG_IS_ENABLED(OF_REAL)
1181 bool device_is_compatible(const struct udevice *dev, const char *compat)
1183 return ofnode_device_is_compatible(dev_ofnode(dev), compat);
1186 bool of_machine_is_compatible(const char *compat)
1188 return ofnode_device_is_compatible(ofnode_root(), compat);
1191 int dev_disable_by_path(const char *path)
1194 ofnode node = ofnode_path(path);
1195 struct udevice *dev;
1198 if (!of_live_active())
1201 list_for_each_entry(uc, gd->uclass_root, sibling_node) {
1202 ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev);
1210 ret = device_remove(dev, DM_REMOVE_NORMAL);
1214 ret = device_unbind(dev);
1218 return ofnode_set_enabled(node, false);
1221 int dev_enable_by_path(const char *path)
1223 ofnode node = ofnode_path(path);
1224 ofnode pnode = ofnode_get_parent(node);
1225 struct udevice *parent;
1228 if (!of_live_active())
1231 ret = device_find_by_ofnode(pnode, &parent);
1235 ret = ofnode_set_enabled(node, true);
1239 return lists_bind_fdt(parent, node, NULL, NULL, false);
1243 #if CONFIG_IS_ENABLED(OF_PLATDATA_RT)
1244 static struct udevice_rt *dev_get_rt(const struct udevice *dev)
1246 struct udevice *base = ll_entry_start(struct udevice, udevice);
1247 uint each_size = dm_udevice_size();
1248 int idx = ((void *)dev - (void *)base) / each_size;
1250 struct udevice_rt *urt = gd_dm_udevice_rt() + idx;
1255 u32 dev_get_flags(const struct udevice *dev)
1257 const struct udevice_rt *urt = dev_get_rt(dev);
1262 void dev_or_flags(const struct udevice *dev, u32 or)
1264 struct udevice_rt *urt = dev_get_rt(dev);
1269 void dev_bic_flags(const struct udevice *dev, u32 bic)
1271 struct udevice_rt *urt = dev_get_rt(dev);
1273 urt->flags_ &= ~bic;
1275 #endif /* OF_PLATDATA_RT */