Skip to content

Commit c6a5181

Browse files
committed
Merge tag 'renesas-drivers-for-v6.5-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel into soc/drivers
Renesas driver updates for v6.5 (take two) - Convert the R-Mobile SYSC driver to readl_poll_timeout_atomic(). * tag 'renesas-drivers-for-v6.5-tag2' of git://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel: soc: renesas: rmobile-sysc: Convert to readl_poll_timeout_atomic() iopoll: Do not use timekeeping in read_poll_timeout_atomic() iopoll: Call cpu_relax() in busy loops Link: https://lore.kernel.org/r/cover.1686304612.git.geert+renesas@glider.be Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2 parents edc24de + a00d47f commit c6a5181

2 files changed

Lines changed: 28 additions & 25 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,

include/linux/iopoll.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
} \
5454
if (__sleep_us) \
5555
usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
56+
cpu_relax(); \
5657
} \
5758
(cond) ? 0 : -ETIMEDOUT; \
5859
})
@@ -73,28 +74,41 @@
7374
* Returns 0 on success and -ETIMEDOUT upon a timeout. In either
7475
* case, the last read value at @args is stored in @val.
7576
*
77+
* This macro does not rely on timekeeping. Hence it is safe to call even when
78+
* timekeeping is suspended, at the expense of an underestimation of wall clock
79+
* time, which is rather minimal with a non-zero delay_us.
80+
*
7681
* When available, you'll probably want to use one of the specialized
7782
* macros defined below rather than this macro directly.
7883
*/
7984
#define read_poll_timeout_atomic(op, val, cond, delay_us, timeout_us, \
8085
delay_before_read, args...) \
8186
({ \
8287
u64 __timeout_us = (timeout_us); \
88+
s64 __left_ns = __timeout_us * NSEC_PER_USEC; \
8389
unsigned long __delay_us = (delay_us); \
84-
ktime_t __timeout = ktime_add_us(ktime_get(), __timeout_us); \
85-
if (delay_before_read && __delay_us) \
90+
u64 __delay_ns = __delay_us * NSEC_PER_USEC; \
91+
if (delay_before_read && __delay_us) { \
8692
udelay(__delay_us); \
93+
if (__timeout_us) \
94+
__left_ns -= __delay_ns; \
95+
} \
8796
for (;;) { \
8897
(val) = op(args); \
8998
if (cond) \
9099
break; \
91-
if (__timeout_us && \
92-
ktime_compare(ktime_get(), __timeout) > 0) { \
100+
if (__timeout_us && __left_ns < 0) { \
93101
(val) = op(args); \
94102
break; \
95103
} \
96-
if (__delay_us) \
104+
if (__delay_us) { \
97105
udelay(__delay_us); \
106+
if (__timeout_us) \
107+
__left_ns -= __delay_ns; \
108+
} \
109+
cpu_relax(); \
110+
if (__timeout_us) \
111+
__left_ns--; \
98112
} \
99113
(cond) ? 0 : -ETIMEDOUT; \
100114
})

0 commit comments

Comments
 (0)