1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved.
6 #include <linux/slab.h>
8 #include <linux/delay.h>
10 #include <linux/clk.h>
11 #include <linux/clk-provider.h>
15 #define PLL_BASE_BYPASS BIT(31)
16 #define PLL_BASE_ENABLE BIT(30)
17 #define PLL_BASE_REF_ENABLE BIT(29)
18 #define PLL_BASE_OVERRIDE BIT(28)
20 #define PLL_BASE_DIVP_SHIFT 20
21 #define PLL_BASE_DIVP_WIDTH 3
22 #define PLL_BASE_DIVN_SHIFT 8
23 #define PLL_BASE_DIVN_WIDTH 10
24 #define PLL_BASE_DIVM_SHIFT 0
25 #define PLL_BASE_DIVM_WIDTH 5
26 #define PLLU_POST_DIVP_MASK 0x1
28 #define PLL_MISC_DCCON_SHIFT 20
29 #define PLL_MISC_CPCON_SHIFT 8
30 #define PLL_MISC_CPCON_WIDTH 4
31 #define PLL_MISC_CPCON_MASK ((1 << PLL_MISC_CPCON_WIDTH) - 1)
32 #define PLL_MISC_LFCON_SHIFT 4
33 #define PLL_MISC_LFCON_WIDTH 4
34 #define PLL_MISC_LFCON_MASK ((1 << PLL_MISC_LFCON_WIDTH) - 1)
35 #define PLL_MISC_VCOCON_SHIFT 0
36 #define PLL_MISC_VCOCON_WIDTH 4
37 #define PLL_MISC_VCOCON_MASK ((1 << PLL_MISC_VCOCON_WIDTH) - 1)
39 #define OUT_OF_TABLE_CPCON 8
41 #define PMC_PLLP_WB0_OVERRIDE 0xf8
42 #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12)
43 #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE BIT(11)
45 #define PLL_POST_LOCK_DELAY 50
47 #define PLLDU_LFCON_SET_DIVN 600
49 #define PLLE_BASE_DIVCML_SHIFT 24
50 #define PLLE_BASE_DIVCML_MASK 0xf
51 #define PLLE_BASE_DIVP_SHIFT 16
52 #define PLLE_BASE_DIVP_WIDTH 6
53 #define PLLE_BASE_DIVN_SHIFT 8
54 #define PLLE_BASE_DIVN_WIDTH 8
55 #define PLLE_BASE_DIVM_SHIFT 0
56 #define PLLE_BASE_DIVM_WIDTH 8
57 #define PLLE_BASE_ENABLE BIT(31)
59 #define PLLE_MISC_SETUP_BASE_SHIFT 16
60 #define PLLE_MISC_SETUP_BASE_MASK (0xffff << PLLE_MISC_SETUP_BASE_SHIFT)
61 #define PLLE_MISC_LOCK_ENABLE BIT(9)
62 #define PLLE_MISC_READY BIT(15)
63 #define PLLE_MISC_SETUP_EX_SHIFT 2
64 #define PLLE_MISC_SETUP_EX_MASK (3 << PLLE_MISC_SETUP_EX_SHIFT)
65 #define PLLE_MISC_SETUP_MASK (PLLE_MISC_SETUP_BASE_MASK | \
66 PLLE_MISC_SETUP_EX_MASK)
67 #define PLLE_MISC_SETUP_VALUE (7 << PLLE_MISC_SETUP_BASE_SHIFT)
69 #define PLLE_SS_CTRL 0x68
70 #define PLLE_SS_CNTL_BYPASS_SS BIT(10)
71 #define PLLE_SS_CNTL_INTERP_RESET BIT(11)
72 #define PLLE_SS_CNTL_SSC_BYP BIT(12)
73 #define PLLE_SS_CNTL_CENTER BIT(14)
74 #define PLLE_SS_CNTL_INVERT BIT(15)
75 #define PLLE_SS_DISABLE (PLLE_SS_CNTL_BYPASS_SS | PLLE_SS_CNTL_INTERP_RESET |\
77 #define PLLE_SS_MAX_MASK 0x1ff
78 #define PLLE_SS_MAX_VAL_TEGRA114 0x25
79 #define PLLE_SS_MAX_VAL_TEGRA210 0x21
80 #define PLLE_SS_INC_MASK (0xff << 16)
81 #define PLLE_SS_INC_VAL (0x1 << 16)
82 #define PLLE_SS_INCINTRV_MASK (0x3f << 24)
83 #define PLLE_SS_INCINTRV_VAL_TEGRA114 (0x20 << 24)
84 #define PLLE_SS_INCINTRV_VAL_TEGRA210 (0x23 << 24)
85 #define PLLE_SS_COEFFICIENTS_MASK \
86 (PLLE_SS_MAX_MASK | PLLE_SS_INC_MASK | PLLE_SS_INCINTRV_MASK)
87 #define PLLE_SS_COEFFICIENTS_VAL_TEGRA114 \
88 (PLLE_SS_MAX_VAL_TEGRA114 | PLLE_SS_INC_VAL |\
89 PLLE_SS_INCINTRV_VAL_TEGRA114)
90 #define PLLE_SS_COEFFICIENTS_VAL_TEGRA210 \
91 (PLLE_SS_MAX_VAL_TEGRA210 | PLLE_SS_INC_VAL |\
92 PLLE_SS_INCINTRV_VAL_TEGRA210)
94 #define PLLE_AUX_PLLP_SEL BIT(2)
95 #define PLLE_AUX_USE_LOCKDET BIT(3)
96 #define PLLE_AUX_ENABLE_SWCTL BIT(4)
97 #define PLLE_AUX_SS_SWCTL BIT(6)
98 #define PLLE_AUX_SEQ_ENABLE BIT(24)
99 #define PLLE_AUX_SEQ_START_STATE BIT(25)
100 #define PLLE_AUX_PLLRE_SEL BIT(28)
101 #define PLLE_AUX_SS_SEQ_INCLUDE BIT(31)
103 #define XUSBIO_PLL_CFG0 0x51c
104 #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
105 #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2)
106 #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6)
107 #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24)
108 #define XUSBIO_PLL_CFG0_SEQ_START_STATE BIT(25)
110 #define SATA_PLL_CFG0 0x490
111 #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0)
112 #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2)
113 #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24)
114 #define SATA_PLL_CFG0_SEQ_START_STATE BIT(25)
116 #define PLLE_MISC_PLLE_PTS BIT(8)
117 #define PLLE_MISC_IDDQ_SW_VALUE BIT(13)
118 #define PLLE_MISC_IDDQ_SW_CTRL BIT(14)
119 #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4
120 #define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT)
121 #define PLLE_MISC_VREG_CTRL_SHIFT 2
122 #define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT)
124 #define PLLCX_MISC_STROBE BIT(31)
125 #define PLLCX_MISC_RESET BIT(30)
126 #define PLLCX_MISC_SDM_DIV_SHIFT 28
127 #define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT)
128 #define PLLCX_MISC_FILT_DIV_SHIFT 26
129 #define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT)
130 #define PLLCX_MISC_ALPHA_SHIFT 18
131 #define PLLCX_MISC_DIV_LOW_RANGE \
132 ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \
133 (0x1 << PLLCX_MISC_FILT_DIV_SHIFT))
134 #define PLLCX_MISC_DIV_HIGH_RANGE \
135 ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \
136 (0x2 << PLLCX_MISC_FILT_DIV_SHIFT))
137 #define PLLCX_MISC_COEF_LOW_RANGE \
138 ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT))
139 #define PLLCX_MISC_KA_SHIFT 2
140 #define PLLCX_MISC_KB_SHIFT 9
141 #define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \
142 (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \
143 PLLCX_MISC_DIV_LOW_RANGE | \
145 #define PLLCX_MISC1_DEFAULT 0x000d2308
146 #define PLLCX_MISC2_DEFAULT 0x30211200
147 #define PLLCX_MISC3_DEFAULT 0x200
149 #define PMC_SATA_PWRGT 0x1ac
150 #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5)
151 #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4)
153 #define PLLSS_MISC_KCP 0
154 #define PLLSS_MISC_KVCO 0
155 #define PLLSS_MISC_SETUP 0
156 #define PLLSS_EN_SDM 0
157 #define PLLSS_EN_SSC 0
158 #define PLLSS_EN_DITHER2 0
159 #define PLLSS_EN_DITHER 1
160 #define PLLSS_SDM_RESET 0
161 #define PLLSS_CLAMP 0
162 #define PLLSS_SDM_SSC_MAX 0
163 #define PLLSS_SDM_SSC_MIN 0
164 #define PLLSS_SDM_SSC_STEP 0
165 #define PLLSS_SDM_DIN 0
166 #define PLLSS_MISC_DEFAULT ((PLLSS_MISC_KCP << 25) | \
167 (PLLSS_MISC_KVCO << 24) | \
169 #define PLLSS_CFG_DEFAULT ((PLLSS_EN_SDM << 31) | \
170 (PLLSS_EN_SSC << 30) | \
171 (PLLSS_EN_DITHER2 << 29) | \
172 (PLLSS_EN_DITHER << 28) | \
173 (PLLSS_SDM_RESET) << 27 | \
175 #define PLLSS_CTRL1_DEFAULT \
176 ((PLLSS_SDM_SSC_MAX << 16) | PLLSS_SDM_SSC_MIN)
177 #define PLLSS_CTRL2_DEFAULT \
178 ((PLLSS_SDM_SSC_STEP << 16) | PLLSS_SDM_DIN)
179 #define PLLSS_LOCK_OVERRIDE BIT(24)
180 #define PLLSS_REF_SRC_SEL_SHIFT 25
181 #define PLLSS_REF_SRC_SEL_MASK (3 << PLLSS_REF_SRC_SEL_SHIFT)
183 #define UTMIP_PLL_CFG1 0x484
184 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
185 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
186 #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
187 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
188 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15)
189 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
190 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17)
192 #define UTMIP_PLL_CFG2 0x488
193 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
194 #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
195 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
196 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1)
197 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
198 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3)
199 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
200 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5)
201 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24)
202 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25)
203 #define UTMIP_PLL_CFG2_PHY_XTAL_CLOCKEN BIT(30)
205 #define UTMIPLL_HW_PWRDN_CFG0 0x52c
206 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0)
207 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1)
208 #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
209 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4)
210 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5)
211 #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
212 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
213 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25)
215 #define PLLU_HW_PWRDN_CFG0 0x530
216 #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0)
217 #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2)
218 #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6)
219 #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7)
220 #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24)
221 #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28)
223 #define XUSB_PLL_CFG0 0x534
224 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff
225 #define XUSB_PLL_CFG0_PLLU_LOCK_DLY (0x3ff << 14)
227 #define PLLU_BASE_CLKENABLE_USB BIT(21)
228 #define PLLU_BASE_OVERRIDE BIT(24)
230 #define pll_readl(offset, p) readl_relaxed(p->clk_base + offset)
231 #define pll_readl_base(p) pll_readl(p->params->base_reg, p)
232 #define pll_readl_misc(p) pll_readl(p->params->misc_reg, p)
233 #define pll_override_readl(offset, p) readl_relaxed(p->pmc + offset)
234 #define pll_readl_sdm_din(p) pll_readl(p->params->sdm_din_reg, p)
235 #define pll_readl_sdm_ctrl(p) pll_readl(p->params->sdm_ctrl_reg, p)
237 #define pll_writel(val, offset, p) writel_relaxed(val, p->clk_base + offset)
238 #define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p)
239 #define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p)
240 #define pll_override_writel(val, offset, p) writel(val, p->pmc + offset)
241 #define pll_writel_sdm_din(val, p) pll_writel(val, p->params->sdm_din_reg, p)
242 #define pll_writel_sdm_ctrl(val, p) pll_writel(val, p->params->sdm_ctrl_reg, p)
244 #define mask(w) ((1 << (w)) - 1)
245 #define divm_mask(p) mask(p->params->div_nmp->divm_width)
246 #define divn_mask(p) mask(p->params->div_nmp->divn_width)
247 #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\
248 mask(p->params->div_nmp->divp_width))
249 #define sdm_din_mask(p) p->params->sdm_din_mask
250 #define sdm_en_mask(p) p->params->sdm_ctrl_en_mask
252 #define divm_shift(p) (p)->params->div_nmp->divm_shift
253 #define divn_shift(p) (p)->params->div_nmp->divn_shift
254 #define divp_shift(p) (p)->params->div_nmp->divp_shift
256 #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p))
257 #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p))
258 #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p))
260 #define divm_max(p) (divm_mask(p))
261 #define divn_max(p) (divn_mask(p))
262 #define divp_max(p) (1 << (divp_mask(p)))
264 #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU))
265 #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat)
267 static struct div_nmp default_nmp
= {
268 .divn_shift
= PLL_BASE_DIVN_SHIFT
,
269 .divn_width
= PLL_BASE_DIVN_WIDTH
,
270 .divm_shift
= PLL_BASE_DIVM_SHIFT
,
271 .divm_width
= PLL_BASE_DIVM_WIDTH
,
272 .divp_shift
= PLL_BASE_DIVP_SHIFT
,
273 .divp_width
= PLL_BASE_DIVP_WIDTH
,
276 static void clk_pll_enable_lock(struct tegra_clk_pll
*pll
)
280 if (!(pll
->params
->flags
& TEGRA_PLL_USE_LOCK
))
283 if (!(pll
->params
->flags
& TEGRA_PLL_HAS_LOCK_ENABLE
))
286 val
= pll_readl_misc(pll
);
287 val
|= BIT(pll
->params
->lock_enable_bit_idx
);
288 pll_writel_misc(val
, pll
);
291 static int clk_pll_wait_for_lock(struct tegra_clk_pll
*pll
)
295 void __iomem
*lock_addr
;
297 if (!(pll
->params
->flags
& TEGRA_PLL_USE_LOCK
)) {
298 udelay(pll
->params
->lock_delay
);
302 lock_addr
= pll
->clk_base
;
303 if (pll
->params
->flags
& TEGRA_PLL_LOCK_MISC
)
304 lock_addr
+= pll
->params
->misc_reg
;
306 lock_addr
+= pll
->params
->base_reg
;
308 lock_mask
= pll
->params
->lock_mask
;
310 for (i
= 0; i
< pll
->params
->lock_delay
; i
++) {
311 val
= readl_relaxed(lock_addr
);
312 if ((val
& lock_mask
) == lock_mask
) {
313 udelay(PLL_POST_LOCK_DELAY
);
316 udelay(2); /* timeout = 2 * lock time */
319 pr_err("%s: Timed out waiting for pll %s lock\n", __func__
,
320 clk_hw_get_name(&pll
->hw
));
325 int tegra_pll_wait_for_lock(struct tegra_clk_pll
*pll
)
327 return clk_pll_wait_for_lock(pll
);
330 static int clk_pll_is_enabled(struct clk_hw
*hw
)
332 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
335 if (pll
->params
->flags
& TEGRA_PLLM
) {
336 val
= readl_relaxed(pll
->pmc
+ PMC_PLLP_WB0_OVERRIDE
);
337 if (val
& PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE
)
338 return val
& PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE
? 1 : 0;
341 val
= pll_readl_base(pll
);
343 return val
& PLL_BASE_ENABLE
? 1 : 0;
346 static void _clk_pll_enable(struct clk_hw
*hw
)
348 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
351 if (pll
->params
->iddq_reg
) {
352 val
= pll_readl(pll
->params
->iddq_reg
, pll
);
353 val
&= ~BIT(pll
->params
->iddq_bit_idx
);
354 pll_writel(val
, pll
->params
->iddq_reg
, pll
);
358 if (pll
->params
->reset_reg
) {
359 val
= pll_readl(pll
->params
->reset_reg
, pll
);
360 val
&= ~BIT(pll
->params
->reset_bit_idx
);
361 pll_writel(val
, pll
->params
->reset_reg
, pll
);
364 clk_pll_enable_lock(pll
);
366 val
= pll_readl_base(pll
);
367 if (pll
->params
->flags
& TEGRA_PLL_BYPASS
)
368 val
&= ~PLL_BASE_BYPASS
;
369 val
|= PLL_BASE_ENABLE
;
370 pll_writel_base(val
, pll
);
372 if (pll
->params
->flags
& TEGRA_PLLM
) {
373 val
= readl_relaxed(pll
->pmc
+ PMC_PLLP_WB0_OVERRIDE
);
374 val
|= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE
;
375 writel_relaxed(val
, pll
->pmc
+ PMC_PLLP_WB0_OVERRIDE
);
379 static void _clk_pll_disable(struct clk_hw
*hw
)
381 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
384 val
= pll_readl_base(pll
);
385 if (pll
->params
->flags
& TEGRA_PLL_BYPASS
)
386 val
&= ~PLL_BASE_BYPASS
;
387 val
&= ~PLL_BASE_ENABLE
;
388 pll_writel_base(val
, pll
);
390 if (pll
->params
->flags
& TEGRA_PLLM
) {
391 val
= readl_relaxed(pll
->pmc
+ PMC_PLLP_WB0_OVERRIDE
);
392 val
&= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE
;
393 writel_relaxed(val
, pll
->pmc
+ PMC_PLLP_WB0_OVERRIDE
);
396 if (pll
->params
->reset_reg
) {
397 val
= pll_readl(pll
->params
->reset_reg
, pll
);
398 val
|= BIT(pll
->params
->reset_bit_idx
);
399 pll_writel(val
, pll
->params
->reset_reg
, pll
);
402 if (pll
->params
->iddq_reg
) {
403 val
= pll_readl(pll
->params
->iddq_reg
, pll
);
404 val
|= BIT(pll
->params
->iddq_bit_idx
);
405 pll_writel(val
, pll
->params
->iddq_reg
, pll
);
410 static void pll_clk_start_ss(struct tegra_clk_pll
*pll
)
412 if (pll
->params
->defaults_set
&& pll
->params
->ssc_ctrl_reg
) {
413 u32 val
= pll_readl(pll
->params
->ssc_ctrl_reg
, pll
);
415 val
|= pll
->params
->ssc_ctrl_en_mask
;
416 pll_writel(val
, pll
->params
->ssc_ctrl_reg
, pll
);
420 static void pll_clk_stop_ss(struct tegra_clk_pll
*pll
)
422 if (pll
->params
->defaults_set
&& pll
->params
->ssc_ctrl_reg
) {
423 u32 val
= pll_readl(pll
->params
->ssc_ctrl_reg
, pll
);
425 val
&= ~pll
->params
->ssc_ctrl_en_mask
;
426 pll_writel(val
, pll
->params
->ssc_ctrl_reg
, pll
);
430 static int clk_pll_enable(struct clk_hw
*hw
)
432 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
433 unsigned long flags
= 0;
436 if (clk_pll_is_enabled(hw
))
440 spin_lock_irqsave(pll
->lock
, flags
);
444 ret
= clk_pll_wait_for_lock(pll
);
446 pll_clk_start_ss(pll
);
449 spin_unlock_irqrestore(pll
->lock
, flags
);
454 static void clk_pll_disable(struct clk_hw
*hw
)
456 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
457 unsigned long flags
= 0;
460 spin_lock_irqsave(pll
->lock
, flags
);
462 pll_clk_stop_ss(pll
);
464 _clk_pll_disable(hw
);
467 spin_unlock_irqrestore(pll
->lock
, flags
);
470 static int _p_div_to_hw(struct clk_hw
*hw
, u8 p_div
)
472 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
473 const struct pdiv_map
*p_tohw
= pll
->params
->pdiv_tohw
;
476 while (p_tohw
->pdiv
) {
477 if (p_div
<= p_tohw
->pdiv
)
478 return p_tohw
->hw_val
;
486 int tegra_pll_p_div_to_hw(struct tegra_clk_pll
*pll
, u8 p_div
)
488 return _p_div_to_hw(&pll
->hw
, p_div
);
491 static int _hw_to_p_div(struct clk_hw
*hw
, u8 p_div_hw
)
493 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
494 const struct pdiv_map
*p_tohw
= pll
->params
->pdiv_tohw
;
497 while (p_tohw
->pdiv
) {
498 if (p_div_hw
== p_tohw
->hw_val
)
505 return 1 << p_div_hw
;
508 static int _get_table_rate(struct clk_hw
*hw
,
509 struct tegra_clk_pll_freq_table
*cfg
,
510 unsigned long rate
, unsigned long parent_rate
)
512 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
513 struct tegra_clk_pll_freq_table
*sel
;
516 for (sel
= pll
->params
->freq_table
; sel
->input_rate
!= 0; sel
++)
517 if (sel
->input_rate
== parent_rate
&&
518 sel
->output_rate
== rate
)
521 if (sel
->input_rate
== 0)
524 if (pll
->params
->pdiv_tohw
) {
525 p
= _p_div_to_hw(hw
, sel
->p
);
532 cfg
->input_rate
= sel
->input_rate
;
533 cfg
->output_rate
= sel
->output_rate
;
537 cfg
->cpcon
= sel
->cpcon
;
538 cfg
->sdm_data
= sel
->sdm_data
;
543 static int _calc_rate(struct clk_hw
*hw
, struct tegra_clk_pll_freq_table
*cfg
,
544 unsigned long rate
, unsigned long parent_rate
)
546 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
551 switch (parent_rate
) {
554 cfreq
= (rate
<= 1000000 * 1000) ? 1000000 : 2000000;
557 cfreq
= (rate
<= 1000000 * 1000) ? 1000000 : 2600000;
561 cfreq
= (rate
<= 1200000 * 1000) ? 1200000 : 2400000;
566 * PLL_P_OUT1 rate is not listed in PLLA table
568 cfreq
= parent_rate
/ (parent_rate
/ 1000000);
571 pr_err("%s Unexpected reference rate %lu\n",
572 __func__
, parent_rate
);
576 /* Raise VCO to guarantee 0.5% accuracy */
577 for (cfg
->output_rate
= rate
; cfg
->output_rate
< 200 * cfreq
;
578 cfg
->output_rate
<<= 1)
581 cfg
->m
= parent_rate
/ cfreq
;
582 cfg
->n
= cfg
->output_rate
/ cfreq
;
583 cfg
->cpcon
= OUT_OF_TABLE_CPCON
;
585 if (cfg
->m
== 0 || cfg
->m
> divm_max(pll
) ||
586 cfg
->n
> divn_max(pll
) || (1 << p_div
) > divp_max(pll
) ||
587 cfg
->output_rate
> pll
->params
->vco_max
) {
591 cfg
->output_rate
= cfg
->n
* DIV_ROUND_UP(parent_rate
, cfg
->m
);
592 cfg
->output_rate
>>= p_div
;
594 if (pll
->params
->pdiv_tohw
) {
595 ret
= _p_div_to_hw(hw
, 1 << p_div
);
607 * SDM (Sigma Delta Modulator) divisor is 16-bit 2's complement signed number
608 * within (-2^12 ... 2^12-1) range. Represented in PLL data structure as
609 * unsigned 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used
610 * to indicate that SDM is disabled.
612 * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13
614 static void clk_pll_set_sdm_data(struct clk_hw
*hw
,
615 struct tegra_clk_pll_freq_table
*cfg
)
617 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
621 if (!pll
->params
->sdm_din_reg
)
625 val
= pll_readl_sdm_din(pll
) & (~sdm_din_mask(pll
));
626 val
|= sdin_data_to_din(cfg
->sdm_data
) & sdm_din_mask(pll
);
627 pll_writel_sdm_din(val
, pll
);
630 val
= pll_readl_sdm_ctrl(pll
);
631 enabled
= (val
& sdm_en_mask(pll
));
633 if (cfg
->sdm_data
== 0 && enabled
)
634 val
&= ~pll
->params
->sdm_ctrl_en_mask
;
636 if (cfg
->sdm_data
!= 0 && !enabled
)
637 val
|= pll
->params
->sdm_ctrl_en_mask
;
639 pll_writel_sdm_ctrl(val
, pll
);
642 static void _update_pll_mnp(struct tegra_clk_pll
*pll
,
643 struct tegra_clk_pll_freq_table
*cfg
)
646 struct tegra_clk_pll_params
*params
= pll
->params
;
647 struct div_nmp
*div_nmp
= params
->div_nmp
;
649 if ((params
->flags
& (TEGRA_PLLM
| TEGRA_PLLMB
)) &&
650 (pll_override_readl(PMC_PLLP_WB0_OVERRIDE
, pll
) &
651 PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE
)) {
652 val
= pll_override_readl(params
->pmc_divp_reg
, pll
);
653 val
&= ~(divp_mask(pll
) << div_nmp
->override_divp_shift
);
654 val
|= cfg
->p
<< div_nmp
->override_divp_shift
;
655 pll_override_writel(val
, params
->pmc_divp_reg
, pll
);
657 val
= pll_override_readl(params
->pmc_divnm_reg
, pll
);
658 val
&= ~((divm_mask(pll
) << div_nmp
->override_divm_shift
) |
659 (divn_mask(pll
) << div_nmp
->override_divn_shift
));
660 val
|= (cfg
->m
<< div_nmp
->override_divm_shift
) |
661 (cfg
->n
<< div_nmp
->override_divn_shift
);
662 pll_override_writel(val
, params
->pmc_divnm_reg
, pll
);
664 val
= pll_readl_base(pll
);
666 val
&= ~(divm_mask_shifted(pll
) | divn_mask_shifted(pll
) |
667 divp_mask_shifted(pll
));
669 val
|= (cfg
->m
<< divm_shift(pll
)) |
670 (cfg
->n
<< divn_shift(pll
)) |
671 (cfg
->p
<< divp_shift(pll
));
673 pll_writel_base(val
, pll
);
675 clk_pll_set_sdm_data(&pll
->hw
, cfg
);
679 static void _get_pll_mnp(struct tegra_clk_pll
*pll
,
680 struct tegra_clk_pll_freq_table
*cfg
)
683 struct tegra_clk_pll_params
*params
= pll
->params
;
684 struct div_nmp
*div_nmp
= params
->div_nmp
;
686 *cfg
= (struct tegra_clk_pll_freq_table
) { };
688 if ((params
->flags
& (TEGRA_PLLM
| TEGRA_PLLMB
)) &&
689 (pll_override_readl(PMC_PLLP_WB0_OVERRIDE
, pll
) &
690 PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE
)) {
691 val
= pll_override_readl(params
->pmc_divp_reg
, pll
);
692 cfg
->p
= (val
>> div_nmp
->override_divp_shift
) & divp_mask(pll
);
694 val
= pll_override_readl(params
->pmc_divnm_reg
, pll
);
695 cfg
->m
= (val
>> div_nmp
->override_divm_shift
) & divm_mask(pll
);
696 cfg
->n
= (val
>> div_nmp
->override_divn_shift
) & divn_mask(pll
);
698 val
= pll_readl_base(pll
);
700 cfg
->m
= (val
>> div_nmp
->divm_shift
) & divm_mask(pll
);
701 cfg
->n
= (val
>> div_nmp
->divn_shift
) & divn_mask(pll
);
702 cfg
->p
= (val
>> div_nmp
->divp_shift
) & divp_mask(pll
);
704 if (pll
->params
->sdm_din_reg
) {
705 if (sdm_en_mask(pll
) & pll_readl_sdm_ctrl(pll
)) {
706 val
= pll_readl_sdm_din(pll
);
707 val
&= sdm_din_mask(pll
);
708 cfg
->sdm_data
= sdin_din_to_data(val
);
714 static void _update_pll_cpcon(struct tegra_clk_pll
*pll
,
715 struct tegra_clk_pll_freq_table
*cfg
,
720 val
= pll_readl_misc(pll
);
722 val
&= ~(PLL_MISC_CPCON_MASK
<< PLL_MISC_CPCON_SHIFT
);
723 val
|= cfg
->cpcon
<< PLL_MISC_CPCON_SHIFT
;
725 if (pll
->params
->flags
& TEGRA_PLL_SET_LFCON
) {
726 val
&= ~(PLL_MISC_LFCON_MASK
<< PLL_MISC_LFCON_SHIFT
);
727 if (cfg
->n
>= PLLDU_LFCON_SET_DIVN
)
728 val
|= 1 << PLL_MISC_LFCON_SHIFT
;
729 } else if (pll
->params
->flags
& TEGRA_PLL_SET_DCCON
) {
730 val
&= ~(1 << PLL_MISC_DCCON_SHIFT
);
731 if (rate
>= (pll
->params
->vco_max
>> 1))
732 val
|= 1 << PLL_MISC_DCCON_SHIFT
;
735 pll_writel_misc(val
, pll
);
738 static int _program_pll(struct clk_hw
*hw
, struct tegra_clk_pll_freq_table
*cfg
,
741 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
742 struct tegra_clk_pll_freq_table old_cfg
;
745 state
= clk_pll_is_enabled(hw
);
747 _get_pll_mnp(pll
, &old_cfg
);
749 if (state
&& pll
->params
->defaults_set
&& pll
->params
->dyn_ramp
&&
750 (cfg
->m
== old_cfg
.m
) && (cfg
->p
== old_cfg
.p
)) {
751 ret
= pll
->params
->dyn_ramp(pll
, cfg
);
757 pll_clk_stop_ss(pll
);
758 _clk_pll_disable(hw
);
761 if (!pll
->params
->defaults_set
&& pll
->params
->set_defaults
)
762 pll
->params
->set_defaults(pll
);
764 _update_pll_mnp(pll
, cfg
);
766 if (pll
->params
->flags
& TEGRA_PLL_HAS_CPCON
)
767 _update_pll_cpcon(pll
, cfg
, rate
);
771 ret
= clk_pll_wait_for_lock(pll
);
772 pll_clk_start_ss(pll
);
778 static int clk_pll_set_rate(struct clk_hw
*hw
, unsigned long rate
,
779 unsigned long parent_rate
)
781 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
782 struct tegra_clk_pll_freq_table cfg
, old_cfg
;
783 unsigned long flags
= 0;
786 if (pll
->params
->flags
& TEGRA_PLL_FIXED
) {
787 if (rate
!= pll
->params
->fixed_rate
) {
788 pr_err("%s: Can not change %s fixed rate %lu to %lu\n",
789 __func__
, clk_hw_get_name(hw
),
790 pll
->params
->fixed_rate
, rate
);
796 if (_get_table_rate(hw
, &cfg
, rate
, parent_rate
) &&
797 pll
->params
->calc_rate(hw
, &cfg
, rate
, parent_rate
)) {
798 pr_err("%s: Failed to set %s rate %lu\n", __func__
,
799 clk_hw_get_name(hw
), rate
);
804 spin_lock_irqsave(pll
->lock
, flags
);
806 _get_pll_mnp(pll
, &old_cfg
);
807 if (pll
->params
->flags
& TEGRA_PLL_VCO_OUT
)
810 if (old_cfg
.m
!= cfg
.m
|| old_cfg
.n
!= cfg
.n
|| old_cfg
.p
!= cfg
.p
||
811 old_cfg
.sdm_data
!= cfg
.sdm_data
)
812 ret
= _program_pll(hw
, &cfg
, rate
);
815 spin_unlock_irqrestore(pll
->lock
, flags
);
820 static long clk_pll_round_rate(struct clk_hw
*hw
, unsigned long rate
,
821 unsigned long *prate
)
823 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
824 struct tegra_clk_pll_freq_table cfg
;
826 if (pll
->params
->flags
& TEGRA_PLL_FIXED
) {
827 /* PLLM/MB are used for memory; we do not change rate */
828 if (pll
->params
->flags
& (TEGRA_PLLM
| TEGRA_PLLMB
))
829 return clk_hw_get_rate(hw
);
830 return pll
->params
->fixed_rate
;
833 if (_get_table_rate(hw
, &cfg
, rate
, *prate
) &&
834 pll
->params
->calc_rate(hw
, &cfg
, rate
, *prate
))
837 return cfg
.output_rate
;
840 static unsigned long clk_pll_recalc_rate(struct clk_hw
*hw
,
841 unsigned long parent_rate
)
843 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
844 struct tegra_clk_pll_freq_table cfg
;
846 u64 rate
= parent_rate
;
849 val
= pll_readl_base(pll
);
851 if ((pll
->params
->flags
& TEGRA_PLL_BYPASS
) && (val
& PLL_BASE_BYPASS
))
854 if ((pll
->params
->flags
& TEGRA_PLL_FIXED
) &&
855 !(pll
->params
->flags
& (TEGRA_PLLM
| TEGRA_PLLMB
)) &&
856 !(val
& PLL_BASE_OVERRIDE
)) {
857 struct tegra_clk_pll_freq_table sel
;
858 if (_get_table_rate(hw
, &sel
, pll
->params
->fixed_rate
,
860 pr_err("Clock %s has unknown fixed frequency\n",
861 clk_hw_get_name(hw
));
864 return pll
->params
->fixed_rate
;
867 _get_pll_mnp(pll
, &cfg
);
869 if (pll
->params
->flags
& TEGRA_PLL_VCO_OUT
) {
872 pdiv
= _hw_to_p_div(hw
, cfg
.p
);
874 WARN(1, "Clock %s has invalid pdiv value : 0x%x\n",
875 clk_hw_get_name(hw
), cfg
.p
);
880 if (pll
->params
->set_gain
)
881 pll
->params
->set_gain(&cfg
);
891 static int clk_plle_training(struct tegra_clk_pll
*pll
)
894 unsigned long timeout
;
900 * PLLE is already disabled, and setup cleared;
901 * create falling edge on PLLE IDDQ input.
903 val
= readl(pll
->pmc
+ PMC_SATA_PWRGT
);
904 val
|= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE
;
905 writel(val
, pll
->pmc
+ PMC_SATA_PWRGT
);
907 val
= readl(pll
->pmc
+ PMC_SATA_PWRGT
);
908 val
|= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL
;
909 writel(val
, pll
->pmc
+ PMC_SATA_PWRGT
);
911 val
= readl(pll
->pmc
+ PMC_SATA_PWRGT
);
912 val
&= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE
;
913 writel(val
, pll
->pmc
+ PMC_SATA_PWRGT
);
915 val
= pll_readl_misc(pll
);
917 timeout
= jiffies
+ msecs_to_jiffies(100);
919 val
= pll_readl_misc(pll
);
920 if (val
& PLLE_MISC_READY
)
922 if (time_after(jiffies
, timeout
)) {
923 pr_err("%s: timeout waiting for PLLE\n", __func__
);
932 static int clk_plle_enable(struct clk_hw
*hw
)
934 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
935 struct tegra_clk_pll_freq_table sel
;
936 unsigned long input_rate
;
940 if (clk_pll_is_enabled(hw
))
943 input_rate
= clk_hw_get_rate(clk_hw_get_parent(hw
));
945 if (_get_table_rate(hw
, &sel
, pll
->params
->fixed_rate
, input_rate
))
950 val
= pll_readl_misc(pll
);
951 val
&= ~(PLLE_MISC_LOCK_ENABLE
| PLLE_MISC_SETUP_MASK
);
952 pll_writel_misc(val
, pll
);
954 val
= pll_readl_misc(pll
);
955 if (!(val
& PLLE_MISC_READY
)) {
956 err
= clk_plle_training(pll
);
961 if (pll
->params
->flags
& TEGRA_PLLE_CONFIGURE
) {
962 /* configure dividers */
963 val
= pll_readl_base(pll
);
964 val
&= ~(divp_mask_shifted(pll
) | divn_mask_shifted(pll
) |
965 divm_mask_shifted(pll
));
966 val
&= ~(PLLE_BASE_DIVCML_MASK
<< PLLE_BASE_DIVCML_SHIFT
);
967 val
|= sel
.m
<< divm_shift(pll
);
968 val
|= sel
.n
<< divn_shift(pll
);
969 val
|= sel
.p
<< divp_shift(pll
);
970 val
|= sel
.cpcon
<< PLLE_BASE_DIVCML_SHIFT
;
971 pll_writel_base(val
, pll
);
974 val
= pll_readl_misc(pll
);
975 val
|= PLLE_MISC_SETUP_VALUE
;
976 val
|= PLLE_MISC_LOCK_ENABLE
;
977 pll_writel_misc(val
, pll
);
979 val
= readl(pll
->clk_base
+ PLLE_SS_CTRL
);
980 val
&= ~PLLE_SS_COEFFICIENTS_MASK
;
981 val
|= PLLE_SS_DISABLE
;
982 writel(val
, pll
->clk_base
+ PLLE_SS_CTRL
);
984 val
= pll_readl_base(pll
);
985 val
|= (PLL_BASE_BYPASS
| PLL_BASE_ENABLE
);
986 pll_writel_base(val
, pll
);
988 clk_pll_wait_for_lock(pll
);
993 static unsigned long clk_plle_recalc_rate(struct clk_hw
*hw
,
994 unsigned long parent_rate
)
996 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
997 u32 val
= pll_readl_base(pll
);
998 u32 divn
= 0, divm
= 0, divp
= 0;
999 u64 rate
= parent_rate
;
1001 divp
= (val
>> pll
->params
->div_nmp
->divp_shift
) & (divp_mask(pll
));
1002 divn
= (val
>> pll
->params
->div_nmp
->divn_shift
) & (divn_mask(pll
));
1003 divm
= (val
>> pll
->params
->div_nmp
->divm_shift
) & (divm_mask(pll
));
1011 static void tegra_clk_pll_restore_context(struct clk_hw
*hw
)
1013 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1014 struct clk_hw
*parent
= clk_hw_get_parent(hw
);
1015 unsigned long parent_rate
= clk_hw_get_rate(parent
);
1016 unsigned long rate
= clk_hw_get_rate(hw
);
1018 if (clk_pll_is_enabled(hw
))
1021 if (pll
->params
->set_defaults
)
1022 pll
->params
->set_defaults(pll
);
1024 clk_pll_set_rate(hw
, rate
, parent_rate
);
1026 if (!__clk_get_enable_count(hw
->clk
))
1027 clk_pll_disable(hw
);
1032 const struct clk_ops tegra_clk_pll_ops
= {
1033 .is_enabled
= clk_pll_is_enabled
,
1034 .enable
= clk_pll_enable
,
1035 .disable
= clk_pll_disable
,
1036 .recalc_rate
= clk_pll_recalc_rate
,
1037 .round_rate
= clk_pll_round_rate
,
1038 .set_rate
= clk_pll_set_rate
,
1039 .restore_context
= tegra_clk_pll_restore_context
,
1042 const struct clk_ops tegra_clk_plle_ops
= {
1043 .recalc_rate
= clk_plle_recalc_rate
,
1044 .is_enabled
= clk_pll_is_enabled
,
1045 .disable
= clk_pll_disable
,
1046 .enable
= clk_plle_enable
,
1050 * Structure defining the fields for USB UTMI clocks Parameters.
1052 struct utmi_clk_param
{
1053 /* Oscillator Frequency in Hz */
1055 /* UTMIP PLL Enable Delay Count */
1056 u8 enable_delay_count
;
1057 /* UTMIP PLL Stable count */
1059 /* UTMIP PLL Active delay count */
1060 u8 active_delay_count
;
1061 /* UTMIP PLL Xtal frequency count */
1065 static const struct utmi_clk_param utmi_parameters
[] = {
1067 .osc_frequency
= 13000000, .enable_delay_count
= 0x02,
1068 .stable_count
= 0x33, .active_delay_count
= 0x05,
1069 .xtal_freq_count
= 0x7f
1071 .osc_frequency
= 19200000, .enable_delay_count
= 0x03,
1072 .stable_count
= 0x4b, .active_delay_count
= 0x06,
1073 .xtal_freq_count
= 0xbb
1075 .osc_frequency
= 12000000, .enable_delay_count
= 0x02,
1076 .stable_count
= 0x2f, .active_delay_count
= 0x04,
1077 .xtal_freq_count
= 0x76
1079 .osc_frequency
= 26000000, .enable_delay_count
= 0x04,
1080 .stable_count
= 0x66, .active_delay_count
= 0x09,
1081 .xtal_freq_count
= 0xfe
1083 .osc_frequency
= 16800000, .enable_delay_count
= 0x03,
1084 .stable_count
= 0x41, .active_delay_count
= 0x0a,
1085 .xtal_freq_count
= 0xa4
1087 .osc_frequency
= 38400000, .enable_delay_count
= 0x0,
1088 .stable_count
= 0x0, .active_delay_count
= 0x6,
1089 .xtal_freq_count
= 0x80
1093 static int clk_pllu_enable(struct clk_hw
*hw
)
1095 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1096 struct clk_hw
*pll_ref
= clk_hw_get_parent(hw
);
1097 struct clk_hw
*osc
= clk_hw_get_parent(pll_ref
);
1098 const struct utmi_clk_param
*params
= NULL
;
1099 unsigned long flags
= 0, input_rate
;
1105 pr_err("%s: failed to get OSC clock\n", __func__
);
1109 input_rate
= clk_hw_get_rate(osc
);
1112 spin_lock_irqsave(pll
->lock
, flags
);
1114 _clk_pll_enable(hw
);
1116 ret
= clk_pll_wait_for_lock(pll
);
1120 for (i
= 0; i
< ARRAY_SIZE(utmi_parameters
); i
++) {
1121 if (input_rate
== utmi_parameters
[i
].osc_frequency
) {
1122 params
= &utmi_parameters
[i
];
1128 pr_err("%s: unexpected input rate %lu Hz\n", __func__
,
1134 value
= pll_readl_base(pll
);
1135 value
&= ~PLLU_BASE_OVERRIDE
;
1136 pll_writel_base(value
, pll
);
1138 value
= readl_relaxed(pll
->clk_base
+ UTMIP_PLL_CFG2
);
1139 /* Program UTMIP PLL stable and active counts */
1140 value
&= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
1141 value
|= UTMIP_PLL_CFG2_STABLE_COUNT(params
->stable_count
);
1142 value
&= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
1143 value
|= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params
->active_delay_count
);
1144 /* Remove power downs from UTMIP PLL control bits */
1145 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN
;
1146 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN
;
1147 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN
;
1148 writel_relaxed(value
, pll
->clk_base
+ UTMIP_PLL_CFG2
);
1150 value
= readl_relaxed(pll
->clk_base
+ UTMIP_PLL_CFG1
);
1151 /* Program UTMIP PLL delay and oscillator frequency counts */
1152 value
&= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
1153 value
|= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params
->enable_delay_count
);
1154 value
&= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
1155 value
|= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params
->xtal_freq_count
);
1156 /* Remove power downs from UTMIP PLL control bits */
1157 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN
;
1158 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN
;
1159 value
&= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN
;
1160 writel_relaxed(value
, pll
->clk_base
+ UTMIP_PLL_CFG1
);
1164 spin_unlock_irqrestore(pll
->lock
, flags
);
1169 static const struct clk_ops tegra_clk_pllu_ops
= {
1170 .is_enabled
= clk_pll_is_enabled
,
1171 .enable
= clk_pllu_enable
,
1172 .disable
= clk_pll_disable
,
1173 .recalc_rate
= clk_pll_recalc_rate
,
1174 .round_rate
= clk_pll_round_rate
,
1175 .set_rate
= clk_pll_set_rate
,
1178 static int _pll_fixed_mdiv(struct tegra_clk_pll_params
*pll_params
,
1179 unsigned long parent_rate
)
1181 u16 mdiv
= parent_rate
/ pll_params
->cf_min
;
1183 if (pll_params
->flags
& TEGRA_MDIV_NEW
)
1184 return (!pll_params
->mdiv_default
? mdiv
:
1185 min(mdiv
, pll_params
->mdiv_default
));
1187 if (pll_params
->mdiv_default
)
1188 return pll_params
->mdiv_default
;
1190 if (parent_rate
> pll_params
->cf_max
)
1196 static int _calc_dynamic_ramp_rate(struct clk_hw
*hw
,
1197 struct tegra_clk_pll_freq_table
*cfg
,
1198 unsigned long rate
, unsigned long parent_rate
)
1200 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1207 p
= DIV_ROUND_UP(pll
->params
->vco_min
, rate
);
1208 cfg
->m
= _pll_fixed_mdiv(pll
->params
, parent_rate
);
1209 cfg
->output_rate
= rate
* p
;
1210 cfg
->n
= cfg
->output_rate
* cfg
->m
/ parent_rate
;
1211 cfg
->input_rate
= parent_rate
;
1213 p_div
= _p_div_to_hw(hw
, p
);
1219 if (cfg
->n
> divn_max(pll
) || cfg
->output_rate
> pll
->params
->vco_max
)
1225 #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \
1226 defined(CONFIG_ARCH_TEGRA_124_SOC) || \
1227 defined(CONFIG_ARCH_TEGRA_132_SOC) || \
1228 defined(CONFIG_ARCH_TEGRA_210_SOC)
1230 u16
tegra_pll_get_fixed_mdiv(struct clk_hw
*hw
, unsigned long input_rate
)
1232 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1234 return (u16
)_pll_fixed_mdiv(pll
->params
, input_rate
);
1237 static unsigned long _clip_vco_min(unsigned long vco_min
,
1238 unsigned long parent_rate
)
1240 return DIV_ROUND_UP(vco_min
, parent_rate
) * parent_rate
;
1243 static int _setup_dynamic_ramp(struct tegra_clk_pll_params
*pll_params
,
1244 void __iomem
*clk_base
,
1245 unsigned long parent_rate
)
1250 switch (parent_rate
) {
1266 pr_err("%s: Unexpected reference rate %lu\n",
1267 __func__
, parent_rate
);
1272 val
= step_a
<< pll_params
->stepa_shift
;
1273 val
|= step_b
<< pll_params
->stepb_shift
;
1274 writel_relaxed(val
, clk_base
+ pll_params
->dyn_ramp_reg
);
1279 static int _pll_ramp_calc_pll(struct clk_hw
*hw
,
1280 struct tegra_clk_pll_freq_table
*cfg
,
1281 unsigned long rate
, unsigned long parent_rate
)
1283 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1286 err
= _get_table_rate(hw
, cfg
, rate
, parent_rate
);
1288 err
= _calc_dynamic_ramp_rate(hw
, cfg
, rate
, parent_rate
);
1290 if (cfg
->m
!= _pll_fixed_mdiv(pll
->params
, parent_rate
)) {
1297 if (cfg
->p
> pll
->params
->max_p
)
1304 static int clk_pllxc_set_rate(struct clk_hw
*hw
, unsigned long rate
,
1305 unsigned long parent_rate
)
1307 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1308 struct tegra_clk_pll_freq_table cfg
, old_cfg
;
1309 unsigned long flags
= 0;
1312 ret
= _pll_ramp_calc_pll(hw
, &cfg
, rate
, parent_rate
);
1317 spin_lock_irqsave(pll
->lock
, flags
);
1319 _get_pll_mnp(pll
, &old_cfg
);
1320 if (pll
->params
->flags
& TEGRA_PLL_VCO_OUT
)
1323 if (old_cfg
.m
!= cfg
.m
|| old_cfg
.n
!= cfg
.n
|| old_cfg
.p
!= cfg
.p
)
1324 ret
= _program_pll(hw
, &cfg
, rate
);
1327 spin_unlock_irqrestore(pll
->lock
, flags
);
1332 static long clk_pll_ramp_round_rate(struct clk_hw
*hw
, unsigned long rate
,
1333 unsigned long *prate
)
1335 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1336 struct tegra_clk_pll_freq_table cfg
;
1338 u64 output_rate
= *prate
;
1340 ret
= _pll_ramp_calc_pll(hw
, &cfg
, rate
, *prate
);
1344 p_div
= _hw_to_p_div(hw
, cfg
.p
);
1348 if (pll
->params
->set_gain
)
1349 pll
->params
->set_gain(&cfg
);
1351 output_rate
*= cfg
.n
;
1352 do_div(output_rate
, cfg
.m
* p_div
);
1357 static void _pllcx_strobe(struct tegra_clk_pll
*pll
)
1361 val
= pll_readl_misc(pll
);
1362 val
|= PLLCX_MISC_STROBE
;
1363 pll_writel_misc(val
, pll
);
1366 val
&= ~PLLCX_MISC_STROBE
;
1367 pll_writel_misc(val
, pll
);
1370 static int clk_pllc_enable(struct clk_hw
*hw
)
1372 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1375 unsigned long flags
= 0;
1377 if (clk_pll_is_enabled(hw
))
1381 spin_lock_irqsave(pll
->lock
, flags
);
1383 _clk_pll_enable(hw
);
1386 val
= pll_readl_misc(pll
);
1387 val
&= ~PLLCX_MISC_RESET
;
1388 pll_writel_misc(val
, pll
);
1393 ret
= clk_pll_wait_for_lock(pll
);
1396 spin_unlock_irqrestore(pll
->lock
, flags
);
1401 static void _clk_pllc_disable(struct clk_hw
*hw
)
1403 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1406 _clk_pll_disable(hw
);
1408 val
= pll_readl_misc(pll
);
1409 val
|= PLLCX_MISC_RESET
;
1410 pll_writel_misc(val
, pll
);
1414 static void clk_pllc_disable(struct clk_hw
*hw
)
1416 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1417 unsigned long flags
= 0;
1420 spin_lock_irqsave(pll
->lock
, flags
);
1422 _clk_pllc_disable(hw
);
1425 spin_unlock_irqrestore(pll
->lock
, flags
);
1428 static int _pllcx_update_dynamic_coef(struct tegra_clk_pll
*pll
,
1429 unsigned long input_rate
, u32 n
)
1431 u32 val
, n_threshold
;
1433 switch (input_rate
) {
1448 pr_err("%s: Unexpected reference rate %lu\n",
1449 __func__
, input_rate
);
1453 val
= pll_readl_misc(pll
);
1454 val
&= ~(PLLCX_MISC_SDM_DIV_MASK
| PLLCX_MISC_FILT_DIV_MASK
);
1455 val
|= n
<= n_threshold
?
1456 PLLCX_MISC_DIV_LOW_RANGE
: PLLCX_MISC_DIV_HIGH_RANGE
;
1457 pll_writel_misc(val
, pll
);
1462 static int clk_pllc_set_rate(struct clk_hw
*hw
, unsigned long rate
,
1463 unsigned long parent_rate
)
1465 struct tegra_clk_pll_freq_table cfg
, old_cfg
;
1466 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1467 unsigned long flags
= 0;
1471 spin_lock_irqsave(pll
->lock
, flags
);
1473 ret
= _pll_ramp_calc_pll(hw
, &cfg
, rate
, parent_rate
);
1477 _get_pll_mnp(pll
, &old_cfg
);
1479 if (cfg
.m
!= old_cfg
.m
) {
1484 if (old_cfg
.n
== cfg
.n
&& old_cfg
.p
== cfg
.p
)
1487 state
= clk_pll_is_enabled(hw
);
1489 _clk_pllc_disable(hw
);
1491 ret
= _pllcx_update_dynamic_coef(pll
, parent_rate
, cfg
.n
);
1495 _update_pll_mnp(pll
, &cfg
);
1498 ret
= clk_pllc_enable(hw
);
1502 spin_unlock_irqrestore(pll
->lock
, flags
);
1507 static long _pllre_calc_rate(struct tegra_clk_pll
*pll
,
1508 struct tegra_clk_pll_freq_table
*cfg
,
1509 unsigned long rate
, unsigned long parent_rate
)
1512 u64 output_rate
= parent_rate
;
1514 m
= _pll_fixed_mdiv(pll
->params
, parent_rate
);
1515 n
= rate
* m
/ parent_rate
;
1518 do_div(output_rate
, m
);
1528 static int clk_pllre_set_rate(struct clk_hw
*hw
, unsigned long rate
,
1529 unsigned long parent_rate
)
1531 struct tegra_clk_pll_freq_table cfg
, old_cfg
;
1532 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1533 unsigned long flags
= 0;
1537 spin_lock_irqsave(pll
->lock
, flags
);
1539 _pllre_calc_rate(pll
, &cfg
, rate
, parent_rate
);
1540 _get_pll_mnp(pll
, &old_cfg
);
1543 if (cfg
.m
!= old_cfg
.m
|| cfg
.n
!= old_cfg
.n
) {
1544 state
= clk_pll_is_enabled(hw
);
1546 _clk_pll_disable(hw
);
1548 _update_pll_mnp(pll
, &cfg
);
1551 _clk_pll_enable(hw
);
1552 ret
= clk_pll_wait_for_lock(pll
);
1557 spin_unlock_irqrestore(pll
->lock
, flags
);
1562 static unsigned long clk_pllre_recalc_rate(struct clk_hw
*hw
,
1563 unsigned long parent_rate
)
1565 struct tegra_clk_pll_freq_table cfg
;
1566 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1567 u64 rate
= parent_rate
;
1569 _get_pll_mnp(pll
, &cfg
);
1572 do_div(rate
, cfg
.m
);
1577 static long clk_pllre_round_rate(struct clk_hw
*hw
, unsigned long rate
,
1578 unsigned long *prate
)
1580 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1582 return _pllre_calc_rate(pll
, NULL
, rate
, *prate
);
1585 static int clk_plle_tegra114_enable(struct clk_hw
*hw
)
1587 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1588 struct tegra_clk_pll_freq_table sel
;
1591 unsigned long flags
= 0;
1592 unsigned long input_rate
;
1594 if (clk_pll_is_enabled(hw
))
1597 input_rate
= clk_hw_get_rate(clk_hw_get_parent(hw
));
1599 if (_get_table_rate(hw
, &sel
, pll
->params
->fixed_rate
, input_rate
))
1603 spin_lock_irqsave(pll
->lock
, flags
);
1605 val
= pll_readl_base(pll
);
1606 val
&= ~BIT(29); /* Disable lock override */
1607 pll_writel_base(val
, pll
);
1609 val
= pll_readl(pll
->params
->aux_reg
, pll
);
1610 val
|= PLLE_AUX_ENABLE_SWCTL
;
1611 val
&= ~PLLE_AUX_SEQ_ENABLE
;
1612 pll_writel(val
, pll
->params
->aux_reg
, pll
);
1615 val
= pll_readl_misc(pll
);
1616 val
|= PLLE_MISC_LOCK_ENABLE
;
1617 val
|= PLLE_MISC_IDDQ_SW_CTRL
;
1618 val
&= ~PLLE_MISC_IDDQ_SW_VALUE
;
1619 val
|= PLLE_MISC_PLLE_PTS
;
1620 val
&= ~(PLLE_MISC_VREG_BG_CTRL_MASK
| PLLE_MISC_VREG_CTRL_MASK
);
1621 pll_writel_misc(val
, pll
);
1624 val
= pll_readl(PLLE_SS_CTRL
, pll
);
1625 val
|= PLLE_SS_DISABLE
;
1626 pll_writel(val
, PLLE_SS_CTRL
, pll
);
1628 val
= pll_readl_base(pll
);
1629 val
&= ~(divp_mask_shifted(pll
) | divn_mask_shifted(pll
) |
1630 divm_mask_shifted(pll
));
1631 val
&= ~(PLLE_BASE_DIVCML_MASK
<< PLLE_BASE_DIVCML_SHIFT
);
1632 val
|= sel
.m
<< divm_shift(pll
);
1633 val
|= sel
.n
<< divn_shift(pll
);
1634 val
|= sel
.cpcon
<< PLLE_BASE_DIVCML_SHIFT
;
1635 pll_writel_base(val
, pll
);
1638 _clk_pll_enable(hw
);
1639 ret
= clk_pll_wait_for_lock(pll
);
1644 val
= pll_readl(PLLE_SS_CTRL
, pll
);
1645 val
&= ~(PLLE_SS_CNTL_CENTER
| PLLE_SS_CNTL_INVERT
);
1646 val
&= ~PLLE_SS_COEFFICIENTS_MASK
;
1647 val
|= PLLE_SS_COEFFICIENTS_VAL_TEGRA114
;
1648 pll_writel(val
, PLLE_SS_CTRL
, pll
);
1649 val
&= ~(PLLE_SS_CNTL_SSC_BYP
| PLLE_SS_CNTL_BYPASS_SS
);
1650 pll_writel(val
, PLLE_SS_CTRL
, pll
);
1652 val
&= ~PLLE_SS_CNTL_INTERP_RESET
;
1653 pll_writel(val
, PLLE_SS_CTRL
, pll
);
1656 /* Enable hw control of xusb brick pll */
1657 val
= pll_readl_misc(pll
);
1658 val
&= ~PLLE_MISC_IDDQ_SW_CTRL
;
1659 pll_writel_misc(val
, pll
);
1661 val
= pll_readl(pll
->params
->aux_reg
, pll
);
1662 val
|= (PLLE_AUX_USE_LOCKDET
| PLLE_AUX_SEQ_START_STATE
);
1663 val
&= ~(PLLE_AUX_ENABLE_SWCTL
| PLLE_AUX_SS_SWCTL
);
1664 pll_writel(val
, pll
->params
->aux_reg
, pll
);
1666 val
|= PLLE_AUX_SEQ_ENABLE
;
1667 pll_writel(val
, pll
->params
->aux_reg
, pll
);
1669 val
= pll_readl(XUSBIO_PLL_CFG0
, pll
);
1670 val
|= (XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET
|
1671 XUSBIO_PLL_CFG0_SEQ_START_STATE
);
1672 val
&= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL
|
1673 XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL
);
1674 pll_writel(val
, XUSBIO_PLL_CFG0
, pll
);
1676 val
|= XUSBIO_PLL_CFG0_SEQ_ENABLE
;
1677 pll_writel(val
, XUSBIO_PLL_CFG0
, pll
);
1679 /* Enable hw control of SATA pll */
1680 val
= pll_readl(SATA_PLL_CFG0
, pll
);
1681 val
&= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL
;
1682 val
|= SATA_PLL_CFG0_PADPLL_USE_LOCKDET
;
1683 val
|= SATA_PLL_CFG0_SEQ_START_STATE
;
1684 pll_writel(val
, SATA_PLL_CFG0
, pll
);
1688 val
= pll_readl(SATA_PLL_CFG0
, pll
);
1689 val
|= SATA_PLL_CFG0_SEQ_ENABLE
;
1690 pll_writel(val
, SATA_PLL_CFG0
, pll
);
1694 spin_unlock_irqrestore(pll
->lock
, flags
);
1699 static void clk_plle_tegra114_disable(struct clk_hw
*hw
)
1701 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1702 unsigned long flags
= 0;
1706 spin_lock_irqsave(pll
->lock
, flags
);
1708 _clk_pll_disable(hw
);
1710 val
= pll_readl_misc(pll
);
1711 val
|= PLLE_MISC_IDDQ_SW_CTRL
| PLLE_MISC_IDDQ_SW_VALUE
;
1712 pll_writel_misc(val
, pll
);
1716 spin_unlock_irqrestore(pll
->lock
, flags
);
1719 static int clk_pllu_tegra114_enable(struct clk_hw
*hw
)
1721 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
1722 const struct utmi_clk_param
*params
= NULL
;
1723 struct clk
*osc
= __clk_lookup("osc");
1724 unsigned long flags
= 0, input_rate
;
1730 pr_err("%s: failed to get OSC clock\n", __func__
);
1734 if (clk_pll_is_enabled(hw
))
1737 input_rate
= clk_hw_get_rate(__clk_get_hw(osc
));
1740 spin_lock_irqsave(pll
->lock
, flags
);
1742 _clk_pll_enable(hw
);
1744 ret
= clk_pll_wait_for_lock(pll
);
1748 for (i
= 0; i
< ARRAY_SIZE(utmi_parameters
); i
++) {
1749 if (input_rate
== utmi_parameters
[i
].osc_frequency
) {
1750 params
= &utmi_parameters
[i
];
1756 pr_err("%s: unexpected input rate %lu Hz\n", __func__
,
1762 value
= pll_readl_base(pll
);
1763 value
&= ~PLLU_BASE_OVERRIDE
;
1764 pll_writel_base(value
, pll
);
1766 value
= readl_relaxed(pll
->clk_base
+ UTMIP_PLL_CFG2
);
1767 /* Program UTMIP PLL stable and active counts */
1768 value
&= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
1769 value
|= UTMIP_PLL_CFG2_STABLE_COUNT(params
->stable_count
);
1770 value
&= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
1771 value
|= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(params
->active_delay_count
);
1772 /* Remove power downs from UTMIP PLL control bits */
1773 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN
;
1774 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN
;
1775 value
&= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN
;
1776 writel_relaxed(value
, pll
->clk_base
+ UTMIP_PLL_CFG2
);
1778 value
= readl_relaxed(pll
->clk_base
+ UTMIP_PLL_CFG1
);
1779 /* Program UTMIP PLL delay and oscillator frequency counts */
1780 value
&= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
1781 value
|= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(params
->enable_delay_count
);
1782 value
&= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
1783 value
|= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(params
->xtal_freq_count
);
1784 /* Remove power downs from UTMIP PLL control bits */
1785 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN
;
1786 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN
;
1787 value
&= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP
;
1788 value
&= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN
;
1789 writel_relaxed(value
, pll
->clk_base
+ UTMIP_PLL_CFG1
);
1791 /* Setup HW control of UTMIPLL */
1792 value
= readl_relaxed(pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1793 value
|= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET
;
1794 value
&= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL
;
1795 value
|= UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE
;
1796 writel_relaxed(value
, pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1798 value
= readl_relaxed(pll
->clk_base
+ UTMIP_PLL_CFG1
);
1799 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP
;
1800 value
&= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN
;
1801 writel_relaxed(value
, pll
->clk_base
+ UTMIP_PLL_CFG1
);
1806 * Setup SW override of UTMIPLL assuming USB2.0 ports are assigned
1809 value
= readl_relaxed(pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1810 value
|= UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL
;
1811 value
&= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE
;
1812 writel_relaxed(value
, pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1816 /* Enable HW control of UTMIPLL */
1817 value
= readl_relaxed(pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1818 value
|= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE
;
1819 writel_relaxed(value
, pll
->clk_base
+ UTMIPLL_HW_PWRDN_CFG0
);
1823 spin_unlock_irqrestore(pll
->lock
, flags
);
1828 static void _clk_plle_tegra_init_parent(struct tegra_clk_pll
*pll
)
1832 /* ensure parent is set to pll_ref */
1833 val
= pll_readl_base(pll
);
1834 val_aux
= pll_readl(pll
->params
->aux_reg
, pll
);
1836 if (val
& PLL_BASE_ENABLE
) {
1837 if ((val_aux
& PLLE_AUX_PLLRE_SEL
) ||
1838 (val_aux
& PLLE_AUX_PLLP_SEL
))
1839 WARN(1, "pll_e enabled with unsupported parent %s\n",
1840 (val_aux
& PLLE_AUX_PLLP_SEL
) ? "pllp_out0" :
1843 val_aux
&= ~(PLLE_AUX_PLLRE_SEL
| PLLE_AUX_PLLP_SEL
);
1844 pll_writel(val_aux
, pll
->params
->aux_reg
, pll
);
1845 fence_udelay(1, pll
->clk_base
);
1850 static struct tegra_clk_pll
*_tegra_init_pll(void __iomem
*clk_base
,
1851 void __iomem
*pmc
, struct tegra_clk_pll_params
*pll_params
,
1854 struct tegra_clk_pll
*pll
;
1856 pll
= kzalloc(sizeof(*pll
), GFP_KERNEL
);
1858 return ERR_PTR(-ENOMEM
);
1860 pll
->clk_base
= clk_base
;
1863 pll
->params
= pll_params
;
1866 if (!pll_params
->div_nmp
)
1867 pll_params
->div_nmp
= &default_nmp
;
1872 static struct clk
*_tegra_clk_register_pll(struct tegra_clk_pll
*pll
,
1873 const char *name
, const char *parent_name
, unsigned long flags
,
1874 const struct clk_ops
*ops
)
1876 struct clk_init_data init
;
1881 init
.parent_names
= (parent_name
? &parent_name
: NULL
);
1882 init
.num_parents
= (parent_name
? 1 : 0);
1884 /* Default to _calc_rate if unspecified */
1885 if (!pll
->params
->calc_rate
) {
1886 if (pll
->params
->flags
& TEGRA_PLLM
)
1887 pll
->params
->calc_rate
= _calc_dynamic_ramp_rate
;
1889 pll
->params
->calc_rate
= _calc_rate
;
1892 if (pll
->params
->set_defaults
)
1893 pll
->params
->set_defaults(pll
);
1895 /* Data in .init is copied by clk_register(), so stack variable OK */
1896 pll
->hw
.init
= &init
;
1898 return clk_register(NULL
, &pll
->hw
);
1901 struct clk
*tegra_clk_register_pll(const char *name
, const char *parent_name
,
1902 void __iomem
*clk_base
, void __iomem
*pmc
,
1903 unsigned long flags
, struct tegra_clk_pll_params
*pll_params
,
1906 struct tegra_clk_pll
*pll
;
1909 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
1911 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
1913 return ERR_CAST(pll
);
1915 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
1916 &tegra_clk_pll_ops
);
1923 static struct div_nmp pll_e_nmp
= {
1924 .divn_shift
= PLLE_BASE_DIVN_SHIFT
,
1925 .divn_width
= PLLE_BASE_DIVN_WIDTH
,
1926 .divm_shift
= PLLE_BASE_DIVM_SHIFT
,
1927 .divm_width
= PLLE_BASE_DIVM_WIDTH
,
1928 .divp_shift
= PLLE_BASE_DIVP_SHIFT
,
1929 .divp_width
= PLLE_BASE_DIVP_WIDTH
,
1932 struct clk
*tegra_clk_register_plle(const char *name
, const char *parent_name
,
1933 void __iomem
*clk_base
, void __iomem
*pmc
,
1934 unsigned long flags
, struct tegra_clk_pll_params
*pll_params
,
1937 struct tegra_clk_pll
*pll
;
1940 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
1942 if (!pll_params
->div_nmp
)
1943 pll_params
->div_nmp
= &pll_e_nmp
;
1945 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
1947 return ERR_CAST(pll
);
1949 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
1950 &tegra_clk_plle_ops
);
1957 struct clk
*tegra_clk_register_pllu(const char *name
, const char *parent_name
,
1958 void __iomem
*clk_base
, unsigned long flags
,
1959 struct tegra_clk_pll_params
*pll_params
, spinlock_t
*lock
)
1961 struct tegra_clk_pll
*pll
;
1964 pll_params
->flags
|= TEGRA_PLLU
;
1966 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
1968 return ERR_CAST(pll
);
1970 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
1971 &tegra_clk_pllu_ops
);
1978 #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \
1979 defined(CONFIG_ARCH_TEGRA_124_SOC) || \
1980 defined(CONFIG_ARCH_TEGRA_132_SOC) || \
1981 defined(CONFIG_ARCH_TEGRA_210_SOC)
1982 static const struct clk_ops tegra_clk_pllxc_ops
= {
1983 .is_enabled
= clk_pll_is_enabled
,
1984 .enable
= clk_pll_enable
,
1985 .disable
= clk_pll_disable
,
1986 .recalc_rate
= clk_pll_recalc_rate
,
1987 .round_rate
= clk_pll_ramp_round_rate
,
1988 .set_rate
= clk_pllxc_set_rate
,
1991 static const struct clk_ops tegra_clk_pllc_ops
= {
1992 .is_enabled
= clk_pll_is_enabled
,
1993 .enable
= clk_pllc_enable
,
1994 .disable
= clk_pllc_disable
,
1995 .recalc_rate
= clk_pll_recalc_rate
,
1996 .round_rate
= clk_pll_ramp_round_rate
,
1997 .set_rate
= clk_pllc_set_rate
,
2000 static const struct clk_ops tegra_clk_pllre_ops
= {
2001 .is_enabled
= clk_pll_is_enabled
,
2002 .enable
= clk_pll_enable
,
2003 .disable
= clk_pll_disable
,
2004 .recalc_rate
= clk_pllre_recalc_rate
,
2005 .round_rate
= clk_pllre_round_rate
,
2006 .set_rate
= clk_pllre_set_rate
,
2009 static const struct clk_ops tegra_clk_plle_tegra114_ops
= {
2010 .is_enabled
= clk_pll_is_enabled
,
2011 .enable
= clk_plle_tegra114_enable
,
2012 .disable
= clk_plle_tegra114_disable
,
2013 .recalc_rate
= clk_pll_recalc_rate
,
2016 static const struct clk_ops tegra_clk_pllu_tegra114_ops
= {
2017 .is_enabled
= clk_pll_is_enabled
,
2018 .enable
= clk_pllu_tegra114_enable
,
2019 .disable
= clk_pll_disable
,
2020 .recalc_rate
= clk_pll_recalc_rate
,
2023 struct clk
*tegra_clk_register_pllxc(const char *name
, const char *parent_name
,
2024 void __iomem
*clk_base
, void __iomem
*pmc
,
2025 unsigned long flags
,
2026 struct tegra_clk_pll_params
*pll_params
,
2029 struct tegra_clk_pll
*pll
;
2030 struct clk
*clk
, *parent
;
2031 unsigned long parent_rate
;
2034 parent
= __clk_lookup(parent_name
);
2036 WARN(1, "parent clk %s of %s must be registered first\n",
2038 return ERR_PTR(-EINVAL
);
2041 if (!pll_params
->pdiv_tohw
)
2042 return ERR_PTR(-EINVAL
);
2044 parent_rate
= clk_get_rate(parent
);
2046 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2048 if (pll_params
->adjust_vco
)
2049 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2053 * If the pll has a set_defaults callback, it will take care of
2054 * configuring dynamic ramping and setting IDDQ in that path.
2056 if (!pll_params
->set_defaults
) {
2059 err
= _setup_dynamic_ramp(pll_params
, clk_base
, parent_rate
);
2061 return ERR_PTR(err
);
2063 val
= readl_relaxed(clk_base
+ pll_params
->base_reg
);
2064 val_iddq
= readl_relaxed(clk_base
+ pll_params
->iddq_reg
);
2066 if (val
& PLL_BASE_ENABLE
)
2067 WARN_ON(val_iddq
& BIT(pll_params
->iddq_bit_idx
));
2069 val_iddq
|= BIT(pll_params
->iddq_bit_idx
);
2070 writel_relaxed(val_iddq
,
2071 clk_base
+ pll_params
->iddq_reg
);
2075 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2077 return ERR_CAST(pll
);
2079 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2080 &tegra_clk_pllxc_ops
);
2087 struct clk
*tegra_clk_register_pllre(const char *name
, const char *parent_name
,
2088 void __iomem
*clk_base
, void __iomem
*pmc
,
2089 unsigned long flags
,
2090 struct tegra_clk_pll_params
*pll_params
,
2091 spinlock_t
*lock
, unsigned long parent_rate
)
2094 struct tegra_clk_pll
*pll
;
2097 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2099 if (pll_params
->adjust_vco
)
2100 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2103 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2105 return ERR_CAST(pll
);
2107 /* program minimum rate by default */
2109 val
= pll_readl_base(pll
);
2110 if (val
& PLL_BASE_ENABLE
)
2111 WARN_ON(readl_relaxed(clk_base
+ pll_params
->iddq_reg
) &
2112 BIT(pll_params
->iddq_bit_idx
));
2116 m
= _pll_fixed_mdiv(pll_params
, parent_rate
);
2117 val
= m
<< divm_shift(pll
);
2118 val
|= (pll_params
->vco_min
/ parent_rate
) << divn_shift(pll
);
2119 pll_writel_base(val
, pll
);
2122 /* disable lock override */
2124 val
= pll_readl_misc(pll
);
2126 pll_writel_misc(val
, pll
);
2128 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2129 &tegra_clk_pllre_ops
);
2136 struct clk
*tegra_clk_register_pllm(const char *name
, const char *parent_name
,
2137 void __iomem
*clk_base
, void __iomem
*pmc
,
2138 unsigned long flags
,
2139 struct tegra_clk_pll_params
*pll_params
,
2142 struct tegra_clk_pll
*pll
;
2143 struct clk
*clk
, *parent
;
2144 unsigned long parent_rate
;
2146 if (!pll_params
->pdiv_tohw
)
2147 return ERR_PTR(-EINVAL
);
2149 parent
= __clk_lookup(parent_name
);
2151 WARN(1, "parent clk %s of %s must be registered first\n",
2153 return ERR_PTR(-EINVAL
);
2156 parent_rate
= clk_get_rate(parent
);
2158 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2160 if (pll_params
->adjust_vco
)
2161 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2164 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
2165 pll_params
->flags
|= TEGRA_PLLM
;
2166 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2168 return ERR_CAST(pll
);
2170 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2171 &tegra_clk_pll_ops
);
2178 struct clk
*tegra_clk_register_pllc(const char *name
, const char *parent_name
,
2179 void __iomem
*clk_base
, void __iomem
*pmc
,
2180 unsigned long flags
,
2181 struct tegra_clk_pll_params
*pll_params
,
2184 struct clk
*parent
, *clk
;
2185 const struct pdiv_map
*p_tohw
= pll_params
->pdiv_tohw
;
2186 struct tegra_clk_pll
*pll
;
2187 struct tegra_clk_pll_freq_table cfg
;
2188 unsigned long parent_rate
;
2191 return ERR_PTR(-EINVAL
);
2193 parent
= __clk_lookup(parent_name
);
2195 WARN(1, "parent clk %s of %s must be registered first\n",
2197 return ERR_PTR(-EINVAL
);
2200 parent_rate
= clk_get_rate(parent
);
2202 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2204 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
2205 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2207 return ERR_CAST(pll
);
2210 * Most of PLLC register fields are shadowed, and can not be read
2211 * directly from PLL h/w. Hence, actual PLLC boot state is unknown.
2212 * Initialize PLL to default state: disabled, reset; shadow registers
2213 * loaded with default parameters; dividers are preset for half of
2214 * minimum VCO rate (the latter assured that shadowed divider settings
2215 * are within supported range).
2218 cfg
.m
= _pll_fixed_mdiv(pll_params
, parent_rate
);
2219 cfg
.n
= cfg
.m
* pll_params
->vco_min
/ parent_rate
;
2221 while (p_tohw
->pdiv
) {
2222 if (p_tohw
->pdiv
== 2) {
2223 cfg
.p
= p_tohw
->hw_val
;
2229 if (!p_tohw
->pdiv
) {
2231 return ERR_PTR(-EINVAL
);
2234 pll_writel_base(0, pll
);
2235 _update_pll_mnp(pll
, &cfg
);
2237 pll_writel_misc(PLLCX_MISC_DEFAULT
, pll
);
2238 pll_writel(PLLCX_MISC1_DEFAULT
, pll_params
->ext_misc_reg
[0], pll
);
2239 pll_writel(PLLCX_MISC2_DEFAULT
, pll_params
->ext_misc_reg
[1], pll
);
2240 pll_writel(PLLCX_MISC3_DEFAULT
, pll_params
->ext_misc_reg
[2], pll
);
2242 _pllcx_update_dynamic_coef(pll
, parent_rate
, cfg
.n
);
2244 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2245 &tegra_clk_pllc_ops
);
2252 struct clk
*tegra_clk_register_plle_tegra114(const char *name
,
2253 const char *parent_name
,
2254 void __iomem
*clk_base
, unsigned long flags
,
2255 struct tegra_clk_pll_params
*pll_params
,
2258 struct tegra_clk_pll
*pll
;
2261 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
2263 return ERR_CAST(pll
);
2265 _clk_plle_tegra_init_parent(pll
);
2267 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2268 &tegra_clk_plle_tegra114_ops
);
2276 tegra_clk_register_pllu_tegra114(const char *name
, const char *parent_name
,
2277 void __iomem
*clk_base
, unsigned long flags
,
2278 struct tegra_clk_pll_params
*pll_params
,
2281 struct tegra_clk_pll
*pll
;
2284 pll_params
->flags
|= TEGRA_PLLU
;
2286 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
2288 return ERR_CAST(pll
);
2290 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2291 &tegra_clk_pllu_tegra114_ops
);
2299 #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) || defined(CONFIG_ARCH_TEGRA_210_SOC)
2300 static const struct clk_ops tegra_clk_pllss_ops
= {
2301 .is_enabled
= clk_pll_is_enabled
,
2302 .enable
= clk_pll_enable
,
2303 .disable
= clk_pll_disable
,
2304 .recalc_rate
= clk_pll_recalc_rate
,
2305 .round_rate
= clk_pll_ramp_round_rate
,
2306 .set_rate
= clk_pllxc_set_rate
,
2307 .restore_context
= tegra_clk_pll_restore_context
,
2310 struct clk
*tegra_clk_register_pllss(const char *name
, const char *parent_name
,
2311 void __iomem
*clk_base
, unsigned long flags
,
2312 struct tegra_clk_pll_params
*pll_params
,
2315 struct tegra_clk_pll
*pll
;
2316 struct clk
*clk
, *parent
;
2317 struct tegra_clk_pll_freq_table cfg
;
2318 unsigned long parent_rate
;
2322 if (!pll_params
->div_nmp
)
2323 return ERR_PTR(-EINVAL
);
2325 parent
= __clk_lookup(parent_name
);
2327 WARN(1, "parent clk %s of %s must be registered first\n",
2329 return ERR_PTR(-EINVAL
);
2332 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
2334 return ERR_CAST(pll
);
2336 val
= pll_readl_base(pll
);
2337 val
&= ~PLLSS_REF_SRC_SEL_MASK
;
2338 pll_writel_base(val
, pll
);
2340 parent_rate
= clk_get_rate(parent
);
2342 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2344 /* initialize PLL to minimum rate */
2346 cfg
.m
= _pll_fixed_mdiv(pll_params
, parent_rate
);
2347 cfg
.n
= cfg
.m
* pll_params
->vco_min
/ parent_rate
;
2349 for (i
= 0; pll_params
->pdiv_tohw
[i
].pdiv
; i
++)
2353 return ERR_PTR(-EINVAL
);
2356 cfg
.p
= pll_params
->pdiv_tohw
[i
-1].hw_val
;
2358 _update_pll_mnp(pll
, &cfg
);
2360 pll_writel_misc(PLLSS_MISC_DEFAULT
, pll
);
2361 pll_writel(PLLSS_CFG_DEFAULT
, pll_params
->ext_misc_reg
[0], pll
);
2362 pll_writel(PLLSS_CTRL1_DEFAULT
, pll_params
->ext_misc_reg
[1], pll
);
2363 pll_writel(PLLSS_CTRL1_DEFAULT
, pll_params
->ext_misc_reg
[2], pll
);
2365 val
= pll_readl_base(pll
);
2366 val_iddq
= readl_relaxed(clk_base
+ pll_params
->iddq_reg
);
2367 if (val
& PLL_BASE_ENABLE
) {
2368 if (val_iddq
& BIT(pll_params
->iddq_bit_idx
)) {
2369 WARN(1, "%s is on but IDDQ set\n", name
);
2371 return ERR_PTR(-EINVAL
);
2374 val_iddq
|= BIT(pll_params
->iddq_bit_idx
);
2375 writel_relaxed(val_iddq
, clk_base
+ pll_params
->iddq_reg
);
2378 val
&= ~PLLSS_LOCK_OVERRIDE
;
2379 pll_writel_base(val
, pll
);
2381 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2382 &tegra_clk_pllss_ops
);
2391 #if defined(CONFIG_ARCH_TEGRA_210_SOC)
2392 struct clk
*tegra_clk_register_pllre_tegra210(const char *name
,
2393 const char *parent_name
, void __iomem
*clk_base
,
2394 void __iomem
*pmc
, unsigned long flags
,
2395 struct tegra_clk_pll_params
*pll_params
,
2396 spinlock_t
*lock
, unsigned long parent_rate
)
2398 struct tegra_clk_pll
*pll
;
2401 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2403 if (pll_params
->adjust_vco
)
2404 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2407 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2409 return ERR_CAST(pll
);
2411 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2412 &tegra_clk_pll_ops
);
2419 static int clk_plle_tegra210_is_enabled(struct clk_hw
*hw
)
2421 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
2424 val
= pll_readl_base(pll
);
2426 return val
& PLLE_BASE_ENABLE
? 1 : 0;
2429 static int clk_plle_tegra210_enable(struct clk_hw
*hw
)
2431 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
2432 struct tegra_clk_pll_freq_table sel
;
2435 unsigned long flags
= 0;
2436 unsigned long input_rate
;
2438 if (clk_plle_tegra210_is_enabled(hw
))
2441 input_rate
= clk_hw_get_rate(clk_hw_get_parent(hw
));
2443 if (_get_table_rate(hw
, &sel
, pll
->params
->fixed_rate
, input_rate
))
2447 spin_lock_irqsave(pll
->lock
, flags
);
2449 val
= pll_readl(pll
->params
->aux_reg
, pll
);
2450 if (val
& PLLE_AUX_SEQ_ENABLE
)
2453 val
= pll_readl_base(pll
);
2454 val
&= ~BIT(30); /* Disable lock override */
2455 pll_writel_base(val
, pll
);
2457 val
= pll_readl_misc(pll
);
2458 val
|= PLLE_MISC_LOCK_ENABLE
;
2459 val
|= PLLE_MISC_IDDQ_SW_CTRL
;
2460 val
&= ~PLLE_MISC_IDDQ_SW_VALUE
;
2461 val
|= PLLE_MISC_PLLE_PTS
;
2462 val
&= ~(PLLE_MISC_VREG_BG_CTRL_MASK
| PLLE_MISC_VREG_CTRL_MASK
);
2463 pll_writel_misc(val
, pll
);
2466 val
= pll_readl(PLLE_SS_CTRL
, pll
);
2467 val
|= PLLE_SS_DISABLE
;
2468 pll_writel(val
, PLLE_SS_CTRL
, pll
);
2470 val
= pll_readl_base(pll
);
2471 val
&= ~(divp_mask_shifted(pll
) | divn_mask_shifted(pll
) |
2472 divm_mask_shifted(pll
));
2473 val
&= ~(PLLE_BASE_DIVCML_MASK
<< PLLE_BASE_DIVCML_SHIFT
);
2474 val
|= sel
.m
<< divm_shift(pll
);
2475 val
|= sel
.n
<< divn_shift(pll
);
2476 val
|= sel
.cpcon
<< PLLE_BASE_DIVCML_SHIFT
;
2477 pll_writel_base(val
, pll
);
2480 val
= pll_readl_base(pll
);
2481 val
|= PLLE_BASE_ENABLE
;
2482 pll_writel_base(val
, pll
);
2484 ret
= clk_pll_wait_for_lock(pll
);
2489 val
= pll_readl(PLLE_SS_CTRL
, pll
);
2490 val
&= ~(PLLE_SS_CNTL_CENTER
| PLLE_SS_CNTL_INVERT
);
2491 val
&= ~PLLE_SS_COEFFICIENTS_MASK
;
2492 val
|= PLLE_SS_COEFFICIENTS_VAL_TEGRA210
;
2493 pll_writel(val
, PLLE_SS_CTRL
, pll
);
2494 val
&= ~(PLLE_SS_CNTL_SSC_BYP
| PLLE_SS_CNTL_BYPASS_SS
);
2495 pll_writel(val
, PLLE_SS_CTRL
, pll
);
2497 val
&= ~PLLE_SS_CNTL_INTERP_RESET
;
2498 pll_writel(val
, PLLE_SS_CTRL
, pll
);
2501 val
= pll_readl_misc(pll
);
2502 val
&= ~PLLE_MISC_IDDQ_SW_CTRL
;
2503 pll_writel_misc(val
, pll
);
2505 val
= pll_readl(pll
->params
->aux_reg
, pll
);
2506 val
|= (PLLE_AUX_USE_LOCKDET
| PLLE_AUX_SS_SEQ_INCLUDE
);
2507 val
&= ~(PLLE_AUX_ENABLE_SWCTL
| PLLE_AUX_SS_SWCTL
);
2508 pll_writel(val
, pll
->params
->aux_reg
, pll
);
2510 val
|= PLLE_AUX_SEQ_ENABLE
;
2511 pll_writel(val
, pll
->params
->aux_reg
, pll
);
2515 spin_unlock_irqrestore(pll
->lock
, flags
);
2520 static void clk_plle_tegra210_disable(struct clk_hw
*hw
)
2522 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
2523 unsigned long flags
= 0;
2527 spin_lock_irqsave(pll
->lock
, flags
);
2529 /* If PLLE HW sequencer is enabled, SW should not disable PLLE */
2530 val
= pll_readl(pll
->params
->aux_reg
, pll
);
2531 if (val
& PLLE_AUX_SEQ_ENABLE
)
2534 val
= pll_readl_base(pll
);
2535 val
&= ~PLLE_BASE_ENABLE
;
2536 pll_writel_base(val
, pll
);
2538 val
= pll_readl(pll
->params
->aux_reg
, pll
);
2539 val
|= PLLE_AUX_ENABLE_SWCTL
| PLLE_AUX_SS_SWCTL
;
2540 pll_writel(val
, pll
->params
->aux_reg
, pll
);
2542 val
= pll_readl_misc(pll
);
2543 val
|= PLLE_MISC_IDDQ_SW_CTRL
| PLLE_MISC_IDDQ_SW_VALUE
;
2544 pll_writel_misc(val
, pll
);
2549 spin_unlock_irqrestore(pll
->lock
, flags
);
2552 static void tegra_clk_plle_t210_restore_context(struct clk_hw
*hw
)
2554 struct tegra_clk_pll
*pll
= to_clk_pll(hw
);
2556 _clk_plle_tegra_init_parent(pll
);
2559 static const struct clk_ops tegra_clk_plle_tegra210_ops
= {
2560 .is_enabled
= clk_plle_tegra210_is_enabled
,
2561 .enable
= clk_plle_tegra210_enable
,
2562 .disable
= clk_plle_tegra210_disable
,
2563 .recalc_rate
= clk_pll_recalc_rate
,
2564 .restore_context
= tegra_clk_plle_t210_restore_context
,
2567 struct clk
*tegra_clk_register_plle_tegra210(const char *name
,
2568 const char *parent_name
,
2569 void __iomem
*clk_base
, unsigned long flags
,
2570 struct tegra_clk_pll_params
*pll_params
,
2573 struct tegra_clk_pll
*pll
;
2576 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
2578 return ERR_CAST(pll
);
2580 _clk_plle_tegra_init_parent(pll
);
2582 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2583 &tegra_clk_plle_tegra210_ops
);
2590 struct clk
*tegra_clk_register_pllc_tegra210(const char *name
,
2591 const char *parent_name
, void __iomem
*clk_base
,
2592 void __iomem
*pmc
, unsigned long flags
,
2593 struct tegra_clk_pll_params
*pll_params
,
2596 struct clk
*parent
, *clk
;
2597 const struct pdiv_map
*p_tohw
= pll_params
->pdiv_tohw
;
2598 struct tegra_clk_pll
*pll
;
2599 unsigned long parent_rate
;
2602 return ERR_PTR(-EINVAL
);
2604 parent
= __clk_lookup(parent_name
);
2606 WARN(1, "parent clk %s of %s must be registered first\n",
2608 return ERR_PTR(-EINVAL
);
2611 parent_rate
= clk_get_rate(parent
);
2613 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2615 if (pll_params
->adjust_vco
)
2616 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2619 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
2620 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2622 return ERR_CAST(pll
);
2624 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2625 &tegra_clk_pll_ops
);
2632 struct clk
*tegra_clk_register_pllss_tegra210(const char *name
,
2633 const char *parent_name
, void __iomem
*clk_base
,
2634 unsigned long flags
,
2635 struct tegra_clk_pll_params
*pll_params
,
2638 struct tegra_clk_pll
*pll
;
2639 struct clk
*clk
, *parent
;
2640 unsigned long parent_rate
;
2643 if (!pll_params
->div_nmp
)
2644 return ERR_PTR(-EINVAL
);
2646 parent
= __clk_lookup(parent_name
);
2648 WARN(1, "parent clk %s of %s must be registered first\n",
2650 return ERR_PTR(-EINVAL
);
2653 val
= readl_relaxed(clk_base
+ pll_params
->base_reg
);
2654 if (val
& PLLSS_REF_SRC_SEL_MASK
) {
2655 WARN(1, "not supported reference clock for %s\n", name
);
2656 return ERR_PTR(-EINVAL
);
2659 parent_rate
= clk_get_rate(parent
);
2661 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2663 if (pll_params
->adjust_vco
)
2664 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2667 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
2668 pll
= _tegra_init_pll(clk_base
, NULL
, pll_params
, lock
);
2670 return ERR_CAST(pll
);
2672 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2673 &tegra_clk_pll_ops
);
2681 struct clk
*tegra_clk_register_pllmb(const char *name
, const char *parent_name
,
2682 void __iomem
*clk_base
, void __iomem
*pmc
,
2683 unsigned long flags
,
2684 struct tegra_clk_pll_params
*pll_params
,
2687 struct tegra_clk_pll
*pll
;
2688 struct clk
*clk
, *parent
;
2689 unsigned long parent_rate
;
2691 if (!pll_params
->pdiv_tohw
)
2692 return ERR_PTR(-EINVAL
);
2694 parent
= __clk_lookup(parent_name
);
2696 WARN(1, "parent clk %s of %s must be registered first\n",
2698 return ERR_PTR(-EINVAL
);
2701 parent_rate
= clk_get_rate(parent
);
2703 pll_params
->vco_min
= _clip_vco_min(pll_params
->vco_min
, parent_rate
);
2705 if (pll_params
->adjust_vco
)
2706 pll_params
->vco_min
= pll_params
->adjust_vco(pll_params
,
2709 pll_params
->flags
|= TEGRA_PLL_BYPASS
;
2710 pll_params
->flags
|= TEGRA_PLLMB
;
2711 pll
= _tegra_init_pll(clk_base
, pmc
, pll_params
, lock
);
2713 return ERR_CAST(pll
);
2715 clk
= _tegra_clk_register_pll(pll
, name
, parent_name
, flags
,
2716 &tegra_clk_pll_ops
);