Skip to content

Commit 892abfb

Browse files
ziyao233pdp7
authored andcommitted
clk: thead: th1520-ap: Poll for PLL lock and wait for stability
All PLLs found on TH1520 SoC take 21250ns at maximum to lock, and their lock status is indicated by register PLL_STS (offset 0x80 inside AP clock controller). We should poll the register to ensure the PLL actually locks after enabling it. Furthermore, a 30us delay is added after enabling the PLL, after which the PLL could be considered stable as stated by vendor clock code. Fixes: 56a48c1 ("clk: thead: add support for enabling/disabling PLLs") Reviewed-by: Drew Fustini <fustini@kernel.org> Signed-off-by: Yao Zi <ziyao@disroot.org> Signed-off-by: Drew Fustini <fustini@kernel.org>
1 parent 5f35212 commit 892abfb

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

drivers/clk/thead/clk-th1520-ap.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#include <dt-bindings/clock/thead,th1520-clk-ap.h>
99
#include <linux/bitfield.h>
1010
#include <linux/clk-provider.h>
11+
#include <linux/delay.h>
1112
#include <linux/device.h>
1213
#include <linux/module.h>
1314
#include <linux/platform_device.h>
1415
#include <linux/regmap.h>
1516

17+
#define TH1520_PLL_STS 0x80
18+
1619
#define TH1520_PLL_POSTDIV2 GENMASK(26, 24)
1720
#define TH1520_PLL_POSTDIV1 GENMASK(22, 20)
1821
#define TH1520_PLL_FBDIV GENMASK(19, 8)
@@ -23,6 +26,13 @@
2326
#define TH1520_PLL_FRAC GENMASK(23, 0)
2427
#define TH1520_PLL_FRAC_BITS 24
2528

29+
/*
30+
* All PLLs in TH1520 take 21250ns at maximum to lock, let's take its double
31+
* for safety.
32+
*/
33+
#define TH1520_PLL_LOCK_TIMEOUT_US 44
34+
#define TH1520_PLL_STABLE_DELAY_US 30
35+
2636
struct ccu_internal {
2737
u8 shift;
2838
u8 width;
@@ -64,6 +74,7 @@ struct ccu_div {
6474

6575
struct ccu_pll {
6676
struct ccu_common common;
77+
u32 lock_sts_mask;
6778
};
6879

6980
#define TH_CCU_ARG(_shift, _width) \
@@ -299,9 +310,21 @@ static void ccu_pll_disable(struct clk_hw *hw)
299310
static int ccu_pll_enable(struct clk_hw *hw)
300311
{
301312
struct ccu_pll *pll = hw_to_ccu_pll(hw);
313+
u32 reg;
314+
int ret;
302315

303-
return regmap_clear_bits(pll->common.map, pll->common.cfg1,
304-
TH1520_PLL_VCO_RST);
316+
regmap_clear_bits(pll->common.map, pll->common.cfg1,
317+
TH1520_PLL_VCO_RST);
318+
319+
ret = regmap_read_poll_timeout_atomic(pll->common.map, TH1520_PLL_STS,
320+
reg, reg & pll->lock_sts_mask,
321+
5, TH1520_PLL_LOCK_TIMEOUT_US);
322+
if (ret)
323+
return ret;
324+
325+
udelay(TH1520_PLL_STABLE_DELAY_US);
326+
327+
return 0;
305328
}
306329

307330
static int ccu_pll_is_enabled(struct clk_hw *hw)
@@ -389,6 +412,7 @@ static struct ccu_pll cpu_pll0_clk = {
389412
&clk_pll_ops,
390413
CLK_IS_CRITICAL),
391414
},
415+
.lock_sts_mask = BIT(1),
392416
};
393417

394418
static struct ccu_pll cpu_pll1_clk = {
@@ -401,6 +425,7 @@ static struct ccu_pll cpu_pll1_clk = {
401425
&clk_pll_ops,
402426
CLK_IS_CRITICAL),
403427
},
428+
.lock_sts_mask = BIT(4),
404429
};
405430

406431
static struct ccu_pll gmac_pll_clk = {
@@ -413,6 +438,7 @@ static struct ccu_pll gmac_pll_clk = {
413438
&clk_pll_ops,
414439
CLK_IS_CRITICAL),
415440
},
441+
.lock_sts_mask = BIT(3),
416442
};
417443

418444
static const struct clk_hw *gmac_pll_clk_parent[] = {
@@ -433,6 +459,7 @@ static struct ccu_pll video_pll_clk = {
433459
&clk_pll_ops,
434460
CLK_IS_CRITICAL),
435461
},
462+
.lock_sts_mask = BIT(7),
436463
};
437464

438465
static const struct clk_hw *video_pll_clk_parent[] = {
@@ -453,6 +480,7 @@ static struct ccu_pll dpu0_pll_clk = {
453480
&clk_pll_ops,
454481
0),
455482
},
483+
.lock_sts_mask = BIT(8),
456484
};
457485

458486
static const struct clk_hw *dpu0_pll_clk_parent[] = {
@@ -469,6 +497,7 @@ static struct ccu_pll dpu1_pll_clk = {
469497
&clk_pll_ops,
470498
0),
471499
},
500+
.lock_sts_mask = BIT(9),
472501
};
473502

474503
static const struct clk_hw *dpu1_pll_clk_parent[] = {
@@ -485,6 +514,7 @@ static struct ccu_pll tee_pll_clk = {
485514
&clk_pll_ops,
486515
CLK_IS_CRITICAL),
487516
},
517+
.lock_sts_mask = BIT(10),
488518
};
489519

490520
static const struct clk_parent_data c910_i0_parents[] = {

0 commit comments

Comments
 (0)