Skip to content

Commit 6a734b3

Browse files
Sam ProtsenkoSylwester Nawrocki
authored andcommitted
clk: samsung: clk-pll: Implement pll0831x PLL type
pll0831x PLL is used in Exynos850 SoC for top-level fractional PLLs. The code was derived from very similar pll36xx type, with next differences: 1. Lock time for pll0831x is 500*P_DIV, when for pll36xx it's 3000*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 pll36xx implementation) 3. The offset from PMS-values register to K-value register is 0x8 for pll0831x, when for pll36xx it's 0x4 When defining pll0831x type, CON3 register offset should be provided as a "con" parameter of PLL() macro, like this: PLL(pll_0831x, 0, "fout_mmc_pll", "oscclk", PLL_LOCKTIME_PLL_MMC, PLL_CON3_PLL_MMC, pll0831x_26mhz_tbl), To define PLL rates table, one can use PLL_36XX_RATE() macro, e.g.: PLL_36XX_RATE(26 * MHZ, 799999877, 31, 1, 0, -15124) as it's completely appropriate for pl0831x 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_mmc_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]> 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 8f90f43 commit 6a734b3

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

drivers/clk/samsung/clk-pll.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,103 @@ static const struct clk_ops samsung_pll0822x_clk_min_ops = {
498498
.recalc_rate = samsung_pll0822x_recalc_rate,
499499
};
500500

501+
/*
502+
* PLL0831x Clock Type
503+
*/
504+
/* Maximum lock time can be 500 * PDIV cycles */
505+
#define PLL0831X_LOCK_FACTOR (500)
506+
507+
#define PLL0831X_KDIV_MASK (0xFFFF)
508+
#define PLL0831X_MDIV_MASK (0x1FF)
509+
#define PLL0831X_PDIV_MASK (0x3F)
510+
#define PLL0831X_SDIV_MASK (0x7)
511+
#define PLL0831X_MDIV_SHIFT (16)
512+
#define PLL0831X_PDIV_SHIFT (8)
513+
#define PLL0831X_SDIV_SHIFT (0)
514+
#define PLL0831X_KDIV_SHIFT (0)
515+
#define PLL0831X_LOCK_STAT_SHIFT (29)
516+
#define PLL0831X_ENABLE_SHIFT (31)
517+
518+
static unsigned long samsung_pll0831x_recalc_rate(struct clk_hw *hw,
519+
unsigned long parent_rate)
520+
{
521+
struct samsung_clk_pll *pll = to_clk_pll(hw);
522+
u32 mdiv, pdiv, sdiv, pll_con3, pll_con5;
523+
s16 kdiv;
524+
u64 fvco = parent_rate;
525+
526+
pll_con3 = readl_relaxed(pll->con_reg);
527+
pll_con5 = readl_relaxed(pll->con_reg + 8);
528+
mdiv = (pll_con3 >> PLL0831X_MDIV_SHIFT) & PLL0831X_MDIV_MASK;
529+
pdiv = (pll_con3 >> PLL0831X_PDIV_SHIFT) & PLL0831X_PDIV_MASK;
530+
sdiv = (pll_con3 >> PLL0831X_SDIV_SHIFT) & PLL0831X_SDIV_MASK;
531+
kdiv = (s16)((pll_con5 >> PLL0831X_KDIV_SHIFT) & PLL0831X_KDIV_MASK);
532+
533+
fvco *= (mdiv << 16) + kdiv;
534+
do_div(fvco, (pdiv << sdiv));
535+
fvco >>= 16;
536+
537+
return (unsigned long)fvco;
538+
}
539+
540+
static int samsung_pll0831x_set_rate(struct clk_hw *hw, unsigned long drate,
541+
unsigned long parent_rate)
542+
{
543+
const struct samsung_pll_rate_table *rate;
544+
struct samsung_clk_pll *pll = to_clk_pll(hw);
545+
u32 pll_con3, pll_con5;
546+
547+
/* Get required rate settings from table */
548+
rate = samsung_get_pll_settings(pll, drate);
549+
if (!rate) {
550+
pr_err("%s: Invalid rate : %lu for pll clk %s\n", __func__,
551+
drate, clk_hw_get_name(hw));
552+
return -EINVAL;
553+
}
554+
555+
pll_con3 = readl_relaxed(pll->con_reg);
556+
pll_con5 = readl_relaxed(pll->con_reg + 8);
557+
558+
/* Change PLL PMSK values */
559+
pll_con3 &= ~((PLL0831X_MDIV_MASK << PLL0831X_MDIV_SHIFT) |
560+
(PLL0831X_PDIV_MASK << PLL0831X_PDIV_SHIFT) |
561+
(PLL0831X_SDIV_MASK << PLL0831X_SDIV_SHIFT));
562+
pll_con3 |= (rate->mdiv << PLL0831X_MDIV_SHIFT) |
563+
(rate->pdiv << PLL0831X_PDIV_SHIFT) |
564+
(rate->sdiv << PLL0831X_SDIV_SHIFT);
565+
pll_con5 &= ~(PLL0831X_KDIV_MASK << PLL0831X_KDIV_SHIFT);
566+
/*
567+
* kdiv is 16-bit 2's complement (s16), but stored as unsigned int.
568+
* Cast it to u16 to avoid leading 0xffff's in case of negative value.
569+
*/
570+
pll_con5 |= ((u16)rate->kdiv << PLL0831X_KDIV_SHIFT);
571+
572+
/* Set PLL lock time */
573+
writel_relaxed(rate->pdiv * PLL0831X_LOCK_FACTOR, pll->lock_reg);
574+
575+
/* Write PMSK values */
576+
writel_relaxed(pll_con3, pll->con_reg);
577+
writel_relaxed(pll_con5, pll->con_reg + 8);
578+
579+
/* Wait for PLL lock if the PLL is enabled */
580+
if (pll_con3 & BIT(pll->enable_offs))
581+
return samsung_pll_lock_wait(pll, BIT(pll->lock_offs));
582+
583+
return 0;
584+
}
585+
586+
static const struct clk_ops samsung_pll0831x_clk_ops = {
587+
.recalc_rate = samsung_pll0831x_recalc_rate,
588+
.set_rate = samsung_pll0831x_set_rate,
589+
.round_rate = samsung_pll_round_rate,
590+
.enable = samsung_pll3xxx_enable,
591+
.disable = samsung_pll3xxx_disable,
592+
};
593+
594+
static const struct clk_ops samsung_pll0831x_clk_min_ops = {
595+
.recalc_rate = samsung_pll0831x_recalc_rate,
596+
};
597+
501598
/*
502599
* PLL45xx Clock Type
503600
*/
@@ -1407,6 +1504,14 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
14071504
else
14081505
init.ops = &samsung_pll36xx_clk_ops;
14091506
break;
1507+
case pll_0831x:
1508+
pll->enable_offs = PLL0831X_ENABLE_SHIFT;
1509+
pll->lock_offs = PLL0831X_LOCK_STAT_SHIFT;
1510+
if (!pll->rate_table)
1511+
init.ops = &samsung_pll0831x_clk_min_ops;
1512+
else
1513+
init.ops = &samsung_pll0831x_clk_ops;
1514+
break;
14101515
case pll_6552:
14111516
case pll_6552_s3c2416:
14121517
init.ops = &samsung_pll6552_clk_ops;

drivers/clk/samsung/clk-pll.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum samsung_pll_type {
3737
pll_1452x,
3838
pll_1460x,
3939
pll_0822x,
40+
pll_0831x,
4041
};
4142

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

0 commit comments

Comments
 (0)