All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
@ 2021-01-22 11:36 ` Geert Uytterhoeven
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-22 11:36 UTC (permalink / raw)
  To: Magnus Damm
  Cc: Yoshihiro Shimoda, linux-renesas-soc, linux-arm-kernel,
	Geert Uytterhoeven

Replace the open-coded polling loops by calls to the
readl_poll_timeout_atomic() helper macro.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/soc/renesas/rcar-sysc.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/drivers/soc/renesas/rcar-sysc.c b/drivers/soc/renesas/rcar-sysc.c
index a00bb098e1fe7488..4ff2671a699a4a3b 100644
--- a/drivers/soc/renesas/rcar-sysc.c
+++ b/drivers/soc/renesas/rcar-sysc.c
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/soc/renesas/rcar-sysc.h>
 
 #include "rcar-sysc.h"
@@ -44,13 +45,13 @@
 #define PWRER_OFFS		0x14	/* Power Shutoff/Resume Error */
 
 
-#define SYSCSR_RETRIES		100
+#define SYSCSR_TIMEOUT		100
 #define SYSCSR_DELAY_US		1
 
 #define PWRER_RETRIES		100
 #define PWRER_DELAY_US		1
 
-#define SYSCISR_RETRIES		1000
+#define SYSCISR_TIMEOUT		1000
 #define SYSCISR_DELAY_US	1
 
 #define RCAR_PD_ALWAYS_ON	32	/* Always-on power area */
@@ -68,7 +69,8 @@ static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val;
 static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
 {
 	unsigned int sr_bit, reg_offs;
-	int k;
+	u32 val;
+	int ret;
 
 	if (on) {
 		sr_bit = SYSCSR_PONENB;
@@ -79,13 +81,10 @@ static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
 	}
 
 	/* Wait until SYSC is ready to accept a power request */
-	for (k = 0; k < SYSCSR_RETRIES; k++) {
-		if (ioread32(rcar_sysc_base + SYSCSR) & BIT(sr_bit))
-			break;
-		udelay(SYSCSR_DELAY_US);
-	}
-
-	if (k == SYSCSR_RETRIES)
+	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCSR, val,
+					val & BIT(sr_bit), SYSCSR_DELAY_US,
+					SYSCSR_TIMEOUT);
+	if (ret)
 		return -EAGAIN;
 
 	/* Submit power shutoff or power resume request */
@@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
 	unsigned int chan_mask = BIT(sysc_ch->chan_bit);
 	unsigned int status;
 	unsigned long flags;
-	int ret = 0;
-	int k;
+	int k, ret;
 
 	spin_lock_irqsave(&rcar_sysc_lock, flags);
 
@@ -145,13 +143,10 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
 	}
 
 	/* Wait until the power shutoff or resume request has completed * */
-	for (k = 0; k < SYSCISR_RETRIES; k++) {
-		if (ioread32(rcar_sysc_base + SYSCISR) & isr_mask)
-			break;
-		udelay(SYSCISR_DELAY_US);
-	}
-
-	if (k == SYSCISR_RETRIES)
+	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCISR, status,
+					status & isr_mask, SYSCISR_DELAY_US,
+					SYSCISR_TIMEOUT);
+	if (ret)
 		ret = -EIO;
 
 	iowrite32(isr_mask, rcar_sysc_base + SYSCISCR);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
@ 2021-01-22 11:36 ` Geert Uytterhoeven
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-22 11:36 UTC (permalink / raw)
  To: Magnus Damm
  Cc: linux-renesas-soc, Yoshihiro Shimoda, Geert Uytterhoeven,
	linux-arm-kernel

Replace the open-coded polling loops by calls to the
readl_poll_timeout_atomic() helper macro.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/soc/renesas/rcar-sysc.c | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/drivers/soc/renesas/rcar-sysc.c b/drivers/soc/renesas/rcar-sysc.c
index a00bb098e1fe7488..4ff2671a699a4a3b 100644
--- a/drivers/soc/renesas/rcar-sysc.c
+++ b/drivers/soc/renesas/rcar-sysc.c
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/soc/renesas/rcar-sysc.h>
 
 #include "rcar-sysc.h"
@@ -44,13 +45,13 @@
 #define PWRER_OFFS		0x14	/* Power Shutoff/Resume Error */
 
 
-#define SYSCSR_RETRIES		100
+#define SYSCSR_TIMEOUT		100
 #define SYSCSR_DELAY_US		1
 
 #define PWRER_RETRIES		100
 #define PWRER_DELAY_US		1
 
