2 * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/slab.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/clk-provider.h>
22 #include <linux/clk.h>
26 #define PLL_BASE_BYPASS BIT(31)
27 #define PLL_BASE_ENABLE BIT(30)
28 #define PLL_BASE_REF_ENABLE BIT(29)
29 #define PLL_BASE_OVERRIDE BIT(28)
31 #define PLL_BASE_DIVP_SHIFT 20
32 #define PLL_BASE_DIVP_WIDTH 3
33 #define PLL_BASE_DIVN_SHIFT 8
34 #define PLL_BASE_DIVN_WIDTH 10
35 #define PLL_BASE_DIVM_SHIFT 0
36 #define PLL_BASE_DIVM_WIDTH 5
37 #define PLLU_POST_DIVP_MASK 0x1
39 #define PLL_MISC_DCCON_SHIFT 20
40 #define PLL_MISC_CPCON_SHIFT 8
41 #define PLL_MISC_CPCON_WIDTH 4
42 #define PLL_MISC_CPCON_MASK ((1 << PLL_MISC_CPCON_WIDTH) - 1)
43 #define PLL_MISC_LFCON_SHIFT 4
44 #define PLL_MISC_LFCON_WIDTH 4
45 #define PLL_MISC_LFCON_MASK ((1 << PLL_MISC_LFCON_WIDTH) - 1)
46 #define PLL_MISC_VCOCON_SHIFT 0
47 #define PLL_MISC_VCOCON_WIDTH 4
48 #define PLL_MISC_VCOCON_MASK ((1 << PLL_MISC_VCOCON_WIDTH) - 1)
50 #define OUT_OF_TABLE_CPCON 8
52 #define PMC_PLLP_WB0_OVERRIDE 0xf8
53 #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12)
54 #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE BIT(11)
56 #define PLL_POST_LOCK_DELAY 50
58 #define PLLDU_LFCON_SET_DIVN 600
60 #define PLLE_BASE_DIVCML_SHIFT 24
61 #define PLLE_BASE_DIVCML_WIDTH 4
62 #define PLLE_BASE_DIVP_SHIFT 16
63 #define PLLE_BASE_DIVP_WIDTH 7
64 #define PLLE_BASE_DIVN_SHIFT 8
65 #define PLLE_BASE_DIVN_WIDTH 8
66 #define PLLE_BASE_DIVM_SHIFT 0
67 #define PLLE_BASE_DIVM_WIDTH 8
69 #define PLLE_MISC_SETUP_BASE_SHIFT 16
70 #define PLLE_MISC_SETUP_BASE_MASK (0xffff << PLLE_MISC_SETUP_BASE_SHIFT)
71 #define PLLE_MISC_LOCK_ENABLE BIT(9)
72 #define PLLE_MISC_READY BIT(15)
73 #define PLLE_MISC_SETUP_EX_SHIFT 2
74 #define PLLE_MISC_SETUP_EX_MASK (3 << PLLE_MISC_SETUP_EX_SHIFT)
75 #define PLLE_MISC_SETUP_MASK (PLLE_MISC_SETUP_BASE_MASK | \
76 PLLE_MISC_SETUP_EX_MASK)
77 #define PLLE_MISC_SETUP_VALUE (7 << PLLE_MISC_SETUP_BASE_SHIFT)
79 #define PLLE_SS_CTRL 0x68
80 #define PLLE_SS_CNTL_BYPASS_SS BIT(10)
81 #define PLLE_SS_CNTL_INTERP_RESET BIT(11)
82 #define PLLE_SS_CNTL_SSC_BYP BIT(12)
83 #define PLLE_SS_CNTL_CENTER BIT(14)
84 #define PLLE_SS_CNTL_INVERT BIT(15)
85 #define PLLE_SS_DISABLE (PLLE_SS_CNTL_BYPASS_SS | PLLE_SS_CNTL_INTERP_RESET |\
87 #define PLLE_SS_MAX_MASK 0x1ff
88 #define PLLE_SS_MAX_VAL 0x25
89 #define PLLE_SS_INC_MASK (0xff << 16)
90 #define PLLE_SS_INC_VAL (0x1 << 16)
91 #define PLLE_SS_INCINTRV_MASK (0x3f << 24)
92 #define PLLE_SS_INCINTRV_VAL (0x20 << 24)
93 #define PLLE_SS_COEFFICIENTS_MASK \
94 (PLLE_SS_MAX_MASK | PLLE_SS_INC_MASK | PLLE_SS_INCINTRV_MASK)
95 #define PLLE_SS_COEFFICIENTS_VAL \
96 (PLLE_SS_MAX_VAL | PLLE_SS_INC_VAL | PLLE_SS_INCINTRV_VAL)
98 #define PLLE_AUX_PLLP_SEL BIT(2)
99 #define PLLE_AUX_ENABLE_SWCTL BIT(4)
100 #define PLLE_AUX_SEQ_ENABLE BIT(24)
101 #define PLLE_AUX_PLLRE_SEL BIT(28)
103 #define PLLE_MISC_PLLE_PTS BIT(8)
104 #define PLLE_MISC_IDDQ_SW_VALUE BIT(13)
105 #define PLLE_MISC_IDDQ_SW_CTRL BIT(14)
106 #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4
107 #define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT)
108 #define PLLE_MISC_VREG_CTRL_SHIFT 2
109 #define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT)
111 #define PLLCX_MISC_STROBE BIT(31)
112 #define PLLCX_MISC_RESET BIT(30)
113 #define PLLCX_MISC_SDM_DIV_SHIFT 28
114 #define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT)
115 #define PLLCX_MISC_FILT_DIV_SHIFT 26
116 #define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT)
117 #define PLLCX_MISC_ALPHA_SHIFT 18
118 #define PLLCX_MISC_DIV_LOW_RANGE \
119 ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \
120 (0x1 << PLLCX_MISC_FILT_DIV_SHIFT))
121 #define PLLCX_MISC_DIV_HIGH_RANGE \
122 ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \
123 (0x2 << PLLCX_MISC_FILT_DIV_SHIFT))
124 #define PLLCX_MISC_COEF_LOW_RANGE \
125 ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT))
126 #define PLLCX_MISC_KA_SHIFT 2
127 #define PLLCX_MISC_KB_SHIFT 9
128 #define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \
129 (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \
130 PLLCX_MISC_DIV_LOW_RANGE | \
132 #define PLLCX_MISC1_DEFAULT 0x000d2308
133 #define PLLCX_MISC2_DEFAULT 0x30211200
134 #define PLLCX_MISC3_DEFAULT 0x200
136 #define PMC_SATA_PWRGT 0x1ac
137 #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5)
138 #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4)
140 #define pll_readl(offset, p) readl_relaxed(p->clk_base + offset)
141 #define pll_readl_base(p) pll_readl(p->params->base_reg, p)
142 #define pll_readl_misc(p) pll_readl(p->params->misc_reg, p)
143 #define pll_override_readl(offset, p) readl_relaxed(p->pmc + offset)
145 #define pll_writel(val, offset, p) writel_relaxed(val, p->clk_base + offset)
146 #define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p)
147 #define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p)
148 #define pll_override_writel(val, offset, p) writel(val, p->pmc + offset)
150 #define mask(w) ((1 << (w)) - 1)
151 #define divm_mask(p) mask(p->params->div_nmp->divm_width)
152 #define divn_mask(p) mask(p->params->div_nmp->divn_width)
153 #define divp_mask(p) (p->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK : \
154 mask(p->params->div_nmp->divp_width))
156 #define divm_max(p) (divm_mask(p))
157 #define divn_max(p) (divn_mask(p))
158 #define divp_max(p) (1 << (divp_mask(p)))
160 static struct div_nmp default_nmp = {
161 .divn_shift = PLL_BASE_DIVN_SHIFT,
162 .divn_width = PLL_BASE_DIVN_WIDTH,
163 .divm_shift = PLL_BASE_DIVM_SHIFT,
164 .divm_width = PLL_BASE_DIVM_WIDTH,
165 .divp_shift = PLL_BASE_DIVP_SHIFT,
166 .divp_width = PLL_BASE_DIVP_WIDTH,
169 static void clk_pll_enable_lock(struct tegra_clk_pll *pll)
173 if (!(pll->flags & TEGRA_PLL_USE_LOCK))
176 if (!(pll->flags & TEGRA_PLL_HAS_LOCK_ENABLE))
179 val = pll_readl_misc(pll);
180 val |= BIT(pll->params->lock_enable_bit_idx);
181 pll_writel_misc(val, pll);
184 static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll)
188 void __iomem *lock_addr;
190 if (!(pll->flags & TEGRA_PLL_USE_LOCK)) {
191 udelay(pll->params->lock_delay);
195 lock_addr = pll->clk_base;
196 if (pll->flags & TEGRA_PLL_LOCK_MISC)
197 lock_addr += pll->params->misc_reg;
199 lock_addr += pll->params->base_reg;
201 lock_mask = pll->params->lock_mask;
203 for (i = 0; i < pll->params->lock_delay; i++) {
204 val = readl_relaxed(lock_addr);
205 if ((val & lock_mask) == lock_mask) {
206 udelay(PLL_POST_LOCK_DELAY);
209 udelay(2); /* timeout = 2 * lock time */
212 pr_err("%s: Timed out waiting for pll %s lock\n", __func__,
213 __clk_get_name(pll->hw.clk));
218 static int clk_pll_is_enabled(struct clk_hw *hw)
220 struct tegra_clk_pll *pll = to_clk_pll(hw);
223 if (pll->flags & TEGRA_PLLM) {
224 val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
225 if (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)
226 return val & PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE ? 1 : 0;
229 val = pll_readl_base(pll);
231 return val & PLL_BASE_ENABLE ? 1 : 0;
234 static void _clk_pll_enable(struct clk_hw *hw)
236 struct tegra_clk_pll *pll = to_clk_pll(hw);
239 clk_pll_enable_lock(pll);
241 val = pll_readl_base(pll);
242 if (pll->flags & TEGRA_PLL_BYPASS)
243 val &= ~PLL_BASE_BYPASS;
244 val |= PLL_BASE_ENABLE;
245 pll_writel_base(val, pll);
247 if (pll->flags & TEGRA_PLLM) {
248 val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
249 val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
250 writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE);
254 static void _clk_pll_disable(struct clk_hw *hw)
256 struct tegra_clk_pll *pll = to_clk_pll(hw);
259 val = pll_readl_base(pll);
260 if (pll->flags & TEGRA_PLL_BYPASS)
261 val &= ~PLL_BASE_BYPASS;
262 val &= ~PLL_BASE_ENABLE;
263 pll_writel_base(val, pll);
265 if (pll->flags & TEGRA_PLLM) {
266 val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE);
267 val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
268 writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE);
272 static int clk_pll_enable(struct clk_hw *hw)
274 struct tegra_clk_pll *pll = to_clk_pll(hw);
275 unsigned long flags = 0;
279 spin_lock_irqsave(pll->lock, flags);
283 ret = clk_pll_wait_for_lock(pll);
286 spin_unlock_irqrestore(pll->lock, flags);
291 static void clk_pll_disable(struct clk_hw *hw)
293 struct tegra_clk_pll *pll = to_clk_pll(hw);
294 unsigned long flags = 0;
297 spin_lock_irqsave(pll->lock, flags);
299 _clk_pll_disable(hw);
302 spin_unlock_irqrestore(pll->lock, flags);
305 static int _p_div_to_hw(struct clk_hw *hw, u8 p_div)
307 struct tegra_clk_pll *pll = to_clk_pll(hw);
308 struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
311 while (p_tohw->pdiv) {
312 if (p_div <= p_tohw->pdiv)
313 return p_tohw->hw_val;
321 static int _hw_to_p_div(struct clk_hw *hw, u8 p_div_hw)
323 struct tegra_clk_pll *pll = to_clk_pll(hw);
324 struct pdiv_map *p_tohw = pll->params->pdiv_tohw;
327 while (p_tohw->pdiv) {
328 if (p_div_hw == p_tohw->hw_val)
335 return 1 << p_div_hw;
338 static int _get_table_rate(struct clk_hw *hw,
339 struct tegra_clk_pll_freq_table *cfg,
340 unsigned long rate, unsigned long parent_rate)
342 struct tegra_clk_pll *pll = to_clk_pll(hw);
343 struct tegra_clk_pll_freq_table *sel;
345 for (sel = pll->freq_table; sel->input_rate != 0; sel++)
346 if (sel->input_rate == parent_rate &&
347 sel->output_rate == rate)
350 if (sel->input_rate == 0)
353 cfg->input_rate = sel->input_rate;
354 cfg->output_rate = sel->output_rate;
358 cfg->cpcon = sel->cpcon;
363 static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
364 unsigned long rate, unsigned long parent_rate)
366 struct tegra_clk_pll *pll = to_clk_pll(hw);
371 switch (parent_rate) {
374 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000;
377 cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000;
381 cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000;
386 * PLL_P_OUT1 rate is not listed in PLLA table
388 cfreq = parent_rate/(parent_rate/1000000);
391 pr_err("%s Unexpected reference rate %lu\n",
392 __func__, parent_rate);
396 /* Raise VCO to guarantee 0.5% accuracy */
397 for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq;
398 cfg->output_rate <<= 1)
401 cfg->m = parent_rate / cfreq;
402 cfg->n = cfg->output_rate / cfreq;
403 cfg->cpcon = OUT_OF_TABLE_CPCON;
405 if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) ||
406 (1 << p_div) > divp_max(pll)
407 || cfg->output_rate > pll->params->vco_max) {
408 pr_err("%s: Failed to set %s rate %lu\n",
409 __func__, __clk_get_name(hw->clk), rate);
414 cfg->output_rate >>= p_div;
416 if (pll->params->pdiv_tohw) {
417 ret = _p_div_to_hw(hw, 1 << p_div);
428 static void _update_pll_mnp(struct tegra_clk_pll *pll,
429 struct tegra_clk_pll_freq_table *cfg)
432 struct tegra_clk_pll_params *params = pll->params;
433 struct div_nmp *div_nmp = params->div_nmp;
435 if ((pll->flags & TEGRA_PLLM) &&
436 (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) &
437 PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) {
438 val = pll_override_readl(params->pmc_divp_reg, pll);
439 val &= ~(divp_mask(pll) << div_nmp->override_divp_shift);
440 val |= cfg->p << div_nmp->override_divp_shift;
441 pll_override_writel(val, params->pmc_divp_reg, pll);
443 val = pll_override_readl(params->pmc_divnm_reg, pll);
444 val &= ~(divm_mask(pll) << div_nmp->override_divm_shift) |
445 ~(divn_mask(pll) << div_nmp->override_divn_shift);
446 val |= (cfg->m << div_nmp->override_divm_shift) |
447 (cfg->n << div_nmp->override_divn_shift);
448 pll_override_writel(val, params->pmc_divnm_reg, pll);
450 val = pll_readl_base(pll);
452 val &= ~((divm_mask(pll) << div_nmp->divm_shift) |
453 (divn_mask(pll) << div_nmp->divn_shift) |
454 (divp_mask(pll) << div_nmp->divp_shift));
456 val |= ((cfg->m << div_nmp->divm_shift) |
457 (cfg->n << div_nmp->divn_shift) |
458 (cfg->p << div_nmp->divp_shift));
460 pll_writel_base(val, pll);
464 static void _get_pll_mnp(struct tegra_clk_pll *pll,
465 struct tegra_clk_pll_freq_table *cfg)
468 struct tegra_clk_pll_params *params = pll->params;
469 struct div_nmp *div_nmp = params->div_nmp;
471 if ((pll->flags & TEGRA_PLLM) &&
472 (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) &
473 PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) {
474 val = pll_override_readl(params->pmc_divp_reg, pll);
475 cfg->p = (val >> div_nmp->override_divp_shift) & divp_mask(pll);
477 val = pll_override_readl(params->pmc_divnm_reg, pll);
478 cfg->m = (val >> div_nmp->override_divm_shift) & divm_mask(pll);
479 cfg->n = (val >> div_nmp->override_divn_shift) & divn_mask(pll);
481 val = pll_readl_base(pll);
483 cfg->m = (val >> div_nmp->divm_shift) & divm_mask(pll);
484 cfg->n = (val >> div_nmp->divn_shift) & divn_mask(pll);
485 cfg->p = (val >> div_nmp->divp_shift) & divp_mask(pll);
489 static void _update_pll_cpcon(struct tegra_clk_pll *pll,
490 struct tegra_clk_pll_freq_table *cfg,
495 val = pll_readl_misc(pll);
497 val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT);
498 val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT;
500 if (pll->flags & TEGRA_PLL_SET_LFCON) {
501 val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT);
502 if (cfg->n >= PLLDU_LFCON_SET_DIVN)
503 val |= 1 << PLL_MISC_LFCON_SHIFT;
504 } else if (pll->flags & TEGRA_PLL_SET_DCCON) {
505 val &= ~(1 << PLL_MISC_DCCON_SHIFT);
506 if (rate >= (pll->params->vco_max >> 1))
507 val |= 1 << PLL_MISC_DCCON_SHIFT;
510 pll_writel_misc(val, pll);
513 static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg,
516 struct tegra_clk_pll *pll = to_clk_pll(hw);
519 state = clk_pll_is_enabled(hw);
522 _clk_pll_disable(hw);
524 _update_pll_mnp(pll, cfg);
526 if (pll->flags & TEGRA_PLL_HAS_CPCON)
527 _update_pll_cpcon(pll, cfg, rate);
531 ret = clk_pll_wait_for_lock(pll);
537 static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate,
538 unsigned long parent_rate)
540 struct tegra_clk_pll *pll = to_clk_pll(hw);
541 struct tegra_clk_pll_freq_table cfg, old_cfg;
542 unsigned long flags = 0;
545 if (pll->flags & TEGRA_PLL_FIXED) {
546 if (rate != pll->fixed_rate) {
547 pr_err("%s: Can not change %s fixed rate %lu to %lu\n",
548 __func__, __clk_get_name(hw->clk),
549 pll->fixed_rate, rate);
555 if (_get_table_rate(hw, &cfg, rate, parent_rate) &&
556 _calc_rate(hw, &cfg, rate, parent_rate)) {
561 spin_lock_irqsave(pll->lock, flags);
563 _get_pll_mnp(pll, &old_cfg);
565 if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p)
566 ret = _program_pll(hw, &cfg, rate);
569 spin_unlock_irqrestore(pll->lock, flags);
574 static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate,
575 unsigned long *prate)
577 struct tegra_clk_pll *pll = to_clk_pll(hw);
578 struct tegra_clk_pll_freq_table cfg;
580 if (pll->flags & TEGRA_PLL_FIXED)
581 return pll->fixed_rate;
583 /* PLLM is used for memory; we do not change rate */
584 if (pll->flags & TEGRA_PLLM)
585 return __clk_get_rate(hw->clk);
587 if (_get_table_rate(hw, &cfg, rate, *prate) &&
588 _calc_rate(hw, &cfg, rate, *prate)) {
593 return cfg.output_rate;
596 static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
597 unsigned long parent_rate)
599 struct tegra_clk_pll *pll = to_clk_pll(hw);
600 struct tegra_clk_pll_freq_table cfg;
602 u64 rate = parent_rate;
605 val = pll_readl_base(pll);
607 if ((pll->flags & TEGRA_PLL_BYPASS) && (val & PLL_BASE_BYPASS))
610 if ((pll->flags & TEGRA_PLL_FIXED) && !(val & PLL_BASE_OVERRIDE)) {
611 struct tegra_clk_pll_freq_table sel;
612 if (_get_table_rate(hw, &sel, pll->fixed_rate, parent_rate)) {
613 pr_err("Clock %s has unknown fixed frequency\n",
614 __clk_get_name(hw->clk));
617 return pll->fixed_rate;
620 _get_pll_mnp(pll, &cfg);
622 pdiv = _hw_to_p_div(hw, cfg.p);
636 static int clk_plle_training(struct tegra_clk_pll *pll)
639 unsigned long timeout;
645 * PLLE is already disabled, and setup cleared;
646 * create falling edge on PLLE IDDQ input.
648 val = readl(pll->pmc + PMC_SATA_PWRGT);
649 val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
650 writel(val, pll->pmc + PMC_SATA_PWRGT);
652 val = readl(pll->pmc + PMC_SATA_PWRGT);
653 val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL;
654 writel(val, pll->pmc + PMC_SATA_PWRGT);
656 val = readl(pll->pmc + PMC_SATA_PWRGT);
657 val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE;
658 writel(val, pll->pmc + PMC_SATA_PWRGT);
660 val = pll_readl_misc(pll);
662 timeout = jiffies + msecs_to_jiffies(100);
664 val = pll_readl_misc(pll);
665 if (val & PLLE_MISC_READY)
667 if (time_after(jiffies, timeout)) {
668 pr_err("%s: timeout waiting for PLLE\n", __func__);
677 static int clk_plle_enable(struct clk_hw *hw)
679 struct tegra_clk_pll *pll = to_clk_pll(hw);
680 unsigned long input_rate = clk_get_rate(clk_get_parent(hw->clk));
681 struct tegra_clk_pll_freq_table sel;
685 if (_get_table_rate(hw, &sel, pll->fixed_rate, input_rate))
690 val = pll_readl_misc(pll);
691 val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK);
692 pll_writel_misc(val, pll);
694 val = pll_readl_misc(pll);
695 if (!(val & PLLE_MISC_READY)) {
696 err = clk_plle_training(pll);
701 if (pll->flags & TEGRA_PLLE_CONFIGURE) {
702 /* configure dividers */
703 val = pll_readl_base(pll);
704 val &= ~(divm_mask(pll) | divn_mask(pll) | divp_mask(pll));
705 val &= ~(PLLE_BASE_DIVCML_WIDTH << PLLE_BASE_DIVCML_SHIFT);
706 val |= sel.m << pll->params->div_nmp->divm_shift;
707 val |= sel.n << pll->params->div_nmp->divn_shift;
708 val |= sel.p << pll->params->div_nmp->divp_shift;
709 val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
710 pll_writel_base(val, pll);
713 val = pll_readl_misc(pll);
714 val |= PLLE_MISC_SETUP_VALUE;
715 val |= PLLE_MISC_LOCK_ENABLE;
716 pll_writel_misc(val, pll);
718 val = readl(pll->clk_base + PLLE_SS_CTRL);
719 val |= PLLE_SS_DISABLE;
720 writel(val, pll->clk_base + PLLE_SS_CTRL);
722 val |= pll_readl_base(pll);
723 val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE);
724 pll_writel_base(val, pll);
726 clk_pll_wait_for_lock(pll);
731 static unsigned long clk_plle_recalc_rate(struct clk_hw *hw,
732 unsigned long parent_rate)
734 struct tegra_clk_pll *pll = to_clk_pll(hw);
735 u32 val = pll_readl_base(pll);
736 u32 divn = 0, divm = 0, divp = 0;
737 u64 rate = parent_rate;
739 divp = (val >> pll->params->div_nmp->divp_shift) & (divp_mask(pll));
740 divn = (val >> pll->params->div_nmp->divn_shift) & (divn_mask(pll));
741 divm = (val >> pll->params->div_nmp->divm_shift) & (divm_mask(pll));
749 const struct clk_ops tegra_clk_pll_ops = {
750 .is_enabled = clk_pll_is_enabled,
751 .enable = clk_pll_enable,
752 .disable = clk_pll_disable,
753 .recalc_rate = clk_pll_recalc_rate,
754 .round_rate = clk_pll_round_rate,
755 .set_rate = clk_pll_set_rate,
758 const struct clk_ops tegra_clk_plle_ops = {
759 .recalc_rate = clk_plle_recalc_rate,
760 .is_enabled = clk_pll_is_enabled,
761 .disable = clk_pll_disable,
762 .enable = clk_plle_enable,
765 #ifdef CONFIG_ARCH_TEGRA_114_SOC
767 static int _pll_fixed_mdiv(struct tegra_clk_pll_params *pll_params,
768 unsigned long parent_rate)
770 if (parent_rate > pll_params->cf_max)
776 static int clk_pll_iddq_enable(struct clk_hw *hw)
778 struct tegra_clk_pll *pll = to_clk_pll(hw);
779 unsigned long flags = 0;
785 spin_lock_irqsave(pll->lock, flags);
787 val = pll_readl(pll->params->iddq_reg, pll);
788 val &= ~BIT(pll->params->iddq_bit_idx);
789 pll_writel(val, pll->params->iddq_reg, pll);
794 ret = clk_pll_wait_for_lock(pll);
797 spin_unlock_irqrestore(pll->lock, flags);
802 static void clk_pll_iddq_disable(struct clk_hw *hw)
804 struct tegra_clk_pll *pll = to_clk_pll(hw);
805 unsigned long flags = 0;
809 spin_lock_irqsave(pll->lock, flags);
811 _clk_pll_disable(hw);
813 val = pll_readl(pll->params->iddq_reg, pll);
814 val |= BIT(pll->params->iddq_bit_idx);
815 pll_writel(val, pll->params->iddq_reg, pll);
819 spin_unlock_irqrestore(pll->lock, flags);
822 static int _calc_dynamic_ramp_rate(struct clk_hw *hw,
823 struct tegra_clk_pll_freq_table *cfg,
824 unsigned long rate, unsigned long parent_rate)
826 struct tegra_clk_pll *pll = to_clk_pll(hw);
833 p = DIV_ROUND_UP(pll->params->vco_min, rate);
834 cfg->m = _pll_fixed_mdiv(pll->params, parent_rate);
835 cfg->output_rate = rate * p;
836 cfg->n = cfg->output_rate * cfg->m / parent_rate;
838 p_div = _p_div_to_hw(hw, p);
844 if (cfg->n > divn_max(pll) || cfg->output_rate > pll->params->vco_max)
850 static int _pll_ramp_calc_pll(struct clk_hw *hw,
851 struct tegra_clk_pll_freq_table *cfg,
852 unsigned long rate, unsigned long parent_rate)
854 struct tegra_clk_pll *pll = to_clk_pll(hw);
857 err = _get_table_rate(hw, cfg, rate, parent_rate);
859 err = _calc_dynamic_ramp_rate(hw, cfg, rate, parent_rate);
861 if (cfg->m != _pll_fixed_mdiv(pll->params, parent_rate)) {
866 p_div = _p_div_to_hw(hw, cfg->p);
873 if (cfg->p > pll->params->max_p)
880 static int clk_pllxc_set_rate(struct clk_hw *hw, unsigned long rate,
881 unsigned long parent_rate)
883 struct tegra_clk_pll *pll = to_clk_pll(hw);
884 struct tegra_clk_pll_freq_table cfg, old_cfg;
885 unsigned long flags = 0;
888 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
893 spin_lock_irqsave(pll->lock, flags);
895 _get_pll_mnp(pll, &old_cfg);
897 if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p)
898 ret = _program_pll(hw, &cfg, rate);
901 spin_unlock_irqrestore(pll->lock, flags);
906 static long clk_pll_ramp_round_rate(struct clk_hw *hw, unsigned long rate,
907 unsigned long *prate)
909 struct tegra_clk_pll_freq_table cfg;
911 u64 output_rate = *prate;
913 ret = _pll_ramp_calc_pll(hw, &cfg, rate, *prate);
917 p_div = _hw_to_p_div(hw, cfg.p);
921 output_rate *= cfg.n;
922 do_div(output_rate, cfg.m * p_div);
927 static int clk_pllm_set_rate(struct clk_hw *hw, unsigned long rate,
928 unsigned long parent_rate)
930 struct tegra_clk_pll_freq_table cfg;
931 struct tegra_clk_pll *pll = to_clk_pll(hw);
932 unsigned long flags = 0;
936 spin_lock_irqsave(pll->lock, flags);
938 state = clk_pll_is_enabled(hw);
940 if (rate != clk_get_rate(hw->clk)) {
941 pr_err("%s: Cannot change active PLLM\n", __func__);
948 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
952 _update_pll_mnp(pll, &cfg);
956 spin_unlock_irqrestore(pll->lock, flags);
961 static void _pllcx_strobe(struct tegra_clk_pll *pll)
965 val = pll_readl_misc(pll);
966 val |= PLLCX_MISC_STROBE;
967 pll_writel_misc(val, pll);
970 val &= ~PLLCX_MISC_STROBE;
971 pll_writel_misc(val, pll);
974 static int clk_pllc_enable(struct clk_hw *hw)
976 struct tegra_clk_pll *pll = to_clk_pll(hw);
979 unsigned long flags = 0;
982 spin_lock_irqsave(pll->lock, flags);
987 val = pll_readl_misc(pll);
988 val &= ~PLLCX_MISC_RESET;
989 pll_writel_misc(val, pll);
994 ret = clk_pll_wait_for_lock(pll);
997 spin_unlock_irqrestore(pll->lock, flags);
1002 static void _clk_pllc_disable(struct clk_hw *hw)
1004 struct tegra_clk_pll *pll = to_clk_pll(hw);
1007 _clk_pll_disable(hw);
1009 val = pll_readl_misc(pll);
1010 val |= PLLCX_MISC_RESET;
1011 pll_writel_misc(val, pll);
1015 static void clk_pllc_disable(struct clk_hw *hw)
1017 struct tegra_clk_pll *pll = to_clk_pll(hw);
1018 unsigned long flags = 0;
1021 spin_lock_irqsave(pll->lock, flags);
1023 _clk_pllc_disable(hw);
1026 spin_unlock_irqrestore(pll->lock, flags);
1029 static int _pllcx_update_dynamic_coef(struct tegra_clk_pll *pll,
1030 unsigned long input_rate, u32 n)
1032 u32 val, n_threshold;
1034 switch (input_rate) {
1049 pr_err("%s: Unexpected reference rate %lu\n",
1050 __func__, input_rate);
1054 val = pll_readl_misc(pll);
1055 val &= ~(PLLCX_MISC_SDM_DIV_MASK | PLLCX_MISC_FILT_DIV_MASK);
1056 val |= n <= n_threshold ?
1057 PLLCX_MISC_DIV_LOW_RANGE : PLLCX_MISC_DIV_HIGH_RANGE;
1058 pll_writel_misc(val, pll);
1063 static int clk_pllc_set_rate(struct clk_hw *hw, unsigned long rate,
1064 unsigned long parent_rate)
1066 struct tegra_clk_pll_freq_table cfg, old_cfg;
1067 struct tegra_clk_pll *pll = to_clk_pll(hw);
1068 unsigned long flags = 0;
1072 spin_lock_irqsave(pll->lock, flags);
1074 ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate);
1078 _get_pll_mnp(pll, &old_cfg);
1080 if (cfg.m != old_cfg.m) {
1085 if (old_cfg.n == cfg.n && old_cfg.p == cfg.p)
1088 state = clk_pll_is_enabled(hw);
1090 _clk_pllc_disable(hw);
1092 ret = _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
1096 _update_pll_mnp(pll, &cfg);
1099 ret = clk_pllc_enable(hw);
1103 spin_unlock_irqrestore(pll->lock, flags);
1108 static long _pllre_calc_rate(struct tegra_clk_pll *pll,
1109 struct tegra_clk_pll_freq_table *cfg,
1110 unsigned long rate, unsigned long parent_rate)
1113 u64 output_rate = parent_rate;
1115 m = _pll_fixed_mdiv(pll->params, parent_rate);
1116 n = rate * m / parent_rate;
1119 do_div(output_rate, m);
1128 static int clk_pllre_set_rate(struct clk_hw *hw, unsigned long rate,
1129 unsigned long parent_rate)
1131 struct tegra_clk_pll_freq_table cfg, old_cfg;
1132 struct tegra_clk_pll *pll = to_clk_pll(hw);
1133 unsigned long flags = 0;
1137 spin_lock_irqsave(pll->lock, flags);
1139 _pllre_calc_rate(pll, &cfg, rate, parent_rate);
1140 _get_pll_mnp(pll, &old_cfg);
1143 if (cfg.m != old_cfg.m || cfg.n != old_cfg.n) {
1144 state = clk_pll_is_enabled(hw);
1146 _clk_pll_disable(hw);
1148 _update_pll_mnp(pll, &cfg);
1151 _clk_pll_enable(hw);
1152 ret = clk_pll_wait_for_lock(pll);
1157 spin_unlock_irqrestore(pll->lock, flags);
1162 static unsigned long clk_pllre_recalc_rate(struct clk_hw *hw,
1163 unsigned long parent_rate)
1165 struct tegra_clk_pll_freq_table cfg;
1166 struct tegra_clk_pll *pll = to_clk_pll(hw);
1167 u64 rate = parent_rate;
1169 _get_pll_mnp(pll, &cfg);
1172 do_div(rate, cfg.m);
1177 static long clk_pllre_round_rate(struct clk_hw *hw, unsigned long rate,
1178 unsigned long *prate)
1180 struct tegra_clk_pll *pll = to_clk_pll(hw);
1182 return _pllre_calc_rate(pll, NULL, rate, *prate);
1185 static int clk_plle_tegra114_enable(struct clk_hw *hw)
1187 struct tegra_clk_pll *pll = to_clk_pll(hw);
1188 struct tegra_clk_pll_freq_table sel;
1191 unsigned long flags = 0;
1192 unsigned long input_rate = clk_get_rate(clk_get_parent(hw->clk));
1194 if (_get_table_rate(hw, &sel, pll->fixed_rate, input_rate))
1198 spin_lock_irqsave(pll->lock, flags);
1200 val = pll_readl_base(pll);
1201 val &= ~BIT(29); /* Disable lock override */
1202 pll_writel_base(val, pll);
1204 val = pll_readl(pll->params->aux_reg, pll);
1205 val |= PLLE_AUX_ENABLE_SWCTL;
1206 val &= ~PLLE_AUX_SEQ_ENABLE;
1207 pll_writel(val, pll->params->aux_reg, pll);
1210 val = pll_readl_misc(pll);
1211 val |= PLLE_MISC_LOCK_ENABLE;
1212 val |= PLLE_MISC_IDDQ_SW_CTRL;
1213 val &= ~PLLE_MISC_IDDQ_SW_VALUE;
1214 val |= PLLE_MISC_PLLE_PTS;
1215 val |= PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK;
1216 pll_writel_misc(val, pll);
1219 val = pll_readl(PLLE_SS_CTRL, pll);
1220 val |= PLLE_SS_DISABLE;
1221 pll_writel(val, PLLE_SS_CTRL, pll);
1223 val = pll_readl_base(pll);
1224 val &= ~(divm_mask(pll) | divn_mask(pll) | divp_mask(pll));
1225 val &= ~(PLLE_BASE_DIVCML_WIDTH << PLLE_BASE_DIVCML_SHIFT);
1226 val |= sel.m << pll->params->div_nmp->divm_shift;
1227 val |= sel.n << pll->params->div_nmp->divn_shift;
1228 val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT;
1229 pll_writel_base(val, pll);
1232 _clk_pll_enable(hw);
1233 ret = clk_pll_wait_for_lock(pll);
1238 val = pll_readl(PLLE_SS_CTRL, pll);
1239 val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT);
1240 val &= ~PLLE_SS_COEFFICIENTS_MASK;
1241 val |= PLLE_SS_COEFFICIENTS_VAL;
1242 pll_writel(val, PLLE_SS_CTRL, pll);
1243 val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS);
1244 pll_writel(val, PLLE_SS_CTRL, pll);
1246 val &= ~PLLE_SS_CNTL_INTERP_RESET;
1247 pll_writel(val, PLLE_SS_CTRL, pll);
1250 /* TODO: enable hw control of xusb brick pll */
1254 spin_unlock_irqrestore(pll->lock, flags);
1259 static void clk_plle_tegra114_disable(struct clk_hw *hw)
1261 struct tegra_clk_pll *pll = to_clk_pll(hw);
1262 unsigned long flags = 0;
1266 spin_lock_irqsave(pll->lock, flags);
1268 _clk_pll_disable(hw);
1270 val = pll_readl_misc(pll);
1271 val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE;
1272 pll_writel_misc(val, pll);
1276 spin_unlock_irqrestore(pll->lock, flags);
1280 static struct tegra_clk_pll *_tegra_init_pll(void __iomem *clk_base,
1281 void __iomem *pmc, unsigned long fixed_rate,
1282 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
1283 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
1285 struct tegra_clk_pll *pll;
1287 pll = kzalloc(sizeof(*pll), GFP_KERNEL);
1289 return ERR_PTR(-ENOMEM);
1291 pll->clk_base = clk_base;
1294 pll->freq_table = freq_table;
1295 pll->params = pll_params;
1296 pll->fixed_rate = fixed_rate;
1297 pll->flags = pll_flags;
1300 if (!pll_params->div_nmp)
1301 pll_params->div_nmp = &default_nmp;
1306 static struct clk *_tegra_clk_register_pll(struct tegra_clk_pll *pll,
1307 const char *name, const char *parent_name, unsigned long flags,
1308 const struct clk_ops *ops)
1310 struct clk_init_data init;
1315 init.parent_names = (parent_name ? &parent_name : NULL);
1316 init.num_parents = (parent_name ? 1 : 0);
1318 /* Data in .init is copied by clk_register(), so stack variable OK */
1319 pll->hw.init = &init;
1321 return clk_register(NULL, &pll->hw);
1324 struct clk *tegra_clk_register_pll(const char *name, const char *parent_name,
1325 void __iomem *clk_base, void __iomem *pmc,
1326 unsigned long flags, unsigned long fixed_rate,
1327 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
1328 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
1330 struct tegra_clk_pll *pll;
1333 pll_flags |= TEGRA_PLL_BYPASS;
1334 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1335 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1338 return ERR_CAST(pll);
1340 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1341 &tegra_clk_pll_ops);
1348 struct clk *tegra_clk_register_plle(const char *name, const char *parent_name,
1349 void __iomem *clk_base, void __iomem *pmc,
1350 unsigned long flags, unsigned long fixed_rate,
1351 struct tegra_clk_pll_params *pll_params, u32 pll_flags,
1352 struct tegra_clk_pll_freq_table *freq_table, spinlock_t *lock)
1354 struct tegra_clk_pll *pll;
1357 pll_flags |= TEGRA_PLL_LOCK_MISC | TEGRA_PLL_BYPASS;
1358 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1359 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1362 return ERR_CAST(pll);
1364 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1365 &tegra_clk_plle_ops);
1372 #ifdef CONFIG_ARCH_TEGRA_114_SOC
1373 const struct clk_ops tegra_clk_pllxc_ops = {
1374 .is_enabled = clk_pll_is_enabled,
1375 .enable = clk_pll_iddq_enable,
1376 .disable = clk_pll_iddq_disable,
1377 .recalc_rate = clk_pll_recalc_rate,
1378 .round_rate = clk_pll_ramp_round_rate,
1379 .set_rate = clk_pllxc_set_rate,
1382 const struct clk_ops tegra_clk_pllm_ops = {
1383 .is_enabled = clk_pll_is_enabled,
1384 .enable = clk_pll_iddq_enable,
1385 .disable = clk_pll_iddq_disable,
1386 .recalc_rate = clk_pll_recalc_rate,
1387 .round_rate = clk_pll_ramp_round_rate,
1388 .set_rate = clk_pllm_set_rate,
1391 const struct clk_ops tegra_clk_pllc_ops = {
1392 .is_enabled = clk_pll_is_enabled,
1393 .enable = clk_pllc_enable,
1394 .disable = clk_pllc_disable,
1395 .recalc_rate = clk_pll_recalc_rate,
1396 .round_rate = clk_pll_ramp_round_rate,
1397 .set_rate = clk_pllc_set_rate,
1400 const struct clk_ops tegra_clk_pllre_ops = {
1401 .is_enabled = clk_pll_is_enabled,
1402 .enable = clk_pll_iddq_enable,
1403 .disable = clk_pll_iddq_disable,
1404 .recalc_rate = clk_pllre_recalc_rate,
1405 .round_rate = clk_pllre_round_rate,
1406 .set_rate = clk_pllre_set_rate,
1409 const struct clk_ops tegra_clk_plle_tegra114_ops = {
1410 .is_enabled = clk_pll_is_enabled,
1411 .enable = clk_plle_tegra114_enable,
1412 .disable = clk_plle_tegra114_disable,
1413 .recalc_rate = clk_pll_recalc_rate,
1417 struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name,
1418 void __iomem *clk_base, void __iomem *pmc,
1419 unsigned long flags, unsigned long fixed_rate,
1420 struct tegra_clk_pll_params *pll_params,
1422 struct tegra_clk_pll_freq_table *freq_table,
1425 struct tegra_clk_pll *pll;
1428 if (!pll_params->pdiv_tohw)
1429 return ERR_PTR(-EINVAL);
1431 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1432 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1435 return ERR_CAST(pll);
1437 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1438 &tegra_clk_pllxc_ops);
1445 struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name,
1446 void __iomem *clk_base, void __iomem *pmc,
1447 unsigned long flags, unsigned long fixed_rate,
1448 struct tegra_clk_pll_params *pll_params,
1450 struct tegra_clk_pll_freq_table *freq_table,
1451 spinlock_t *lock, unsigned long parent_rate)
1454 struct tegra_clk_pll *pll;
1457 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE | TEGRA_PLL_LOCK_MISC;
1458 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1461 return ERR_CAST(pll);
1463 /* program minimum rate by default */
1465 val = pll_readl_base(pll);
1466 if (val & PLL_BASE_ENABLE)
1467 WARN_ON(val & pll_params->iddq_bit_idx);
1471 m = _pll_fixed_mdiv(pll_params, parent_rate);
1472 val = m << PLL_BASE_DIVM_SHIFT;
1473 val |= (pll_params->vco_min / parent_rate)
1474 << PLL_BASE_DIVN_SHIFT;
1475 pll_writel_base(val, pll);
1478 /* disable lock override */
1480 val = pll_readl_misc(pll);
1482 pll_writel_misc(val, pll);
1484 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1485 &tegra_clk_pllre_ops);
1492 struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name,
1493 void __iomem *clk_base, void __iomem *pmc,
1494 unsigned long flags, unsigned long fixed_rate,
1495 struct tegra_clk_pll_params *pll_params,
1497 struct tegra_clk_pll_freq_table *freq_table,
1500 struct tegra_clk_pll *pll;
1503 if (!pll_params->pdiv_tohw)
1504 return ERR_PTR(-EINVAL);
1506 pll_flags |= TEGRA_PLL_BYPASS;
1507 pll_flags |= TEGRA_PLL_HAS_LOCK_ENABLE;
1508 pll_flags |= TEGRA_PLLM;
1509 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1512 return ERR_CAST(pll);
1514 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1515 &tegra_clk_pllm_ops);
1522 struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name,
1523 void __iomem *clk_base, void __iomem *pmc,
1524 unsigned long flags, unsigned long fixed_rate,
1525 struct tegra_clk_pll_params *pll_params,
1527 struct tegra_clk_pll_freq_table *freq_table,
1530 struct clk *parent, *clk;
1531 struct pdiv_map *p_tohw = pll_params->pdiv_tohw;
1532 struct tegra_clk_pll *pll;
1533 struct tegra_clk_pll_freq_table cfg;
1534 unsigned long parent_rate;
1537 return ERR_PTR(-EINVAL);
1539 parent = __clk_lookup(parent_name);
1540 if (IS_ERR(parent)) {
1541 WARN(1, "parent clk %s of %s must be registered first\n",
1543 return ERR_PTR(-EINVAL);
1546 pll_flags |= TEGRA_PLL_BYPASS;
1547 pll = _tegra_init_pll(clk_base, pmc, fixed_rate, pll_params, pll_flags,
1550 return ERR_CAST(pll);
1552 parent_rate = __clk_get_rate(parent);
1555 * Most of PLLC register fields are shadowed, and can not be read
1556 * directly from PLL h/w. Hence, actual PLLC boot state is unknown.
1557 * Initialize PLL to default state: disabled, reset; shadow registers
1558 * loaded with default parameters; dividers are preset for half of
1559 * minimum VCO rate (the latter assured that shadowed divider settings
1560 * are within supported range).
1563 cfg.m = _pll_fixed_mdiv(pll_params, parent_rate);
1564 cfg.n = cfg.m * pll_params->vco_min / parent_rate;
1566 while (p_tohw->pdiv) {
1567 if (p_tohw->pdiv == 2) {
1568 cfg.p = p_tohw->hw_val;
1574 if (!p_tohw->pdiv) {
1576 return ERR_PTR(-EINVAL);
1579 pll_writel_base(0, pll);
1580 _update_pll_mnp(pll, &cfg);
1582 pll_writel_misc(PLLCX_MISC_DEFAULT, pll);
1583 pll_writel(PLLCX_MISC1_DEFAULT, pll_params->ext_misc_reg[0], pll);
1584 pll_writel(PLLCX_MISC2_DEFAULT, pll_params->ext_misc_reg[1], pll);
1585 pll_writel(PLLCX_MISC3_DEFAULT, pll_params->ext_misc_reg[2], pll);
1587 _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n);
1589 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1590 &tegra_clk_pllc_ops);
1597 struct clk *tegra_clk_register_plle_tegra114(const char *name,
1598 const char *parent_name,
1599 void __iomem *clk_base, unsigned long flags,
1600 unsigned long fixed_rate,
1601 struct tegra_clk_pll_params *pll_params,
1602 struct tegra_clk_pll_freq_table *freq_table,
1605 struct tegra_clk_pll *pll;
1609 pll = _tegra_init_pll(clk_base, NULL, fixed_rate, pll_params,
1610 TEGRA_PLL_HAS_LOCK_ENABLE, freq_table, lock);
1612 return ERR_CAST(pll);
1614 /* ensure parent is set to pll_re_vco */
1616 val = pll_readl_base(pll);
1617 val_aux = pll_readl(pll_params->aux_reg, pll);
1619 if (val & PLL_BASE_ENABLE) {
1620 if (!(val_aux & PLLE_AUX_PLLRE_SEL))
1621 WARN(1, "pll_e enabled with unsupported parent %s\n",
1622 (val & PLLE_AUX_PLLP_SEL) ? "pllp_out0" : "pll_ref");
1624 val_aux |= PLLE_AUX_PLLRE_SEL;
1625 pll_writel(val, pll_params->aux_reg, pll);
1628 clk = _tegra_clk_register_pll(pll, name, parent_name, flags,
1629 &tegra_clk_plle_tegra114_ops);