[U-Boot] [PATCH v2 3/4] core: Add dev_{disable,enable}_by_path
Mario Six
mario.six at gdsys.cc
Fri Apr 27 12:51:48 UTC 2018
We cannot use device structures to disable devices, since getting
them with the API functions would bind and activate the device, which
would fail if the underlying device does not exist.
Hence, add a function to disable devices by path in a live device tree.
Signed-off-by: Mario Six <mario.six at gdsys.cc>
---
v1 -> v2:
* Simplified np_to_ofnode(of_find_node_by_path(path)) to ofnode_path(path)
* Switched to returning -ENOSYS if livetree is not enabled
* Removed device_find_by_ofnode usage
---
drivers/core/device.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++
include/dm/device.h | 20 ++++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 940a153c58..3bb2fa02af 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -724,3 +724,61 @@ bool of_machine_is_compatible(const char *compat)
return !fdt_node_check_compatible(fdt, 0, compat);
}
+
+int dev_disable_by_path(const char *path)
+{
+ struct uclass *uc;
+ ofnode node = ofnode_path(path);
+ struct udevice *dev;
+ int res = 1;
+
+ if (!of_live_active())
+ return -ENOSYS;
+
+ list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ res = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev);
+ if (!res || dev)
+ break;
+ }
+
+ if (res || !dev)
+ return res;
+
+ res = device_remove(dev, DM_REMOVE_NORMAL);
+ if (res)
+ return res;
+
+ res = device_unbind(dev);
+ if (res)
+ return res;
+
+ return ofnode_set_enabled(node, false);
+}
+
+int dev_enable_by_path(const char *path)
+{
+ struct uclass *uc;
+ ofnode node = ofnode_path(path);
+ ofnode pnode = ofnode_get_parent(node);
+ struct udevice *parent;
+ int res = 1;
+
+ if (!of_live_active())
+ return -ENOSYS;
+
+ list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ res = uclass_find_device_by_ofnode(uc->uc_drv->id, pnode,
+ &parent);
+ if (!res || parent)
+ break;
+ }
+
+ if (res || !parent)
+ return res;
+
+ res = ofnode_set_enabled(node, true);
+ if (res)
+ return res;
+
+ return lists_bind_fdt(parent, node, NULL);
+}
diff --git a/include/dm/device.h b/include/dm/device.h
index 7786b1cf4e..f55907966a 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -586,6 +586,26 @@ bool device_is_compatible(struct udevice *dev, const char *compat);
*/
bool of_machine_is_compatible(const char *compat);
+#ifdef CONFIG_OF_LIVE
+
+/**
+ * dev_disable_by_path() - Disable a device given its device tree path
+ *
+ * @path: The device tree path identifying the device to be disabled
+ * @return 0 on success, -ve on error
+ */
+int dev_disable_by_path(const char *path);
+
+/**
+ * dev_enable_by_path() - Enable a device given its device tree path
+ *
+ * @path: The device tree path identifying the device to be enabled
+ * @return 0 on success, -ve on error
+ */
+int dev_enable_by_path(const char *path);
+
+#endif /* CONFIG_OF_LIVE */
+
/**
* device_is_on_pci_bus - Test if a device is on a PCI bus
*
--
2.16.1
More information about the U-Boot
mailing list