-#define SYSCISR_RETRIES		1000
+#define SYSCISR_TIMEOUT		1000
 #define SYSCISR_DELAY_US	1
 
 #define RCAR_PD_ALWAYS_ON	32	/* Always-on power area */
@@ -68,7 +69,8 @@ static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val;
 static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
 {
 	unsigned int sr_bit, reg_offs;
-	int k;
+	u32 val;
+	int ret;
 
 	if (on) {
 		sr_bit = SYSCSR_PONENB;
@@ -79,13 +81,10 @@ static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
 	}
 
 	/* Wait until SYSC is ready to accept a power request */
-	for (k = 0; k < SYSCSR_RETRIES; k++) {
-		if (ioread32(rcar_sysc_base + SYSCSR) & BIT(sr_bit))
-			break;
-		udelay(SYSCSR_DELAY_US);
-	}
-
-	if (k == SYSCSR_RETRIES)
+	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCSR, val,
+					val & BIT(sr_bit), SYSCSR_DELAY_US,
+					SYSCSR_TIMEOUT);
+	if (ret)
 		return -EAGAIN;
 
 	/* Submit power shutoff or power resume request */
@@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
 	unsigned int chan_mask = BIT(sysc_ch->chan_bit);
 	unsigned int status;
 	unsigned long flags;
-	int ret = 0;
-	int k;
+	int k, ret;
 
 	spin_lock_irqsave(&rcar_sysc_lock, flags);
 
@@ -145,13 +143,10 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
 	}
 
 	/* Wait until the power shutoff or resume request has completed * */
-	for (k = 0; k < SYSCISR_RETRIES; k++) {
-		if (ioread32(rcar_sysc_base + SYSCISR) & isr_mask)
-			break;
-		udelay(SYSCISR_DELAY_US);
-	}
-
-	if (k == SYSCISR_RETRIES)
+	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCISR, status,
+					status & isr_mask, SYSCISR_DELAY_US,
+					SYSCISR_TIMEOUT);
+	if (ret)
 		ret = -EIO;
 
 	iowrite32(isr_mask, rcar_sysc_base + SYSCISCR);
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
  2021-01-22 11:36 ` Geert Uytterhoeven
@ 2021-01-22 19:04   ` Niklas Söderlund
  -1 siblings, 0 replies; 6+ messages in thread
From: Niklas Söderlund @ 2021-01-22 19:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Magnus Damm, Yoshihiro Shimoda, linux-renesas-soc, linux-arm-kernel

Hi Geert,

Thanks for your patch.

On 2021-01-22 12:36:37 +0100, Geert Uytterhoeven wrote:
> Replace the open-coded polling loops by calls to the
> readl_poll_timeout_atomic() helper macro.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/soc/renesas/rcar-sysc.c | 33 ++++++++++++++-------------------
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/soc/renesas/rcar-sysc.c b/drivers/soc/renesas/rcar-sysc.c
> index a00bb098e1fe7488..4ff2671a699a4a3b 100644
> --- a/drivers/soc/renesas/rcar-sysc.c
> +++ b/drivers/soc/renesas/rcar-sysc.c
> @@ -15,6 +15,7 @@
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
>  #include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <linux/soc/renesas/rcar-sysc.h>
>  
>  #include "rcar-sysc.h"
> @@ -44,13 +45,13 @@
>  #define PWRER_OFFS		0x14	/* Power Shutoff/Resume Error */
>  
>  
> -#define SYSCSR_RETRIES		100
> +#define SYSCSR_TIMEOUT		100
>  #define SYSCSR_DELAY_US		1
>  
>  #define PWRER_RETRIES		100
>  #define PWRER_DELAY_US		1
>  
> -#define SYSCISR_RETRIES		1000
> +#define SYSCISR_TIMEOUT		1000
>  #define SYSCISR_DELAY_US	1
>  
>  #define RCAR_PD_ALWAYS_ON	32	/* Always-on power area */
> @@ -68,7 +69,8 @@ static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val;
>  static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
>  {
>  	unsigned int sr_bit, reg_offs;
> -	int k;
> +	u32 val;
> +	int ret;
>  
>  	if (on) {
>  		sr_bit = SYSCSR_PONENB;
> @@ -79,13 +81,10 @@ static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	}
>  
>  	/* Wait until SYSC is ready to accept a power request */
> -	for (k = 0; k < SYSCSR_RETRIES; k++) {
> -		if (ioread32(rcar_sysc_base + SYSCSR) & BIT(sr_bit))
> -			break;
> -		udelay(SYSCSR_DELAY_US);
> -	}
> -
> -	if (k == SYSCSR_RETRIES)
> +	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCSR, val,
> +					val & BIT(sr_bit), SYSCSR_DELAY_US,
> +					SYSCSR_TIMEOUT);
> +	if (ret)
>  		return -EAGAIN;
>  
>  	/* Submit power shutoff or power resume request */
> @@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	unsigned int chan_mask = BIT(sysc_ch->chan_bit);
>  	unsigned int status;
>  	unsigned long flags;
> -	int ret = 0;
> -	int k;
> +	int k, ret;

