[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250525190806.1204531-3-edgar.iglesias@gmail.com>
Date: Sun, 25 May 2025 21:08:04 +0200
From: "Edgar E. Iglesias" <edgar.iglesias@...il.com>
To: mturquette@...libre.com,
sboyd@...nel.org,
robh@...nel.org,
krzk+dt@...nel.org,
conor+dt@...nel.org,
jank@...ence.com
Cc: edgar.iglesias@....com,
linux-clk@...r.kernel.org,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH v1 2/2] clk: fixed-mmio: Add optional poll for clk readiness
From: "Edgar E. Iglesias" <edgar.iglesias@....com>
Add optional poll for clk readiness prior to reading the fixed rate.
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@....com>
---
drivers/clk/clk-fixed-mmio.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/drivers/clk/clk-fixed-mmio.c b/drivers/clk/clk-fixed-mmio.c
index 3bfcf4cd98a2..4b5ba1ad06ac 100644
--- a/drivers/clk/clk-fixed-mmio.c
+++ b/drivers/clk/clk-fixed-mmio.c
@@ -11,10 +11,36 @@
#include <linux/clk-provider.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/platform_device.h>
+static int fixed_mmio_clk_wait_ready(struct device_node *node,
+ void __iomem *base)
+{
+ u32 ready_mask;
+ u32 ready_val;
+ u32 timeout;
+ u32 v;
+
+ if (of_property_read_u32(node, "ready-timeout", &timeout))
+ timeout = 0;
+
+ if (of_property_read_u32(node, "ready-mask", &ready_mask))
+ ready_mask = ~0;
+
+ if (of_property_read_u32(node, "ready-val", &ready_val)) {
+ pr_err("%pOFn: missing ready-val property\n", node);
+ return -EINVAL;
+ }
+
+ pr_info("%pOFn: wait for clock\n", node);
+ return readl_relaxed_poll_timeout_atomic(base, v,
+ (v & ready_mask) == ready_val,
+ 1, timeout);
+}
+
static struct clk_hw *fixed_mmio_clk_setup(struct device_node *node)
{
struct clk_hw *clk;
@@ -23,6 +49,15 @@ static struct clk_hw *fixed_mmio_clk_setup(struct device_node *node)
u32 freq;
int ret;
+ base = of_iomap(node, 1);
+ if (base) {
+ /* Wait for clk to get ready. */
+ ret = fixed_mmio_clk_wait_ready(node, base);
+ iounmap(base);
+ if (ret)
+ return ERR_PTR(ret);
+ }
+
base = of_iomap(node, 0);
if (!base) {
pr_err("%pOFn: failed to map address\n", node);
--
2.43.0
Powered by blists - more mailing lists