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