Commit 0a036388 authored by Peter Chen's avatar Peter Chen Committed by Shawn Guo

ARM: imx: clk-pllv3: improve the timeout waiting method

There are two improvements for this commit:

- Add comparing pll lock condition after while loop. It can
fix potential fake timeout problem caused by the code is just
scheduled out before compare the timeout, and the time of
scheduling out are more than one jiffies.

- Move timeout assignment more close to compare the timeout.
It can reduce the possibility the code is scheduled out, and
the timeout can be more precise.
Signed-off-by: default avatarPeter Chen <peter.chen@freescale.com>
Acked-by: default avatarSascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: default avatarShawn Guo <shawn.guo@linaro.org>
parent dfd87144
...@@ -48,7 +48,7 @@ struct clk_pllv3 { ...@@ -48,7 +48,7 @@ struct clk_pllv3 {
static int clk_pllv3_prepare(struct clk_hw *hw) static int clk_pllv3_prepare(struct clk_hw *hw)
{ {
struct clk_pllv3 *pll = to_clk_pllv3(hw); struct clk_pllv3 *pll = to_clk_pllv3(hw);
unsigned long timeout = jiffies + msecs_to_jiffies(10); unsigned long timeout;
u32 val; u32 val;
val = readl_relaxed(pll->base); val = readl_relaxed(pll->base);
...@@ -59,12 +59,19 @@ static int clk_pllv3_prepare(struct clk_hw *hw) ...@@ -59,12 +59,19 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
val &= ~BM_PLL_POWER; val &= ~BM_PLL_POWER;
writel_relaxed(val, pll->base); writel_relaxed(val, pll->base);
timeout = jiffies + msecs_to_jiffies(10);
/* Wait for PLL to lock */ /* Wait for PLL to lock */
while (!(readl_relaxed(pll->base) & BM_PLL_LOCK)) do {
if (readl_relaxed(pll->base) & BM_PLL_LOCK)
break;
if (time_after(jiffies, timeout)) if (time_after(jiffies, timeout))
return -ETIMEDOUT; break;
} while (1);
if (readl_relaxed(pll->base) & BM_PLL_LOCK)
return 0; return 0;
else
return -ETIMEDOUT;
} }
static void clk_pllv3_unprepare(struct clk_hw *hw) static void clk_pllv3_unprepare(struct clk_hw *hw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment