linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout
@ 2020-01-28 10:02 Heiko Stuebner
  2020-01-28 10:02 ` [PATCH 2/3] clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout Heiko Stuebner
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Heiko Stuebner @ 2020-01-28 10:02 UTC (permalink / raw)
  To: linux-clk
  Cc: heiko, sboyd, Heiko Stuebner, mturquette, zhangqing,
	linux-kernel, linux-rockchip, linux-arm-kernel,
	christoph.muellner

From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

Instead of open coding the polling of the lock status, use the
handy readl_poll_timeout for this. As the pll locking is normally
blazingly fast and we don't want to incur additional delays, we're
not doing any sleeps similar to for example the imx clk-pllv4
and define a very safe but still short timeout of 1ms.

Suggested-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
---
 drivers/clk/rockchip/clk-pll.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 198417d56300..43c9fd0086a2 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -585,19 +585,18 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
 static int rockchip_rk3399_pll_wait_lock(struct rockchip_clk_pll *pll)
 {
 	u32 pllcon;
-	int delay = 24000000;
+	int ret;
 
-	/* poll check the lock status in rk3399 xPLLCON2 */
-	while (delay > 0) {
-		pllcon = readl_relaxed(pll->reg_base + RK3399_PLLCON(2));
-		if (pllcon & RK3399_PLLCON2_LOCK_STATUS)
-			return 0;
+	/*
+	 * Lock time typical 250, max 500 input clock cycles @24MHz
+	 * So define a very safe maximum of 1000us, meaning 24000 cycles.
+	 */
+	ret = readl_poll_timeout(pll->reg_base + RK3399_PLLCON(2), pllcon,
+				 pllcon & RK3399_PLLCON2_LOCK_STATUS, 0, 1000);
+	if (ret)
+		pr_err("%s: timeout waiting for pll to lock\n", __func__);
 
-		delay--;
-	}
-
-	pr_err("%s: timeout waiting for pll to lock\n", __func__);
-	return -ETIMEDOUT;
+	return ret;
 }
 
 static void rockchip_rk3399_pll_get_params(struct rockchip_clk_pll *pll,
-- 
2.24.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

* [PATCH 2/3] clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout
  2020-01-28 10:02 [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Heiko Stuebner
@ 2020-01-28 10:02 ` Heiko Stuebner
  2020-01-28 10:02 ` [PATCH 3/3] clk: rockchip: convert rk3036 pll type to use internal lock status Heiko Stuebner
  2020-01-28 15:28 ` [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Robin Murphy
  2 siblings, 0 replies; 6+ messages in thread
From: Heiko Stuebner @ 2020-01-28 10:02 UTC (permalink / raw)
  To: linux-clk
  Cc: heiko, sboyd, Heiko Stuebner, mturquette, zhangqing,
	linux-kernel, linux-rockchip, linux-arm-kernel,
	christoph.muellner

From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

Instead of open coding the polling of the lock status, use the
handy regmap_read_poll_timeout for this. As the pll locking is
normally blazingly fast and we don't want to incur additional
delays, we're not doing any sleeps similar to for example the imx
clk-pllv4 and define a very safe but still short timeout of 1ms.

Suggested-by: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
---
 drivers/clk/rockchip/clk-pll.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 43c9fd0086a2..26ca46d49191 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -86,23 +86,14 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
 {
 	struct regmap *grf = pll->ctx->grf;
 	unsigned int val;
-	int delay = 24000000, ret;
-
-	while (delay > 0) {
-		ret = regmap_read(grf, pll->lock_offset, &val);
-		if (ret) {
-			pr_err("%s: failed to read pll lock status: %d\n",
-			       __func__, ret);
-			return ret;
-		}
+	int ret;
 
-		if (val & BIT(pll->lock_shift))
-			return 0;
-		delay--;
-	}
+	ret = regmap_read_poll_timeout(grf, pll->lock_offset, val,
+				       val & BIT(pll->lock_shift), 0, 1000);
+	if (ret)
+		pr_err("%s: timeout waiting for pll to lock\n", __func__);
 
-	pr_err("%s: timeout waiting for pll to lock\n", __func__);
-	return -ETIMEDOUT;
+	return ret;
 }
 
 /**
-- 
2.24.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

* [PATCH 3/3] clk: rockchip: convert rk3036 pll type to use internal lock status
  2020-01-28 10:02 [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Heiko Stuebner
  2020-01-28 10:02 ` [PATCH 2/3] clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout Heiko Stuebner
@ 2020-01-28 10:02 ` Heiko Stuebner
  2020-01-28 15:28 ` [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Robin Murphy
  2 siblings, 0 replies; 6+ messages in thread
From: Heiko Stuebner @ 2020-01-28 10:02 UTC (permalink / raw)
  To: linux-clk
  Cc: heiko, sboyd, Heiko Stuebner, mturquette, zhangqing,
	linux-kernel, linux-rockchip, linux-arm-kernel,
	christoph.muellner

From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

The rk3036 pll type exposes its lock status in both its pllcon registers
as well as the General Register Files. To remove one dependency convert
it to the "internal" lock status, similar to how rk3399 handles it.

Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
---
 drivers/clk/rockchip/clk-pll.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
index 26ca46d49191..a677f1f8fac7 100644
--- a/drivers/clk/rockchip/clk-pll.c
+++ b/drivers/clk/rockchip/clk-pll.c
@@ -12,6 +12,7 @@
 #include <linux/io.h>
 #include <linux/delay.h>
 #include <linux/clk-provider.h>
+#include <linux/iopoll.h>
 #include <linux/regmap.h>
 #include <linux/clk.h>
 #include "clk.h"
@@ -109,12 +110,29 @@ static int rockchip_pll_wait_lock(struct rockchip_clk_pll *pll)
 #define RK3036_PLLCON1_REFDIV_SHIFT		0
 #define RK3036_PLLCON1_POSTDIV2_MASK		0x7
 #define RK3036_PLLCON1_POSTDIV2_SHIFT		6
+#define RK3036_PLLCON1_LOCK_STATUS		BIT(10)
 #define RK3036_PLLCON1_DSMPD_MASK		0x1
 #define RK3036_PLLCON1_DSMPD_SHIFT		12
+#define RK3036_PLLCON1_PWRDOWN			BIT(13)
 #define RK3036_PLLCON2_FRAC_MASK		0xffffff
 #define RK3036_PLLCON2_FRAC_SHIFT		0
 
-#define RK3036_PLLCON1_PWRDOWN			(1 << 13)
+static int rockchip_rk3036_pll_wait_lock(struct rockchip_clk_pll *pll)
+{
+	u32 pllcon;
+	int ret;
+
+	/*
+	 * Lock time typical 250, max 500 input clock cycles @24MHz
+	 * So define a very safe maximum of 1000us, meaning 24000 cycles.
+	 */
+	ret = readl_poll_timeout(pll->reg_base + RK3036_PLLCON(1), pllcon,
+				 pllcon & RK3036_PLLCON1_LOCK_STATUS, 0, 1000);
+	if (ret)
+		pr_err("%s: timeout waiting for pll to lock\n", __func__);
+
+	return ret;
+}
 
 static void rockchip_rk3036_pll_get_params(struct rockchip_clk_pll *pll,
 					struct rockchip_pll_rate_table *rate)
