linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait
@ 2020-03-18  3:26 Anson Huang
  2020-03-18 11:14 ` Abel Vesa
  2020-03-19 19:58 ` Stephen Boyd
  0 siblings, 2 replies; 3+ messages in thread
From: Anson Huang @ 2020-03-18  3:26 UTC (permalink / raw)
  To: mturquette, sboyd, shawnguo, s.hauer, kernel, festevam, allison,
	gustavo, kstewart, tglx, abel.vesa, linux-clk, linux-arm-kernel,
	linux-kernel
  Cc: Linux-imx

Use readl_poll_timeout() for PLL lock wait which can simplify the
code a lot.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 drivers/clk/imx/clk-pllv3.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
index df91a82..3dfa9c3 100644
--- a/drivers/clk/imx/clk-pllv3.c
+++ b/drivers/clk/imx/clk-pllv3.c
@@ -7,6 +7,7 @@
 #include <linux/clk-provider.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
 #include <linux/err.h>
@@ -25,6 +26,8 @@
 #define IMX7_ENET_PLL_POWER	(0x1 << 5)
 #define IMX7_DDR_PLL_POWER	(0x1 << 20)
 
+#define PLL_LOCK_TIMEOUT	10000
+
 /**
  * struct clk_pllv3 - IMX PLL clock version 3
  * @clk_hw:	 clock source
@@ -53,23 +56,14 @@ struct clk_pllv3 {
 
 static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
 {
-	unsigned long timeout = jiffies + msecs_to_jiffies(10);
 	u32 val = readl_relaxed(pll->base) & pll->power_bit;
 
 	/* No need to wait for lock when pll is not powered up */
 	if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
 		return 0;
 
-	/* Wait for PLL to lock */
-	do {
-		if (readl_relaxed(pll->base) & BM_PLL_LOCK)
-			break;
-		if (time_after(jiffies, timeout))
-			break;
-		usleep_range(50, 500);
-	} while (1);
-
-	return readl_relaxed(pll->base) & BM_PLL_LOCK ? 0 : -ETIMEDOUT;
+	return readl_poll_timeout(pll->base, val, val & BM_PLL_LOCK, 500,
+				  PLL_LOCK_TIMEOUT);
 }
 
 static int clk_pllv3_prepare(struct clk_hw *hw)
-- 
2.7.4


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

* Re: [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait
  2020-03-18  3:26 [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait Anson Huang
@ 2020-03-18 11:14 ` Abel Vesa
  2020-03-19 19:58 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Abel Vesa @ 2020-03-18 11:14 UTC (permalink / raw)
  To: Anson Huang
  Cc: mturquette, sboyd, shawnguo, s.hauer, kernel, festevam, allison,
	gustavo, kstewart, tglx, linux-clk, linux-arm-kernel,
	linux-kernel, Linux-imx

On 20-03-18 11:26:44, Anson Huang wrote:
> Use readl_poll_timeout() for PLL lock wait which can simplify the
> code a lot.
> 
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>

Reviewed-by: Abel Vesa <abel.vesa@nxp.com>

> ---
>  drivers/clk/imx/clk-pllv3.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
> index df91a82..3dfa9c3 100644
> --- a/drivers/clk/imx/clk-pllv3.c
> +++ b/drivers/clk/imx/clk-pllv3.c
> @@ -7,6 +7,7 @@
>  #include <linux/clk-provider.h>
>  #include <linux/delay.h>
>  #include <linux/io.h>
> +#include <linux/iopoll.h>
>  #include <linux/slab.h>
>  #include <linux/jiffies.h>
>  #include <linux/err.h>
> @@ -25,6 +26,8 @@
>  #define IMX7_ENET_PLL_POWER	(0x1 << 5)
>  #define IMX7_DDR_PLL_POWER	(0x1 << 20)
>  
> +#define PLL_LOCK_TIMEOUT	10000
> +
>  /**
>   * struct clk_pllv3 - IMX PLL clock version 3
>   * @clk_hw:	 clock source
> @@ -53,23 +56,14 @@ struct clk_pllv3 {
>  
>  static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
>  {
> -	unsigned long timeout = jiffies + msecs_to_jiffies(10);
>  	u32 val = readl_relaxed(pll->base) & pll->power_bit;
>  
>  	/* No need to wait for lock when pll is not powered up */
>  	if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
>  		return 0;
>  
> -	/* Wait for PLL to lock */
> -	do {
> -		if (readl_relaxed(pll->base) & BM_PLL_LOCK)
> -			break;
> -		if (time_after(jiffies, timeout))
> -			break;
> -		usleep_range(50, 500);
> -	} while (1);
> -
> -	return readl_relaxed(pll->base) & BM_PLL_LOCK ? 0 : -ETIMEDOUT;
> +	return readl_poll_timeout(pll->base, val, val & BM_PLL_LOCK, 500,
> +				  PLL_LOCK_TIMEOUT);
>  }
>  
>  static int clk_pllv3_prepare(struct clk_hw *hw)
> -- 
> 2.7.4
> 

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

* Re: [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait
  2020-03-18  3:26 [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait Anson Huang
  2020-03-18 11:14 ` Abel Vesa
@ 2020-03-19 19:58 ` Stephen Boyd
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2020-03-19 19:58 UTC (permalink / raw)
  To: Anson Huang, abel.vesa, allison, festevam, gustavo, kernel,
	kstewart, linux-arm-kernel, linux-clk, linux-kernel, mturquette,
	s.hauer, shawnguo, tglx
  Cc: Linux-imx

Quoting Anson Huang (2020-03-17 20:26:44)
> diff --git a/drivers/clk/imx/clk-pllv3.c b/drivers/clk/imx/clk-pllv3.c
> index df91a82..3dfa9c3 100644
> --- a/drivers/clk/imx/clk-pllv3.c
> +++ b/drivers/clk/imx/clk-pllv3.c
> @@ -53,23 +56,14 @@ struct clk_pllv3 {
>  
>  static int clk_pllv3_wait_lock(struct clk_pllv3 *pll)
>  {
> -       unsigned long timeout = jiffies + msecs_to_jiffies(10);
>         u32 val = readl_relaxed(pll->base) & pll->power_bit;
>  
>         /* No need to wait for lock when pll is not powered up */
>         if ((pll->powerup_set && !val) || (!pll->powerup_set && val))
>                 return 0;
>  
> -       /* Wait for PLL to lock */
> -       do {
> -               if (readl_relaxed(pll->base) & BM_PLL_LOCK)
> -                       break;
> -               if (time_after(jiffies, timeout))
> -                       break;
> -               usleep_range(50, 500);
> -       } while (1);
> -
> -       return readl_relaxed(pll->base) & BM_PLL_LOCK ? 0 : -ETIMEDOUT;
> +       return readl_poll_timeout(pll->base, val, val & BM_PLL_LOCK, 500,

Did you want to use readl_relaxed_poll_timeout() to keep it the same as
before?

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

end of thread, other threads:[~2020-03-19 19:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18  3:26 [PATCH] clk: imx: clk-pllv3: Use readl_poll_timeout() for PLL lock wait Anson Huang
2020-03-18 11:14 ` Abel Vesa
2020-03-19 19:58 ` Stephen Boyd

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).