From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mario Six Date: Wed, 28 Mar 2018 14:37:15 +0200 Subject: [U-Boot] [PATCH 3/3] core: Add dev_{disable,enable}_by_path In-Reply-To: <20180328123715.15861-1-mario.six@gdsys.cc> References: <20180328123715.15861-1-mario.six@gdsys.cc> Message-ID: <20180328123715.15861-3-mario.six@gdsys.cc> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- drivers/core/device.c | 36 ++++++++++++++++++++++++++++++++++++ include/dm/device.h | 20 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/core/device.c b/drivers/core/device.c index 940a153c58..c627453bb9 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -724,3 +724,39 @@ bool of_machine_is_compatible(const char *compat) return !fdt_node_check_compatible(fdt, 0, compat); } + +#ifdef CONFIG_OF_LIVE +int dev_disable_by_path(const char *path) +{ + ofnode node = np_to_ofnode(of_find_node_by_path(path)); + struct udevice *dev = ofnode_dev(node); + int res; + + res = device_remove(dev, DM_REMOVE_NORMAL); + if (res) + return res; + + res = device_unbind(dev); + if (res) + return res; + + return ofnode_disable(node); +} + +int dev_enable_by_path(const char *path) +{ + ofnode node = np_to_ofnode(of_find_node_by_path(path)); + ofnode pnode = ofnode_get_parent(node); + struct udevice *parent = ofnode_dev(pnode); + int res; + + if (!parent) + return -EINVAL; + + res = ofnode_enable(node); + if (res) + return res; + + return lists_bind_fdt(parent, node, NULL); +} +#endif /* CONFIG_OF_LIVE */ 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