nit: I would make k an unsigned as it's now only used in incremental 
loops starting at 0.

With or without this unrelated nit,

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

>  
>  	spin_lock_irqsave(&rcar_sysc_lock, flags);
>  
> @@ -145,13 +143,10 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	}
>  
>  	/* Wait until the power shutoff or resume request has completed * */
> -	for (k = 0; k < SYSCISR_RETRIES; k++) {
> -		if (ioread32(rcar_sysc_base + SYSCISR) & isr_mask)
> -			break;
> -		udelay(SYSCISR_DELAY_US);
> -	}
> -
> -	if (k == SYSCISR_RETRIES)
> +	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCISR, status,
> +					status & isr_mask, SYSCISR_DELAY_US,
> +					SYSCISR_TIMEOUT);
> +	if (ret)
>  		ret = -EIO;
>  
>  	iowrite32(isr_mask, rcar_sysc_base + SYSCISCR);
> -- 
> 2.25.1
> 

-- 
Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
@ 2021-01-22 19:04   ` Niklas Söderlund
  0 siblings, 0 replies; 6+ messages in thread
From: Niklas Söderlund @ 2021-01-22 19:04 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-renesas-soc, Yoshihiro Shimoda, Magnus Damm, linux-arm-kernel

Hi Geert,

Thanks for your patch.

On 2021-01-22 12:36:37 +0100, Geert Uytterhoeven wrote:
> Replace the open-coded polling loops by calls to the
> readl_poll_timeout_atomic() helper macro.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  drivers/soc/renesas/rcar-sysc.c | 33 ++++++++++++++-------------------
>  1 file changed, 14 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/soc/renesas/rcar-sysc.c b/drivers/soc/renesas/rcar-sysc.c
> index a00bb098e1fe7488..4ff2671a699a4a3b 100644
> --- a/drivers/soc/renesas/rcar-sysc.c
> +++ b/drivers/soc/renesas/rcar-sysc.c
> @@ -15,6 +15,7 @@
>  #include <linux/slab.h>
>  #include <linux/spinlock.h>
>  #include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <linux/soc/renesas/rcar-sysc.h>
>  
>  #include "rcar-sysc.h"
> @@ -44,13 +45,13 @@
>  #define PWRER_OFFS		0x14	/* Power Shutoff/Resume Error */
>  
>  
> -#define SYSCSR_RETRIES		100
> +#define SYSCSR_TIMEOUT		100
>  #define SYSCSR_DELAY_US		1
>  
>  #define PWRER_RETRIES		100
>  #define PWRER_DELAY_US		1
>  
> -#define SYSCISR_RETRIES		1000
> +#define SYSCISR_TIMEOUT		1000
>  #define SYSCISR_DELAY_US	1
>  
>  #define RCAR_PD_ALWAYS_ON	32	/* Always-on power area */
> @@ -68,7 +69,8 @@ static u32 rcar_sysc_extmask_offs, rcar_sysc_extmask_val;
>  static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
>  {
>  	unsigned int sr_bit, reg_offs;
> -	int k;
> +	u32 val;
> +	int ret;
>  
>  	if (on) {
>  		sr_bit = SYSCSR_PONENB;
> @@ -79,13 +81,10 @@ static int rcar_sysc_pwr_on_off(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	}
>  
>  	/* Wait until SYSC is ready to accept a power request */
> -	for (k = 0; k < SYSCSR_RETRIES; k++) {
> -		if (ioread32(rcar_sysc_base + SYSCSR) & BIT(sr_bit))
> -			break;
> -		udelay(SYSCSR_DELAY_US);
> -	}
> -
> -	if (k == SYSCSR_RETRIES)
> +	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCSR, val,
> +					val & BIT(sr_bit), SYSCSR_DELAY_US,
> +					SYSCSR_TIMEOUT);
> +	if (ret)
>  		return -EAGAIN;
>  
>  	/* Submit power shutoff or power resume request */
> @@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	unsigned int chan_mask = BIT(sysc_ch->chan_bit);
>  	unsigned int status;
>  	unsigned long flags;
> -	int ret = 0;
> -	int k;
> +	int k, ret;

nit: I would make k an unsigned as it's now only used in incremental 
loops starting at 0.

With or without this unrelated nit,

Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

>  
>  	spin_lock_irqsave(&rcar_sysc_lock, flags);
>  
> @@ -145,13 +143,10 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
>  	}
>  
>  	/* Wait until the power shutoff or resume request has completed * */
> -	for (k = 0; k < SYSCISR_RETRIES; k++) {
> -		if (ioread32(rcar_sysc_base + SYSCISR) & isr_mask)
> -			break;
> -		udelay(SYSCISR_DELAY_US);
> -	}
> -
> -	if (k == SYSCISR_RETRIES)
> +	ret = readl_poll_timeout_atomic(rcar_sysc_base + SYSCISR, status,
> +					status & isr_mask, SYSCISR_DELAY_US,
> +					SYSCISR_TIMEOUT);
> +	if (ret)
>  		ret = -EIO;
>  
>  	iowrite32(isr_mask, rcar_sysc_base + SYSCISCR);
> -- 
> 2.25.1
> 

-- 
Regards,
Niklas Söderlund

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
  2021-01-22 19:04   ` Niklas Söderlund
