Skip to content

Commit 8f90f43

Browse files
Sam ProtsenkoSylwester Nawrocki
authored andcommitted
clk: samsung: clk-pll: Implement pll0822x PLL type
pll0822x PLL is used in Exynos850 SoC for top-level integer PLLs. The code was derived from very similar pll35xx type, with next differences: 1. Lock time for pll0822x is 150*P_DIV, when for pll35xx it's 270*P_DIV 2. It's not suggested in Exynos850 TRM that S_DIV change doesn't require performing PLL lock procedure (which is done in pll35xx implementation) When defining pll0822x type, CON3 register offset should be provided as a "con" parameter of PLL() macro, like this: PLL(pll_0822x, 0, "fout_shared0_pll", "oscclk", PLL_LOCKTIME_PLL_SHARED0, PLL_CON3_PLL_SHARED0, exynos850_shared0_pll_rates), To define PLL rates table, one can use PLL_35XX_RATE() macro, e.g.: PLL_35XX_RATE(26 * MHZ, 1600 * MHZ, 800, 13, 0) as it's completely appropriate for pl0822x type and there is no sense in duplicating that. If bit #1 (MANUAL_PLL_CTRL) is not set in CON1 register, it won't be possible to set new rate, with next error showing in kernel log: Could not lock PLL fout_shared1_pll That can happen for example if bootloader clears that bit beforehand. PLL driver doesn't account for that, so if MANUAL_PLL_CTRL bit was cleared, it's assumed it was done for a reason and it shouldn't be possible to change that PLL's rate at all. Signed-off-by: Sam Protsenko <[email protected]> Signed-off-by: Sylwester Nawrocki <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Acked-by: Chanwoo Choi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sylwester Nawrocki <[email protected]>
1 parent 1d26eae commit 8f90f43

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

drivers/clk/samsung/clk-pll.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,89 @@ static const struct clk_ops samsung_pll36xx_clk_min_ops = {
415415
.recalc_rate = samsung_pll36xx_recalc_rate,
416416
};
417417

418+
/*
419+
* PLL0822x Clock Type
420+
*/
421+
/* Maximum lock time can be 150 * PDIV cycles */
422+
#define PLL0822X_LOCK_FACTOR (150)
423+
424+
#define PLL0822X_MDIV_MASK (0x3FF)
425+
#define PLL0822X_PDIV_MASK (0x3F)
426+
#define PLL0822X_SDIV_MASK (0x7)
427+
#define PLL0822X_MDIV_SHIFT (16)
428+
#define PLL0822X_PDIV_SHIFT (8)
429+
#define PLL0822X_SDIV_SHIFT (0)
430+
#define PLL0822X_LOCK_STAT_SHIFT (29)
431+
#define PLL0822X_ENABLE_SHIFT (31)
432+
433+
static unsigned long samsung_pll0822x_recalc_rate(struct clk_hw *hw,
434+
unsigned long parent_rate)
435+
{
436+
struct samsung_clk_pll *pll = to_clk_pll(hw);
437+
u32 mdiv, pdiv, sdiv, pll_con3;
438+
u64 fvco = parent_rate;
439+
440+
pll_con3 = readl_relaxed(pll->con_reg);
441+
mdiv = (pll_con3 >> PLL0822X_MDIV_SHIFT) & PLL0822X_MDIV_MASK;
442+
pdiv = (pll_con3 >> PLL0822X_PDIV_SHIFT) & PLL0822X_PDIV_MASK;
443+
sdiv = (pll_con3 >> PLL0822X_SDIV_SHIFT) & PLL0822X_SDIV_MASK;
444+
445+
fvco *= mdiv;
446+
do_div(fvco, (pdiv << sdiv));
447+
448+
return (unsigned long)fvco;
449+
}
450+
451+
static int samsung_pll0822x_set_rate(struct clk_hw *hw, unsigned long drate,
452+
unsigned long prate)
453+
{
454+
const struct samsung_pll_rate_table *rate;
455+
struct samsung_clk_pll *pll = to_clk_pll(hw);
456+
u32 pll_con3;
457+
458+
/* Get required rate settings from table */
459+
rate = samsung_get_pll_settings(pll, drate);
460+
if (!rate) {
461+
pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__,
462+
drate, clk_hw_get_name(hw));
463+
return -EINVAL;
464+
}
465+
466+
/* Change PLL PMS values */
467+
pll_con3 = readl_relaxed(pll->con_reg);
468+
pll_con3 &= ~((PLL0822X_MDIV_MASK << PLL0822X_MDIV_SHIFT) |
469+
(PLL0822X_PDIV_MASK << PLL0822X_PDIV_SHIFT) |
470+
(PLL0822X_SDIV_MASK << PLL0822X_SDIV_SHIFT));
471+
pll_con3 |= (rate->mdiv << PLL0822X_MDIV_SHIFT) |
472+
(rate->pdiv << PLL0822X_PDIV_SHIFT) |
473+
(rate->sdiv << PLL0822X_SDIV_SHIFT);
474+
475+
/* Set PLL lock time */
476+
writel_relaxed(rate->pdiv * PLL0822X_LOCK_FACTOR,
477+
pll->lock_reg);
478+
479+
/* Write PMS values */
480+
writel_relaxed(pll_con3, pll->con_reg);
481+
482+
/* Wait for PLL lock if the PLL is enabled */
483+
if (pll_con3 & BIT(pll->enable_offs))
484+
return samsung_pll_lock_wait(pll, BIT(pll->lock_offs));
485+
486+
return 0;
487+
}
488+
489+
static const struct clk_ops samsung_pll0822x_clk_ops = {
490+
.recalc_rate = samsung_pll0822x_recalc_rate,
491+
.round_rate = samsung_pll_round_rate,
492+
.set_rate = samsung_pll0822x_set_rate,
493+
.enable = samsung_pll3xxx_enable,
494+
.disable = samsung_pll3xxx_disable,
495+
};
496+
497+
static const struct clk_ops samsung_pll0822x_clk_min_ops = {
498+
.recalc_rate = samsung_pll0822x_recalc_rate,
499+
};
500+
418501
/*
419502
* PLL45xx Clock Type
420503
*/
@@ -1296,6 +1379,14 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
12961379
else
12971380
init.ops = &samsung_pll35xx_clk_ops;
12981381
break;
1382+
case pll_0822x:
1383+
pll->enable_offs = PLL0822X_ENABLE_SHIFT;
1384+
pll->lock_offs = PLL0822X_LOCK_STAT_SHIFT;
1385+
if (!pll->rate_table)
1386+
init.ops = &samsung_pll0822x_clk_min_ops;
1387+
else
1388+
init.ops = &samsung_pll0822x_clk_ops;
1389+
break;
12991390
case pll_4500:
13001391
init.ops = &samsung_pll45xx_clk_min_ops;
13011392
break;

drivers/clk/samsung/clk-pll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum samsung_pll_type {
3636
pll_1451x,
3737
pll_1452x,
3838
pll_1460x,
39+
pll_0822x,
3940
};
4041

4142
#define PLL_RATE(_fin, _m, _p, _s, _k, _ks) \

0 commit comments

Comments
 (0)