[U-Boot] [PATCH v2 1/2] clk: clk-uclass: Add post binding for CLK uclass
Wenyou Yang
wenyou.yang at atmel.com
Tue Jun 7 09:11:26 CEST 2016
Add post binding support for CLK uclass to recursively bind
its children as clk devices.
Signed-off-by: Wenyou Yang <wenyou.yang at atmel.com>
---
Changes in v2: None
drivers/clk/clk-uclass.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index b483c1e..ee568e4 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -106,7 +106,58 @@ int clk_get_by_index(struct udevice *dev, int index, struct udevice **clk_devp)
}
#endif
+/**
+ * clk_post-bind() - post binding for CLK uclass
+ * Recursively bind its children as clk devices.
+ *
+ * @dev: clk device
+ * @return: 0 on success, or negative error code on failure
+ */
+static int clk_post_bind(struct udevice *dev)
+{
+ const void *fdt = gd->fdt_blob;
+ int offset = dev->of_offset;
+ bool pre_reloc_only = !(gd->flags & GD_FLG_RELOC);
+ const char *name;
+ int ret;
+
+ for (offset = fdt_first_subnode(fdt, offset);
+ offset > 0;
+ offset = fdt_next_subnode(fdt, offset)) {
+ if (pre_reloc_only &&
+ !fdt_getprop(fdt, offset, "u-boot,dm-pre-reloc", NULL))
+ continue;
+ /*
+ * If this node has "compatible" property, this is not a clk
+ * node, but a normal device. skip.
+ */
+ fdt_get_property(fdt, offset, "compatible", &ret);
+ if (ret >= 0)
+ continue;
+
+ if (ret != -FDT_ERR_NOTFOUND)
+ return ret;
+
+ name = fdt_get_name(fdt, offset, NULL);
+ if (!name)
+ return -EINVAL;
+
+ ret = device_bind_driver_to_node(dev, "clk", name,
+ offset, NULL);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
UCLASS_DRIVER(clk) = {
.id = UCLASS_CLK,
+ .post_bind = clk_post_bind,
.name = "clk",
};
+
+U_BOOT_DRIVER(clk_generic) = {
+ .id = UCLASS_CLK,
+ .name = "clk",
+};
--
2.7.4
More information about the U-Boot
mailing list