@ 2021-01-25 13:12     ` Geert Uytterhoeven
  -1 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-25 13:12 UTC (permalink / raw)
  To: Niklas Söderlund
  Cc: Geert Uytterhoeven, Magnus Damm, Yoshihiro Shimoda,
	Linux-Renesas, Linux ARM

Hi Niklas,

On Fri, Jan 22, 2021 at 8:04 PM Niklas Söderlund
<niklas.soderlund@ragnatech.se> wrote:
> On 2021-01-22 12:36:37 +0100, Geert Uytterhoeven wrote:
> > Replace the open-coded polling loops by calls to the
> > readl_poll_timeout_atomic() helper macro.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

> > --- a/drivers/soc/renesas/rcar-sysc.c
> > +++ b/drivers/soc/renesas/rcar-sysc.c

> > @@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
> >       unsigned int chan_mask = BIT(sysc_ch->chan_bit);
> >       unsigned int status;
> >       unsigned long flags;
> > -     int ret = 0;
> > -     int k;
> > +     int k, ret;
>
> nit: I would make k an unsigned as it's now only used in incremental
> loops starting at 0.

That was the case before, too, wasn't it? ;-)

> With or without this unrelated nit,
>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Thanks, will make the change.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic()
@ 2021-01-25 13:12     ` Geert Uytterhoeven
  0 siblings, 0 replies; 6+ messages in thread
From: Geert Uytterhoeven @ 2021-01-25 13:12 UTC (permalink / raw)
  To: Niklas Söderlund
  Cc: Linux-Renesas, Yoshihiro Shimoda, Magnus Damm, Linux ARM,
	Geert Uytterhoeven

Hi Niklas,

On Fri, Jan 22, 2021 at 8:04 PM Niklas Söderlund
<niklas.soderlund@ragnatech.se> wrote:
> On 2021-01-22 12:36:37 +0100, Geert Uytterhoeven wrote:
> > Replace the open-coded polling loops by calls to the
> > readl_poll_timeout_atomic() helper macro.
> >
> > Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

> > --- a/drivers/soc/renesas/rcar-sysc.c
> > +++ b/drivers/soc/renesas/rcar-sysc.c

> > @@ -101,8 +100,7 @@ static int rcar_sysc_power(const struct rcar_sysc_ch *sysc_ch, bool on)
> >       unsigned int chan_mask = BIT(sysc_ch->chan_bit);
> >       unsigned int status;
> >       unsigned long flags;
> > -     int ret = 0;
> > -     int k;
> > +     int k, ret;
>
> nit: I would make k an unsigned as it's now only used in incremental
> loops starting at 0.

That was the case before, too, wasn't it? ;-)

> With or without this unrelated nit,
>
> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Thanks, will make the change.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-25 13:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-22 11:36 [PATCH] soc: renesas: rcar-sysc: Use readl_poll_timeout_atomic() Geert Uytterhoeven
2021-01-22 11:36 ` Geert Uytterhoeven
2021-01-22 19:04 ` Niklas Söderlund
2021-01-22 19:04   ` Niklas Söderlund
2021-01-25 13:12   ` Geert Uytterhoeven
2021-01-25 13:12     ` Geert Uytterhoeven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.