[U-Boot] [RFC 14/35] reset: sunxi: a64: Bind reset from clock driver

Jagan Teki jagan at amarulasolutions.com
Mon Jul 16 11:28:29 UTC 2018


Since clock and reset drivers have same DT node,
we cann't follow another binding for reset so bind
the reset driver from clock driver.

Binding here rely on name of the uclass driver rather
than matching id.

So, this patch will pick the clock driver name as input
and replace the sunfix ccu with reset. This logic is
suggested by 'Chakra Divi'

Signed-off-by: Chakra Divi <chakra at openedev.com>
Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
 arch/arm/include/asm/arch-sunxi/clock.h |  8 +++++
 drivers/clk/sunxi/Makefile              |  1 +
 drivers/clk/sunxi/clk_a64.c             |  1 +
 drivers/clk/sunxi/clk_sunxi.c           | 39 +++++++++++++++++++++++++
 4 files changed, 49 insertions(+)
 create mode 100644 drivers/clk/sunxi/clk_sunxi.c

diff --git a/arch/arm/include/asm/arch-sunxi/clock.h b/arch/arm/include/asm/arch-sunxi/clock.h
index 46c3eed377..f8c5cb3fc5 100644
--- a/arch/arm/include/asm/arch-sunxi/clock.h
+++ b/arch/arm/include/asm/arch-sunxi/clock.h
@@ -34,4 +34,12 @@ void clock_init_sec(void);
 void clock_init_uart(void);
 #endif
 
+/*
+ * sunxi_clk_bind() - Bind reset device as child of clock device
+ *
+ * @cdev:	clock udevice
+ * @return 0 success, or error value
+ */
+int sunxi_clk_bind(struct udevice *cdev);
+
 #endif /* _SUNXI_CLOCK_H */
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index fc9da34208..860bb6dfea 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -4,4 +4,5 @@
 # SPDX-License-Identifier:      GPL-2.0+
 #
 
+obj-$(CONFIG_CLK_SUNXI) += clk_sunxi.o
 obj-$(CONFIG_CLK_SUN50I_A64) += clk_a64.o
diff --git a/drivers/clk/sunxi/clk_a64.c b/drivers/clk/sunxi/clk_a64.c
index 3997432260..42d5974262 100644
--- a/drivers/clk/sunxi/clk_a64.c
+++ b/drivers/clk/sunxi/clk_a64.c
@@ -137,4 +137,5 @@ U_BOOT_DRIVER(clk_sun50i_a64) = {
 	.ofdata_to_platdata	= a64_clk_ofdata_to_platdata,
 	.ops		= &a64_clk_ops,
 	.probe		= a64_clk_probe,
+	.bind		= sunxi_clk_bind,
 };
diff --git a/drivers/clk/sunxi/clk_sunxi.c b/drivers/clk/sunxi/clk_sunxi.c
new file mode 100644
index 0000000000..ca2544b1a0
--- /dev/null
+++ b/drivers/clk/sunxi/clk_sunxi.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Copyright (C) 2018 Amarula Solutions B.V.
+ * Author: Jagan Teki <jagan at amarulasolutions.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/arch/clock.h>
+#include <dm/lists.h>
+
+int sunxi_clk_bind(struct udevice *cdev)
+{
+	struct udevice *rst_dev;
+	char *dev_name = "reset";
+	char drv_name[30];
+	int ret;
+
+	/**
+	 * reset driver doesn't have separate dt binding, so probe them
+	 * using driver name.
+	 * example: sun50i_a64_ccu is clock driver,
+	 *          sun50i_a64_reset is reset driver.
+	 */
+	strcpy(drv_name, cdev->driver->name);
+	memcpy(&drv_name[strlen(drv_name) - 3], dev_name, strlen(dev_name));
+
+	ret = device_bind_driver_to_node(cdev, drv_name, dev_name,
+					 dev_ofnode(cdev), &rst_dev);
+	if (ret) {
+		debug("Warning: failed to bind (%s) reset driver: ret=%d\n",
+		      drv_name, ret);
+		return ret;
+	}
+
+	return 0;
+}
-- 
2.17.1



More information about the U-Boot mailing list