summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2018-09-30 18:16:51 -0400
committerTom Rini <trini@konsulko.com>2018-09-30 18:16:51 -0400
commitd24c1d0f4da3b081a4fedf7ae2a08790871f08d0 (patch)
tree30051c24000bbb640b6296c8a71a8e05f0cc06e4 /drivers/core
parent2c1e16b9d2e3a6138acf4ffd9866e47ddbe6d453 (diff)
parent31b8217e83a63d1c8c70edcdcdf5aff3b1791640 (diff)
downloadu-boot-d24c1d0f4da3b081a4fedf7ae2a08790871f08d0.tar.gz
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/device.c78
-rw-r--r--drivers/core/ofnode.c70
2 files changed, 148 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index fd59fe1e0f..feed43c8c3 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -516,6 +516,33 @@ static int device_get_device_tail(struct udevice *dev, int ret,
return 0;
}
+/**
+ * device_find_by_ofnode() - Return device associated with given ofnode
+ *
+ * The returned device is *not* activated.
+ *
+ * @node: The ofnode for which a associated device should be looked up
+ * @devp: Pointer to structure to hold the found device
+ * Return: 0 if OK, -ve on error
+ */
+static int device_find_by_ofnode(ofnode node, struct udevice **devp)
+{
+ struct uclass *uc;
+ struct udevice *dev;
+ int ret;
+
+ list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node,
+ &dev);
+ if (!ret || dev) {
+ *devp = dev;
+ return 0;
+ }
+ }
+
+ return -ENODEV;
+}
+
int device_get_child(struct udevice *parent, int index, struct udevice **devp)
{
struct udevice *dev;
@@ -739,3 +766,54 @@ 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 ret = 1;
+
+ if (!of_live_active())
+ return -ENOSYS;
+
+ list_for_each_entry(uc, &gd->uclass_root, sibling_node) {
+ ret = uclass_find_device_by_ofnode(uc->uc_drv->id, node, &dev);
+ if (!ret)
+ break;
+ }
+
+ if (ret)
+ return ret;
+
+ ret = device_remove(dev, DM_REMOVE_NORMAL);
+ if (ret)
+ return ret;
+
+ ret = device_unbind(dev);
+ if (ret)
+ return ret;
+
+ return ofnode_set_enabled(node, false);
+}
+
+int dev_enable_by_path(const char *path)
+{
+ ofnode node = ofnode_path(path);
+ ofnode pnode = ofnode_get_parent(node);
+ struct udevice *parent;
+ int ret = 1;
+
+ if (!of_live_active())
+ return -ENOSYS;
+
+ ret = device_find_by_ofnode(pnode, &parent);
+ if (ret)
+ return ret;
+
+ ret = ofnode_set_enabled(node, true);
+ if (ret)
+ return ret;
+
+ return lists_bind_fdt(parent, node, NULL);
+}
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index a7e1927723..1e354803b0 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -791,3 +791,73 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,
propname, propval, proplen));
}
}
+
+int ofnode_write_prop(ofnode node, const char *propname, int len,
+ const void *value)
+{
+ const struct device_node *np = ofnode_to_np(node);
+ struct property *pp;
+ struct property *pp_last = NULL;
+ struct property *new;
+
+ if (!of_live_active())
+ return -ENOSYS;
+
+ if (!np)
+ return -EINVAL;
+
+ for (pp = np->properties; pp; pp = pp->next) {
+ if (strcmp(pp->name, propname) == 0) {
+ /* Property exists -> change value */
+ pp->value = (void *)value;
+ pp->length = len;
+ return 0;
+ }
+ pp_last = pp;
+ }
+
+ if (!pp_last)
+ return -ENOENT;
+
+ /* Property does not exist -> append new property */
+ new = malloc(sizeof(struct property));
+ if (!new)
+ return -ENOMEM;
+
+ new->name = strdup(propname);
+ if (!new->name)
+ return -ENOMEM;
+
+ new->value = (void *)value;
+ new->length = len;
+ new->next = NULL;
+
+ pp_last->next = new;
+
+ return 0;
+}
+
+int ofnode_write_string(ofnode node, const char *propname, const char *value)
+{
+ if (!of_live_active())
+ return -ENOSYS;
+
+ assert(ofnode_valid(node));
+
+ debug("%s: %s = %s", __func__, propname, value);
+
+ return ofnode_write_prop(node, propname, strlen(value) + 1, value);
+}
+
+int ofnode_set_enabled(ofnode node, bool value)
+{
+ if (!of_live_active())
+ return -ENOSYS;
+
+ assert(ofnode_valid(node));
+
+ if (value)
+ return ofnode_write_string(node, "status", "okay");
+ else
+ return ofnode_write_string(node, "status", "disable");
+}