Skip to content

Commit 14e5366

Browse files
committed
clk: renesas: cpg-mssr: Convert to readl_poll_timeout_atomic()
Use readl_poll_timeout_atomic() instead of open-coding the same operation. As typically no retries are needed, 10 µs is a suitable timeout value. Signed-off-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/832d29fd9aa3239ea949535309d2bdb003d40c9e.1685692810.git.geert+renesas@glider.be
1 parent f267be7 commit 14e5366

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

drivers/clk/renesas/renesas-cpg-mssr.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/device.h>
1818
#include <linux/init.h>
1919
#include <linux/io.h>
20+
#include <linux/iopoll.h>
2021
#include <linux/mod_devicetable.h>
2122
#include <linux/module.h>
2223
#include <linux/of_address.h>
@@ -196,8 +197,8 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
196197
struct device *dev = priv->dev;
197198
u32 bitmask = BIT(bit);
198199
unsigned long flags;
199-
unsigned int i;
200200
u32 value;
201+
int error;
201202

202203
dev_dbg(dev, "MSTP %u%02u/%pC %s\n", reg, bit, hw->clk,
203204
enable ? "ON" : "OFF");
@@ -228,19 +229,13 @@ static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
228229
if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
229230
return 0;
230231

231-
for (i = 1000; i > 0; --i) {
232-
if (!(readl(priv->base + priv->status_regs[reg]) & bitmask))
233-
break;
234-
cpu_relax();
235-
}
236-
237-
if (!i) {
232+
error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg],
233+
value, !(value & bitmask), 0, 10);
234+
if (error)
238235
dev_err(dev, "Failed to enable SMSTP %p[%d]\n",
239236
priv->base + priv->control_regs[reg], bit);
240-
return -ETIMEDOUT;
241-
}
242237

243-
return 0;
238+
return error;
244239
}
245240

246241
static int cpg_mstp_clock_enable(struct clk_hw *hw)
@@ -896,8 +891,9 @@ static int cpg_mssr_suspend_noirq(struct device *dev)
896891
static int cpg_mssr_resume_noirq(struct device *dev)
897892
{
898893
struct cpg_mssr_priv *priv = dev_get_drvdata(dev);
899-
unsigned int reg, i;
894+
unsigned int reg;
900895
u32 mask, oldval, newval;
896+
int error;
901897

902898
/* This is the best we can do to check for the presence of PSCI */
903899
if (!psci_ops.cpu_suspend)
@@ -935,14 +931,9 @@ static int cpg_mssr_resume_noirq(struct device *dev)
935931
if (!mask)
936932
continue;
937933

938-
for (i = 1000; i > 0; --i) {
939-
oldval = readl(priv->base + priv->status_regs[reg]);
940-
if (!(oldval & mask))
941-
break;
942-
cpu_relax();
943-
}
944-
945-
if (!i)
934+
error = readl_poll_timeout_atomic(priv->base + priv->status_regs[reg],
935+
oldval, !(oldval & mask), 0, 10);
936+
if (error)
946937
dev_warn(dev, "Failed to enable SMSTP%u[0x%x]\n", reg,
947938
oldval & mask);
948939
}

0 commit comments

Comments
 (0)