@@ -212,7 +230,7 @@ static int rockchip_rk3036_pll_set_params(struct rockchip_clk_pll *pll,
 	writel_relaxed(pllcon, pll->reg_base + RK3036_PLLCON(2));
 
 	/* wait for the pll to lock */
-	ret = rockchip_pll_wait_lock(pll);
+	ret = rockchip_rk3036_pll_wait_lock(pll);
 	if (ret) {
 		pr_warn("%s: pll update unsuccessful, trying to restore old params\n",
 			__func__);
@@ -251,7 +269,7 @@ static int rockchip_rk3036_pll_enable(struct clk_hw *hw)
 
 	writel(HIWORD_UPDATE(0, RK3036_PLLCON1_PWRDOWN, 0),
 	       pll->reg_base + RK3036_PLLCON(1));
-	rockchip_pll_wait_lock(pll);
+	rockchip_rk3036_pll_wait_lock(pll);
 
 	return 0;
 }
-- 
2.24.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 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout
  2020-01-28 10:02 [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Heiko Stuebner
  2020-01-28 10:02 ` [PATCH 2/3] clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout Heiko Stuebner
  2020-01-28 10:02 ` [PATCH 3/3] clk: rockchip: convert rk3036 pll type to use internal lock status Heiko Stuebner
@ 2020-01-28 15:28 ` Robin Murphy
  2020-01-28 16:29   ` Heiko Stuebner
  2 siblings, 1 reply; 6+ messages in thread
From: Robin Murphy @ 2020-01-28 15:28 UTC (permalink / raw)
  To: Heiko Stuebner, linux-clk
  Cc: sboyd, Heiko Stuebner, mturquette, zhangqing, linux-kernel,
	linux-rockchip, linux-arm-kernel, christoph.muellner

On 28/01/2020 10:02 am, Heiko Stuebner wrote:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> 
> Instead of open coding the polling of the lock status, use the
> handy readl_poll_timeout for this. As the pll locking is normally
> blazingly fast and we don't want to incur additional delays, we're
> not doing any sleeps similar to for example the imx clk-pllv4
> and define a very safe but still short timeout of 1ms.
> 
> Suggested-by: Stephen Boyd <sboyd@kernel.org>
> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> ---
>   drivers/clk/rockchip/clk-pll.c | 21 ++++++++++-----------
>   1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> index 198417d56300..43c9fd0086a2 100644
> --- a/drivers/clk/rockchip/clk-pll.c
> +++ b/drivers/clk/rockchip/clk-pll.c
> @@ -585,19 +585,18 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
>   static int rockchip_rk3399_pll_wait_lock(struct rockchip_clk_pll *pll)
>   {
>   	u32 pllcon;
> -	int delay = 24000000;
> +	int ret;
>   
> -	/* poll check the lock status in rk3399 xPLLCON2 */
> -	while (delay > 0) {
> -		pllcon = readl_relaxed(pll->reg_base + RK3399_PLLCON(2));
> -		if (pllcon & RK3399_PLLCON2_LOCK_STATUS)
> -			return 0;
> +	/*
> +	 * Lock time typical 250, max 500 input clock cycles @24MHz
> +	 * So define a very safe maximum of 1000us, meaning 24000 cycles.
> +	 */
> +	ret = readl_poll_timeout(pll->reg_base + RK3399_PLLCON(2), pllcon,
> +				 pllcon & RK3399_PLLCON2_LOCK_STATUS, 0, 1000);

Note that the existing I/O accessor was readl_relaxed(), but using plain 
readl_poll_timeout() switches it to regular readl(). It may well not 
matter, but since it's not noted as an intentional change it seemed 
worth pointing out.

Robin.

> +	if (ret)
> +		pr_err("%s: timeout waiting for pll to lock\n", __func__);
>   
> -		delay--;
> -	}
> -
> -	pr_err("%s: timeout waiting for pll to lock\n", __func__);
> -	return -ETIMEDOUT;
> +	return ret;
>   }
>   
>   static void rockchip_rk3399_pll_get_params(struct rockchip_clk_pll *pll,
> 

_______________________________________________
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 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout
  2020-01-28 15:28 ` [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Robin Murphy
@ 2020-01-28 16:29   ` Heiko Stuebner
  2020-01-28 18:43     ` Robin Murphy
  0 siblings, 1 reply; 6+ messages in thread
From: Heiko Stuebner @ 2020-01-28 16:29 UTC (permalink / raw)
  To: Robin Murphy
  Cc: sboyd, mturquette, zhangqing, linux-kernel, linux-rockchip,
	linux-clk, linux-arm-kernel, christoph.muellner

Am Dienstag, 28. Januar 2020, 16:28:44 CET schrieb Robin Murphy:
> On 28/01/2020 10:02 am, Heiko Stuebner wrote:
> > From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> > 
> > Instead of open coding the polling of the lock status, use the
> > handy readl_poll_timeout for this. As the pll locking is normally
> > blazingly fast and we don't want to incur additional delays, we're
> > not doing any sleeps similar to for example the imx clk-pllv4
> > and define a very safe but still short timeout of 1ms.
> > 
> > Suggested-by: Stephen Boyd <sboyd@kernel.org>
> > Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> > ---
> >   drivers/clk/rockchip/clk-pll.c | 21 ++++++++++-----------
> >   1 file changed, 10 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
> > index 198417d56300..43c9fd0086a2 100644
> > --- a/drivers/clk/rockchip/clk-pll.c
> > +++ b/drivers/clk/rockchip/clk-pll.c
> > @@ -585,19 +585,18 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
> >   static int rockchip_rk3399_pll_wait_lock(struct rockchip_clk_pll *pll)
> >   {
> >   	u32 pllcon;
> > -	int delay = 24000000;
> > +	int ret;
> >   
> > -	/* poll check the lock status in rk3399 xPLLCON2 */
> > -	while (delay > 0) {
> > -		pllcon = readl_relaxed(pll->reg_base + RK3399_PLLCON(2));
> > -		if (pllcon & RK3399_PLLCON2_LOCK_STATUS)
> > -			return 0;
> > +	/*
> > +	 * Lock time typical 250, max 500 input clock cycles @24MHz
> > +	 * So define a very safe maximum of 1000us, meaning 24000 cycles.
> > +	 */
> > +	ret = readl_poll_timeout(pll->reg_base + RK3399_PLLCON(2), pllcon,
> > +				 pllcon & RK3399_PLLCON2_LOCK_STATUS, 0, 1000);
> 
> Note that the existing I/O accessor was readl_relaxed(), but using plain 
> readl_poll_timeout() switches it to regular readl(). It may well not 
> matter, but since it's not noted as an intentional change it seemed 
> worth pointing out.

So we end up with an additional __iormb() after each readl_relaxed call.
So except for a small speed-penalty per iteration is there some other
memory-barrier wirednes that could come into play? (Somehow I always
forget the contents of Will's memory-barrier talks after a time)


From a bit of non-scientific testing, rk3328 seems to need at max 20
iterations in the wait_lock loop for the pll to lock, when doing cpufreq
scaling.

While interestingly px30 takes somewhere between 900 and 2000 iterations
on the same pll type.
[Though sleeps are not really possible anyway due to pll rates also getting
set during of_clk_register early during boot which results in errors about
scheduling the idle thread, so in the end it doesn't really matter]

Heiko



_______________________________________________
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 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout
  2020-01-28 16:29   ` Heiko Stuebner
@ 2020-01-28 18:43     ` Robin Murphy
  0 siblings, 0 replies; 6+ messages in thread
From: Robin Murphy @ 2020-01-28 18:43 UTC (permalink / raw)
  To: Heiko Stuebner
  Cc: sboyd, mturquette, zhangqing, linux-kernel, linux-rockchip,
	linux-clk, linux-arm-kernel, christoph.muellner

On 28/01/2020 4:29 pm, Heiko Stuebner wrote:
> Am Dienstag, 28. Januar 2020, 16:28:44 CET schrieb Robin Murphy:
>> On 28/01/2020 10:02 am, Heiko Stuebner wrote:
>>> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>>>
>>> Instead of open coding the polling of the lock status, use the
>>> handy readl_poll_timeout for this. As the pll locking is normally
>>> blazingly fast and we don't want to incur additional delays, we're
>>> not doing any sleeps similar to for example the imx clk-pllv4
>>> and define a very safe but still short timeout of 1ms.
>>>
>>> Suggested-by: Stephen Boyd <sboyd@kernel.org>
>>> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>>> ---
>>>    drivers/clk/rockchip/clk-pll.c | 21 ++++++++++-----------
>>>    1 file changed, 10 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
>>> index 198417d56300..43c9fd0086a2 100644
>>> --- a/drivers/clk/rockchip/clk-pll.c
>>> +++ b/drivers/clk/rockchip/clk-pll.c
>>> @@ -585,19 +585,18 @@ static const struct clk_ops rockchip_rk3066_pll_clk_ops = {
>>>    static int rockchip_rk3399_pll_wait_lock(struct rockchip_clk_pll *pll)
>>>    {
>>>    	u32 pllcon;
>>> -	int delay = 24000000;
>>> +	int ret;
>>>    
>>> -	/* poll check the lock status in rk3399 xPLLCON2 */
>>> -	while (delay > 0) {
>>> -		pllcon = readl_relaxed(pll->reg_base + RK3399_PLLCON(2));
>>> -		if (pllcon & RK3399_PLLCON2_LOCK_STATUS)
>>> -			return 0;
>>> +	/*
>>> +	 * Lock time typical 250, max 500 input clock cycles @24MHz
>>> +	 * So define a very safe maximum of 1000us, meaning 24000 cycles.
>>> +	 */
>>> +	ret = readl_poll_timeout(pll->reg_base + RK3399_PLLCON(2), pllcon,
>>> +				 pllcon & RK3399_PLLCON2_LOCK_STATUS, 0, 1000);
>>
>> Note that the existing I/O accessor was readl_relaxed(), but using plain
>> readl_poll_timeout() switches it to regular readl(). It may well not
>> matter, but since it's not noted as an intentional change it seemed
>> worth pointing out.
> 
> So we end up with an additional __iormb() after each readl_relaxed call.
> So except for a small speed-penalty per iteration is there some other
> memory-barrier wirednes that could come into play? (Somehow I always
> forget the contents of Will's memory-barrier talks after a time)

For the current arm64 implementation, probably not. For 32-bit it's 
still a DSB, which might in theory generate a bunch of coherency traffic 
synchronising with all the other CPUs each time, although unless you're 
counting every last microWatt even that's unlikely to be anything to 
worry about in practice. You *could* keep consistency with 
readl_relaxed_poll_timeout() instead, but you could equally argue the 
"use regular accessors for simplicity unless there's a provable benefit 
to using relaxed ones" angle. Up to you :)

Robin.

>  From a bit of non-scientific testing, rk3328 seems to need at max 20
> iterations in the wait_lock loop for the pll to lock, when doing cpufreq
> scaling.
> 
> While interestingly px30 takes somewhere between 900 and 2000 iterations
> on the same pll type.
> [Though sleeps are not really possible anyway due to pll rates also getting
> set during of_clk_register early during boot which results in errors about
> scheduling the idle thread, so in the end it doesn't really matter]
> 
> Heiko
> 
> 

_______________________________________________
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:[~2020-01-28 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-28 10:02 [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Heiko Stuebner
2020-01-28 10:02 ` [PATCH 2/3] clk: rockchip: convert basic pll lock_wait to use regmap_read_poll_timeout Heiko Stuebner
2020-01-28 10:02 ` [PATCH 3/3] clk: rockchip: convert rk3036 pll type to use internal lock status Heiko Stuebner
2020-01-28 15:28 ` [PATCH 1/3] clk: rockchip: convert rk3399 pll type to use readl_poll_timeout Robin Murphy
2020-01-28 16:29   ` Heiko Stuebner
2020-01-28 18:43     ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).