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