xref: /linux/drivers/clk/tegra/clk-tegra210.c (revision 98c4b3661b5aee0e583d17d6304f6489c0f41155)
1 /*
2  * Copyright (c) 2012-2014 NVIDIA CORPORATION.  All rights reserved.
3  *
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.
7  *
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
11  * more details.
12  *
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/>.
15  */
16 
17 #include <linux/io.h>
18 #include <linux/clk.h>
19 #include <linux/clk-provider.h>
20 #include <linux/clkdev.h>
21 #include <linux/of.h>
22 #include <linux/of_address.h>
23 #include <linux/delay.h>
24 #include <linux/export.h>
25 #include <linux/clk/tegra.h>
26 #include <dt-bindings/clock/tegra210-car.h>
27 
28 #include "clk.h"
29 #include "clk-id.h"
30 
31 /*
32  * TEGRA210_CAR_BANK_COUNT: the number of peripheral clock register
33  * banks present in the Tegra210 CAR IP block.  The banks are
34  * identified by single letters, e.g.: L, H, U, V, W, X, Y.  See
35  * periph_regs[] in drivers/clk/tegra/clk.c
36  */
37 #define TEGRA210_CAR_BANK_COUNT			7
38 
39 #define CLK_SOURCE_CSITE 0x1d4
40 #define CLK_SOURCE_EMC 0x19c
41 
42 #define PLLC_BASE 0x80
43 #define PLLC_OUT 0x84
44 #define PLLC_MISC0 0x88
45 #define PLLC_MISC1 0x8c
46 #define PLLC_MISC2 0x5d0
47 #define PLLC_MISC3 0x5d4
48 
49 #define PLLC2_BASE 0x4e8
50 #define PLLC2_MISC0 0x4ec
51 #define PLLC2_MISC1 0x4f0
52 #define PLLC2_MISC2 0x4f4
53 #define PLLC2_MISC3 0x4f8
54 
55 #define PLLC3_BASE 0x4fc
56 #define PLLC3_MISC0 0x500
57 #define PLLC3_MISC1 0x504
58 #define PLLC3_MISC2 0x508
59 #define PLLC3_MISC3 0x50c
60 
61 #define PLLM_BASE 0x90
62 #define PLLM_MISC1 0x98
63 #define PLLM_MISC2 0x9c
64 #define PLLP_BASE 0xa0
65 #define PLLP_MISC0 0xac
66 #define PLLP_MISC1 0x680
67 #define PLLA_BASE 0xb0
68 #define PLLA_MISC0 0xbc
69 #define PLLA_MISC1 0xb8
70 #define PLLA_MISC2 0x5d8
71 #define PLLD_BASE 0xd0
72 #define PLLD_MISC0 0xdc
73 #define PLLD_MISC1 0xd8
74 #define PLLU_BASE 0xc0
75 #define PLLU_OUTA 0xc4
76 #define PLLU_MISC0 0xcc
77 #define PLLU_MISC1 0xc8
78 #define PLLX_BASE 0xe0
79 #define PLLX_MISC0 0xe4
80 #define PLLX_MISC1 0x510
81 #define PLLX_MISC2 0x514
82 #define PLLX_MISC3 0x518
83 #define PLLX_MISC4 0x5f0
84 #define PLLX_MISC5 0x5f4
85 #define PLLE_BASE 0xe8
86 #define PLLE_MISC0 0xec
87 #define PLLD2_BASE 0x4b8
88 #define PLLD2_MISC0 0x4bc
89 #define PLLD2_MISC1 0x570
90 #define PLLD2_MISC2 0x574
91 #define PLLD2_MISC3 0x578
92 #define PLLE_AUX 0x48c
93 #define PLLRE_BASE 0x4c4
94 #define PLLRE_MISC0 0x4c8
95 #define PLLDP_BASE 0x590
96 #define PLLDP_MISC 0x594
97 
98 #define PLLC4_BASE 0x5a4
99 #define PLLC4_MISC0 0x5a8
100 #define PLLC4_OUT 0x5e4
101 #define PLLMB_BASE 0x5e8
102 #define PLLMB_MISC1 0x5ec
103 #define PLLA1_BASE 0x6a4
104 #define PLLA1_MISC0 0x6a8
105 #define PLLA1_MISC1 0x6ac
106 #define PLLA1_MISC2 0x6b0
107 #define PLLA1_MISC3 0x6b4
108 
109 #define PLLU_IDDQ_BIT 31
110 #define PLLCX_IDDQ_BIT 27
111 #define PLLRE_IDDQ_BIT 24
112 #define PLLA_IDDQ_BIT 25
113 #define PLLD_IDDQ_BIT 20
114 #define PLLSS_IDDQ_BIT 18
115 #define PLLM_IDDQ_BIT 5
116 #define PLLMB_IDDQ_BIT 17
117 #define PLLXP_IDDQ_BIT 3
118 
119 #define PLLCX_RESET_BIT 30
120 
121 #define PLL_BASE_LOCK BIT(27)
122 #define PLLCX_BASE_LOCK BIT(26)
123 #define PLLE_MISC_LOCK BIT(11)
124 #define PLLRE_MISC_LOCK BIT(27)
125 
126 #define PLL_MISC_LOCK_ENABLE 18
127 #define PLLC_MISC_LOCK_ENABLE 24
128 #define PLLDU_MISC_LOCK_ENABLE 22
129 #define PLLU_MISC_LOCK_ENABLE 29
130 #define PLLE_MISC_LOCK_ENABLE 9
131 #define PLLRE_MISC_LOCK_ENABLE 30
132 #define PLLSS_MISC_LOCK_ENABLE 30
133 #define PLLP_MISC_LOCK_ENABLE 18
134 #define PLLM_MISC_LOCK_ENABLE 4
135 #define PLLMB_MISC_LOCK_ENABLE 16
136 #define PLLA_MISC_LOCK_ENABLE 28
137 #define PLLU_MISC_LOCK_ENABLE 29
138 #define PLLD_MISC_LOCK_ENABLE 18
139 
140 #define PLLA_SDM_DIN_MASK 0xffff
141 #define PLLA_SDM_EN_MASK BIT(26)
142 
143 #define PLLD_SDM_EN_MASK BIT(16)
144 
145 #define PLLD2_SDM_EN_MASK BIT(31)
146 #define PLLD2_SSC_EN_MASK BIT(30)
147 
148 #define PLLDP_SS_CFG	0x598
149 #define PLLDP_SDM_EN_MASK BIT(31)
150 #define PLLDP_SSC_EN_MASK BIT(30)
151 #define PLLDP_SS_CTRL1	0x59c
152 #define PLLDP_SS_CTRL2	0x5a0
153 
154 #define PMC_PLLM_WB0_OVERRIDE 0x1dc
155 #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0
156 
157 #define UTMIP_PLL_CFG2 0x488
158 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
159 #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
160 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
161 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1)
162 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
163 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3)
164 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
165 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5)
166 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24)
167 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25)
168 
169 #define UTMIP_PLL_CFG1 0x484
170 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
171 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
172 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17)
173 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
174 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15)
175 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
176 #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
177 
178 #define SATA_PLL_CFG0				0x490
179 #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL	BIT(0)
180 #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET	BIT(2)
181 #define SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ		BIT(13)
182 #define SATA_PLL_CFG0_SEQ_ENABLE		BIT(24)
183 
184 #define XUSBIO_PLL_CFG0				0x51c
185 #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL	BIT(0)
186 #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL	BIT(2)
187 #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET	BIT(6)
188 #define XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ	BIT(13)
189 #define XUSBIO_PLL_CFG0_SEQ_ENABLE		BIT(24)
190 
191 #define UTMIPLL_HW_PWRDN_CFG0			0x52c
192 #define UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK	BIT(31)
193 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE	BIT(25)
194 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE	BIT(24)
195 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE	BIT(7)
196 #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET	BIT(6)
197 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE	BIT(5)
198 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL	BIT(4)
199 #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL	BIT(2)
200 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE	BIT(1)
201 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL	BIT(0)
202 
203 #define PLLU_HW_PWRDN_CFG0			0x530
204 #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE	BIT(28)
205 #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE		BIT(24)
206 #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT	BIT(7)
207 #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET		BIT(6)
208 #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL	BIT(2)
209 #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL	BIT(0)
210 
211 #define XUSB_PLL_CFG0				0x534
212 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY		0x3ff
213 #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK	(0x3ff << 14)
214 
215 #define SPARE_REG0 0x55c
216 #define CLK_M_DIVISOR_SHIFT 2
217 #define CLK_M_DIVISOR_MASK 0x3
218 
219 /*
220  * SDM fractional divisor is 16-bit 2's complement signed number within
221  * (-2^12 ... 2^12-1) range. Represented in PLL data structure as unsigned
222  * 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used to
223  * indicate that SDM is disabled.
224  *
225  * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13
226  */
227 #define PLL_SDM_COEFF BIT(13)
228 #define sdin_din_to_data(din)	((u16)((din) ? : 0xFFFFU))
229 #define sdin_data_to_din(dat)	(((dat) == 0xFFFFU) ? 0 : (s16)dat)
230 
231 /* Tegra CPU clock and reset control regs */
232 #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS	0x470
233 
234 #ifdef CONFIG_PM_SLEEP
235 static struct cpu_clk_suspend_context {
236 	u32 clk_csite_src;
237 } tegra210_cpu_clk_sctx;
238 #endif
239 
240 static void __iomem *clk_base;
241 static void __iomem *pmc_base;
242 
243 static unsigned long osc_freq;
244 static unsigned long pll_ref_freq;
245 
246 static DEFINE_SPINLOCK(pll_d_lock);
247 static DEFINE_SPINLOCK(pll_e_lock);
248 static DEFINE_SPINLOCK(pll_re_lock);
249 static DEFINE_SPINLOCK(pll_u_lock);
250 static DEFINE_SPINLOCK(emc_lock);
251 
252 /* possible OSC frequencies in Hz */
253 static unsigned long tegra210_input_freq[] = {
254 	[5] = 38400000,
255 	[8] = 12000000,
256 };
257 
258 static const char *mux_pllmcp_clkm[] = {
259 	"pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_mb", "pll_mb",
260 	"pll_p",
261 };
262 #define mux_pllmcp_clkm_idx NULL
263 
264 #define PLL_ENABLE			(1 << 30)
265 
266 #define PLLCX_MISC1_IDDQ		(1 << 27)
267 #define PLLCX_MISC0_RESET		(1 << 30)
268 
269 #define PLLCX_MISC0_DEFAULT_VALUE	0x40080000
270 #define PLLCX_MISC0_WRITE_MASK		0x400ffffb
271 #define PLLCX_MISC1_DEFAULT_VALUE	0x08000000
272 #define PLLCX_MISC1_WRITE_MASK		0x08003cff
273 #define PLLCX_MISC2_DEFAULT_VALUE	0x1f720f05
274 #define PLLCX_MISC2_WRITE_MASK		0xffffff17
275 #define PLLCX_MISC3_DEFAULT_VALUE	0x000000c4
276 #define PLLCX_MISC3_WRITE_MASK		0x00ffffff
277 
278 /* PLLA */
279 #define PLLA_BASE_IDDQ			(1 << 25)
280 #define PLLA_BASE_LOCK			(1 << 27)
281 
282 #define PLLA_MISC0_LOCK_ENABLE		(1 << 28)
283 #define PLLA_MISC0_LOCK_OVERRIDE	(1 << 27)
284 
285 #define PLLA_MISC2_EN_SDM		(1 << 26)
286 #define PLLA_MISC2_EN_DYNRAMP		(1 << 25)
287 
288 #define PLLA_MISC0_DEFAULT_VALUE	0x12000020
289 #define PLLA_MISC0_WRITE_MASK		0x7fffffff
290 #define PLLA_MISC2_DEFAULT_VALUE	0x0
291 #define PLLA_MISC2_WRITE_MASK		0x06ffffff
292 
293 /* PLLD */
294 #define PLLD_MISC0_EN_SDM		(1 << 16)
295 #define PLLD_MISC0_LOCK_OVERRIDE	(1 << 17)
296 #define PLLD_MISC0_LOCK_ENABLE		(1 << 18)
297 #define PLLD_MISC0_IDDQ			(1 << 20)
298 #define PLLD_MISC0_DSI_CLKENABLE	(1 << 21)
299 
300 #define PLLD_MISC0_DEFAULT_VALUE	0x00140000
301 #define PLLD_MISC0_WRITE_MASK		0x3ff7ffff
302 #define PLLD_MISC1_DEFAULT_VALUE	0x20
303 #define PLLD_MISC1_WRITE_MASK		0x00ffffff
304 
305 /* PLLD2 and PLLDP  and PLLC4 */
306 #define PLLDSS_BASE_LOCK		(1 << 27)
307 #define PLLDSS_BASE_LOCK_OVERRIDE	(1 << 24)
308 #define PLLDSS_BASE_IDDQ		(1 << 18)
309 #define PLLDSS_BASE_REF_SEL_SHIFT	25
310 #define PLLDSS_BASE_REF_SEL_MASK	(0x3 << PLLDSS_BASE_REF_SEL_SHIFT)
311 
312 #define PLLDSS_MISC0_LOCK_ENABLE	(1 << 30)
313 
314 #define PLLDSS_MISC1_CFG_EN_SDM		(1 << 31)
315 #define PLLDSS_MISC1_CFG_EN_SSC		(1 << 30)
316 
317 #define PLLD2_MISC0_DEFAULT_VALUE	0x40000020
318 #define PLLD2_MISC1_CFG_DEFAULT_VALUE	0x10000000
319 #define PLLD2_MISC2_CTRL1_DEFAULT_VALUE	0x0
320 #define PLLD2_MISC3_CTRL2_DEFAULT_VALUE	0x0
321 
322 #define PLLDP_MISC0_DEFAULT_VALUE	0x40000020
323 #define PLLDP_MISC1_CFG_DEFAULT_VALUE	0xc0000000
324 #define PLLDP_MISC2_CTRL1_DEFAULT_VALUE	0xf400f0da
325 #define PLLDP_MISC3_CTRL2_DEFAULT_VALUE	0x2004f400
326 
327 #define PLLDSS_MISC0_WRITE_MASK		0x47ffffff
328 #define PLLDSS_MISC1_CFG_WRITE_MASK	0xf8000000
329 #define PLLDSS_MISC2_CTRL1_WRITE_MASK	0xffffffff
330 #define PLLDSS_MISC3_CTRL2_WRITE_MASK	0xffffffff
331 
332 #define PLLC4_MISC0_DEFAULT_VALUE	0x40000000
333 
334 /* PLLRE */
335 #define PLLRE_MISC0_LOCK_ENABLE		(1 << 30)
336 #define PLLRE_MISC0_LOCK_OVERRIDE	(1 << 29)
337 #define PLLRE_MISC0_LOCK		(1 << 27)
338 #define PLLRE_MISC0_IDDQ		(1 << 24)
339 
340 #define PLLRE_BASE_DEFAULT_VALUE	0x0
341 #define PLLRE_MISC0_DEFAULT_VALUE	0x41000000
342 
343 #define PLLRE_BASE_DEFAULT_MASK		0x1c000000
344 #define PLLRE_MISC0_WRITE_MASK		0x67ffffff
345 
346 /* PLLX */
347 #define PLLX_USE_DYN_RAMP		1
348 #define PLLX_BASE_LOCK			(1 << 27)
349 
350 #define PLLX_MISC0_FO_G_DISABLE		(0x1 << 28)
351 #define PLLX_MISC0_LOCK_ENABLE		(0x1 << 18)
352 
353 #define PLLX_MISC2_DYNRAMP_STEPB_SHIFT	24
354 #define PLLX_MISC2_DYNRAMP_STEPB_MASK	(0xFF << PLLX_MISC2_DYNRAMP_STEPB_SHIFT)
355 #define PLLX_MISC2_DYNRAMP_STEPA_SHIFT	16
356 #define PLLX_MISC2_DYNRAMP_STEPA_MASK	(0xFF << PLLX_MISC2_DYNRAMP_STEPA_SHIFT)
357 #define PLLX_MISC2_NDIV_NEW_SHIFT	8
358 #define PLLX_MISC2_NDIV_NEW_MASK	(0xFF << PLLX_MISC2_NDIV_NEW_SHIFT)
359 #define PLLX_MISC2_LOCK_OVERRIDE	(0x1 << 4)
360 #define PLLX_MISC2_DYNRAMP_DONE		(0x1 << 2)
361 #define PLLX_MISC2_EN_DYNRAMP		(0x1 << 0)
362 
363 #define PLLX_MISC3_IDDQ			(0x1 << 3)
364 
365 #define PLLX_MISC0_DEFAULT_VALUE	PLLX_MISC0_LOCK_ENABLE
366 #define PLLX_MISC0_WRITE_MASK		0x10c40000
367 #define PLLX_MISC1_DEFAULT_VALUE	0x20
368 #define PLLX_MISC1_WRITE_MASK		0x00ffffff
369 #define PLLX_MISC2_DEFAULT_VALUE	0x0
370 #define PLLX_MISC2_WRITE_MASK		0xffffff11
371 #define PLLX_MISC3_DEFAULT_VALUE	PLLX_MISC3_IDDQ
372 #define PLLX_MISC3_WRITE_MASK		0x01ff0f0f
373 #define PLLX_MISC4_DEFAULT_VALUE	0x0
374 #define PLLX_MISC4_WRITE_MASK		0x8000ffff
375 #define PLLX_MISC5_DEFAULT_VALUE	0x0
376 #define PLLX_MISC5_WRITE_MASK		0x0000ffff
377 
378 #define PLLX_HW_CTRL_CFG		0x548
379 #define PLLX_HW_CTRL_CFG_SWCTRL		(0x1 << 0)
380 
381 /* PLLMB */
382 #define PLLMB_BASE_LOCK			(1 << 27)
383 
384 #define PLLMB_MISC1_LOCK_OVERRIDE	(1 << 18)
385 #define PLLMB_MISC1_IDDQ		(1 << 17)
386 #define PLLMB_MISC1_LOCK_ENABLE		(1 << 16)
387 
388 #define PLLMB_MISC1_DEFAULT_VALUE	0x00030000
389 #define PLLMB_MISC1_WRITE_MASK		0x0007ffff
390 
391 /* PLLP */
392 #define PLLP_BASE_OVERRIDE		(1 << 28)
393 #define PLLP_BASE_LOCK			(1 << 27)
394 
395 #define PLLP_MISC0_LOCK_ENABLE		(1 << 18)
396 #define PLLP_MISC0_LOCK_OVERRIDE	(1 << 17)
397 #define PLLP_MISC0_IDDQ			(1 << 3)
398 
399 #define PLLP_MISC1_HSIO_EN_SHIFT	29
400 #define PLLP_MISC1_HSIO_EN		(1 << PLLP_MISC1_HSIO_EN_SHIFT)
401 #define PLLP_MISC1_XUSB_EN_SHIFT	28
402 #define PLLP_MISC1_XUSB_EN		(1 << PLLP_MISC1_XUSB_EN_SHIFT)
403 
404 #define PLLP_MISC0_DEFAULT_VALUE	0x00040008
405 #define PLLP_MISC1_DEFAULT_VALUE	0x0
406 
407 #define PLLP_MISC0_WRITE_MASK		0xdc6000f
408 #define PLLP_MISC1_WRITE_MASK		0x70ffffff
409 
410 /* PLLU */
411 #define PLLU_BASE_LOCK			(1 << 27)
412 #define PLLU_BASE_OVERRIDE		(1 << 24)
413 #define PLLU_BASE_CLKENABLE_USB		(1 << 21)
414 #define PLLU_BASE_CLKENABLE_HSIC	(1 << 22)
415 #define PLLU_BASE_CLKENABLE_ICUSB	(1 << 23)
416 #define PLLU_BASE_CLKENABLE_48M		(1 << 25)
417 #define PLLU_BASE_CLKENABLE_ALL		(PLLU_BASE_CLKENABLE_USB |\
418 					 PLLU_BASE_CLKENABLE_HSIC |\
419 					 PLLU_BASE_CLKENABLE_ICUSB |\
420 					 PLLU_BASE_CLKENABLE_48M)
421 
422 #define PLLU_MISC0_IDDQ			(1 << 31)
423 #define PLLU_MISC0_LOCK_ENABLE		(1 << 29)
424 #define PLLU_MISC1_LOCK_OVERRIDE	(1 << 0)
425 
426 #define PLLU_MISC0_DEFAULT_VALUE	0xa0000000
427 #define PLLU_MISC1_DEFAULT_VALUE	0x0
428 
429 #define PLLU_MISC0_WRITE_MASK		0xbfffffff
430 #define PLLU_MISC1_WRITE_MASK		0x00000007
431 
432 void tegra210_xusb_pll_hw_control_enable(void)
433 {
434 	u32 val;
435 
436 	val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0);
437 	val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL |
438 		 XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL);
439 	val |= XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET |
440 	       XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ;
441 	writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0);
442 }
443 EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_control_enable);
444 
445 void tegra210_xusb_pll_hw_sequence_start(void)
446 {
447 	u32 val;
448 
449 	val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0);
450 	val |= XUSBIO_PLL_CFG0_SEQ_ENABLE;
451 	writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0);
452 }
453 EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_sequence_start);
454 
455 void tegra210_sata_pll_hw_control_enable(void)
456 {
457 	u32 val;
458 
459 	val = readl_relaxed(clk_base + SATA_PLL_CFG0);
460 	val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL;
461 	val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET |
462 	       SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ;
463 	writel_relaxed(val, clk_base + SATA_PLL_CFG0);
464 }
465 EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_control_enable);
466 
467 void tegra210_sata_pll_hw_sequence_start(void)
468 {
469 	u32 val;
470 
471 	val = readl_relaxed(clk_base + SATA_PLL_CFG0);
472 	val |= SATA_PLL_CFG0_SEQ_ENABLE;
473 	writel_relaxed(val, clk_base + SATA_PLL_CFG0);
474 }
475 EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_sequence_start);
476 
477 static inline void _pll_misc_chk_default(void __iomem *base,
478 					struct tegra_clk_pll_params *params,
479 					u8 misc_num, u32 default_val, u32 mask)
480 {
481 	u32 boot_val = readl_relaxed(base + params->ext_misc_reg[misc_num]);
482 
483 	boot_val &= mask;
484 	default_val &= mask;
485 	if (boot_val != default_val) {
486 		pr_warn("boot misc%d 0x%x: expected 0x%x\n",
487 			misc_num, boot_val, default_val);
488 		pr_warn(" (comparison mask = 0x%x)\n", mask);
489 		params->defaults_set = false;
490 	}
491 }
492 
493 /*
494  * PLLCX: PLLC, PLLC2, PLLC3, PLLA1
495  * Hybrid PLLs with dynamic ramp. Dynamic ramp is allowed for any transition
496  * that changes NDIV only, while PLL is already locked.
497  */
498 static void pllcx_check_defaults(struct tegra_clk_pll_params *params)
499 {
500 	u32 default_val;
501 
502 	default_val = PLLCX_MISC0_DEFAULT_VALUE & (~PLLCX_MISC0_RESET);
503 	_pll_misc_chk_default(clk_base, params, 0, default_val,
504 			PLLCX_MISC0_WRITE_MASK);
505 
506 	default_val = PLLCX_MISC1_DEFAULT_VALUE & (~PLLCX_MISC1_IDDQ);
507 	_pll_misc_chk_default(clk_base, params, 1, default_val,
508 			PLLCX_MISC1_WRITE_MASK);
509 
510 	default_val = PLLCX_MISC2_DEFAULT_VALUE;
511 	_pll_misc_chk_default(clk_base, params, 2, default_val,
512 			PLLCX_MISC2_WRITE_MASK);
513 
514 	default_val = PLLCX_MISC3_DEFAULT_VALUE;
515 	_pll_misc_chk_default(clk_base, params, 3, default_val,
516 			PLLCX_MISC3_WRITE_MASK);
517 }
518 
519 static void tegra210_pllcx_set_defaults(const char *name,
520 					struct tegra_clk_pll *pllcx)
521 {
522 	pllcx->params->defaults_set = true;
523 
524 	if (readl_relaxed(clk_base + pllcx->params->base_reg) &
525 			PLL_ENABLE) {
526 		/* PLL is ON: only check if defaults already set */
527 		pllcx_check_defaults(pllcx->params);
528 		pr_warn("%s already enabled. Postponing set full defaults\n",
529 			name);
530 		return;
531 	}
532 
533 	/* Defaults assert PLL reset, and set IDDQ */
534 	writel_relaxed(PLLCX_MISC0_DEFAULT_VALUE,
535 			clk_base + pllcx->params->ext_misc_reg[0]);
536 	writel_relaxed(PLLCX_MISC1_DEFAULT_VALUE,
537 			clk_base + pllcx->params->ext_misc_reg[1]);
538 	writel_relaxed(PLLCX_MISC2_DEFAULT_VALUE,
539 			clk_base + pllcx->params->ext_misc_reg[2]);
540 	writel_relaxed(PLLCX_MISC3_DEFAULT_VALUE,
541 			clk_base + pllcx->params->ext_misc_reg[3]);
542 	udelay(1);
543 }
544 
545 static void _pllc_set_defaults(struct tegra_clk_pll *pllcx)
546 {
547 	tegra210_pllcx_set_defaults("PLL_C", pllcx);
548 }
549 
550 static void _pllc2_set_defaults(struct tegra_clk_pll *pllcx)
551 {
552 	tegra210_pllcx_set_defaults("PLL_C2", pllcx);
553 }
554 
555 static void _pllc3_set_defaults(struct tegra_clk_pll *pllcx)
556 {
557 	tegra210_pllcx_set_defaults("PLL_C3", pllcx);
558 }
559 
560 static void _plla1_set_defaults(struct tegra_clk_pll *pllcx)
561 {
562 	tegra210_pllcx_set_defaults("PLL_A1", pllcx);
563 }
564 
565 /*
566  * PLLA
567  * PLL with dynamic ramp and fractional SDM. Dynamic ramp is not used.
568  * Fractional SDM is allowed to provide exact audio rates.
569  */
570 static void tegra210_plla_set_defaults(struct tegra_clk_pll *plla)
571 {
572 	u32 mask;
573 	u32 val = readl_relaxed(clk_base + plla->params->base_reg);
574 
575 	plla->params->defaults_set = true;
576 
577 	if (val & PLL_ENABLE) {
578 		/*
579 		 * PLL is ON: check if defaults already set, then set those
580 		 * that can be updated in flight.
581 		 */
582 		if (val & PLLA_BASE_IDDQ) {
583 			pr_warn("PLL_A boot enabled with IDDQ set\n");
584 			plla->params->defaults_set = false;
585 		}
586 
587 		pr_warn("PLL_A already enabled. Postponing set full defaults\n");
588 
589 		val = PLLA_MISC0_DEFAULT_VALUE;	/* ignore lock enable */
590 		mask = PLLA_MISC0_LOCK_ENABLE | PLLA_MISC0_LOCK_OVERRIDE;
591 		_pll_misc_chk_default(clk_base, plla->params, 0, val,
592 				~mask & PLLA_MISC0_WRITE_MASK);
593 
594 		val = PLLA_MISC2_DEFAULT_VALUE; /* ignore all but control bit */
595 		_pll_misc_chk_default(clk_base, plla->params, 2, val,
596 				PLLA_MISC2_EN_DYNRAMP);
597 
598 		/* Enable lock detect */
599 		val = readl_relaxed(clk_base + plla->params->ext_misc_reg[0]);
600 		val &= ~mask;
601 		val |= PLLA_MISC0_DEFAULT_VALUE & mask;
602 		writel_relaxed(val, clk_base + plla->params->ext_misc_reg[0]);
603 		udelay(1);
604 
605 		return;
606 	}
607 
608 	/* set IDDQ, enable lock detect, disable dynamic ramp and SDM */
609 	val |= PLLA_BASE_IDDQ;
610 	writel_relaxed(val, clk_base + plla->params->base_reg);
611 	writel_relaxed(PLLA_MISC0_DEFAULT_VALUE,
612 			clk_base + plla->params->ext_misc_reg[0]);
613 	writel_relaxed(PLLA_MISC2_DEFAULT_VALUE,
614 			clk_base + plla->params->ext_misc_reg[2]);
615 	udelay(1);
616 }
617 
618 /*
619  * PLLD
620  * PLL with fractional SDM.
621  */
622 static void tegra210_plld_set_defaults(struct tegra_clk_pll *plld)
623 {
624 	u32 val;
625 	u32 mask = 0xffff;
626 
627 	plld->params->defaults_set = true;
628 
629 	if (readl_relaxed(clk_base + plld->params->base_reg) &
630 			PLL_ENABLE) {
631 		pr_warn("PLL_D already enabled. Postponing set full defaults\n");
632 
633 		/*
634 		 * PLL is ON: check if defaults already set, then set those
635 		 * that can be updated in flight.
636 		 */
637 		val = PLLD_MISC1_DEFAULT_VALUE;
638 		_pll_misc_chk_default(clk_base, plld->params, 1,
639 				val, PLLD_MISC1_WRITE_MASK);
640 
641 		/* ignore lock, DSI and SDM controls, make sure IDDQ not set */
642 		val = PLLD_MISC0_DEFAULT_VALUE & (~PLLD_MISC0_IDDQ);
643 		mask |= PLLD_MISC0_DSI_CLKENABLE | PLLD_MISC0_LOCK_ENABLE |
644 			PLLD_MISC0_LOCK_OVERRIDE | PLLD_MISC0_EN_SDM;
645 		_pll_misc_chk_default(clk_base, plld->params, 0, val,
646 				~mask & PLLD_MISC0_WRITE_MASK);
647 
648 		/* Enable lock detect */
649 		mask = PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE;
650 		val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]);
651 		val &= ~mask;
652 		val |= PLLD_MISC0_DEFAULT_VALUE & mask;
653 		writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]);
654 		udelay(1);
655 
656 		return;
657 	}
658 
659 	val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]);
660 	val &= PLLD_MISC0_DSI_CLKENABLE;
661 	val |= PLLD_MISC0_DEFAULT_VALUE;
662 	/* set IDDQ, enable lock detect, disable SDM */
663 	writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]);
664 	writel_relaxed(PLLD_MISC1_DEFAULT_VALUE, clk_base +
665 			plld->params->ext_misc_reg[1]);
666 	udelay(1);
667 }
668 
669 /*
670  * PLLD2, PLLDP
671  * PLL with fractional SDM and Spread Spectrum (SDM is a must if SSC is used).
672  */
673 static void plldss_defaults(const char *pll_name, struct tegra_clk_pll *plldss,
674 		u32 misc0_val, u32 misc1_val, u32 misc2_val, u32 misc3_val)
675 {
676 	u32 default_val;
677 	u32 val = readl_relaxed(clk_base + plldss->params->base_reg);
678 
679 	plldss->params->defaults_set = true;
680 
681 	if (val & PLL_ENABLE) {
682 		pr_warn("%s already enabled. Postponing set full defaults\n",
683 			 pll_name);
684 
685 		/*
686 		 * PLL is ON: check if defaults already set, then set those
687 		 * that can be updated in flight.
688 		 */
689 		if (val & PLLDSS_BASE_IDDQ) {
690 			pr_warn("plldss boot enabled with IDDQ set\n");
691 			plldss->params->defaults_set = false;
692 		}
693 
694 		/* ignore lock enable */
695 		default_val = misc0_val;
696 		_pll_misc_chk_default(clk_base, plldss->params, 0, default_val,
697 				     PLLDSS_MISC0_WRITE_MASK &
698 				     (~PLLDSS_MISC0_LOCK_ENABLE));
699 
700 		/*
701 		 * If SSC is used, check all settings, otherwise just confirm
702 		 * that SSC is not used on boot as well. Do nothing when using
703 		 * this function for PLLC4 that has only MISC0.
704 		 */
705 		if (plldss->params->ssc_ctrl_en_mask) {
706 			default_val = misc1_val;
707 			_pll_misc_chk_default(clk_base, plldss->params, 1,
708 				default_val, PLLDSS_MISC1_CFG_WRITE_MASK);
709 			default_val = misc2_val;
710 			_pll_misc_chk_default(clk_base, plldss->params, 2,
711 				default_val, PLLDSS_MISC2_CTRL1_WRITE_MASK);
712 			default_val = misc3_val;
713 			_pll_misc_chk_default(clk_base, plldss->params, 3,
714 				default_val, PLLDSS_MISC3_CTRL2_WRITE_MASK);
715 		} else if (plldss->params->ext_misc_reg[1]) {
716 			default_val = misc1_val;
717 			_pll_misc_chk_default(clk_base, plldss->params, 1,
718 				default_val, PLLDSS_MISC1_CFG_WRITE_MASK &
719 				(~PLLDSS_MISC1_CFG_EN_SDM));
720 		}
721 
722 		/* Enable lock detect */
723 		if (val & PLLDSS_BASE_LOCK_OVERRIDE) {
724 			val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
725 			writel_relaxed(val, clk_base +
726 					plldss->params->base_reg);
727 		}
728 
729 		val = readl_relaxed(clk_base + plldss->params->ext_misc_reg[0]);
730 		val &= ~PLLDSS_MISC0_LOCK_ENABLE;
731 		val |= misc0_val & PLLDSS_MISC0_LOCK_ENABLE;
732 		writel_relaxed(val, clk_base + plldss->params->ext_misc_reg[0]);
733 		udelay(1);
734 
735 		return;
736 	}
737 
738 	/* set IDDQ, enable lock detect, configure SDM/SSC  */
739 	val |= PLLDSS_BASE_IDDQ;
740 	val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
741 	writel_relaxed(val, clk_base + plldss->params->base_reg);
742 
743 	/* When using this function for PLLC4 exit here */
744 	if (!plldss->params->ext_misc_reg[1]) {
745 		writel_relaxed(misc0_val, clk_base +
746 				plldss->params->ext_misc_reg[0]);
747 		udelay(1);
748 		return;
749 	}
750 
751 	writel_relaxed(misc0_val, clk_base +
752 			plldss->params->ext_misc_reg[0]);
753 	/* if SSC used set by 1st enable */
754 	writel_relaxed(misc1_val & (~PLLDSS_MISC1_CFG_EN_SSC),
755 			clk_base + plldss->params->ext_misc_reg[1]);
756 	writel_relaxed(misc2_val, clk_base + plldss->params->ext_misc_reg[2]);
757 	writel_relaxed(misc3_val, clk_base + plldss->params->ext_misc_reg[3]);
758 	udelay(1);
759 }
760 
761 static void tegra210_plld2_set_defaults(struct tegra_clk_pll *plld2)
762 {
763 	plldss_defaults("PLL_D2", plld2, PLLD2_MISC0_DEFAULT_VALUE,
764 			PLLD2_MISC1_CFG_DEFAULT_VALUE,
765 			PLLD2_MISC2_CTRL1_DEFAULT_VALUE,
766 			PLLD2_MISC3_CTRL2_DEFAULT_VALUE);
767 }
768 
769 static void tegra210_plldp_set_defaults(struct tegra_clk_pll *plldp)
770 {
771 	plldss_defaults("PLL_DP", plldp, PLLDP_MISC0_DEFAULT_VALUE,
772 			PLLDP_MISC1_CFG_DEFAULT_VALUE,
773 			PLLDP_MISC2_CTRL1_DEFAULT_VALUE,
774 			PLLDP_MISC3_CTRL2_DEFAULT_VALUE);
775 }
776 
777 /*
778  * PLLC4
779  * Base and misc0 layout is the same as PLLD2/PLLDP, but no SDM/SSC support.
780  * VCO is exposed to the clock tree via fixed 1/3 and 1/5 dividers.
781  */
782 static void tegra210_pllc4_set_defaults(struct tegra_clk_pll *pllc4)
783 {
784 	plldss_defaults("PLL_C4", pllc4, PLLC4_MISC0_DEFAULT_VALUE, 0, 0, 0);
785 }
786 
787 /*
788  * PLLRE
789  * VCO is exposed to the clock tree directly along with post-divider output
790  */
791 static void tegra210_pllre_set_defaults(struct tegra_clk_pll *pllre)
792 {
793 	u32 mask;
794 	u32 val = readl_relaxed(clk_base + pllre->params->base_reg);
795 
796 	pllre->params->defaults_set = true;
797 
798 	if (val & PLL_ENABLE) {
799 		pr_warn("PLL_RE already enabled. Postponing set full defaults\n");
800 
801 		/*
802 		 * PLL is ON: check if defaults already set, then set those
803 		 * that can be updated in flight.
804 		 */
805 		val &= PLLRE_BASE_DEFAULT_MASK;
806 		if (val != PLLRE_BASE_DEFAULT_VALUE) {
807 			pr_warn("pllre boot base 0x%x : expected 0x%x\n",
808 				val, PLLRE_BASE_DEFAULT_VALUE);
809 			pr_warn("(comparison mask = 0x%x)\n",
810 				PLLRE_BASE_DEFAULT_MASK);
811 			pllre->params->defaults_set = false;
812 		}
813 
814 		/* Ignore lock enable */
815 		val = PLLRE_MISC0_DEFAULT_VALUE & (~PLLRE_MISC0_IDDQ);
816 		mask = PLLRE_MISC0_LOCK_ENABLE | PLLRE_MISC0_LOCK_OVERRIDE;
817 		_pll_misc_chk_default(clk_base, pllre->params, 0, val,
818 				~mask & PLLRE_MISC0_WRITE_MASK);
819 
820 		/* Enable lock detect */
821 		val = readl_relaxed(clk_base + pllre->params->ext_misc_reg[0]);
822 		val &= ~mask;
823 		val |= PLLRE_MISC0_DEFAULT_VALUE & mask;
824 		writel_relaxed(val, clk_base + pllre->params->ext_misc_reg[0]);
825 		udelay(1);
826 
827 		return;
828 	}
829 
830 	/* set IDDQ, enable lock detect */
831 	val &= ~PLLRE_BASE_DEFAULT_MASK;
832 	val |= PLLRE_BASE_DEFAULT_VALUE & PLLRE_BASE_DEFAULT_MASK;
833 	writel_relaxed(val, clk_base + pllre->params->base_reg);
834 	writel_relaxed(PLLRE_MISC0_DEFAULT_VALUE,
835 			clk_base + pllre->params->ext_misc_reg[0]);
836 	udelay(1);
837 }
838 
839 static void pllx_get_dyn_steps(struct clk_hw *hw, u32 *step_a, u32 *step_b)
840 {
841 	unsigned long input_rate;
842 
843 	/* cf rate */
844 	if (!IS_ERR_OR_NULL(hw->clk))
845 		input_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
846 	else
847 		input_rate = 38400000;
848 
849 	input_rate /= tegra_pll_get_fixed_mdiv(hw, input_rate);
850 
851 	switch (input_rate) {
852 	case 12000000:
853 	case 12800000:
854 	case 13000000:
855 		*step_a = 0x2B;
856 		*step_b = 0x0B;
857 		return;
858 	case 19200000:
859 		*step_a = 0x12;
860 		*step_b = 0x08;
861 		return;
862 	case 38400000:
863 		*step_a = 0x04;
864 		*step_b = 0x05;
865 		return;
866 	default:
867 		pr_err("%s: Unexpected reference rate %lu\n",
868 			__func__, input_rate);
869 		BUG();
870 	}
871 }
872 
873 static void pllx_check_defaults(struct tegra_clk_pll *pll)
874 {
875 	u32 default_val;
876 
877 	default_val = PLLX_MISC0_DEFAULT_VALUE;
878 	/* ignore lock enable */
879 	_pll_misc_chk_default(clk_base, pll->params, 0, default_val,
880 			PLLX_MISC0_WRITE_MASK & (~PLLX_MISC0_LOCK_ENABLE));
881 
882 	default_val = PLLX_MISC1_DEFAULT_VALUE;
883 	_pll_misc_chk_default(clk_base, pll->params, 1, default_val,
884 			PLLX_MISC1_WRITE_MASK);
885 
886 	/* ignore all but control bit */
887 	default_val = PLLX_MISC2_DEFAULT_VALUE;
888 	_pll_misc_chk_default(clk_base, pll->params, 2,
889 			default_val, PLLX_MISC2_EN_DYNRAMP);
890 
891 	default_val = PLLX_MISC3_DEFAULT_VALUE & (~PLLX_MISC3_IDDQ);
892 	_pll_misc_chk_default(clk_base, pll->params, 3, default_val,
893 			PLLX_MISC3_WRITE_MASK);
894 
895 	default_val = PLLX_MISC4_DEFAULT_VALUE;
896 	_pll_misc_chk_default(clk_base, pll->params, 4, default_val,
897 			PLLX_MISC4_WRITE_MASK);
898 
899 	default_val = PLLX_MISC5_DEFAULT_VALUE;
900 	_pll_misc_chk_default(clk_base, pll->params, 5, default_val,
901 			PLLX_MISC5_WRITE_MASK);
902 }
903 
904 static void tegra210_pllx_set_defaults(struct tegra_clk_pll *pllx)
905 {
906 	u32 val;
907 	u32 step_a, step_b;
908 
909 	pllx->params->defaults_set = true;
910 
911 	/* Get ready dyn ramp state machine settings */
912 	pllx_get_dyn_steps(&pllx->hw, &step_a, &step_b);
913 	val = PLLX_MISC2_DEFAULT_VALUE & (~PLLX_MISC2_DYNRAMP_STEPA_MASK) &
914 		(~PLLX_MISC2_DYNRAMP_STEPB_MASK);
915 	val |= step_a << PLLX_MISC2_DYNRAMP_STEPA_SHIFT;
916 	val |= step_b << PLLX_MISC2_DYNRAMP_STEPB_SHIFT;
917 
918 	if (readl_relaxed(clk_base + pllx->params->base_reg) & PLL_ENABLE) {
919 		pr_warn("PLL_X already enabled. Postponing set full defaults\n");
920 
921 		/*
922 		 * PLL is ON: check if defaults already set, then set those
923 		 * that can be updated in flight.
924 		 */
925 		pllx_check_defaults(pllx);
926 
927 		/* Configure dyn ramp, disable lock override */
928 		writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
929 
930 		/* Enable lock detect */
931 		val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[0]);
932 		val &= ~PLLX_MISC0_LOCK_ENABLE;
933 		val |= PLLX_MISC0_DEFAULT_VALUE & PLLX_MISC0_LOCK_ENABLE;
934 		writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[0]);
935 		udelay(1);
936 
937 		return;
938 	}
939 
940 	/* Enable lock detect and CPU output */
941 	writel_relaxed(PLLX_MISC0_DEFAULT_VALUE, clk_base +
942 			pllx->params->ext_misc_reg[0]);
943 
944 	/* Setup */
945 	writel_relaxed(PLLX_MISC1_DEFAULT_VALUE, clk_base +
946 			pllx->params->ext_misc_reg[1]);
947 
948 	/* Configure dyn ramp state machine, disable lock override */
949 	writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
950 
951 	/* Set IDDQ */
952 	writel_relaxed(PLLX_MISC3_DEFAULT_VALUE, clk_base +
953 			pllx->params->ext_misc_reg[3]);
954 
955 	/* Disable SDM */
956 	writel_relaxed(PLLX_MISC4_DEFAULT_VALUE, clk_base +
957 			pllx->params->ext_misc_reg[4]);
958 	writel_relaxed(PLLX_MISC5_DEFAULT_VALUE, clk_base +
959 			pllx->params->ext_misc_reg[5]);
960 	udelay(1);
961 }
962 
963 /* PLLMB */
964 static void tegra210_pllmb_set_defaults(struct tegra_clk_pll *pllmb)
965 {
966 	u32 mask, val = readl_relaxed(clk_base + pllmb->params->base_reg);
967 
968 	pllmb->params->defaults_set = true;
969 
970 	if (val & PLL_ENABLE) {
971 		pr_warn("PLL_MB already enabled. Postponing set full defaults\n");
972 
973 		/*
974 		 * PLL is ON: check if defaults already set, then set those
975 		 * that can be updated in flight.
976 		 */
977 		val = PLLMB_MISC1_DEFAULT_VALUE & (~PLLMB_MISC1_IDDQ);
978 		mask = PLLMB_MISC1_LOCK_ENABLE | PLLMB_MISC1_LOCK_OVERRIDE;
979 		_pll_misc_chk_default(clk_base, pllmb->params, 0, val,
980 				~mask & PLLMB_MISC1_WRITE_MASK);
981 
982 		/* Enable lock detect */
983 		val = readl_relaxed(clk_base + pllmb->params->ext_misc_reg[0]);
984 		val &= ~mask;
985 		val |= PLLMB_MISC1_DEFAULT_VALUE & mask;
986 		writel_relaxed(val, clk_base + pllmb->params->ext_misc_reg[0]);
987 		udelay(1);
988 
989 		return;
990 	}
991 
992 	/* set IDDQ, enable lock detect */
993 	writel_relaxed(PLLMB_MISC1_DEFAULT_VALUE,
994 			clk_base + pllmb->params->ext_misc_reg[0]);
995 	udelay(1);
996 }
997 
998 /*
999  * PLLP
1000  * VCO is exposed to the clock tree directly along with post-divider output.
1001  * Both VCO and post-divider output rates are fixed at 408MHz and 204MHz,
1002  * respectively.
1003  */
1004 static void pllp_check_defaults(struct tegra_clk_pll *pll, bool enabled)
1005 {
1006 	u32 val, mask;
1007 
1008 	/* Ignore lock enable (will be set), make sure not in IDDQ if enabled */
1009 	val = PLLP_MISC0_DEFAULT_VALUE & (~PLLP_MISC0_IDDQ);
1010 	mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
1011 	if (!enabled)
1012 		mask |= PLLP_MISC0_IDDQ;
1013 	_pll_misc_chk_default(clk_base, pll->params, 0, val,
1014 			~mask & PLLP_MISC0_WRITE_MASK);
1015 
1016 	/* Ignore branch controls */
1017 	val = PLLP_MISC1_DEFAULT_VALUE;
1018 	mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
1019 	_pll_misc_chk_default(clk_base, pll->params, 1, val,
1020 			~mask & PLLP_MISC1_WRITE_MASK);
1021 }
1022 
1023 static void tegra210_pllp_set_defaults(struct tegra_clk_pll *pllp)
1024 {
1025 	u32 mask;
1026 	u32 val = readl_relaxed(clk_base + pllp->params->base_reg);
1027 
1028 	pllp->params->defaults_set = true;
1029 
1030 	if (val & PLL_ENABLE) {
1031 		pr_warn("PLL_P already enabled. Postponing set full defaults\n");
1032 
1033 		/*
1034 		 * PLL is ON: check if defaults already set, then set those
1035 		 * that can be updated in flight.
1036 		 */
1037 		pllp_check_defaults(pllp, true);
1038 
1039 		/* Enable lock detect */
1040 		val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[0]);
1041 		mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
1042 		val &= ~mask;
1043 		val |= PLLP_MISC0_DEFAULT_VALUE & mask;
1044 		writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[0]);
1045 		udelay(1);
1046 
1047 		return;
1048 	}
1049 
1050 	/* set IDDQ, enable lock detect */
1051 	writel_relaxed(PLLP_MISC0_DEFAULT_VALUE,
1052 			clk_base + pllp->params->ext_misc_reg[0]);
1053 
1054 	/* Preserve branch control */
1055 	val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[1]);
1056 	mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
1057 	val &= mask;
1058 	val |= ~mask & PLLP_MISC1_DEFAULT_VALUE;
1059 	writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[1]);
1060 	udelay(1);
1061 }
1062 
1063 /*
1064  * PLLU
1065  * VCO is exposed to the clock tree directly along with post-divider output.
1066  * Both VCO and post-divider output rates are fixed at 480MHz and 240MHz,
1067  * respectively.
1068  */
1069 static void pllu_check_defaults(struct tegra_clk_pll *pll, bool hw_control)
1070 {
1071 	u32 val, mask;
1072 
1073 	/* Ignore lock enable (will be set) and IDDQ if under h/w control */
1074 	val = PLLU_MISC0_DEFAULT_VALUE & (~PLLU_MISC0_IDDQ);
1075 	mask = PLLU_MISC0_LOCK_ENABLE | (hw_control ? PLLU_MISC0_IDDQ : 0);
1076 	_pll_misc_chk_default(clk_base, pll->params, 0, val,
1077 			~mask & PLLU_MISC0_WRITE_MASK);
1078 
1079 	val = PLLU_MISC1_DEFAULT_VALUE;
1080 	mask = PLLU_MISC1_LOCK_OVERRIDE;
1081 	_pll_misc_chk_default(clk_base, pll->params, 1, val,
1082 			~mask & PLLU_MISC1_WRITE_MASK);
1083 }
1084 
1085 static void tegra210_pllu_set_defaults(struct tegra_clk_pll *pllu)
1086 {
1087 	u32 val = readl_relaxed(clk_base + pllu->params->base_reg);
1088 
1089 	pllu->params->defaults_set = true;
1090 
1091 	if (val & PLL_ENABLE) {
1092 		pr_warn("PLL_U already enabled. Postponing set full defaults\n");
1093 
1094 		/*
1095 		 * PLL is ON: check if defaults already set, then set those
1096 		 * that can be updated in flight.
1097 		 */
1098 		pllu_check_defaults(pllu, false);
1099 
1100 		/* Enable lock detect */
1101 		val = readl_relaxed(clk_base + pllu->params->ext_misc_reg[0]);
1102 		val &= ~PLLU_MISC0_LOCK_ENABLE;
1103 		val |= PLLU_MISC0_DEFAULT_VALUE & PLLU_MISC0_LOCK_ENABLE;
1104 		writel_relaxed(val, clk_base + pllu->params->ext_misc_reg[0]);
1105 
1106 		val = readl_relaxed(clk_base + pllu->params->ext_misc_reg[1]);
1107 		val &= ~PLLU_MISC1_LOCK_OVERRIDE;
1108 		val |= PLLU_MISC1_DEFAULT_VALUE & PLLU_MISC1_LOCK_OVERRIDE;
1109 		writel_relaxed(val, clk_base + pllu->params->ext_misc_reg[1]);
1110 		udelay(1);
1111 
1112 		return;
1113 	}
1114 
1115 	/* set IDDQ, enable lock detect */
1116 	writel_relaxed(PLLU_MISC0_DEFAULT_VALUE,
1117 			clk_base + pllu->params->ext_misc_reg[0]);
1118 	writel_relaxed(PLLU_MISC1_DEFAULT_VALUE,
1119 			clk_base + pllu->params->ext_misc_reg[1]);
1120 	udelay(1);
1121 }
1122 
1123 #define mask(w) ((1 << (w)) - 1)
1124 #define divm_mask(p) mask(p->params->div_nmp->divm_width)
1125 #define divn_mask(p) mask(p->params->div_nmp->divn_width)
1126 #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\
1127 		      mask(p->params->div_nmp->divp_width))
1128 
1129 #define divm_shift(p) ((p)->params->div_nmp->divm_shift)
1130 #define divn_shift(p) ((p)->params->div_nmp->divn_shift)
1131 #define divp_shift(p) ((p)->params->div_nmp->divp_shift)
1132 
1133 #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p))
1134 #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p))
1135 #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p))
1136 
1137 #define PLL_LOCKDET_DELAY 2	/* Lock detection safety delays */
1138 static int tegra210_wait_for_mask(struct tegra_clk_pll *pll,
1139 				  u32 reg, u32 mask)
1140 {
1141 	int i;
1142 	u32 val = 0;
1143 
1144 	for (i = 0; i < pll->params->lock_delay / PLL_LOCKDET_DELAY + 1; i++) {
1145 		udelay(PLL_LOCKDET_DELAY);
1146 		val = readl_relaxed(clk_base + reg);
1147 		if ((val & mask) == mask) {
1148 			udelay(PLL_LOCKDET_DELAY);
1149 			return 0;
1150 		}
1151 	}
1152 	return -ETIMEDOUT;
1153 }
1154 
1155 static int tegra210_pllx_dyn_ramp(struct tegra_clk_pll *pllx,
1156 		struct tegra_clk_pll_freq_table *cfg)
1157 {
1158 	u32 val, base, ndiv_new_mask;
1159 
1160 	ndiv_new_mask = (divn_mask(pllx) >> pllx->params->div_nmp->divn_shift)
1161 			 << PLLX_MISC2_NDIV_NEW_SHIFT;
1162 
1163 	val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]);
1164 	val &= (~ndiv_new_mask);
1165 	val |= cfg->n << PLLX_MISC2_NDIV_NEW_SHIFT;
1166 	writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
1167 	udelay(1);
1168 
1169 	val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]);
1170 	val |= PLLX_MISC2_EN_DYNRAMP;
1171 	writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
1172 	udelay(1);
1173 
1174 	tegra210_wait_for_mask(pllx, pllx->params->ext_misc_reg[2],
1175 			       PLLX_MISC2_DYNRAMP_DONE);
1176 
1177 	base = readl_relaxed(clk_base + pllx->params->base_reg) &
1178 		(~divn_mask_shifted(pllx));
1179 	base |= cfg->n << pllx->params->div_nmp->divn_shift;
1180 	writel_relaxed(base, clk_base + pllx->params->base_reg);
1181 	udelay(1);
1182 
1183 	val &= ~PLLX_MISC2_EN_DYNRAMP;
1184 	writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]);
1185 	udelay(1);
1186 
1187 	pr_debug("%s: dynamic ramp to m = %u n = %u p = %u, Fout = %lu kHz\n",
1188 		 __clk_get_name(pllx->hw.clk), cfg->m, cfg->n, cfg->p,
1189 		 cfg->input_rate / cfg->m * cfg->n /
1190 		 pllx->params->pdiv_tohw[cfg->p].pdiv / 1000);
1191 
1192 	return 0;
1193 }
1194 
1195 /*
1196  * Common configuration for PLLs with fixed input divider policy:
1197  * - always set fixed M-value based on the reference rate
1198  * - always set P-value value 1:1 for output rates above VCO minimum, and
1199  *   choose minimum necessary P-value for output rates below VCO maximum
1200  * - calculate N-value based on selected M and P
1201  * - calculate SDM_DIN fractional part
1202  */
1203 static int tegra210_pll_fixed_mdiv_cfg(struct clk_hw *hw,
1204 			       struct tegra_clk_pll_freq_table *cfg,
1205 			       unsigned long rate, unsigned long input_rate)
1206 {
1207 	struct tegra_clk_pll *pll = to_clk_pll(hw);
1208 	struct tegra_clk_pll_params *params = pll->params;
1209 	int p;
1210 	unsigned long cf, p_rate;
1211 	u32 pdiv;
1212 
1213 	if (!rate)
1214 		return -EINVAL;
1215 
1216 	if (!(params->flags & TEGRA_PLL_VCO_OUT)) {
1217 		p = DIV_ROUND_UP(params->vco_min, rate);
1218 		p = params->round_p_to_pdiv(p, &pdiv);
1219 	} else {
1220 		p = rate >= params->vco_min ? 1 : -EINVAL;
1221 	}
1222 
1223 	if (IS_ERR_VALUE(p))
1224 		return -EINVAL;
1225 
1226 	cfg->m = tegra_pll_get_fixed_mdiv(hw, input_rate);
1227 	cfg->p = p;
1228 
1229 	/* Store P as HW value, as that is what is expected */
1230 	cfg->p = tegra_pll_p_div_to_hw(pll, cfg->p);
1231 
1232 	p_rate = rate * p;
1233 	if (p_rate > params->vco_max)
1234 		p_rate = params->vco_max;
1235 	cf = input_rate / cfg->m;
1236 	cfg->n = p_rate / cf;
1237 
1238 	cfg->sdm_data = 0;
1239 	if (params->sdm_ctrl_reg) {
1240 		unsigned long rem = p_rate - cf * cfg->n;
1241 		/* If ssc is enabled SDM enabled as well, even for integer n */
1242 		if (rem || params->ssc_ctrl_reg) {
1243 			u64 s = rem * PLL_SDM_COEFF;
1244 
1245 			do_div(s, cf);
1246 			s -= PLL_SDM_COEFF / 2;
1247 			cfg->sdm_data = sdin_din_to_data(s);
1248 		}
1249 	}
1250 
1251 	cfg->input_rate = input_rate;
1252 	cfg->output_rate = rate;
1253 
1254 	return 0;
1255 }
1256 
1257 /*
1258  * clk_pll_set_gain - set gain to m, n to calculate correct VCO rate
1259  *
1260  * @cfg: struct tegra_clk_pll_freq_table * cfg
1261  *
1262  * For Normal mode:
1263  *     Fvco = Fref * NDIV / MDIV
1264  *
1265  * For fractional mode:
1266  *     Fvco = Fref * (NDIV + 0.5 + SDM_DIN / PLL_SDM_COEFF) / MDIV
1267  */
1268 static void tegra210_clk_pll_set_gain(struct tegra_clk_pll_freq_table *cfg)
1269 {
1270 	cfg->n = cfg->n * PLL_SDM_COEFF + PLL_SDM_COEFF/2 +
1271 			sdin_data_to_din(cfg->sdm_data);
1272 	cfg->m *= PLL_SDM_COEFF;
1273 }
1274 
1275 static unsigned long
1276 tegra210_clk_adjust_vco_min(struct tegra_clk_pll_params *params,
1277 			    unsigned long parent_rate)
1278 {
1279 	unsigned long vco_min = params->vco_min;
1280 
1281 	params->vco_min += DIV_ROUND_UP(parent_rate, PLL_SDM_COEFF);
1282 	vco_min = min(vco_min, params->vco_min);
1283 
1284 	return vco_min;
1285 }
1286 
1287 static struct div_nmp pllx_nmp = {
1288 	.divm_shift = 0,
1289 	.divm_width = 8,
1290 	.divn_shift = 8,
1291 	.divn_width = 8,
1292 	.divp_shift = 20,
1293 	.divp_width = 5,
1294 };
1295 /*
1296  * PLL post divider maps - two types: quasi-linear and exponential
1297  * post divider.
1298  */
1299 #define PLL_QLIN_PDIV_MAX	16
1300 static const struct pdiv_map pll_qlin_pdiv_to_hw[] = {
1301 	{ .pdiv =  1, .hw_val =  0 },
1302 	{ .pdiv =  2, .hw_val =  1 },
1303 	{ .pdiv =  3, .hw_val =  2 },
1304 	{ .pdiv =  4, .hw_val =  3 },
1305 	{ .pdiv =  5, .hw_val =  4 },
1306 	{ .pdiv =  6, .hw_val =  5 },
1307 	{ .pdiv =  8, .hw_val =  6 },
1308 	{ .pdiv =  9, .hw_val =  7 },
1309 	{ .pdiv = 10, .hw_val =  8 },
1310 	{ .pdiv = 12, .hw_val =  9 },
1311 	{ .pdiv = 15, .hw_val = 10 },
1312 	{ .pdiv = 16, .hw_val = 11 },
1313 	{ .pdiv = 18, .hw_val = 12 },
1314 	{ .pdiv = 20, .hw_val = 13 },
1315 	{ .pdiv = 24, .hw_val = 14 },
1316 	{ .pdiv = 30, .hw_val = 15 },
1317 	{ .pdiv = 32, .hw_val = 16 },
1318 };
1319 
1320 static u32 pll_qlin_p_to_pdiv(u32 p, u32 *pdiv)
1321 {
1322 	int i;
1323 
1324 	if (p) {
1325 		for (i = 0; i <= PLL_QLIN_PDIV_MAX; i++) {
1326 			if (p <= pll_qlin_pdiv_to_hw[i].pdiv) {
1327 				if (pdiv)
1328 					*pdiv = i;
1329 				return pll_qlin_pdiv_to_hw[i].pdiv;
1330 			}
1331 		}
1332 	}
1333 
1334 	return -EINVAL;
1335 }
1336 
1337 #define PLL_EXPO_PDIV_MAX	7
1338 static const struct pdiv_map pll_expo_pdiv_to_hw[] = {
1339 	{ .pdiv =   1, .hw_val = 0 },
1340 	{ .pdiv =   2, .hw_val = 1 },
1341 	{ .pdiv =   4, .hw_val = 2 },
1342 	{ .pdiv =   8, .hw_val = 3 },
1343 	{ .pdiv =  16, .hw_val = 4 },
1344 	{ .pdiv =  32, .hw_val = 5 },
1345 	{ .pdiv =  64, .hw_val = 6 },
1346 	{ .pdiv = 128, .hw_val = 7 },
1347 };
1348 
1349 static u32 pll_expo_p_to_pdiv(u32 p, u32 *pdiv)
1350 {
1351 	if (p) {
1352 		u32 i = fls(p);
1353 
1354 		if (i == ffs(p))
1355 			i--;
1356 
1357 		if (i <= PLL_EXPO_PDIV_MAX) {
1358 			if (pdiv)
1359 				*pdiv = i;
1360 			return 1 << i;
1361 		}
1362 	}
1363 	return -EINVAL;
1364 }
1365 
1366 static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
1367 	/* 1 GHz */
1368 	{ 12000000, 1000000000, 166, 1, 1, 0 }, /* actual: 996.0 MHz */
1369 	{ 13000000, 1000000000, 153, 1, 1, 0 }, /* actual: 994.0 MHz */
1370 	{ 38400000, 1000000000, 156, 3, 1, 0 }, /* actual: 998.4 MHz */
1371 	{        0,          0,   0, 0, 0, 0 },
1372 };
1373 
1374 static struct tegra_clk_pll_params pll_x_params = {
1375 	.input_min = 12000000,
1376 	.input_max = 800000000,
1377 	.cf_min = 12000000,
1378 	.cf_max = 38400000,
1379 	.vco_min = 1350000000,
1380 	.vco_max = 3000000000UL,
1381 	.base_reg = PLLX_BASE,
1382 	.misc_reg = PLLX_MISC0,
1383 	.lock_mask = PLL_BASE_LOCK,
1384 	.lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
1385 	.lock_delay = 300,
1386 	.ext_misc_reg[0] = PLLX_MISC0,
1387 	.ext_misc_reg[1] = PLLX_MISC1,
1388 	.ext_misc_reg[2] = PLLX_MISC2,
1389 	.ext_misc_reg[3] = PLLX_MISC3,
1390 	.ext_misc_reg[4] = PLLX_MISC4,
1391 	.ext_misc_reg[5] = PLLX_MISC5,
1392 	.iddq_reg = PLLX_MISC3,
1393 	.iddq_bit_idx = PLLXP_IDDQ_BIT,
1394 	.max_p = PLL_QLIN_PDIV_MAX,
1395 	.mdiv_default = 2,
1396 	.dyn_ramp_reg = PLLX_MISC2,
1397 	.stepa_shift = 16,
1398 	.stepb_shift = 24,
1399 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1400 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1401 	.div_nmp = &pllx_nmp,
1402 	.freq_table = pll_x_freq_table,
1403 	.flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
1404 	.dyn_ramp = tegra210_pllx_dyn_ramp,
1405 	.set_defaults = tegra210_pllx_set_defaults,
1406 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1407 };
1408 
1409 static struct div_nmp pllc_nmp = {
1410 	.divm_shift = 0,
1411 	.divm_width = 8,
1412 	.divn_shift = 10,
1413 	.divn_width = 8,
1414 	.divp_shift = 20,
1415 	.divp_width = 5,
1416 };
1417 
1418 static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = {
1419 	{ 12000000, 510000000, 85, 1, 1, 0 },
1420 	{ 13000000, 510000000, 78, 1, 1, 0 }, /* actual: 507.0 MHz */
1421 	{ 38400000, 510000000, 79, 3, 1, 0 }, /* actual: 505.6 MHz */
1422 	{        0,         0,  0, 0, 0, 0 },
1423 };
1424 
1425 static struct tegra_clk_pll_params pll_c_params = {
1426 	.input_min = 12000000,
1427 	.input_max = 700000000,
1428 	.cf_min = 12000000,
1429 	.cf_max = 50000000,
1430 	.vco_min = 600000000,
1431 	.vco_max = 1200000000,
1432 	.base_reg = PLLC_BASE,
1433 	.misc_reg = PLLC_MISC0,
1434 	.lock_mask = PLL_BASE_LOCK,
1435 	.lock_delay = 300,
1436 	.iddq_reg = PLLC_MISC1,
1437 	.iddq_bit_idx = PLLCX_IDDQ_BIT,
1438 	.reset_reg = PLLC_MISC0,
1439 	.reset_bit_idx = PLLCX_RESET_BIT,
1440 	.max_p = PLL_QLIN_PDIV_MAX,
1441 	.ext_misc_reg[0] = PLLC_MISC0,
1442 	.ext_misc_reg[1] = PLLC_MISC1,
1443 	.ext_misc_reg[2] = PLLC_MISC2,
1444 	.ext_misc_reg[3] = PLLC_MISC3,
1445 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1446 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1447 	.mdiv_default = 3,
1448 	.div_nmp = &pllc_nmp,
1449 	.freq_table = pll_cx_freq_table,
1450 	.flags = TEGRA_PLL_USE_LOCK,
1451 	.set_defaults = _pllc_set_defaults,
1452 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1453 };
1454 
1455 static struct div_nmp pllcx_nmp = {
1456 	.divm_shift = 0,
1457 	.divm_width = 8,
1458 	.divn_shift = 10,
1459 	.divn_width = 8,
1460 	.divp_shift = 20,
1461 	.divp_width = 5,
1462 };
1463 
1464 static struct tegra_clk_pll_params pll_c2_params = {
1465 	.input_min = 12000000,
1466 	.input_max = 700000000,
1467 	.cf_min = 12000000,
1468 	.cf_max = 50000000,
1469 	.vco_min = 600000000,
1470 	.vco_max = 1200000000,
1471 	.base_reg = PLLC2_BASE,
1472 	.misc_reg = PLLC2_MISC0,
1473 	.iddq_reg = PLLC2_MISC1,
1474 	.iddq_bit_idx = PLLCX_IDDQ_BIT,
1475 	.reset_reg = PLLC2_MISC0,
1476 	.reset_bit_idx = PLLCX_RESET_BIT,
1477 	.lock_mask = PLLCX_BASE_LOCK,
1478 	.lock_delay = 300,
1479 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1480 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1481 	.mdiv_default = 3,
1482 	.div_nmp = &pllcx_nmp,
1483 	.max_p = PLL_QLIN_PDIV_MAX,
1484 	.ext_misc_reg[0] = PLLC2_MISC0,
1485 	.ext_misc_reg[1] = PLLC2_MISC1,
1486 	.ext_misc_reg[2] = PLLC2_MISC2,
1487 	.ext_misc_reg[3] = PLLC2_MISC3,
1488 	.freq_table = pll_cx_freq_table,
1489 	.flags = TEGRA_PLL_USE_LOCK,
1490 	.set_defaults = _pllc2_set_defaults,
1491 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1492 };
1493 
1494 static struct tegra_clk_pll_params pll_c3_params = {
1495 	.input_min = 12000000,
1496 	.input_max = 700000000,
1497 	.cf_min = 12000000,
1498 	.cf_max = 50000000,
1499 	.vco_min = 600000000,
1500 	.vco_max = 1200000000,
1501 	.base_reg = PLLC3_BASE,
1502 	.misc_reg = PLLC3_MISC0,
1503 	.lock_mask = PLLCX_BASE_LOCK,
1504 	.lock_delay = 300,
1505 	.iddq_reg = PLLC3_MISC1,
1506 	.iddq_bit_idx = PLLCX_IDDQ_BIT,
1507 	.reset_reg = PLLC3_MISC0,
1508 	.reset_bit_idx = PLLCX_RESET_BIT,
1509 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1510 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1511 	.mdiv_default = 3,
1512 	.div_nmp = &pllcx_nmp,
1513 	.max_p = PLL_QLIN_PDIV_MAX,
1514 	.ext_misc_reg[0] = PLLC3_MISC0,
1515 	.ext_misc_reg[1] = PLLC3_MISC1,
1516 	.ext_misc_reg[2] = PLLC3_MISC2,
1517 	.ext_misc_reg[3] = PLLC3_MISC3,
1518 	.freq_table = pll_cx_freq_table,
1519 	.flags = TEGRA_PLL_USE_LOCK,
1520 	.set_defaults = _pllc3_set_defaults,
1521 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1522 };
1523 
1524 static struct div_nmp pllss_nmp = {
1525 	.divm_shift = 0,
1526 	.divm_width = 8,
1527 	.divn_shift = 8,
1528 	.divn_width = 8,
1529 	.divp_shift = 19,
1530 	.divp_width = 5,
1531 };
1532 
1533 static struct tegra_clk_pll_freq_table pll_c4_vco_freq_table[] = {
1534 	{ 12000000, 600000000, 50, 1, 0, 0 },
1535 	{ 13000000, 600000000, 46, 1, 0, 0 }, /* actual: 598.0 MHz */
1536 	{ 38400000, 600000000, 62, 4, 0, 0 }, /* actual: 595.2 MHz */
1537 	{        0,         0,  0, 0, 0, 0 },
1538 };
1539 
1540 static const struct clk_div_table pll_vco_post_div_table[] = {
1541 	{ .val =  0, .div =  1 },
1542 	{ .val =  1, .div =  2 },
1543 	{ .val =  2, .div =  3 },
1544 	{ .val =  3, .div =  4 },
1545 	{ .val =  4, .div =  5 },
1546 	{ .val =  5, .div =  6 },
1547 	{ .val =  6, .div =  8 },
1548 	{ .val =  7, .div = 10 },
1549 	{ .val =  8, .div = 12 },
1550 	{ .val =  9, .div = 16 },
1551 	{ .val = 10, .div = 12 },
1552 	{ .val = 11, .div = 16 },
1553 	{ .val = 12, .div = 20 },
1554 	{ .val = 13, .div = 24 },
1555 	{ .val = 14, .div = 32 },
1556 	{ .val =  0, .div =  0 },
1557 };
1558 
1559 static struct tegra_clk_pll_params pll_c4_vco_params = {
1560 	.input_min = 9600000,
1561 	.input_max = 800000000,
1562 	.cf_min = 9600000,
1563 	.cf_max = 19200000,
1564 	.vco_min = 500000000,
1565 	.vco_max = 1080000000,
1566 	.base_reg = PLLC4_BASE,
1567 	.misc_reg = PLLC4_MISC0,
1568 	.lock_mask = PLL_BASE_LOCK,
1569 	.lock_delay = 300,
1570 	.max_p = PLL_QLIN_PDIV_MAX,
1571 	.ext_misc_reg[0] = PLLC4_MISC0,
1572 	.iddq_reg = PLLC4_BASE,
1573 	.iddq_bit_idx = PLLSS_IDDQ_BIT,
1574 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1575 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1576 	.mdiv_default = 3,
1577 	.div_nmp = &pllss_nmp,
1578 	.freq_table = pll_c4_vco_freq_table,
1579 	.set_defaults = tegra210_pllc4_set_defaults,
1580 	.flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
1581 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1582 };
1583 
1584 static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
1585 	{ 12000000,  800000000,  66, 1, 0, 0 }, /* actual: 792.0 MHz */
1586 	{ 13000000,  800000000,  61, 1, 0, 0 }, /* actual: 793.0 MHz */
1587 	{ 38400000,  297600000,  93, 4, 2, 0 },
1588 	{ 38400000,  400000000, 125, 4, 2, 0 },
1589 	{ 38400000,  532800000, 111, 4, 1, 0 },
1590 	{ 38400000,  665600000, 104, 3, 1, 0 },
1591 	{ 38400000,  800000000, 125, 3, 1, 0 },
1592 	{ 38400000,  931200000,  97, 4, 0, 0 },
1593 	{ 38400000, 1065600000, 111, 4, 0, 0 },
1594 	{ 38400000, 1200000000, 125, 4, 0, 0 },
1595 	{ 38400000, 1331200000, 104, 3, 0, 0 },
1596 	{ 38400000, 1459200000,  76, 2, 0, 0 },
1597 	{ 38400000, 1600000000, 125, 3, 0, 0 },
1598 	{        0,          0,   0, 0, 0, 0 },
1599 };
1600 
1601 static struct div_nmp pllm_nmp = {
1602 	.divm_shift = 0,
1603 	.divm_width = 8,
1604 	.override_divm_shift = 0,
1605 	.divn_shift = 8,
1606 	.divn_width = 8,
1607 	.override_divn_shift = 8,
1608 	.divp_shift = 20,
1609 	.divp_width = 5,
1610 	.override_divp_shift = 27,
1611 };
1612 
1613 static struct tegra_clk_pll_params pll_m_params = {
1614 	.input_min = 9600000,
1615 	.input_max = 500000000,
1616 	.cf_min = 9600000,
1617 	.cf_max = 19200000,
1618 	.vco_min = 800000000,
1619 	.vco_max = 1866000000,
1620 	.base_reg = PLLM_BASE,
1621 	.misc_reg = PLLM_MISC2,
1622 	.lock_mask = PLL_BASE_LOCK,
1623 	.lock_enable_bit_idx = PLLM_MISC_LOCK_ENABLE,
1624 	.lock_delay = 300,
1625 	.iddq_reg = PLLM_MISC2,
1626 	.iddq_bit_idx = PLLM_IDDQ_BIT,
1627 	.max_p = PLL_QLIN_PDIV_MAX,
1628 	.ext_misc_reg[0] = PLLM_MISC2,
1629 	.ext_misc_reg[1] = PLLM_MISC1,
1630 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1631 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1632 	.div_nmp = &pllm_nmp,
1633 	.pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE,
1634 	.pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2,
1635 	.freq_table = pll_m_freq_table,
1636 	.flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
1637 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1638 };
1639 
1640 static struct tegra_clk_pll_params pll_mb_params = {
1641 	.input_min = 9600000,
1642 	.input_max = 500000000,
1643 	.cf_min = 9600000,
1644 	.cf_max = 19200000,
1645 	.vco_min = 800000000,
1646 	.vco_max = 1866000000,
1647 	.base_reg = PLLMB_BASE,
1648 	.misc_reg = PLLMB_MISC1,
1649 	.lock_mask = PLL_BASE_LOCK,
1650 	.lock_delay = 300,
1651 	.iddq_reg = PLLMB_MISC1,
1652 	.iddq_bit_idx = PLLMB_IDDQ_BIT,
1653 	.max_p = PLL_QLIN_PDIV_MAX,
1654 	.ext_misc_reg[0] = PLLMB_MISC1,
1655 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1656 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1657 	.div_nmp = &pllm_nmp,
1658 	.freq_table = pll_m_freq_table,
1659 	.flags = TEGRA_PLL_USE_LOCK,
1660 	.set_defaults = tegra210_pllmb_set_defaults,
1661 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1662 };
1663 
1664 
1665 static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
1666 	/* PLLE special case: use cpcon field to store cml divider value */
1667 	{ 672000000, 100000000, 125, 42, 0, 13 },
1668 	{ 624000000, 100000000, 125, 39, 0, 13 },
1669 	{ 336000000, 100000000, 125, 21, 0, 13 },
1670 	{ 312000000, 100000000, 200, 26, 0, 14 },
1671 	{  38400000, 100000000, 125,  2, 0, 14 },
1672 	{  12000000, 100000000, 200,  1, 0, 14 },
1673 	{         0,         0,   0,  0, 0,  0 },
1674 };
1675 
1676 static struct div_nmp plle_nmp = {
1677 	.divm_shift = 0,
1678 	.divm_width = 8,
1679 	.divn_shift = 8,
1680 	.divn_width = 8,
1681 	.divp_shift = 24,
1682 	.divp_width = 5,
1683 };
1684 
1685 static struct tegra_clk_pll_params pll_e_params = {
1686 	.input_min = 12000000,
1687 	.input_max = 800000000,
1688 	.cf_min = 12000000,
1689 	.cf_max = 38400000,
1690 	.vco_min = 1600000000,
1691 	.vco_max = 2500000000U,
1692 	.base_reg = PLLE_BASE,
1693 	.misc_reg = PLLE_MISC0,
1694 	.aux_reg = PLLE_AUX,
1695 	.lock_mask = PLLE_MISC_LOCK,
1696 	.lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
1697 	.lock_delay = 300,
1698 	.div_nmp = &plle_nmp,
1699 	.freq_table = pll_e_freq_table,
1700 	.flags = TEGRA_PLL_FIXED | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_USE_LOCK |
1701 		 TEGRA_PLL_HAS_LOCK_ENABLE,
1702 	.fixed_rate = 100000000,
1703 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1704 };
1705 
1706 static struct tegra_clk_pll_freq_table pll_re_vco_freq_table[] = {
1707 	{ 12000000, 672000000, 56, 1, 0, 0 },
1708 	{ 13000000, 672000000, 51, 1, 0, 0 }, /* actual: 663.0 MHz */
1709 	{ 38400000, 672000000, 70, 4, 0, 0 },
1710 	{        0,         0,  0, 0, 0, 0 },
1711 };
1712 
1713 static struct div_nmp pllre_nmp = {
1714 	.divm_shift = 0,
1715 	.divm_width = 8,
1716 	.divn_shift = 8,
1717 	.divn_width = 8,
1718 	.divp_shift = 16,
1719 	.divp_width = 5,
1720 };
1721 
1722 static struct tegra_clk_pll_params pll_re_vco_params = {
1723 	.input_min = 9600000,
1724 	.input_max = 800000000,
1725 	.cf_min = 9600000,
1726 	.cf_max = 19200000,
1727 	.vco_min = 350000000,
1728 	.vco_max = 700000000,
1729 	.base_reg = PLLRE_BASE,
1730 	.misc_reg = PLLRE_MISC0,
1731 	.lock_mask = PLLRE_MISC_LOCK,
1732 	.lock_delay = 300,
1733 	.max_p = PLL_QLIN_PDIV_MAX,
1734 	.ext_misc_reg[0] = PLLRE_MISC0,
1735 	.iddq_reg = PLLRE_MISC0,
1736 	.iddq_bit_idx = PLLRE_IDDQ_BIT,
1737 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1738 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1739 	.div_nmp = &pllre_nmp,
1740 	.freq_table = pll_re_vco_freq_table,
1741 	.flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_VCO_OUT,
1742 	.set_defaults = tegra210_pllre_set_defaults,
1743 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1744 };
1745 
1746 static struct div_nmp pllp_nmp = {
1747 	.divm_shift = 0,
1748 	.divm_width = 8,
1749 	.divn_shift = 10,
1750 	.divn_width = 8,
1751 	.divp_shift = 20,
1752 	.divp_width = 5,
1753 };
1754 
1755 static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
1756 	{ 12000000, 408000000, 34, 1, 0, 0 },
1757 	{ 38400000, 408000000, 85, 8, 0, 0 }, /* cf = 4.8MHz, allowed exception */
1758 	{        0,         0,  0, 0, 0, 0 },
1759 };
1760 
1761 static struct tegra_clk_pll_params pll_p_params = {
1762 	.input_min = 9600000,
1763 	.input_max = 800000000,
1764 	.cf_min = 9600000,
1765 	.cf_max = 19200000,
1766 	.vco_min = 350000000,
1767 	.vco_max = 700000000,
1768 	.base_reg = PLLP_BASE,
1769 	.misc_reg = PLLP_MISC0,
1770 	.lock_mask = PLL_BASE_LOCK,
1771 	.lock_delay = 300,
1772 	.iddq_reg = PLLP_MISC0,
1773 	.iddq_bit_idx = PLLXP_IDDQ_BIT,
1774 	.ext_misc_reg[0] = PLLP_MISC0,
1775 	.ext_misc_reg[1] = PLLP_MISC1,
1776 	.div_nmp = &pllp_nmp,
1777 	.freq_table = pll_p_freq_table,
1778 	.fixed_rate = 408000000,
1779 	.flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
1780 	.set_defaults = tegra210_pllp_set_defaults,
1781 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1782 };
1783 
1784 static struct tegra_clk_pll_params pll_a1_params = {
1785 	.input_min = 12000000,
1786 	.input_max = 700000000,
1787 	.cf_min = 12000000,
1788 	.cf_max = 50000000,
1789 	.vco_min = 600000000,
1790 	.vco_max = 1200000000,
1791 	.base_reg = PLLA1_BASE,
1792 	.misc_reg = PLLA1_MISC0,
1793 	.lock_mask = PLLCX_BASE_LOCK,
1794 	.lock_delay = 300,
1795 	.iddq_reg = PLLA1_MISC0,
1796 	.iddq_bit_idx = PLLCX_IDDQ_BIT,
1797 	.reset_reg = PLLA1_MISC0,
1798 	.reset_bit_idx = PLLCX_RESET_BIT,
1799 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1800 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1801 	.div_nmp = &pllc_nmp,
1802 	.ext_misc_reg[0] = PLLA1_MISC0,
1803 	.ext_misc_reg[1] = PLLA1_MISC1,
1804 	.ext_misc_reg[2] = PLLA1_MISC2,
1805 	.ext_misc_reg[3] = PLLA1_MISC3,
1806 	.freq_table = pll_cx_freq_table,
1807 	.flags = TEGRA_PLL_USE_LOCK,
1808 	.set_defaults = _plla1_set_defaults,
1809 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1810 };
1811 
1812 static struct div_nmp plla_nmp = {
1813 	.divm_shift = 0,
1814 	.divm_width = 8,
1815 	.divn_shift = 8,
1816 	.divn_width = 8,
1817 	.divp_shift = 20,
1818 	.divp_width = 5,
1819 };
1820 
1821 static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
1822 	{ 12000000, 282240000, 47, 1, 1, 1, 0xf148 }, /* actual: 282240234 */
1823 	{ 12000000, 368640000, 61, 1, 1, 1, 0xfe15 }, /* actual: 368640381 */
1824 	{ 12000000, 240000000, 60, 1, 2, 1,      0 },
1825 	{ 13000000, 282240000, 43, 1, 1, 1, 0xfd7d }, /* actual: 282239807 */
1826 	{ 13000000, 368640000, 56, 1, 1, 1, 0x06d8 }, /* actual: 368640137 */
1827 	{ 13000000, 240000000, 55, 1, 2, 1,      0 }, /* actual: 238.3 MHz */
1828 	{ 38400000, 282240000, 44, 3, 1, 1, 0xf333 }, /* actual: 282239844 */
1829 	{ 38400000, 368640000, 57, 3, 1, 1, 0x0333 }, /* actual: 368639844 */
1830 	{ 38400000, 240000000, 75, 3, 3, 1,      0 },
1831 	{        0,         0,  0, 0, 0, 0,      0 },
1832 };
1833 
1834 static struct tegra_clk_pll_params pll_a_params = {
1835 	.input_min = 12000000,
1836 	.input_max = 800000000,
1837 	.cf_min = 12000000,
1838 	.cf_max = 19200000,
1839 	.vco_min = 500000000,
1840 	.vco_max = 1000000000,
1841 	.base_reg = PLLA_BASE,
1842 	.misc_reg = PLLA_MISC0,
1843 	.lock_mask = PLL_BASE_LOCK,
1844 	.lock_delay = 300,
1845 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1846 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1847 	.iddq_reg = PLLA_BASE,
1848 	.iddq_bit_idx = PLLA_IDDQ_BIT,
1849 	.div_nmp = &plla_nmp,
1850 	.sdm_din_reg = PLLA_MISC1,
1851 	.sdm_din_mask = PLLA_SDM_DIN_MASK,
1852 	.sdm_ctrl_reg = PLLA_MISC2,
1853 	.sdm_ctrl_en_mask = PLLA_SDM_EN_MASK,
1854 	.ext_misc_reg[0] = PLLA_MISC0,
1855 	.ext_misc_reg[1] = PLLA_MISC1,
1856 	.ext_misc_reg[2] = PLLA_MISC2,
1857 	.freq_table = pll_a_freq_table,
1858 	.flags = TEGRA_PLL_USE_LOCK | TEGRA_MDIV_NEW,
1859 	.set_defaults = tegra210_plla_set_defaults,
1860 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1861 	.set_gain = tegra210_clk_pll_set_gain,
1862 	.adjust_vco = tegra210_clk_adjust_vco_min,
1863 };
1864 
1865 static struct div_nmp plld_nmp = {
1866 	.divm_shift = 0,
1867 	.divm_width = 8,
1868 	.divn_shift = 11,
1869 	.divn_width = 8,
1870 	.divp_shift = 20,
1871 	.divp_width = 3,
1872 };
1873 
1874 static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
1875 	{ 12000000, 594000000, 99, 1, 1, 0,      0 },
1876 	{ 13000000, 594000000, 91, 1, 1, 0, 0xfc4f }, /* actual: 594000183 */
1877 	{ 38400000, 594000000, 30, 1, 1, 0, 0x0e00 },
1878 	{        0,         0,  0, 0, 0, 0,      0 },
1879 };
1880 
1881 static struct tegra_clk_pll_params pll_d_params = {
1882 	.input_min = 12000000,
1883 	.input_max = 800000000,
1884 	.cf_min = 12000000,
1885 	.cf_max = 38400000,
1886 	.vco_min = 750000000,
1887 	.vco_max = 1500000000,
1888 	.base_reg = PLLD_BASE,
1889 	.misc_reg = PLLD_MISC0,
1890 	.lock_mask = PLL_BASE_LOCK,
1891 	.lock_delay = 1000,
1892 	.iddq_reg = PLLD_MISC0,
1893 	.iddq_bit_idx = PLLD_IDDQ_BIT,
1894 	.round_p_to_pdiv = pll_expo_p_to_pdiv,
1895 	.pdiv_tohw = pll_expo_pdiv_to_hw,
1896 	.div_nmp = &plld_nmp,
1897 	.sdm_din_reg = PLLD_MISC0,
1898 	.sdm_din_mask = PLLA_SDM_DIN_MASK,
1899 	.sdm_ctrl_reg = PLLD_MISC0,
1900 	.sdm_ctrl_en_mask = PLLD_SDM_EN_MASK,
1901 	.ext_misc_reg[0] = PLLD_MISC0,
1902 	.ext_misc_reg[1] = PLLD_MISC1,
1903 	.freq_table = pll_d_freq_table,
1904 	.flags = TEGRA_PLL_USE_LOCK,
1905 	.mdiv_default = 1,
1906 	.set_defaults = tegra210_plld_set_defaults,
1907 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1908 	.set_gain = tegra210_clk_pll_set_gain,
1909 	.adjust_vco = tegra210_clk_adjust_vco_min,
1910 };
1911 
1912 static struct tegra_clk_pll_freq_table tegra210_pll_d2_freq_table[] = {
1913 	{ 12000000, 594000000, 99, 1, 1, 0, 0xf000 },
1914 	{ 13000000, 594000000, 91, 1, 1, 0, 0xfc4f }, /* actual: 594000183 */
1915 	{ 38400000, 594000000, 30, 1, 1, 0, 0x0e00 },
1916 	{        0,         0,  0, 0, 0, 0,      0 },
1917 };
1918 
1919 /* s/w policy, always tegra_pll_ref */
1920 static struct tegra_clk_pll_params pll_d2_params = {
1921 	.input_min = 12000000,
1922 	.input_max = 800000000,
1923 	.cf_min = 12000000,
1924 	.cf_max = 38400000,
1925 	.vco_min = 750000000,
1926 	.vco_max = 1500000000,
1927 	.base_reg = PLLD2_BASE,
1928 	.misc_reg = PLLD2_MISC0,
1929 	.lock_mask = PLL_BASE_LOCK,
1930 	.lock_delay = 300,
1931 	.iddq_reg = PLLD2_BASE,
1932 	.iddq_bit_idx = PLLSS_IDDQ_BIT,
1933 	.sdm_din_reg = PLLD2_MISC3,
1934 	.sdm_din_mask = PLLA_SDM_DIN_MASK,
1935 	.sdm_ctrl_reg = PLLD2_MISC1,
1936 	.sdm_ctrl_en_mask = PLLD2_SDM_EN_MASK,
1937 	.ssc_ctrl_reg = PLLD2_MISC1,
1938 	.ssc_ctrl_en_mask = PLLD2_SSC_EN_MASK,
1939 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1940 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1941 	.div_nmp = &pllss_nmp,
1942 	.ext_misc_reg[0] = PLLD2_MISC0,
1943 	.ext_misc_reg[1] = PLLD2_MISC1,
1944 	.ext_misc_reg[2] = PLLD2_MISC2,
1945 	.ext_misc_reg[3] = PLLD2_MISC3,
1946 	.max_p = PLL_QLIN_PDIV_MAX,
1947 	.mdiv_default = 1,
1948 	.freq_table = tegra210_pll_d2_freq_table,
1949 	.set_defaults = tegra210_plld2_set_defaults,
1950 	.flags = TEGRA_PLL_USE_LOCK,
1951 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1952 	.set_gain = tegra210_clk_pll_set_gain,
1953 	.adjust_vco = tegra210_clk_adjust_vco_min,
1954 };
1955 
1956 static struct tegra_clk_pll_freq_table pll_dp_freq_table[] = {
1957 	{ 12000000, 270000000, 90, 1, 3, 0, 0xf000 },
1958 	{ 13000000, 270000000, 83, 1, 3, 0, 0xf000 }, /* actual: 269.8 MHz */
1959 	{ 38400000, 270000000, 28, 1, 3, 0, 0xf400 },
1960 	{        0,         0,  0, 0, 0, 0,      0 },
1961 };
1962 
1963 static struct tegra_clk_pll_params pll_dp_params = {
1964 	.input_min = 12000000,
1965 	.input_max = 800000000,
1966 	.cf_min = 12000000,
1967 	.cf_max = 38400000,
1968 	.vco_min = 750000000,
1969 	.vco_max = 1500000000,
1970 	.base_reg = PLLDP_BASE,
1971 	.misc_reg = PLLDP_MISC,
1972 	.lock_mask = PLL_BASE_LOCK,
1973 	.lock_delay = 300,
1974 	.iddq_reg = PLLDP_BASE,
1975 	.iddq_bit_idx = PLLSS_IDDQ_BIT,
1976 	.sdm_din_reg = PLLDP_SS_CTRL2,
1977 	.sdm_din_mask = PLLA_SDM_DIN_MASK,
1978 	.sdm_ctrl_reg = PLLDP_SS_CFG,
1979 	.sdm_ctrl_en_mask = PLLDP_SDM_EN_MASK,
1980 	.ssc_ctrl_reg = PLLDP_SS_CFG,
1981 	.ssc_ctrl_en_mask = PLLDP_SSC_EN_MASK,
1982 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
1983 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
1984 	.div_nmp = &pllss_nmp,
1985 	.ext_misc_reg[0] = PLLDP_MISC,
1986 	.ext_misc_reg[1] = PLLDP_SS_CFG,
1987 	.ext_misc_reg[2] = PLLDP_SS_CTRL1,
1988 	.ext_misc_reg[3] = PLLDP_SS_CTRL2,
1989 	.max_p = PLL_QLIN_PDIV_MAX,
1990 	.mdiv_default = 1,
1991 	.freq_table = pll_dp_freq_table,
1992 	.set_defaults = tegra210_plldp_set_defaults,
1993 	.flags = TEGRA_PLL_USE_LOCK,
1994 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
1995 	.set_gain = tegra210_clk_pll_set_gain,
1996 	.adjust_vco = tegra210_clk_adjust_vco_min,
1997 };
1998 
1999 static struct div_nmp pllu_nmp = {
2000 	.divm_shift = 0,
2001 	.divm_width = 8,
2002 	.divn_shift = 8,
2003 	.divn_width = 8,
2004 	.divp_shift = 16,
2005 	.divp_width = 5,
2006 };
2007 
2008 static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
2009 	{ 12000000, 480000000, 40, 1, 0, 0 },
2010 	{ 13000000, 480000000, 36, 1, 0, 0 }, /* actual: 468.0 MHz */
2011 	{ 38400000, 480000000, 25, 2, 0, 0 },
2012 	{        0,         0,  0, 0, 0, 0 },
2013 };
2014 
2015 static struct tegra_clk_pll_params pll_u_vco_params = {
2016 	.input_min = 9600000,
2017 	.input_max = 800000000,
2018 	.cf_min = 9600000,
2019 	.cf_max = 19200000,
2020 	.vco_min = 350000000,
2021 	.vco_max = 700000000,
2022 	.base_reg = PLLU_BASE,
2023 	.misc_reg = PLLU_MISC0,
2024 	.lock_mask = PLL_BASE_LOCK,
2025 	.lock_delay = 1000,
2026 	.iddq_reg = PLLU_MISC0,
2027 	.iddq_bit_idx = PLLU_IDDQ_BIT,
2028 	.ext_misc_reg[0] = PLLU_MISC0,
2029 	.ext_misc_reg[1] = PLLU_MISC1,
2030 	.round_p_to_pdiv = pll_qlin_p_to_pdiv,
2031 	.pdiv_tohw = pll_qlin_pdiv_to_hw,
2032 	.div_nmp = &pllu_nmp,
2033 	.freq_table = pll_u_freq_table,
2034 	.flags = TEGRA_PLLU | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT,
2035 	.set_defaults = tegra210_pllu_set_defaults,
2036 	.calc_rate = tegra210_pll_fixed_mdiv_cfg,
2037 };
2038 
2039 struct utmi_clk_param {
2040 	/* Oscillator Frequency in KHz */
2041 	u32 osc_frequency;
2042 	/* UTMIP PLL Enable Delay Count  */
2043 	u8 enable_delay_count;
2044 	/* UTMIP PLL Stable count */
2045 	u16 stable_count;
2046 	/*  UTMIP PLL Active delay count */
2047 	u8 active_delay_count;
2048 	/* UTMIP PLL Xtal frequency count */
2049 	u16 xtal_freq_count;
2050 };
2051 
2052 static const struct utmi_clk_param utmi_parameters[] = {
2053 	{
2054 		.osc_frequency = 38400000, .enable_delay_count = 0x0,
2055 		.stable_count = 0x0, .active_delay_count = 0x6,
2056 		.xtal_freq_count = 0x80
2057 	}, {
2058 		.osc_frequency = 13000000, .enable_delay_count = 0x02,
2059 		.stable_count = 0x33, .active_delay_count = 0x05,
2060 		.xtal_freq_count = 0x7f
2061 	}, {
2062 		.osc_frequency = 19200000, .enable_delay_count = 0x03,
2063 		.stable_count = 0x4b, .active_delay_count = 0x06,
2064 		.xtal_freq_count = 0xbb
2065 	}, {
2066 		.osc_frequency = 12000000, .enable_delay_count = 0x02,
2067 		.stable_count = 0x2f, .active_delay_count = 0x08,
2068 		.xtal_freq_count = 0x76
2069 	}, {
2070 		.osc_frequency = 26000000, .enable_delay_count = 0x04,
2071 		.stable_count = 0x66, .active_delay_count = 0x09,
2072 		.xtal_freq_count = 0xfe
2073 	}, {
2074 		.osc_frequency = 16800000, .enable_delay_count = 0x03,
2075 		.stable_count = 0x41, .active_delay_count = 0x0a,
2076 		.xtal_freq_count = 0xa4
2077 	},
2078 };
2079 
2080 static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = {
2081 	[tegra_clk_ispb] = { .dt_id = TEGRA210_CLK_ISPB, .present = true },
2082 	[tegra_clk_rtc] = { .dt_id = TEGRA210_CLK_RTC, .present = true },
2083 	[tegra_clk_timer] = { .dt_id = TEGRA210_CLK_TIMER, .present = true },
2084 	[tegra_clk_uarta_8] = { .dt_id = TEGRA210_CLK_UARTA, .present = true },
2085 	[tegra_clk_sdmmc2_9] = { .dt_id = TEGRA210_CLK_SDMMC2, .present = true },
2086 	[tegra_clk_i2s1] = { .dt_id = TEGRA210_CLK_I2S1, .present = true },
2087 	[tegra_clk_i2c1] = { .dt_id = TEGRA210_CLK_I2C1, .present = true },
2088 	[tegra_clk_sdmmc1_9] = { .dt_id = TEGRA210_CLK_SDMMC1, .present = true },
2089 	[tegra_clk_sdmmc4_9] = { .dt_id = TEGRA210_CLK_SDMMC4, .present = true },
2090 	[tegra_clk_pwm] = { .dt_id = TEGRA210_CLK_PWM, .present = true },
2091 	[tegra_clk_i2s2] = { .dt_id = TEGRA210_CLK_I2S2, .present = true },
2092 	[tegra_clk_usbd] = { .dt_id = TEGRA210_CLK_USBD, .present = true },
2093 	[tegra_clk_isp_9] = { .dt_id = TEGRA210_CLK_ISP, .present = true },
2094 	[tegra_clk_disp2_8] = { .dt_id = TEGRA210_CLK_DISP2, .present = true },
2095 	[tegra_clk_disp1_8] = { .dt_id = TEGRA210_CLK_DISP1, .present = true },
2096 	[tegra_clk_host1x_9] = { .dt_id = TEGRA210_CLK_HOST1X, .present = true },
2097 	[tegra_clk_i2s0] = { .dt_id = TEGRA210_CLK_I2S0, .present = true },
2098 	[tegra_clk_apbdma] = { .dt_id = TEGRA210_CLK_APBDMA, .present = true },
2099 	[tegra_clk_kfuse] = { .dt_id = TEGRA210_CLK_KFUSE, .present = true },
2100 	[tegra_clk_sbc1_9] = { .dt_id = TEGRA210_CLK_SBC1, .present = true },
2101 	[tegra_clk_sbc2_9] = { .dt_id = TEGRA210_CLK_SBC2, .present = true },
2102 	[tegra_clk_sbc3_9] = { .dt_id = TEGRA210_CLK_SBC3, .present = true },
2103 	[tegra_clk_i2c5] = { .dt_id = TEGRA210_CLK_I2C5, .present = true },
2104 	[tegra_clk_csi] = { .dt_id = TEGRA210_CLK_CSI, .present = true },
2105 	[tegra_clk_i2c2] = { .dt_id = TEGRA210_CLK_I2C2, .present = true },
2106 	[tegra_clk_uartc_8] = { .dt_id = TEGRA210_CLK_UARTC, .present = true },
2107 	[tegra_clk_mipi_cal] = { .dt_id = TEGRA210_CLK_MIPI_CAL, .present = true },
2108 	[tegra_clk_emc] = { .dt_id = TEGRA210_CLK_EMC, .present = true },
2109 	[tegra_clk_usb2] = { .dt_id = TEGRA210_CLK_USB2, .present = true },
2110 	[tegra_clk_bsev] = { .dt_id = TEGRA210_CLK_BSEV, .present = true },
2111 	[tegra_clk_uartd_8] = { .dt_id = TEGRA210_CLK_UARTD, .present = true },
2112 	[tegra_clk_i2c3] = { .dt_id = TEGRA210_CLK_I2C3, .present = true },
2113 	[tegra_clk_sbc4_9] = { .dt_id = TEGRA210_CLK_SBC4, .present = true },
2114 	[tegra_clk_sdmmc3_9] = { .dt_id = TEGRA210_CLK_SDMMC3, .present = true },
2115 	[tegra_clk_pcie] = { .dt_id = TEGRA210_CLK_PCIE, .present = true },
2116 	[tegra_clk_owr_8] = { .dt_id = TEGRA210_CLK_OWR, .present = true },
2117 	[tegra_clk_afi] = { .dt_id = TEGRA210_CLK_AFI, .present = true },
2118 	[tegra_clk_csite_8] = { .dt_id = TEGRA210_CLK_CSITE, .present = true },
2119 	[tegra_clk_soc_therm_8] = { .dt_id = TEGRA210_CLK_SOC_THERM, .present = true },
2120 	[tegra_clk_dtv] = { .dt_id = TEGRA210_CLK_DTV, .present = true },
2121 	[tegra_clk_i2cslow] = { .dt_id = TEGRA210_CLK_I2CSLOW, .present = true },
2122 	[tegra_clk_tsec_8] = { .dt_id = TEGRA210_CLK_TSEC, .present = true },
2123 	[tegra_clk_xusb_host] = { .dt_id = TEGRA210_CLK_XUSB_HOST, .present = true },
2124 	[tegra_clk_csus] = { .dt_id = TEGRA210_CLK_CSUS, .present = true },
2125 	[tegra_clk_mselect] = { .dt_id = TEGRA210_CLK_MSELECT, .present = true },
2126 	[tegra_clk_tsensor] = { .dt_id = TEGRA210_CLK_TSENSOR, .present = true },
2127 	[tegra_clk_i2s3] = { .dt_id = TEGRA210_CLK_I2S3, .present = true },
2128 	[tegra_clk_i2s4] = { .dt_id = TEGRA210_CLK_I2S4, .present = true },
2129 	[tegra_clk_i2c4] = { .dt_id = TEGRA210_CLK_I2C4, .present = true },
2130 	[tegra_clk_d_audio] = { .dt_id = TEGRA210_CLK_D_AUDIO, .present = true },
2131 	[tegra_clk_hda2codec_2x_8] = { .dt_id = TEGRA210_CLK_HDA2CODEC_2X, .present = true },
2132 	[tegra_clk_spdif_2x] = { .dt_id = TEGRA210_CLK_SPDIF_2X, .present = true },
2133 	[tegra_clk_actmon] = { .dt_id = TEGRA210_CLK_ACTMON, .present = true },
2134 	[tegra_clk_extern1] = { .dt_id = TEGRA210_CLK_EXTERN1, .present = true },
2135 	[tegra_clk_extern2] = { .dt_id = TEGRA210_CLK_EXTERN2, .present = true },
2136 	[tegra_clk_extern3] = { .dt_id = TEGRA210_CLK_EXTERN3, .present = true },
2137 	[tegra_clk_sata_oob_8] = { .dt_id = TEGRA210_CLK_SATA_OOB, .present = true },
2138 	[tegra_clk_sata_8] = { .dt_id = TEGRA210_CLK_SATA, .present = true },
2139 	[tegra_clk_hda_8] = { .dt_id = TEGRA210_CLK_HDA, .present = true },
2140 	[tegra_clk_hda2hdmi] = { .dt_id = TEGRA210_CLK_HDA2HDMI, .present = true },
2141 	[tegra_clk_cilab] = { .dt_id = TEGRA210_CLK_CILAB, .present = true },
2142 	[tegra_clk_cilcd] = { .dt_id = TEGRA210_CLK_CILCD, .present = true },
2143 	[tegra_clk_cile] = { .dt_id = TEGRA210_CLK_CILE, .present = true },
2144 	[tegra_clk_dsialp] = { .dt_id = TEGRA210_CLK_DSIALP, .present = true },
2145 	[tegra_clk_dsiblp] = { .dt_id = TEGRA210_CLK_DSIBLP, .present = true },
2146 	[tegra_clk_entropy_8] = { .dt_id = TEGRA210_CLK_ENTROPY, .present = true },
2147 	[tegra_clk_xusb_ss] = { .dt_id = TEGRA210_CLK_XUSB_SS, .present = true },
2148 	[tegra_clk_i2c6] = { .dt_id = TEGRA210_CLK_I2C6, .present = true },
2149 	[tegra_clk_vim2_clk] = { .dt_id = TEGRA210_CLK_VIM2_CLK, .present = true },
2150 	[tegra_clk_clk72Mhz_8] = { .dt_id = TEGRA210_CLK_CLK72MHZ, .present = true },
2151 	[tegra_clk_vic03_8] = { .dt_id = TEGRA210_CLK_VIC03, .present = true },
2152 	[tegra_clk_dpaux] = { .dt_id = TEGRA210_CLK_DPAUX, .present = true },
2153 	[tegra_clk_dpaux1] = { .dt_id = TEGRA210_CLK_DPAUX1, .present = true },
2154 	[tegra_clk_sor0] = { .dt_id = TEGRA210_CLK_SOR0, .present = true },
2155 	[tegra_clk_sor0_lvds] = { .dt_id = TEGRA210_CLK_SOR0_LVDS, .present = true },
2156 	[tegra_clk_gpu] = { .dt_id = TEGRA210_CLK_GPU, .present = true },
2157 	[tegra_clk_pll_g_ref] = { .dt_id = TEGRA210_CLK_PLL_G_REF, .present = true, },
2158 	[tegra_clk_uartb_8] = { .dt_id = TEGRA210_CLK_UARTB, .present = true },
2159 	[tegra_clk_vfir] = { .dt_id = TEGRA210_CLK_VFIR, .present = true },
2160 	[tegra_clk_spdif_in_8] = { .dt_id = TEGRA210_CLK_SPDIF_IN, .present = true },
2161 	[tegra_clk_spdif_out] = { .dt_id = TEGRA210_CLK_SPDIF_OUT, .present = true },
2162 	[tegra_clk_vi_10] = { .dt_id = TEGRA210_CLK_VI, .present = true },
2163 	[tegra_clk_vi_sensor_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR, .present = true },
2164 	[tegra_clk_fuse] = { .dt_id = TEGRA210_CLK_FUSE, .present = true },
2165 	[tegra_clk_fuse_burn] = { .dt_id = TEGRA210_CLK_FUSE_BURN, .present = true },
2166 	[tegra_clk_clk_32k] = { .dt_id = TEGRA210_CLK_CLK_32K, .present = true },
2167 	[tegra_clk_clk_m] = { .dt_id = TEGRA210_CLK_CLK_M, .present = true },
2168 	[tegra_clk_clk_m_div2] = { .dt_id = TEGRA210_CLK_CLK_M_DIV2, .present = true },
2169 	[tegra_clk_clk_m_div4] = { .dt_id = TEGRA210_CLK_CLK_M_DIV4, .present = true },
2170 	[tegra_clk_pll_ref] = { .dt_id = TEGRA210_CLK_PLL_REF, .present = true },
2171 	[tegra_clk_pll_c] = { .dt_id = TEGRA210_CLK_PLL_C, .present = true },
2172 	[tegra_clk_pll_c_out1] = { .dt_id = TEGRA210_CLK_PLL_C_OUT1, .present = true },
2173 	[tegra_clk_pll_c2] = { .dt_id = TEGRA210_CLK_PLL_C2, .present = true },
2174 	[tegra_clk_pll_c3] = { .dt_id = TEGRA210_CLK_PLL_C3, .present = true },
2175 	[tegra_clk_pll_m] = { .dt_id = TEGRA210_CLK_PLL_M, .present = true },
2176 	[tegra_clk_pll_m_out1] = { .dt_id = TEGRA210_CLK_PLL_M_OUT1, .present = true },
2177 	[tegra_clk_pll_p] = { .dt_id = TEGRA210_CLK_PLL_P, .present = true },
2178 	[tegra_clk_pll_p_out1] = { .dt_id = TEGRA210_CLK_PLL_P_OUT1, .present = true },
2179 	[tegra_clk_pll_p_out3] = { .dt_id = TEGRA210_CLK_PLL_P_OUT3, .present = true },
2180 	[tegra_clk_pll_p_out4_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT4, .present = true },
2181 	[tegra_clk_pll_p_out_hsio] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_HSIO, .present = true },
2182 	[tegra_clk_pll_p_out_xusb] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_XUSB, .present = true },
2183 	[tegra_clk_pll_p_out_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_CPU, .present = true },
2184 	[tegra_clk_pll_p_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_ADSP, .present = true },
2185 	[tegra_clk_pll_a] = { .dt_id = TEGRA210_CLK_PLL_A, .present = true },
2186 	[tegra_clk_pll_a_out0] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0, .present = true },
2187 	[tegra_clk_pll_d] = { .dt_id = TEGRA210_CLK_PLL_D, .present = true },
2188 	[tegra_clk_pll_d_out0] = { .dt_id = TEGRA210_CLK_PLL_D_OUT0, .present = true },
2189 	[tegra_clk_pll_d2] = { .dt_id = TEGRA210_CLK_PLL_D2, .present = true },
2190 	[tegra_clk_pll_d2_out0] = { .dt_id = TEGRA210_CLK_PLL_D2_OUT0, .present = true },
2191 	[tegra_clk_pll_u] = { .dt_id = TEGRA210_CLK_PLL_U, .present = true },
2192 	[tegra_clk_pll_u_out] = { .dt_id = TEGRA210_CLK_PLL_U_OUT, .present = true },
2193 	[tegra_clk_pll_u_out1] = { .dt_id = TEGRA210_CLK_PLL_U_OUT1, .present = true },
2194 	[tegra_clk_pll_u_out2] = { .dt_id = TEGRA210_CLK_PLL_U_OUT2, .present = true },
2195 	[tegra_clk_pll_u_480m] = { .dt_id = TEGRA210_CLK_PLL_U_480M, .present = true },
2196 	[tegra_clk_pll_u_60m] = { .dt_id = TEGRA210_CLK_PLL_U_60M, .present = true },
2197 	[tegra_clk_pll_u_48m] = { .dt_id = TEGRA210_CLK_PLL_U_48M, .present = true },
2198 	[tegra_clk_pll_x] = { .dt_id = TEGRA210_CLK_PLL_X, .present = true },
2199 	[tegra_clk_pll_x_out0] = { .dt_id = TEGRA210_CLK_PLL_X_OUT0, .present = true },
2200 	[tegra_clk_pll_re_vco] = { .dt_id = TEGRA210_CLK_PLL_RE_VCO, .present = true },
2201 	[tegra_clk_pll_re_out] = { .dt_id = TEGRA210_CLK_PLL_RE_OUT, .present = true },
2202 	[tegra_clk_spdif_in_sync] = { .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC, .present = true },
2203 	[tegra_clk_i2s0_sync] = { .dt_id = TEGRA210_CLK_I2S0_SYNC, .present = true },
2204 	[tegra_clk_i2s1_sync] = { .dt_id = TEGRA210_CLK_I2S1_SYNC, .present = true },
2205 	[tegra_clk_i2s2_sync] = { .dt_id = TEGRA210_CLK_I2S2_SYNC, .present = true },
2206 	[tegra_clk_i2s3_sync] = { .dt_id = TEGRA210_CLK_I2S3_SYNC, .present = true },
2207 	[tegra_clk_i2s4_sync] = { .dt_id = TEGRA210_CLK_I2S4_SYNC, .present = true },
2208 	[tegra_clk_vimclk_sync] = { .dt_id = TEGRA210_CLK_VIMCLK_SYNC, .present = true },
2209 	[tegra_clk_audio0] = { .dt_id = TEGRA210_CLK_AUDIO0, .present = true },
2210 	[tegra_clk_audio1] = { .dt_id = TEGRA210_CLK_AUDIO1, .present = true },
2211 	[tegra_clk_audio2] = { .dt_id = TEGRA210_CLK_AUDIO2, .present = true },
2212 	[tegra_clk_audio3] = { .dt_id = TEGRA210_CLK_AUDIO3, .present = true },
2213 	[tegra_clk_audio4] = { .dt_id = TEGRA210_CLK_AUDIO4, .present = true },
2214 	[tegra_clk_spdif] = { .dt_id = TEGRA210_CLK_SPDIF, .present = true },
2215 	[tegra_clk_clk_out_1] = { .dt_id = TEGRA210_CLK_CLK_OUT_1, .present = true },
2216 	[tegra_clk_clk_out_2] = { .dt_id = TEGRA210_CLK_CLK_OUT_2, .present = true },
2217 	[tegra_clk_clk_out_3] = { .dt_id = TEGRA210_CLK_CLK_OUT_3, .present = true },
2218 	[tegra_clk_blink] = { .dt_id = TEGRA210_CLK_BLINK, .present = true },
2219 	[tegra_clk_xusb_gate] = { .dt_id = TEGRA210_CLK_XUSB_GATE, .present = true },
2220 	[tegra_clk_xusb_host_src_8] = { .dt_id = TEGRA210_CLK_XUSB_HOST_SRC, .present = true },
2221 	[tegra_clk_xusb_falcon_src_8] = { .dt_id = TEGRA210_CLK_XUSB_FALCON_SRC, .present = true },
2222 	[tegra_clk_xusb_fs_src] = { .dt_id = TEGRA210_CLK_XUSB_FS_SRC, .present = true },
2223 	[tegra_clk_xusb_ss_src_8] = { .dt_id = TEGRA210_CLK_XUSB_SS_SRC, .present = true },
2224 	[tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA210_CLK_XUSB_SS_DIV2, .present = true },
2225 	[tegra_clk_xusb_dev_src_8] = { .dt_id = TEGRA210_CLK_XUSB_DEV_SRC, .present = true },
2226 	[tegra_clk_xusb_dev] = { .dt_id = TEGRA210_CLK_XUSB_DEV, .present = true },
2227 	[tegra_clk_xusb_hs_src_4] = { .dt_id = TEGRA210_CLK_XUSB_HS_SRC, .present = true },
2228 	[tegra_clk_xusb_ssp_src] = { .dt_id = TEGRA210_CLK_XUSB_SSP_SRC, .present = true },
2229 	[tegra_clk_usb2_hsic_trk] = { .dt_id = TEGRA210_CLK_USB2_HSIC_TRK, .present = true },
2230 	[tegra_clk_hsic_trk] = { .dt_id = TEGRA210_CLK_HSIC_TRK, .present = true },
2231 	[tegra_clk_usb2_trk] = { .dt_id = TEGRA210_CLK_USB2_TRK, .present = true },
2232 	[tegra_clk_sclk] = { .dt_id = TEGRA210_CLK_SCLK, .present = true },
2233 	[tegra_clk_sclk_mux] = { .dt_id = TEGRA210_CLK_SCLK_MUX, .present = true },
2234 	[tegra_clk_hclk] = { .dt_id = TEGRA210_CLK_HCLK, .present = true },
2235 	[tegra_clk_pclk] = { .dt_id = TEGRA210_CLK_PCLK, .present = true },
2236 	[tegra_clk_cclk_g] = { .dt_id = TEGRA210_CLK_CCLK_G, .present = true },
2237 	[tegra_clk_cclk_lp] = { .dt_id = TEGRA210_CLK_CCLK_LP, .present = true },
2238 	[tegra_clk_dfll_ref] = { .dt_id = TEGRA210_CLK_DFLL_REF, .present = true },
2239 	[tegra_clk_dfll_soc] = { .dt_id = TEGRA210_CLK_DFLL_SOC, .present = true },
2240 	[tegra_clk_vi_sensor2_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR2, .present = true },
2241 	[tegra_clk_pll_p_out5] = { .dt_id = TEGRA210_CLK_PLL_P_OUT5, .present = true },
2242 	[tegra_clk_pll_c4] = { .dt_id = TEGRA210_CLK_PLL_C4, .present = true },
2243 	[tegra_clk_pll_dp] = { .dt_id = TEGRA210_CLK_PLL_DP, .present = true },
2244 	[tegra_clk_audio0_mux] = { .dt_id = TEGRA210_CLK_AUDIO0_MUX, .present = true },
2245 	[tegra_clk_audio1_mux] = { .dt_id = TEGRA210_CLK_AUDIO1_MUX, .present = true },
2246 	[tegra_clk_audio2_mux] = { .dt_id = TEGRA210_CLK_AUDIO2_MUX, .present = true },
2247 	[tegra_clk_audio3_mux] = { .dt_id = TEGRA210_CLK_AUDIO3_MUX, .present = true },
2248 	[tegra_clk_audio4_mux] = { .dt_id = TEGRA210_CLK_AUDIO4_MUX, .present = true },
2249 	[tegra_clk_spdif_mux] = { .dt_id = TEGRA210_CLK_SPDIF_MUX, .present = true },
2250 	[tegra_clk_clk_out_1_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_1_MUX, .present = true },
2251 	[tegra_clk_clk_out_2_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_2_MUX, .present = true },
2252 	[tegra_clk_clk_out_3_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_3_MUX, .present = true },
2253 	[tegra_clk_maud] = { .dt_id = TEGRA210_CLK_MAUD, .present = true },
2254 	[tegra_clk_mipibif] = { .dt_id = TEGRA210_CLK_MIPIBIF, .present = true },
2255 	[tegra_clk_qspi] = { .dt_id = TEGRA210_CLK_QSPI, .present = true },
2256 	[tegra_clk_sdmmc_legacy] = { .dt_id = TEGRA210_CLK_SDMMC_LEGACY, .present = true },
2257 	[tegra_clk_tsecb] = { .dt_id = TEGRA210_CLK_TSECB, .present = true },
2258 	[tegra_clk_uartape] = { .dt_id = TEGRA210_CLK_UARTAPE, .present = true },
2259 	[tegra_clk_vi_i2c] = { .dt_id = TEGRA210_CLK_VI_I2C, .present = true },
2260 	[tegra_clk_ape] = { .dt_id = TEGRA210_CLK_APE, .present = true },
2261 	[tegra_clk_dbgapb] = { .dt_id = TEGRA210_CLK_DBGAPB, .present = true },
2262 	[tegra_clk_nvdec] = { .dt_id = TEGRA210_CLK_NVDEC, .present = true },
2263 	[tegra_clk_nvenc] = { .dt_id = TEGRA210_CLK_NVENC, .present = true },
2264 	[tegra_clk_nvjpg] = { .dt_id = TEGRA210_CLK_NVJPG, .present = true },
2265 	[tegra_clk_pll_c4_out0] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT0, .present = true },
2266 	[tegra_clk_pll_c4_out1] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT1, .present = true },
2267 	[tegra_clk_pll_c4_out2] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT2, .present = true },
2268 	[tegra_clk_pll_c4_out3] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT3, .present = true },
2269 	[tegra_clk_apb2ape] = { .dt_id = TEGRA210_CLK_APB2APE, .present = true },
2270 };
2271 
2272 static struct tegra_devclk devclks[] __initdata = {
2273 	{ .con_id = "clk_m", .dt_id = TEGRA210_CLK_CLK_M },
2274 	{ .con_id = "pll_ref", .dt_id = TEGRA210_CLK_PLL_REF },
2275 	{ .con_id = "clk_32k", .dt_id = TEGRA210_CLK_CLK_32K },
2276 	{ .con_id = "clk_m_div2", .dt_id = TEGRA210_CLK_CLK_M_DIV2 },
2277 	{ .con_id = "clk_m_div4", .dt_id = TEGRA210_CLK_CLK_M_DIV4 },
2278 	{ .con_id = "pll_c", .dt_id = TEGRA210_CLK_PLL_C },
2279 	{ .con_id = "pll_c_out1", .dt_id = TEGRA210_CLK_PLL_C_OUT1 },
2280 	{ .con_id = "pll_c2", .dt_id = TEGRA210_CLK_PLL_C2 },
2281 	{ .con_id = "pll_c3", .dt_id = TEGRA210_CLK_PLL_C3 },
2282 	{ .con_id = "pll_p", .dt_id = TEGRA210_CLK_PLL_P },
2283 	{ .con_id = "pll_p_out1", .dt_id = TEGRA210_CLK_PLL_P_OUT1 },
2284 	{ .con_id = "pll_p_out2", .dt_id = TEGRA210_CLK_PLL_P_OUT2 },
2285 	{ .con_id = "pll_p_out3", .dt_id = TEGRA210_CLK_PLL_P_OUT3 },
2286 	{ .con_id = "pll_p_out4", .dt_id = TEGRA210_CLK_PLL_P_OUT4 },
2287 	{ .con_id = "pll_m", .dt_id = TEGRA210_CLK_PLL_M },
2288 	{ .con_id = "pll_m_out1", .dt_id = TEGRA210_CLK_PLL_M_OUT1 },
2289 	{ .con_id = "pll_x", .dt_id = TEGRA210_CLK_PLL_X },
2290 	{ .con_id = "pll_x_out0", .dt_id = TEGRA210_CLK_PLL_X_OUT0 },
2291 	{ .con_id = "pll_u", .dt_id = TEGRA210_CLK_PLL_U },
2292 	{ .con_id = "pll_u_out", .dt_id = TEGRA210_CLK_PLL_U_OUT },
2293 	{ .con_id = "pll_u_out1", .dt_id = TEGRA210_CLK_PLL_U_OUT1 },
2294 	{ .con_id = "pll_u_out2", .dt_id = TEGRA210_CLK_PLL_U_OUT2 },
2295 	{ .con_id = "pll_u_480M", .dt_id = TEGRA210_CLK_PLL_U_480M },
2296 	{ .con_id = "pll_u_60M", .dt_id = TEGRA210_CLK_PLL_U_60M },
2297 	{ .con_id = "pll_u_48M", .dt_id = TEGRA210_CLK_PLL_U_48M },
2298 	{ .con_id = "pll_d", .dt_id = TEGRA210_CLK_PLL_D },
2299 	{ .con_id = "pll_d_out0", .dt_id = TEGRA210_CLK_PLL_D_OUT0 },
2300 	{ .con_id = "pll_d2", .dt_id = TEGRA210_CLK_PLL_D2 },
2301 	{ .con_id = "pll_d2_out0", .dt_id = TEGRA210_CLK_PLL_D2_OUT0 },
2302 	{ .con_id = "pll_a", .dt_id = TEGRA210_CLK_PLL_A },
2303 	{ .con_id = "pll_a_out0", .dt_id = TEGRA210_CLK_PLL_A_OUT0 },
2304 	{ .con_id = "pll_re_vco", .dt_id = TEGRA210_CLK_PLL_RE_VCO },
2305 	{ .con_id = "pll_re_out", .dt_id = TEGRA210_CLK_PLL_RE_OUT },
2306 	{ .con_id = "spdif_in_sync", .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC },
2307 	{ .con_id = "i2s0_sync", .dt_id = TEGRA210_CLK_I2S0_SYNC },
2308 	{ .con_id = "i2s1_sync", .dt_id = TEGRA210_CLK_I2S1_SYNC },
2309 	{ .con_id = "i2s2_sync", .dt_id = TEGRA210_CLK_I2S2_SYNC },
2310 	{ .con_id = "i2s3_sync", .dt_id = TEGRA210_CLK_I2S3_SYNC },
2311 	{ .con_id = "i2s4_sync", .dt_id = TEGRA210_CLK_I2S4_SYNC },
2312 	{ .con_id = "vimclk_sync", .dt_id = TEGRA210_CLK_VIMCLK_SYNC },
2313 	{ .con_id = "audio0", .dt_id = TEGRA210_CLK_AUDIO0 },
2314 	{ .con_id = "audio1", .dt_id = TEGRA210_CLK_AUDIO1 },
2315 	{ .con_id = "audio2", .dt_id = TEGRA210_CLK_AUDIO2 },
2316 	{ .con_id = "audio3", .dt_id = TEGRA210_CLK_AUDIO3 },
2317 	{ .con_id = "audio4", .dt_id = TEGRA210_CLK_AUDIO4 },
2318 	{ .con_id = "spdif", .dt_id = TEGRA210_CLK_SPDIF },
2319 	{ .con_id = "spdif_2x", .dt_id = TEGRA210_CLK_SPDIF_2X },
2320 	{ .con_id = "extern1", .dev_id = "clk_out_1", .dt_id = TEGRA210_CLK_EXTERN1 },
2321 	{ .con_id = "extern2", .dev_id = "clk_out_2", .dt_id = TEGRA210_CLK_EXTERN2 },
2322 	{ .con_id = "extern3", .dev_id = "clk_out_3", .dt_id = TEGRA210_CLK_EXTERN3 },
2323 	{ .con_id = "blink", .dt_id = TEGRA210_CLK_BLINK },
2324 	{ .con_id = "cclk_g", .dt_id = TEGRA210_CLK_CCLK_G },
2325 	{ .con_id = "cclk_lp", .dt_id = TEGRA210_CLK_CCLK_LP },
2326 	{ .con_id = "sclk", .dt_id = TEGRA210_CLK_SCLK },
2327 	{ .con_id = "hclk", .dt_id = TEGRA210_CLK_HCLK },
2328 	{ .con_id = "pclk", .dt_id = TEGRA210_CLK_PCLK },
2329 	{ .con_id = "fuse", .dt_id = TEGRA210_CLK_FUSE },
2330 	{ .dev_id = "rtc-tegra", .dt_id = TEGRA210_CLK_RTC },
2331 	{ .dev_id = "timer", .dt_id = TEGRA210_CLK_TIMER },
2332 	{ .con_id = "pll_c4_out0", .dt_id = TEGRA210_CLK_PLL_C4_OUT0 },
2333 	{ .con_id = "pll_c4_out1", .dt_id = TEGRA210_CLK_PLL_C4_OUT1 },
2334 	{ .con_id = "pll_c4_out2", .dt_id = TEGRA210_CLK_PLL_C4_OUT2 },
2335 	{ .con_id = "pll_c4_out3", .dt_id = TEGRA210_CLK_PLL_C4_OUT3 },
2336 	{ .con_id = "dpaux", .dt_id = TEGRA210_CLK_DPAUX },
2337 	{ .con_id = "sor0", .dt_id = TEGRA210_CLK_SOR0 },
2338 };
2339 
2340 static struct tegra_audio_clk_info tegra210_audio_plls[] = {
2341 	{ "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_ref" },
2342 	{ "pll_a1", &pll_a1_params, tegra_clk_pll_a1, "pll_ref" },
2343 };
2344 
2345 static struct clk **clks;
2346 
2347 static void tegra210_utmi_param_configure(void __iomem *clk_base)
2348 {
2349 	u32 reg;
2350 	int i;
2351 
2352 	for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
2353 		if (osc_freq == utmi_parameters[i].osc_frequency)
2354 			break;
2355 	}
2356 
2357 	if (i >= ARRAY_SIZE(utmi_parameters)) {
2358 		pr_err("%s: Unexpected oscillator freq %lu\n", __func__,
2359 		       osc_freq);
2360 		return;
2361 	}
2362 
2363 	reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0);
2364 	reg |= PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE |
2365 	       PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT |
2366 	       PLLU_HW_PWRDN_CFG0_USE_LOCKDET;
2367 	reg &= ~(PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL |
2368 		  PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL);
2369 	writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0);
2370 
2371 	reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0);
2372 	reg |= PLLU_HW_PWRDN_CFG0_SEQ_ENABLE;
2373 	writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0);
2374 	udelay(1);
2375 
2376 	reg = readl_relaxed(clk_base + PLLU_BASE);
2377 	reg &= ~PLLU_BASE_CLKENABLE_USB;
2378 	writel_relaxed(reg, clk_base + PLLU_BASE);
2379 
2380 	reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
2381 	reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
2382 	writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
2383 
2384 	udelay(10);
2385 
2386 	reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
2387 
2388 	/* Program UTMIP PLL stable and active counts */
2389 	/* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */
2390 	reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
2391 	reg |= UTMIP_PLL_CFG2_STABLE_COUNT(utmi_parameters[i].stable_count);
2392 
2393 	reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
2394 
2395 	reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(utmi_parameters[i].
2396 					    active_delay_count);
2397 	writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
2398 
2399 	/* Program UTMIP PLL delay and oscillator frequency counts */
2400 	reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
2401 	reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
2402 
2403 	reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(utmi_parameters[i].
2404 					    enable_delay_count);
2405 
2406 	reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
2407 	reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(utmi_parameters[i].
2408 					   xtal_freq_count);
2409 
2410 	reg |= UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
2411 	writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
2412 
2413 	/* Remove power downs from UTMIP PLL control bits */
2414 	reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
2415 	reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
2416 	reg |= UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
2417 	writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
2418 	udelay(1);
2419 
2420 	/* Enable samplers for SNPS, XUSB_HOST, XUSB_DEV */
2421 	reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
2422 	reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP;
2423 	reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP;
2424 	reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP;
2425 	reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
2426 	reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
2427 	reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN;
2428 	writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
2429 
2430 	/* Setup HW control of UTMIPLL */
2431 	reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
2432 	reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
2433 	reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
2434 	writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
2435 
2436 	reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
2437 	reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET;
2438 	reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL;
2439 	writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
2440 
2441 	udelay(1);
2442 
2443 	reg = readl_relaxed(clk_base + XUSB_PLL_CFG0);
2444 	reg &= ~XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY;
2445 	writel_relaxed(reg, clk_base + XUSB_PLL_CFG0);
2446 
2447 	udelay(1);
2448 
2449 	/* Enable HW control UTMIPLL */
2450 	reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0);
2451 	reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE;
2452 	writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0);
2453 }
2454 
2455 static __init void tegra210_periph_clk_init(void __iomem *clk_base,
2456 					    void __iomem *pmc_base)
2457 {
2458 	struct clk *clk;
2459 
2460 	/* xusb_ss_div2 */
2461 	clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0,
2462 					1, 2);
2463 	clks[TEGRA210_CLK_XUSB_SS_DIV2] = clk;
2464 
2465 	/* pll_d_dsi_out */
2466 	clk = clk_register_gate(NULL, "pll_d_dsi_out", "pll_d_out0", 0,
2467 				clk_base + PLLD_MISC0, 21, 0, &pll_d_lock);
2468 	clks[TEGRA210_CLK_PLL_D_DSI_OUT] = clk;
2469 
2470 	/* dsia */
2471 	clk = tegra_clk_register_periph_gate("dsia", "pll_d_dsi_out", 0,
2472 					     clk_base, 0, 48,
2473 					     periph_clk_enb_refcnt);
2474 	clks[TEGRA210_CLK_DSIA] = clk;
2475 
2476 	/* dsib */
2477 	clk = tegra_clk_register_periph_gate("dsib", "pll_d_dsi_out", 0,
2478 					     clk_base, 0, 82,
2479 					     periph_clk_enb_refcnt);
2480 	clks[TEGRA210_CLK_DSIB] = clk;
2481 
2482 	/* emc mux */
2483 	clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
2484 			       ARRAY_SIZE(mux_pllmcp_clkm), 0,
2485 			       clk_base + CLK_SOURCE_EMC,
2486 			       29, 3, 0, &emc_lock);
2487 
2488 	clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
2489 				    &emc_lock);
2490 	clks[TEGRA210_CLK_MC] = clk;
2491 
2492 	/* cml0 */
2493 	clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX,
2494 				0, 0, &pll_e_lock);
2495 	clk_register_clkdev(clk, "cml0", NULL);
2496 	clks[TEGRA210_CLK_CML0] = clk;
2497 
2498 	/* cml1 */
2499 	clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX,
2500 				1, 0, &pll_e_lock);
2501 	clk_register_clkdev(clk, "cml1", NULL);
2502 	clks[TEGRA210_CLK_CML1] = clk;
2503 
2504 	tegra_periph_clk_init(clk_base, pmc_base, tegra210_clks, &pll_p_params);
2505 }
2506 
2507 static void __init tegra210_pll_init(void __iomem *clk_base,
2508 				     void __iomem *pmc)
2509 {
2510 	u32 val;
2511 	struct clk *clk;
2512 
2513 	/* PLLC */
2514 	clk = tegra_clk_register_pllxc_tegra210("pll_c", "pll_ref", clk_base,
2515 			pmc, 0, &pll_c_params, NULL);
2516 	if (!WARN_ON(IS_ERR(clk)))
2517 		clk_register_clkdev(clk, "pll_c", NULL);
2518 	clks[TEGRA210_CLK_PLL_C] = clk;
2519 
2520 	/* PLLC_OUT1 */
2521 	clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
2522 			clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
2523 			8, 8, 1, NULL);
2524 	clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
2525 				clk_base + PLLC_OUT, 1, 0,
2526 				CLK_SET_RATE_PARENT, 0, NULL);
2527 	clk_register_clkdev(clk, "pll_c_out1", NULL);
2528 	clks[TEGRA210_CLK_PLL_C_OUT1] = clk;
2529 
2530 	/* PLLC_UD */
2531 	clk = clk_register_fixed_factor(NULL, "pll_c_ud", "pll_c",
2532 					CLK_SET_RATE_PARENT, 1, 1);
2533 	clk_register_clkdev(clk, "pll_c_ud", NULL);
2534 	clks[TEGRA210_CLK_PLL_C_UD] = clk;
2535 
2536 	/* PLLC2 */
2537 	clk = tegra_clk_register_pllc_tegra210("pll_c2", "pll_ref", clk_base,
2538 			     pmc, 0, &pll_c2_params, NULL);
2539 	clk_register_clkdev(clk, "pll_c2", NULL);
2540 	clks[TEGRA210_CLK_PLL_C2] = clk;
2541 
2542 	/* PLLC3 */
2543 	clk = tegra_clk_register_pllc_tegra210("pll_c3", "pll_ref", clk_base,
2544 			     pmc, 0, &pll_c3_params, NULL);
2545 	clk_register_clkdev(clk, "pll_c3", NULL);
2546 	clks[TEGRA210_CLK_PLL_C3] = clk;
2547 
2548 	/* PLLM */
2549 	clk = tegra_clk_register_pllm("pll_m", "osc", clk_base, pmc,
2550 			     CLK_SET_RATE_GATE, &pll_m_params, NULL);
2551 	clk_register_clkdev(clk, "pll_m", NULL);
2552 	clks[TEGRA210_CLK_PLL_M] = clk;
2553 
2554 	/* PLLMB */
2555 	clk = tegra_clk_register_pllmb("pll_mb", "osc", clk_base, pmc,
2556 			     CLK_SET_RATE_GATE, &pll_mb_params, NULL);
2557 	clk_register_clkdev(clk, "pll_mb", NULL);
2558 	clks[TEGRA210_CLK_PLL_MB] = clk;
2559 
2560 	clk_register_clkdev(clk, "pll_m_out1", NULL);
2561 	clks[TEGRA210_CLK_PLL_M_OUT1] = clk;
2562 
2563 	/* PLLM_UD */
2564 	clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m",
2565 					CLK_SET_RATE_PARENT, 1, 1);
2566 	clk_register_clkdev(clk, "pll_m_ud", NULL);
2567 	clks[TEGRA210_CLK_PLL_M_UD] = clk;
2568 
2569 	/* PLLU_VCO */
2570 	val = readl(clk_base + pll_u_vco_params.base_reg);
2571 	val &= ~PLLU_BASE_OVERRIDE; /* disable PLLU_OVERRIDE */
2572 	writel(val, clk_base + pll_u_vco_params.base_reg);
2573 
2574 	clk = tegra_clk_register_pllre("pll_u_vco", "pll_ref", clk_base, pmc,
2575 			    0, &pll_u_vco_params, &pll_u_lock, pll_ref_freq);
2576 	clk_register_clkdev(clk, "pll_u_vco", NULL);
2577 	clks[TEGRA210_CLK_PLL_U] = clk;
2578 
2579 	/* PLLU_OUT */
2580 	clk = clk_register_divider_table(NULL, "pll_u_out", "pll_u_vco", 0,
2581 					 clk_base + PLLU_BASE, 16, 4, 0,
2582 					 pll_vco_post_div_table, NULL);
2583 	clk_register_clkdev(clk, "pll_u_out", NULL);
2584 	clks[TEGRA210_CLK_PLL_U_OUT] = clk;
2585 
2586 	/* PLLU_OUT1 */
2587 	clk = tegra_clk_register_divider("pll_u_out1_div", "pll_u_out",
2588 				clk_base + PLLU_OUTA, 0,
2589 				TEGRA_DIVIDER_ROUND_UP,
2590 				8, 8, 1, &pll_u_lock);
2591 	clk = tegra_clk_register_pll_out("pll_u_out1", "pll_u_out1_div",
2592 				clk_base + PLLU_OUTA, 1, 0,
2593 				CLK_SET_RATE_PARENT, 0, &pll_u_lock);
2594 	clk_register_clkdev(clk, "pll_u_out1", NULL);
2595 	clks[TEGRA210_CLK_PLL_U_OUT1] = clk;
2596 
2597 	/* PLLU_OUT2 */
2598 	clk = tegra_clk_register_divider("pll_u_out2_div", "pll_u_out",
2599 				clk_base + PLLU_OUTA, 0,
2600 				TEGRA_DIVIDER_ROUND_UP,
2601 				24, 8, 1, &pll_u_lock);
2602 	clk = tegra_clk_register_pll_out("pll_u_out2", "pll_u_out2_div",
2603 				clk_base + PLLU_OUTA, 17, 16,
2604 				CLK_SET_RATE_PARENT, 0, &pll_u_lock);
2605 	clk_register_clkdev(clk, "pll_u_out2", NULL);
2606 	clks[TEGRA210_CLK_PLL_U_OUT2] = clk;
2607 
2608 	tegra210_utmi_param_configure(clk_base);
2609 
2610 	/* PLLU_480M */
2611 	clk = clk_register_gate(NULL, "pll_u_480M", "pll_u_vco",
2612 				CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
2613 				22, 0, &pll_u_lock);
2614 	clk_register_clkdev(clk, "pll_u_480M", NULL);
2615 	clks[TEGRA210_CLK_PLL_U_480M] = clk;
2616 
2617 	/* PLLU_60M */
2618 	clk = clk_register_gate(NULL, "pll_u_60M", "pll_u_out2",
2619 				CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
2620 				23, 0, NULL);
2621 	clk_register_clkdev(clk, "pll_u_60M", NULL);
2622 	clks[TEGRA210_CLK_PLL_U_60M] = clk;
2623 
2624 	/* PLLU_48M */
2625 	clk = clk_register_gate(NULL, "pll_u_48M", "pll_u_out1",
2626 				CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
2627 				25, 0, NULL);
2628 	clk_register_clkdev(clk, "pll_u_48M", NULL);
2629 	clks[TEGRA210_CLK_PLL_U_48M] = clk;
2630 
2631 	/* PLLD */
2632 	clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0,
2633 			    &pll_d_params, &pll_d_lock);
2634 	clk_register_clkdev(clk, "pll_d", NULL);
2635 	clks[TEGRA210_CLK_PLL_D] = clk;
2636 
2637 	/* PLLD_OUT0 */
2638 	clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
2639 					CLK_SET_RATE_PARENT, 1, 2);
2640 	clk_register_clkdev(clk, "pll_d_out0", NULL);
2641 	clks[TEGRA210_CLK_PLL_D_OUT0] = clk;
2642 
2643 	/* PLLRE */
2644 	clk = tegra_clk_register_pllre("pll_re_vco", "pll_ref", clk_base, pmc,
2645 			     0, &pll_re_vco_params, &pll_re_lock, pll_ref_freq);
2646 	clk_register_clkdev(clk, "pll_re_vco", NULL);
2647 	clks[TEGRA210_CLK_PLL_RE_VCO] = clk;
2648 
2649 	clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0,
2650 					 clk_base + PLLRE_BASE, 16, 5, 0,
2651 					 pll_vco_post_div_table, &pll_re_lock);
2652 	clk_register_clkdev(clk, "pll_re_out", NULL);
2653 	clks[TEGRA210_CLK_PLL_RE_OUT] = clk;
2654 
2655 	/* PLLE */
2656 	clk = tegra_clk_register_plle_tegra210("pll_e", "pll_ref",
2657 				      clk_base, 0, &pll_e_params, NULL);
2658 	clk_register_clkdev(clk, "pll_e", NULL);
2659 	clks[TEGRA210_CLK_PLL_E] = clk;
2660 
2661 	/* PLLC4 */
2662 	clk = tegra_clk_register_pllre("pll_c4_vco", "pll_ref", clk_base, pmc,
2663 			     0, &pll_c4_vco_params, NULL, pll_ref_freq);
2664 	clk_register_clkdev(clk, "pll_c4_vco", NULL);
2665 	clks[TEGRA210_CLK_PLL_C4] = clk;
2666 
2667 	/* PLLC4_OUT0 */
2668 	clk = clk_register_divider_table(NULL, "pll_c4_out0", "pll_c4_vco", 0,
2669 					 clk_base + PLLC4_BASE, 19, 4, 0,
2670 					 pll_vco_post_div_table, NULL);
2671 	clk_register_clkdev(clk, "pll_c4_out0", NULL);
2672 	clks[TEGRA210_CLK_PLL_C4_OUT0] = clk;
2673 
2674 	/* PLLC4_OUT1 */
2675 	clk = clk_register_fixed_factor(NULL, "pll_c4_out1", "pll_c4_vco",
2676 					CLK_SET_RATE_PARENT, 1, 3);
2677 	clk_register_clkdev(clk, "pll_c4_out1", NULL);
2678 	clks[TEGRA210_CLK_PLL_C4_OUT1] = clk;
2679 
2680 	/* PLLC4_OUT2 */
2681 	clk = clk_register_fixed_factor(NULL, "pll_c4_out2", "pll_c4_vco",
2682 					CLK_SET_RATE_PARENT, 1, 5);
2683 	clk_register_clkdev(clk, "pll_c4_out2", NULL);
2684 	clks[TEGRA210_CLK_PLL_C4_OUT2] = clk;
2685 
2686 	/* PLLC4_OUT3 */
2687 	clk = tegra_clk_register_divider("pll_c4_out3_div", "pll_c4_out0",
2688 			clk_base + PLLC4_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
2689 			8, 8, 1, NULL);
2690 	clk = tegra_clk_register_pll_out("pll_c4_out3", "pll_c4_out3_div",
2691 				clk_base + PLLC4_OUT, 1, 0,
2692 				CLK_SET_RATE_PARENT, 0, NULL);
2693 	clk_register_clkdev(clk, "pll_c4_out3", NULL);
2694 	clks[TEGRA210_CLK_PLL_C4_OUT3] = clk;
2695 
2696 	/* PLLDP */
2697 	clk = tegra_clk_register_pllss_tegra210("pll_dp", "pll_ref", clk_base,
2698 					0, &pll_dp_params, NULL);
2699 	clk_register_clkdev(clk, "pll_dp", NULL);
2700 	clks[TEGRA210_CLK_PLL_DP] = clk;
2701 
2702 	/* PLLD2 */
2703 	clk = tegra_clk_register_pllss_tegra210("pll_d2", "pll_ref", clk_base,
2704 					0, &pll_d2_params, NULL);
2705 	clk_register_clkdev(clk, "pll_d2", NULL);
2706 	clks[TEGRA210_CLK_PLL_D2] = clk;
2707 
2708 	/* PLLD2_OUT0 */
2709 	clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
2710 					CLK_SET_RATE_PARENT, 1, 1);
2711 	clk_register_clkdev(clk, "pll_d2_out0", NULL);
2712 	clks[TEGRA210_CLK_PLL_D2_OUT0] = clk;
2713 
2714 	/* PLLP_OUT2 */
2715 	clk = clk_register_fixed_factor(NULL, "pll_p_out2", "pll_p",
2716 					CLK_SET_RATE_PARENT, 1, 2);
2717 	clk_register_clkdev(clk, "pll_p_out2", NULL);
2718 	clks[TEGRA210_CLK_PLL_P_OUT2] = clk;
2719 
2720 }
2721 
2722 /* Tegra210 CPU clock and reset control functions */
2723 static void tegra210_wait_cpu_in_reset(u32 cpu)
2724 {
2725 	unsigned int reg;
2726 
2727 	do {
2728 		reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
2729 		cpu_relax();
2730 	} while (!(reg & (1 << cpu)));  /* check CPU been reset or not */
2731 }
2732 
2733 static void tegra210_disable_cpu_clock(u32 cpu)
2734 {
2735 	/* flow controller would take care in the power sequence. */
2736 }
2737 
2738 #ifdef CONFIG_PM_SLEEP
2739 static void tegra210_cpu_clock_suspend(void)
2740 {
2741 	/* switch coresite to clk_m, save off original source */
2742 	tegra210_cpu_clk_sctx.clk_csite_src =
2743 				readl(clk_base + CLK_SOURCE_CSITE);
2744 	writel(3 << 30, clk_base + CLK_SOURCE_CSITE);
2745 }
2746 
2747 static void tegra210_cpu_clock_resume(void)
2748 {
2749 	writel(tegra210_cpu_clk_sctx.clk_csite_src,
2750 				clk_base + CLK_SOURCE_CSITE);
2751 }
2752 #endif
2753 
2754 static struct tegra_cpu_car_ops tegra210_cpu_car_ops = {
2755 	.wait_for_reset	= tegra210_wait_cpu_in_reset,
2756 	.disable_clock	= tegra210_disable_cpu_clock,
2757 #ifdef CONFIG_PM_SLEEP
2758 	.suspend	= tegra210_cpu_clock_suspend,
2759 	.resume		= tegra210_cpu_clock_resume,
2760 #endif
2761 };
2762 
2763 static const struct of_device_id pmc_match[] __initconst = {
2764 	{ .compatible = "nvidia,tegra210-pmc" },
2765 	{ },
2766 };
2767 
2768 static struct tegra_clk_init_table init_table[] __initdata = {
2769 	{ TEGRA210_CLK_UARTA, TEGRA210_CLK_PLL_P, 408000000, 0 },
2770 	{ TEGRA210_CLK_UARTB, TEGRA210_CLK_PLL_P, 408000000, 0 },
2771 	{ TEGRA210_CLK_UARTC, TEGRA210_CLK_PLL_P, 408000000, 0 },
2772 	{ TEGRA210_CLK_UARTD, TEGRA210_CLK_PLL_P, 408000000, 0 },
2773 	{ TEGRA210_CLK_PLL_A, TEGRA210_CLK_CLK_MAX, 564480000, 1 },
2774 	{ TEGRA210_CLK_PLL_A_OUT0, TEGRA210_CLK_CLK_MAX, 11289600, 1 },
2775 	{ TEGRA210_CLK_EXTERN1, TEGRA210_CLK_PLL_A_OUT0, 0, 1 },
2776 	{ TEGRA210_CLK_CLK_OUT_1_MUX, TEGRA210_CLK_EXTERN1, 0, 1 },
2777 	{ TEGRA210_CLK_CLK_OUT_1, TEGRA210_CLK_CLK_MAX, 0, 1 },
2778 	{ TEGRA210_CLK_I2S0, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
2779 	{ TEGRA210_CLK_I2S1, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
2780 	{ TEGRA210_CLK_I2S2, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
2781 	{ TEGRA210_CLK_I2S3, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
2782 	{ TEGRA210_CLK_I2S4, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 },
2783 	{ TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_P, 136000000, 1 },
2784 	{ TEGRA210_CLK_SCLK_MUX, TEGRA210_CLK_PLL_P, 0, 1 },
2785 	{ TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 1 },
2786 	{ TEGRA210_CLK_DFLL_SOC, TEGRA210_CLK_PLL_P, 51000000, 1 },
2787 	{ TEGRA210_CLK_DFLL_REF, TEGRA210_CLK_PLL_P, 51000000, 1 },
2788 	{ TEGRA210_CLK_SBC4, TEGRA210_CLK_PLL_P, 12000000, 1 },
2789 	{ TEGRA210_CLK_PLL_RE_VCO, TEGRA210_CLK_CLK_MAX, 672000000, 1 },
2790 	{ TEGRA210_CLK_XUSB_GATE, TEGRA210_CLK_CLK_MAX, 0, 1 },
2791 	{ TEGRA210_CLK_XUSB_SS_SRC, TEGRA210_CLK_PLL_U_480M, 120000000, 0 },
2792 	{ TEGRA210_CLK_XUSB_FS_SRC, TEGRA210_CLK_PLL_U_48M, 48000000, 0 },
2793 	{ TEGRA210_CLK_XUSB_HS_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 },
2794 	{ TEGRA210_CLK_XUSB_SSP_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 },
2795 	{ TEGRA210_CLK_XUSB_FALCON_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 204000000, 0 },
2796 	{ TEGRA210_CLK_XUSB_HOST_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 },
2797 	{ TEGRA210_CLK_XUSB_DEV_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 },
2798 	{ TEGRA210_CLK_SATA, TEGRA210_CLK_PLL_P, 104000000, 0 },
2799 	{ TEGRA210_CLK_SATA_OOB, TEGRA210_CLK_PLL_P, 204000000, 0 },
2800 	{ TEGRA210_CLK_EMC, TEGRA210_CLK_CLK_MAX, 0, 1 },
2801 	{ TEGRA210_CLK_MSELECT, TEGRA210_CLK_CLK_MAX, 0, 1 },
2802 	{ TEGRA210_CLK_CSITE, TEGRA210_CLK_CLK_MAX, 0, 1 },
2803 	{ TEGRA210_CLK_TSENSOR, TEGRA210_CLK_CLK_M, 400000, 0 },
2804 	{ TEGRA210_CLK_I2C1, TEGRA210_CLK_PLL_P, 0, 0 },
2805 	{ TEGRA210_CLK_I2C2, TEGRA210_CLK_PLL_P, 0, 0 },
2806 	{ TEGRA210_CLK_I2C3, TEGRA210_CLK_PLL_P, 0, 0 },
2807 	{ TEGRA210_CLK_I2C4, TEGRA210_CLK_PLL_P, 0, 0 },
2808 	{ TEGRA210_CLK_I2C5, TEGRA210_CLK_PLL_P, 0, 0 },
2809 	{ TEGRA210_CLK_I2C6, TEGRA210_CLK_PLL_P, 0, 0 },
2810 	{ TEGRA210_CLK_PLL_DP, TEGRA210_CLK_CLK_MAX, 270000000, 0 },
2811 	{ TEGRA210_CLK_SOC_THERM, TEGRA210_CLK_PLL_P, 51000000, 0 },
2812 	{ TEGRA210_CLK_CCLK_G, TEGRA210_CLK_CLK_MAX, 0, 1 },
2813 	/* This MUST be the last entry. */
2814 	{ TEGRA210_CLK_CLK_MAX, TEGRA210_CLK_CLK_MAX, 0, 0 },
2815 };
2816 
2817 /**
2818  * tegra210_clock_apply_init_table - initialize clocks on Tegra210 SoCs
2819  *
2820  * Program an initial clock rate and enable or disable clocks needed
2821  * by the rest of the kernel, for Tegra210 SoCs.  It is intended to be
2822  * called by assigning a pointer to it to tegra_clk_apply_init_table -
2823  * this will be called as an arch_initcall.  No return value.
2824  */
2825 static void __init tegra210_clock_apply_init_table(void)
2826 {
2827 	tegra_init_from_table(init_table, clks, TEGRA210_CLK_CLK_MAX);
2828 }
2829 
2830 /**
2831  * tegra210_clock_init - Tegra210-specific clock initialization
2832  * @np: struct device_node * of the DT node for the SoC CAR IP block
2833  *
2834  * Register most SoC clocks for the Tegra210 system-on-chip.  Intended
2835  * to be called by the OF init code when a DT node with the
2836  * "nvidia,tegra210-car" string is encountered, and declared with
2837  * CLK_OF_DECLARE.  No return value.
2838  */
2839 static void __init tegra210_clock_init(struct device_node *np)
2840 {
2841 	struct device_node *node;
2842 	u32 value, clk_m_div;
2843 
2844 	clk_base = of_iomap(np, 0);
2845 	if (!clk_base) {
2846 		pr_err("ioremap tegra210 CAR failed\n");
2847 		return;
2848 	}
2849 
2850 	node = of_find_matching_node(NULL, pmc_match);
2851 	if (!node) {
2852 		pr_err("Failed to find pmc node\n");
2853 		WARN_ON(1);
2854 		return;
2855 	}
2856 
2857 	pmc_base = of_iomap(node, 0);
2858 	if (!pmc_base) {
2859 		pr_err("Can't map pmc registers\n");
2860 		WARN_ON(1);
2861 		return;
2862 	}
2863 
2864 	clks = tegra_clk_init(clk_base, TEGRA210_CLK_CLK_MAX,
2865 			      TEGRA210_CAR_BANK_COUNT);
2866 	if (!clks)
2867 		return;
2868 
2869 	value = clk_readl(clk_base + SPARE_REG0) >> CLK_M_DIVISOR_SHIFT;
2870 	clk_m_div = (value & CLK_M_DIVISOR_MASK) + 1;
2871 
2872 	if (tegra_osc_clk_init(clk_base, tegra210_clks, tegra210_input_freq,
2873 			       ARRAY_SIZE(tegra210_input_freq), clk_m_div,
2874 			       &osc_freq, &pll_ref_freq) < 0)
2875 		return;
2876 
2877 	tegra_fixed_clk_init(tegra210_clks);
2878 	tegra210_pll_init(clk_base, pmc_base);
2879 	tegra210_periph_clk_init(clk_base, pmc_base);
2880 	tegra_audio_clk_init(clk_base, pmc_base, tegra210_clks,
2881 			     tegra210_audio_plls,
2882 			     ARRAY_SIZE(tegra210_audio_plls));
2883 	tegra_pmc_clk_init(pmc_base, tegra210_clks);
2884 
2885 	/* For Tegra210, PLLD is the only source for DSIA & DSIB */
2886 	value = clk_readl(clk_base + PLLD_BASE);
2887 	value &= ~BIT(25);
2888 	clk_writel(value, clk_base + PLLD_BASE);
2889 
2890 	tegra_clk_apply_init_table = tegra210_clock_apply_init_table;
2891 
2892 	tegra_super_clk_gen5_init(clk_base, pmc_base, tegra210_clks,
2893 				  &pll_x_params);
2894 	tegra_add_of_provider(np);
2895 	tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
2896 
2897 	tegra_cpu_car_ops = &tegra210_cpu_car_ops;
2898 }
2899 CLK_OF_DECLARE(tegra210, "nvidia,tegra210-car", tegra210_clock_init);
2900