Skip to content

Commit a00d47f

Browse files
committed
soc: renesas: rmobile-sysc: Convert to readl_poll_timeout_atomic()
Use readl_poll_timeout_atomic() instead of open-coding the same operation. 1. rmobile_pd_power_down(): as typically less than 20 retries are needed, PSTR_RETRIES (100) µs is a suitable timeout value. 2. __rmobile_pd_power_up(): the old method of first polling some cycles with a 1 µs delay, followed by more polling cycles without any delay didn't make much sense, as the latter was insignificant compared to the former. Furthermore, typically no retries are needed. Hence just retain the polling with delay. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/ae4bf03ab8fd5a557c683086958d6764babc0723.1685692810.git.geert+renesas@glider.be
1 parent a1b1dd7 commit a00d47f

1 file changed

Lines changed: 9 additions & 20 deletions

File tree

drivers/soc/renesas/rmobile-sysc.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#include <linux/clk/renesas.h>
1313
#include <linux/console.h>
1414
#include <linux/delay.h>
15+
#include <linux/io.h>
16+
#include <linux/iopoll.h>
1517
#include <linux/of.h>
1618
#include <linux/of_address.h>
1719
#include <linux/pm.h>
1820
#include <linux/pm_clock.h>
1921
#include <linux/pm_domain.h>
2022
#include <linux/slab.h>
2123

22-
#include <asm/io.h>
23-
2424
/* SYSC */
2525
#define SPDCR 0x08 /* SYS Power Down Control Register */
2626
#define SWUCR 0x14 /* SYS Wakeup Control Register */
@@ -47,6 +47,7 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
4747
{
4848
struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
4949
unsigned int mask = BIT(rmobile_pd->bit_shift);
50+
u32 val;
5051

5152
if (rmobile_pd->suspend) {
5253
int ret = rmobile_pd->suspend();
@@ -56,14 +57,10 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
5657
}
5758

5859
if (readl(rmobile_pd->base + PSTR) & mask) {
59-
unsigned int retry_count;
6060
writel(mask, rmobile_pd->base + SPDCR);
6161

62-
for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
63-
if (!(readl(rmobile_pd->base + SPDCR) & mask))
64-
break;
65-
cpu_relax();
66-
}
62+
readl_poll_timeout_atomic(rmobile_pd->base + SPDCR, val,
63+
!(val & mask), 0, PSTR_RETRIES);
6764
}
6865

6966
pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n", genpd->name, mask,
@@ -74,25 +71,17 @@ static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
7471

7572
static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd)
7673
{
77-
unsigned int mask = BIT(rmobile_pd->bit_shift);
78-
unsigned int retry_count;
74+
unsigned int val, mask = BIT(rmobile_pd->bit_shift);
7975
int ret = 0;
8076

8177
if (readl(rmobile_pd->base + PSTR) & mask)
8278
return ret;
8379

8480
writel(mask, rmobile_pd->base + SWUCR);
8581

86-
for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
87-
if (!(readl(rmobile_pd->base + SWUCR) & mask))
88-
break;
89-
if (retry_count > PSTR_RETRIES)
90-
udelay(PSTR_DELAY_US);
91-
else
92-
cpu_relax();
93-
}
94-
if (!retry_count)
95-
ret = -EIO;
82+
ret = readl_poll_timeout_atomic(rmobile_pd->base + SWUCR, val,
83+
(val & mask), PSTR_DELAY_US,
84+
PSTR_RETRIES * PSTR_DELAY_US);
9685

9786
pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
9887
rmobile_pd->genpd.name, mask,

0 commit comments

Comments
 (0)