2 * arch/arm/mach-tegra/tegra21_clocks.c
4 * Copyright (C) 2013-2015 NVIDIA Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/list.h>
24 #include <linux/spinlock.h>
25 #include <linux/err.h>
26 #include <linux/clk.h>
27 #include <linux/syscore_ops.h>
28 #include <linux/platform_device.h>
29 #include <linux/tegra_soctherm.h>
30 #include <soc/tegra/tegra_bpmp.h>
31 #include <dt-bindings/clk/tegra210-clk.h>
33 #include <asm/clkdev.h>
34 #include <asm/arch_timer.h>
37 #include <mach/hardware.h>
38 #include <mach/tegra_emc.h>
42 #include <linux/platform/tegra/clock.h>
43 #include "tegra_clocks_ops.h"
44 #include <linux/platform/tegra/dvfs.h>
48 #include <linux/platform/tegra/tegra_cl_dvfs.h>
53 #define RST_DEVICES_L 0x004
54 #define RST_DEVICES_H 0x008
55 #define RST_DEVICES_U 0x00C
56 #define RST_DEVICES_V 0x358
57 #define RST_DEVICES_W 0x35C
58 #define RST_DEVICES_X 0x28C
59 #define RST_DEVICES_Y 0x2A4
60 #define RST_DEVICES_SET_L 0x300
61 #define RST_DEVICES_CLR_L 0x304
62 #define RST_DEVICES_SET_V 0x430
63 #define RST_DEVICES_CLR_V 0x434
64 #define RST_DEVICES_SET_X 0x290
65 #define RST_DEVICES_CLR_X 0x294
66 #define RST_DEVICES_SET_Y 0x2A8
67 #define RST_DEVICES_CLR_Y 0x2AC
68 #define RST_DEVICES_NUM 7
70 #define CLK_OUT_ENB_L 0x010
71 #define CLK_OUT_ENB_H 0x014
72 #define CLK_OUT_ENB_U 0x018
73 #define CLK_OUT_ENB_V 0x360
74 #define CLK_OUT_ENB_W 0x364
75 #define CLK_OUT_ENB_X 0x280
76 #define CLK_OUT_ENB_Y 0x298
77 #define CLK_OUT_ENB_SET_L 0x320
78 #define CLK_OUT_ENB_CLR_L 0x324
79 #define CLK_OUT_ENB_SET_V 0x440
80 #define CLK_OUT_ENB_CLR_V 0x444
81 #define CLK_OUT_ENB_SET_X 0x284
82 #define CLK_OUT_ENB_CLR_X 0x288
83 #define CLK_OUT_ENB_SET_Y 0x29C
84 #define CLK_OUT_ENB_CLR_Y 0x2A0
85 #define CLK_OUT_ENB_NUM 7
87 #define CLK_OUT_ENB_L_RESET_MASK 0xdcd7dff9
88 #define CLK_OUT_ENB_H_RESET_MASK 0x87d1f3e7
89 #define CLK_OUT_ENB_U_RESET_MASK 0xf3fed3fa
90 #define CLK_OUT_ENB_V_RESET_MASK 0xffc18cfb
91 #define CLK_OUT_ENB_W_RESET_MASK 0x793fb7ff
92 #define CLK_OUT_ENB_X_RESET_MASK 0x3fe66fff
93 #define CLK_OUT_ENB_Y_RESET_MASK 0xfc1fc7ff
95 #define RST_DEVICES_V_SWR_CPULP_RST_DIS (0x1 << 1) /* Reserved on Tegra11 */
96 #define CLK_OUT_ENB_V_CLK_ENB_CPULP_EN (0x1 << 1)
98 #define PERIPH_CLK_TO_BIT(c) (1 << (c->u.periph.clk_num % 32))
99 #define PERIPH_CLK_TO_RST_REG(c) \
100 periph_clk_to_reg((c), RST_DEVICES_L, RST_DEVICES_V, \
101 RST_DEVICES_X, RST_DEVICES_Y, 4)
102 #define PERIPH_CLK_TO_RST_SET_REG(c) \
103 periph_clk_to_reg((c), RST_DEVICES_SET_L, RST_DEVICES_SET_V, \
104 RST_DEVICES_SET_X, RST_DEVICES_SET_Y, 8)
105 #define PERIPH_CLK_TO_RST_CLR_REG(c) \
106 periph_clk_to_reg((c), RST_DEVICES_CLR_L, RST_DEVICES_CLR_V, \
107 RST_DEVICES_CLR_X, RST_DEVICES_CLR_Y, 8)
109 #define PERIPH_CLK_TO_ENB_REG(c) \
110 periph_clk_to_reg((c), CLK_OUT_ENB_L, CLK_OUT_ENB_V, \
111 CLK_OUT_ENB_X, CLK_OUT_ENB_Y, 4)
112 #define PERIPH_CLK_TO_ENB_SET_REG(c) \
113 periph_clk_to_reg((c), CLK_OUT_ENB_SET_L, CLK_OUT_ENB_SET_V, \
114 CLK_OUT_ENB_SET_X, CLK_OUT_ENB_SET_Y, 8)
115 #define PERIPH_CLK_TO_ENB_CLR_REG(c) \
116 periph_clk_to_reg((c), CLK_OUT_ENB_CLR_L, CLK_OUT_ENB_CLR_V, \
117 CLK_OUT_ENB_CLR_X, CLK_OUT_ENB_CLR_Y, 8)
119 #define CLK_MASK_ARM 0x44
120 #define MISC_CLK_ENB 0x48
122 #define OSC_CTRL 0x50
123 #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28)
124 #define OSC_CTRL_OSC_FREQ_12MHZ (0x8<<28)
125 #define OSC_CTRL_OSC_FREQ_13MHZ (0x0<<28)
126 #define OSC_CTRL_OSC_FREQ_19_2MHZ (0x4<<28)
127 #define OSC_CTRL_OSC_FREQ_38_4MHZ (0x5<<28)
128 #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
130 #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26)
131 #define OSC_CTRL_PLL_REF_DIV_1 (0<<26)
132 #define OSC_CTRL_PLL_REF_DIV_2 (1<<26)
133 #define OSC_CTRL_PLL_REF_DIV_4 (2<<26)
135 #define PERIPH_CLK_SOURCE_I2S1 0x100
136 #define PERIPH_CLK_SOURCE_EMC 0x19c
137 #define PERIPH_CLK_SOURCE_EMC_MC_SAME (1<<16)
138 #define PERIPH_CLK_SOURCE_EMC_DIV2_EN (1<<15)
139 #define PERIPH_CLK_SOURCE_QSPI_DIV2_EN (1<<8)
140 #define PERIPH_CLK_SOURCE_LA 0x1f8
141 #define PERIPH_CLK_SOURCE_NUM1 \
142 ((PERIPH_CLK_SOURCE_LA - PERIPH_CLK_SOURCE_I2S1) / 4)
144 #define PERIPH_CLK_SOURCE_MSELECT 0x3b4
145 #define PERIPH_CLK_SOURCE_SE 0x42c
146 #define PERIPH_CLK_SOURCE_NUM2 \
147 ((PERIPH_CLK_SOURCE_SE - PERIPH_CLK_SOURCE_MSELECT) / 4 + 1)
149 #define AUDIO_DLY_CLK 0x49c
150 #define AUDIO_SYNC_CLK_SPDIF 0x4b4
151 #define PERIPH_CLK_SOURCE_NUM3 \
152 ((AUDIO_SYNC_CLK_SPDIF - AUDIO_DLY_CLK) / 4 + 1)
154 #define SPARE_REG 0x55c
155 #define SPARE_REG_CLK_M_DIVISOR_SHIFT 2
156 #define SPARE_REG_CLK_M_DIVISOR_MASK (3 << SPARE_REG_CLK_M_DIVISOR_SHIFT)
158 #define AUDIO_SYNC_CLK_DMIC1 0x560
159 #define AUDIO_SYNC_CLK_DMIC2 0x564
160 #define PERIPH_CLK_SOURCE_NUM4 \
161 ((AUDIO_SYNC_CLK_DMIC2 - AUDIO_SYNC_CLK_DMIC1) / 4 + 1)
163 #define PERIPH_CLK_SOURCE_XUSB_HOST 0x600
164 #define PERIPH_CLK_SOURCE_EMC_DLL 0x664
165 #define PERIPH_CLK_SOURCE_VIC 0x678
166 #define PERIPH_CLK_SOURCE_NUM5 \
167 ((PERIPH_CLK_SOURCE_VIC - PERIPH_CLK_SOURCE_XUSB_HOST) / 4)
169 #define PERIPH_CLK_SOURCE_SDMMC_LEGACY 0x694
170 #define PERIPH_CLK_SOURCE_NVENC 0x6a0
171 #define PERIPH_CLK_SOURCE_NUM6 \
172 ((PERIPH_CLK_SOURCE_NVENC - PERIPH_CLK_SOURCE_SDMMC_LEGACY) / 4 + 1)
174 #define AUDIO_SYNC_CLK_DMIC3 0x6b8
175 #define PERIPH_CLK_SOURCE_DBGAPB 0x718
176 #define PERIPH_CLK_SOURCE_NUM7 \
177 ((PERIPH_CLK_SOURCE_DBGAPB - AUDIO_SYNC_CLK_DMIC3) / 4 + 1)
179 #define PERIPH_CLK_SOURCE_NUM (PERIPH_CLK_SOURCE_NUM1 + \
180 PERIPH_CLK_SOURCE_NUM2 + \
181 PERIPH_CLK_SOURCE_NUM3 + \
182 PERIPH_CLK_SOURCE_NUM4 + \
183 PERIPH_CLK_SOURCE_NUM5 + \
184 PERIPH_CLK_SOURCE_NUM6 + \
185 PERIPH_CLK_SOURCE_NUM7)
187 #define CPU_SOFTRST_CTRL 0x380
188 #define CPU_SOFTRST_CTRL1 0x384
189 #define CPU_SOFTRST_CTRL2 0x388
191 #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
192 #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
193 #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
194 #define PERIPH_CLK_SOURCE_DIVIDLE_SHIFT 8
195 #define PERIPH_CLK_SOURCE_DIVIDLE_VAL 50
196 #define PERIPH_CLK_UART_DIV_ENB (1<<24)
197 #define PERIPH_CLK_VI_SEL_EX_SHIFT 24
198 #define PERIPH_CLK_VI_SEL_EX_MASK (0x3<<PERIPH_CLK_VI_SEL_EX_SHIFT)
199 #define PERIPH_CLK_NAND_DIV_EX_ENB (1<<8)
200 #define PERIPH_CLK_DTV_POLARITY_INV (1<<25)
202 #define AUDIO_SYNC_SOURCE_MASK 0x0F
203 #define AUDIO_SYNC_DISABLE_BIT 0x10
204 #define AUDIO_SYNC_TAP_NIBBLE_SHIFT(c) ((c->reg_shift - 24) * 4)
206 #define PERIPH_CLK_SOR_CLK_SEL_SHIFT 14
207 #define PERIPH_CLK_SOR0_CLK_SEL_MASK (0x1<<PERIPH_CLK_SOR_CLK_SEL_SHIFT)
208 #define PERIPH_CLK_SOR1_CLK_SEL_MASK (0x3<<PERIPH_CLK_SOR_CLK_SEL_SHIFT)
210 /* Secondary PLL dividers */
211 #define PLL_OUT_RATIO_MASK (0xFF<<8)
212 #define PLL_OUT_RATIO_SHIFT 8
213 #define PLL_OUT_OVERRIDE (1<<2)
214 #define PLL_OUT_CLKEN (1<<1)
215 #define PLL_OUT_RESET_DISABLE (1<<0)
217 /* PLLC, PLLC2, PLLC3 and PLLA1 */
218 #define PLLCX_USE_DYN_RAMP 0
219 #define PLLCX_BASE_LOCK (1 << 26)
221 #define PLLCX_MISC0_RESET (1 << 30)
222 #define PLLCX_MISC0_LOOP_CTRL_SHIFT 0
223 #define PLLCX_MISC0_LOOP_CTRL_MASK (0x3 << PLLCX_MISC0_LOOP_CTRL_SHIFT)
225 #define PLLCX_MISC1_IDDQ (1 << 27)
227 #define PLLCX_MISC0_DEFAULT_VALUE 0x40080000
228 #define PLLCX_MISC0_WRITE_MASK 0x400ffffb
229 #define PLLCX_MISC1_DEFAULT_VALUE 0x08000000
230 #define PLLCX_MISC1_WRITE_MASK 0x08003cff
231 #define PLLCX_MISC2_DEFAULT_VALUE 0x1f720f05
232 #define PLLCX_MISC2_WRITE_MASK 0xffffff17
233 #define PLLCX_MISC3_DEFAULT_VALUE 0x000000c4
234 #define PLLCX_MISC3_WRITE_MASK 0x00ffffff
237 #define PLLA_BASE_LOCK (1 << 27)
238 #define PLLA_BASE_IDDQ (1 << 25)
240 #define PLLA_MISC0_LOCK_ENABLE (1 << 28)
241 #define PLLA_MISC0_LOCK_OVERRIDE (1 << 27)
243 #define PLLA_MISC2_EN_SDM (1 << 26)
244 #define PLLA_MISC2_EN_DYNRAMP (1 << 25)
246 #define PLLA_MISC0_DEFAULT_VALUE 0x12000020
247 #define PLLA_MISC0_WRITE_MASK 0x7fffffff
248 #define PLLA_MISC2_DEFAULT_VALUE 0x0
249 #define PLLA_MISC2_WRITE_MASK 0x06ffffff
252 #define PLLD_BASE_LOCK (1 << 27)
253 #define PLLD_BASE_DSI_MUX_SHIFT 25
254 #define PLLD_BASE_DSI_MUX_MASK (0x1 << PLLD_BASE_DSI_MUX_SHIFT)
255 #define PLLD_BASE_CSI_CLKSOURCE (1 << 23)
257 #define PLLD_MISC0_DSI_CLKENABLE (1 << 21)
258 #define PLLD_MISC0_IDDQ (1 << 20)
259 #define PLLD_MISC0_LOCK_ENABLE (1 << 18)
260 #define PLLD_MISC0_LOCK_OVERRIDE (1 << 17)
261 #define PLLD_MISC0_EN_SDM (1 << 16)
263 #define PLLD_MISC0_DEFAULT_VALUE 0x00140000
264 #define PLLD_MISC0_WRITE_MASK 0x3ff7ffff
265 #define PLLD_MISC1_DEFAULT_VALUE 0x20
266 #define PLLD_MISC1_WRITE_MASK 0x00ffffff
268 /* PLLD2 and PLLDP and PLLC4 */
269 #define PLLDSS_BASE_LOCK (1 << 27)
270 #define PLLDSS_BASE_LOCK_OVERRIDE (1 << 24)
271 #define PLLDSS_BASE_IDDQ (1 << 18)
272 #define PLLDSS_BASE_REF_SEL_SHIFT 25
273 #define PLLDSS_BASE_REF_SEL_MASK (0x3 << PLLDSS_BASE_REF_SEL_SHIFT)
275 #define PLLDSS_MISC0_LOCK_ENABLE (1 << 30)
277 #define PLLDSS_MISC1_CFG_EN_SDM (1 << 31)
278 #define PLLDSS_MISC1_CFG_EN_SSC (1 << 30)
280 #define PLLD2_MISC0_DEFAULT_VALUE 0x40000020
281 #define PLLD2_MISC1_CFG_DEFAULT_VALUE 0x10000000
282 #define PLLD2_MISC2_CTRL1_DEFAULT_VALUE 0x0
283 #define PLLD2_MISC3_CTRL2_DEFAULT_VALUE 0x0
285 #define PLLDP_MISC0_DEFAULT_VALUE 0x40000020
286 #define PLLDP_MISC1_CFG_DEFAULT_VALUE 0xc0000000
287 #define PLLDP_MISC2_CTRL1_DEFAULT_VALUE 0xf400f0da
288 #define PLLDP_MISC3_CTRL2_DEFAULT_VALUE 0x2004f400
290 #define PLLDSS_MISC0_WRITE_MASK 0x47ffffff
291 #define PLLDSS_MISC1_CFG_WRITE_MASK 0xf8000000
292 #define PLLDSS_MISC2_CTRL1_WRITE_MASK 0xffffffff
293 #define PLLDSS_MISC3_CTRL2_WRITE_MASK 0xffffffff
295 #define PLLC4_MISC0_DEFAULT_VALUE 0x40000000
298 #define PLLRE_MISC0_LOCK_ENABLE (1 << 30)
299 #define PLLRE_MISC0_LOCK_OVERRIDE (1 << 29)
300 #define PLLRE_MISC0_LOCK (1 << 27)
301 #define PLLRE_MISC0_IDDQ (1 << 24)
303 #define PLLRE_BASE_DEFAULT_VALUE 0x0
304 #define PLLRE_MISC0_DEFAULT_VALUE 0x41000000
306 #define PLLRE_BASE_DEFAULT_MASK 0x1c000000
307 #define PLLRE_MISC0_WRITE_MASK 0x67ffffff
310 #define PLLU_BASE_LOCK (1 << 27)
311 #define PLLU_BASE_OVERRIDE (1 << 24)
312 #define PLLU_BASE_CLKENABLE_USB (1 << 21)
314 #define PLLU_MISC0_IDDQ (1 << 31)
315 #define PLLU_MISC0_LOCK_ENABLE (1 << 29)
316 #define PLLU_MISC1_LOCK_OVERRIDE (1 << 0)
318 #define PLLU_MISC0_DEFAULT_VALUE 0xa0000000
319 #define PLLU_MISC1_DEFAULT_VALUE 0x0
321 #define PLLU_MISC0_WRITE_MASK 0xbfffffff
322 #define PLLU_MISC1_WRITE_MASK 0x00000007
325 #define PLLP_BASE_OVERRIDE (1 << 28)
326 #define PLLP_BASE_LOCK (1 << 27)
328 #define PLLP_MISC0_LOCK_ENABLE (1 << 18)
329 #define PLLP_MISC0_LOCK_OVERRIDE (1 << 17)
330 #define PLLP_MISC0_IDDQ (1 << 3)
332 #define PLLP_MISC1_HSIO_EN_SHIFT 29
333 #define PLLP_MISC1_HSIO_EN (1 << PLLP_MISC1_HSIO_EN_SHIFT)
334 #define PLLP_MISC1_XUSB_EN_SHIFT 28
335 #define PLLP_MISC1_XUSB_EN (1 << PLLP_MISC1_XUSB_EN_SHIFT)
337 #define PLLP_MISC0_DEFAULT_VALUE 0x00040008
338 #define PLLP_MISC1_DEFAULT_VALUE 0x0
340 #define PLLP_MISC0_WRITE_MASK 0xdc6000f
341 #define PLLP_MISC1_WRITE_MASK 0x70ffffff
344 #define PLLX_USE_DYN_RAMP 1
345 #define PLLX_BASE_LOCK (1 << 27)
347 #define PLLX_MISC0_FO_G_DISABLE (0x1 << 28)
348 #define PLLX_MISC0_LOCK_ENABLE (0x1 << 18)
350 #define PLLX_MISC2_DYNRAMP_STEPB_SHIFT 24
351 #define PLLX_MISC2_DYNRAMP_STEPB_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPB_SHIFT)
352 #define PLLX_MISC2_DYNRAMP_STEPA_SHIFT 16
353 #define PLLX_MISC2_DYNRAMP_STEPA_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPA_SHIFT)
354 #define PLLX_MISC2_NDIV_NEW_SHIFT 8
355 #define PLLX_MISC2_NDIV_NEW_MASK (0xFF << PLLX_MISC2_NDIV_NEW_SHIFT)
356 #define PLLX_MISC2_LOCK_OVERRIDE (0x1 << 4)
357 #define PLLX_MISC2_DYNRAMP_DONE (0x1 << 2)
358 #define PLLX_MISC2_EN_DYNRAMP (0x1 << 0)
360 #define PLLX_MISC3_IDDQ (0x1 << 3)
362 #define PLLX_MISC0_DEFAULT_VALUE PLLX_MISC0_LOCK_ENABLE
363 #define PLLX_MISC0_WRITE_MASK 0x10c40000
364 #define PLLX_MISC1_DEFAULT_VALUE 0x20
365 #define PLLX_MISC1_WRITE_MASK 0x00ffffff
366 #define PLLX_MISC2_DEFAULT_VALUE 0x0
367 #define PLLX_MISC2_WRITE_MASK 0xffffff11
368 #define PLLX_MISC3_DEFAULT_VALUE PLLX_MISC3_IDDQ
369 #define PLLX_MISC3_WRITE_MASK 0x01ff0f0f
370 #define PLLX_MISC4_DEFAULT_VALUE 0x0
371 #define PLLX_MISC4_WRITE_MASK 0x8000ffff
372 #define PLLX_MISC5_DEFAULT_VALUE 0x0
373 #define PLLX_MISC5_WRITE_MASK 0x0000ffff
375 #define PLLX_HW_CTRL_CFG 0x548
376 #define PLLX_HW_CTRL_CFG_SWCTRL (0x1 << 0)
379 #define PLLM_BASE_LOCK (1 << 27)
381 #define PLLM_MISC0_SYNCMUX_CTRL_SHIFT 10
382 #define PLLM_MISC0_SYNCMUX_CTRL_MASK (0xF << PLLM_MISC0_SYNCMUX_CTRL_SHIFT)
383 #define PLLM_MISC0_IDDQ (1 << 5)
384 #define PLLM_MISC0_LOCK_ENABLE (1 << 4)
385 #define PLLM_MISC0_LOCK_OVERRIDE (1 << 3)
387 #define PMC_PLLP_WB0_OVERRIDE 0xf8
388 #define PMC_PLLP_WB0_OVERRIDE_PLLM_IDDQ (1 << 14)
389 #define PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO (1 << 13)
390 #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE (1 << 12)
391 #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE (1 << 11)
393 /* M, N layout for PLLM override and base registers are the same */
394 #define PMC_PLLM_WB0_OVERRIDE 0x1dc
396 /* PDIV override and base layouts are different */
397 #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0
398 #define PMC_PLLM_WB0_OVERRIDE_2_DIVP_SHIFT 27
399 #define PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK (0x1F << 27)
402 #define PLLMB_BASE_LOCK (1 << 27)
404 #define PLLMB_MISC0_LOCK_OVERRIDE (1 << 18)
405 #define PLLMB_MISC0_IDDQ (1 << 17)
406 #define PLLMB_MISC0_LOCK_ENABLE (1 << 16)
408 #define PLLMB_MISC0_DEFAULT_VALUE 0x00030000
409 #define PLLMB_MISC0_WRITE_MASK 0x0007ffff
411 #define SUPER_CLK_MUX 0x00
412 #define SUPER_STATE_SHIFT 28
413 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
414 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
415 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
416 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
417 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
418 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
419 #define SUPER_SOURCE_MASK 0xF
420 #define SUPER_FIQ_SOURCE_SHIFT 12
421 #define SUPER_IRQ_SOURCE_SHIFT 8
422 #define SUPER_RUN_SOURCE_SHIFT 4
423 #define SUPER_IDLE_SOURCE_SHIFT 0
425 #define SUPER_CLK_DIVIDER 0x04
426 #define SUPER_CLOCK_DIV_U71_SHIFT 16
427 #define SUPER_CLOCK_DIV_U71_MASK (0xff << SUPER_CLOCK_DIV_U71_SHIFT)
429 #define SUPER_SKIPPER_ENABLE (1 << 31)
430 #define SUPER_SKIPPER_TERM_SIZE 8
431 #define SUPER_SKIPPER_MUL_SHIFT 8
432 #define SUPER_SKIPPER_MUL_MASK (((1 << SUPER_SKIPPER_TERM_SIZE) - 1) \
433 << SUPER_SKIPPER_MUL_SHIFT)
434 #define SUPER_SKIPPER_DIV_SHIFT 0
435 #define SUPER_SKIPPER_DIV_MASK (((1 << SUPER_SKIPPER_TERM_SIZE) - 1) \
436 << SUPER_SKIPPER_DIV_SHIFT)
438 #define BUS_CLK_DISABLE (1<<3)
439 #define BUS_CLK_DIV_MASK 0x3
442 #define PMC_CTRL_BLINK_ENB (1 << 7)
444 #define PMC_DPD_PADS_ORIDE 0x1c
445 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
447 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
448 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
449 #define PMC_BLINK_TIMER_ENB (1 << 15)
450 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
451 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
453 #define UTMIP_PLL_CFG2 0x488
454 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6)
455 #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
456 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN (1 << 0)
457 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP (1 << 1)
458 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN (1 << 2)
459 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP (1 << 3)
460 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN (1 << 4)
461 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP (1 << 5)
462 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN (1 << 24)
463 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP (1 << 25)
465 #define UTMIP_PLL_CFG1 0x484
466 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27)
467 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
468 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP (1 << 15)
469 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN (1 << 14)
470 #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN (1 << 12)
471 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP (1 << 17)
472 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN (1 << 16)
475 #define PLLE_BASE_ENABLE (1 << 31)
476 #define PLLE_BASE_LOCK_OVERRIDE (1 << 30)
477 #define PLLE_BASE_DIVCML_SHIFT 24
478 #define PLLE_BASE_DIVCML_MASK (0x1F<<PLLE_BASE_DIVCML_SHIFT)
479 #define PLLE_BASE_DIVN_SHIFT 8
480 #define PLLE_BASE_DIVN_MASK (0xFF<<PLLE_BASE_DIVN_SHIFT)
481 #define PLLE_BASE_DIVM_SHIFT 0
482 #define PLLE_BASE_DIVM_MASK (0xFF<<PLLE_BASE_DIVM_SHIFT)
484 #define PLLE_MISC_IDDQ_SW_CTRL (1<<14)
485 #define PLLE_MISC_IDDQ_SW_VALUE (1<<13)
486 #define PLLE_MISC_LOCK (1<<11)
487 #define PLLE_MISC_LOCK_ENABLE (1<<9)
488 #define PLLE_MISC_PLLE_PTS (1<<8)
489 #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4
490 #define PLLE_MISC_VREG_BG_CTRL_MASK (0x3<<PLLE_MISC_VREG_BG_CTRL_SHIFT)
491 #define PLLE_MISC_VREG_CTRL_SHIFT 2
492 #define PLLE_MISC_VREG_CTRL_MASK (0x3<<PLLE_MISC_VREG_CTRL_SHIFT)
494 #define PLLE_SS_CTRL 0x68
495 #define PLLE_SS_INCINTRV_SHIFT 24
496 #define PLLE_SS_INCINTRV_MASK (0x3f<<PLLE_SS_INCINTRV_SHIFT)
497 #define PLLE_SS_INC_SHIFT 16
498 #define PLLE_SS_INC_MASK (0xff<<PLLE_SS_INC_SHIFT)
499 #define PLLE_SS_CNTL_INVERT (0x1 << 15)
500 #define PLLE_SS_CNTL_CENTER (0x1 << 14)
501 #define PLLE_SS_CNTL_SSC_BYP (0x1 << 12)
502 #define PLLE_SS_CNTL_INTERP_RESET (0x1 << 11)
503 #define PLLE_SS_CNTL_BYPASS_SS (0x1 << 10)
504 #define PLLE_SS_MAX_SHIFT 0
505 #define PLLE_SS_MAX_MASK (0x1ff<<PLLE_SS_MAX_SHIFT)
506 #define PLLE_SS_COEFFICIENTS_MASK \
507 (PLLE_SS_INCINTRV_MASK | PLLE_SS_INC_MASK | PLLE_SS_MAX_MASK)
508 #define PLLE_SS_COEFFICIENTS_VAL \
509 ((0x23<<PLLE_SS_INCINTRV_SHIFT) | (0x1<<PLLE_SS_INC_SHIFT) | \
510 (0x21<<PLLE_SS_MAX_SHIFT))
511 #define PLLE_SS_DISABLE (PLLE_SS_CNTL_SSC_BYP |\
512 PLLE_SS_CNTL_INTERP_RESET | PLLE_SS_CNTL_BYPASS_SS)
514 #define PLLE_AUX 0x48c
515 #define PLLE_AUX_PLLRE_SEL (1<<28)
516 #define PLLE_AUX_SEQ_STATE_SHIFT 26
517 #define PLLE_AUX_SEQ_STATE_MASK (0x3<<PLLE_AUX_SEQ_STATE_SHIFT)
518 #define PLLE_AUX_SS_SEQ_INCLUDE (1<<31)
519 #define PLLE_AUX_SEQ_START_STATE (1<<25)
520 #define PLLE_AUX_SEQ_ENABLE (1<<24)
521 #define PLLE_AUX_SS_SWCTL (1<<6)
522 #define PLLE_AUX_ENABLE_SWCTL (1<<4)
523 #define PLLE_AUX_USE_LOCKDET (1<<3)
524 #define PLLE_AUX_PLLP_SEL (1<<2)
526 #define PLLE_AUX_CML_SATA_ENABLE (1<<1)
527 #define PLLE_AUX_CML_PCIE_ENABLE (1<<0)
529 #define SOURCE_SATA 0x424
531 /* USB PLLs PD HW controls */
532 #define XUSBIO_PLL_CFG0 0x51c
533 #define XUSBIO_PLL_CFG0_SEQ_START_STATE (1<<25)
534 #define XUSBIO_PLL_CFG0_SEQ_ENABLE (1<<24)
535 #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET (1<<6)
536 #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL (1<<2)
537 #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL (1<<0)
539 #define UTMIPLL_HW_PWRDN_CFG0 0x52c
540 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE (1<<25)
541 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE (1<<24)
542 #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET (1<<6)
543 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE (1<<5)
544 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL (1<<4)
545 #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL (1<<2)
546 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE (1<<1)
547 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL (1<<0)
549 #define PLLU_HW_PWRDN_CFG0 0x530
550 #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE (1<<28)
551 #define PLLU_HW_PWRDN_CFG0_SEQ_START_STATE (1<<25)
552 #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE (1<<24)
553 #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT (1<<7)
554 #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET (1<<6)
555 #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL (1<<2)
556 #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL (1<<0)
558 #define XUSB_PLL_CFG0 0x534
559 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY (0x3ff<<0)
560 #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_SHIFT 14
561 #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK \
562 (0x3ff<<XUSB_PLL_CFG0_PLLU_LOCK_DLY_SHIFT)
565 #define DFLL_BASE 0x2f4
566 #define DFLL_BASE_RESET (1<<0)
569 #define ADSP_NEON (1 << 26)
570 #define ADSP_SCU (1 << 25)
571 #define ADSP_WDT (1 << 24)
572 #define ADSP_DBG (1 << 23)
573 #define ADSP_PERIPH (1 << 22)
574 #define ADSP_INTF (1 << 21)
575 #define ADSP_CORE (1 << 7)
577 #define ROUND_DIVIDER_UP 0
578 #define ROUND_DIVIDER_DOWN 1
579 #define DIVIDER_1_5_ALLOWED 0
581 /* PLLP default fixed rate in h/w controlled mode */
582 #define PLLP_DEFAULT_FIXED_RATE 408000000
584 /* Use PLL_RE as PLLE input (default - OSC via pll reference divider) */
585 #define USE_PLLE_INPUT_PLLRE 0
587 static void pllc4_set_fixed_rates(unsigned long cf);
588 static void tegra21_dfll_cpu_late_init(struct clk *c);
589 static void tegra21_pllp_init_dependencies(unsigned long pllp_rate);
591 static unsigned long tegra21_clk_shared_bus_update(struct clk *bus,
592 struct clk **bus_top, struct clk **bus_slow, unsigned long *rate_cap);
593 static unsigned long tegra21_clk_cap_shared_bus(struct clk *bus,
594 unsigned long rate, unsigned long ceiling);
596 static struct clk *pll_u;
598 static bool detach_shared_bus;
599 module_param(detach_shared_bus, bool, 0644);
601 /* Defines default range for dynamic frequency lock loop (DFLL)
602 to be used as CPU clock source:
603 "0" - DFLL is not used,
604 "1" - DFLL is used as a source for all CPU rates
605 "2" - DFLL is used only for high rates above crossover with PLL dvfs curve
610 * Structure defining the fields for USB UTMI clocks Parameters.
612 struct utmi_clk_param
614 /* Oscillator Frequency in KHz */
616 /* UTMIP PLL Enable Delay Count */
617 u8 enable_delay_count;
618 /* UTMIP PLL Stable count */
620 /* UTMIP PLL Active delay count */
621 u8 active_delay_count;
622 /* UTMIP PLL Xtal frequency count */
626 static const struct utmi_clk_param utmi_parameters[] =
628 /* OSC_FREQUENCY, ENABLE_DLY, STABLE_CNT, ACTIVE_DLY, XTAL_FREQ_CNT */
629 {13000000, 0x02, 0x33, 0x05, 0x7F},
630 {12000000, 0x02, 0x2F, 0x04, 0x76},
632 {19200000, 0x03, 0x4B, 0x06, 0xBB},
633 /* HACK!!! FIXME!!! following entry for 38.4MHz is a stub */
634 {38400000, 0x0, 0x0, 0x06, 0x80}
637 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
638 static void __iomem *misc_gp_base = IO_ADDRESS(TEGRA_APB_MISC_BASE);
640 #define MISC_GP_HIDREV 0x804
641 #define MISC_GP_TRANSACTOR_SCRATCH_0 0x864
642 #define MISC_GP_TRANSACTOR_SCRATCH_LA_ENABLE (0x1 << 1)
643 #define MISC_GP_TRANSACTOR_SCRATCH_DDS_ENABLE (0x1 << 2)
644 #define MISC_GP_TRANSACTOR_SCRATCH_DP2_ENABLE (0x1 << 3)
646 #define pmc_writel(value, reg) \
647 __raw_writel(value, reg_pmc_base + (reg))
648 #define pmc_readl(reg) \
649 readl(reg_pmc_base + (reg))
650 #define chipid_readl() \
651 __raw_readl(misc_gp_base + MISC_GP_HIDREV)
654 * Some peripheral clocks share an enable bit, so refcount the enable bits
655 * in registers CLK_ENABLE_L, ... CLK_ENABLE_W, and protect refcount updates
658 static DEFINE_SPINLOCK(periph_refcount_lock);
659 static int tegra_periph_clk_enable_refcount[CLK_OUT_ENB_NUM * 32];
661 static inline int clk_set_div(struct clk *c, u32 n)
663 return clk_set_rate(c, (clk_get_rate(c->parent) + n-1) / n);
666 static inline u32 periph_clk_to_reg(
667 struct clk *c, u32 reg_L, u32 reg_V, u32 reg_X, u32 reg_Y, int offs)
669 u32 reg = c->u.periph.clk_num / 32;
670 BUG_ON(reg >= RST_DEVICES_NUM);
672 reg = reg_L + (reg * offs);
674 reg = reg_V + ((reg - 3) * offs);
682 static int clk_div_x1_get_divider(unsigned long parent_rate, unsigned long rate,
684 u32 flags, u32 round_mode)
686 s64 divider_ux1 = parent_rate;
690 if (!(flags & DIV_U71_INT))
692 if (round_mode == ROUND_DIVIDER_UP)
693 divider_ux1 += rate - 1;
694 do_div(divider_ux1, rate);
695 if (flags & DIV_U71_INT)
698 if (divider_ux1 - 2 < 0)
701 if (divider_ux1 - 2 > max_x)
704 #if !DIVIDER_1_5_ALLOWED
705 if (divider_ux1 == 3)
706 divider_ux1 = (round_mode == ROUND_DIVIDER_UP) ? 4 : 2;
708 return divider_ux1 - 2;
711 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate,
712 u32 flags, u32 round_mode)
714 return clk_div_x1_get_divider(parent_rate, rate, 0xFF,
718 static int clk_div151_get_divider(unsigned long parent_rate, unsigned long rate,
719 u32 flags, u32 round_mode)
721 return clk_div_x1_get_divider(parent_rate, rate, 0xFFFF,
725 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
729 divider_u16 = parent_rate;
732 divider_u16 += rate - 1;
733 do_div(divider_u16, rate);
735 if (divider_u16 - 1 < 0)
738 if (divider_u16 - 1 > 0xFFFF)
741 return divider_u16 - 1;
744 static long fixed_src_bus_round_updown(struct clk *c, struct clk *src,
745 u32 flags, unsigned long rate, bool up, u32 *div)
748 unsigned long source_rate, round_rate;
750 source_rate = clk_get_rate(src);
752 divider = clk_div71_get_divider(source_rate, rate + (up ? -1 : 1),
753 flags, up ? ROUND_DIVIDER_DOWN : ROUND_DIVIDER_UP);
755 divider = flags & DIV_U71_INT ? 0xFE : 0xFF;
756 round_rate = source_rate * 2 / (divider + 2);
760 round_rate = source_rate * 2 / (divider + 2);
762 if (round_rate > c->max_rate) {
763 divider += flags & DIV_U71_INT ? 2 : 1;
764 #if !DIVIDER_1_5_ALLOWED
765 divider = max(2, divider);
767 round_rate = source_rate * 2 / (divider + 2);
775 static inline bool bus_user_is_slower(struct clk *a, struct clk *b)
777 return a->u.shared_bus_user.client->max_rate <
778 b->u.shared_bus_user.client->max_rate;
781 static inline bool bus_user_request_is_lower(struct clk *a, struct clk *b)
783 return a->u.shared_bus_user.rate <
784 b->u.shared_bus_user.rate;
787 static void super_clk_set_u71_div_no_skip(struct clk *c)
789 clk_writel_delay(c->u.cclk.div71 << SUPER_CLOCK_DIV_U71_SHIFT,
790 c->reg + SUPER_CLK_DIVIDER);
792 c->div = c->u.cclk.div71 + 2;
795 static void super_clk_clr_u71_div_no_skip(struct clk *c)
797 clk_writel_delay(0, c->reg + SUPER_CLK_DIVIDER);
802 /* clk_m functions */
803 static unsigned long tegra21_osc_autodetect_rate(struct clk *c)
805 u32 osc_ctrl = clk_readl(OSC_CTRL);
806 u32 pll_ref_div = clk_readl(OSC_CTRL) & OSC_CTRL_PLL_REF_DIV_MASK;
808 switch (osc_ctrl & OSC_CTRL_OSC_FREQ_MASK) {
809 case OSC_CTRL_OSC_FREQ_12MHZ:
812 case OSC_CTRL_OSC_FREQ_13MHZ:
813 /* 13MHz for FPGA only, BUG_ON otherwise */
814 BUG_ON(!tegra_platform_is_fpga());
817 case OSC_CTRL_OSC_FREQ_38_4MHZ:
821 pr_err("supported OSC freq: %08x\n", osc_ctrl);
825 BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
830 static void tegra21_osc_init(struct clk *c)
832 pr_debug("%s on clock %s\n", __func__, c->name);
833 tegra21_osc_autodetect_rate(c);
837 static int tegra21_osc_enable(struct clk *c)
839 pr_debug("%s on clock %s\n", __func__, c->name);
843 static void tegra21_osc_disable(struct clk *c)
845 pr_debug("%s on clock %s\n", __func__, c->name);
846 WARN(1, "Attempting to disable main SoC clock\n");
849 static struct clk_ops tegra_osc_ops = {
850 .init = tegra21_osc_init,
851 .enable = tegra21_osc_enable,
852 .disable = tegra21_osc_disable,
855 static void tegra21_clk_m_init(struct clk *c)
858 u32 spare = clk_readl(SPARE_REG);
860 pr_debug("%s on clock %s\n", __func__, c->name);
862 rate = clk_get_rate(c->parent); /* the rate of osc clock */
864 if (tegra_platform_is_fpga()) {
865 if (rate == 38400000) {
866 /* Set divider to (2 + 1) to still maintain
867 clk_m to 13MHz instead of reporting clk_m as
868 19.2 MHz when it is actually set to 13MHz */
869 spare &= ~SPARE_REG_CLK_M_DIVISOR_MASK;
870 spare |= (2 << SPARE_REG_CLK_M_DIVISOR_SHIFT);
871 clk_writel(spare, SPARE_REG);
875 c->div = ((spare & SPARE_REG_CLK_M_DIVISOR_MASK)
876 >> SPARE_REG_CLK_M_DIVISOR_SHIFT) + 1;
881 static int tegra21_clk_m_enable(struct clk *c)
883 pr_debug("%s on clock %s\n", __func__, c->name);
887 static void tegra21_clk_m_disable(struct clk *c)
889 pr_debug("%s on clock %s\n", __func__, c->name);
890 WARN(1, "Attempting to disable main SoC clock\n");
893 static struct clk_ops tegra_clk_m_ops = {
894 .init = tegra21_clk_m_init,
895 .enable = tegra21_clk_m_enable,
896 .disable = tegra21_clk_m_disable,
899 static struct clk_ops tegra_clk_m_div_ops = {
900 .enable = tegra21_clk_m_enable,
903 /* PLL reference divider functions */
904 static void tegra21_pll_ref_init(struct clk *c)
906 u32 pll_ref_div = clk_readl(OSC_CTRL) & OSC_CTRL_PLL_REF_DIV_MASK;
907 pr_debug("%s on clock %s\n", __func__, c->name);
909 switch (pll_ref_div) {
910 case OSC_CTRL_PLL_REF_DIV_1:
913 case OSC_CTRL_PLL_REF_DIV_2:
916 case OSC_CTRL_PLL_REF_DIV_4:
920 pr_err("%s: Invalid pll ref divider %d", __func__, pll_ref_div);
927 static struct clk_ops tegra_pll_ref_ops = {
928 .init = tegra21_pll_ref_init,
929 .enable = tegra21_clk_m_enable,
930 .disable = tegra21_clk_m_disable,
933 /* super clock functions */
934 /* "super clocks" on tegra21x have two-stage muxes, fractional 7.1 divider and
935 * clock skipping super divider. We will ignore the clock skipping divider,
936 * since we can't lower the voltage when using the clock skip, but we can if
937 * we lower the PLL frequency. Note that skipping divider can and will be used
938 * by thermal control h/w for automatic throttling. There is also a 7.1 divider
939 * that most CPU super-clock inputs can be routed through. We will not use it
940 * as well (keep default 1:1 state), to avoid high jitter on PLLX and DFLL path
941 * and possible concurrency access issues with thermal h/w (7.1 divider setting
942 * share register with clock skipping divider)
944 static void tegra21_super_clk_init(struct clk *c)
949 const struct clk_mux_sel *sel;
950 val = clk_readl(c->reg + SUPER_CLK_MUX);
952 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
953 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
954 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
955 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
956 source = (val >> shift) & SUPER_SOURCE_MASK;
958 for (sel = c->inputs; sel->input != NULL; sel++) {
959 if (sel->value == source)
962 BUG_ON(sel->input == NULL);
963 c->parent = sel->input;
965 if (c->flags & DIV_U71) {
970 * Make sure 7.1 divider is 1:1, clear h/w skipper control -
971 * it will be enabled by soctherm later
973 val = clk_readl(c->reg + SUPER_CLK_DIVIDER);
974 BUG_ON(val & SUPER_CLOCK_DIV_U71_MASK);
976 clk_writel(val, c->reg + SUPER_CLK_DIVIDER);
979 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
982 static int tegra21_super_clk_enable(struct clk *c)
987 static void tegra21_super_clk_disable(struct clk *c)
989 /* since tegra 3 has 2 CPU super clocks - low power lp-mode clock and
990 geared up g-mode super clock - mode switch may request to disable
991 either of them; accept request with no affect on h/w */
994 static int tegra21_super_clk_set_parent(struct clk *c, struct clk *p)
997 const struct clk_mux_sel *sel;
1000 val = clk_readl(c->reg + SUPER_CLK_MUX);
1001 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
1002 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
1003 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
1004 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
1005 for (sel = c->inputs; sel->input != NULL; sel++) {
1006 if (sel->input == p) {
1007 val &= ~(SUPER_SOURCE_MASK << shift);
1008 val |= (sel->value & SUPER_SOURCE_MASK) << shift;
1010 if ((c->flags & DIV_U71) && !c->u.cclk.div71) {
1011 /* Make sure 7.1 divider is 1:1 */
1012 u32 div = clk_readl(c->reg + SUPER_CLK_DIVIDER);
1013 BUG_ON(div & SUPER_CLOCK_DIV_U71_MASK);
1017 tegra_clk_prepare_enable(p);
1019 clk_writel_delay(val, c->reg);
1021 if (c->refcnt && c->parent)
1022 tegra_clk_disable_unprepare(c->parent);
1032 * Do not use super clocks "skippers", since dividing using a clock skipper
1033 * does not allow the voltage to be scaled down. Instead adjust the rate of
1034 * the parent clock. This requires that the parent of a super clock have no
1035 * other children, otherwise the rate will change underneath the other
1038 static int tegra21_super_clk_set_rate(struct clk *c, unsigned long rate)
1041 * In tegra21_cpu_clk_set_plls(), tegra21_sbus_cmplx_set_rate(), and
1042 * tegra21_adsp_bus_clk_set_rate() this interface is skipped by directly
1043 * setting rate of source plls.
1045 return clk_set_rate(c->parent, rate);
1048 static struct clk_ops tegra_super_ops = {
1049 .init = tegra21_super_clk_init,
1050 .enable = tegra21_super_clk_enable,
1051 .disable = tegra21_super_clk_disable,
1052 .set_parent = tegra21_super_clk_set_parent,
1053 .set_rate = tegra21_super_clk_set_rate,
1056 /* virtual cpu clock functions */
1057 /* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
1058 To change the frequency of these clocks, the parent pll may need to be
1059 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
1060 and then the clock moved back to the pll. To hide this sequence, a virtual
1063 static void tegra21_cpu_clk_init(struct clk *c)
1065 c->state = (!is_lp_cluster() == (c->u.cpu.mode == MODE_G)) ? ON : OFF;
1068 static int tegra21_cpu_clk_enable(struct clk *c)
1073 static void tegra21_cpu_clk_disable(struct clk *c)
1075 /* since tegra 3 has 2 virtual CPU clocks - low power lp-mode clock
1076 and geared up g-mode clock - mode switch may request to disable
1077 either of them; accept request with no affect on h/w */
1080 static int tegra21_cpu_clk_set_plls(struct clk *c, unsigned long rate,
1081 unsigned long old_rate)
1085 bool on_main = false;
1086 unsigned long backup_rate, main_rate;
1087 struct clk *main_pll = c->u.cpu.main;
1090 * Take an extra reference to the main pll so it doesn't turn off when
1091 * we move the cpu off of it. If possible, use main pll dynamic ramp
1092 * to reach target rate in one shot. Otherwise, use dynamic ramp to
1093 * lower current rate to pll VCO minimum level before switching to
1096 if (c->parent->parent == main_pll) {
1097 tegra_clk_prepare_enable(main_pll);
1101 dramp = (rate > c->u.cpu.backup_rate) &&
1102 tegra_pll_can_ramp_to_rate(main_pll, rate);
1104 if (dramp || tegra_pll_can_ramp_to_min(main_pll, &main_rate)) {
1105 ret = clk_set_rate(main_pll, main_rate);
1107 pr_err("Failed to set cpu rate %lu on source"
1108 " %s\n", main_rate, main_pll->name);
1112 if (main_rate == rate)
1114 } else if (main_pll->u.pll.dyn_ramp) {
1115 pr_warn("%s: not ready for dynamic ramp to %lu\n",
1116 main_pll->name, rate);
1120 /* Switch to back-up source, and stay on it if target rate is below
1122 if (c->parent->parent != c->u.cpu.backup) {
1123 ret = clk_set_parent(c->parent, c->u.cpu.backup);
1125 pr_err("Failed to switch cpu to %s\n",
1126 c->u.cpu.backup->name);
1131 backup_rate = min(rate, c->u.cpu.backup_rate);
1132 if (backup_rate != clk_get_rate_locked(c)) {
1133 ret = clk_set_rate(c->u.cpu.backup, backup_rate);
1135 pr_err("Failed to set cpu rate %lu on backup source\n",
1140 if (rate == backup_rate)
1143 /* Switch from backup source to main at rate not exceeding pll VCO
1144 minimum. Use dynamic ramp to reach target rate if it is above VCO
1147 if (!tegra_pll_can_ramp_from_min(main_pll, rate, &main_rate)) {
1148 if (main_pll->u.pll.dyn_ramp)
1149 pr_warn("%s: not ready for dynamic ramp to %lu\n",
1150 main_pll->name, rate);
1153 ret = clk_set_rate(main_pll, main_rate);
1155 pr_err("Failed to set cpu rate %lu on source"
1156 " %s\n", main_rate, main_pll->name);
1160 ret = clk_set_parent(c->parent, main_pll);
1162 pr_err("Failed to switch cpu to %s\n", main_pll->name);
1166 if (rate != main_rate) {
1167 ret = clk_set_rate(main_pll, rate);
1169 pr_err("Failed to set cpu rate %lu on source"
1170 " %s\n", rate, main_pll->name);
1177 tegra_clk_disable_unprepare(main_pll);
1182 static int tegra21_cpu_clk_dfll_on(struct clk *c, unsigned long rate,
1183 unsigned long old_rate)
1186 struct clk *dfll = c->u.cpu.dynamic;
1187 unsigned long dfll_rate_min = c->dvfs->dfll_data.use_dfll_rate_min;
1189 /* dfll rate request */
1190 ret = clk_set_rate(dfll, rate);
1192 pr_err("Failed to set cpu rate %lu on source"
1193 " %s\n", rate, dfll->name);
1197 /* 1st time - switch to dfll */
1198 if (c->parent->parent != dfll) {
1199 if (max(old_rate, rate) < dfll_rate_min) {
1200 /* set interim cpu dvfs rate at dfll_rate_min to
1201 prevent voltage drop below dfll Vmin */
1202 ret = tegra_dvfs_set_rate(c, dfll_rate_min);
1204 pr_err("Failed to set cpu dvfs rate %lu\n",
1210 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, true);
1211 ret = clk_set_parent(c->parent, dfll);
1213 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1214 pr_err("Failed to switch cpu to %s\n", dfll->name);
1217 ret = tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 1);
1218 WARN(ret, "Failed to lock %s at rate %lu\n", dfll->name, rate);
1220 /* prevent legacy dvfs voltage scaling */
1221 tegra_dvfs_dfll_mode_set(c->dvfs, rate);
1222 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1227 static int tegra21_cpu_clk_dfll_off(struct clk *c, unsigned long rate,
1228 unsigned long old_rate)
1232 struct clk *dfll = c->u.cpu.dynamic;
1233 unsigned long dfll_rate_min = c->dvfs->dfll_data.use_dfll_rate_min;
1235 rate = min(rate, c->max_rate - c->dvfs->dfll_data.max_rate_boost);
1236 pll = (rate <= c->u.cpu.backup_rate) ? c->u.cpu.backup : c->u.cpu.main;
1237 dfll_rate_min = max(rate, dfll_rate_min);
1239 /* set target rate last time in dfll mode */
1240 if (old_rate != dfll_rate_min) {
1241 ret = tegra_dvfs_set_rate(c, dfll_rate_min);
1243 ret = clk_set_rate(dfll, dfll_rate_min);
1246 pr_err("Failed to set cpu rate %lu on source %s\n",
1247 dfll_rate_min, dfll->name);
1252 /* unlock dfll - release volatge rail control */
1253 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, true);
1254 ret = tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 0);
1256 pr_err("Failed to unlock %s\n", dfll->name);
1260 /* restore legacy dvfs operations and set appropriate voltage */
1261 ret = tegra_dvfs_dfll_mode_clear(c->dvfs, dfll_rate_min);
1263 pr_err("Failed to set cpu rail for rate %lu\n", rate);
1267 /* set pll to target rate and return to pll source */
1268 ret = clk_set_rate(pll, rate);
1270 pr_err("Failed to set cpu rate %lu on source"
1271 " %s\n", rate, pll->name);
1274 ret = clk_set_parent(c->parent, pll);
1276 pr_err("Failed to switch cpu to %s\n", pll->name);
1280 /* If going up, adjust voltage here (down path is taken care of by the
1281 framework after set rate exit) */
1282 if (old_rate <= rate)
1283 tegra_dvfs_set_rate(c, rate);
1285 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1289 tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 1);
1290 tegra_dvfs_dfll_mode_set(c->dvfs, old_rate);
1291 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1295 static int tegra21_cpu_clk_set_rate(struct clk *c, unsigned long rate)
1297 unsigned long old_rate = clk_get_rate_locked(c);
1298 bool has_dfll = c->u.cpu.dynamic &&
1299 (c->u.cpu.dynamic->state != UNINITIALIZED);
1300 bool is_dfll = c->parent->parent == c->u.cpu.dynamic;
1302 /* On SILICON allow CPU rate change only if cpu regulator is connected.
1303 Ignore regulator connection on FPGA and SIMULATION platforms. */
1304 if (c->dvfs && tegra_platform_is_silicon()) {
1305 if (!c->dvfs->dvfs_rail)
1307 else if ((!c->dvfs->dvfs_rail->reg) && (old_rate < rate) &&
1308 (c->boot_rate < rate)) {
1309 WARN(1, "Increasing CPU rate while regulator is not"
1310 " ready is not allowed\n");
1314 if (has_dfll && c->dvfs && c->dvfs->dvfs_rail) {
1315 if (tegra_dvfs_is_dfll_range(c->dvfs, rate))
1316 return tegra21_cpu_clk_dfll_on(c, rate, old_rate);
1318 return tegra21_cpu_clk_dfll_off(c, rate, old_rate);
1320 return tegra21_cpu_clk_set_plls(c, rate, old_rate);
1323 static long tegra21_cpu_clk_round_rate(struct clk *c, unsigned long rate)
1325 unsigned long max_rate = c->max_rate;
1327 /* Remove dfll boost to maximum rate when running on PLL */
1328 if (c->dvfs && !tegra_dvfs_is_dfll_scale(c->dvfs, rate))
1329 max_rate -= c->dvfs->dfll_data.max_rate_boost;
1331 if (rate > max_rate)
1333 else if (rate < c->min_rate)
1338 static struct clk_ops tegra_cpu_ops = {
1339 .init = tegra21_cpu_clk_init,
1340 .enable = tegra21_cpu_clk_enable,
1341 .disable = tegra21_cpu_clk_disable,
1342 .set_rate = tegra21_cpu_clk_set_rate,
1343 .round_rate = tegra21_cpu_clk_round_rate,
1347 static void tegra21_cpu_cmplx_clk_init(struct clk *c)
1349 int i = is_lp_cluster() ? 1 : 0;
1351 BUG_ON(c->inputs[0].input->u.cpu.mode != MODE_G);
1352 BUG_ON(c->inputs[1].input->u.cpu.mode != MODE_LP);
1354 c->parent = c->inputs[i].input;
1357 /* cpu complex clock provides second level vitualization (on top of
1358 cpu virtual cpu rate control) in order to hide the CPU mode switch
1360 #if PARAMETERIZE_CLUSTER_SWITCH
1361 static unsigned int switch_delay;
1362 static unsigned int switch_flags;
1363 static DEFINE_SPINLOCK(parameters_lock);
1365 void tegra_cluster_switch_set_parameters(unsigned int us, unsigned int flags)
1367 spin_lock(¶meters_lock);
1369 switch_flags = flags;
1370 spin_unlock(¶meters_lock);
1374 static int tegra21_cpu_cmplx_clk_enable(struct clk *c)
1379 static void tegra21_cpu_cmplx_clk_disable(struct clk *c)
1381 pr_debug("%s on clock %s\n", __func__, c->name);
1383 /* oops - don't disable the CPU complex clock! */
1387 static int tegra21_cpu_cmplx_clk_set_rate(struct clk *c, unsigned long rate)
1389 unsigned long flags;
1391 struct clk *parent = c->parent;
1393 if (!parent->ops || !parent->ops->set_rate)
1396 clk_lock_save(parent, &flags);
1398 ret = clk_set_rate_locked(parent, rate);
1400 clk_unlock_restore(parent, &flags);
1405 static int cpu_cmplx_find_edp_safe_rates(unsigned long rate,
1406 struct clk *c_from, unsigned long *rate_from,
1407 struct clk *c_to, unsigned long *rate_to)
1410 *rate_from = rate; /* current rate is EDP safe on current cluster */
1411 *rate_to = clk_get_cpu_edp_safe_rate(c_to);
1413 /* EDP safe rate on target cluster is not specified: iso rate switch */
1414 if (*rate_to == 0) {
1415 rate = max(rate, c_to->min_rate);
1416 rate = min(rate, c_to->max_rate);
1417 BUG_ON((rate < c_from->min_rate) || (rate > c_from->max_rate));
1423 /* Determine EDP safe rates, given DVFS voltage interdependencies */
1424 ret = tegra_dvfs_butterfly_throttle(c_from, rate_from, c_to, rate_to);
1428 if ((*rate_from < c_from->min_rate) ||
1429 (*rate_from > c_from->max_rate)) {
1430 pr_err("%s: EDP safe %s rate %lu out of range (%lu %lu)\n",
1431 __func__, c_from->name, *rate_from,
1432 c_from->min_rate, c_from->max_rate);
1436 if ((*rate_to < c_to->min_rate) || (*rate_to > c_to->max_rate)) {
1437 pr_err("%s: EDP safe %s rate %lu out of range (%lu %lu)\n",
1438 __func__, c_to->name, *rate_to,
1439 c_to->min_rate, c_to->max_rate);
1446 static int cpu_cmplx_set_rate_from(struct clk *c_from, unsigned long rate_from,
1447 unsigned long rate, struct clk **c_source)
1449 if (rate_from != rate) {
1450 int ret = clk_set_rate(c_from, rate_from);
1452 pr_err("%s: Failed to set rate %lu for %s\n",
1453 __func__, rate_from, c_from->name);
1456 *c_source = c_from->parent->parent;
1461 static int tegra21_cpu_cmplx_clk_set_parent(struct clk *c, struct clk *p)
1464 unsigned int flags = 0, delay = 0;
1465 const struct clk_mux_sel *sel;
1466 unsigned long rate_from, rate_to;
1467 unsigned long rate = clk_get_rate(c->parent);
1468 struct clk *dfll = c->parent->u.cpu.dynamic ? : p->u.cpu.dynamic;
1469 struct clk *c_source, *p_source;
1472 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
1474 WARN(1, "%s: cpu refcnt is 0: aborted switch from %s to %s\n",
1475 __func__, c->parent->name, p->name);
1478 BUG_ON(c->parent->u.cpu.mode != (is_lp_cluster() ? MODE_LP : MODE_G));
1480 for (sel = c->inputs; sel->input != NULL; sel++) {
1481 if (sel->input == p)
1487 #if PARAMETERIZE_CLUSTER_SWITCH
1488 spin_lock(¶meters_lock);
1489 flags = switch_flags;
1490 delay = switch_delay;
1492 spin_unlock(¶meters_lock);
1495 flags = TEGRA_POWER_CLUSTER_IMMEDIATE;
1496 flags |= TEGRA_POWER_CLUSTER_PART_DEFAULT;
1499 flags |= (p->u.cpu.mode == MODE_LP) ? TEGRA_POWER_CLUSTER_LP :
1500 TEGRA_POWER_CLUSTER_G;
1502 if (p == c->parent) {
1503 if (flags & TEGRA_POWER_CLUSTER_FORCE) {
1504 /* Allow parameterized switch to the same mode */
1505 ret = tegra_cluster_control(delay, flags);
1507 pr_err("%s: Failed to force %s mode to %s\n",
1508 __func__, c->name, p->name);
1511 return 0; /* already switched - exit */
1514 /* Find EDP safe rates for switch */
1515 ret = cpu_cmplx_find_edp_safe_rates(
1516 rate, c->parent, &rate_from, p, &rate_to);
1518 pr_err("%s: Didn't find EDP safe rates for %s to %s switch\n",
1519 __func__, c->parent->name, p->name);
1523 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, true);
1524 c_source = c->parent->parent->parent;
1525 dfll_range_to = p->dvfs && tegra_dvfs_is_dfll_range(p->dvfs, rate_to);
1526 if (c_source == dfll) {
1528 * G (DFLL selected as clock source) => LP switch:
1529 * - set EDP safe rate on current cluster
1530 * - turn DFLL into open loop mode ("release" VDD_CPU rail)
1531 * - select target p_source for LP, and get EDP safe rate ready
1533 ret = cpu_cmplx_set_rate_from(c->parent, rate_from, rate,
1538 ret = tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 0);
1542 p_source = rate_to <= p->u.cpu.backup_rate ?
1543 p->u.cpu.backup : p->u.cpu.main;
1544 ret = clk_set_rate(p_source, rate_to);
1547 } else if ((p->parent->parent == dfll) || dfll_range_to) {
1549 * LP => G (DFLL selected as clock source) switch:
1550 * - set EDP safe rate on current cluster
1551 * - select target p_source as dfll, and set DFLL rate ready.
1552 * DFLL is still disabled, initial rate only set skipper so
1553 * that when enabled in open loop DFLL is running at low EDP
1554 * safe rate. In case when the entire G cluster rate range is
1555 * sourced from DFLL any EDP safe rate also guarantees voltage
1556 * above DFLL Vmin. In case when there is low PLL sourced rate
1557 * range, we need explicitly apply DFLL rate floor, which may
1558 * violate EDP limitations. Only former case is productized on
1561 ret = cpu_cmplx_set_rate_from(c->parent, rate_from, rate,
1566 BUG_ON(!dfll_range_to);
1569 ret = clk_set_rate(dfll, dfll_range_to ? rate_to :
1570 max(rate_to, p->dvfs->dfll_data.use_dfll_rate_min));
1575 * DFLL is not selected on either side of the switch:
1576 * - set common EDP safe rate (since we use the same PLL on
1577 * both clusters in this case)
1578 * - set target p_source equal to current clock source
1580 rate_from = min(rate_from, rate_to);
1581 if ((rate_from < c->parent->min_rate) ||
1582 (rate_from < p->min_rate)) {
1583 pr_err("%s: common EDP safe rate %lu out of range\n",
1584 __func__, rate_from);
1589 ret = cpu_cmplx_set_rate_from(c->parent, rate_from, rate,
1594 p_source = c_source;
1597 /* Switch new parent to target clock source if necessary */
1598 if (p->parent->parent != p_source) {
1599 ret = clk_set_parent(p->parent, p_source);
1601 pr_err("%s: Failed to set parent %s for %s\n",
1602 __func__, p_source->name, p->name);
1608 * G=>LP switch with c_source DFLL in open loop mode: restore legacy
1609 * DVFS rail control with no changes in voltage (DFLL is still sourcing
1610 * G cluster, and no need to bump up voltage to PLLX V/F curve); then
1611 * enabling new parent (LP cluster clock) will set voltage to the max of
1612 * G-on-DFLL and LP-on-PLLX required levels.
1614 * For any other combination of sources, rail is already under legacy
1615 * DVFS control, and enabling new parent scales new mode voltage rail
1616 * in advance before the switch happens. If target p_source is DFLL it
1617 * is switched here to open loop mode.
1619 if (c_source == dfll)
1620 tegra_dvfs_dfll_mode_clear(c->parent->dvfs, 0);
1622 ret = tegra_clk_prepare_enable(p);
1624 pr_err("%s: Failed to enable parent clock %s\n",
1629 pr_debug("%s: switch %s(rate %lu) to %s(rate %lu) at %d mV\n", __func__,
1630 c->parent->name, clk_get_rate(c->parent),
1631 p->name, clk_get_rate(p),
1632 tegra_dvfs_rail_get_current_millivolts(tegra_cpu_rail));
1634 /* switch CPU mode */
1635 ret = tegra_cluster_control(delay, flags);
1637 tegra_clk_disable_unprepare(p);
1638 pr_err("%s: Failed to switch %s mode to %s\n",
1639 __func__, c->name, p->name);
1644 * Lock DFLL now (resume closed loop VDD_CPU control).
1645 * G CPU operations are resumed on DFLL if it was the last G CPU
1646 * clock source, or if resume rate is in DFLL usage range in case
1647 * when auto-switch between PLL and DFLL is enabled.
1649 if (p_source == dfll) {
1650 clk_set_rate(dfll, rate_to);
1651 tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 1);
1652 tegra_dvfs_dfll_mode_set(p->dvfs, rate_to);
1655 /* Disabling old parent scales old mode voltage rail */
1656 tegra_clk_disable_unprepare(c->parent);
1660 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1664 /* Restore rate, and re-lock DFLL if necessary after aborted switch */
1665 clk_set_rate(c->parent, rate);
1666 if (c_source == dfll) {
1667 tegra_clk_cfg_ex(dfll, TEGRA_CLK_DFLL_LOCK, 1);
1668 tegra_dvfs_dfll_mode_set(c->parent->dvfs, rate);
1670 tegra_dvfs_rail_mode_updating(tegra_cpu_rail, false);
1672 pr_err("%s: aborted switch from %s to %s\n",
1673 __func__, c->parent->name, p->name);
1677 static long tegra21_cpu_cmplx_round_rate(struct clk *c,
1680 return clk_round_rate(c->parent, rate);
1683 static struct clk_ops tegra_cpu_cmplx_ops = {
1684 .init = tegra21_cpu_cmplx_clk_init,
1685 .enable = tegra21_cpu_cmplx_clk_enable,
1686 .disable = tegra21_cpu_cmplx_clk_disable,
1687 .set_rate = tegra21_cpu_cmplx_clk_set_rate,
1688 .set_parent = tegra21_cpu_cmplx_clk_set_parent,
1689 .round_rate = tegra21_cpu_cmplx_round_rate,
1692 /* virtual cop clock functions. Used to acquire the fake 'cop' clock to
1693 * reset the COP block (i.e. AVP) */
1694 static void tegra21_cop_clk_reset(struct clk *c, bool assert)
1696 unsigned long reg = assert ? RST_DEVICES_SET_L : RST_DEVICES_CLR_L;
1698 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
1699 clk_writel(1 << 1, reg);
1702 static struct clk_ops tegra_cop_ops = {
1703 .reset = tegra21_cop_clk_reset,
1706 /* bus clock functions */
1707 static DEFINE_SPINLOCK(bus_clk_lock);
1709 static int bus_set_div(struct clk *c, int div)
1712 unsigned long flags;
1714 if (!div || (div > (BUS_CLK_DIV_MASK + 1)))
1717 spin_lock_irqsave(&bus_clk_lock, flags);
1718 val = clk_readl(c->reg);
1719 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
1720 val |= (div - 1) << c->reg_shift;
1721 clk_writel(val, c->reg);
1723 spin_unlock_irqrestore(&bus_clk_lock, flags);
1728 static void tegra21_bus_clk_init(struct clk *c)
1730 u32 val = clk_readl(c->reg);
1731 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
1732 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
1736 static int tegra21_bus_clk_enable(struct clk *c)
1738 u32 val = clk_readl(c->reg);
1739 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
1740 clk_writel(val, c->reg);
1744 static void tegra21_bus_clk_disable(struct clk *c)
1746 u32 val = clk_readl(c->reg);
1747 val |= BUS_CLK_DISABLE << c->reg_shift;
1748 clk_writel(val, c->reg);
1751 static int tegra21_bus_clk_set_rate(struct clk *c, unsigned long rate)
1753 unsigned long parent_rate = clk_get_rate(c->parent);
1756 for (i = 1; i <= 4; i++) {
1757 if (rate >= parent_rate / i)
1758 return bus_set_div(c, i);
1763 static struct clk_ops tegra_bus_ops = {
1764 .init = tegra21_bus_clk_init,
1765 .enable = tegra21_bus_clk_enable,
1766 .disable = tegra21_bus_clk_disable,
1767 .set_rate = tegra21_bus_clk_set_rate,
1771 * Virtual system bus complex clock is used to hide the sequence of
1772 * changing sclk/hclk/pclk parents and dividers to configure requested
1775 #define BUS_AHB_DIV_MAX (BUS_CLK_DIV_MASK + 1UL)
1776 #define BUS_APB_DIV_MAX (BUS_CLK_DIV_MASK + 1UL)
1778 static unsigned long sclk_pclk_unity_ratio_rate_max = 136000000;
1780 struct clk_div_sel {
1785 static struct clk_div_sel sbus_round_table[MAX_DVFS_FREQS + 1];
1786 static int sbus_round_table_size;
1788 static int last_round_idx;
1789 static int get_start_idx(unsigned long rate)
1791 int i = last_round_idx;
1792 if (rate == sbus_round_table[i].rate)
1798 static void tegra21_sbus_cmplx_init(struct clk *c)
1801 struct clk *sclk_div = c->parent->parent;
1803 c->max_rate = sclk_div->max_rate;
1804 c->min_rate = sclk_div->min_rate;
1806 rate = clk_get_rate(c->u.system.sclk_low);
1807 if (tegra_platform_is_qt())
1811 * Unity and low range thresholds must be an exact proper factors of
1812 * low range parent. Unity threshold must be set within low range
1814 if (c->u.system.threshold &&
1815 (sclk_pclk_unity_ratio_rate_max > c->u.system.threshold))
1816 sclk_pclk_unity_ratio_rate_max = c->u.system.threshold;
1817 if (sclk_pclk_unity_ratio_rate_max)
1818 BUG_ON((rate % sclk_pclk_unity_ratio_rate_max) != 0);
1819 if (c->u.system.threshold)
1820 BUG_ON((rate % c->u.system.threshold) != 0);
1821 BUG_ON(!(sclk_div->flags & DIV_U71));
1824 /* This special sbus round function is implemented because:
1826 * (a) sbus complex clock source is selected automatically based on rate
1828 * (b) since sbus is a shared bus, and its frequency is set to the highest
1829 * enabled shared_bus_user clock, the target rate should be rounded up divider
1830 * ladder (if max limit allows it) - for pll_div and peripheral_div common is
1831 * rounding down - special case again.
1833 * Note that final rate is trimmed (not rounded up) to avoid spiraling up in
1834 * recursive calls. Lost 1Hz is added in tegra21_sbus_cmplx_set_rate before
1835 * actually setting divider rate.
1837 static void sbus_build_round_table_one(struct clk *c, unsigned long rate, int j)
1839 struct clk_div_sel sel;
1840 struct clk *sclk_div = c->parent->parent;
1841 u32 flags = sclk_div->flags;
1843 sel.src = c->u.system.sclk_low;
1844 sel.rate = fixed_src_bus_round_updown(
1845 c, sel.src, flags, rate, false, &sel.div);
1846 sbus_round_table[j] = sel;
1848 /* Don't use high frequency source above threshold */
1849 if (rate <= c->u.system.threshold)
1852 sel.src = c->u.system.sclk_high;
1853 sel.rate = fixed_src_bus_round_updown(
1854 c, sel.src, flags, rate, false, &sel.div);
1855 if (sbus_round_table[j].rate < sel.rate)
1856 sbus_round_table[j] = sel;
1859 /* Populate sbus (not Avalon) round table with dvfs entries (not knights) */
1860 static void sbus_build_round_table(struct clk *c)
1864 bool inserted_u = false;
1865 bool inserted_t = false;
1866 unsigned long threshold = c->u.system.threshold;
1869 * Make sure unity ratio threshold always inserted into the table.
1870 * If no dvfs specified, just add maximum rate entry. Othrwise, add
1871 * entries for all dvfs rates.
1873 if (!c->dvfs || !c->dvfs->num_freqs) {
1874 sbus_build_round_table_one(
1875 c, sclk_pclk_unity_ratio_rate_max, j++);
1876 sbus_build_round_table_one(c, threshold, j++);
1877 sbus_build_round_table_one(c, c->max_rate, j++);
1878 sbus_round_table_size = j;
1882 for (i = 0; i < c->dvfs->num_freqs; i++) {
1883 rate = c->dvfs->freqs[i];
1884 if (rate <= 1 * c->dvfs->freqs_mult)
1885 continue; /* skip 1kHz place holders */
1887 if (i && (rate == c->dvfs->freqs[i - 1]))
1888 continue; /* skip duplicated rate */
1890 if (!inserted_u && (rate >= sclk_pclk_unity_ratio_rate_max)) {
1892 if (sclk_pclk_unity_ratio_rate_max == threshold)
1895 if (rate > sclk_pclk_unity_ratio_rate_max)
1896 sbus_build_round_table_one(
1897 c, sclk_pclk_unity_ratio_rate_max, j++);
1899 if (!inserted_t && (rate >= threshold)) {
1901 if (rate > threshold)
1902 sbus_build_round_table_one(c, threshold, j++);
1904 sbus_build_round_table_one(c, rate, j++);
1906 sbus_round_table_size = j;
1909 /* Clip requested rate to the entry in the round table. Allow +/-1Hz slack. */
1910 static long tegra21_sbus_cmplx_round_updown(struct clk *c, unsigned long rate,
1915 if (!sbus_round_table_size) {
1916 sbus_build_round_table(c);
1917 if (!sbus_round_table_size) {
1918 WARN(1, "Invalid sbus round table\n");
1923 rate = max(rate, c->min_rate);
1925 i = get_start_idx(rate);
1926 for (; i < sbus_round_table_size - 1; i++) {
1927 unsigned long sel_rate = sbus_round_table[i].rate;
1928 if (abs(rate - sel_rate) <= 1) {
1930 } else if (rate < sel_rate) {
1937 return sbus_round_table[i].rate;
1940 static long tegra21_sbus_cmplx_round_rate(struct clk *c, unsigned long rate)
1942 return tegra21_sbus_cmplx_round_updown(c, rate, true);
1946 * Select {source : divider} setting from pre-built round table, and actually
1947 * change the configuration. Since voltage during switch is at safe level for
1948 * current and new sbus rates (but not above) over-clocking during the switch
1949 * is not allowed. Hence, the order of switch: 1st change divider if its setting
1950 * increases, then switch source clock, and finally change divider if it goes
1951 * down. No over-clocking is guaranteed, but dip below both initial and final
1952 * rates is possible.
1954 static int tegra21_sbus_cmplx_set_rate(struct clk *c, unsigned long rate)
1957 struct clk *skipper = c->parent;
1958 struct clk *sclk_div = skipper->parent;
1959 struct clk *sclk_mux = sclk_div->parent;
1960 struct clk_div_sel *new_sel = NULL;
1961 unsigned long sclk_div_rate = clk_get_rate(sclk_div);
1964 * Configure SCLK/HCLK/PCLK guranteed safe combination:
1965 * - keep hclk at the same rate as sclk
1966 * - set pclk at 1:2 rate of hclk
1967 * - disable sclk skipper
1969 bus_set_div(c->u.system.pclk, 2);
1970 bus_set_div(c->u.system.hclk, 1);
1971 c->child_bus->child_bus->div = 2;
1972 c->child_bus->div = 1;
1973 clk_set_rate(skipper, c->max_rate);
1975 /* Select new source/divider */
1976 i = get_start_idx(rate);
1977 for (; i < sbus_round_table_size; i++) {
1978 if (rate == sbus_round_table[i].rate) {
1979 new_sel = &sbus_round_table[i];
1986 if (sclk_div_rate == rate) {
1987 pr_debug("sbus_set_rate: no change in rate %lu on parent %s\n",
1988 clk_get_rate_locked(c), sclk_mux->parent->name);
1992 /* Raise voltage on the way up */
1993 if (c->dvfs && (rate > sclk_div_rate)) {
1994 ret = tegra_dvfs_set_rate(c, rate);
1997 pr_debug("sbus_set_rate: set %d mV\n", c->dvfs->cur_millivolts);
2001 if (sclk_div->div < new_sel->div) {
2002 unsigned long sdiv_rate = sclk_div_rate * sclk_div->div;
2003 sdiv_rate = DIV_ROUND_UP(sdiv_rate, new_sel->div);
2004 ret = clk_set_rate(sclk_div, sdiv_rate);
2006 pr_err("%s: Failed to set %s rate to %lu\n",
2007 __func__, sclk_div->name, sdiv_rate);
2010 pr_debug("sbus_set_rate: rate %lu on parent %s\n",
2011 clk_get_rate_locked(c), sclk_mux->parent->name);
2015 if (new_sel->src != sclk_mux->parent) {
2016 ret = clk_set_parent(sclk_mux, new_sel->src);
2018 pr_err("%s: Failed to switch sclk source to %s\n",
2019 __func__, new_sel->src->name);
2022 pr_debug("sbus_set_rate: rate %lu on parent %s\n",
2023 clk_get_rate_locked(c), sclk_mux->parent->name);
2026 if (sclk_div->div > new_sel->div) {
2027 ret = clk_set_rate(sclk_div, rate + 1);
2029 pr_err("%s: Failed to set %s rate to %lu\n",
2030 __func__, sclk_div->name, rate);
2033 pr_debug("sbus_set_rate: rate %lu on parent %s\n",
2034 clk_get_rate_locked(c), sclk_mux->parent->name);
2037 /* Lower voltage on the way down */
2038 if (c->dvfs && (rate < sclk_div_rate)) {
2039 ret = tegra_dvfs_set_rate(c, rate);
2042 pr_debug("sbus_set_rate: set %d mV\n", c->dvfs->cur_millivolts);
2049 * Limitations on SCLK/HCLK/PCLK ratios:
2050 * (A) H/w limitation:
2051 * if SCLK >= 136MHz, SCLK:PCLK >= 2
2052 * (B) S/w policy limitation, in addition to (A):
2053 * if any APB bus shared user request is enabled, HCLK:PCLK >= 2
2054 * Reason for (B): assuming APB bus shared user has requested X < 136MHz,
2055 * HCLK = PCLK = X, and new AHB user is coming on-line requesting Y >= 136MHz,
2056 * we can consider 2 paths depending on order of changing HCLK rate and
2058 * (i) HCLK:PCLK = X:X => Y:Y* => Y:Y/2, (*) violates rule (A)
2059 * (ii) HCLK:PCLK = X:X => X:X/2* => Y:Y/2, (*) under-clocks APB user
2060 * In this case we can not guarantee safe transition from HCLK:PCLK = 1:1
2061 * below 60MHz to HCLK rate above 60MHz without under-clocking APB user.
2062 * Hence, policy (B).
2064 * When there are no request from APB users, path (ii) can be used to
2065 * increase HCLK above 136MHz, and HCLK:PCLK = 1:1 is allowed.
2067 * Note: with common divider used in the path for all SCLK sources SCLK rate
2068 * during switching may dip down, anyway. So, in general, policy (ii) does not
2069 * prevent underclocking users during clock transition.
2071 static int tegra21_clk_sbus_update(struct clk *bus)
2075 unsigned long s_rate, h_rate, p_rate, ceiling, s_rate_raw;
2076 struct clk *ahb, *apb;
2077 struct clk *skipper = bus->parent;
2079 if (detach_shared_bus)
2082 s_rate = tegra21_clk_shared_bus_update(bus, &ahb, &apb, &ceiling);
2083 if (bus->override_rate) {
2084 ret = clk_set_rate_locked(bus, s_rate);
2086 clk_set_rate(skipper, s_rate);
2090 ahb = bus->child_bus;
2091 apb = ahb->child_bus;
2092 h_rate = ahb->u.shared_bus_user.rate;
2093 p_rate = apb->u.shared_bus_user.rate;
2094 p_requested = apb->refcnt > 1;
2096 /* Propagate ratio requirements up from PCLK to SCLK */
2098 h_rate = max(h_rate, p_rate * 2);
2099 s_rate = max(s_rate, h_rate);
2100 if (s_rate >= sclk_pclk_unity_ratio_rate_max)
2101 s_rate = max(s_rate, p_rate * 2);
2103 /* Propagate cap requirements down from SCLK to PCLK */
2104 s_rate_raw = s_rate;
2105 s_rate = tegra21_clk_cap_shared_bus(bus, s_rate, ceiling);
2106 if (s_rate >= sclk_pclk_unity_ratio_rate_max)
2107 p_rate = min(p_rate, s_rate / 2);
2108 h_rate = min(h_rate, s_rate);
2110 p_rate = min(p_rate, h_rate / 2);
2113 /* Set new sclk rate in safe 1:1:2, rounded "up" configuration */
2114 ret = clk_set_rate_locked(bus, s_rate);
2117 clk_set_rate(skipper, s_rate_raw);
2119 /* Finally settle new bus divider values */
2120 s_rate = clk_get_rate_locked(bus);
2121 div = min(s_rate / h_rate, BUS_AHB_DIV_MAX);
2123 bus_set_div(bus->u.system.hclk, div);
2127 h_rate = clk_get_rate(bus->u.system.hclk);
2128 div = min(h_rate / p_rate, BUS_APB_DIV_MAX);
2130 bus_set_div(bus->u.system.pclk, div);
2137 static struct clk_ops tegra_sbus_cmplx_ops = {
2138 .init = tegra21_sbus_cmplx_init,
2139 .set_rate = tegra21_sbus_cmplx_set_rate,
2140 .round_rate = tegra21_sbus_cmplx_round_rate,
2141 .round_rate_updown = tegra21_sbus_cmplx_round_updown,
2142 .shared_bus_update = tegra21_clk_sbus_update,
2146 * Virtual ADSP bus clock operations. Used to hide the sequence of changing
2147 * and re-locking ADSP source PLLA1 in flight to configure requested ADSP
2150 static void tegra21_adsp_bus_clk_init(struct clk *c)
2152 c->state = c->parent->state;
2153 c->min_rate = c->u.cpu.main->min_rate;
2156 static int tegra21_adsp_bus_clk_enable(struct clk *c)
2161 static void tegra21_adsp_bus_clk_disable(struct clk *c)
2165 static int tegra21_adsp_bus_clk_set_rate(struct clk *c, unsigned long rate)
2168 struct clk *main_pll = c->u.cpu.main;
2171 * If ADSP clock is disabled or it is not on main pll (may happen after
2172 * boot), set main pll rate, and make sure it is selected as adsp clock
2175 if (!c->refcnt || (c->parent->parent != main_pll)) {
2176 ret = clk_set_rate(main_pll, rate);
2178 pr_err("Failed to set adsp rate %lu on %s\n",
2179 rate, main_pll->name);
2183 if (c->parent->parent == main_pll)
2186 ret = clk_set_parent(c->parent, main_pll);
2188 pr_err("Failed to switch adsp to %s\n", main_pll->name);
2194 * Take an extra reference to the main pll so it doesn't turn off when
2195 * we move the cpu off of it. If possible, use main pll dynamic ramp
2196 * to reach target rate in one shot. Otherwise use backup source while
2199 tegra_clk_prepare_enable(main_pll);
2201 if (tegra_pll_can_ramp_to_rate(main_pll, rate)) {
2202 ret = clk_set_rate(main_pll, rate);
2204 pr_err("Failed to ramp %s to adsp rate %lu\n",
2205 main_pll->name, rate);
2209 /* Set backup divider, and switch to backup source */
2210 super_clk_set_u71_div_no_skip(c->parent);
2211 ret = clk_set_parent(c->parent, c->u.cpu.backup);
2213 super_clk_clr_u71_div_no_skip(c->parent);
2214 pr_err("Failed to switch adsp to %s\n", c->u.cpu.backup->name);
2218 /* Set main pll rate, switch back to main, and clear backup divider */
2219 ret = clk_set_rate(main_pll, rate);
2221 pr_err("Failed set adsp rate %lu on %s\n",
2222 rate, main_pll->name);
2226 ret = clk_set_parent(c->parent, main_pll);
2228 pr_err("Failed to switch adsp to %s\n", main_pll->name);
2231 super_clk_clr_u71_div_no_skip(c->parent);
2234 tegra_clk_disable_unprepare(main_pll);
2238 static long tegra21_adsp_bus_clk_round_rate(struct clk *c, unsigned long rate)
2240 if (rate > c->max_rate)
2242 else if (rate < c->min_rate)
2247 /* Blink output functions */
2248 static void tegra21_blink_clk_init(struct clk *c)
2252 val = pmc_readl(PMC_CTRL);
2253 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
2255 val = pmc_readl(c->reg);
2257 if (val & PMC_BLINK_TIMER_ENB) {
2258 unsigned int on_off;
2260 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
2261 PMC_BLINK_TIMER_DATA_ON_MASK;
2262 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
2263 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
2265 /* each tick in the blink timer is 4 32KHz clocks */
2266 c->div = on_off * 4;
2272 static int tegra21_blink_clk_enable(struct clk *c)
2276 val = pmc_readl(PMC_DPD_PADS_ORIDE);
2277 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
2279 val = pmc_readl(PMC_CTRL);
2280 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
2281 pmc_readl(PMC_CTRL);
2286 static void tegra21_blink_clk_disable(struct clk *c)
2290 val = pmc_readl(PMC_CTRL);
2291 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
2293 val = pmc_readl(PMC_DPD_PADS_ORIDE);
2294 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
2295 pmc_readl(PMC_DPD_PADS_ORIDE);
2298 static int tegra21_blink_clk_set_rate(struct clk *c, unsigned long rate)
2300 unsigned long parent_rate = clk_get_rate(c->parent);
2301 if (rate >= parent_rate) {
2303 pmc_writel(0, c->reg);
2305 unsigned int on_off;
2308 on_off = DIV_ROUND_UP(parent_rate / 8, rate);
2309 c->div = on_off * 8;
2311 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
2312 PMC_BLINK_TIMER_DATA_ON_SHIFT;
2313 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
2314 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
2316 val |= PMC_BLINK_TIMER_ENB;
2317 pmc_writel(val, c->reg);
2324 static struct clk_ops tegra_blink_clk_ops = {
2325 .init = &tegra21_blink_clk_init,
2326 .enable = &tegra21_blink_clk_enable,
2327 .disable = &tegra21_blink_clk_disable,
2328 .set_rate = &tegra21_blink_clk_set_rate,
2331 /* UTMIP PLL configuration */
2332 static void tegra21_utmi_param_configure(struct clk *c)
2336 unsigned long main_rate =
2337 clk_get_rate(c->parent->parent);
2339 for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
2340 if (main_rate == utmi_parameters[i].osc_frequency) {
2345 if (i >= ARRAY_SIZE(utmi_parameters)) {
2346 pr_err("%s: Unexpected main rate %lu\n", __func__, main_rate);
2350 reg = clk_readl(UTMIPLL_HW_PWRDN_CFG0);
2351 reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE;
2352 pll_writel_delay(reg, UTMIPLL_HW_PWRDN_CFG0);
2354 reg = clk_readl(UTMIP_PLL_CFG2);
2355 /* Program UTMIP PLL stable and active counts */
2356 /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */
2357 reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
2358 reg |= UTMIP_PLL_CFG2_STABLE_COUNT(
2359 utmi_parameters[i].stable_count);
2360 clk_writel(reg, UTMIP_PLL_CFG2);
2362 /* Program UTMIP PLL delay and oscillator frequency counts */
2363 reg = clk_readl(UTMIP_PLL_CFG1);
2364 reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
2365 reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(
2366 utmi_parameters[i].enable_delay_count);
2368 reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
2369 reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(
2370 utmi_parameters[i].xtal_freq_count);
2372 /* Remove power downs from UTMIP PLL control bits */
2373 reg |= UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
2374 clk_writel(reg, UTMIP_PLL_CFG1);
2376 /* Enable PLL with SW programming */
2377 reg = clk_readl(UTMIP_PLL_CFG1);
2378 reg |= UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
2379 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
2380 pll_writel_delay(reg, UTMIP_PLL_CFG1);
2382 /* Enable Samplers for SNPS IP, XUSB_HOST, XUSB_DEV */
2383 reg = clk_readl(UTMIP_PLL_CFG2);
2384 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP;
2385 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP;
2386 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP;
2387 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
2388 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
2389 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN;
2390 clk_writel(reg, UTMIP_PLL_CFG2);
2392 /* Enable HW Power Sequencer */
2393 reg = clk_readl(UTMIP_PLL_CFG1);
2394 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP;
2395 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
2396 clk_writel(reg, UTMIP_PLL_CFG1);
2398 reg = clk_readl(UTMIPLL_HW_PWRDN_CFG0);
2399 reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL;
2400 reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET;
2401 pll_writel_delay(reg, UTMIPLL_HW_PWRDN_CFG0);
2403 reg = clk_readl(XUSB_PLL_CFG0);
2404 reg &= ~XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY;
2405 pll_writel_delay(reg, XUSB_PLL_CFG0);
2407 /* Enable HW control UTMIPLL */
2408 reg = clk_readl(UTMIPLL_HW_PWRDN_CFG0);
2409 reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE;
2410 pll_writel_delay(reg, UTMIPLL_HW_PWRDN_CFG0);
2414 * PLL post divider maps - two types: quasi-linear and exponential
2417 #define PLL_QLIN_PDIV_MAX 16
2418 static u8 pll_qlin_pdiv_to_p[PLL_QLIN_PDIV_MAX + 1] = {
2419 /* PDIV: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 */
2420 /* p: */ 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 30, 32 };
2422 static u32 pll_qlin_p_to_pdiv(u32 p, u32 *pdiv)
2427 for (i = 0; i <= PLL_QLIN_PDIV_MAX; i++) {
2428 if (p <= pll_qlin_pdiv_to_p[i]) {
2431 return pll_qlin_pdiv_to_p[i];
2438 #define PLL_EXPO_PDIV_MAX 7
2439 static u8 pll_expo_pdiv_to_p[PLL_EXPO_PDIV_MAX + 1] = {
2440 /* PDIV: 0, 1, 2, 3, 4, 5, 6, 7 */
2441 /* p: */ 1, 2, 4, 8, 16, 32, 64, 128 };
2443 static u32 pll_expo_p_to_pdiv(u32 p, u32 *pdiv)
2450 if (i <= PLL_EXPO_PDIV_MAX) {
2460 * PLLCX: PLLC, PLLC2, PLLC3, PLLA1
2461 * Hybrid PLLs with dynamic ramp. Dynamic ramp is allowed for any transition
2462 * that changes NDIV only, while PLL is already locked.
2464 static void pllcx_check_defaults(struct clk *c, unsigned long input_rate)
2468 default_val = PLLCX_MISC0_DEFAULT_VALUE & (~PLLCX_MISC0_RESET);
2469 PLL_MISC_CHK_DEFAULT(c, 0, default_val, PLLCX_MISC0_WRITE_MASK);
2471 default_val = PLLCX_MISC1_DEFAULT_VALUE & (~PLLCX_MISC1_IDDQ);
2472 PLL_MISC_CHK_DEFAULT(c, 1, default_val, PLLCX_MISC1_WRITE_MASK);
2474 default_val = PLLCX_MISC2_DEFAULT_VALUE;
2475 PLL_MISC_CHK_DEFAULT(c, 2, default_val, PLLCX_MISC2_WRITE_MASK);
2477 default_val = PLLCX_MISC3_DEFAULT_VALUE;
2478 PLL_MISC_CHK_DEFAULT(c, 3, default_val, PLLCX_MISC3_WRITE_MASK);
2481 static void pllcx_set_defaults(struct clk *c, unsigned long input_rate)
2483 c->u.pll.defaults_set = true;
2485 if (clk_readl(c->reg) & c->u.pll.controls->enable_mask) {
2486 /* PLL is ON: only check if defaults already set */
2487 pllcx_check_defaults(c, input_rate);
2491 /* Defaults assert PLL reset, and set IDDQ */
2492 clk_writel(PLLCX_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
2493 clk_writel(PLLCX_MISC1_DEFAULT_VALUE, c->reg + c->u.pll.misc1);
2494 clk_writel(PLLCX_MISC2_DEFAULT_VALUE, c->reg + c->u.pll.misc2);
2495 pll_writel_delay(PLLCX_MISC3_DEFAULT_VALUE, c->reg + c->u.pll.misc3);
2498 #if PLLCX_USE_DYN_RAMP
2499 static int pllcx_dyn_ramp(struct clk *c, struct clk_pll_freq_table *cfg)
2502 struct clk_pll_controls *ctrl = c->u.pll.controls;
2503 struct clk_pll_div_layout *divs = c->u.pll.div_layout;
2505 u32 val = clk_readl(c->reg);
2506 val &= ~divs->ndiv_mask;
2507 val |= cfg->n << divs->ndiv_shift;
2508 pll_writel_delay(val, c->reg);
2510 reg = pll_reg_idx_to_addr(c, ctrl->lock_reg_idx);
2511 tegra_pll_clk_wait_for_lock(c, reg, ctrl->lock_mask);
2516 #define pllcx_dyn_ramp NULL
2519 static void tegra21_pllcx_clk_init(struct clk *c)
2521 tegra_pll_clk_init(c);
2524 static struct clk_ops tegra_pllcx_ops = {
2525 .init = tegra21_pllcx_clk_init,
2526 .enable = tegra_pll_clk_enable,
2527 .disable = tegra_pll_clk_disable,
2528 .set_rate = tegra_pll_clk_set_rate,
2533 * PLL with dynamic ramp and fractional SDM. Dynamic ramp is not used.
2534 * Fractional SDM is allowed to provide exact audio rates.
2536 static void plla_set_defaults(struct clk *c, unsigned long input_rate)
2539 u32 val = clk_readl(c->reg);
2540 c->u.pll.defaults_set = true;
2542 if (val & c->u.pll.controls->enable_mask) {
2544 * PLL is ON: check if defaults already set, then set those
2545 * that can be updated in flight.
2547 if (val & PLLA_BASE_IDDQ) {
2548 pr_warn("%s boot enabled with IDDQ set\n", c->name);
2549 c->u.pll.defaults_set = false;
2552 val = PLLA_MISC0_DEFAULT_VALUE; /* ignore lock enable */
2553 mask = PLLA_MISC0_LOCK_ENABLE | PLLA_MISC0_LOCK_OVERRIDE;
2554 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLA_MISC0_WRITE_MASK);
2556 val = PLLA_MISC2_DEFAULT_VALUE; /* ignore all but control bit */
2557 PLL_MISC_CHK_DEFAULT(c, 2, val, PLLA_MISC2_EN_DYNRAMP);
2559 /* Enable lock detect */
2560 val = clk_readl(c->reg + c->u.pll.misc0);
2562 val |= PLLA_MISC0_DEFAULT_VALUE & mask;
2563 pll_writel_delay(val, c->reg + c->u.pll.misc0);
2568 /* set IDDQ, enable lock detect, disable dynamic ramp and SDM */
2569 val |= PLLA_BASE_IDDQ;
2570 clk_writel(val, c->reg);
2571 clk_writel(PLLA_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
2572 pll_writel_delay(PLLA_MISC2_DEFAULT_VALUE, c->reg + c->u.pll.misc2);
2575 static void tegra21_plla_clk_init(struct clk *c)
2577 tegra_pll_clk_init(c);
2580 static struct clk_ops tegra_plla_ops = {
2581 .init = tegra21_plla_clk_init,
2582 .enable = tegra_pll_clk_enable,
2583 .disable = tegra_pll_clk_disable,
2584 .set_rate = tegra_pll_clk_set_rate,
2589 * PLL with fractional SDM.
2591 static void plld_set_defaults(struct clk *c, unsigned long input_rate)
2593 u32 val = clk_readl(c->reg);
2594 u32 mask = c->u.pll.div_layout->sdm_din_mask;
2596 c->u.pll.defaults_set = true;
2598 if (val & c->u.pll.controls->enable_mask) {
2600 * PLL is ON: check if defaults already set, then set those
2601 * that can be updated in flight.
2603 val = PLLD_MISC1_DEFAULT_VALUE;
2604 PLL_MISC_CHK_DEFAULT(c, 1, val, PLLD_MISC1_WRITE_MASK);
2606 /* ignore lock, DSI and SDM controls, make sure IDDQ not set */
2607 val = PLLD_MISC0_DEFAULT_VALUE & (~PLLD_MISC0_IDDQ);
2608 mask |= PLLD_MISC0_DSI_CLKENABLE | PLLD_MISC0_LOCK_ENABLE |
2609 PLLD_MISC0_LOCK_OVERRIDE | PLLD_MISC0_EN_SDM;
2610 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLD_MISC0_WRITE_MASK);
2612 /* Enable lock detect */
2613 mask = PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE;
2614 val = clk_readl(c->reg + c->u.pll.misc0);
2616 val |= PLLD_MISC0_DEFAULT_VALUE & mask;
2617 pll_writel_delay(val, c->reg + c->u.pll.misc0);
2622 /* set IDDQ, enable lock detect, disable SDM */
2623 val = clk_readl(c->reg + c->u.pll.misc0) & PLLD_MISC0_DSI_CLKENABLE;
2624 clk_writel(val | PLLD_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
2625 pll_writel_delay(PLLD_MISC1_DEFAULT_VALUE, c->reg + c->u.pll.misc1);
2628 static void tegra21_plld_clk_init(struct clk *c)
2630 tegra_pll_clk_init(c);
2634 tegra21_plld_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
2640 case TEGRA_CLK_PLLD_CSI_OUT_ENB:
2641 mask = PLLD_BASE_CSI_CLKSOURCE;
2644 case TEGRA_CLK_MIPI_CSI_OUT_ENB:
2646 clear = PLLD_BASE_CSI_CLKSOURCE;
2649 case TEGRA_CLK_PLLD_DSI_OUT_ENB:
2650 mask = PLLD_MISC0_DSI_CLKENABLE;
2651 reg = c->reg + c->u.pll.misc0;
2653 case TEGRA_CLK_PLLD_MIPI_MUX_SEL:
2654 mask = PLLD_BASE_DSI_MUX_MASK;
2661 val = clk_readl(reg);
2667 clk_writel(val, reg);
2671 static struct clk_ops tegra_plld_ops = {
2672 .init = tegra21_plld_clk_init,
2673 .enable = tegra_pll_clk_enable,
2674 .disable = tegra_pll_clk_disable,
2675 .set_rate = tegra_pll_clk_set_rate,
2676 .clk_cfg_ex = tegra21_plld_clk_cfg_ex,
2681 * PLL with fractional SDM and Spread Spectrum (SDM is a must if SSC is used).
2683 static void plldss_defaults(struct clk *c, u32 misc0_val, u32 misc1_val,
2684 u32 misc2_val, u32 misc3_val)
2687 u32 val = clk_readl(c->reg);
2688 c->u.pll.defaults_set = true;
2690 if (val & c->u.pll.controls->enable_mask) {
2692 * PLL is ON: check if defaults already set, then set those
2693 * that can be updated in flight.
2695 if (val & PLLDSS_BASE_IDDQ) {
2696 pr_warn("%s boot enabled with IDDQ set\n", c->name);
2697 c->u.pll.defaults_set = false;
2700 default_val = misc0_val;
2701 PLL_MISC_CHK_DEFAULT(c, 0, default_val, /* ignore lock enable */
2702 PLLDSS_MISC0_WRITE_MASK &
2703 (~PLLDSS_MISC0_LOCK_ENABLE));
2706 * If SSC is used, check all settings, otherwise just confirm
2707 * that SSC is not used on boot as well. Do nothing when using
2708 * this function for PLLC4 that has only MISC0.
2710 if (c->u.pll.controls->ssc_en_mask) {
2711 default_val = misc1_val;
2712 PLL_MISC_CHK_DEFAULT(c, 1, default_val,
2713 PLLDSS_MISC1_CFG_WRITE_MASK);
2714 default_val = misc2_val;
2715 PLL_MISC_CHK_DEFAULT(c, 2, default_val,
2716 PLLDSS_MISC2_CTRL1_WRITE_MASK);
2717 default_val = misc3_val;
2718 PLL_MISC_CHK_DEFAULT(c, 3, default_val,
2719 PLLDSS_MISC3_CTRL2_WRITE_MASK);
2720 } else if (c->u.pll.misc1) {
2721 default_val = misc1_val;
2722 PLL_MISC_CHK_DEFAULT(c, 1, default_val,
2723 PLLDSS_MISC1_CFG_WRITE_MASK &
2724 (~PLLDSS_MISC1_CFG_EN_SDM));
2727 /* Enable lock detect */
2728 if (val & PLLDSS_BASE_LOCK_OVERRIDE) {
2729 val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
2730 clk_writel(val, c->reg);
2733 val = clk_readl(c->reg + c->u.pll.misc0);
2734 val &= ~PLLDSS_MISC0_LOCK_ENABLE;
2735 val |= misc0_val & PLLDSS_MISC0_LOCK_ENABLE;
2736 pll_writel_delay(val, c->reg + c->u.pll.misc0);
2741 /* set IDDQ, enable lock detect, configure SDM/SSC */
2742 val |= PLLDSS_BASE_IDDQ;
2743 val &= ~PLLDSS_BASE_LOCK_OVERRIDE;
2744 clk_writel(val, c->reg);
2746 /* When using this function for PLLC4 exit here */
2747 if (!c->u.pll.misc1) {
2748 pll_writel_delay(misc0_val, c->reg + c->u.pll.misc0);
2752 clk_writel(misc0_val, c->reg + c->u.pll.misc0);
2753 clk_writel(misc1_val & (~PLLDSS_MISC1_CFG_EN_SSC),
2754 c->reg + c->u.pll.misc1); /* if SSC used set by 1st enable */
2755 clk_writel(misc2_val, c->reg + c->u.pll.misc2);
2756 pll_writel_delay(misc3_val, c->reg + c->u.pll.misc3);
2759 static void plldss_select_ref(struct clk *c)
2761 u32 val = clk_readl(c->reg);
2762 u32 ref = (val & PLLDSS_BASE_REF_SEL_MASK) >> PLLDSS_BASE_REF_SEL_SHIFT;
2765 * The only productized reference clock is tegra_pll_ref. Made sure
2766 * it is selected on boot. If pll is enabled, shut it down before
2767 * changing reference selection.
2770 if (val & c->u.pll.controls->enable_mask) {
2771 WARN(1, "%s boot enabled with not supported ref %u\n",
2773 val &= ~c->u.pll.controls->enable_mask;
2774 pll_writel_delay(val, c->reg);
2776 val &= ~PLLDSS_BASE_REF_SEL_MASK;
2777 pll_writel_delay(val, c->reg);
2781 static void plld2_set_defaults(struct clk *c, unsigned long input_rate)
2783 plldss_defaults(c, PLLD2_MISC0_DEFAULT_VALUE,
2784 PLLD2_MISC1_CFG_DEFAULT_VALUE,
2785 PLLD2_MISC2_CTRL1_DEFAULT_VALUE,
2786 PLLD2_MISC3_CTRL2_DEFAULT_VALUE);
2789 static void tegra21_plld2_clk_init(struct clk *c)
2791 if (PLLD2_MISC1_CFG_DEFAULT_VALUE & PLLDSS_MISC1_CFG_EN_SSC) {
2792 /* SSC requires SDM enabled */
2793 BUILD_BUG_ON(!(PLLD2_MISC1_CFG_DEFAULT_VALUE &
2794 PLLDSS_MISC1_CFG_EN_SDM));
2796 /* SSC should be disabled */
2797 c->u.pll.controls->ssc_en_mask = 0;
2799 plldss_select_ref(c);
2801 tegra_pll_clk_init(c);
2804 static struct clk_ops tegra_plld2_ops = {
2805 .init = tegra21_plld2_clk_init,
2806 .enable = tegra_pll_clk_enable,
2807 .disable = tegra_pll_clk_disable,
2808 .set_rate = tegra_pll_clk_set_rate,
2811 static void plldp_set_defaults(struct clk *c, unsigned long input_rate)
2813 plldss_defaults(c, PLLDP_MISC0_DEFAULT_VALUE,
2814 PLLDP_MISC1_CFG_DEFAULT_VALUE,
2815 PLLDP_MISC2_CTRL1_DEFAULT_VALUE,
2816 PLLDP_MISC3_CTRL2_DEFAULT_VALUE);
2819 static void tegra21_plldp_clk_init(struct clk *c)
2822 if (PLLDP_MISC1_CFG_DEFAULT_VALUE & PLLDSS_MISC1_CFG_EN_SSC) {
2823 /* SSC requires SDM enabled */
2824 BUILD_BUG_ON(!(PLLDP_MISC1_CFG_DEFAULT_VALUE &
2825 PLLDSS_MISC1_CFG_EN_SDM));
2827 /* SSC should be disabled */
2828 c->u.pll.controls->ssc_en_mask = 0;
2830 plldss_select_ref(c);
2832 tegra_pll_clk_init(c);
2835 static struct clk_ops tegra_plldp_ops = {
2836 .init = tegra21_plldp_clk_init,
2837 .enable = tegra_pll_clk_enable,
2838 .disable = tegra_pll_clk_disable,
2839 .set_rate = tegra_pll_clk_set_rate,
2844 * Base and misc0 layout is the same as PLLD2/PLLDP, but no SDM/SSC support.
2845 * VCO is exposed to the clock tree via fixed 1/3 and 1/5 dividers.
2847 static void pllc4_set_defaults(struct clk *c, unsigned long input_rate)
2849 plldss_defaults(c, PLLC4_MISC0_DEFAULT_VALUE, 0, 0, 0);
2852 static void tegra21_pllc4_vco_init(struct clk *c)
2854 unsigned long input_rate = clk_get_rate(c->parent);
2855 unsigned long cf = input_rate / pll_get_fixed_mdiv(c, input_rate);
2856 pllc4_set_fixed_rates(cf);
2858 plldss_select_ref(c);
2859 tegra_pll_clk_init(c);
2862 static struct clk_ops tegra_pllc4_vco_ops = {
2863 .init = tegra21_pllc4_vco_init,
2864 .enable = tegra_pll_clk_enable,
2865 .disable = tegra_pll_clk_disable,
2866 .set_rate = tegra_pll_clk_set_rate,
2871 * VCO is exposed to the clock tree directly along with post-divider output
2873 static void pllre_set_defaults(struct clk *c, unsigned long input_rate)
2876 u32 val = clk_readl(c->reg);
2877 c->u.pll.defaults_set = true;
2879 if (val & c->u.pll.controls->enable_mask) {
2881 * PLL is ON: check if defaults already set, then set those
2882 * that can be updated in flight.
2884 val &= PLLRE_BASE_DEFAULT_MASK;
2885 if (val != PLLRE_BASE_DEFAULT_VALUE) {
2886 pr_warn("%s boot base 0x%x : expected 0x%x\n",
2887 (c)->name, val, PLLRE_BASE_DEFAULT_VALUE);
2888 pr_warn("(comparison mask = 0x%x)\n",
2889 PLLRE_BASE_DEFAULT_MASK);
2890 c->u.pll.defaults_set = false;
2893 /* Ignore lock enable */
2894 val = PLLRE_MISC0_DEFAULT_VALUE & (~PLLRE_MISC0_IDDQ);
2895 mask = PLLRE_MISC0_LOCK_ENABLE | PLLRE_MISC0_LOCK_OVERRIDE;
2896 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLRE_MISC0_WRITE_MASK);
2898 /* Enable lock detect */
2899 val = clk_readl(c->reg + c->u.pll.misc0);
2901 val |= PLLRE_MISC0_DEFAULT_VALUE & mask;
2902 pll_writel_delay(val, c->reg + c->u.pll.misc0);
2907 /* set IDDQ, enable lock detect */
2908 val &= ~PLLRE_BASE_DEFAULT_MASK;
2909 val |= PLLRE_BASE_DEFAULT_VALUE & PLLRE_BASE_DEFAULT_MASK;
2910 clk_writel(val, c->reg);
2911 pll_writel_delay(PLLRE_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
2914 static void tegra21_pllre_vco_init(struct clk *c)
2916 tegra_pll_clk_init(c);
2919 static struct clk_ops tegra_pllre_vco_ops = {
2920 .init = tegra21_pllre_vco_init,
2921 .enable = tegra_pll_clk_enable,
2922 .disable = tegra_pll_clk_disable,
2923 .set_rate = tegra_pll_clk_set_rate,
2928 * VCO is exposed to the clock tree directly along with post-divider output.
2929 * Both VCO and post-divider output rates are fixed at 480MHz and 240MHz,
2932 static void pllu_check_defaults(struct clk *c, bool hw_control)
2936 /* Ignore lock enable (will be set) and IDDQ if under h/w control */
2937 val = PLLU_MISC0_DEFAULT_VALUE & (~PLLU_MISC0_IDDQ);
2938 mask = PLLU_MISC0_LOCK_ENABLE | (hw_control ? PLLU_MISC0_IDDQ : 0);
2939 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLU_MISC0_WRITE_MASK);
2941 val = PLLU_MISC1_DEFAULT_VALUE;
2942 mask = PLLU_MISC1_LOCK_OVERRIDE;
2943 PLL_MISC_CHK_DEFAULT(c, 1, val, ~mask & PLLU_MISC1_WRITE_MASK);
2946 static void pllu_set_defaults(struct clk *c, unsigned long input_rate)
2948 u32 val = clk_readl(c->reg);
2949 c->u.pll.defaults_set = true;
2951 if (val & c->u.pll.controls->enable_mask) {
2953 * PLL is ON: check if defaults already set, then set those
2954 * that can be updated in flight.
2956 pllu_check_defaults(c, false);
2958 /* Enable lock detect */
2959 val = clk_readl(c->reg + c->u.pll.misc0);
2960 val &= ~PLLU_MISC0_LOCK_ENABLE;
2961 val |= PLLU_MISC0_DEFAULT_VALUE & PLLU_MISC0_LOCK_ENABLE;
2962 pll_writel_delay(val, c->reg + c->u.pll.misc0);
2964 val = clk_readl(c->reg + c->u.pll.misc1);
2965 val &= ~PLLU_MISC1_LOCK_OVERRIDE;
2966 val |= PLLU_MISC1_DEFAULT_VALUE & PLLU_MISC1_LOCK_OVERRIDE;
2967 pll_writel_delay(val, c->reg + c->u.pll.misc1);
2972 /* set IDDQ, enable lock detect */
2973 clk_writel(PLLU_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
2974 pll_writel_delay(PLLU_MISC1_DEFAULT_VALUE, c->reg + c->u.pll.misc1);
2977 static void tegra21_pllu_vco_init(struct clk *c)
2979 u32 val = clk_readl(c->reg);
2983 * If PLLU state is already under h/w control just check defaults, and
2984 * verify expected fixed VCO rate (pll dividers can still be read from
2985 * the base register).
2987 if (!(val & PLLU_BASE_OVERRIDE)) {
2988 struct clk_pll_freq_table cfg = { };
2989 c->state = (val & c->u.pll.controls->enable_mask) ? ON : OFF;
2991 c->u.pll.defaults_set = true;
2992 pllu_check_defaults(c, true);
2993 pll_base_parse_cfg(c, &cfg);
2994 pll_clk_set_gain(c, &cfg);
2996 pll_clk_verify_fixed_rate(c);
2997 pr_info("%s: boot with h/w control already set\n", c->name);
3001 /* S/w controlled initialization */
3002 tegra_pll_clk_init(c);
3005 static void tegra21_pllu_hw_ctrl_set(struct clk *c)
3007 u32 val = clk_readl(c->reg);
3009 /* Put PLLU under h/w control (if not already) */
3010 if (val & PLLU_BASE_OVERRIDE) {
3011 val &= ~PLLU_BASE_OVERRIDE;
3012 pll_writel_delay(val, c->reg);
3014 val = clk_readl(PLLU_HW_PWRDN_CFG0);
3015 val |= PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE |
3016 PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT |
3017 PLLU_HW_PWRDN_CFG0_USE_LOCKDET;
3018 val &= ~(PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL |
3019 PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL);
3020 clk_writel(val, PLLU_HW_PWRDN_CFG0);
3022 val = clk_readl(XUSB_PLL_CFG0);
3023 val &= ~XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK;
3024 pll_writel_delay(val, XUSB_PLL_CFG0);
3026 val = clk_readl(PLLU_HW_PWRDN_CFG0);
3027 val |= PLLU_HW_PWRDN_CFG0_SEQ_ENABLE;
3028 pll_writel_delay(val, PLLU_HW_PWRDN_CFG0);
3031 /* Disable clock branch to UTMIP PLL (using OSC directly) */
3032 val = clk_readl(c->reg);
3033 val &= ~PLLU_BASE_CLKENABLE_USB;
3034 clk_writel(val, c->reg);
3036 /* Put UTMIP PLL under h/w control (if not already) */
3037 val = clk_readl(UTMIPLL_HW_PWRDN_CFG0);
3038 if (!(val & UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE))
3039 tegra21_utmi_param_configure(c);
3042 static int tegra21_pllu_clk_enable(struct clk *c)
3044 int ret = tegra_pll_clk_enable(c);
3048 tegra21_pllu_hw_ctrl_set(c);
3052 static struct clk_ops tegra_pllu_vco_ops = {
3053 .init = tegra21_pllu_vco_init,
3054 .enable = tegra21_pllu_clk_enable,
3055 .disable = tegra_pll_clk_disable,
3056 .set_rate = tegra_pll_clk_set_rate,
3061 * VCO is exposed to the clock tree directly along with post-divider output.
3062 * Both VCO and post-divider output rates are fixed at 408MHz and 204MHz,
3065 static void pllp_check_defaults(struct clk *c, bool enabled)
3069 /* Ignore lock enable (will be set), make sure not in IDDQ if enabled */
3070 val = PLLP_MISC0_DEFAULT_VALUE & (~PLLP_MISC0_IDDQ);
3071 mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
3073 mask |= PLLP_MISC0_IDDQ;
3074 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLP_MISC0_WRITE_MASK);
3076 /* Ignore branch controls */
3077 val = PLLP_MISC1_DEFAULT_VALUE;
3078 mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
3079 PLL_MISC_CHK_DEFAULT(c, 1, val, ~mask & PLLP_MISC1_WRITE_MASK);
3082 static void pllp_set_defaults(struct clk *c, unsigned long input_rate)
3085 u32 val = clk_readl(c->reg);
3086 c->u.pll.defaults_set = true;
3088 if (val & c->u.pll.controls->enable_mask) {
3090 * PLL is ON: check if defaults already set, then set those
3091 * that can be updated in flight.
3093 pllp_check_defaults(c, true);
3095 /* Enable lock detect */
3096 val = clk_readl(c->reg + c->u.pll.misc0);
3097 mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE;
3099 val |= PLLP_MISC0_DEFAULT_VALUE & mask;
3100 pll_writel_delay(val, c->reg + c->u.pll.misc0);
3105 /* set IDDQ, enable lock detect */
3106 clk_writel(PLLP_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
3108 /* Preserve branch control */
3109 val = clk_readl(c->reg + c->u.pll.misc1);
3110 mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
3112 val |= ~mask & PLLP_MISC1_DEFAULT_VALUE;
3113 pll_writel_delay(val, c->reg + c->u.pll.misc1);
3116 static void pllp_vco_init(struct clk *c)
3118 u32 val = clk_readl(c->reg);
3121 * If PLLP state is already under h/w control just check defaults, and
3122 * set expected fixed VCO rate (pll dividers cannot be read in this case
3123 * from the base register).
3125 if (!(val & PLLP_BASE_OVERRIDE)) {
3126 const struct clk_pll_freq_table *sel;
3127 unsigned long input_rate = clk_get_rate(c->parent);
3128 c->state = (val & c->u.pll.controls->enable_mask) ? ON : OFF;
3130 c->u.pll.defaults_set = true;
3131 pllp_check_defaults(c, c->state == ON);
3133 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
3134 if (sel->input_rate == input_rate &&
3135 sel->output_rate == c->u.pll.fixed_rate) {
3141 WARN(1, "%s: unexpected fixed rate %lu\n",
3142 c->name, c->u.pll.fixed_rate);
3144 c->mul = c->u.pll.fixed_rate / 100000;
3145 c->div = input_rate / 100000;
3146 pll_clk_verify_fixed_rate(c);
3150 /* S/w controlled initialization */
3151 tegra_pll_clk_init(c);
3154 static void tegra21_pllp_vco_init(struct clk *c)
3157 tegra21_pllp_init_dependencies(c->u.pll.fixed_rate);
3160 static struct clk_ops tegra_pllp_vco_ops = {
3161 .init = tegra21_pllp_vco_init,
3162 .enable = tegra_pll_clk_enable,
3163 .disable = tegra_pll_clk_disable,
3164 .set_rate = tegra_pll_clk_set_rate,
3169 * PLL with dynamic ramp and fractional SDM. Dynamic ramp is allowed for any
3170 * transition that changes NDIV only, while PLL is already locked. SDM is not
3171 * used and always disabled.
3173 static void pllx_get_dyn_steps(struct clk *c, unsigned long input_rate,
3174 u32 *step_a, u32 *step_b)
3176 input_rate /= pll_get_fixed_mdiv(c, input_rate); /* cf rate */
3177 switch (input_rate) {
3193 pr_err("%s: Unexpected reference rate %lu\n",
3194 __func__, input_rate);
3199 static void pllx_check_defaults(struct clk *c, unsigned long input_rate)
3203 default_val = PLLX_MISC0_DEFAULT_VALUE;
3204 PLL_MISC_CHK_DEFAULT(c, 0, default_val, /* ignore lock enable */
3205 PLLX_MISC0_WRITE_MASK & (~PLLX_MISC0_LOCK_ENABLE));
3207 default_val = PLLX_MISC1_DEFAULT_VALUE;
3208 PLL_MISC_CHK_DEFAULT(c, 1, default_val, PLLX_MISC1_WRITE_MASK);
3210 default_val = PLLX_MISC2_DEFAULT_VALUE; /* ignore all but control bit */
3211 PLL_MISC_CHK_DEFAULT(c, 2, default_val, PLLX_MISC2_EN_DYNRAMP);
3213 default_val = PLLX_MISC3_DEFAULT_VALUE & (~PLLX_MISC3_IDDQ);
3214 PLL_MISC_CHK_DEFAULT(c, 3, default_val, PLLX_MISC3_WRITE_MASK);
3216 default_val = PLLX_MISC4_DEFAULT_VALUE;
3217 PLL_MISC_CHK_DEFAULT(c, 4, default_val, PLLX_MISC4_WRITE_MASK);
3219 default_val = PLLX_MISC5_DEFAULT_VALUE;
3220 PLL_MISC_CHK_DEFAULT(c, 5, default_val, PLLX_MISC5_WRITE_MASK);
3223 static void pllx_set_defaults(struct clk *c, unsigned long input_rate)
3228 c->u.pll.defaults_set = true;
3230 /* Get ready dyn ramp state machine settings */
3231 pllx_get_dyn_steps(c, input_rate, &step_a, &step_b);
3232 val = PLLX_MISC2_DEFAULT_VALUE & (~PLLX_MISC2_DYNRAMP_STEPA_MASK) &
3233 (~PLLX_MISC2_DYNRAMP_STEPB_MASK);
3234 val |= step_a << PLLX_MISC2_DYNRAMP_STEPA_SHIFT;
3235 val |= step_b << PLLX_MISC2_DYNRAMP_STEPB_SHIFT;
3237 if (clk_readl(c->reg) & c->u.pll.controls->enable_mask) {
3239 * PLL is ON: check if defaults already set, then set those
3240 * that can be updated in flight.
3242 pllx_check_defaults(c, input_rate);
3244 /* Configure dyn ramp, disable lock override */
3245 clk_writel(val, c->reg + c->u.pll.misc2);
3247 /* Enable lock detect */
3248 val = clk_readl(c->reg + c->u.pll.misc0);
3249 val &= ~PLLX_MISC0_LOCK_ENABLE;
3250 val |= PLLX_MISC0_DEFAULT_VALUE & PLLX_MISC0_LOCK_ENABLE;
3251 pll_writel_delay(val, c->reg + c->u.pll.misc0);
3256 /* Enable lock detect and CPU output */
3257 clk_writel(PLLX_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
3260 clk_writel(PLLX_MISC1_DEFAULT_VALUE, c->reg + c->u.pll.misc1);
3262 /* Configure dyn ramp state machine, disable lock override */
3263 clk_writel(val, c->reg + c->u.pll.misc2);
3266 clk_writel(PLLX_MISC3_DEFAULT_VALUE, c->reg + c->u.pll.misc3);
3269 clk_writel(PLLX_MISC4_DEFAULT_VALUE, c->reg + c->u.pll.misc4);
3270 pll_writel_delay(PLLX_MISC5_DEFAULT_VALUE, c->reg + c->u.pll.misc5);
3273 #if PLLX_USE_DYN_RAMP
3274 static int pllx_dyn_ramp(struct clk *c, struct clk_pll_freq_table *cfg)
3276 u32 reg, val, base, ndiv_new_mask;
3277 struct clk_pll_controls *ctrl = c->u.pll.controls;
3278 struct clk_pll_div_layout *divs = c->u.pll.div_layout;
3280 reg = pll_reg_idx_to_addr(c, divs->ndiv_new_reg_idx);
3281 ndiv_new_mask = (divs->ndiv_mask >> divs->ndiv_shift) <<
3282 divs->ndiv_new_shift;
3283 val = clk_readl(reg) & (~ndiv_new_mask);
3284 val |= cfg->n << divs->ndiv_new_shift;
3285 pll_writel_delay(val, reg);
3287 reg = pll_reg_idx_to_addr(c, ctrl->dramp_ctrl_reg_idx);
3288 val = clk_readl(reg);
3289 val |= ctrl->dramp_en_mask;
3290 pll_writel_delay(val, reg);
3291 tegra_pll_clk_wait_for_lock(c, reg, ctrl->dramp_done_mask);
3293 base = clk_readl(c->reg) & (~divs->ndiv_mask);
3294 base |= cfg->n << divs->ndiv_shift;
3295 pll_writel_delay(base, c->reg);
3297 val &= ~ctrl->dramp_en_mask;
3298 pll_writel_delay(val, reg);
3300 pr_debug("%s: dynamic ramp to m = %u n = %u p = %u, Fout = %lu kHz\n",
3301 c->name, cfg->m, cfg->n, cfg->p,
3302 cfg->input_rate / cfg->m * cfg->n / cfg->p / 1000);
3308 static void tegra21_pllx_clk_init(struct clk *c)
3310 /* Only s/w dyn ramp control is supported */
3311 u32 val = clk_readl(PLLX_HW_CTRL_CFG);
3312 BUG_ON(!(val & PLLX_HW_CTRL_CFG_SWCTRL) && !tegra_platform_is_linsim());
3314 tegra_pll_clk_init(c);
3317 static struct clk_ops tegra_pllx_ops = {
3318 .init = tegra21_pllx_clk_init,
3319 .enable = tegra_pll_clk_enable,
3320 .disable = tegra_pll_clk_disable,
3321 .set_rate = tegra_pll_clk_set_rate,
3327 * Identical PLLs used exclusively as memory clock source. Configuration
3328 * and control fields in CAR module are separate for both PLL, and can
3329 * be set independently. Most control fields (ENABLE, IDDQ, M/N/P dividers)
3330 * have override counterparts in PMC module, however there is only one set
3331 * of registers that applied either to PLLM or PLLMB depending on override
3334 * By default selection between PLLM and PLLMB outputs is controlled by EMC
3335 * clock switch h/w state machine. If any s/w override either in CAR, or in
3336 * PMC is enabled on boot, PLLMB is no longer can be used as EMC parent.
3338 * Only PLLM is used as boot PLL, setup by boot-rom.
3340 static void pllm_check_defaults(struct clk *c)
3343 c->u.pll.defaults_set = true;
3346 * PLLM is setup on boot/suspend exit by boot-rom.
3347 * Just enable lock, and check default configuration:
3348 * - PLLM syncmux is under h/w control
3349 * - PMC override is disabled
3351 val = clk_readl(c->reg + c->u.pll.misc0);
3352 val &= ~PLLM_MISC0_LOCK_OVERRIDE;
3353 val |= PLLM_MISC0_LOCK_ENABLE;
3354 pll_writel_delay(val, c->reg + c->u.pll.misc0);
3356 /* FIXME: no support for invalid configurations; replace with BUG() */
3357 if (val & PLLM_MISC0_SYNCMUX_CTRL_MASK) {
3358 WARN(1, "%s: Unsupported config: PLLM syncmux s/w control\n",
3360 c->u.pll.defaults_set = false;
3363 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3364 if (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) {
3365 WARN(1, "%s: Unsupported config: PMC override enabled\n",
3367 c->u.pll.defaults_set = false;
3369 /* No boot on PLLMB */
3370 BUG_ON(val & PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO);
3374 static void tegra21_pllm_clk_init(struct clk *c)
3377 unsigned long input_rate = clk_get_rate(c->parent);
3378 unsigned long cf = input_rate / pll_get_fixed_mdiv(c, input_rate);
3380 struct clk_pll_freq_table cfg = { };
3381 struct clk_pll_controls *ctrl = c->u.pll.controls;
3382 struct clk_pll_div_layout *divs = c->u.pll.div_layout;
3383 BUG_ON(!ctrl || !divs);
3385 /* clip vco_min to exact multiple of comparison rate */
3386 c->u.pll.vco_min = DIV_ROUND_UP(c->u.pll.vco_min, cf) * cf;
3387 c->min_rate = DIV_ROUND_UP(c->u.pll.vco_min,
3388 divs->pdiv_to_p[divs->pdiv_max]);
3390 /* Check PLLM setup */
3391 pllm_check_defaults(c);
3393 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3394 if ((val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) &&
3395 (~val & PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO)) {
3396 c->state = (val & PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE) ? ON : OFF;
3397 if (c->state == ON) {
3398 /* PLLM boot control from PMC + enabled: record rate */
3399 val = pmc_readl(PMC_PLLM_WB0_OVERRIDE);
3400 cfg.m = (val & divs->mdiv_mask) >> divs->mdiv_shift;
3401 cfg.n = (val & divs->ndiv_mask) >> divs->ndiv_shift;
3403 val = pmc_readl(PMC_PLLM_WB0_OVERRIDE_2);
3404 cfg.p = (val & PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK) >>
3405 PMC_PLLM_WB0_OVERRIDE_2_DIVP_SHIFT;
3406 cfg.p = divs->pdiv_to_p[cfg.p];
3407 pll_clk_set_gain(c, &cfg);
3411 val = clk_readl(c->reg);
3412 c->state = (val & ctrl->enable_mask) ? ON : OFF;
3413 if (c->state == ON) {
3414 /* PLLM boot control from CAR + enabled: record rate */
3415 pll_base_parse_cfg(c, &cfg);
3416 pll_clk_set_gain(c, &cfg);
3421 /* PLLM is disabled on boot: set rate close to to 1/4 of minimum VCO */
3422 c->ops->set_rate(c, c->u.pll.vco_min / 4);
3425 static int tegra21_pllm_clk_enable(struct clk *c)
3427 u32 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3429 if ((val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) &&
3430 (~val & PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO)) {
3431 pr_debug("%s on clock %s\n", __func__, c->name);
3433 val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_IDDQ;
3434 pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
3435 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3436 udelay(5); /* out of IDDQ delay to 5us */
3438 val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
3439 pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
3440 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3442 tegra_pll_clk_wait_for_lock(c, c->reg, PLLM_BASE_LOCK);
3445 return tegra_pll_clk_enable(c);
3448 static void tegra21_pllm_clk_disable(struct clk *c)
3450 u32 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3452 if ((val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) &&
3453 (~val & PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO)) {
3454 pr_debug("%s on clock %s\n", __func__, c->name);
3456 val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE;
3457 pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
3458 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3461 val |= PMC_PLLP_WB0_OVERRIDE_PLLM_IDDQ;
3462 pmc_writel(val, PMC_PLLP_WB0_OVERRIDE);
3463 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3467 tegra_pll_clk_disable(c);
3470 static int tegra21_pllm_clk_set_rate(struct clk *c, unsigned long rate)
3473 struct clk_pll_freq_table cfg = { };
3474 unsigned long input_rate = clk_get_rate(c->parent);
3476 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
3478 if (c->state == ON) {
3479 if (rate != clk_get_rate_locked(c)) {
3480 pr_err("%s: Can not change memory %s rate in flight\n",
3487 if (pll_clk_find_cfg(c, &cfg, rate, input_rate, &pdiv))
3490 pll_clk_set_gain(c, &cfg);
3492 val = pmc_readl(PMC_PLLP_WB0_OVERRIDE);
3493 if ((val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) &&
3494 (~val & PMC_PLLP_WB0_OVERRIDE_PLLM_SEL_VCO)) {
3495 struct clk_pll_div_layout *divs = c->u.pll.div_layout;
3497 val = pmc_readl(PMC_PLLM_WB0_OVERRIDE_2);
3498 val &= ~PMC_PLLM_WB0_OVERRIDE_2_DIVP_MASK;
3499 val |= pdiv << PMC_PLLM_WB0_OVERRIDE_2_DIVP_SHIFT;
3500 pmc_writel(val, PMC_PLLM_WB0_OVERRIDE_2);
3502 val = pmc_readl(PMC_PLLM_WB0_OVERRIDE);
3503 val &= ~(divs->mdiv_mask | divs->ndiv_mask);
3504 val |= cfg.m << divs->mdiv_shift | cfg.n << divs->ndiv_shift;
3505 pmc_writel(val, PMC_PLLM_WB0_OVERRIDE);
3506 val = pmc_readl(PMC_PLLM_WB0_OVERRIDE);
3509 val = clk_readl(c->reg);
3510 pll_base_set_div(c, cfg.m, cfg.n, pdiv, val);
3516 static struct clk_ops tegra_pllm_ops = {
3517 .init = tegra21_pllm_clk_init,
3518 .enable = tegra21_pllm_clk_enable,
3519 .disable = tegra21_pllm_clk_disable,
3520 .set_rate = tegra21_pllm_clk_set_rate,
3524 static void pllmb_set_defaults(struct clk *c, unsigned long input_rate)
3526 u32 mask, val = clk_readl(c->reg);
3527 c->u.pll.defaults_set = true;
3529 if (val & c->u.pll.controls->enable_mask) {
3531 * PLL is ON: check if defaults already set, then set those
3532 * that can be updated in flight.
3534 val = PLLMB_MISC0_DEFAULT_VALUE & (~PLLMB_MISC0_IDDQ);
3535 mask = PLLMB_MISC0_LOCK_ENABLE | PLLMB_MISC0_LOCK_OVERRIDE;
3536 PLL_MISC_CHK_DEFAULT(c, 0, val, ~mask & PLLMB_MISC0_WRITE_MASK);
3538 /* Enable lock detect */
3539 val = clk_readl(c->reg + c->u.pll.misc0);
3541 val |= PLLMB_MISC0_DEFAULT_VALUE & mask;
3542 pll_writel_delay(val, c->reg + c->u.pll.misc0);
3547 /* set IDDQ, enable lock detect */
3548 pll_writel_delay(PLLMB_MISC0_DEFAULT_VALUE, c->reg + c->u.pll.misc0);
3551 static int tegra21_pllmb_clk_set_rate(struct clk *c, unsigned long rate)
3553 if (c->state == ON) {
3554 if (rate != clk_get_rate_locked(c)) {
3555 pr_err("%s: Can not change memory %s rate in flight\n",
3561 return tegra_pll_clk_set_rate(c, rate);
3564 static void tegra21_pllmb_clk_init(struct clk *c)
3566 tegra_pll_clk_init(c);
3569 static struct clk_ops tegra_pllmb_ops = {
3570 .init = tegra21_pllmb_clk_init,
3571 .enable = tegra_pll_clk_enable,
3572 .disable = tegra_pll_clk_disable,
3573 .set_rate = tegra21_pllmb_clk_set_rate,
3578 * Analog interpolator based SS PLL (with optional SDM SS - not used).
3580 static void select_pll_e_input(struct clk *c)
3583 u32 aux_reg = clk_readl(PLLE_AUX);
3585 #if USE_PLLE_INPUT_PLLRE
3586 aux_reg |= PLLE_AUX_PLLRE_SEL;
3587 p = c->inputs[2].input;
3589 aux_reg &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL);
3590 p = c->inputs[0].input;
3593 tegra_clk_prepare_enable(p);
3595 pll_writel_delay(aux_reg, PLLE_AUX);
3597 if (p != c->parent) {
3598 tegra_clk_disable_unprepare(c->parent);
3603 static void tegra21_plle_clk_init(struct clk *c)
3606 struct clk *pll_ref = tegra_get_clock_by_name("pll_ref");
3607 struct clk *re_vco = tegra_get_clock_by_name("pll_re_vco");
3608 struct clk *pllp = tegra_get_clock_by_name("pllp");
3609 #if USE_PLLE_INPUT_PLLRE
3610 struct clk *ref = re_vco;
3612 struct clk *ref = pll_ref;
3615 val = clk_readl(c->reg);
3616 c->state = (val & PLLE_BASE_ENABLE) ? ON : OFF;
3618 c->mul = (val & PLLE_BASE_DIVN_MASK) >> PLLE_BASE_DIVN_SHIFT;
3619 c->div = (val & PLLE_BASE_DIVM_MASK) >> PLLE_BASE_DIVM_SHIFT;
3620 p = (val & PLLE_BASE_DIVCML_MASK) >> PLLE_BASE_DIVCML_SHIFT;
3621 c->div *= pll_qlin_pdiv_to_p[p];
3623 val = clk_readl(PLLE_AUX);
3624 c->parent = (val & PLLE_AUX_PLLRE_SEL) ? re_vco :
3625 (val & PLLE_AUX_PLLP_SEL) ? pllp : pll_ref;
3626 if (c->parent != ref) {
3627 if (c->state == ON) {
3628 WARN(1, "%s: pll_e is left enabled with %s input\n",
3629 __func__, c->parent->name);
3634 static void tegra21_plle_clk_disable(struct clk *c)
3637 pr_debug("%s on clock %s\n", __func__, c->name);
3639 /* FIXME: do we need to restore other s/w controls ? */
3640 val = clk_readl(c->reg);
3641 val &= ~PLLE_BASE_ENABLE;
3642 clk_writel(val, c->reg);
3644 val = clk_readl(c->reg + c->u.pll.misc0);
3645 val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE;
3646 pll_writel_delay(val, c->reg + c->u.pll.misc0);
3649 static int tegra21_plle_clk_enable(struct clk *c)
3653 const struct clk_pll_freq_table *sel;
3654 unsigned long rate = c->u.pll.fixed_rate;
3655 unsigned long input_rate = clk_get_rate(c->parent);
3657 if (c->state == ON) {
3658 /* BL left plle enabled - don't change configuartion */
3659 pr_warn("%s: pll_e is already enabled\n", __func__);
3663 /* Fixed per prod settings input */
3664 select_pll_e_input(c);
3665 input_rate = clk_get_rate(c->parent);
3667 /* PLLE config must be tabulated */
3668 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
3669 if (sel->input_rate == input_rate && sel->output_rate == rate)
3673 if (sel->input_rate == 0) {
3674 pr_err("%s: %s input rate %lu is out-of-table\n",
3675 __func__, c->name, input_rate);
3679 p = c->u.pll.round_p_to_pdiv(sel->p, &pdiv);
3680 BUG_ON(IS_ERR_VALUE(p) || (p != sel->p));
3682 /* setup locking configuration, s/w control of IDDQ and enable modes,
3683 take pll out of IDDQ via s/w control, setup VREG */
3684 val = clk_readl(c->reg);
3685 val &= ~PLLE_BASE_LOCK_OVERRIDE;
3686 clk_writel(val, c->reg);
3688 val = clk_readl(c->reg + c->u.pll.misc0);
3689 val |= PLLE_MISC_LOCK_ENABLE;
3690 val |= PLLE_MISC_IDDQ_SW_CTRL;
3691 val &= ~PLLE_MISC_IDDQ_SW_VALUE;
3692 val |= PLLE_MISC_PLLE_PTS;
3693 clk_writel(val, c->reg + c->u.pll.misc0);
3696 /* configure dividers, disable SS */
3697 val = clk_readl(PLLE_SS_CTRL);
3698 val |= PLLE_SS_DISABLE;
3699 clk_writel(val, PLLE_SS_CTRL);
3701 val = clk_readl(c->reg);
3702 val &= ~(PLLE_BASE_DIVM_MASK | PLLE_BASE_DIVN_MASK |
3703 PLLE_BASE_DIVCML_MASK);
3704 val |= (sel->m << PLLE_BASE_DIVM_SHIFT) |
3705 (sel->n << PLLE_BASE_DIVN_SHIFT) |
3706 (pdiv << PLLE_BASE_DIVCML_SHIFT);
3707 pll_writel_delay(val, c->reg);
3709 c->div = sel->m * sel->p;
3711 /* enable and lock pll */
3712 val |= PLLE_BASE_ENABLE;
3713 clk_writel(val, c->reg);
3714 tegra_pll_clk_wait_for_lock(
3715 c, c->reg + c->u.pll.misc0, PLLE_MISC_LOCK);
3718 val = clk_readl(PLLE_SS_CTRL);
3719 val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT);
3720 val &= ~PLLE_SS_COEFFICIENTS_MASK;
3721 val |= PLLE_SS_COEFFICIENTS_VAL;
3722 clk_writel(val, PLLE_SS_CTRL);
3723 val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS);
3724 pll_writel_delay(val, PLLE_SS_CTRL);
3725 val &= ~PLLE_SS_CNTL_INTERP_RESET;
3726 pll_writel_delay(val, PLLE_SS_CTRL);
3730 /* switch pll under h/w control */
3731 val = clk_readl(c->reg + c->u.pll.misc0);
3732 val &= ~PLLE_MISC_IDDQ_SW_CTRL;
3733 clk_writel(val, c->reg + c->u.pll.misc0);
3735 val = clk_readl(PLLE_AUX);
3736 val |= PLLE_AUX_USE_LOCKDET | PLLE_AUX_SS_SEQ_INCLUDE;
3737 val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL);
3738 pll_writel_delay(val, PLLE_AUX);
3739 val |= PLLE_AUX_SEQ_ENABLE;
3740 pll_writel_delay(val, PLLE_AUX);
3745 static struct clk_ops tegra_plle_ops = {
3746 .init = tegra21_plle_clk_init,
3747 .enable = tegra21_plle_clk_enable,
3748 .disable = tegra21_plle_clk_disable,
3752 * Tegra21 includes dynamic frequency lock loop (DFLL) with automatic voltage
3753 * control as possible CPU clock source. It is included in the Tegra12 clock
3754 * tree as "complex PLL" with standard Tegra clock framework APIs. However,
3755 * DFLL locking logic h/w access APIs are separated in the tegra_cl_dvfs.c
3756 * module. Hence, DFLL operations, with the exception of initialization, are
3757 * basically cl-dvfs wrappers.
3760 /* DFLL operations */
3761 #ifdef CONFIG_ARCH_TEGRA_HAS_CL_DVFS
3762 static void tune_cpu_trimmers(bool trim_high)
3764 tegra_soctherm_adjust_cpu_zone(trim_high);
3765 pr_info_once("%s: init soctherm cpu zone %s\n", __func__,
3766 trim_high ? "HIGH" : "LOW");
3767 pr_debug("%s: adjust soctherm cpu zone %s\n", __func__,
3768 trim_high ? "HIGH" : "LOW");
3772 static void __init tegra21_dfll_clk_init(struct clk *c)
3774 unsigned long int dfll_boot_req_khz = tegra_dfll_boot_req_khz();
3775 c->ops->init = tegra21_dfll_cpu_late_init;
3778 * If boot loader has set dfll clock, then dfll freq is
3779 * passed in kernel command line from bootloader
3781 if (dfll_boot_req_khz)
3782 c->rate = dfll_boot_req_khz * 1000;
3785 static int tegra21_dfll_clk_enable(struct clk *c)
3787 if (c->u.dfll.cl_dvfs)
3788 return tegra_cl_dvfs_enable(c->u.dfll.cl_dvfs);
3792 static void tegra21_dfll_clk_disable(struct clk *c)
3794 if (c->u.dfll.cl_dvfs)
3795 tegra_cl_dvfs_disable(c->u.dfll.cl_dvfs);
3798 static unsigned long boost_dfll_rate(struct clk *c, unsigned long rate)
3800 struct clk *consumer = c->u.dfll.consumer;
3801 if (!consumer || !consumer->dvfs || !consumer->dvfs->boost_table ||
3802 (consumer->dvfs->num_freqs <= 1))
3805 /* Only one top DVFS step boost is allowed */
3806 if (rate < consumer->dvfs->freqs[consumer->dvfs->num_freqs-2])
3809 return consumer->dvfs->freqs[consumer->dvfs->num_freqs-1];
3812 static int tegra21_dfll_clk_set_rate(struct clk *c, unsigned long rate)
3814 if (c->u.dfll.cl_dvfs) {
3815 unsigned long boost_rate = boost_dfll_rate(c, rate);
3816 int ret = tegra_cl_dvfs_request_rate(c->u.dfll.cl_dvfs,
3819 * Record requested rate. Thus, non boosted rate is reported.
3820 * It also ensures correct clock settings when switching back
3821 * and forth to a clock source with different than DFLL
3822 * granularity, and prevents other than DFLL clock source to run
3823 * at boost rate that is supported on DFLL only.
3833 static void tegra21_dfll_clk_reset(struct clk *c, bool assert)
3835 u32 val = assert ? DFLL_BASE_RESET : 0;
3836 clk_writel_delay(val, c->reg);
3840 tegra21_dfll_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
3842 if (p == TEGRA_CLK_DFLL_LOCK) {
3843 if (c->u.dfll.cl_dvfs)
3844 return setting ? tegra_cl_dvfs_lock(c->u.dfll.cl_dvfs) :
3845 tegra_cl_dvfs_unlock(c->u.dfll.cl_dvfs);
3851 #ifdef CONFIG_PM_SLEEP
3852 static void tegra21_dfll_clk_resume(struct clk *c)
3854 if (!(clk_readl(c->reg) & DFLL_BASE_RESET))
3855 return; /* already resumed */
3857 if (c->u.dfll.cl_dvfs) {
3858 tegra_periph_reset_deassert(c);
3859 tegra_cl_dvfs_resume(c->u.dfll.cl_dvfs);
3864 static struct clk_ops tegra_dfll_ops = {
3865 .init = tegra21_dfll_clk_init,
3866 .enable = tegra21_dfll_clk_enable,
3867 .disable = tegra21_dfll_clk_disable,
3868 .set_rate = tegra21_dfll_clk_set_rate,
3869 .reset = tegra21_dfll_clk_reset,
3870 .clk_cfg_ex = tegra21_dfll_clk_cfg_ex,
3873 /* DFLL sysfs interface */
3874 static int tegra21_use_dfll_cb(const char *arg, const struct kernel_param *kp)
3877 unsigned int old_use_dfll;
3878 if (CONFIG_TEGRA_USE_DFLL_RANGE != TEGRA_USE_DFLL_CDEV_CNTRL) {
3879 old_use_dfll = use_dfll;
3880 param_set_int(arg, kp);
3881 ret = tegra_clk_dfll_range_control(use_dfll);
3883 use_dfll = old_use_dfll;
3886 pr_warn("\n%s: Failed to set use_dfll\n", __func__);
3887 pr_warn("DFLL usage is under thermal cooling device control\n");
3892 static struct kernel_param_ops tegra21_use_dfll_ops = {
3893 .set = tegra21_use_dfll_cb,
3894 .get = param_get_int,
3896 module_param_cb(use_dfll, &tegra21_use_dfll_ops, &use_dfll, 0644);
3899 * PLL internal post divider ops for PLLs that have both VCO and post-divider
3900 * output separtely connected to the clock tree.
3902 static struct clk_ops tegra_pll_out_ops = {
3903 .init = tegra_pll_out_clk_init,
3904 .enable = tegra_pll_out_clk_enable,
3905 .disable = tegra_pll_out_clk_disable,
3906 .set_rate = tegra_pll_out_clk_set_rate,
3909 static struct clk_ops tegra_pll_out_fixed_ops = {
3910 .init = tegra_pll_out_clk_init,
3911 .enable = tegra_pll_out_clk_enable,
3912 .disable = tegra_pll_out_clk_disable,
3915 static void tegra21_pllu_out_clk_init(struct clk *c)
3918 struct clk *pll = c->parent;
3919 val = clk_readl(pll->reg);
3922 * If PLLU state is already under h/w control just record output ratio,
3923 * and verify expected fixed output rate.
3925 if (!(val & PLLU_BASE_OVERRIDE)) {
3926 struct clk_pll_div_layout *divs = pll->u.pll.div_layout;
3928 c->state = c->parent->state;
3929 c->max_rate = pll->u.pll.vco_max;
3931 p = (val & divs->pdiv_mask) >> divs->pdiv_shift;
3932 if (p > divs->pdiv_max)
3933 p = divs->pdiv_max; /* defer invalid p WARN to verify */
3934 p = divs->pdiv_to_p[p];
3938 pll_clk_verify_fixed_rate(c);
3940 /* Complete PLLU output s/w controlled initialization */
3941 tegra_pll_out_clk_init(c);
3945 static struct clk_ops tegra_pllu_out_ops = {
3946 .init = tegra21_pllu_out_clk_init,
3947 .enable = tegra_pll_out_clk_enable,
3948 .disable = tegra_pll_out_clk_disable,
3949 .set_rate = tegra_pll_out_clk_set_rate,
3952 static void tegra21_pllp_out_clk_init(struct clk *c)
3955 struct clk *pll = c->parent;
3956 val = clk_readl(pll->reg);
3959 * If PLLP state is already under h/w control just record expected
3960 * fixed output rate.
3962 if (!(val & PLLP_BASE_OVERRIDE)) {
3963 c->state = c->parent->state;
3964 c->max_rate = pll->u.pll.vco_max;
3965 c->div = pll->u.pll.fixed_rate / c->u.pll.fixed_rate;
3967 pll_clk_verify_fixed_rate(c);
3969 /* Complete pllp output s/w controlled initialization */
3970 tegra_pll_out_clk_init(c);
3973 /* Reset not used PLL_P_OUT1 branch. */
3974 clk_writel(0x0, pll->reg + 0x4);
3977 static struct clk_ops tegra_pllp_out_ops = {
3978 .init = tegra21_pllp_out_clk_init,
3979 .enable = tegra_pll_out_clk_enable,
3980 .disable = tegra_pll_out_clk_disable,
3981 .set_rate = tegra_pll_out_clk_set_rate,
3984 #ifdef CONFIG_PM_SLEEP
3985 static void tegra_pllu_out_resume_enable(struct clk *c)
3987 u32 val = clk_readl(c->parent->reg);
3988 if (!(val & PLLU_BASE_OVERRIDE) ||
3989 val & c->parent->u.pll.controls->enable_mask)
3990 return; /* already resumed */
3992 tegra_pll_out_resume_enable(c);
3995 static void tegra_pllp_out_resume_enable(struct clk *c)
3997 u32 val = clk_readl(c->parent->reg);
3999 /* Reset not used PLL_P_OUT1 branch. */
4000 clk_writel(0x0, c->parent->reg + 0x4);
4002 if (!(val & PLLP_BASE_OVERRIDE) ||
4003 val & c->parent->u.pll.controls->enable_mask)
4004 return; /* already resumed */
4006 tegra_pll_out_resume_enable(c);
4011 /* PLL external secondary divider ops (non-atomic shared register access) */
4012 static DEFINE_SPINLOCK(pll_div_lock);
4014 static int tegra21_pll_div_clk_set_rate(struct clk *c, unsigned long rate);
4015 static void tegra21_pll_div_clk_init(struct clk *c)
4017 if (c->flags & DIV_U71) {
4019 if ((c->parent->state == OFF) || (!c->parent->ops->disable &&
4020 (c->parent->parent->state == OFF)))
4023 val = clk_readl(c->reg);
4024 val >>= c->reg_shift;
4025 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
4026 if (!(val & PLL_OUT_RESET_DISABLE))
4029 if (c->u.pll_div.default_rate) {
4030 int ret = tegra21_pll_div_clk_set_rate(
4031 c, c->u.pll_div.default_rate);
4035 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
4036 c->div = (divu71 + 2);
4038 } else if (c->flags & DIV_2) {
4040 if (c->flags & (PLLD | PLLX)) {
4047 u32 val = clk_readl(c->reg);
4048 c->state = val & (0x1 << c->reg_shift) ? ON : OFF;
4049 c->max_rate = c->parent->max_rate;
4053 static int tegra21_pll_div_clk_enable(struct clk *c)
4057 unsigned long flags;
4059 pr_debug("%s: %s\n", __func__, c->name);
4060 if (c->flags & DIV_U71) {
4061 spin_lock_irqsave(&pll_div_lock, flags);
4062 val = clk_readl(c->reg);
4063 new_val = val >> c->reg_shift;
4066 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
4068 val &= ~(0xFFFF << c->reg_shift);
4069 val |= new_val << c->reg_shift;
4070 clk_writel_delay(val, c->reg);
4071 spin_unlock_irqrestore(&pll_div_lock, flags);
4073 } else if (c->flags & DIV_2) {
4075 } else if (c->flags & PLLU) {
4076 clk_lock_save(pll_u, &flags);
4077 val = clk_readl(c->reg) | (0x1 << c->reg_shift);
4078 clk_writel_delay(val, c->reg);
4079 clk_unlock_restore(pll_u, &flags);
4082 spin_lock_irqsave(&pll_div_lock, flags);
4083 val = clk_readl(c->reg) | (0x1 << c->reg_shift);
4084 clk_writel_delay(val, c->reg);
4085 spin_unlock_irqrestore(&pll_div_lock, flags);
4091 static void tegra21_pll_div_clk_disable(struct clk *c)
4095 unsigned long flags;
4097 pr_debug("%s: %s\n", __func__, c->name);
4098 if (c->flags & DIV_U71) {
4099 spin_lock_irqsave(&pll_div_lock, flags);
4100 val = clk_readl(c->reg);
4101 new_val = val >> c->reg_shift;
4104 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
4106 val &= ~(0xFFFF << c->reg_shift);
4107 val |= new_val << c->reg_shift;
4108 clk_writel_delay(val, c->reg);
4109 spin_unlock_irqrestore(&pll_div_lock, flags);
4110 } else if (c->flags & PLLU) {
4111 clk_lock_save(pll_u, &flags);
4112 val = clk_readl(c->reg) & (~(0x1 << c->reg_shift));
4113 clk_writel_delay(val, c->reg);
4114 clk_unlock_restore(pll_u, &flags);
4116 spin_lock_irqsave(&pll_div_lock, flags);
4117 val = clk_readl(c->reg) & (~(0x1 << c->reg_shift));
4118 clk_writel_delay(val, c->reg);
4119 spin_unlock_irqrestore(&pll_div_lock, flags);
4123 static int tegra21_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
4128 unsigned long parent_rate = clk_get_rate(c->parent);
4129 unsigned long flags;
4131 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
4132 if (c->flags & DIV_U71) {
4133 divider_u71 = clk_div71_get_divider(
4134 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4135 if (divider_u71 >= 0) {
4136 spin_lock_irqsave(&pll_div_lock, flags);
4137 val = clk_readl(c->reg);
4138 new_val = val >> c->reg_shift;
4140 if (c->flags & DIV_U71_FIXED)
4141 new_val |= PLL_OUT_OVERRIDE;
4142 new_val &= ~PLL_OUT_RATIO_MASK;
4143 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
4145 val &= ~(0xFFFF << c->reg_shift);
4146 val |= new_val << c->reg_shift;
4147 clk_writel_delay(val, c->reg);
4148 c->div = divider_u71 + 2;
4150 spin_unlock_irqrestore(&pll_div_lock, flags);
4153 } else if (c->flags & DIV_2)
4154 return clk_set_rate(c->parent, rate * 2);
4159 static long tegra21_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
4162 unsigned long parent_rate = clk_get_rate(c->parent);
4163 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
4165 if (c->flags & DIV_U71) {
4166 divider = clk_div71_get_divider(
4167 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4170 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
4171 } else if (c->flags & DIV_2)
4172 /* no rounding - fixed DIV_2 dividers pass rate to parent PLL */
4178 static struct clk_ops tegra_pll_div_ops = {
4179 .init = tegra21_pll_div_clk_init,
4180 .enable = tegra21_pll_div_clk_enable,
4181 .disable = tegra21_pll_div_clk_disable,
4182 .set_rate = tegra21_pll_div_clk_set_rate,
4183 .round_rate = tegra21_pll_div_clk_round_rate,
4186 /* Periph clk ops */
4187 static inline u32 periph_clk_source_mask(struct clk *c)
4189 if (c->u.periph.src_mask)
4190 return c->u.periph.src_mask;
4191 else if (c->flags & MUX_PWM)
4193 else if (c->flags & MUX_CLK_OUT)
4194 return 3 << (c->u.periph.clk_num + 4);
4195 else if (c->flags & PLLD)
4196 return PLLD_BASE_DSI_MUX_MASK;
4201 static inline u32 periph_clk_source_shift(struct clk *c)
4203 if (c->u.periph.src_shift)
4204 return c->u.periph.src_shift;
4205 else if (c->flags & MUX_PWM)
4207 else if (c->flags & MUX_CLK_OUT)
4208 return c->u.periph.clk_num + 4;
4209 else if (c->flags & PLLD)
4210 return PLLD_BASE_DSI_MUX_SHIFT;
4215 static void periph_clk_state_init(struct clk *c)
4217 if (c->flags & PERIPH_NO_ENB) {
4218 c->state = c->parent->state;
4224 if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c)))
4226 if (!(c->flags & PERIPH_NO_RESET))
4227 if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) & PERIPH_CLK_TO_BIT(c))
4231 static bool periph_clk_can_force_safe_rate(struct clk *c)
4234 * As a general rule, force safe rate always for clocks supplied
4235 * to peripherals under reset. If clock does not have associated reset
4236 * at all, force safe rate if clock is disabled (can do it on Tegra21
4237 * that allow to change dividers of the disabled clocks).
4239 if (c->flags & PERIPH_NO_RESET)
4240 return c->state == OFF;
4242 return clk_readl(PERIPH_CLK_TO_RST_REG(c)) & PERIPH_CLK_TO_BIT(c);
4245 static void tegra21_periph_clk_init(struct clk *c)
4247 u32 val = clk_readl(c->reg);
4248 const struct clk_mux_sel *mux = NULL;
4249 const struct clk_mux_sel *sel;
4250 if (c->flags & MUX) {
4251 for (sel = c->inputs; sel->input != NULL; sel++) {
4252 if (((val & periph_clk_source_mask(c)) >>
4253 periph_clk_source_shift(c)) == sel->value)
4258 c->parent = mux->input;
4260 c->parent = c->inputs[0].input;
4263 if (c->flags & DIV_U71) {
4264 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
4265 if (c->flags & DIV_U71_IDLE) {
4266 val &= ~(PERIPH_CLK_SOURCE_DIVU71_MASK <<
4267 PERIPH_CLK_SOURCE_DIVIDLE_SHIFT);
4268 val |= (PERIPH_CLK_SOURCE_DIVIDLE_VAL <<
4269 PERIPH_CLK_SOURCE_DIVIDLE_SHIFT);
4270 clk_writel(val, c->reg);
4272 c->div = divu71 + 2;
4274 } else if (c->flags & DIV_U151) {
4275 u32 divu151 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
4276 if ((c->flags & DIV_U151_UART) &&
4277 (!(val & PERIPH_CLK_UART_DIV_ENB))) {
4280 c->div = divu151 + 2;
4282 } else if (c->flags & DIV_U16) {
4283 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
4284 c->div = divu16 + 1;
4286 } else if (!c->div || !c->mul) {
4291 periph_clk_state_init(c);
4293 /* if peripheral is left under reset - enforce safe rate */
4294 if (periph_clk_can_force_safe_rate(c))
4295 tegra_periph_clk_safe_rate_init(c);
4298 static int tegra21_periph_clk_enable(struct clk *c)
4300 unsigned long flags;
4301 pr_debug("%s on clock %s\n", __func__, c->name);
4303 if (c->flags & PERIPH_NO_ENB)
4306 spin_lock_irqsave(&periph_refcount_lock, flags);
4308 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
4309 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1) {
4310 spin_unlock_irqrestore(&periph_refcount_lock, flags);
4314 clk_writel_delay(PERIPH_CLK_TO_BIT(c), PERIPH_CLK_TO_ENB_SET_REG(c));
4316 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET)) {
4317 if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) & PERIPH_CLK_TO_BIT(c)) {
4318 udelay(RESET_PROPAGATION_DELAY);
4319 clk_writel_delay(PERIPH_CLK_TO_BIT(c),
4320 PERIPH_CLK_TO_RST_CLR_REG(c));
4323 spin_unlock_irqrestore(&periph_refcount_lock, flags);
4327 static void tegra21_periph_clk_disable(struct clk *c)
4329 unsigned long val, flags;
4330 pr_debug("%s on clock %s\n", __func__, c->name);
4332 if (c->flags & PERIPH_NO_ENB)
4335 spin_lock_irqsave(&periph_refcount_lock, flags);
4338 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
4340 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] == 0) {
4341 /* If peripheral is in the APB bus then read the APB bus to
4342 * flush the write operation in apb bus. This will avoid the
4343 * peripheral access after disabling clock*/
4344 if (c->flags & PERIPH_ON_APB)
4345 val = chipid_readl();
4347 clk_writel_delay(PERIPH_CLK_TO_BIT(c),
4348 PERIPH_CLK_TO_ENB_CLR_REG(c));
4350 spin_unlock_irqrestore(&periph_refcount_lock, flags);
4353 static void tegra21_periph_clk_reset(struct clk *c, bool assert)
4356 pr_debug("%s %s on clock %s\n", __func__,
4357 assert ? "assert" : "deassert", c->name);
4359 if (!(c->flags & PERIPH_NO_RESET)) {
4361 /* If peripheral is in the APB bus then read the APB
4362 * bus to flush the write operation in apb bus. This
4363 * will avoid the peripheral access after disabling
4365 if (c->flags & PERIPH_ON_APB)
4366 val = chipid_readl();
4368 clk_writel_delay(PERIPH_CLK_TO_BIT(c),
4369 PERIPH_CLK_TO_RST_SET_REG(c));
4371 clk_writel_delay(PERIPH_CLK_TO_BIT(c),
4372 PERIPH_CLK_TO_RST_CLR_REG(c));
4376 static int tegra21_periph_clk_set_parent(struct clk *c, struct clk *p)
4379 const struct clk_mux_sel *sel;
4380 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
4382 if (!(c->flags & MUX))
4383 return (p == c->parent) ? 0 : (-EINVAL);
4385 for (sel = c->inputs; sel->input != NULL; sel++) {
4386 if (sel->input == p) {
4387 val = clk_readl(c->reg);
4388 val &= ~periph_clk_source_mask(c);
4389 val |= (sel->value << periph_clk_source_shift(c));
4392 tegra_clk_prepare_enable(p);
4394 clk_writel_delay(val, c->reg);
4396 if (c->refcnt && c->parent)
4397 tegra_clk_disable_unprepare(c->parent);
4407 static int tegra21_periph_clk_set_rate(struct clk *c, unsigned long rate)
4411 unsigned long parent_rate = clk_get_rate(c->parent);
4413 if (c->flags & DIV_U71) {
4414 divider = clk_div71_get_divider(
4415 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4417 val = clk_readl(c->reg);
4418 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
4420 clk_writel_delay(val, c->reg);
4421 c->div = divider + 2;
4425 } else if (c->flags & DIV_U151) {
4426 divider = clk_div151_get_divider(
4427 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4429 val = clk_readl(c->reg);
4430 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
4432 if (c->flags & DIV_U151_UART) {
4434 val |= PERIPH_CLK_UART_DIV_ENB;
4436 val &= ~PERIPH_CLK_UART_DIV_ENB;
4438 clk_writel_delay(val, c->reg);
4439 c->div = divider + 2;
4443 } else if (c->flags & DIV_U16) {
4444 divider = clk_div16_get_divider(parent_rate, rate);
4446 val = clk_readl(c->reg);
4447 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
4449 clk_writel_delay(val, c->reg);
4450 c->div = divider + 1;
4454 } else if (parent_rate <= rate) {
4462 static long tegra21_periph_clk_round_rate(struct clk *c,
4466 unsigned long parent_rate = clk_get_rate(c->parent);
4467 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
4469 if (c->flags & DIV_U71) {
4470 divider = clk_div71_get_divider(
4471 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4475 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
4476 } else if (c->flags & DIV_U151) {
4477 divider = clk_div151_get_divider(
4478 parent_rate, rate, c->flags, ROUND_DIVIDER_UP);
4482 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
4483 } else if (c->flags & DIV_U16) {
4484 divider = clk_div16_get_divider(parent_rate, rate);
4487 return DIV_ROUND_UP(parent_rate, divider + 1);
4492 static struct clk_ops tegra_periph_clk_ops = {
4493 .init = &tegra21_periph_clk_init,
4494 .enable = &tegra21_periph_clk_enable,
4495 .disable = &tegra21_periph_clk_disable,
4496 .set_parent = &tegra21_periph_clk_set_parent,
4497 .set_rate = &tegra21_periph_clk_set_rate,
4498 .round_rate = &tegra21_periph_clk_round_rate,
4499 .reset = &tegra21_periph_clk_reset,
4502 static int tegra21_qspi_clk_cfg_ex(struct clk *c,
4503 enum tegra_clk_ex_param p, u32 setting)
4505 if (p == TEGRA_CLK_QSPI_DIV2_ENB) {
4507 u32 val = clk_readl(c->reg);
4509 div2_val = val & PERIPH_CLK_SOURCE_QSPI_DIV2_EN;
4511 if (setting && !div2_val) {
4512 val |= PERIPH_CLK_SOURCE_QSPI_DIV2_EN;
4513 clk_writel_delay(val, c->reg);
4514 } else if (!setting && div2_val) {
4515 val &= ~PERIPH_CLK_SOURCE_QSPI_DIV2_EN;
4516 clk_writel_delay(val, c->reg);
4523 static struct clk_ops tegra_qspi_clk_ops = {
4524 .init = &tegra21_periph_clk_init,
4525 .enable = &tegra21_periph_clk_enable,
4526 .disable = &tegra21_periph_clk_disable,
4527 .set_parent = &tegra21_periph_clk_set_parent,
4528 .set_rate = &tegra21_periph_clk_set_rate,
4529 .round_rate = &tegra21_periph_clk_round_rate,
4530 .reset = &tegra21_periph_clk_reset,
4531 .clk_cfg_ex = &tegra21_qspi_clk_cfg_ex,
4534 /* Supper skipper ops */
4535 static void tegra21_clk_super_skip_init(struct clk *c)
4539 c->parent->skipper = c;
4541 /* Skipper is always ON (does not gate the clock) */
4543 c->max_rate = c->parent->max_rate;
4545 /* Always set initial 1:1 ratio */
4546 clk_writel(0, c->reg);
4551 static int tegra21_clk_super_skip_enable(struct clk *c)
4553 /* no clock gate in skipper, just pass thru to parent */
4557 #ifdef CONFIG_TEGRA_BPMP_SCLK_SKIP
4558 static void tegra_bpmp_sclk_skip_set_rate(unsigned long input_rate,
4561 uint32_t mb[] = { cpu_to_le32(input_rate), cpu_to_le32(rate) };
4562 int r = tegra_bpmp_send_receive_atomic(MRQ_SCLK_SKIP_SET_RATE,
4563 &mb, sizeof(mb), NULL, 0);
4568 static int tegra21_clk_super_skip_set_rate(struct clk *c, unsigned long rate)
4571 u64 output_rate = rate;
4572 unsigned long input_rate, flags;
4574 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
4577 * Locking parent clock prevents parent rate change while super skipper
4578 * is updated. It also takes care of super skippers that share h/w
4579 * register with parent clock divider. Skipper output rate can be
4580 * rounded up, since volatge is set based on source clock rate.
4582 clk_lock_save(c->parent, &flags);
4583 input_rate = clk_get_rate_locked(c->parent);
4585 div = 1 << SUPER_SKIPPER_TERM_SIZE;
4586 output_rate <<= SUPER_SKIPPER_TERM_SIZE;
4587 output_rate += input_rate - 1;
4588 do_div(output_rate, input_rate);
4589 mul = output_rate ? : 1;
4592 val = SUPER_SKIPPER_ENABLE |
4593 ((mul - 1) << SUPER_SKIPPER_MUL_SHIFT) |
4594 ((div - 1) << SUPER_SKIPPER_DIV_SHIFT);
4603 #ifdef CONFIG_TEGRA_BPMP_SCLK_SKIP
4604 /* For SCLK do not touch the register directly - send IPC to BPMP */
4605 if (c->flags & DIV_BUS)
4606 tegra_bpmp_sclk_skip_set_rate(input_rate, rate);
4609 clk_writel(val, c->reg);
4611 clk_unlock_restore(c->parent, &flags);
4615 static struct clk_ops tegra_clk_super_skip_ops = {
4616 .init = &tegra21_clk_super_skip_init,
4617 .enable = &tegra21_clk_super_skip_enable,
4618 .set_rate = &tegra21_clk_super_skip_set_rate,
4621 /* 1x shared bus ops */
4622 static long _1x_round_updown(struct clk *c, struct clk *src,
4623 unsigned long rate, bool up)
4625 return fixed_src_bus_round_updown(c, src, c->flags, rate, up, NULL);
4628 static long tegra21_1xbus_round_updown(struct clk *c, unsigned long rate,
4631 unsigned long pll_low_rate, pll_high_rate;
4633 rate = max(rate, c->min_rate);
4635 pll_low_rate = _1x_round_updown(c, c->u.periph.pll_low, rate, up);
4636 if (rate <= c->u.periph.threshold) {
4637 c->u.periph.pll_selected = c->u.periph.pll_low;
4638 return pll_low_rate;
4641 pll_high_rate = _1x_round_updown(c, c->u.periph.pll_high, rate, up);
4642 if (pll_high_rate <= c->u.periph.threshold) {
4643 c->u.periph.pll_selected = c->u.periph.pll_low;
4644 return pll_low_rate; /* prevent oscillation across threshold */
4648 /* rounding up: both plls may hit max, and round down */
4649 if (pll_high_rate < rate) {
4650 if (pll_low_rate < pll_high_rate) {
4651 c->u.periph.pll_selected = c->u.periph.pll_high;
4652 return pll_high_rate;
4655 if ((pll_low_rate < rate) ||
4656 (pll_low_rate > pll_high_rate)) {
4657 c->u.periph.pll_selected = c->u.periph.pll_high;
4658 return pll_high_rate;
4661 } else if (pll_low_rate < pll_high_rate) {
4662 /* rounding down: to get here both plls able to round down */
4663 c->u.periph.pll_selected = c->u.periph.pll_high;
4664 return pll_high_rate;
4666 c->u.periph.pll_selected = c->u.periph.pll_low;
4667 return pll_low_rate;
4670 static long tegra21_1xbus_round_rate(struct clk *c, unsigned long rate)
4672 return tegra21_1xbus_round_updown(c, rate, true);
4675 static int tegra21_1xbus_set_rate(struct clk *c, unsigned long rate)
4677 /* Compensate rate truncating during rounding */
4678 return tegra21_periph_clk_set_rate(c, rate + 1);
4681 static int tegra21_clk_1xbus_update(struct clk *c)
4684 struct clk *new_parent;
4685 unsigned long rate, old_rate;
4687 if (detach_shared_bus)
4690 rate = tegra21_clk_shared_bus_update(c, NULL, NULL, NULL);
4692 old_rate = clk_get_rate_locked(c);
4693 pr_debug("\n1xbus %s: rate %lu on parent %s: new request %lu\n",
4694 c->name, old_rate, c->parent->name, rate);
4695 if (rate == old_rate)
4698 if (!c->u.periph.min_div_low || !c->u.periph.min_div_high) {
4699 unsigned long r, m = c->max_rate;
4700 r = clk_get_rate(c->u.periph.pll_low);
4701 c->u.periph.min_div_low = DIV_ROUND_UP(r, m) * c->mul;
4702 r = clk_get_rate(c->u.periph.pll_high);
4703 c->u.periph.min_div_high = DIV_ROUND_UP(r, m) * c->mul;
4706 new_parent = c->u.periph.pll_selected;
4709 * The transition procedure below is guaranteed to switch to the target
4710 * parent/rate without violation of max clock limits. It would attempt
4711 * to switch without dip in bus rate if it is possible, but this cannot
4712 * be guaranteed (example: switch from 408 MHz : 1 to 624 MHz : 2 with
4713 * maximum bus limit 408 MHz will be executed as 408 => 204 => 312 MHz,
4714 * and there is no way to avoid rate dip in this case).
4716 if (new_parent != c->parent) {
4717 int interim_div = 0;
4718 /* Switching to pll_high may over-clock bus if current divider
4719 is too small - increase divider to safe value */
4720 if ((new_parent == c->u.periph.pll_high) &&
4721 (c->div < c->u.periph.min_div_high))
4722 interim_div = c->u.periph.min_div_high;
4724 /* Switching to pll_low may dip down rate if current divider
4725 is too big - decrease divider as much as we can */
4726 if ((new_parent == c->u.periph.pll_low) &&
4727 (c->div > c->u.periph.min_div_low) &&
4728 (c->div > c->u.periph.min_div_high))
4729 interim_div = c->u.periph.min_div_low;
4732 u64 interim_rate = old_rate * c->div;
4733 do_div(interim_rate, interim_div);
4734 ret = clk_set_rate_locked(c, interim_rate);
4736 pr_err("Failed to set %s rate to %lu\n",
4737 c->name, (unsigned long)interim_rate);
4740 pr_debug("1xbus %s: rate %lu on parent %s\n", c->name,
4741 clk_get_rate_locked(c), c->parent->name);
4744 ret = clk_set_parent_locked(c, new_parent);
4746 pr_err("Failed to set %s parent %s\n",
4747 c->name, new_parent->name);
4751 old_rate = clk_get_rate_locked(c);
4752 pr_debug("1xbus %s: rate %lu on parent %s\n", c->name,
4753 old_rate, c->parent->name);
4754 if (rate == old_rate)
4758 ret = clk_set_rate_locked(c, rate);
4760 pr_err("Failed to set %s rate to %lu\n", c->name, rate);
4763 pr_debug("1xbus %s: rate %lu on parent %s\n", c->name,
4764 clk_get_rate_locked(c), c->parent->name);
4769 static struct clk_ops tegra_1xbus_clk_ops = {
4770 .init = &tegra21_periph_clk_init,
4771 .enable = &tegra21_periph_clk_enable,
4772 .disable = &tegra21_periph_clk_disable,
4773 .set_parent = &tegra21_periph_clk_set_parent,
4774 .set_rate = &tegra21_1xbus_set_rate,
4775 .round_rate = &tegra21_1xbus_round_rate,
4776 .round_rate_updown = &tegra21_1xbus_round_updown,
4777 .reset = &tegra21_periph_clk_reset,
4778 .shared_bus_update = &tegra21_clk_1xbus_update,
4781 /* Periph VI extended clock configuration ops */
4783 tegra21_vi_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
4785 if (p == TEGRA_CLK_VI_INP_SEL) {
4786 u32 val = clk_readl(c->reg);
4787 val &= ~PERIPH_CLK_VI_SEL_EX_MASK;
4788 val |= (setting << PERIPH_CLK_VI_SEL_EX_SHIFT) &
4789 PERIPH_CLK_VI_SEL_EX_MASK;
4790 clk_writel(val, c->reg);
4796 static struct clk_ops tegra_vi_clk_ops = {
4797 .init = &tegra21_periph_clk_init,
4798 .enable = &tegra21_periph_clk_enable,
4799 .disable = &tegra21_periph_clk_disable,
4800 .set_parent = &tegra21_periph_clk_set_parent,
4801 .set_rate = &tegra21_periph_clk_set_rate,
4802 .round_rate = &tegra21_periph_clk_round_rate,
4803 .clk_cfg_ex = &tegra21_vi_clk_cfg_ex,
4804 .reset = &tegra21_periph_clk_reset,
4807 /* SOR clocks operations */
4808 static void tegra21_sor_brick_init(struct clk *c)
4811 * Brick configuration is under DC driver control - wiil be in sync
4812 * with h/w after DC SOR init.
4814 c->parent = c->inputs[0].input;
4815 c->state = c->parent->state;
4821 static int tegra21_sor_brick_set_rate(struct clk *c, unsigned long rate)
4824 * Brick rate is under DC driver control, this interface is used for
4825 * information purposes, as well as for DVFS update.
4827 unsigned long parent_rate = clk_get_rate(c->parent);
4829 c->div = 10; /* brick link divisor */
4831 mul = mul * rate + parent_rate / 2;
4832 do_div(mul, parent_rate);
4838 static int tegra21_sor_brick_set_parent(struct clk *c, struct clk *p)
4841 const struct clk_mux_sel *sel;
4843 if (!(c->flags & MUX))
4844 return (p == c->parent) ? 0 : (-EINVAL);
4846 * Brick parent selection is under DC driver control, this interface
4847 * is used to propagate enable/disable relations, for information
4848 * purposes, as well as for DVFS update.
4850 for (sel = c->inputs; sel->input != NULL; sel++) {
4851 if (sel->input == p) {
4853 tegra_clk_prepare_enable(p);
4854 tegra_clk_disable_unprepare(c->parent);
4863 static struct clk_ops tegra_sor_brick_ops = {
4864 .init = &tegra21_sor_brick_init,
4865 .enable = &tegra21_periph_clk_enable,
4866 .disable = &tegra21_periph_clk_disable,
4867 .set_parent = &tegra21_sor_brick_set_parent,
4868 .set_rate = &tegra21_sor_brick_set_rate,
4871 static void tegra21_sor0_clk_init(struct clk *c)
4873 c->u.periph.src_mask = PERIPH_CLK_SOR0_CLK_SEL_MASK;
4874 c->u.periph.src_shift = PERIPH_CLK_SOR_CLK_SEL_SHIFT;
4875 tegra21_periph_clk_init(c);
4879 tegra21_sor0_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
4881 if (p == TEGRA_CLK_SOR_CLK_SEL) {
4882 int i = setting ? 1 : 0;
4883 return clk_set_parent_locked(c, c->inputs[i].input);
4888 static struct clk_ops tegra_sor0_clk_ops = {
4889 .init = &tegra21_sor0_clk_init,
4890 .enable = &tegra21_periph_clk_enable,
4891 .disable = &tegra21_periph_clk_disable,
4892 .set_parent = &tegra21_periph_clk_set_parent,
4893 .clk_cfg_ex = &tegra21_sor0_clk_cfg_ex,
4894 .reset = &tegra21_periph_clk_reset,
4897 static void tegra21_sor1_clk_init(struct clk *c)
4899 c->u.periph.src_mask = PERIPH_CLK_SOR1_CLK_SEL_MASK;
4900 c->u.periph.src_shift = PERIPH_CLK_SOR_CLK_SEL_SHIFT;
4901 tegra21_periph_clk_init(c);
4904 static int tegra21_sor1_clk_set_parent(struct clk *c, struct clk *p)
4907 unsigned long flags;
4908 const struct clk_mux_sel *sel;
4909 struct clk *src = c->inputs[2].input; /* sor1_src entry in sor1 mux */
4911 for (sel = c->inputs; sel->input != NULL; sel++) {
4912 if (sel->input == p) {
4914 tegra_clk_prepare_enable(p);
4916 * Since sor1 output mux control setting share the same
4917 * register with source mux/divider switch, use switch
4918 * lock to protect r-m-w of output mux controls
4920 clk_lock_save(src, &flags);
4921 val = clk_readl(c->reg);
4922 val &= ~periph_clk_source_mask(c);
4923 val |= (sel->value << periph_clk_source_shift(c));
4924 clk_writel_delay(val, c->reg);
4925 clk_unlock_restore(src, &flags);
4928 tegra_clk_disable_unprepare(c->parent);
4938 tegra21_sor1_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
4941 if ((p != TEGRA_CLK_SOR_CLK_SEL) || (setting > 3))
4944 * If LSb is set, sor1_brick is selected regardless of MSb. As such
4945 * setting 3 and 1 result in the same clock source. The set parent api
4946 * always selects the 1st match for requested parent, so effectively
4947 * setting 3 is reduced to 1.
4949 return clk_set_parent_locked(c, c->inputs[setting].input);
4952 static struct clk_ops tegra_sor1_clk_ops = {
4953 .init = &tegra21_sor1_clk_init,
4954 .enable = &tegra21_periph_clk_enable,
4955 .disable = &tegra21_periph_clk_disable,
4956 .set_parent = &tegra21_sor1_clk_set_parent,
4957 .clk_cfg_ex = &tegra21_sor1_clk_cfg_ex,
4958 .reset = &tegra21_periph_clk_reset,
4961 /* Periph DTV extended clock configuration ops */
4963 tegra21_dtv_clk_cfg_ex(struct clk *c, enum tegra_clk_ex_param p, u32 setting)
4965 if (p == TEGRA_CLK_DTV_INVERT) {
4966 u32 val = clk_readl(c->reg);
4968 val |= PERIPH_CLK_DTV_POLARITY_INV;
4970 val &= ~PERIPH_CLK_DTV_POLARITY_INV;
4971 clk_writel(val, c->reg);
4977 static struct clk_ops tegra_dtv_clk_ops = {
4978 .init = &tegra21_periph_clk_init,
4979 .enable = &tegra21_periph_clk_enable,
4980 .disable = &tegra21_periph_clk_disable,
4981 .set_parent = &tegra21_periph_clk_set_parent,
4982 .set_rate = &tegra21_periph_clk_set_rate,
4983 .round_rate = &tegra21_periph_clk_round_rate,
4984 .clk_cfg_ex = &tegra21_dtv_clk_cfg_ex,
4985 .reset = &tegra21_periph_clk_reset,
4988 static void tegra21_dpaux_clk_init(struct clk *c)
4992 tegra21_periph_clk_init(c);
4995 static struct clk_ops tegra_dpaux_clk_ops = {
4996 .init = &tegra21_dpaux_clk_init,
4997 .enable = &tegra21_periph_clk_enable,
4998 .disable = &tegra21_periph_clk_disable,
4999 .set_parent = &tegra21_periph_clk_set_parent,
5000 .set_rate = &tegra21_periph_clk_set_rate,
5001 .reset = &tegra21_periph_clk_reset,
5004 /* XUSB SS clock ops */
5005 static DEFINE_SPINLOCK(xusb_ss_lock);
5007 static int tegra21_xusb_ss_set_rate(struct clk *c, unsigned long rate)
5010 unsigned long flags;
5012 spin_lock_irqsave(&xusb_ss_lock, flags);
5013 ret = tegra21_periph_clk_set_rate(c, rate);
5014 spin_unlock_irqrestore(&xusb_ss_lock, flags);
5018 static int tegra21_xusb_ss_set_parent(struct clk *c, struct clk *p)
5021 unsigned long flags;
5022 const struct clk_mux_sel *sel;
5023 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
5025 for (sel = c->inputs; sel->input != NULL; sel++) {
5026 if (sel->input == p) {
5028 tegra_clk_prepare_enable(p);
5030 spin_lock_irqsave(&xusb_ss_lock, flags);
5031 val = clk_readl(c->reg);
5032 val &= ~periph_clk_source_mask(c);
5033 val |= (sel->value << periph_clk_source_shift(c));
5034 clk_writel_delay(val, c->reg);
5035 spin_unlock_irqrestore(&xusb_ss_lock, flags);
5037 if (c->refcnt && c->parent)
5038 tegra_clk_disable_unprepare(c->parent);
5048 static struct clk_ops tegra_xusb_ss_ops = {
5049 .init = &tegra21_periph_clk_init,
5050 .enable = &tegra21_periph_clk_enable,
5051 .disable = &tegra21_periph_clk_disable,
5052 .set_parent = &tegra21_xusb_ss_set_parent,
5053 .set_rate = &tegra21_xusb_ss_set_rate,
5054 .round_rate = &tegra21_periph_clk_round_rate,
5055 .reset = &tegra21_periph_clk_reset,
5058 /* pciex clock support only reset function */
5059 static void tegra21_pciex_clk_init(struct clk *c)
5061 c->state = c->parent->state;
5064 static int tegra21_pciex_clk_enable(struct clk *c)
5069 static void tegra21_pciex_clk_disable(struct clk *c)
5073 static int tegra21_pciex_clk_set_rate(struct clk *c, unsigned long rate)
5075 unsigned long parent_rate = clk_get_rate(c->parent);
5078 * the only supported pcie configurations:
5079 * Gen1: plle = 100MHz, link at 250MHz
5080 * Gen2: plle = 100MHz, link at 500MHz
5082 if (parent_rate == 100000000) {
5083 if (rate == 500000000) {
5087 } else if (rate == 250000000) {
5096 static struct clk_ops tegra_pciex_clk_ops = {
5097 .init = tegra21_pciex_clk_init,
5098 .enable = tegra21_pciex_clk_enable,
5099 .disable = tegra21_pciex_clk_disable,
5100 .set_rate = tegra21_pciex_clk_set_rate,
5101 .reset = tegra21_periph_clk_reset,
5105 /* SDMMC2 and SDMMC4 ops */
5106 static u32 sdmmc24_input_to_lj[] = {
5107 /* 0, 1, 2, 3, 4, 5, 6, 7 */
5108 0, 1, 2, 1, 5, 5, 6, 2
5111 static u32 sdmmc24_input_from_lj[] = {
5112 /* 0, 1, 2, 3, 4, 5, 6, 7 */
5113 0, 3, 7, 3, 4, 4, 6, 7
5117 * The same PLLC4 output branches connected to the low jitter (LJ) and divided
5118 * inputs of the SDMMC2/4 source selection mux. The difference is that clock
5119 * from LJ input does not go through SDMMC2/4 divider. Although it is possible
5120 * to run output clock at the same rate as source from divided input (with
5121 * divider 1:1 setting), the implementation below automatically switches to LJ
5122 * input when SDMMC2/4 clock rate is set equal to the source rate, and one of
5123 * PLLC4 branches is used as a source. Changing SDMMC rate-to-source ratio
5124 * from 1:1 automatically selects divided input. This switching mechanism has
5125 * no effect when PLLP or CLK_M is used as clock source.
5127 * See also mux_pllp_clk_m_pllc4_out2_out1_out0_lj definition for detailed list
5128 * of LJ and divided inputs.
5131 static void sdmmc24_remap_inputs(struct clk *c)
5133 u32 sel_out, sel_in;
5134 u32 val = clk_readl(c->reg);
5136 sel_in = (val & periph_clk_source_mask(c)) >>
5137 periph_clk_source_shift(c);
5139 sel_out = (c->mul == c->div) ? sdmmc24_input_to_lj[sel_in] :
5140 sdmmc24_input_from_lj[sel_in];
5142 if (sel_out != sel_in) {
5143 val &= ~periph_clk_source_mask(c);
5144 val |= (sel_out << periph_clk_source_shift(c));
5146 clk_writel_delay(val, c->reg);
5151 static void tegra21_sdmmc24_clk_init(struct clk *c)
5153 tegra21_periph_clk_init(c);
5154 sdmmc24_remap_inputs(c);
5157 static int tegra21_sdmmc24_clk_set_rate(struct clk *c, unsigned long rate)
5159 int ret = tegra21_periph_clk_set_rate(c, rate);
5161 sdmmc24_remap_inputs(c);
5165 static int tegra21_sdmmc24_clk_set_parent(struct clk *c, struct clk *p)
5168 const struct clk_mux_sel *sel;
5169 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
5171 for (sel = c->inputs; sel->input != NULL; sel++) {
5172 if (sel->input == p) {
5173 sel_val = (c->mul == c->div) ?
5174 sdmmc24_input_to_lj[sel->value] :
5175 sdmmc24_input_from_lj[sel->value];
5177 val = clk_readl(c->reg);
5178 val &= ~periph_clk_source_mask(c);
5179 val |= (sel_val << periph_clk_source_shift(c));
5182 tegra_clk_prepare_enable(p);
5184 clk_writel_delay(val, c->reg);
5186 if (c->refcnt && c->parent)
5187 tegra_clk_disable_unprepare(c->parent);
5196 static struct clk_ops tegra_sdmmc24_clk_ops = {
5197 .init = &tegra21_sdmmc24_clk_init,
5198 .enable = &tegra21_periph_clk_enable,
5199 .disable = &tegra21_periph_clk_disable,
5200 .set_parent = &tegra21_sdmmc24_clk_set_parent,
5201 .set_rate = &tegra21_sdmmc24_clk_set_rate,
5202 .round_rate = &tegra21_periph_clk_round_rate,
5203 .reset = &tegra21_periph_clk_reset,
5206 /* SLCG clock ops */
5207 static DEFINE_SPINLOCK(clk_slcg_lock);
5209 static void tegra21_clk_slcg_init(struct clk *c)
5213 u32 val = clk_readl(c->reg);
5215 c->state = (val & (0x1 << c->u.periph.clk_num)) ? ON : OFF;
5217 strcpy(root_name, c->name);
5218 end = strstr(root_name, "_slcg_ovr");
5221 c->parent = tegra_get_clock_by_name(root_name);
5224 if (WARN(!c->parent, "%s: %s parent %s not found\n",
5225 __func__, c->name, root_name))
5228 c->max_rate = c->parent->max_rate;
5232 static int tegra21_clk_slcg_enable(struct clk *c)
5235 unsigned long flags;
5237 pr_debug("%s on clock %s\n", __func__, c->name);
5239 spin_lock_irqsave(&clk_slcg_lock, flags);
5240 val = clk_readl(c->reg);
5241 val |= (0x1 << c->u.periph.clk_num);
5242 clk_writel_delay(val, c->reg);
5243 spin_unlock_irqrestore(&clk_slcg_lock, flags);
5248 static void tegra21_clk_slcg_disable(struct clk *c)
5251 unsigned long flags;
5253 pr_debug("%s on clock %s\n", __func__, c->name);
5255 spin_lock_irqsave(&clk_slcg_lock, flags);
5256 val = clk_readl(c->reg);
5257 val &= ~(0x1 << c->u.periph.clk_num);
5258 clk_writel_delay(val, c->reg);
5259 spin_unlock_irqrestore(&clk_slcg_lock, flags);
5262 static struct clk_ops tegra_clk_slcg_ops = {
5263 .init = &tegra21_clk_slcg_init,
5264 .enable = &tegra21_clk_slcg_enable,
5265 .disable = &tegra21_clk_slcg_disable,
5268 /* Output clock ops */
5269 static DEFINE_SPINLOCK(clk_out_lock);
5271 static void tegra21_clk_out_init(struct clk *c)
5273 const struct clk_mux_sel *mux = NULL;
5274 const struct clk_mux_sel *sel;
5275 u32 val = pmc_readl(c->reg);
5277 c->state = (val & (0x1 << c->u.periph.clk_num)) ? ON : OFF;
5281 for (sel = c->inputs; sel->input != NULL; sel++) {
5282 if (((val & periph_clk_source_mask(c)) >>
5283 periph_clk_source_shift(c)) == sel->value)
5287 c->parent = mux->input;
5290 static int tegra21_clk_out_enable(struct clk *c)
5293 unsigned long flags;
5295 pr_debug("%s on clock %s\n", __func__, c->name);
5297 spin_lock_irqsave(&clk_out_lock, flags);
5298 val = pmc_readl(c->reg);
5299 val |= (0x1 << c->u.periph.clk_num);
5300 pmc_writel(val, c->reg);
5302 spin_unlock_irqrestore(&clk_out_lock, flags);
5307 static void tegra21_clk_out_disable(struct clk *c)
5310 unsigned long flags;
5312 pr_debug("%s on clock %s\n", __func__, c->name);
5314 spin_lock_irqsave(&clk_out_lock, flags);
5315 val = pmc_readl(c->reg);
5316 val &= ~(0x1 << c->u.periph.clk_num);
5317 pmc_writel(val, c->reg);
5319 spin_unlock_irqrestore(&clk_out_lock, flags);
5322 static int tegra21_clk_out_set_parent(struct clk *c, struct clk *p)
5325 unsigned long flags;
5326 const struct clk_mux_sel *sel;
5328 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
5330 for (sel = c->inputs; sel->input != NULL; sel++) {
5331 if (sel->input == p) {
5333 tegra_clk_prepare_enable(p);
5335 spin_lock_irqsave(&clk_out_lock, flags);
5336 val = pmc_readl(c->reg);
5337 val &= ~periph_clk_source_mask(c);
5338 val |= (sel->value << periph_clk_source_shift(c));
5339 pmc_writel(val, c->reg);
5341 spin_unlock_irqrestore(&clk_out_lock, flags);
5343 if (c->refcnt && c->parent)
5344 tegra_clk_disable_unprepare(c->parent);
5353 static struct clk_ops tegra_clk_out_ops = {
5354 .init = &tegra21_clk_out_init,
5355 .enable = &tegra21_clk_out_enable,
5356 .disable = &tegra21_clk_out_disable,
5357 .set_parent = &tegra21_clk_out_set_parent,
5361 /* External memory controller clock ops */
5362 static void tegra21_emc_clk_init(struct clk *c)
5364 tegra21_periph_clk_init(c);
5365 tegra_emc_dram_type_init(c);
5368 static long tegra21_emc_clk_round_updown(struct clk *c, unsigned long rate,
5371 unsigned long new_rate = max(rate, c->min_rate);
5373 new_rate = tegra_emc_round_rate_updown(new_rate, up);
5374 if (IS_ERR_VALUE(new_rate))
5375 new_rate = c->max_rate;
5380 static long tegra21_emc_clk_round_rate(struct clk *c, unsigned long rate)
5382 return tegra21_emc_clk_round_updown(c, rate, true);
5385 void tegra_mc_divider_update(struct clk *emc)
5387 u32 val = clk_readl(emc->reg) &
5388 (PERIPH_CLK_SOURCE_EMC_MC_SAME | PERIPH_CLK_SOURCE_EMC_DIV2_EN);
5389 emc->child_bus->div = val == 1 ? 4 : (val == 2 ? 1 : 2);
5392 static int tegra21_emc_clk_set_rate(struct clk *c, unsigned long rate)
5398 /* The tegra21x memory controller has an interlock with the clock
5399 * block that allows memory shadowed registers to be updated,
5400 * and then transfer them to the main registers at the same
5401 * time as the clock update without glitches. During clock change
5402 * operation both clock parent and divider may change simultaneously
5403 * to achieve requested rate. */
5404 p = tegra_emc_predict_parent(rate, &div_value);
5405 div_value += 2; /* emc has fractional DIV_U71 divider */
5406 if (IS_ERR_OR_NULL(p)) {
5407 pr_err("%s: Failed to predict emc parent for rate %lu\n",
5412 if (p == c->parent) {
5413 if (div_value == c->div)
5415 } else if (c->refcnt)
5416 tegra_clk_prepare_enable(p);
5418 ret = tegra_emc_set_rate_on_parent(rate, p);
5422 if (p != c->parent) {
5423 if(c->refcnt && c->parent)
5424 tegra_clk_disable_unprepare(c->parent);
5432 static int tegra21_clk_emc_bus_update(struct clk *bus)
5434 struct clk *p = NULL;
5435 unsigned long rate, parent_rate, backup_rate;
5437 if (detach_shared_bus)
5440 rate = tegra21_clk_shared_bus_update(bus, NULL, NULL, NULL);
5442 if (rate == clk_get_rate_locked(bus))
5445 return clk_set_rate_locked(bus, rate);
5448 static struct clk_ops tegra_emc_clk_ops = {
5449 .init = &tegra21_emc_clk_init,
5450 .enable = &tegra21_periph_clk_enable,
5451 .disable = &tegra21_periph_clk_disable,
5452 .set_rate = &tegra21_emc_clk_set_rate,
5453 .round_rate = &tegra21_emc_clk_round_rate,
5454 .round_rate_updown = &tegra21_emc_clk_round_updown,
5455 .reset = &tegra21_periph_clk_reset,
5456 .shared_bus_update = &tegra21_clk_emc_bus_update,
5459 static void tegra21_mc_clk_init(struct clk *c)
5462 if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c)))
5465 c->parent->child_bus = c;
5466 tegra_mc_divider_update(c->parent);
5470 static struct clk_ops tegra_mc_clk_ops = {
5471 .init = &tegra21_mc_clk_init,
5472 .enable = &tegra21_periph_clk_enable,
5473 .disable = &tegra21_periph_clk_disable,
5477 * EMC parent selection algorithm always keeps PLLM and/or PLLMB disabled when
5478 * the respective PLL is not used as EMC clock source. However, boot-loader may
5479 * leave both PLLs enabled. To allow proper start of the algorithm, make sure
5480 * PLLs are disabled if not used.
5482 static void tegra21_emc_sync_plls(struct clk *emc,
5483 struct clk *pllm, struct clk *pllmb)
5485 if (emc->parent != pllm) {
5486 if (pllm->state == ON) {
5487 pllm->ops->disable(pllm);
5492 if (emc->parent != pllmb) {
5493 if (pllmb->state == ON) {
5494 pllmb->ops->disable(pllmb);
5500 #ifdef CONFIG_PM_SLEEP
5503 * WAR: fixing SC7 entry rate is to ensure stable boot up after SC7 resume on
5504 * LP4 platforms. This ensures that there are no MRWs necesary by the bootrom
5505 * when waking the DRAM (since the MRs will already have valid settings for 204
5506 * MHz). Problem is that the BR is not aware of what FSP is in use.
5508 #define FIXED_SC7_ENTRY_RATE 204000000
5510 static void tegra21_emc_clk_suspend(struct clk *c, unsigned long rate)
5512 /* No change if other than LPDDR4 */
5513 if (tegra_emc_get_dram_type() != DRAM_TYPE_LPDDR4)
5516 /* No change in emc configuration for LP1 */
5517 if (!tegra_is_lp0_suspend_mode())
5521 * Scale EMC rate at boot rate - required for entering SC7(LP0)
5524 if (rate != FIXED_SC7_ENTRY_RATE)
5525 tegra21_emc_clk_set_rate(c, FIXED_SC7_ENTRY_RATE);
5529 /* Clock doubler ops (non-atomic shared register access) */
5530 static DEFINE_SPINLOCK(doubler_lock);
5532 static void tegra21_clk_double_init(struct clk *c)
5534 u32 val = clk_readl(c->reg);
5535 c->mul = val & (0x1 << c->reg_shift) ? 1 : 2;
5538 if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c)))
5542 static int tegra21_clk_double_set_rate(struct clk *c, unsigned long rate)
5545 unsigned long parent_rate = clk_get_rate(c->parent);
5546 unsigned long flags;
5548 if (rate == parent_rate) {
5549 spin_lock_irqsave(&doubler_lock, flags);
5550 val = clk_readl(c->reg) | (0x1 << c->reg_shift);
5551 clk_writel(val, c->reg);
5554 spin_unlock_irqrestore(&doubler_lock, flags);
5556 } else if (rate == 2 * parent_rate) {
5557 spin_lock_irqsave(&doubler_lock, flags);
5558 val = clk_readl(c->reg) & (~(0x1 << c->reg_shift));
5559 clk_writel(val, c->reg);
5562 spin_unlock_irqrestore(&doubler_lock, flags);
5568 static struct clk_ops tegra_clk_double_ops = {
5569 .init = &tegra21_clk_double_init,
5570 .enable = &tegra21_periph_clk_enable,
5571 .disable = &tegra21_periph_clk_disable,
5572 .set_rate = &tegra21_clk_double_set_rate,
5575 /* Audio sync clock ops */
5576 static int tegra21_sync_source_set_rate(struct clk *c, unsigned long rate)
5582 static struct clk_ops tegra_sync_source_ops = {
5583 .set_rate = &tegra21_sync_source_set_rate,
5586 static void tegra21_audio_sync_clk_init(struct clk *c)
5589 const struct clk_mux_sel *sel;
5590 u32 val = clk_readl(c->reg);
5591 c->state = (val & AUDIO_SYNC_DISABLE_BIT) ? OFF : ON;
5592 source = val & AUDIO_SYNC_SOURCE_MASK;
5593 for (sel = c->inputs; sel->input != NULL; sel++)
5594 if (sel->value == source)
5596 BUG_ON(sel->input == NULL);
5597 c->parent = sel->input;
5600 static int tegra21_audio_sync_clk_enable(struct clk *c)
5602 u32 val = clk_readl(c->reg);
5603 clk_writel((val & (~AUDIO_SYNC_DISABLE_BIT)), c->reg);
5607 static void tegra21_audio_sync_clk_disable(struct clk *c)
5609 u32 val = clk_readl(c->reg);
5610 clk_writel((val | AUDIO_SYNC_DISABLE_BIT), c->reg);
5613 static int tegra21_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
5616 const struct clk_mux_sel *sel;
5617 for (sel = c->inputs; sel->input != NULL; sel++) {
5618 if (sel->input == p) {
5619 val = clk_readl(c->reg);
5620 val &= ~AUDIO_SYNC_SOURCE_MASK;
5624 tegra_clk_prepare_enable(p);
5626 clk_writel(val, c->reg);
5628 if (c->refcnt && c->parent)
5629 tegra_clk_disable_unprepare(c->parent);
5639 static struct clk_ops tegra_audio_sync_clk_ops = {
5640 .init = tegra21_audio_sync_clk_init,
5641 .enable = tegra21_audio_sync_clk_enable,
5642 .disable = tegra21_audio_sync_clk_disable,
5643 .set_parent = tegra21_audio_sync_clk_set_parent,
5646 /* cml0 (pcie), and cml1 (sata) clock ops */
5647 static void tegra21_cml_clk_init(struct clk *c)
5649 u32 val = clk_readl(c->reg);
5650 c->state = val & (0x1 << c->u.periph.clk_num) ? ON : OFF;
5653 static int tegra21_cml_clk_enable(struct clk *c)
5656 unsigned long flags;
5657 struct clk *parent = c->parent;
5659 clk_lock_save(parent, &flags);
5660 val = clk_readl(c->reg);
5661 val |= (0x1 << c->u.periph.clk_num);
5662 clk_writel(val, c->reg);
5663 clk_unlock_restore(parent, &flags);
5668 static void tegra21_cml_clk_disable(struct clk *c)
5671 unsigned long flags;
5672 struct clk *parent = c->parent;
5674 clk_lock_save(parent, &flags);
5675 val = clk_readl(c->reg);
5676 val &= ~(0x1 << c->u.periph.clk_num);
5677 clk_writel(val, c->reg);
5678 clk_unlock_restore(parent, &flags);
5681 static struct clk_ops tegra_cml_clk_ops = {
5682 .init = &tegra21_cml_clk_init,
5683 .enable = &tegra21_cml_clk_enable,
5684 .disable = &tegra21_cml_clk_disable,
5689 * Some clocks require dynamic re-locking of source PLL in order to
5690 * achieve frequency scaling granularity that matches characterized
5691 * core voltage steps. The cbus clock creates a shared bus that
5692 * provides a virtual root for such clocks to hide and synchronize
5693 * parent PLL re-locking as well as backup operations.
5696 static void tegra21_clk_cbus_init(struct clk *c)
5702 static int tegra21_clk_cbus_enable(struct clk *c)
5707 static long tegra21_clk_cbus_round_updown(struct clk *c, unsigned long rate,
5714 c->min_rate = c->parent->min_rate;
5715 rate = max(rate, c->min_rate);
5719 /* update min now, since no dvfs table was available during init
5720 (skip placeholder entries set to 1 kHz) */
5722 for (i = 0; i < c->dvfs->num_freqs; i++) {
5723 if (c->dvfs->freqs[i] > 1 * c->dvfs->freqs_mult) {
5724 c->min_rate = c->dvfs->freqs[i];
5728 BUG_ON(!c->min_rate);
5730 if (c->stats.histogram) {
5731 c->stats.histogram->rates_num = c->dvfs->num_freqs;
5732 tegra_shared_bus_stats_allocate(c, c->stats.histogram);
5735 rate = max(rate, c->min_rate);
5737 for (i = 0; ; i++) {
5738 unsigned long f = c->dvfs->freqs[i];
5739 if ((f >= rate) || ((i + 1) >= c->dvfs->num_freqs)) {
5740 if (!up && i && (f > rate))
5746 if (c->stats.histogram)
5747 c->stats.histogram->new_rate_idx = i;
5748 return c->dvfs->freqs[i];
5751 static long tegra21_clk_cbus_round_rate(struct clk *c, unsigned long rate)
5753 return tegra21_clk_cbus_round_updown(c, rate, true);
5756 static int cbus_switch_one(struct clk *c, struct clk *p, u32 div, bool abort)
5760 /* set new divider if it is bigger than the current one */
5761 if (c->div < c->mul * div) {
5762 ret = clk_set_div(c, div);
5764 pr_err("%s: failed to set %s clock divider %u: %d\n",
5765 __func__, c->name, div, ret);
5771 if (c->parent != p) {
5772 ret = clk_set_parent(c, p);
5774 pr_err("%s: failed to set %s clock parent %s: %d\n",
5775 __func__, c->name, p->name, ret);
5781 /* set new divider if it is smaller than the current one */
5782 if (c->div > c->mul * div) {
5783 ret = clk_set_div(c, div);
5785 pr_err("%s: failed to set %s clock divider %u: %d\n",
5786 __func__, c->name, div, ret);
5792 static int cbus_backup(struct clk *c)
5797 list_for_each_entry(user, &c->shared_bus_list,
5798 u.shared_bus_user.node) {
5799 struct clk *client = user->u.shared_bus_user.client;
5800 if (client && (client->state == ON) &&
5801 (client->parent == c->parent)) {
5802 ret = cbus_switch_one(
5803 client, c->shared_bus_backup.input,
5804 c->shared_bus_backup.value, true);
5812 static int cbus_dvfs_set_rate(struct clk *c, unsigned long rate)
5817 list_for_each_entry(user, &c->shared_bus_list,
5818 u.shared_bus_user.node) {
5819 struct clk *client = user->u.shared_bus_user.client;
5820 if (client && client->refcnt && (client->parent == c->parent)) {
5821 ret = tegra_dvfs_set_rate(client, rate);
5829 static void cbus_restore(struct clk *c)
5833 list_for_each_entry(user, &c->shared_bus_list,
5834 u.shared_bus_user.node) {
5835 struct clk *client = user->u.shared_bus_user.client;
5837 cbus_switch_one(client, c->parent, c->div, false);
5841 static void cbus_skip(struct clk *c, unsigned long bus_rate)
5846 if (!(c->shared_bus_flags & SHARED_BUS_USE_SKIPPERS))
5849 list_for_each_entry(user, &c->shared_bus_list,
5850 u.shared_bus_user.node) {
5851 struct clk *client = user->u.shared_bus_user.client;
5852 if (client && client->skipper &&
5853 user->u.shared_bus_user.enabled) {
5854 /* Make sure skipper output is above the target */
5855 rate = user->u.shared_bus_user.rate;
5856 rate += bus_rate >> SUPER_SKIPPER_TERM_SIZE;
5858 clk_set_rate(client->skipper, rate);
5859 user->div = client->skipper->div;
5860 user->mul = client->skipper->mul;
5865 static int get_next_backup_div(struct clk *c, unsigned long rate)
5868 unsigned long backup_rate = clk_get_rate(c->shared_bus_backup.input);
5870 rate = max(rate, clk_get_rate_locked(c));
5871 rate = rate - (rate >> 2); /* 25% margin for backup rate */
5872 if ((u64)rate * div < backup_rate)
5873 div = DIV_ROUND_UP(backup_rate, rate);
5879 static int tegra21_clk_cbus_set_rate(struct clk *c, unsigned long rate)
5887 ret = tegra_clk_prepare_enable(c->parent);
5889 pr_err("%s: failed to enable %s clock: %d\n",
5890 __func__, c->name, ret);
5894 dramp = tegra_pll_can_ramp_to_rate(c->parent, rate * c->div);
5896 c->shared_bus_backup.value = get_next_backup_div(c, rate);
5897 ret = cbus_backup(c);
5902 ret = clk_set_rate(c->parent, rate * c->div);
5904 pr_err("%s: failed to set %s clock rate %lu: %d\n",
5905 __func__, c->name, rate, ret);
5909 /* Safe voltage setting is taken care of by cbus clock dvfs; the call
5910 * below only records requirements for each enabled client.
5913 ret = cbus_dvfs_set_rate(c, rate);
5919 tegra_clk_disable_unprepare(c->parent);
5923 static inline void cbus_move_enabled_user(
5924 struct clk *user, struct clk *dst, struct clk *src)
5926 tegra_clk_prepare_enable(dst);
5927 list_move_tail(&user->u.shared_bus_user.node, &dst->shared_bus_list);
5928 tegra_clk_disable_unprepare(src);
5929 clk_reparent(user, dst);
5932 #ifdef CONFIG_TEGRA_DYNAMIC_CBUS
5933 static int tegra21_clk_cbus_update(struct clk *bus)
5936 struct clk *slow = NULL;
5937 struct clk *top = NULL;
5939 unsigned long old_rate;
5940 unsigned long ceiling;
5942 if (detach_shared_bus)
5945 rate = tegra21_clk_shared_bus_update(bus, &top, &slow, &ceiling);
5947 /* use dvfs table of the slowest enabled client as cbus dvfs table */
5948 if (bus->dvfs && slow && (slow != bus->u.cbus.slow_user)) {
5949 unsigned long *dest = &bus->dvfs->freqs[0];
5950 unsigned long *src =
5951 &slow->u.shared_bus_user.client->dvfs->freqs[0];
5952 memcpy(dest, src, sizeof(*dest) * bus->dvfs->num_freqs);
5955 /* update bus state variables and rate */
5956 bus->u.cbus.slow_user = slow;
5957 bus->u.cbus.top_user = top;
5959 rate = tegra21_clk_cap_shared_bus(bus, rate, ceiling);
5960 mv = tegra_dvfs_predict_mv_at_hz_no_tfloor(bus, rate);
5961 if (IS_ERR_VALUE(mv))
5965 mv -= bus->dvfs->cur_millivolts;
5966 if (bus->refcnt && (mv > 0)) {
5967 ret = tegra_dvfs_set_rate(bus, rate);
5973 old_rate = clk_get_rate_locked(bus);
5974 if (IS_ENABLED(CONFIG_TEGRA_MIGRATE_CBUS_USERS) || (old_rate != rate)) {
5975 ret = bus->ops->set_rate(bus, rate);
5979 /* Skippers may change even if bus rate is the same */
5980 cbus_skip(bus, rate);
5984 if (bus->refcnt && (mv <= 0)) {
5985 ret = tegra_dvfs_set_rate(bus, rate);
5991 clk_rate_change_notify(bus, rate);
5995 static int tegra21_clk_cbus_update(struct clk *bus)
5997 unsigned long rate, old_rate;
5999 if (detach_shared_bus)
6002 rate = tegra21_clk_shared_bus_update(bus, NULL, NULL, NULL);
6004 old_rate = clk_get_rate_locked(bus);
6005 if (rate == old_rate) {
6006 /* Skippers may change even if bus rate is the same */
6007 cbus_skip(bus, rate);
6011 return clk_set_rate_locked(bus, rate);
6015 static int tegra21_clk_cbus_migrate_users(struct clk *user)
6017 #ifdef CONFIG_TEGRA_MIGRATE_CBUS_USERS
6018 struct clk *src_bus, *dst_bus, *top_user, *c;
6019 struct list_head *pos, *n;
6021 if (!user->u.shared_bus_user.client || !user->inputs)
6024 /* Dual cbus on Tegra12 */
6025 src_bus = user->inputs[0].input;
6026 dst_bus = user->inputs[1].input;
6028 if (!src_bus->u.cbus.top_user && !dst_bus->u.cbus.top_user)
6031 /* Make sure top user on the source bus is requesting highest rate */
6032 if (!src_bus->u.cbus.top_user || (dst_bus->u.cbus.top_user &&
6033 bus_user_request_is_lower(src_bus->u.cbus.top_user,
6034 dst_bus->u.cbus.top_user)))
6035 swap(src_bus, dst_bus);
6037 /* If top user is the slow one on its own (source) bus, do nothing */
6038 top_user = src_bus->u.cbus.top_user;
6039 BUG_ON(!top_user->u.shared_bus_user.client);
6040 if (!bus_user_is_slower(src_bus->u.cbus.slow_user, top_user))
6043 /* If source bus top user is slower than all users on destination bus,
6044 move top user; otherwise move all users slower than the top one */
6045 if (!dst_bus->u.cbus.slow_user ||
6046 !bus_user_is_slower(dst_bus->u.cbus.slow_user, top_user)) {
6047 cbus_move_enabled_user(top_user, dst_bus, src_bus);
6049 list_for_each_safe(pos, n, &src_bus->shared_bus_list) {
6050 c = list_entry(pos, struct clk, u.shared_bus_user.node);
6051 if (c->u.shared_bus_user.enabled &&
6052 c->u.shared_bus_user.client &&
6053 bus_user_is_slower(c, top_user))
6054 cbus_move_enabled_user(c, dst_bus, src_bus);
6058 /* Update destination bus 1st (move clients), then source */
6059 tegra_clk_shared_bus_update(dst_bus);
6060 tegra_clk_shared_bus_update(src_bus);
6065 static struct clk_ops tegra_clk_cbus_ops = {
6066 .init = tegra21_clk_cbus_init,
6067 .enable = tegra21_clk_cbus_enable,
6068 .set_rate = tegra21_clk_cbus_set_rate,
6069 .round_rate = tegra21_clk_cbus_round_rate,
6070 .round_rate_updown = tegra21_clk_cbus_round_updown,
6071 .shared_bus_update = tegra21_clk_cbus_update,
6074 /* shared bus ops */
6076 * Some clocks may have multiple downstream users that need to request a
6077 * higher clock rate. Shared bus clocks provide a unique shared_bus_user
6078 * clock to each user. The frequency of the bus is set to the highest
6079 * enabled shared_bus_user clock, with a minimum value set by the
6082 * Optionally shared bus may support users migration. Since shared bus and
6083 * its * children (users) have reversed rate relations: user rates determine
6084 * bus rate, * switching user from one parent/bus to another may change rates
6085 * of both parents. Therefore we need a cross-bus lock on top of individual
6086 * user and bus locks. For now, limit bus switch support to cbus only if
6087 * CONFIG_TEGRA_MIGRATE_CBUS_USERS is set.
6090 static unsigned long tegra21_clk_shared_bus_update(struct clk *bus,
6091 struct clk **bus_top, struct clk **bus_slow, unsigned long *rate_cap)
6094 struct clk *slow = NULL;
6095 struct clk *top = NULL;
6097 unsigned long override_rate = 0;
6098 unsigned long top_rate = 0;
6099 unsigned long rate = bus->min_rate;
6100 unsigned long bw = 0;
6101 unsigned long iso_bw = 0;
6102 unsigned long ceiling = bus->max_rate;
6103 unsigned long ceiling_but_iso = bus->max_rate;
6104 u32 usage_flags = 0;
6105 bool rate_set = false;
6107 struct clk *crit_cap = NULL;
6108 struct clk *crit_cap_but_iso = NULL;
6109 struct clk *crit_floor = NULL;
6110 struct clk *override_clk = NULL;
6112 list_for_each_entry(c, &bus->shared_bus_list,
6113 u.shared_bus_user.node) {
6114 bool cap_user = (c->u.shared_bus_user.mode == SHARED_CEILING) ||
6115 (c->u.shared_bus_user.mode == SHARED_CEILING_BUT_ISO);
6117 * Ignore requests from disabled floor and bw users, and from
6118 * auto-users riding the bus. Always honor ceiling users, even
6119 * if they are disabled - we do not want to keep enabled parent
6120 * bus just because ceiling is set.
6122 if (c->u.shared_bus_user.enabled || cap_user) {
6123 unsigned long request_rate = c->u.shared_bus_user.rate;
6124 usage_flags |= c->u.shared_bus_user.usage_flag;
6126 if (!(c->flags & BUS_RATE_LIMIT))
6129 switch (c->u.shared_bus_user.mode) {
6131 iso_bw += request_rate;
6132 if (iso_bw > bus->max_rate)
6133 iso_bw = bus->max_rate;
6137 if (bw > bus->max_rate)
6140 case SHARED_CEILING_BUT_ISO:
6141 if (ceiling_but_iso > request_rate) {
6142 ceiling_but_iso = request_rate;
6143 crit_cap_but_iso = c;
6146 case SHARED_CEILING:
6147 if (ceiling > request_rate) {
6148 ceiling = request_rate;
6152 case SHARED_OVERRIDE:
6153 if (override_rate == 0) {
6154 override_rate = request_rate;
6162 if (rate <= request_rate) {
6163 if (!(c->flags & BUS_RATE_LIMIT) ||
6164 (rate < request_rate))
6166 rate = request_rate;
6168 if (c->u.shared_bus_user.client
6170 if (top_rate < request_rate) {
6171 top_rate = request_rate;
6173 } else if ((top_rate == request_rate) &&
6174 bus_user_is_slower(c, top)) {
6179 if (c->u.shared_bus_user.client &&
6180 (!slow || bus_user_is_slower(c, slow)))
6185 if (bus->flags & PERIPH_EMC_ENB) {
6186 unsigned long iso_bw_min;
6187 bw = tegra_emc_apply_efficiency(
6188 bw, iso_bw, bus->max_rate, usage_flags, &iso_bw_min);
6189 if (bus->ops && bus->ops->round_rate)
6190 iso_bw_min = bus->ops->round_rate(bus, iso_bw_min);
6191 ceiling_but_iso = max(ceiling_but_iso, iso_bw_min);
6198 rate = override_rate ? : rate;
6200 if (ceiling > ceiling_but_iso) {
6201 ceiling = ceiling_but_iso;
6202 crit_cap = crit_cap_but_iso;
6205 if (override_rate) {
6206 ceiling = bus->max_rate;
6208 crit_floor = override_clk;
6210 bus->override_rate = override_rate;
6212 if (bus->stats.histogram) {
6213 struct bus_stats *stats = bus->stats.histogram;
6219 stats->new_cap_idx = !crit_cap ? stats->users_num :
6220 crit_cap->u.shared_bus_user.stats_idx;
6221 stats->new_floor_idx = !crit_floor ? stats->users_num :
6222 crit_floor->u.shared_bus_user.stats_idx;
6225 if (bus_top && bus_slow && rate_cap) {
6226 /* If dynamic bus dvfs table, let the caller to complete
6227 rounding and aggregation */
6230 *rate_cap = ceiling;
6233 * If satic bus dvfs table, complete rounding and aggregation.
6234 * In case when no user requested bus rate, and bus retention
6235 * is enabled, don't scale down - keep current rate.
6237 if (!rate_set && (bus->shared_bus_flags & SHARED_BUS_RETENTION))
6238 rate = clk_get_rate_locked(bus);
6240 rate = tegra21_clk_cap_shared_bus(bus, rate, ceiling);
6246 static unsigned long tegra21_clk_cap_shared_bus(struct clk *bus,
6247 unsigned long rate, unsigned long ceiling)
6250 struct bus_stats *stats = bus->stats.histogram;
6252 if (bus->ops && bus->ops->round_rate_updown)
6253 ceiling = bus->ops->round_rate_updown(bus, ceiling, false);
6255 capped = rate > ceiling;
6259 tegra_shared_bus_stats_update(stats,
6260 stats->new_cap_idx, stats->new_rate_idx);
6263 if (bus->ops && bus->ops->round_rate)
6264 rate = bus->ops->round_rate(bus, rate);
6266 if (!capped && stats) {
6267 tegra_shared_bus_stats_update(stats,
6268 stats->new_floor_idx, stats->new_rate_idx);
6274 static int tegra_clk_shared_bus_migrate_users(struct clk *user)
6276 if (detach_shared_bus)
6279 /* Only cbus migration is supported */
6280 if (user->flags & PERIPH_ON_CBUS)
6281 return tegra21_clk_cbus_migrate_users(user);
6285 static void tegra_clk_shared_bus_user_init(struct clk *c)
6287 c->max_rate = c->parent->max_rate;
6288 c->u.shared_bus_user.rate = c->parent->max_rate;
6292 if ((c->u.shared_bus_user.mode == SHARED_CEILING) ||
6293 (c->u.shared_bus_user.mode == SHARED_CEILING_BUT_ISO)) {
6298 if (c->parent->stats.histogram) {
6299 int i = c->parent->stats.histogram->users_num++;
6300 c->u.shared_bus_user.stats_idx = i;
6301 if (i < STATS_USERS_LIST_SIZE)
6302 c->parent->stats.histogram->users_list[i] = c;
6305 if (c->u.shared_bus_user.client_id) {
6306 c->u.shared_bus_user.client =
6307 tegra_get_clock_by_name(c->u.shared_bus_user.client_id);
6308 if (!c->u.shared_bus_user.client) {
6309 pr_err("%s: could not find clk %s\n", __func__,
6310 c->u.shared_bus_user.client_id);
6313 c->u.shared_bus_user.client->flags |=
6314 c->parent->flags & PERIPH_ON_CBUS;
6315 c->flags |= c->parent->flags & PERIPH_ON_CBUS;
6320 list_add_tail(&c->u.shared_bus_user.node,
6321 &c->parent->shared_bus_list);
6324 static int tegra_clk_shared_bus_user_set_parent(struct clk *c, struct clk *p)
6327 const struct clk_mux_sel *sel;
6329 if (detach_shared_bus)
6335 if (!(c->inputs && c->cross_clk_mutex && clk_cansleep(c)))
6338 for (sel = c->inputs; sel->input != NULL; sel++) {
6339 if (sel->input == p)
6346 tegra_clk_prepare_enable(p);
6348 list_move_tail(&c->u.shared_bus_user.node, &p->shared_bus_list);
6349 ret = tegra_clk_shared_bus_update(p);
6351 list_move_tail(&c->u.shared_bus_user.node,
6352 &c->parent->shared_bus_list);
6353 tegra_clk_shared_bus_update(c->parent);
6354 tegra_clk_disable_unprepare(p);
6358 tegra_clk_shared_bus_update(c->parent);
6361 tegra_clk_disable_unprepare(c->parent);
6368 static int tegra_clk_shared_bus_user_set_rate(struct clk *c, unsigned long rate)
6371 unsigned long flags;
6373 clk_lock_save(c->parent, &flags);
6374 c->u.shared_bus_user.rate = rate;
6375 ret = tegra_clk_shared_bus_update_locked(c->parent);
6376 clk_unlock_restore(c->parent, &flags);
6378 if (!ret && c->cross_clk_mutex && clk_cansleep(c))
6379 tegra_clk_shared_bus_migrate_users(c);
6384 static long tegra_clk_shared_bus_user_round_rate(
6385 struct clk *c, unsigned long rate)
6388 * Defer rounding requests until aggregated. BW users must not be
6389 * rounded at all, others just clipped to bus range (some clients
6390 * may use round api to find limits).
6393 if ((c->u.shared_bus_user.mode != SHARED_BW) &&
6394 (c->u.shared_bus_user.mode != SHARED_ISO_BW)) {
6395 if (rate > c->parent->max_rate) {
6396 rate = c->parent->max_rate;
6398 /* Skippers allow to run below bus minimum */
6399 bool use_skip = c->parent->shared_bus_flags &
6400 SHARED_BUS_USE_SKIPPERS;
6401 struct clk *client = c->u.shared_bus_user.client;
6402 int skip = (use_skip && client && client->skipper) ?
6403 SUPER_SKIPPER_TERM_SIZE : 0;
6404 unsigned long min_rate = c->parent->min_rate >> skip;
6406 if (rate < min_rate)
6413 static int tegra_clk_shared_bus_user_enable(struct clk *c)
6416 unsigned long flags;
6418 clk_lock_save(c->parent, &flags);
6419 c->u.shared_bus_user.enabled = true;
6420 ret = tegra_clk_shared_bus_update_locked(c->parent);
6421 if (!ret && c->u.shared_bus_user.client)
6422 ret = tegra_clk_prepare_enable(c->u.shared_bus_user.client);
6423 clk_unlock_restore(c->parent, &flags);
6425 if (!ret && c->cross_clk_mutex && clk_cansleep(c))
6426 tegra_clk_shared_bus_migrate_users(c);
6431 static void tegra_clk_shared_bus_user_disable(struct clk *c)
6433 unsigned long flags;
6435 clk_lock_save(c->parent, &flags);
6436 if (c->u.shared_bus_user.client)
6437 tegra_clk_disable_unprepare(c->u.shared_bus_user.client);
6438 c->u.shared_bus_user.enabled = false;
6439 tegra_clk_shared_bus_update_locked(c->parent);
6440 clk_unlock_restore(c->parent, &flags);
6442 if (c->cross_clk_mutex && clk_cansleep(c))
6443 tegra_clk_shared_bus_migrate_users(c);
6446 static void tegra_clk_shared_bus_user_reset(struct clk *c, bool assert)
6448 if (c->u.shared_bus_user.client) {
6449 if (c->u.shared_bus_user.client->ops &&
6450 c->u.shared_bus_user.client->ops->reset)
6451 c->u.shared_bus_user.client->ops->reset(
6452 c->u.shared_bus_user.client, assert);
6456 static struct clk_ops tegra_clk_shared_bus_user_ops = {
6457 .init = tegra_clk_shared_bus_user_init,
6458 .enable = tegra_clk_shared_bus_user_enable,
6459 .disable = tegra_clk_shared_bus_user_disable,
6460 .set_parent = tegra_clk_shared_bus_user_set_parent,
6461 .set_rate = tegra_clk_shared_bus_user_set_rate,
6462 .round_rate = tegra_clk_shared_bus_user_round_rate,
6463 .reset = tegra_clk_shared_bus_user_reset,
6466 /* shared bus connector ops (user/bus connector to cascade shared buses) */
6467 static int tegra21_clk_shared_connector_update(struct clk *bus)
6469 unsigned long rate, old_rate;
6471 if (detach_shared_bus)
6474 rate = tegra21_clk_shared_bus_update(bus, NULL, NULL, NULL);
6476 old_rate = clk_get_rate_locked(bus);
6477 if (rate == old_rate)
6480 return clk_set_rate_locked(bus, rate);
6483 static struct clk_ops tegra_clk_shared_connector_ops = {
6484 .init = tegra_clk_shared_bus_user_init,
6485 .enable = tegra_clk_shared_bus_user_enable,
6486 .disable = tegra_clk_shared_bus_user_disable,
6487 .set_parent = tegra_clk_shared_bus_user_set_parent,
6488 .set_rate = tegra_clk_shared_bus_user_set_rate,
6489 .round_rate = tegra_clk_shared_bus_user_round_rate,
6490 .reset = tegra_clk_shared_bus_user_reset,
6491 .shared_bus_update = tegra21_clk_shared_connector_update,
6494 /* coupled gate ops */
6496 * Some clocks may have common enable/disable control, but run at different
6497 * rates, and have different dvfs tables. Coupled gate clock synchronize
6498 * enable/disable operations for such clocks.
6501 static int tegra21_clk_coupled_gate_enable(struct clk *c)
6504 const struct clk_mux_sel *sel;
6507 pr_debug("%s on clock %s\n", __func__, c->name);
6509 for (sel = c->inputs; sel->input != NULL; sel++) {
6510 if (sel->input == c->parent)
6513 ret = tegra_clk_prepare_enable(sel->input);
6515 while (sel != c->inputs) {
6517 if (sel->input == c->parent)
6519 tegra_clk_disable_unprepare(sel->input);
6525 return tegra21_periph_clk_enable(c);
6528 static void tegra21_clk_coupled_gate_disable(struct clk *c)
6530 const struct clk_mux_sel *sel;
6533 pr_debug("%s on clock %s\n", __func__, c->name);
6535 tegra21_periph_clk_disable(c);
6537 if (!c->refcnt) /* happens only on boot clean-up: don't propagate */
6540 for (sel = c->inputs; sel->input != NULL; sel++) {
6541 if (sel->input == c->parent)
6544 if (sel->input->set) /* enforce coupling after boot only */
6545 tegra_clk_disable_unprepare(sel->input);
6550 * AHB and APB shared bus operations
6551 * APB shared bus is a user of AHB shared bus
6552 * AHB shared bus is a user of SCLK complex shared bus
6553 * SCLK/AHB and AHB/APB dividers can be dynamically changed. When AHB and APB
6554 * users requests are propagated to SBUS target rate, current values of the
6555 * dividers are ignored, and flat maximum request is selected as SCLK bus final
6556 * target. Then the dividers will be re-evaluated, based on AHB and APB targets.
6557 * Both AHB and APB buses are always enabled.
6559 static void tegra21_clk_ahb_apb_init(struct clk *c, struct clk *bus_clk)
6561 tegra_clk_shared_bus_user_init(c);
6562 c->max_rate = bus_clk->max_rate;
6563 c->min_rate = bus_clk->min_rate;
6564 c->mul = bus_clk->mul;
6565 c->div = bus_clk->div;
6567 c->u.shared_bus_user.rate = clk_get_rate(bus_clk);
6568 c->u.shared_bus_user.enabled = true;
6569 c->parent->child_bus = c;
6572 static void tegra21_clk_ahb_init(struct clk *c)
6574 struct clk *bus_clk = c->parent->u.system.hclk;
6575 tegra21_clk_ahb_apb_init(c, bus_clk);
6578 static void tegra21_clk_apb_init(struct clk *c)
6580 struct clk *bus_clk = c->parent->parent->u.system.pclk;
6581 tegra21_clk_ahb_apb_init(c, bus_clk);
6584 static int tegra21_clk_ahb_apb_update(struct clk *bus)
6588 if (detach_shared_bus)
6591 rate = tegra21_clk_shared_bus_update(bus, NULL, NULL, NULL);
6592 return clk_set_rate_locked(bus, rate);
6595 static struct clk_ops tegra_clk_ahb_ops = {
6596 .init = tegra21_clk_ahb_init,
6597 .set_rate = tegra_clk_shared_bus_user_set_rate,
6598 .round_rate = tegra_clk_shared_bus_user_round_rate,
6599 .shared_bus_update = tegra21_clk_ahb_apb_update,
6602 static struct clk_ops tegra_clk_apb_ops = {
6603 .init = tegra21_clk_apb_init,
6604 .set_rate = tegra_clk_shared_bus_user_set_rate,
6605 .round_rate = tegra_clk_shared_bus_user_round_rate,
6606 .shared_bus_update = tegra21_clk_ahb_apb_update,
6609 static struct clk_ops tegra_clk_coupled_gate_ops = {
6610 .init = tegra21_periph_clk_init,
6611 .enable = tegra21_clk_coupled_gate_enable,
6612 .disable = tegra21_clk_coupled_gate_disable,
6613 .reset = &tegra21_periph_clk_reset,
6617 /* Clock definitions */
6618 static struct clk tegra_clk_32k = {
6620 .clk_id = TEGRA210_CLK_ID_CLK_32K,
6626 static struct clk tegra_clk_osc = {
6628 .clk_id = TEGRA210_CLK_ID_CLK_OSC,
6629 .flags = ENABLE_ON_INIT,
6630 .ops = &tegra_osc_ops,
6631 .max_rate = 48000000,
6634 static struct clk tegra_clk_m = {
6636 .clk_id = TEGRA210_CLK_ID_CLK_M,
6637 .flags = ENABLE_ON_INIT,
6638 .parent = &tegra_clk_osc,
6639 .ops = &tegra_clk_m_ops,
6640 .max_rate = 48000000,
6643 static struct clk tegra_clk_m_div2 = {
6644 .name = "clk_m_div2",
6645 .clk_id = TEGRA210_CLK_ID_CLK_M_DIV2,
6646 .ops = &tegra_clk_m_div_ops,
6647 .parent = &tegra_clk_m,
6651 .max_rate = 24000000,
6654 static struct clk tegra_clk_m_div4 = {
6655 .name = "clk_m_div4",
6656 .clk_id = TEGRA210_CLK_ID_CLK_M_DIV4,
6657 .ops = &tegra_clk_m_div_ops,
6658 .parent = &tegra_clk_m,
6662 .max_rate = 12000000,
6665 static struct clk tegra_pll_ref = {
6667 .clk_id = TEGRA210_CLK_ID_PLL_REF,
6668 .flags = ENABLE_ON_INIT,
6669 .ops = &tegra_pll_ref_ops,
6670 .parent = &tegra_clk_osc,
6671 .max_rate = 38400000,
6674 static struct clk_pll_freq_table tegra_pll_cx_freq_table[] = {
6675 { 12000000, 510000000, 85, 1, 2},
6676 { 13000000, 510000000, 78, 1, 2}, /* actual: 507.0 MHz */
6677 { 38400000, 510000000, 79, 3, 2}, /* actual: 505.6 MHz */
6678 { 0, 0, 0, 0, 0, 0 },
6681 static struct clk_pll_controls pllcx_controls = {
6682 .enable_mask = PLL_BASE_ENABLE,
6683 .bypass_mask = PLL_BASE_BYPASS,
6684 .reset_mask = PLLCX_MISC0_RESET,
6685 .reset_reg_idx = PLL_MISC0_IDX,
6686 .iddq_mask = PLLCX_MISC1_IDDQ,
6687 .iddq_reg_idx = PLL_MISC1_IDX,
6688 .lock_mask = PLLCX_BASE_LOCK,
6689 .lock_reg_idx = PLL_BASE_IDX,
6692 static struct clk_pll_div_layout pllcx_div_layout = {
6696 .ndiv_mask = 0xff << 10,
6698 .pdiv_mask = 0x1f << 20,
6699 .pdiv_to_p = pll_qlin_pdiv_to_p,
6700 .pdiv_max = PLL_QLIN_PDIV_MAX,
6703 static struct clk tegra_pll_c = {
6705 .clk_id = TEGRA210_CLK_ID_PLL_C,
6706 .ops = &tegra_pllcx_ops,
6708 .parent = &tegra_pll_ref,
6709 .max_rate = 1200000000,
6711 .input_min = 12000000,
6712 .input_max = 700000000,
6715 .vco_min = 600000000,
6716 .vco_max = 1200000000,
6717 .freq_table = tegra_pll_cx_freq_table,
6719 .misc0 = 0x88 - 0x80,
6720 .misc1 = 0x8c - 0x80,
6721 .misc2 = 0x5d0 - 0x80,
6722 .misc3 = 0x5d4 - 0x80,
6723 .controls = &pllcx_controls,
6724 .div_layout = &pllcx_div_layout,
6725 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
6726 .dyn_ramp = pllcx_dyn_ramp,
6727 .set_defaults = pllcx_set_defaults,
6731 static struct clk tegra_pll_c_out1 = {
6732 .name = "pll_c_out1",
6733 .clk_id = TEGRA210_CLK_ID_PLL_C_OUT1,
6734 .ops = &tegra_pll_div_ops,
6735 .flags = DIV_U71 | PERIPH_ON_CBUS,
6736 .parent = &tegra_pll_c,
6739 .max_rate = 700000000,
6742 static struct clk tegra_pll_c2 = {
6744 .clk_id = TEGRA210_CLK_ID_PLL_C2,
6745 .ops = &tegra_pllcx_ops,
6747 .parent = &tegra_pll_ref,
6748 .max_rate = 1200000000,
6750 .input_min = 12000000,
6751 .input_max = 700000000,
6754 .vco_min = 600000000,
6755 .vco_max = 1200000000,
6756 .freq_table = tegra_pll_cx_freq_table,
6758 .misc0 = 0x4ec - 0x4e8,
6759 .misc1 = 0x4f0 - 0x4e8,
6760 .misc2 = 0x4f4 - 0x4e8,
6761 .misc3 = 0x4f8 - 0x4e8,
6762 .controls = &pllcx_controls,
6763 .div_layout = &pllcx_div_layout,
6764 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
6765 .dyn_ramp = pllcx_dyn_ramp,
6766 .set_defaults = pllcx_set_defaults,
6770 static struct clk tegra_pll_c3 = {
6772 .clk_id = TEGRA210_CLK_ID_PLL_C3,
6773 .ops = &tegra_pllcx_ops,
6775 .parent = &tegra_pll_ref,
6776 .max_rate = 1200000000,
6778 .input_min = 12000000,
6779 .input_max = 700000000,
6782 .vco_min = 600000000,
6783 .vco_max = 1200000000,
6784 .freq_table = tegra_pll_cx_freq_table,
6786 .misc0 = 0x500 - 0x4fc,
6787 .misc1 = 0x504 - 0x4fc,
6788 .misc2 = 0x508 - 0x4fc,
6789 .misc3 = 0x50c - 0x4fc,
6790 .controls = &pllcx_controls,
6791 .div_layout = &pllcx_div_layout,
6792 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
6793 .dyn_ramp = pllcx_dyn_ramp,
6794 .set_defaults = pllcx_set_defaults,
6798 static struct clk tegra_pll_a1 = {
6800 .clk_id = TEGRA210_CLK_ID_PLL_A1,
6801 .ops = &tegra_pllcx_ops,
6803 .parent = &tegra_pll_ref,
6804 .max_rate = 1200000000,
6806 .input_min = 12000000,
6807 .input_max = 700000000,
6810 .vco_min = 600000000,
6811 .vco_max = 1200000000,
6812 .freq_table = tegra_pll_cx_freq_table,
6814 .misc0 = 0x6a8 - 0x6a4,
6815 .misc1 = 0x6ac - 0x6a4,
6816 .misc2 = 0x6b0 - 0x6a4,
6817 .misc3 = 0x6b4 - 0x6a4,
6818 .controls = &pllcx_controls,
6819 .div_layout = &pllcx_div_layout,
6820 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
6821 .dyn_ramp = pllcx_dyn_ramp,
6822 .set_defaults = pllcx_set_defaults,
6826 static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
6827 { 12000000, 282240000, 47, 1, 2, 1, 0xf148}, /* actual: 282240234 */
6828 { 12000000, 368640000, 61, 1, 2, 1, 0xfe15}, /* actual: 368640381 */
6829 { 12000000, 240000000, 60, 1, 3, 1, },
6831 { 13000000, 282240000, 43, 1, 2, 1, 0xfd7d}, /* actual: 282239807 */
6832 { 13000000, 368640000, 56, 1, 2, 1, 0x06d8}, /* actual: 368640137 */
6833 { 13000000, 240000000, 55, 1, 3, 1, }, /* actual: 238.3 MHz */
6835 { 38400000, 282240000, 44, 3, 2, 1, 0xf333}, /* actual: 282239844 */
6836 { 38400000, 368640000, 57, 3, 2, 1, 0x0333}, /* actual: 368639844 */
6837 { 38400000, 240000000, 75, 3, 4, 1,},
6838 { 0, 0, 0, 0, 0, 0 },
6841 static struct clk_pll_controls plla_controls = {
6842 .enable_mask = PLL_BASE_ENABLE,
6843 .bypass_mask = PLL_BASE_BYPASS,
6844 .iddq_mask = PLLA_BASE_IDDQ,
6845 .iddq_reg_idx = PLL_BASE_IDX,
6846 .lock_mask = PLLA_BASE_LOCK,
6847 .lock_reg_idx = PLL_BASE_IDX,
6849 .sdm_en_mask = PLLA_MISC2_EN_SDM,
6850 .sdm_ctrl_reg_idx = PLL_MISC2_IDX,
6853 static struct clk_pll_div_layout plla_div_layout = {
6857 .ndiv_mask = 0xff << 8,
6859 .pdiv_mask = 0x1f << 20,
6860 .pdiv_to_p = pll_qlin_pdiv_to_p,
6861 .pdiv_max = PLL_QLIN_PDIV_MAX,
6864 .sdm_din_mask = 0xffff,
6865 .sdm_din_reg_idx = PLL_MISC1_IDX,
6868 static struct clk tegra_pll_a = {
6870 .clk_id = TEGRA210_CLK_ID_PLL_A,
6871 .ops = &tegra_plla_ops,
6873 .parent = &tegra_pll_ref,
6874 .max_rate = 1000000000,
6876 .input_min = 12000000,
6877 .input_max = 800000000,
6880 .vco_min = 500000000,
6881 .vco_max = 1000000000,
6882 .freq_table = tegra_pll_a_freq_table,
6884 .misc0 = 0xbc - 0xb0,
6885 .misc1 = 0xb8 - 0xb0,
6886 .misc2 = 0x5d8 - 0xb0,
6887 .controls = &plla_controls,
6888 .div_layout = &plla_div_layout,
6889 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
6890 .set_defaults = plla_set_defaults,
6894 static struct clk tegra_pll_a_out0 = {
6895 .name = "pll_a_out0",
6896 .clk_id = TEGRA210_CLK_ID_PLL_A_OUT0,
6897 .ops = &tegra_pll_div_ops,
6899 .parent = &tegra_pll_a,
6902 .max_rate = 600000000,
6905 static struct clk_mux_sel mux_plla[] = {
6906 { .input = &tegra_pll_a, .value = 0},
6910 static struct clk tegra_pll_a_out_adsp = {
6911 .name = "pll_a_out_adsp",
6912 .clk_id = TEGRA210_CLK_ID_PLL_A_OUT_ADSP,
6913 .ops = &tegra_periph_clk_ops,
6915 .flags = PERIPH_NO_RESET,
6916 .max_rate = 1000000000,
6922 static struct clk_mux_sel mux_plla_out0[] = {
6923 { .input = &tegra_pll_a_out0, .value = 0},
6927 static struct clk tegra_pll_a_out0_out_adsp = {
6928 .name = "pll_a_out0_out_adsp",
6929 .clk_id = TEGRA210_CLK_ID_PLL_A_OUT0_OUT_ADSP,
6930 .ops = &tegra_periph_clk_ops,
6931 .inputs = mux_plla_out0,
6932 .flags = PERIPH_NO_RESET,
6933 .max_rate = 600000000,
6939 static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
6940 { 12000000, 594000000, 99, 1, 2},
6941 { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f}, /* actual: 594000183 */
6942 { 38400000, 594000000, 30, 1, 2, 0, 0x0e00},
6943 { 0, 0, 0, 0, 0, 0 },
6946 static struct clk_pll_controls plld_controls = {
6947 .enable_mask = PLL_BASE_ENABLE,
6948 .bypass_mask = PLL_BASE_BYPASS,
6949 .iddq_mask = PLLD_MISC0_IDDQ,
6950 .iddq_reg_idx = PLL_MISC0_IDX,
6951 .lock_mask = PLLD_BASE_LOCK,
6952 .lock_reg_idx = PLL_BASE_IDX,
6954 .sdm_en_mask = PLLD_MISC0_EN_SDM,
6955 .sdm_ctrl_reg_idx = PLL_MISC0_IDX,
6958 static struct clk_pll_div_layout plld_div_layout = {
6962 .ndiv_mask = 0xff << 11,
6964 .pdiv_mask = 0x7 << 20,
6965 .pdiv_to_p = pll_expo_pdiv_to_p,
6966 .pdiv_max = PLL_EXPO_PDIV_MAX,
6969 .sdm_din_mask = 0xffff,
6970 .sdm_din_reg_idx = PLL_MISC0_IDX,
6973 static struct clk tegra_pll_d = {
6975 .clk_id = TEGRA210_CLK_ID_PLL_D,
6977 .ops = &tegra_plld_ops,
6979 .parent = &tegra_pll_ref,
6980 .max_rate = 1500000000,
6982 .input_min = 12000000,
6983 .input_max = 800000000,
6986 .vco_min = 750000000,
6987 .vco_max = 1500000000,
6989 .freq_table = tegra_pll_d_freq_table,
6991 .misc0 = 0xdc - 0xd0,
6992 .misc1 = 0xd8 - 0xd0,
6993 .controls = &plld_controls,
6994 .div_layout = &plld_div_layout,
6995 .round_p_to_pdiv = pll_expo_p_to_pdiv,
6996 .set_defaults = plld_set_defaults,
7000 static struct clk tegra_pll_d_out0 = {
7001 .name = "pll_d_out0",
7002 .clk_id = TEGRA210_CLK_ID_PLL_D_OUT0,
7003 .ops = &tegra_pll_div_ops,
7004 .flags = DIV_2 | PLLD,
7005 .parent = &tegra_pll_d,
7006 .max_rate = 750000000,
7009 static struct clk_pll_freq_table tegra_pll_d2_freq_table[] = {
7010 { 12000000, 594000000, 99, 1, 2, 0, 0xf000},
7011 { 13000000, 594000000, 91, 1, 2, 0, 0xfc4f}, /* actual: 594000183 */
7012 { 38400000, 594000000, 30, 1, 2, 0, 0x0e00},
7013 { 0, 0, 0, 0, 0, 0 },
7016 static struct clk_pll_controls plld2_controls = {
7017 .enable_mask = PLL_BASE_ENABLE,
7018 .bypass_mask = PLL_BASE_BYPASS,
7019 .iddq_mask = PLLDSS_BASE_IDDQ,
7020 .iddq_reg_idx = PLL_BASE_IDX,
7021 .lock_mask = PLLDSS_BASE_LOCK,
7022 .lock_reg_idx = PLL_BASE_IDX,
7024 .sdm_en_mask = PLLDSS_MISC1_CFG_EN_SDM,
7025 .ssc_en_mask = PLLDSS_MISC1_CFG_EN_SSC,
7026 .sdm_ctrl_reg_idx = PLL_MISC1_IDX,
7029 static struct clk_pll_div_layout plldss_div_layout = {
7033 .ndiv_mask = 0xff << 8,
7035 .pdiv_mask = 0x1f << 19,
7036 .pdiv_to_p = pll_qlin_pdiv_to_p,
7037 .pdiv_max = PLL_QLIN_PDIV_MAX,
7040 .sdm_din_mask = 0xffff,
7041 .sdm_din_reg_idx = PLL_MISC3_IDX,
7044 static struct clk tegra_pll_d2 = {
7046 .clk_id = TEGRA210_CLK_ID_PLL_D2,
7047 .ops = &tegra_plld2_ops,
7049 .parent = &tegra_pll_ref, /* s/w policy, always tegra_pll_ref */
7050 .max_rate = 1500000000,
7052 .input_min = 12000000,
7053 .input_max = 800000000,
7056 .vco_min = 750000000,
7057 .vco_max = 1500000000,
7059 .freq_table = tegra_pll_d2_freq_table,
7061 .misc0 = 0x4bc - 0x4b8,
7062 .misc1 = 0x570 - 0x4b8,
7063 .misc2 = 0x574 - 0x4b8,
7064 .misc3 = 0x578 - 0x4b8,
7065 .controls = &plld2_controls,
7066 .div_layout = &plldss_div_layout,
7067 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7068 .set_defaults = plld2_set_defaults,
7072 static struct clk_pll_freq_table tegra_pll_dp_freq_table[] = {
7073 { 12000000, 270000000, 90, 1, 4, 0, 0xf000},
7074 { 13000000, 270000000, 83, 1, 4, 0, 0xf000}, /* actual: 269.8 MHz */
7075 { 38400000, 270000000, 28, 1, 4, 0, 0xf400},
7076 { 0, 0, 0, 0, 0, 0 },
7079 static struct clk_pll_controls plldp_controls = {
7080 .enable_mask = PLL_BASE_ENABLE,
7081 .bypass_mask = PLL_BASE_BYPASS,
7082 .iddq_mask = PLLDSS_BASE_IDDQ,
7083 .iddq_reg_idx = PLL_BASE_IDX,
7084 .lock_mask = PLLDSS_BASE_LOCK,
7085 .lock_reg_idx = PLL_BASE_IDX,
7087 .sdm_en_mask = PLLDSS_MISC1_CFG_EN_SDM,
7088 .ssc_en_mask = PLLDSS_MISC1_CFG_EN_SSC,
7089 .sdm_ctrl_reg_idx = PLL_MISC1_IDX,
7092 static struct clk tegra_pll_dp = {
7094 .clk_id = TEGRA210_CLK_ID_PLL_DP,
7096 .ops = &tegra_plldp_ops,
7098 .parent = &tegra_pll_ref, /* s/w policy, always tegra_pll_ref */
7099 .max_rate = 1500000000,
7101 .input_min = 12000000,
7102 .input_max = 800000000,
7105 .vco_min = 750000000,
7106 .vco_max = 1500000000,
7108 .freq_table = tegra_pll_dp_freq_table,
7110 .misc0 = 0x594 - 0x590,
7111 .misc1 = 0x598 - 0x590,
7112 .misc2 = 0x59c - 0x590,
7113 .misc3 = 0x5a0 - 0x590,
7114 .controls = &plldp_controls,
7115 .div_layout = &plldss_div_layout,
7116 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7117 .set_defaults = plldp_set_defaults,
7118 .fixed_rate = 270000000,
7122 static struct clk_pll_freq_table tegra_pllc4_vco_freq_table[] = {
7123 { 12000000, 600000000, 50, 1, 1},
7124 { 13000000, 600000000, 46, 1, 1}, /* actual: 598.0 MHz */
7125 { 38400000, 600000000, 62, 4, 1}, /* actual: 595.2 MHz */
7126 { 0, 0, 0, 0, 0, 0 },
7129 static struct clk_pll_controls pllc4_controls = {
7130 .enable_mask = PLL_BASE_ENABLE,
7131 .bypass_mask = PLL_BASE_BYPASS,
7132 .iddq_mask = PLLDSS_BASE_IDDQ,
7133 .iddq_reg_idx = PLL_BASE_IDX,
7134 .lock_mask = PLLDSS_BASE_LOCK,
7135 .lock_reg_idx = PLL_BASE_IDX,
7138 static struct clk_pll_div_layout pllc4_div_layout = {
7142 .ndiv_mask = 0xff << 8,
7144 .pdiv_mask = 0x1f << 19,
7145 .pdiv_to_p = pll_qlin_pdiv_to_p,
7146 .pdiv_max = PLL_QLIN_PDIV_MAX,
7149 static struct clk tegra_pll_c4_vco = {
7151 .clk_id = TEGRA210_CLK_ID_PLL_C4,
7152 .ops = &tegra_pllc4_vco_ops,
7154 .parent = &tegra_pll_ref, /* s/w policy, always tegra_pll_ref */
7155 .max_rate = 1080000000,
7157 .input_min = 9600000,
7158 .input_max = 800000000,
7161 .vco_min = 500000000,
7162 .vco_max = 1080000000,
7163 .freq_table = tegra_pllc4_vco_freq_table,
7165 .misc0 = 0x5a8 - 0x5a4,
7166 .controls = &pllc4_controls,
7167 .div_layout = &pllc4_div_layout,
7168 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7169 .set_defaults = pllc4_set_defaults,
7174 static struct clk tegra_pll_c4_out0 = {
7175 .name = "pll_c4_out0",
7176 .clk_id = TEGRA210_CLK_ID_PLL_C4_OUT0,
7177 .ops = &tegra_pll_out_ops,
7178 .parent = &tegra_pll_c4_vco,
7181 static struct clk tegra_pll_c4_out1 = {
7182 .name = "pll_c4_out1",
7183 .clk_id = TEGRA210_CLK_ID_PLL_C4_OUT1,
7184 .ops = &tegra_pll_out_fixed_ops,
7185 .parent = &tegra_pll_c4_vco,
7190 static struct clk tegra_pll_c4_out2 = {
7191 .name = "pll_c4_out2",
7192 .clk_id = TEGRA210_CLK_ID_PLL_C4_OUT2,
7193 .ops = &tegra_pll_out_fixed_ops,
7194 .parent = &tegra_pll_c4_vco,
7199 static struct clk tegra_pll_c4_out3 = {
7200 .name = "pll_c4_out3",
7201 .clk_id = TEGRA210_CLK_ID_PLL_C4_OUT3,
7202 .ops = &tegra_pll_div_ops,
7204 .parent = &tegra_pll_c4_out0,
7207 .max_rate = 1080000000,
7210 static struct clk_pll_freq_table tegra_pllre_vco_freq_table[] = {
7211 { 12000000, 672000000, 56, 1, 1},
7212 { 13000000, 672000000, 51, 1, 1}, /* actual: 663.0 MHz */
7213 { 38400000, 672000000, 70, 4, 1},
7214 { 0, 0, 0, 0, 0, 0 },
7217 static struct clk_pll_controls pllre_controls = {
7218 .enable_mask = PLL_BASE_ENABLE,
7219 .bypass_mask = PLL_BASE_BYPASS,
7220 .iddq_mask = PLLRE_MISC0_IDDQ,
7221 .iddq_reg_idx = PLL_MISC0_IDX,
7222 .lock_mask = PLLRE_MISC0_LOCK,
7223 .lock_reg_idx = PLL_MISC0_IDX,
7226 static struct clk_pll_div_layout pllre_div_layout = {
7230 .ndiv_mask = 0xff << 8,
7232 .pdiv_mask = 0x1f << 16,
7233 .pdiv_to_p = pll_qlin_pdiv_to_p,
7234 .pdiv_max = PLL_QLIN_PDIV_MAX,
7237 static struct clk tegra_pll_re_vco = {
7238 .name = "pll_re_vco",
7239 .clk_id = TEGRA210_CLK_ID_PLL_RE,
7240 .ops = &tegra_pllre_vco_ops,
7242 .parent = &tegra_pll_ref,
7243 .max_rate = 700000000,
7245 .input_min = 9600000,
7246 .input_max = 800000000,
7249 .vco_min = 350000000,
7250 .vco_max = 700000000,
7251 .freq_table = tegra_pllre_vco_freq_table,
7253 .misc0 = 0x4c8 - 0x4c4,
7254 .controls = &pllre_controls,
7255 .div_layout = &pllre_div_layout,
7256 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7257 .set_defaults = pllre_set_defaults,
7262 static struct clk tegra_pll_re_out = {
7263 .name = "pll_re_out",
7264 .clk_id = TEGRA210_CLK_ID_PLL_RE_OUT,
7265 .ops = &tegra_pll_out_ops,
7266 .parent = &tegra_pll_re_vco,
7269 static struct clk tegra_pll_re_out1 = {
7270 .name = "pll_re_out1",
7271 .clk_id = TEGRA210_CLK_ID_PLL_RE_OUT1,
7272 .ops = &tegra_pll_div_ops,
7274 .parent = &tegra_pll_re_vco,
7277 .max_rate = 700000000,
7280 static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
7282 { 12000000, 1000000000, 166, 1, 2}, /* actual: 996.0 MHz */
7283 { 13000000, 1000000000, 153, 1, 2}, /* actual: 994.0 MHz */
7284 { 38400000, 1000000000, 156, 3, 2}, /* actual: 998.4 MHz */
7285 { 0, 0, 0, 0, 0, 0 },
7288 static struct clk_pll_controls pllx_controls = {
7289 .enable_mask = PLL_BASE_ENABLE,
7290 .bypass_mask = PLL_BASE_BYPASS,
7291 .iddq_mask = PLLX_MISC3_IDDQ,
7292 .iddq_reg_idx = PLL_MISC3_IDX,
7293 .lock_mask = PLLX_BASE_LOCK,
7294 .lock_reg_idx = PLL_BASE_IDX,
7296 .dramp_en_mask = PLLX_MISC2_EN_DYNRAMP,
7297 .dramp_done_mask = PLLX_MISC2_DYNRAMP_DONE,
7298 .dramp_ctrl_reg_idx = PLL_MISC2_IDX,
7301 static struct clk_pll_div_layout pllx_div_layout = {
7305 .ndiv_mask = 0xff << 8,
7307 .pdiv_mask = 0x1f << 20,
7308 .pdiv_to_p = pll_qlin_pdiv_to_p,
7309 .pdiv_max = PLL_QLIN_PDIV_MAX,
7311 .ndiv_new_shift = PLLX_MISC2_NDIV_NEW_SHIFT,
7312 .ndiv_new_reg_idx = PLL_MISC2_IDX,
7315 static struct clk tegra_pll_x = {
7317 .clk_id = TEGRA210_CLK_ID_PLL_X,
7319 .ops = &tegra_pllx_ops,
7321 .parent = &tegra_pll_ref,
7322 .max_rate = 3000000000UL,
7324 .input_min = 12000000,
7325 .input_max = 800000000,
7328 .vco_min = 1350000000,
7329 .vco_max = 3000000000UL,
7331 .freq_table = tegra_pll_x_freq_table,
7333 .misc0 = 0xe4 - 0xe0,
7334 .misc1 = 0x510 - 0xe0,
7335 .misc2 = 0x514 - 0xe0,
7336 .misc3 = 0x518 - 0xe0,
7337 .misc4 = 0x5f0 - 0xe0,
7338 .misc5 = 0x5f4 - 0xe0,
7339 .controls = &pllx_controls,
7340 .div_layout = &pllx_div_layout,
7341 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7342 #if PLLX_USE_DYN_RAMP
7343 .dyn_ramp = pllx_dyn_ramp,
7345 .set_defaults = pllx_set_defaults,
7349 static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
7350 { 12000000, 800000000, 66, 1, 1}, /* actual: 792.0 MHz */
7351 { 13000000, 800000000, 61, 1, 1}, /* actual: 793.0 MHz */
7352 { 38400000, 297600000, 93, 4, 3},
7353 { 38400000, 400000000, 125, 4, 3},
7354 { 38400000, 532800000, 111, 4, 2},
7355 { 38400000, 665600000, 104, 3, 2},
7356 { 38400000, 800000000, 125, 3, 2},
7357 { 38400000, 931200000, 97, 4, 1},
7358 { 38400000, 1065600000, 111, 4, 1},
7359 { 38400000, 1200000000, 125, 4, 1},
7360 { 38400000, 1331200000, 104, 3, 1},
7361 { 38400000, 1459200000, 76, 2, 1},
7362 { 38400000, 1600000000, 125, 3, 1},
7363 { 0, 0, 0, 0, 0, 0 },
7366 static struct clk_pll_controls pllm_controls = {
7367 .enable_mask = PLL_BASE_ENABLE,
7368 .iddq_mask = PLLM_MISC0_IDDQ,
7369 .iddq_reg_idx = PLL_MISC0_IDX,
7370 .lock_mask = PLLM_BASE_LOCK,
7371 .lock_reg_idx = PLL_BASE_IDX,
7374 static struct clk_pll_div_layout pllm_div_layout = {
7378 .ndiv_mask = 0xff << 8,
7380 .pdiv_mask = 0x1f << 20,
7381 .pdiv_to_p = pll_qlin_pdiv_to_p,
7382 .pdiv_max = PLL_QLIN_PDIV_MAX,
7385 static struct clk tegra_pll_m = {
7387 .clk_id = TEGRA210_CLK_ID_PLL_M,
7389 .ops = &tegra_pllm_ops,
7391 .parent = &tegra_clk_osc,
7392 .max_rate = 1866000000,
7394 .input_min = 9600000,
7395 .input_max = 500000000,
7398 .vco_min = 800000000,
7399 .vco_max = 1866000000,
7400 .freq_table = tegra_pll_m_freq_table,
7402 .misc0 = 0x9c - 0x90,
7403 .misc1 = 0x98 - 0x90,
7404 .controls = &pllm_controls,
7405 .div_layout = &pllm_div_layout,
7406 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7410 static struct clk_pll_controls pllmb_controls = {
7411 .enable_mask = PLL_BASE_ENABLE,
7412 .iddq_mask = PLLMB_MISC0_IDDQ,
7413 .iddq_reg_idx = PLL_MISC0_IDX,
7414 .lock_mask = PLLMB_BASE_LOCK,
7415 .lock_reg_idx = PLL_BASE_IDX,
7418 static struct clk tegra_pll_mb = {
7420 .clk_id = TEGRA210_CLK_ID_PLL_MB,
7421 .ops = &tegra_pllmb_ops,
7423 .parent = &tegra_clk_osc,
7424 .max_rate = 1866000000,
7426 .input_min = 9600000,
7427 .input_max = 500000000,
7430 .vco_min = 800000000,
7431 .vco_max = 1866000000,
7432 .freq_table = tegra_pll_m_freq_table,
7434 .misc0 = 0x5ec - 0x5e8,
7435 .controls = &pllmb_controls,
7436 .div_layout = &pllm_div_layout, /* same, re-used */
7437 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7438 .set_defaults = pllmb_set_defaults,
7442 static struct clk_pll_freq_table tegra_pll_p_vco_freq_table[] = {
7443 { 12000000, 408000000, 34, 1, 1},
7444 { 13000000, 408000000, 408, 13, 1}, /* cf = 1MHz - only on FPGA */
7445 { 38400000, 408000000, 85, 8, 1}, /* cf = 4.8MHz, allowed exception */
7446 { 0, 0, 0, 0, 0, 0 },
7449 static struct clk_pll_controls pllp_controls = {
7450 .enable_mask = PLL_BASE_ENABLE,
7451 .bypass_mask = PLL_BASE_BYPASS,
7452 .iddq_mask = PLLP_MISC0_IDDQ,
7453 .iddq_reg_idx = PLL_MISC0_IDX,
7454 .lock_mask = PLLP_BASE_LOCK,
7455 .lock_reg_idx = PLL_BASE_IDX,
7458 static struct clk tegra_pll_p = {
7460 .clk_id = TEGRA210_CLK_ID_PLL_P,
7461 .flags = ENABLE_ON_INIT | PLL_FIXED,
7462 .ops = &tegra_pllp_vco_ops,
7464 .parent = &tegra_pll_ref,
7465 .max_rate = 700000000,
7467 .input_min = 9600000,
7468 .input_max = 800000000,
7471 .vco_min = 350000000,
7472 .vco_max = 700000000,
7473 .freq_table = tegra_pll_p_vco_freq_table,
7475 .misc0 = 0xac - 0xa0,
7476 .misc1 = 0x680 - 0xa0,
7477 .controls = &pllp_controls,
7478 .div_layout = &pllre_div_layout, /* same, re-used */
7479 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7480 .set_defaults = pllp_set_defaults,
7482 .fixed_rate = 408000000,
7486 static struct clk_mux_sel mux_clk_osc[] = {
7487 { .input = &tegra_clk_osc, .value = 0},
7491 static struct clk_mux_sel mux_pllp[] = {
7492 { .input = &tegra_pll_p, .value = 0},
7496 static struct clk tegra_pll_p_out_adsp = {
7497 .name = "pll_p_out_adsp",
7498 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT_ADSP,
7499 .ops = &tegra_periph_clk_ops,
7501 .flags = PERIPH_NO_RESET,
7502 .max_rate = 700000000,
7508 static struct clk tegra_pll_p_out_cpu = {
7509 .name = "pll_p_out_cpu",
7510 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT_CPU,
7511 .ops = &tegra_periph_clk_ops,
7513 .flags = PERIPH_NO_RESET,
7514 .max_rate = 700000000,
7520 static struct clk tegra_pll_p_out_hsio = {
7521 .name = "pll_p_out_hsio",
7522 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT_HSIO,
7523 .ops = &tegra_pll_div_ops,
7524 .parent = &tegra_pll_p,
7526 .reg_shift = PLLP_MISC1_HSIO_EN_SHIFT,
7529 static struct clk tegra_pll_p_out_xusb = {
7530 .name = "pll_p_out_xusb",
7531 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT_XUSB,
7532 .ops = &tegra_pll_div_ops,
7533 .parent = &tegra_pll_p_out_hsio,
7535 .reg_shift = PLLP_MISC1_XUSB_EN_SHIFT,
7538 static struct clk tegra_pll_p_out2 = {
7539 .name = "pll_p_out2",
7540 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT2,
7542 .ops = &tegra_pllp_out_ops,
7543 .parent = &tegra_pll_p,
7545 .fixed_rate = 204000000,
7549 static struct clk tegra_pll_p_out3 = {
7550 .name = "pll_p_out3",
7551 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT3,
7552 .ops = &tegra_pll_div_ops,
7553 .flags = DIV_U71 | DIV_U71_FIXED,
7554 .parent = &tegra_pll_p,
7557 .max_rate = 408000000,
7560 static struct clk tegra_pll_p_out4 = {
7561 .name = "pll_p_out4",
7562 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT4,
7563 .ops = &tegra_pll_div_ops,
7564 .flags = DIV_U71 | DIV_U71_INT | DIV_U71_FIXED,
7565 .parent = &tegra_pll_p_out_cpu,
7568 .max_rate = 408000000,
7571 static struct clk tegra_pll_p_out5 = {
7572 .name = "pll_p_out5",
7573 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT5,
7574 .ops = &tegra_pll_div_ops,
7575 .flags = DIV_U71 | DIV_U71_FIXED,
7576 .parent = &tegra_pll_p,
7579 .max_rate = 408000000,
7582 static struct clk tegra_pll_p_out_sor = {
7584 .clk_id = TEGRA210_CLK_ID_PLL_P_OUT_SOR,
7585 .ops = &tegra_periph_clk_ops,
7587 .flags = PERIPH_NO_RESET,
7588 .max_rate = 24000000,
7596 static struct clk_pll_freq_table tegra_pll_u_vco_freq_table[] = {
7597 { 12000000, 480000000, 40, 1, 1},
7598 { 13000000, 480000000, 36, 1, 1}, /* actual: 468.0 MHz */
7599 { 38400000, 480000000, 25, 2, 1},
7600 { 0, 0, 0, 0, 0, 0 },
7603 static struct clk_pll_controls pllu_controls = {
7604 .enable_mask = PLL_BASE_ENABLE,
7605 .bypass_mask = PLL_BASE_BYPASS,
7606 .iddq_mask = PLLU_MISC0_IDDQ,
7607 .iddq_reg_idx = PLL_MISC0_IDX,
7608 .lock_mask = PLLU_BASE_LOCK,
7609 .lock_reg_idx = PLL_BASE_IDX,
7612 static struct clk tegra_pll_u_vco = {
7614 .clk_id = TEGRA210_CLK_ID_PLL_U,
7615 .flags = PLLU | PLL_FIXED,
7616 .ops = &tegra_pllu_vco_ops,
7618 .parent = &tegra_pll_ref,
7619 .max_rate = 700000000,
7621 .input_min = 9600000,
7622 .input_max = 800000000,
7625 .vco_min = 350000000,
7626 .vco_max = 700000000,
7627 .freq_table = tegra_pll_u_vco_freq_table,
7629 .misc0 = 0xcc - 0xc0,
7630 .misc1 = 0xc8 - 0xc0,
7631 .controls = &pllu_controls,
7632 .div_layout = &pllre_div_layout, /* same, re-used */
7633 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7634 .set_defaults = pllu_set_defaults,
7636 .fixed_rate = 480000000,
7640 static struct clk tegra_pll_u_out = {
7641 .name = "pll_u_out",
7642 .clk_id = TEGRA210_CLK_ID_PLL_U_OUT,
7643 .flags = PLLU | PLL_FIXED,
7644 .ops = &tegra_pllu_out_ops,
7645 .parent = &tegra_pll_u_vco,
7647 .fixed_rate = 240000000,
7651 static struct clk tegra_pll_u_out1 = {
7652 .name = "pll_u_out1",
7653 .clk_id = TEGRA210_CLK_ID_PLL_U_OUT1,
7654 .ops = &tegra_pll_div_ops,
7655 .flags = DIV_U71 | DIV_U71_FIXED,
7656 .parent = &tegra_pll_u_out,
7659 .max_rate = 480000000,
7661 .default_rate = 48000000,
7665 static struct clk tegra_pll_u_out2 = {
7666 .name = "pll_u_out2",
7667 .clk_id = TEGRA210_CLK_ID_PLL_U_OUT2,
7668 .ops = &tegra_pll_div_ops,
7669 .flags = DIV_U71 | DIV_U71_FIXED,
7670 .parent = &tegra_pll_u_out,
7673 .max_rate = 480000000,
7675 .default_rate = 60000000,
7679 static struct clk tegra_pll_u_480M = {
7680 .name = "pll_u_480M",
7681 .clk_id = TEGRA210_CLK_ID_PLL_U_480M,
7683 .ops = &tegra_pll_div_ops,
7686 .parent = &tegra_pll_u_vco,
7691 static struct clk tegra_pll_u_60M = {
7692 .name = "pll_u_60M",
7693 .clk_id = TEGRA210_CLK_ID_PLL_U_60M,
7695 .ops = &tegra_pll_div_ops,
7698 .parent = &tegra_pll_u_out2,
7703 static struct clk tegra_pll_u_48M = {
7704 .name = "pll_u_48M",
7705 .clk_id = TEGRA210_CLK_ID_PLL_U_48M,
7707 .ops = &tegra_pll_div_ops,
7710 .parent = &tegra_pll_u_out1,
7715 static struct clk tegra_dfll_cpu = {
7717 .clk_id = TEGRA210_CLK_ID_DFLL_CPU,
7719 .ops = &tegra_dfll_ops,
7721 .max_rate = 3000000000UL,
7724 static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
7725 { 672000000, 100000000, 125, 42, 20,},
7726 { 624000000, 100000000, 125, 39, 20,},
7727 { 336000000, 100000000, 125, 21, 20,},
7728 { 312000000, 100000000, 200, 26, 24,},
7729 { 38400000, 100000000, 125, 2, 24,},
7730 { 13000000, 100000000, 184, 1, 24,}, /* actual: 99.6MHz (FPGA) */
7731 { 12000000, 100000000, 200, 1, 24,},
7732 { 0, 0, 0, 0, 0, 0 },
7735 static struct clk_mux_sel mux_pll_e_inputs[] = {
7736 { .input = &tegra_pll_ref, .value = 0},
7737 { .input = &tegra_pll_p, .value = 1},
7738 { .input = &tegra_pll_re_vco, .value = 2},
7739 { .input = &tegra_pll_re_vco, .value = 3},
7743 static struct clk tegra_pll_e = {
7745 .clk_id = TEGRA210_CLK_ID_PLL_E,
7747 .ops = &tegra_plle_ops,
7749 .max_rate = 100000000,
7750 .inputs = mux_pll_e_inputs,
7752 .input_min = 12000000,
7753 .input_max = 800000000,
7756 .vco_min = 1600000000,
7757 .vco_max = 2500000000U,
7758 .freq_table = tegra_pll_e_freq_table,
7760 .fixed_rate = 100000000,
7761 .misc0 = 0xec - 0xe8,
7762 .round_p_to_pdiv = pll_qlin_p_to_pdiv,
7766 static struct clk tegra_pll_e_gate = {
7767 .name = "plle_gate",
7768 .clk_id = TEGRA210_CLK_ID_PLL_E_GATE,
7769 .parent = &tegra_pll_e,
7770 .ops = &tegra_cml_clk_ops,
7772 .max_rate = 100000000,
7778 static struct clk tegra_cml0_clk = {
7780 .clk_id = TEGRA210_CLK_ID_PLL_E_CML0,
7781 .parent = &tegra_pll_e,
7782 .ops = &tegra_cml_clk_ops,
7784 .max_rate = 100000000,
7790 static struct clk tegra_cml1_clk = {
7792 .clk_id = TEGRA210_CLK_ID_PLL_E_CML1,
7793 .parent = &tegra_pll_e,
7794 .ops = &tegra_cml_clk_ops,
7796 .max_rate = 100000000,
7802 static struct clk tegra_pciex_clk = {
7804 .clk_id = TEGRA210_CLK_ID_PCIEX,
7805 .parent = &tegra_pll_e,
7806 .ops = &tegra_pciex_clk_ops,
7807 .max_rate = 500000000,
7813 /* Audio sync clocks */
7814 #define SYNC_SOURCE(_id, _dev, _clk_id) \
7816 .name = #_id "_sync", \
7817 .clk_id = TEGRA210_CLK_ID_##_clk_id##_SYNC, \
7820 .con_id = "ext_audio_sync", \
7823 .max_rate = 24576000, \
7824 .ops = &tegra_sync_source_ops \
7826 static struct clk tegra_sync_source_list[] = {
7827 SYNC_SOURCE(spdif_in, tegra210-spdif, SPDIF_IN),
7828 SYNC_SOURCE(i2s0, tegra210-i2s.0, I2S0),
7829 SYNC_SOURCE(i2s1, tegra210-i2s.1, I2S1),
7830 SYNC_SOURCE(i2s2, tegra210-i2s.2, I2S2),
7831 SYNC_SOURCE(i2s3, tegra210-i2s.3, I2S3),
7832 SYNC_SOURCE(i2s4, tegra210-i2s.4, I2S4),
7833 SYNC_SOURCE(vimclk, vimclk, VIMCLK),
7836 static struct clk_mux_sel mux_d_audio_clk[] = {
7837 { .input = &tegra_pll_a_out0, .value = 0},
7838 { .input = &tegra_pll_p, .value = 0x8000},
7839 { .input = &tegra_clk_m, .value = 0xc000},
7840 { .input = &tegra_sync_source_list[0], .value = 0xE000},
7841 { .input = &tegra_sync_source_list[1], .value = 0xE001},
7842 { .input = &tegra_sync_source_list[2], .value = 0xE002},
7843 { .input = &tegra_sync_source_list[3], .value = 0xE003},
7844 { .input = &tegra_sync_source_list[4], .value = 0xE004},
7845 { .input = &tegra_sync_source_list[5], .value = 0xE005},
7846 { .input = &tegra_pll_a_out0, .value = 0xE006},
7847 { .input = &tegra_sync_source_list[6], .value = 0xE007},
7851 static struct clk_mux_sel mux_audio_sync_clk[] =
7853 { .input = &tegra_sync_source_list[0], .value = 0},
7854 { .input = &tegra_sync_source_list[1], .value = 1},
7855 { .input = &tegra_sync_source_list[2], .value = 2},
7856 { .input = &tegra_sync_source_list[3], .value = 3},
7857 { .input = &tegra_sync_source_list[4], .value = 4},
7858 { .input = &tegra_sync_source_list[5], .value = 5},
7859 { .input = &tegra_pll_a_out0, .value = 6},
7860 { .input = &tegra_sync_source_list[6], .value = 7},
7864 #define AUDIO_SYNC_CLK(_id, _dev, _index, _clk_id) \
7867 .clk_id = TEGRA210_CLK_ID_##_clk_id, \
7870 .con_id = "audio_sync", \
7872 .inputs = mux_audio_sync_clk, \
7873 .reg = 0x4A0 + (_index) * 4, \
7874 .max_rate = 24576000, \
7875 .ops = &tegra_audio_sync_clk_ops \
7877 static struct clk tegra_clk_audio_list[] = {
7878 AUDIO_SYNC_CLK(audio0, tegra210-i2s.0, 0, AUDIO0),
7879 AUDIO_SYNC_CLK(audio1, tegra210-i2s.1, 1, AUDIO1),
7880 AUDIO_SYNC_CLK(audio2, tegra210-i2s.2, 2, AUDIO2),
7881 AUDIO_SYNC_CLK(audio3, tegra210-i2s.3, 3, AUDIO3),
7882 AUDIO_SYNC_CLK(audio4, tegra210-i2s.4, 4, AUDIO4),
7883 AUDIO_SYNC_CLK(audio, tegra210-spdif, 5, AUDIO), /* SPDIF */
7886 #define AUDIO_SYNC_2X_CLK(_id, _dev, _index, _clk_id) \
7888 .name = #_id "_2x", \
7889 .clk_id = TEGRA210_CLK_ID_##_clk_id##_2x, \
7892 .con_id = "audio_sync_2x" \
7894 .flags = PERIPH_NO_RESET, \
7895 .max_rate = 49152000, \
7896 .ops = &tegra_clk_double_ops, \
7898 .reg_shift = 24 + (_index), \
7899 .parent = &tegra_clk_audio_list[(_index)], \
7901 .clk_num = 113 + (_index), \
7904 static struct clk tegra_clk_audio_2x_list[] = {
7905 AUDIO_SYNC_2X_CLK(audio, tegra210-spdif, 5, AUDIO), /* SPDIF */
7908 #define MUX_I2S_SPDIF(_id, _index) \
7909 static struct clk_mux_sel mux_pllaout0_##_id##_pllp_clkm[] = { \
7910 {.input = &tegra_pll_a_out0, .value = 0}, \
7911 {.input = &tegra_clk_audio_list[(_index)], .value = 2}, \
7912 {.input = &tegra_pll_p, .value = 4}, \
7913 {.input = &tegra_clk_m, .value = 6}, \
7916 MUX_I2S_SPDIF(audio0, 0);
7917 MUX_I2S_SPDIF(audio1, 1);
7918 MUX_I2S_SPDIF(audio2, 2);
7919 MUX_I2S_SPDIF(audio3, 3);
7920 MUX_I2S_SPDIF(audio4, 4);
7923 static struct clk_mux_sel mux_pllaout0_audio_2x_pllp_clkm[] = {
7924 {.input = &tegra_pll_a_out0, .value = 0},
7925 {.input = &tegra_clk_audio_2x_list[0], .value = 2},
7926 {.input = &tegra_pll_p, .value = 4},
7927 {.input = &tegra_clk_m, .value = 6},
7931 /* Audio sync dmic clocks */
7932 #define AUDIO_SYNC_DMIC_CLK(_id, _dev, _reg, _clk_id) \
7934 .name = #_id "_dmic", \
7935 .clk_id = TEGRA210_CLK_ID_##_clk_id##_DMIC, \
7938 .con_id = "audio_sync_dmic", \
7940 .inputs = mux_audio_sync_clk, \
7942 .max_rate = 24576000, \
7943 .ops = &tegra_audio_sync_clk_ops \
7946 static struct clk tegra_clk_audio_dmic_list[] = {
7947 AUDIO_SYNC_DMIC_CLK(audio0, tegra210-i2s.0, 0x560, AUDIO0),
7948 AUDIO_SYNC_DMIC_CLK(audio1, tegra210-i2s.1, 0x564, AUDIO1),
7949 AUDIO_SYNC_DMIC_CLK(audio2, tegra210-i2s.2, 0x6b8, AUDIO2),
7952 #define MUX_AUDIO_DMIC(_id, _index) \
7953 static struct clk_mux_sel mux_pllaout0_##_id##_dmic_pllp_clkm[] = { \
7954 {.input = &tegra_pll_a_out0, .value = 0}, \
7955 {.input = &tegra_clk_audio_dmic_list[(_index)], .value = 1}, \
7956 {.input = &tegra_pll_p, .value = 2}, \
7957 {.input = &tegra_clk_m, .value = 3}, \
7960 MUX_AUDIO_DMIC(audio0, 0);
7961 MUX_AUDIO_DMIC(audio1, 1);
7962 MUX_AUDIO_DMIC(audio2, 2);
7964 /* External clock outputs (through PMC) */
7965 #define MUX_EXTERN_OUT(_id) \
7966 static struct clk_mux_sel mux_clkm_clkm2_clkm4_extern##_id[] = { \
7967 {.input = &tegra_clk_m, .value = 0}, \
7968 {.input = &tegra_clk_m_div2, .value = 1}, \
7969 {.input = &tegra_clk_m_div4, .value = 2}, \
7970 {.input = NULL, .value = 3}, /* placeholder */ \
7977 static struct clk_mux_sel *mux_extern_out_list[] = {
7978 mux_clkm_clkm2_clkm4_extern1,
7979 mux_clkm_clkm2_clkm4_extern2,
7980 mux_clkm_clkm2_clkm4_extern3,
7983 #define CLK_OUT_CLK(_id, _max_rate) \
7985 .name = "clk_out_" #_id, \
7986 .clk_id = TEGRA210_CLK_ID_CLK_OUT_##_id, \
7988 .dev_id = "clk_out_" #_id, \
7989 .con_id = "extern" #_id, \
7991 .ops = &tegra_clk_out_ops, \
7993 .inputs = mux_clkm_clkm2_clkm4_extern##_id, \
7994 .flags = MUX_CLK_OUT, \
7995 .max_rate = _max_rate, \
7997 .clk_num = (_id - 1) * 8 + 2, \
8000 static struct clk tegra_clk_out_list[] = {
8001 CLK_OUT_CLK(1, 40800000),
8002 CLK_OUT_CLK(2, 40800000),
8003 CLK_OUT_CLK(3, 40800000),
8006 /* called after peripheral external clocks are initialized */
8007 static void init_clk_out_mux(void)
8012 /* output clock con_id is the name of peripheral
8013 external clock connected to input 3 of the output mux */
8014 for (i = 0; i < ARRAY_SIZE(tegra_clk_out_list); i++) {
8015 c = tegra_get_clock_by_name(
8016 tegra_clk_out_list[i].lookup.con_id);
8018 pr_err("%s: could not find clk %s\n", __func__,
8019 tegra_clk_out_list[i].lookup.con_id);
8020 mux_extern_out_list[i][3].input = c;
8024 /* Peripheral muxes */
8025 static struct clk_mux_sel mux_cclk_g[] = {
8026 { .input = &tegra_clk_m, .value = 0},
8027 { .input = &tegra_clk_32k, .value = 2},
8028 { .input = &tegra_pll_p_out_cpu, .value = 4},
8029 { .input = &tegra_pll_p_out4, .value = 5},
8030 { .input = &tegra_pll_x, .value = 8},
8031 { .input = &tegra_dfll_cpu, .value = 15},
8035 static struct clk_mux_sel mux_cclk_lp[] = {
8036 { .input = &tegra_clk_m, .value = 0},
8037 { .input = &tegra_clk_32k, .value = 2},
8038 { .input = &tegra_pll_p_out_cpu, .value = 4},
8039 { .input = &tegra_pll_p_out4, .value = 5},
8040 { .input = &tegra_pll_x, .value = 8},
8044 static struct clk_mux_sel mux_sclk[] = {
8045 { .input = &tegra_clk_m, .value = 0},
8046 { .input = &tegra_pll_c_out1, .value = 1},
8047 { .input = &tegra_pll_c4_out3, .value = 2},
8048 { .input = &tegra_pll_p, .value = 3},
8049 { .input = &tegra_pll_p_out2, .value = 4},
8050 { .input = &tegra_pll_c4_out1, .value = 5},
8051 { .input = &tegra_clk_32k, .value = 6},
8052 { .input = &tegra_pll_c4_out2, .value = 7},
8056 /* ADSP cluster clocks */
8057 static struct clk_mux_sel mux_aclk_adsp[] = {
8058 { .input = &tegra_pll_p_out_adsp, .value = 2},
8059 { .input = &tegra_pll_a_out0_out_adsp, .value = 3},
8060 { .input = &tegra_clk_m, .value = 6},
8061 { .input = &tegra_pll_a_out_adsp, .value = 7},
8062 { .input = &tegra_pll_a1, .value = 8},
8066 static void tegra21_adsp_clk_reset(struct clk *c, bool assert)
8068 unsigned long reg = assert ? RST_DEVICES_SET_Y : RST_DEVICES_CLR_Y;
8069 u32 val = ADSP_NEON | ADSP_SCU | ADSP_WDT | ADSP_DBG
8070 | ADSP_PERIPH | ADSP_CORE;
8072 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
8075 clk_writel_delay(val | ADSP_INTF, reg);
8077 clk_writel_delay(ADSP_INTF, reg);
8079 * Considering adsp cpu clock (min: 12.5MHZ, max: 1GHz)
8080 * a delay of 5us ensures that it's at least
8081 * 6 * adsp_cpu_cycle_period long.
8084 clk_writel_delay(val, reg);
8088 static int tegra21_adsp_clk_enable(struct clk *c)
8090 u32 val = ADSP_NEON | ADSP_CORE;
8092 clk_writel_delay(val, CLK_OUT_ENB_SET_Y);
8096 static void tegra21_adsp_clk_disable(struct clk *c)
8098 u32 val = ADSP_NEON | ADSP_CORE;
8100 clk_writel_delay(val, CLK_OUT_ENB_CLR_Y);
8103 static void tegra21_adsp_clk_init(struct clk *c)
8106 * Check/enforce ADSP clock default configuration:
8110 tegra21_super_clk_set_parent(c, &tegra_clk_m);
8111 tegra21_super_clk_init(c);
8114 * CPU and system super clocks cannot be disabled, and super clock init
8115 * always marks clock sate ON, which is not true for ADSP. Need explicit
8118 c->state = clk_readl(CLK_OUT_ENB_Y)&(ADSP_NEON | ADSP_CORE) ? ON : OFF;
8119 if (c->state == ON) {
8120 WARN(1, "Tegra ADSP clock is running on boot: turning Off\n");
8121 tegra21_adsp_clk_disable(c);
8126 static struct clk_ops tegra_adsp_ops = {
8127 .init = tegra21_adsp_clk_init,
8128 .enable = tegra21_adsp_clk_enable,
8129 .disable = tegra21_adsp_clk_disable,
8130 .set_parent = tegra21_super_clk_set_parent,
8131 .reset = tegra21_adsp_clk_reset,
8134 static struct clk tegra_clk_aclk_adsp = {
8136 .clk_id = TEGRA210_CLK_ID_ADSP,
8137 .flags = DIV_U71 | DIV_U71_INT,
8138 .inputs = mux_aclk_adsp,
8140 .ops = &tegra_adsp_ops,
8141 .max_rate = 1200000000,
8144 static struct clk_ops tegra_adsp_bus_ops = {
8145 .init = tegra21_adsp_bus_clk_init,
8146 .enable = tegra21_adsp_bus_clk_enable,
8147 .disable = tegra21_adsp_bus_clk_disable,
8148 .set_rate = tegra21_adsp_bus_clk_set_rate,
8149 .round_rate = tegra21_adsp_bus_clk_round_rate,
8150 .shared_bus_update = tegra21_clk_shared_connector_update, /* re-use */
8153 static struct raw_notifier_head adsp_bus_rate_change_nh;
8154 static struct clk tegra_clk_virtual_adsp_bus = {
8156 .clk_id = TEGRA210_CLK_ID_ADSP_BUS,
8157 .parent = &tegra_clk_aclk_adsp,
8158 .ops = &tegra_adsp_bus_ops,
8159 .shared_bus_flags = SHARED_BUS_RETENTION,
8160 .max_rate = 1200000000,
8162 .main = &tegra_pll_a1,
8163 .backup = &tegra_pll_p_out_adsp,
8165 .rate_change_nh = &adsp_bus_rate_change_nh,
8168 /* CPU clusters clocks */
8169 static struct clk tegra_clk_cclk_g = {
8171 .clk_id = TEGRA210_CLK_ID_CCLK_G,
8172 .flags = DIV_U71 | DIV_U71_INT,
8173 .inputs = mux_cclk_g,
8175 .ops = &tegra_super_ops,
8176 .max_rate = 3000000000UL,
8179 static struct clk tegra_clk_cclk_lp = {
8181 .clk_id = TEGRA210_CLK_ID_CCLK_LP,
8182 .flags = DIV_U71 | DIV_U71_INT,
8183 .inputs = mux_cclk_lp,
8185 .ops = &tegra_super_ops,
8186 .max_rate = 1350000000,
8189 static struct clk tegra_clk_virtual_cpu_g = {
8191 .clk_id = TEGRA210_CLK_ID_CPU_G,
8192 .parent = &tegra_clk_cclk_g,
8193 .ops = &tegra_cpu_ops,
8194 .max_rate = 3000000000UL,
8196 .main = &tegra_pll_x,
8197 .backup = &tegra_pll_p_out4,
8198 .dynamic = &tegra_dfll_cpu,
8203 static struct clk tegra_clk_virtual_cpu_lp = {
8205 .clk_id = TEGRA210_CLK_ID_CPU_LP,
8206 .parent = &tegra_clk_cclk_lp,
8207 .ops = &tegra_cpu_ops,
8208 .max_rate = 1350000000,
8209 .min_rate = 3187500,
8211 .main = &tegra_pll_x,
8212 .backup = &tegra_pll_p_out4,
8217 static struct clk_mux_sel mux_cpu_cmplx[] = {
8218 { .input = &tegra_clk_virtual_cpu_g, .value = 0},
8219 { .input = &tegra_clk_virtual_cpu_lp, .value = 1},
8223 static struct clk tegra_clk_cpu_cmplx = {
8225 .clk_id = TEGRA210_CLK_ID_CCPLEX,
8226 .inputs = mux_cpu_cmplx,
8227 .ops = &tegra_cpu_cmplx_ops,
8228 .max_rate = 3000000000UL,
8231 /* System bus clocks */
8232 static struct clk tegra_clk_sclk_mux = {
8234 .clk_id = TEGRA210_CLK_ID_SCLK_MUX,
8237 .ops = &tegra_super_ops,
8238 .max_rate = 1200000000,
8239 .min_rate = 12000000,
8242 static struct clk_mux_sel sclk_mux_out[] = {
8243 { .input = &tegra_clk_sclk_mux, .value = 0},
8247 static struct clk tegra_clk_sclk_div = {
8249 .clk_id = TEGRA210_CLK_ID_SCLK_DIV,
8250 .ops = &tegra_periph_clk_ops,
8252 .max_rate = 600000000,
8253 .min_rate = 12000000,
8254 .inputs = sclk_mux_out,
8255 .flags = DIV_U71 | PERIPH_NO_ENB | PERIPH_NO_RESET,
8258 static struct clk tegra_clk_sclk = {
8260 .clk_id = TEGRA210_CLK_ID_SCLK_SKIP,
8262 .ops = &tegra_clk_super_skip_ops,
8264 .parent = &tegra_clk_sclk_div,
8267 static struct clk tegra_clk_cop = {
8269 .parent = &tegra_clk_sclk,
8270 .ops = &tegra_cop_ops,
8271 .max_rate = 600000000,
8274 static struct clk tegra_clk_hclk = {
8276 .clk_id = TEGRA210_CLK_ID_HCLK,
8278 .parent = &tegra_clk_sclk,
8281 .ops = &tegra_bus_ops,
8282 .max_rate = 600000000,
8283 .min_rate = 12000000,
8286 static struct clk tegra_clk_pclk = {
8288 .clk_id = TEGRA210_CLK_ID_PCLK,
8290 .parent = &tegra_clk_hclk,
8293 .ops = &tegra_bus_ops,
8294 .max_rate = 600000000,
8295 .min_rate = 12000000,
8298 static struct raw_notifier_head sbus_rate_change_nh;
8300 static struct clk tegra_clk_sbus_cmplx = {
8302 .clk_id = TEGRA210_CLK_ID_SBUS,
8303 .parent = &tegra_clk_sclk,
8304 .ops = &tegra_sbus_cmplx_ops,
8306 .pclk = &tegra_clk_pclk,
8307 .hclk = &tegra_clk_hclk,
8308 .sclk_low = &tegra_pll_p,
8309 .sclk_high = &tegra_pll_p,
8311 .rate_change_nh = &sbus_rate_change_nh,
8314 static struct clk tegra_clk_ahb = {
8317 .parent = &tegra_clk_sbus_cmplx,
8318 .ops = &tegra_clk_ahb_ops,
8321 static struct clk tegra_clk_apb = {
8324 .parent = &tegra_clk_ahb,
8325 .ops = &tegra_clk_apb_ops,
8328 static struct clk tegra_clk_blink = {
8330 .clk_id = TEGRA210_CLK_ID_BLINK,
8331 .parent = &tegra_clk_32k,
8333 .ops = &tegra_blink_clk_ops,
8337 static struct clk_ops tegra_xusb_padctl_ops = {
8338 .reset = tegra21_periph_clk_reset,
8341 static struct clk tegra_clk_xusb_padctl = {
8342 .name = "xusb_padctl",
8343 .clk_id = TEGRA210_CLK_ID_XUSB_PADCTRL,
8344 .ops = &tegra_xusb_padctl_ops,
8350 static struct clk tegra_clk_sata_uphy = {
8351 .name = "sata_uphy",
8352 .clk_id = TEGRA210_CLK_ID_SATA_UPHY,
8353 .ops = &tegra_xusb_padctl_ops,
8359 static struct clk tegra_pex_uphy_clk = {
8361 .clk_id = TEGRA210_CLK_ID_PEX_UPHY,
8362 .ops = &tegra_xusb_padctl_ops,
8368 static struct clk tegra_clk_usb2_hsic_trk = {
8369 .name = "usb2_hsic_trk",
8370 .flags = DIV_U71 | PERIPH_NO_ENB | PERIPH_NO_RESET,
8371 .inputs = mux_clk_osc,
8373 .ops = &tegra_periph_clk_ops,
8374 .max_rate = 38400000,
8377 /* Multimedia modules muxes */
8378 static struct clk_mux_sel mux_pllc2_c_c3_pllp_plla1_clkm[] = {
8379 { .input = &tegra_pll_c2, .value = 1},
8380 { .input = &tegra_pll_c, .value = 2},
8381 { .input = &tegra_pll_c3, .value = 3},
8382 { .input = &tegra_pll_p, .value = 4},
8383 { .input = &tegra_pll_a1, .value = 6},
8384 { .input = &tegra_clk_m, .value = 7},
8388 static struct clk_mux_sel mux_pllc4_out1_pllc_pllc4_out2_pllp_clkm_plla_pllc4_out0[] = {
8389 { .input = &tegra_pll_c4_out1, .value = 0},
8390 { .input = &tegra_pll_c, .value = 2},
8391 { .input = &tegra_pll_c4_out2, .value = 3},
8392 { .input = &tegra_pll_p, .value = 4},
8393 { .input = &tegra_clk_m, .value = 5},
8394 { .input = &tegra_pll_a_out0, .value = 6},
8395 { .input = &tegra_pll_c4_out0, .value = 7},
8399 static struct clk_mux_sel mux_pllc_pllp_plla[] = {
8400 { .input = &tegra_pll_c, .value = 2},
8401 { .input = &tegra_pll_p, .value = 4},
8402 { .input = &tegra_pll_a_out0, .value = 6},
8406 static struct clk_mux_sel mux_clkm_pllc_pllp_plla[] = {
8407 { .input = &tegra_clk_m, .value = 0},
8408 { .input = &tegra_pll_c, .value = 1},
8409 { .input = &tegra_pll_p, .value = 2},
8410 { .input = &tegra_pll_a_out0, .value = 3},
8414 static struct clk_mux_sel mux_pllc_pllp_plla1_pllc2_c3_clkm[] = {
8415 { .input = &tegra_pll_c, .value = 1},
8416 { .input = &tegra_pll_p, .value = 2},
8417 { .input = &tegra_pll_a1, .value = 3},
8418 { .input = &tegra_pll_c2, .value = 4},
8419 { .input = &tegra_pll_c3, .value = 5},
8420 { .input = &tegra_clk_m, .value = 6},
8424 static struct clk_mux_sel mux_pllc2_c_c3_pllp_clkm_plla1_pllc4[] = {
8425 { .input = &tegra_pll_c2, .value = 1},
8426 { .input = &tegra_pll_c, .value = 2},
8427 { .input = &tegra_pll_c3, .value = 3},
8428 { .input = &tegra_pll_p, .value = 4},
8429 { .input = &tegra_clk_m, .value = 5},
8430 { .input = &tegra_pll_a1, .value = 6},
8431 { .input = &tegra_pll_c4_out0, .value = 7},
8435 static struct clk_mux_sel mux_pllc_pllp_plla1_pllc2_c3_clkm_pllc4[] = {
8436 { .input = &tegra_pll_c, .value = 1},
8437 { .input = &tegra_pll_p, .value = 2},
8438 { .input = &tegra_pll_a1, .value = 3},
8439 { .input = &tegra_pll_c2, .value = 4},
8440 { .input = &tegra_pll_c3, .value = 5},
8441 { .input = &tegra_clk_m, .value = 6},
8442 { .input = &tegra_pll_c4_out0, .value = 7},
8446 static struct clk_mux_sel mux_plla_pllc4_out0_pllc_pllc4_out1_pllp_clkm_pllc4_out2[] = {
8447 { .input = &tegra_pll_a_out0, .value = 0},
8448 { .input = &tegra_pll_c4_out0, .value = 1},
8449 { .input = &tegra_pll_c, .value = 2},
8450 { .input = &tegra_pll_c4_out1, .value = 3},
8451 { .input = &tegra_pll_p, .value = 4},
8452 { .input = &tegra_pll_c4_out2, .value = 5},
8453 { .input = &tegra_clk_m, .value = 6},
8458 /* FIXME: add EMC latency mux */
8459 /* FIXME: add EMC PLLP branch */
8460 static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
8461 { .input = &tegra_pll_m, .value = 0},
8462 { .input = &tegra_pll_c, .value = 1},
8463 { .input = &tegra_pll_p, .value = 2},
8464 { .input = &tegra_clk_m, .value = 3},
8465 { .input = &tegra_pll_m, .value = 4}, /* low jitter PLLM output */
8466 { .input = &tegra_pll_mb, .value = 5}, /* low jitter PLLMB output */
8467 { .input = &tegra_pll_mb, .value = 6},
8468 { .input = &tegra_pll_p, .value = 7}, /* low jitter PLLP output */
8473 /* Display subsystem muxes */
8474 static struct clk_mux_sel mux_pllp_plld_plld2_clkm[] = {
8475 {.input = &tegra_pll_p_out_hsio, .value = 0},
8476 {.input = &tegra_pll_d_out0, .value = 2},
8477 {.input = &tegra_pll_d2, .value = 5},
8478 {.input = &tegra_clk_m, .value = 6},
8482 static struct clk_mux_sel mux_plld_out0[] = {
8483 { .input = &tegra_pll_d_out0, .value = 0},
8487 static struct clk_mux_sel mux_plldp[] = {
8488 { .input = &tegra_pll_dp, .value = 0},
8492 static struct clk tegra_clk_sor0_brick = {
8493 .name = "sor0_brick",
8494 .clk_id = TEGRA210_CLK_ID_SOR0_BRICK,
8495 .ops = &tegra_sor_brick_ops,
8496 .max_rate = 600000000,
8497 .inputs = mux_plldp,
8498 .flags = PERIPH_NO_ENB | PERIPH_NO_RESET,
8501 static struct clk_mux_sel mux_pllp_sor_sor0_brick[] = {
8502 { .input = &tegra_pll_p_out_sor, .value = 0},
8503 { .input = &tegra_clk_sor0_brick, .value = 1},
8507 static struct clk tegra_clk_sor1_src = {
8509 .clk_id = TEGRA210_CLK_ID_SOR1_SRC,
8510 .ops = &tegra_periph_clk_ops,
8512 .max_rate = 600000000,
8513 .inputs = mux_pllp_plld_plld2_clkm,
8514 .flags = MUX | DIV_U71 | PERIPH_NO_ENB | PERIPH_NO_RESET,
8517 static struct clk_mux_sel mux_plldp_sor1_src[] = {
8518 { .input = &tegra_pll_dp, .value = 0},
8519 { .input = &tegra_clk_sor1_src, .value = 1},
8523 static struct clk tegra_clk_sor1_brick = {
8524 .name = "sor1_brick",
8525 .clk_id = TEGRA210_CLK_ID_SOR1_BRICK,
8526 .ops = &tegra_sor_brick_ops,
8527 .max_rate = 600000000,
8528 .inputs = mux_plldp_sor1_src,
8529 .flags = MUX | PERIPH_NO_ENB | PERIPH_NO_RESET,
8532 static struct clk_mux_sel mux_pllp_sor_sor1_brick_sor1_src[] = {
8533 { .input = &tegra_pll_p_out_sor, .value = 0},
8534 { .input = &tegra_clk_sor1_brick, .value = 1},
8535 { .input = &tegra_clk_sor1_src, .value = 2},
8536 { .input = &tegra_clk_sor1_brick, .value = 3},
8540 static struct clk_mux_sel mux_pllp_pllre_clkm[] = {
8541 { .input = &tegra_pll_p, .value = 0 },
8542 { .input = &tegra_pll_re_out1, .value = 4 },
8543 { .input = &tegra_clk_m, .value = 6 },
8546 /* Peripheral muxes */
8547 static struct clk_mux_sel mux_pllp_pllc_clkm[] = {
8548 {.input = &tegra_pll_p, .value = 0},
8549 {.input = &tegra_pll_c, .value = 2},
8550 {.input = &tegra_clk_m, .value = 6},
8554 static struct clk_mux_sel mux_pllp_pllc_plla_clkm[] = {
8555 {.input = &tegra_pll_p, .value = 0},
8556 {.input = &tegra_pll_c, .value = 2},
8557 {.input = &tegra_pll_a_out0, .value = 4},
8558 {.input = &tegra_clk_m, .value = 6},
8562 static struct clk_mux_sel mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2[] = {
8563 {.input = &tegra_pll_p, .value = 0},
8564 {.input = &tegra_pll_c, .value = 2},
8565 {.input = &tegra_pll_c4_out0, .value = 3},
8566 {.input = &tegra_pll_c4_out1, .value = 5},
8567 {.input = &tegra_clk_m, .value = 6},
8568 {.input = &tegra_pll_c4_out2, .value = 7},
8572 static struct clk_mux_sel mux_pllp_pllc_pllc_out1_pllc4_out2_pllc4_out1_clkm_pllc4_out0[] = {
8573 {.input = &tegra_pll_p, .value = 0},
8574 {.input = &tegra_pll_c_out1, .value = 1},
8575 {.input = &tegra_pll_c, .value = 2},
8576 {.input = &tegra_pll_c4_out2, .value = 4},
8577 {.input = &tegra_pll_c4_out1, .value = 5},
8578 {.input = &tegra_clk_m, .value = 6},
8579 {.input = &tegra_pll_c4_out0, .value = 7},
8583 static struct clk_mux_sel mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0[] = {
8584 {.input = &tegra_pll_p, .value = 0},
8585 {.input = &tegra_pll_c4_out2, .value = 3},
8586 {.input = &tegra_pll_c4_out1, .value = 4},
8587 {.input = &tegra_clk_m, .value = 6},
8588 {.input = &tegra_pll_c4_out0, .value = 7},
8592 static struct clk_mux_sel mux_pllp_clk_m_pllc4_out2_out1_out0_lj[] = {
8593 {.input = &tegra_pll_p, .value = 0},
8594 {.input = &tegra_pll_c4_out2, .value = 1}, /* LJ input */
8595 {.input = &tegra_pll_c4_out0, .value = 2}, /* LJ input */
8596 {.input = &tegra_pll_c4_out2, .value = 3},
8597 {.input = &tegra_pll_c4_out1, .value = 4},
8598 {.input = &tegra_pll_c4_out1, .value = 5}, /* LJ input */
8599 {.input = &tegra_clk_m, .value = 6},
8600 {.input = &tegra_pll_c4_out0, .value = 7},
8604 static struct clk_mux_sel mux_pllp_pllc2_c_c3_clkm[] = {
8605 { .input = &tegra_pll_p, .value = 0},
8606 { .input = &tegra_pll_c2, .value = 1},
8607 { .input = &tegra_pll_c, .value = 2},
8608 { .input = &tegra_pll_c3, .value = 3},
8609 { .input = &tegra_clk_m, .value = 6},
8613 static struct clk_mux_sel mux_pllp_pllc_clkm_1[] = {
8614 {.input = &tegra_pll_p, .value = 0},
8615 {.input = &tegra_pll_c, .value = 2},
8616 {.input = &tegra_clk_m, .value = 5},
8620 static struct clk_mux_sel mux_pllp_clkm_2[] = {
8621 { .input = &tegra_pll_p, .value = 2},
8622 { .input = &tegra_clk_m, .value = 6},
8626 static struct clk_mux_sel mux_pllp_clkm_clk32_plle[] = {
8627 { .input = &tegra_pll_p, .value = 0},
8628 { .input = &tegra_clk_m, .value = 2},
8629 { .input = &tegra_clk_32k, .value = 4},
8630 { .input = &tegra_pll_e_gate, .value = 6},
8634 static struct clk_mux_sel mux_pllp_clkm[] = {
8635 { .input = &tegra_pll_p, .value = 0},
8636 { .input = &tegra_clk_m, .value = 6},
8640 static struct clk_mux_sel mux_pllp_pllp_out3_clkm_clk32k_plla[] = {
8641 { .input = &tegra_pll_p, .value = 0},
8642 { .input = &tegra_pll_p_out3, .value = 1},
8643 { .input = &tegra_clk_m, .value = 2},
8644 { .input = &tegra_clk_32k, .value = 3},
8645 { .input = &tegra_pll_a_out0, .value = 4},
8649 static struct clk_mux_sel mux_pllp_out3_clkm_pllp_pllc4[] = {
8650 { .input = &tegra_pll_p_out3, .value = 0},
8651 { .input = &tegra_clk_m, .value = 3},
8652 { .input = &tegra_pll_p, .value = 4},
8653 { .input = &tegra_pll_c4_out0, .value = 5},
8654 { .input = &tegra_pll_c4_out1, .value = 6},
8655 { .input = &tegra_pll_c4_out2, .value = 7},
8659 static struct clk_mux_sel mux_pllp_pllc_clk32_clkm[] = {
8660 {.input = &tegra_pll_p, .value = 0},
8661 {.input = &tegra_pll_c, .value = 2},
8662 {.input = &tegra_clk_32k, .value = 4},
8663 {.input = &tegra_clk_m, .value = 6},
8667 static struct clk_mux_sel mux_pllp_pllc_clkm_clk32[] = {
8668 {.input = &tegra_pll_p, .value = 0},
8669 {.input = &tegra_pll_c, .value = 2},
8670 {.input = &tegra_clk_m, .value = 4},
8671 {.input = &tegra_clk_32k, .value = 6},
8675 static struct clk_mux_sel mux_plla_clk32_pllp_clkm_plle[] = {
8676 { .input = &tegra_pll_a_out0, .value = 0},
8677 { .input = &tegra_clk_32k, .value = 1},
8678 { .input = &tegra_pll_p, .value = 2},
8679 { .input = &tegra_clk_m, .value = 3},
8680 { .input = &tegra_pll_e_gate, .value = 4},
8684 static struct clk_mux_sel mux_clkm_pllp_pllre[] = {
8685 { .input = &tegra_clk_m, .value = 0},
8686 { .input = &tegra_pll_p_out_xusb, .value = 1},
8687 { .input = &tegra_pll_re_out, .value = 5},
8691 static struct clk_mux_sel mux_clkm_48M_pllp_480M[] = {
8692 { .input = &tegra_clk_m, .value = 0},
8693 { .input = &tegra_pll_u_48M, .value = 2},
8694 { .input = &tegra_pll_p_out_xusb, .value = 4},
8695 { .input = &tegra_pll_u_480M, .value = 6},
8699 static struct clk_mux_sel mux_clkm_pllre_clk32_480M[] = {
8700 { .input = &tegra_clk_m, .value = 0},
8701 { .input = &tegra_pll_re_out, .value = 1},
8702 { .input = &tegra_clk_32k, .value = 2},
8703 { .input = &tegra_pll_u_480M, .value = 3},
8707 static struct clk_mux_sel mux_pllp_out3_pllp_pllc_clkm[] = {
8708 { .input = &tegra_pll_p_out3, .value = 0},
8709 { .input = &tegra_pll_p, .value = 1},
8710 { .input = &tegra_pll_c, .value = 2},
8711 { .input = &tegra_clk_m, .value = 6},
8715 /* Single clock source ("fake") muxes */
8716 static struct clk_mux_sel mux_clk_m[] = {
8717 { .input = &tegra_clk_m, .value = 0},
8721 static struct clk_mux_sel mux_pllp_out3[] = {
8722 { .input = &tegra_pll_p_out3, .value = 0},
8726 static struct clk_mux_sel mux_clk_32k[] = {
8727 { .input = &tegra_clk_32k, .value = 0},
8731 static struct clk_mux_sel mux_clk_usb2_hsic_trk[] = {
8732 { .input = &tegra_clk_usb2_hsic_trk, .value = 0},
8736 static struct clk tegra_clk_mc;
8737 static struct clk_mux_sel mux_clk_mc[] = {
8738 { .input = &tegra_clk_mc, .value = 0},
8742 static struct raw_notifier_head emc_rate_change_nh;
8744 static struct clk tegra_clk_sata = {
8746 .clk_id = TEGRA210_CLK_ID_SATA,
8748 .dev_id = "tegra_sata",
8750 .ops = &tegra_periph_clk_ops,
8752 .max_rate = 102000000,
8756 .inputs = mux_pllp_pllc_clkm,
8757 .flags = MUX | DIV_U71 | PERIPH_ON_APB,
8760 static struct clk tegra_sata_aux_clk = {
8762 .clk_id = TEGRA210_CLK_ID_SATA_AUX,
8764 .dev_id = "tegra_sata_aux",
8766 .parent = &tegra_clk_sata,
8767 .ops = &tegra_cml_clk_ops,
8769 .max_rate = 102000000,
8775 static struct clk tegra_clk_emc = {
8777 .clk_id = TEGRA210_CLK_ID_EMC,
8779 .dev_id = "tegra_emc",
8782 .ops = &tegra_emc_clk_ops,
8784 .max_rate = 1800000000,
8785 .min_rate = 12750000,
8786 .inputs = mux_pllm_pllc_pllp_clkm,
8787 .flags = MUX | DIV_U71 | PERIPH_EMC_ENB,
8791 .rate_change_nh = &emc_rate_change_nh,
8794 static struct clk tegra_clk_mc = {
8796 .clk_id = TEGRA210_CLK_ID_MC,
8797 .ops = &tegra_mc_clk_ops,
8798 .max_rate = 1066000000,
8799 .parent = &tegra_clk_emc,
8800 .flags = PERIPH_NO_RESET,
8806 static struct raw_notifier_head host1x_rate_change_nh;
8808 static struct clk tegra_clk_host1x = {
8810 .clk_id = TEGRA210_CLK_ID_HOST1X,
8814 .ops = &tegra_1xbus_clk_ops,
8816 .inputs = mux_pllc4_out1_pllc_pllc4_out2_pllp_clkm_plla_pllc4_out0,
8817 .flags = MUX | DIV_U71 | DIV_U71_INT,
8818 .max_rate = 600000000,
8819 .min_rate = 12000000,
8822 .pll_low = &tegra_pll_p,
8823 .pll_high = &tegra_pll_p,
8825 .rate_change_nh = &host1x_rate_change_nh,
8828 static struct raw_notifier_head mselect_rate_change_nh;
8830 static struct clk tegra_clk_mselect = {
8832 .clk_id = TEGRA210_CLK_ID_MSELECT,
8834 .dev_id = "mselect",
8836 .ops = &tegra_1xbus_clk_ops,
8838 .inputs = mux_pllp_clkm,
8839 .flags = MUX | DIV_U71 | DIV_U71_INT,
8840 .max_rate = 408000000,
8841 .min_rate = 12000000,
8844 .pll_low = &tegra_pll_p,
8845 .pll_high = &tegra_pll_p,
8846 .threshold = 408000000,
8848 .rate_change_nh = &mselect_rate_change_nh,
8851 static struct raw_notifier_head ape_rate_change_nh;
8853 static struct clk tegra_clk_ape = {
8855 .clk_id = TEGRA210_CLK_ID_APE,
8856 .ops = &tegra_1xbus_clk_ops,
8858 .inputs = mux_plla_pllc4_out0_pllc_pllc4_out1_pllp_clkm_pllc4_out2,
8859 .flags = MUX | DIV_U71 | PERIPH_ON_APB,
8860 .shared_bus_flags = SHARED_BUS_RETENTION,
8861 .max_rate = 408000000,
8862 .min_rate = 12000000,
8865 .pll_low = &tegra_pll_p,
8866 .pll_high = &tegra_pll_p,
8867 .threshold = 408000000,
8869 .rate_change_nh = &ape_rate_change_nh,
8872 static struct raw_notifier_head c2bus_rate_change_nh;
8873 static struct raw_notifier_head c3bus_rate_change_nh;
8875 static struct clk tegra_clk_c2bus = {
8877 .clk_id = TEGRA210_CLK_ID_C2BUS,
8878 .parent = &tegra_pll_c2,
8879 .ops = &tegra_clk_cbus_ops,
8880 .max_rate = 1000000000,
8883 .flags = PERIPH_ON_CBUS,
8884 .shared_bus_backup = {
8885 .input = &tegra_pll_p,
8887 #ifdef CONFIG_TEGRA_CBUS_CAN_USE_SKIPPERS
8888 .shared_bus_flags = SHARED_BUS_USE_SKIPPERS,
8890 .rate_change_nh = &c2bus_rate_change_nh,
8892 static struct clk tegra_clk_c3bus = {
8894 .clk_id = TEGRA210_CLK_ID_C3BUS,
8895 .parent = &tegra_pll_c3,
8896 .ops = &tegra_clk_cbus_ops,
8897 .max_rate = 1000000000,
8900 .flags = PERIPH_ON_CBUS,
8901 .shared_bus_backup = {
8902 .input = &tegra_pll_p,
8904 #ifdef CONFIG_TEGRA_CBUS_CAN_USE_SKIPPERS
8905 .shared_bus_flags = SHARED_BUS_USE_SKIPPERS,
8907 .rate_change_nh = &c3bus_rate_change_nh,
8910 #ifdef CONFIG_TEGRA_MIGRATE_CBUS_USERS
8911 static DEFINE_MUTEX(cbus_mutex);
8912 #define CROSS_CBUS_MUTEX (&cbus_mutex)
8914 #define CROSS_CBUS_MUTEX NULL
8918 static struct clk_mux_sel mux_clk_cbus[] = {
8919 { .input = &tegra_clk_c2bus, .value = 0},
8920 { .input = &tegra_clk_c3bus, .value = 1},
8924 #define DUAL_CBUS_CLK(_name, _dev, _con, _parent, _id, _div, _mode, _clk_id)\
8927 .clk_id = _clk_id, \
8932 .ops = &tegra_clk_shared_bus_user_ops, \
8933 .parent = _parent, \
8934 .inputs = mux_clk_cbus, \
8936 .u.shared_bus_user = { \
8938 .client_div = _div, \
8941 .cross_clk_mutex = CROSS_CBUS_MUTEX, \
8944 static struct clk_ops tegra_clk_gpu_ops = {
8945 .enable = &tegra21_periph_clk_enable,
8946 .disable = &tegra21_periph_clk_disable,
8947 .reset = &tegra21_periph_clk_reset,
8951 * This clock provides a common gate control for branches of different clocks
8952 * supplied to GPU: mselect, memory controller, pll_p_out5, jtag and la. The
8953 * mselect and mc clocks are always running; pll_p_out5 is explicitly controlled
8954 * by GPU driver; jtag and la clocks are set by debug interface configuration.
8955 * Therefore we don't need to propagate refcount to those clocks, and just set
8956 * GPU gate clock as OSC child.
8958 static struct clk tegra_clk_gpu_gate = {
8960 .clk_id = TEGRA210_CLK_ID_GPU_GATE,
8961 .parent = &tegra_clk_osc,
8962 .ops = &tegra_clk_gpu_ops,
8966 .flags = PERIPH_MANUAL_RESET,
8967 .max_rate = 48000000,
8968 .min_rate = 12000000,
8972 * This is a reference clock for GPU. The enable/disable routine control input
8973 * clock of the GPCPLL. The reference clock itself has a fixed frequency. The
8974 * actual GPU clock's frequency is controlled via gbus, which is a child of this
8977 static struct clk tegra_clk_gpu_ref = {
8979 .clk_id = TEGRA210_CLK_ID_GPU_REF,
8980 .ops = &tegra_clk_gpu_ops,
8981 .parent = &tegra_pll_ref,
8985 .flags = PERIPH_NO_RESET,
8986 .max_rate = 48000000,
8987 .min_rate = 12000000,
8990 #define RATE_GRANULARITY 100000 /* 0.1 MHz */
8991 #if defined(CONFIG_TEGRA_CLOCK_DEBUG_FUNC)
8992 static int gbus_round_pass_thru;
8993 void tegra_gbus_round_pass_thru_enable(bool enable)
8996 gbus_round_pass_thru = 1;
8998 gbus_round_pass_thru = 0;
9000 int tegra_gbus_round_pass_thru_get(void)
9002 return gbus_round_pass_thru;
9004 EXPORT_SYMBOL(tegra_gbus_round_pass_thru_enable);
9005 EXPORT_SYMBOL(tegra_gbus_round_pass_thru_get);
9007 #define gbus_round_pass_thru 0
9010 static void tegra21_clk_gbus_init(struct clk *c)
9015 pr_debug("%s on clock %s (export ops %s)\n", __func__,
9016 c->name, c->u.export_clk.ops ? "ready" : "not ready");
9018 if (!c->u.export_clk.ops || !c->u.export_clk.ops->init)
9021 c->u.export_clk.ops->init(c->u.export_clk.ops->data, &rate, &enabled);
9022 c->div = clk_get_rate(c->parent) / RATE_GRANULARITY;
9023 c->mul = rate / RATE_GRANULARITY;
9024 c->state = enabled ? ON : OFF;
9027 static int tegra21_clk_gbus_enable(struct clk *c)
9029 pr_debug("%s on clock %s (export ops %s)\n", __func__,
9030 c->name, c->u.export_clk.ops ? "ready" : "not ready");
9032 if (!c->u.export_clk.ops || !c->u.export_clk.ops->enable)
9035 return c->u.export_clk.ops->enable(c->u.export_clk.ops->data);
9038 static void tegra21_clk_gbus_disable(struct clk *c)
9040 pr_debug("%s on clock %s (export ops %s)\n", __func__,
9041 c->name, c->u.export_clk.ops ? "ready" : "not ready");
9043 if (!c->u.export_clk.ops || !c->u.export_clk.ops->disable)
9046 c->u.export_clk.ops->disable(c->u.export_clk.ops->data);
9049 static int tegra21_clk_gbus_set_rate(struct clk *c, unsigned long rate)
9053 pr_debug("%s %lu on clock %s (export ops %s)\n", __func__,
9054 rate, c->name, c->u.export_clk.ops ? "ready" : "not ready");
9056 if (!c->u.export_clk.ops || !c->u.export_clk.ops->set_rate)
9059 ret = c->u.export_clk.ops->set_rate(c->u.export_clk.ops->data, &rate);
9061 c->mul = rate / RATE_GRANULARITY;
9065 static long tegra21_clk_gbus_round_updown(struct clk *c, unsigned long rate,
9068 return gbus_round_pass_thru ? rate :
9069 tegra21_clk_cbus_round_updown(c, rate, up);
9072 static long tegra21_clk_gbus_round_rate(struct clk *c, unsigned long rate)
9074 return tegra21_clk_gbus_round_updown(c, rate, true);
9077 static struct clk_ops tegra_clk_gbus_ops = {
9078 .init = tegra21_clk_gbus_init,
9079 .enable = tegra21_clk_gbus_enable,
9080 .disable = tegra21_clk_gbus_disable,
9081 .set_rate = tegra21_clk_gbus_set_rate,
9082 .round_rate = tegra21_clk_gbus_round_rate,
9083 .round_rate_updown = tegra21_clk_gbus_round_updown,
9084 .shared_bus_update = tegra21_clk_shared_connector_update, /* re-use */
9087 static struct raw_notifier_head gbus_rate_change_nh;
9088 static wait_queue_head_t gbus_poll_rate;
9089 static struct bus_stats gpu_histogram;
9091 static struct clk tegra_clk_gbus = {
9093 .clk_id = TEGRA210_CLK_ID_GBUS,
9094 .ops = &tegra_clk_gbus_ops,
9095 .parent = &tegra_clk_gpu_ref,
9096 .max_rate = 1300000000,
9097 .shared_bus_flags = SHARED_BUS_RETENTION,
9099 .histogram = &gpu_histogram,
9101 .rate_change_nh = &gbus_rate_change_nh,
9102 .debug_poll_qh = &gbus_poll_rate,
9105 static void tegra21_camera_mclk_init(struct clk *c)
9110 if (!strcmp(c->name, "mclk")) {
9111 c->parent = tegra_get_clock_by_name("vi_sensor");
9112 c->max_rate = c->parent->max_rate;
9113 } else if (!strcmp(c->name, "mclk2")) {
9114 c->parent = tegra_get_clock_by_name("vi_sensor2");
9115 c->max_rate = c->parent->max_rate;
9116 } else if (!strcmp(c->name, "mclk3")) {
9117 c->parent = tegra_get_clock_by_name("extern3");
9118 c->max_rate = c->parent->max_rate;
9119 } else if (!strcmp(c->name, "cam-mipi-cal")) {
9120 c->parent = tegra_get_clock_by_name("uart_mipi_cal");
9121 c->max_rate = c->parent->max_rate;
9125 static int tegra21_camera_mclk_set_rate(struct clk *c, unsigned long rate)
9127 return clk_set_rate(c->parent, rate);
9130 static struct clk_ops tegra_camera_mclk_ops = {
9131 .init = tegra21_camera_mclk_init,
9132 .enable = tegra21_periph_clk_enable,
9133 .disable = tegra21_periph_clk_disable,
9134 .set_rate = tegra21_camera_mclk_set_rate,
9137 static struct clk tegra_camera_mclk = {
9139 .clk_id = TEGRA210_CLK_ID_MCLK,
9140 .ops = &tegra_camera_mclk_ops,
9142 .clk_num = 92, /* csus */
9144 .flags = PERIPH_NO_RESET,
9147 static struct clk tegra_camera_mclk2 = {
9149 .clk_id = TEGRA210_CLK_ID_MCLK2,
9150 .ops = &tegra_camera_mclk_ops,
9152 .clk_num = 171, /* vim2_clk */
9154 .flags = PERIPH_NO_RESET,
9157 static struct clk tegra_camera_mipical = {
9158 .name = "cam-mipi-cal",
9159 .clk_id = TEGRA210_CLK_ID_CAM_MIPI_CAL,
9160 .ops = &tegra_camera_mclk_ops,
9162 .clk_num = 56, /* mipi_cal */
9164 .flags = PERIPH_NO_RESET,
9167 static struct clk_ops tegra_camera_mclk3_ops = {
9168 .init = &tegra21_camera_mclk_init,
9169 .enable = &tegra21_clk_out_enable,
9170 .disable = &tegra21_clk_out_disable,
9171 .set_rate = &tegra21_camera_mclk_set_rate,
9174 static struct clk tegra_camera_mclk3 = {
9176 .clk_id = TEGRA210_CLK_ID_MCLK3,
9177 .ops = &tegra_camera_mclk3_ops,
9179 .flags = MUX_CLK_OUT,
9181 .clk_num = (3 - 1) * 8 + 2,
9185 static struct clk tegra_clk_isp = {
9187 .clk_id = TEGRA210_CLK_ID_ISP,
9188 .ops = &tegra_periph_clk_ops,
9190 .max_rate = 1000000000,
9191 .inputs = mux_pllc_pllp_plla1_pllc2_c3_clkm_pllc4,
9192 .flags = MUX | DIV_U71 | DIV_U71_INT | PERIPH_NO_ENB | PERIPH_NO_RESET,
9195 static struct clk_mux_sel mux_isp[] = {
9196 { .input = &tegra_clk_isp, .value = 0},
9200 static struct clk tegra_clk_hda2codec_2x = {
9201 .name = "hda2codec_2x",
9202 .clk_id = TEGRA210_CLK_ID_HDA2CODEC_2X,
9204 .dev_id = "tegra30-hda",
9205 .con_id = "hda2codec",
9207 .ops = &tegra_periph_clk_ops,
9212 .max_rate = 48000000,
9213 .inputs = mux_pllp_pllc_plla_clkm,
9214 .flags = MUX | DIV_U71 | PERIPH_ON_APB,
9217 static struct clk_mux_sel mux_hda2codec_2x[] = {
9218 { .input = &tegra_clk_hda2codec_2x, .value = 0},
9222 static struct raw_notifier_head cbus_rate_change_nh;
9224 static struct clk tegra_clk_cbus = {
9226 .clk_id = TEGRA210_CLK_ID_CBUS,
9227 .parent = &tegra_pll_c,
9228 .ops = &tegra_clk_cbus_ops,
9229 .max_rate = 1000000000,
9232 .flags = PERIPH_ON_CBUS,
9233 .shared_bus_backup = {
9234 .input = &tegra_pll_p,
9236 .rate_change_nh = &cbus_rate_change_nh,
9239 #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags, \
9243 .clk_id = _clk_id, \
9248 .ops = &tegra_periph_clk_ops, \
9250 .inputs = _inputs, \
9254 .clk_num = _clk_num, \
9258 #define PERIPH_CLK_EX(_name, _dev, _con, _clk_num, _reg, _max, _inputs, \
9259 _flags, _clk_id, _ops) \
9262 .clk_id = _clk_id, \
9269 .inputs = _inputs, \
9273 .clk_num = _clk_num, \
9277 #define SUPER_SKIP_CLK(_name, _dev, _con, _reg, _parent, _flags) \
9284 .ops = &tegra_clk_super_skip_ops, \
9286 .parent = _parent, \
9290 #define PERIPH_CLK_SKIP(_name, _dev, _con, _clk_num, _reg, _reg_skip, _max, \
9291 _inputs, _flags, _clk_id) \
9292 PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags, \
9294 SUPER_SKIP_CLK(_name "_skip", _dev, "skip", _reg_skip, NULL, 0)
9296 #define D_AUDIO_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags, _clk_id) \
9299 .clk_id = _clk_id, \
9304 .ops = &tegra_periph_clk_ops, \
9306 .inputs = _inputs, \
9310 .clk_num = _clk_num, \
9311 .src_mask = 0xE01F << 16, \
9316 #define SHARED_CLK(_name, _dev, _con, _parent, _id, _div, _mode, _clk_id)\
9319 .clk_id = _clk_id, \
9324 .ops = &tegra_clk_shared_bus_user_ops, \
9325 .parent = _parent, \
9326 .u.shared_bus_user = { \
9328 .client_div = _div, \
9332 #define SHARED_LIMIT(_name, _dev, _con, _parent, _id, _div, _mode, _clk_id)\
9335 .clk_id = _clk_id, \
9340 .ops = &tegra_clk_shared_bus_user_ops, \
9341 .parent = _parent, \
9342 .flags = BUS_RATE_LIMIT, \
9343 .u.shared_bus_user = { \
9345 .client_div = _div, \
9349 #define SHARED_CONNECT(_name, _dev, _con, _parent, _id, _div, _mode, _clk_id)\
9352 .clk_id = _clk_id, \
9357 .ops = &tegra_clk_shared_connector_ops, \
9358 .parent = _parent, \
9359 .u.shared_bus_user = { \
9361 .client_div = _div, \
9365 #define SHARED_EMC_CLK(_name, _dev, _con, _parent, _id, _div, _mode, _flag, _clk_id)\
9368 .clk_id = _clk_id, \
9373 .ops = &tegra_clk_shared_bus_user_ops, \
9374 .parent = _parent, \
9375 .u.shared_bus_user = { \
9377 .client_div = _div, \
9379 .usage_flag = _flag, \
9383 static DEFINE_MUTEX(sbus_cross_mutex);
9384 #define SHARED_SCLK(_name, _dev, _con, _parent, _id, _div, _mode, _clk_id)\
9387 .clk_id = _clk_id, \
9392 .ops = &tegra_clk_shared_bus_user_ops, \
9393 .parent = _parent, \
9394 .u.shared_bus_user = { \
9396 .client_div = _div, \
9399 .cross_clk_mutex = &sbus_cross_mutex, \
9402 static struct clk tegra_list_clks[] = {
9403 PERIPH_CLK("ahbdma", "ahbdma", NULL, 33, 0, 38400000, mux_clk_m, 0, TEGRA210_CLK_ID_AHBDMA),
9404 PERIPH_CLK("apbdma", "tegra-apbdma", NULL, 34, 0, 38400000, mux_clk_m, 0, TEGRA210_CLK_ID_APBDMA),
9405 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_RTC),
9406 PERIPH_CLK("timer", "timer", NULL, 5, 0, 38400000, mux_clk_m, 0, TEGRA210_CLK_ID_TIMER),
9407 PERIPH_CLK("spare1", "spare1", NULL, 192, 0, 38400000, mux_clk_m, 0, TEGRA210_CLK_ID_SPARE1),
9408 PERIPH_CLK("axiap", "axiap", NULL, 196, 0, 38400000, mux_clk_m, 0, TEGRA210_CLK_ID_AXIAP),
9409 PERIPH_CLK("iqc1", "tegra210-iqc.0", NULL, 221, 0, 38400000, mux_clk_m, PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_IQC1),
9410 PERIPH_CLK("iqc2", "tegra210-iqc.1", NULL, 220, 0, 38400000, mux_clk_m, PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_IQC2),
9411 PERIPH_CLK("kfuse", "kfuse-tegra", NULL, 40, 0, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_KFUSE),
9412 PERIPH_CLK("fuse", "fuse-tegra", "fuse", 39, 0, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_FUSE),
9413 PERIPH_CLK("fuse_burn", "fuse-tegra", "fuse_burn", 39, 0, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_FUSE_BURN),
9415 PERIPH_CLK("i2s0", "tegra210-i2s.0", NULL, 30, 0x1d8, 24576000, mux_pllaout0_audio0_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_I2S0),
9416 PERIPH_CLK("i2s1", "tegra210-i2s.1", NULL, 11, 0x100, 24576000, mux_pllaout0_audio1_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_I2S1),
9417 PERIPH_CLK("i2s2", "tegra210-i2s.2", NULL, 18, 0x104, 24576000, mux_pllaout0_audio2_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_I2S2),
9418 PERIPH_CLK("i2s3", "tegra210-i2s.3", NULL, 101, 0x3bc, 24576000, mux_pllaout0_audio3_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_I2S3),
9419 PERIPH_CLK("i2s4", "tegra210-i2s.4", NULL, 102, 0x3c0, 24576000, mux_pllaout0_audio4_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_I2S4),
9420 PERIPH_CLK("spdif_out", "tegra210-spdif", "spdif_out", 10, 0x108, 24727300, mux_pllaout0_audio_2x_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_SPDIF_OUT),
9421 PERIPH_CLK("spdif_in", "tegra210-spdif", "spdif_in", 10, 0x10c, 408000000, mux_pllp_pllc_clkm_1, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_SPDIF_IN),
9422 PERIPH_CLK("dmic1", "tegra210-dmic.0", NULL, 161, 0x64c, 12288000, mux_pllaout0_audio0_dmic_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_DMIC1),
9423 PERIPH_CLK("dmic2", "tegra210-dmic.1", NULL, 162, 0x650, 12288000, mux_pllaout0_audio1_dmic_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_DMIC2),
9424 PERIPH_CLK("dmic3", "tegra210-dmic.2", NULL, 197, 0x6bc, 12288000, mux_pllaout0_audio2_dmic_pllp_clkm, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_DMIC3),
9425 PERIPH_CLK("apb2ape", NULL, "apb2ape", 107, 0, 38400000, mux_clk_m, PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_APB2APE),
9426 PERIPH_CLK("maud", "maud", NULL, 202, 0x6d4, 102000000, mux_pllp_pllp_out3_clkm_clk32k_plla, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_MAUD),
9427 PERIPH_CLK("pwm", "7000a000.pwm", NULL, 17, 0x110, 48000000, mux_pllp_pllc_clk32_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_PWM),
9428 D_AUDIO_CLK("d_audio", "tegra210-axbar", "ahub", 106, 0x3d0, 98304000, mux_d_audio_clk, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_AHUB),
9429 PERIPH_CLK("hda", "tegra30-hda", "hda", 125, 0x428, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_HDA),
9430 PERIPH_CLK("hda2hdmi", "tegra30-hda", "hda2hdmi", 128, 0, 48000000, mux_hda2codec_2x, PERIPH_ON_APB, TEGRA210_CLK_ID_HDA2HDMI),
9432 PERIPH_CLK_EX("qspi", "qspi", NULL, 211, 0x6c4, 133000000, mux_pllp_pllc_pllc_out1_pllc4_out2_pllc4_out1_clkm_pllc4_out0, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_QSPI, &tegra_qspi_clk_ops),
9433 PERIPH_CLK("sbc1", "7000d400.spi", NULL, 41, 0x134, 65000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SBC1),
9434 PERIPH_CLK("sbc2", "7000d600.spi", NULL, 44, 0x118, 65000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SBC2),
9435 PERIPH_CLK("sbc3", "7000d800.spi", NULL, 46, 0x11c, 65000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SBC3),
9436 PERIPH_CLK("sbc4", "7000da00.spi", NULL, 68, 0x1b4, 65000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SBC4),
9437 PERIPH_CLK("sata_oob", "tegra_sata_oob", NULL, 123, 0x420, 204000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_SATA_OOB),
9438 PERIPH_CLK("sata_cold", "tegra_sata_cold", NULL, 129, 0, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_SATA_COLD),
9439 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 204000000, mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC1),
9440 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 204000000, mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC3),
9441 PERIPH_CLK("sdmmc1_ddr", "sdhci-tegra.0", "ddr", 14, 0x150, 96000000, mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC1_DDR),
9442 PERIPH_CLK("sdmmc3_ddr", "sdhci-tegra.2", "ddr", 69, 0x1bc, 96000000, mux_pllp_pllc4_out2_pllc4_out1_clkm_pllc4_out0, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC3_DDR),
9443 PERIPH_CLK_EX("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 266000000, mux_pllp_clk_m_pllc4_out2_out1_out0_lj, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC2, &tegra_sdmmc24_clk_ops),
9444 PERIPH_CLK_EX("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 266000000, mux_pllp_clk_m_pllc4_out2_out1_out0_lj, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC4, &tegra_sdmmc24_clk_ops),
9445 PERIPH_CLK_EX("sdmmc2_ddr", "sdhci-tegra.1", "ddr", 9, 0x154, 102000000, mux_pllp_clk_m_pllc4_out2_out1_out0_lj, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC2_DDR, &tegra_sdmmc24_clk_ops),
9446 PERIPH_CLK_EX("sdmmc4_ddr", "sdhci-tegra.3", "ddr", 15, 0x164, 102000000, mux_pllp_clk_m_pllc4_out2_out1_out0_lj, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC4_DDR, &tegra_sdmmc24_clk_ops),
9447 PERIPH_CLK("sdmmc_legacy", "sdmmc_legacy", NULL, 193, 0x694, 208000000, mux_pllp_out3_clkm_pllp_pllc4, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_SDMMC_LEGACY),
9449 PERIPH_CLK("vcp", "nvavp", "vcp", 29, 0, 250000000, mux_clk_m, 0, TEGRA210_CLK_ID_VCP),
9450 PERIPH_CLK("bsev", "tegra-aes", "bsev", 63, 0, 250000000, mux_clk_m, 0, TEGRA210_CLK_ID_BSEV),
9451 PERIPH_CLK("cec", "tegra_cec", NULL, 136, 0, 250000000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_CEC),
9452 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 624000000, mux_pllp_pllre_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_CSITE),
9453 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 408000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_LA),
9455 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 38400000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_OWR),
9456 PERIPH_CLK("i2c1", "7000c000.i2c", "div-clk", 12, 0x124, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C1),
9457 PERIPH_CLK("i2c2", "7000c400.i2c", "div-clk", 54, 0x198, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C2),
9458 PERIPH_CLK("i2c3", "7000c500.i2c", "div-clk", 67, 0x1b8, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C3),
9459 PERIPH_CLK("i2c4", "7000c700.i2c", "div-clk", 103, 0x3c4, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C4),
9460 PERIPH_CLK("i2c5", "7000d000.i2c", "div-clk", 47, 0x128, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C5),
9461 PERIPH_CLK("i2c6", "7000d100.i2c", "div-clk", 166, 0x65c, 136000000, mux_pllp_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2C6),
9462 PERIPH_CLK("vii2c", "546c0000.i2c", "vii2c", 208, 0x6c8, 136000000, mux_pllp_pllc_clkm, MUX | DIV_U16 | PERIPH_ON_APB, TEGRA210_CLK_ID_VII2C),
9463 PERIPH_CLK("i2cslow", "546c0000.i2c", "i2cslow", 81, 0x3fc, 50000000, mux_pllp_pllc_clk32_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_I2CSLOW),
9464 PERIPH_CLK("mipibif", "mipibif", NULL, 173, 0x660, 408000000, mux_pllp_clkm, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_MIPIIF),
9465 PERIPH_CLK("mipi-cal", "mipi-cal", NULL, 56, 0, 102000000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_MIPI_CAL),
9466 PERIPH_CLK("uarta", "70006000.serial", NULL, 6, 0x178, 1190400000, mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, MUX | DIV_U151 | DIV_U151_UART | PERIPH_ON_APB, TEGRA210_CLK_ID_UARTA),
9467 PERIPH_CLK("uartb", "70006040.serial", NULL, 7, 0x17c, 1190400000, mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, MUX | DIV_U151 | DIV_U151_UART | PERIPH_ON_APB, TEGRA210_CLK_ID_UARTB),
9468 PERIPH_CLK("uartc", "70006200.serial", NULL, 55, 0x1a0, 1190400000, mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, MUX | DIV_U151 | DIV_U151_UART | PERIPH_ON_APB, TEGRA210_CLK_ID_UARTC),
9469 PERIPH_CLK("uartd", "70006300.serial", NULL, 65, 0x1c0, 1190400000, mux_pllp_pllc_pllc4_out0_pllc4_out1_clkm_pllc4_out2, MUX | DIV_U151 | DIV_U151_UART | PERIPH_ON_APB, TEGRA210_CLK_ID_UARTD),
9470 PERIPH_CLK("uartape", "uartape", NULL, 212, 0x710, 204000000, mux_pllp_pllc_clkm, MUX | DIV_U151 | DIV_U151_UART | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_UARTAPE),
9472 PERIPH_CLK("vi_sensor", NULL, "vi_sensor", 164, 0x1a8, 408000000, mux_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_VI_SENSOR),
9473 PERIPH_CLK("vi_sensor2", NULL, "vi_sensor2", 165, 0x658, 408000000, mux_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_VI_SENSOR2),
9474 PERIPH_CLK_EX("dtv", "dtv", NULL, 79, 0x1dc, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_DTV, &tegra_dtv_clk_ops),
9475 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 1500000000, mux_pllp_plld_plld2_clkm, MUX, TEGRA210_CLK_ID_DISP1),
9476 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 1500000000, mux_pllp_plld_plld2_clkm, MUX, TEGRA210_CLK_ID_DISP2),
9477 PERIPH_CLK_EX("sor0", NULL, "sor0", 182, 0x414, 600000000, mux_pllp_sor_sor0_brick, MUX, TEGRA210_CLK_ID_SOR0, &tegra_sor0_clk_ops),
9478 PERIPH_CLK_EX("sor1", NULL, "sor1", 183, 0x410, 600000000, mux_pllp_sor_sor1_brick_sor1_src, MUX, TEGRA210_CLK_ID_SOR1, &tegra_sor1_clk_ops),
9479 PERIPH_CLK_EX("dpaux", "dpaux", NULL, 181, 0, 24000000, mux_pllp, 0, TEGRA210_CLK_ID_DPAUX, &tegra_dpaux_clk_ops),
9480 PERIPH_CLK_EX("dpaux1", "dpaux1", NULL, 207, 0, 24000000, mux_pllp, 0, TEGRA210_CLK_ID_DPAUX1, &tegra_dpaux_clk_ops),
9482 PERIPH_CLK("usbd", "tegra-udc.0", NULL, 22, 0, 480000000, mux_clk_m, 0, TEGRA210_CLK_ID_USBD),
9483 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0, TEGRA210_CLK_ID_USB2),
9484 PERIPH_CLK("hsic_trk", NULL, "hsic_trk", 209, 0, 38400000, mux_clk_usb2_hsic_trk, PERIPH_NO_RESET, TEGRA210_CLK_ID_HSIC_TRK),
9485 PERIPH_CLK("usb2_trk", NULL, "usb2_trk", 210, 0, 38400000, mux_clk_usb2_hsic_trk, PERIPH_NO_RESET, TEGRA210_CLK_ID_USB2_TRK),
9487 PERIPH_CLK("dsia", "tegradc.0", "dsia", 48, 0xd0, 750000000, mux_plld_out0, PLLD, TEGRA210_CLK_ID_DSIA),
9488 PERIPH_CLK("dsib", "tegradc.1", "dsib", 82, 0x4b8, 750000000, mux_plld_out0, PLLD, TEGRA210_CLK_ID_DSIB),
9489 PERIPH_CLK("dsi1-fixed", "tegradc.0", "dsi-fixed", 0, 0, 108000000, mux_pllp_out3, PERIPH_NO_ENB | PERIPH_NO_RESET, TEGRA210_CLK_ID_DSI1_FIXED),
9490 PERIPH_CLK("dsi2-fixed", "tegradc.1", "dsi-fixed", 0, 0, 108000000, mux_pllp_out3, PERIPH_NO_ENB | PERIPH_NO_RESET, TEGRA210_CLK_ID_DSI2_FIXED),
9491 PERIPH_CLK("csi", "vi", "csi", 52, 0, 750000000, mux_plld_out0, PLLD, TEGRA210_CLK_ID_CSI),
9492 PERIPH_CLK("csus", "vi", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET, TEGRA210_CLK_ID_CSUS),
9493 PERIPH_CLK("vim2_clk", "vi", "vim2_clk", 171, 0, 150000000, mux_clk_m, PERIPH_NO_RESET, TEGRA210_CLK_ID_VIM2_CLK),
9494 PERIPH_CLK("cilab", "vi", "cilab", 144, 0x614, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_CILAB),
9495 PERIPH_CLK("cilcd", "vi", "cilcd", 145, 0x618, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_CILCD),
9496 PERIPH_CLK("cile", "vi", "cile", 146, 0x61c, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_CILE),
9497 PERIPH_CLK("dsialp", "tegradc.0", "dsialp", 147, 0x620, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_DSIALP),
9498 PERIPH_CLK("dsiblp", "tegradc.1", "dsiblp", 148, 0x624, 102000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_DSIBLP),
9500 PERIPH_CLK("entropy", "entropy", NULL, 149, 0x628, 102000000, mux_pllp_clkm_clk32_plle, MUX | DIV_U71, TEGRA210_CLK_ID_ENTROPY),
9501 PERIPH_CLK("uart_mipi_cal", "uart_mipi_cal", NULL, 177, 0x66c, 102000000, mux_pllp_out3_pllp_pllc_clkm, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_UART_MIPI_CAL),
9502 PERIPH_CLK("dbgapb", "dbgapb", NULL, 185, 0x718, 136000000, mux_pllp_clkm_2, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_DBGAPB),
9503 PERIPH_CLK("tsensor", "tegra-tsensor", NULL, 100, 0x3b8, 19200000, mux_pllp_pllc_clkm_clk32, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_TSENSOR),
9504 PERIPH_CLK("actmon", "actmon", NULL, 119, 0x3e8, 204000000, mux_pllp_pllc_clk32_clkm, MUX | DIV_U71, TEGRA210_CLK_ID_ACTMON),
9505 PERIPH_CLK("extern1", "extern1", NULL, 120, 0x3ec, 408000000, mux_plla_clk32_pllp_clkm_plle, MUX | DIV_U71, TEGRA210_CLK_ID_EXTERN1),
9506 PERIPH_CLK("extern2", "extern2", NULL, 121, 0x3f0, 408000000, mux_plla_clk32_pllp_clkm_plle, MUX | DIV_U71, TEGRA210_CLK_ID_EXTERN2),
9507 PERIPH_CLK("extern3", "extern3", NULL, 122, 0x3f4, 408000000, mux_plla_clk32_pllp_clkm_plle, MUX | DIV_U71, TEGRA210_CLK_ID_EXTERN3),
9508 PERIPH_CLK("pcie", "tegra-pcie", "pcie", 70, 0, 250000000, mux_clk_m, 0, TEGRA210_CLK_ID_PCIE),
9509 PERIPH_CLK("afi", "tegra-pcie", "afi", 72, 0, 250000000, mux_clk_m, 0, TEGRA210_CLK_ID_AFI),
9510 PERIPH_CLK("cl_dvfs_ref", "tegra_cl_dvfs", "ref", 155, 0x62c, 54000000, mux_pllp_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_DFLL_REF),
9511 PERIPH_CLK("cl_dvfs_soc", "tegra_cl_dvfs", "soc", 155, 0x630, 54000000, mux_pllp_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_DFLL_SOC),
9512 PERIPH_CLK("soc_therm", "soc_therm", NULL, 78, 0x644, 136000000, mux_clkm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_SOC_THERM),
9514 PERIPH_CLK("dp2", "dp2", NULL, 152, 0, 38400000, mux_clk_m, PERIPH_ON_APB, TEGRA210_CLK_ID_DP2),
9515 PERIPH_CLK("mc_bbc", "mc_bbc", NULL, 170, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_BBC),
9516 PERIPH_CLK("mc_capa", "mc_capa", NULL, 167, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_CAPA),
9517 PERIPH_CLK("mc_cbpa", "mc_cbpa", NULL, 168, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_CBPA),
9518 PERIPH_CLK("mc_cpu", "mc_cpu", NULL, 169, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_CPU),
9519 PERIPH_CLK("mc_ccpa", "mc_ccpa", NULL, 201, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_CCPA),
9520 PERIPH_CLK("mc_cdpa", "mc_cdpa", NULL, 200, 0, 1066000000, mux_clk_mc, PERIPH_NO_RESET, TEGRA210_CLK_ID_MC_CDPA),
9522 PERIPH_CLK_SKIP("vic03", "vic03", NULL, 178, 0x678, 0x6f0, 1000000000, mux_pllc_pllp_plla1_pllc2_c3_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_VIC),
9523 PERIPH_CLK_SKIP("msenc", "msenc", NULL, 219, 0x6a0, 0x6e8, 1000000000, mux_pllc2_c_c3_pllp_plla1_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_NVENC),
9524 PERIPH_CLK_SKIP("nvdec", "nvdec", NULL, 194, 0x698, 0x6f4, 1000000000, mux_pllc2_c_c3_pllp_plla1_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_NVDEC),
9525 PERIPH_CLK_SKIP("nvjpg", "nvjpg", NULL, 195, 0x69c, 0x700, 1000000000, mux_pllc2_c_c3_pllp_plla1_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_NVJPG),
9526 PERIPH_CLK_SKIP("se", "se", NULL, 127, 0x42c, 0x704, 1000000000, mux_pllp_pllc2_c_c3_clkm, MUX | DIV_U71 | DIV_U71_INT | PERIPH_ON_APB, TEGRA210_CLK_ID_SE),
9527 PERIPH_CLK_SKIP("tsec", "tegra_tsec", "tsec", 83, 0x1f4, 0x708, 408000000, mux_pllp_pllc_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_TSEC),
9528 PERIPH_CLK_SKIP("tsecb", "tsecb", NULL, 206, 0x6d8, 0x70c, 1000000000, mux_pllp_pllc2_c_c3_clkm, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_TSECB),
9529 PERIPH_CLK_SKIP("ispa", "isp", "ispa", 23, 0, 0x6f8, 1000000000, mux_isp, PERIPH_ON_APB, TEGRA210_CLK_ID_ISPA),
9530 PERIPH_CLK_SKIP("ispb", "isp", "ispb", 3, 0, 0x6fc, 1000000000, mux_isp, PERIPH_ON_APB, TEGRA210_CLK_ID_ISPB),
9531 PERIPH_CLK_EX("vi", "vi", "vi", 20, 0x148, 1000000000, mux_pllc2_c_c3_pllp_clkm_plla1_pllc4, MUX | DIV_U71 | DIV_U71_INT, TEGRA210_CLK_ID_VI, &tegra_vi_clk_ops),
9532 SUPER_SKIP_CLK("vi_skip", "vi", "skip", 0x6ec, NULL, 0),
9534 SHARED_SCLK("avp.sclk", "nvavp", "sclk", &tegra_clk_sbus_cmplx, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_AVP_USER),
9535 SHARED_SCLK("usbd.sclk", "tegra-udc.0", "sclk", &tegra_clk_ahb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_USBD_USER),
9536 SHARED_SCLK("usb1.sclk", "tegra-ehci.0", "sclk", &tegra_clk_ahb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_USBD1_USER),
9537 SHARED_SCLK("usb2.sclk", "tegra-ehci.1", "sclk", &tegra_clk_ahb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_USBD2_USER),
9538 SHARED_SCLK("sdmmc4.sclk", "sdhci-tegra.3", "sclk", &tegra_clk_ahb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_SDMMC4_USER),
9539 SHARED_SCLK("wake.sclk", "wake_sclk", "sclk", &tegra_clk_sbus_cmplx, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_WAKE_USER),
9540 SHARED_SCLK("camera.sclk", "vi", "sclk", &tegra_clk_sbus_cmplx, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_CAMERA_USER),
9541 SHARED_SCLK("mon.avp", "tegra_actmon", "avp", &tegra_clk_sbus_cmplx, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_MON_AVP_USER),
9542 SHARED_SCLK("cap.sclk", "cap_sclk", NULL, &tegra_clk_sbus_cmplx, NULL, 0, SHARED_CEILING, 0),
9543 SHARED_SCLK("cap.vcore.sclk", "cap.vcore.sclk", NULL, &tegra_clk_sbus_cmplx, NULL, 0, SHARED_CEILING, 0),
9544 SHARED_SCLK("cap.throttle.sclk", "cap_throttle", NULL, &tegra_clk_sbus_cmplx, NULL, 0, SHARED_CEILING, 0),
9545 SHARED_SCLK("floor.sclk", "floor_sclk", NULL, &tegra_clk_sbus_cmplx, NULL, 0, 0, 0),
9546 SHARED_SCLK("override.sclk", "override_sclk", NULL, &tegra_clk_sbus_cmplx, NULL, 0, SHARED_OVERRIDE, 0),
9547 SHARED_SCLK("sbc1.sclk", "7000d400.spi", "sclk", &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_SBC1_USER),
9548 SHARED_SCLK("sbc2.sclk", "7000d600.spi", "sclk", &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_SBC2_USER),
9549 SHARED_SCLK("sbc3.sclk", "7000d800.spi", "sclk", &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_SBC3_USER),
9550 SHARED_SCLK("sbc4.sclk", "7000da00.spi", "sclk", &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_SBC4_USER),
9551 SHARED_SCLK("qspi.sclk", "qspi", "sclk", &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_QSPI_USER),
9552 SHARED_SCLK("boot.apb.sclk", "boot.apb.sclk", NULL, &tegra_clk_apb, NULL, 0, 0, TEGRA210_CLK_ID_SBUS_BOOT_APB_USER),
9554 SHARED_EMC_CLK("avp.emc", "nvavp", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_AVP_USER),
9555 SHARED_EMC_CLK("cpu.emc", "tegra-cpu", "cpu_emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_CPU_USER),
9556 SHARED_EMC_CLK("disp1.emc", "tegradc.0", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_DC1), TEGRA210_CLK_ID_EMC_DISP1_USER),
9557 SHARED_EMC_CLK("disp2.emc", "tegradc.1", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_DC2), TEGRA210_CLK_ID_EMC_DISP2_USER),
9558 SHARED_EMC_CLK("disp1.la.emc", "tegradc.0", "emc.la", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_DISP1_LA_USER),
9559 SHARED_EMC_CLK("disp2.la.emc", "tegradc.1", "emc.la", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_DISP2_LA_USER),
9560 SHARED_EMC_CLK("usbd.emc", "tegra-udc.0", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_USBD_USER),
9561 SHARED_EMC_CLK("usb1.emc", "tegra-ehci.0", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_USB1_USER),
9562 SHARED_EMC_CLK("usb2.emc", "tegra-ehci.1", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_USB2_USER),
9563 SHARED_EMC_CLK("sdmmc3.emc", "sdhci-tegra.2", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_SDMMC3_USER),
9564 SHARED_EMC_CLK("sdmmc4.emc", "sdhci-tegra.3", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_SDMMC4_USER),
9565 SHARED_EMC_CLK("mon.emc", "tegra_actmon", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_MON_USER),
9566 SHARED_EMC_CLK("cap.emc", "cap.emc", NULL, &tegra_clk_emc, NULL, 0, SHARED_CEILING, 0, 0),
9567 SHARED_EMC_CLK("cap.vcore.emc", "cap.vcore.emc", NULL, &tegra_clk_emc, NULL, 0, SHARED_CEILING, 0, 0),
9568 SHARED_EMC_CLK("cap.throttle.emc", "cap_throttle", NULL, &tegra_clk_emc, NULL, 0, SHARED_CEILING_BUT_ISO, 0, 0),
9569 SHARED_EMC_CLK("3d.emc", "tegra_gpu.0", "emc", &tegra_clk_emc, NULL, 0, 0, BIT(EMC_USER_3D), TEGRA210_CLK_ID_EMC_3D_USER),
9570 SHARED_EMC_CLK("msenc.emc", "tegra_msenc", "emc", &tegra_clk_emc, NULL, 0, SHARED_BW, BIT(EMC_USER_MSENC), TEGRA210_CLK_ID_EMC_NVENC_USER),
9571 SHARED_EMC_CLK("nvjpg.emc", "tegra_nvjpg", "emc", &tegra_clk_emc, NULL, 0, SHARED_BW, BIT(EMC_USER_NVJPG), TEGRA210_CLK_ID_EMC_NVJPG_USER),
9572 SHARED_EMC_CLK("nvdec.emc", "tegra_nvdec", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_NVDEC_USER),
9573 SHARED_EMC_CLK("tsec.emc", "tegra_tsec", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_TSEC_USER),
9574 SHARED_EMC_CLK("tsecb.emc", "tegra_tsecb", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_TSECB_USER),
9575 #ifdef CONFIG_VI_ONE_DEVICE
9576 SHARED_EMC_CLK("vi.emc", "tegra_vi", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_VI), TEGRA210_CLK_ID_EMC_VI_USER),
9578 SHARED_EMC_CLK("via.emc", "tegra_vi.0", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_VI), TEGRA210_CLK_ID_EMC_VIA_USER),
9579 SHARED_EMC_CLK("vib.emc", "tegra_vi.1", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_VI2), TEGRA210_CLK_ID_EMC_VIB_USER),
9581 SHARED_EMC_CLK("ispa.emc", "tegra_isp.0", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_ISP1), TEGRA210_CLK_ID_EMC_ISPA_USER),
9582 SHARED_EMC_CLK("ispb.emc", "tegra_isp.1", "emc", &tegra_clk_emc, NULL, 0, SHARED_ISO_BW, BIT(EMC_USER_ISP2), TEGRA210_CLK_ID_EMC_ISPB_USER),
9583 SHARED_EMC_CLK("camera.emc", "tegra_camera_ctrl", "emc", &tegra_clk_emc, NULL, 0, SHARED_BW, 0, TEGRA210_CLK_ID_EMC_CAMERA_USER),
9584 SHARED_EMC_CLK("iso.emc", "iso", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_ISO_USER),
9585 SHARED_EMC_CLK("floor.emc", "floor.emc", NULL, &tegra_clk_emc, NULL, 0, 0, 0, 0),
9586 SHARED_EMC_CLK("override.emc", "override.emc", NULL, &tegra_clk_emc, NULL, 0, SHARED_OVERRIDE, 0, 0),
9587 SHARED_EMC_CLK("vic.emc", "tegra_vic03", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_VIC_USER),
9588 SHARED_EMC_CLK("vic_shared.emc", "tegra_vic03", "emc_shared", &tegra_clk_emc, NULL, 0, SHARED_BW, 0, TEGRA210_CLK_ID_EMC_VIC_SHARED_USER),
9589 SHARED_EMC_CLK("battery.emc", "battery_edp", "emc", &tegra_clk_emc, NULL, 0, SHARED_CEILING, 0, 0),
9590 SHARED_EMC_CLK("ape.emc", "ape", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_APE_USER),
9591 SHARED_EMC_CLK("pcie.emc", "tegra_pcie", "emc", &tegra_clk_emc, NULL, 0, 0, 0, TEGRA210_CLK_ID_EMC_PCIE_USER),
9593 DUAL_CBUS_CLK("vic03.cbus", "tegra_vic03", "vic03", &tegra_clk_c2bus, "vic03", 0, 0, TEGRA210_CLK_ID_CXBUS_VIC_USER),
9594 DUAL_CBUS_CLK("nvjpg.cbus", "tegra_nvjpg", "nvjpg", &tegra_clk_c2bus, "nvjpg", 0, 0, TEGRA210_CLK_ID_CXBUS_NVJPG_USER),
9595 DUAL_CBUS_CLK("se.cbus", "tegra21-se", NULL, &tegra_clk_c2bus, "se", 0, 0, TEGRA210_CLK_ID_CXBUS_SE_USER),
9596 DUAL_CBUS_CLK("tsecb.cbus", "tegra_tsecb", "tsecb", &tegra_clk_c2bus, "tsecb", 0, 0, TEGRA210_CLK_ID_CXBUS_TSECB_USER),
9597 SHARED_LIMIT("cap.c2bus", "cap.c2bus", NULL, &tegra_clk_c2bus, NULL, 0, SHARED_CEILING, 0),
9598 SHARED_LIMIT("cap.vcore.c2bus", "cap.vcore.c2bus", NULL, &tegra_clk_c2bus, NULL, 0, SHARED_CEILING, 0),
9599 SHARED_LIMIT("cap.throttle.c2bus", "cap_throttle", NULL, &tegra_clk_c2bus, NULL, 0, SHARED_CEILING, 0),
9600 SHARED_LIMIT("floor.c2bus", "floor.c2bus", NULL, &tegra_clk_c2bus, NULL, 0, 0, 0),
9601 SHARED_CLK("override.c2bus", "override.c2bus", NULL, &tegra_clk_c2bus, NULL, 0, SHARED_OVERRIDE, 0),
9602 SHARED_LIMIT("edp.c2bus", "edp.c2bus", NULL, &tegra_clk_c2bus, NULL, 0, SHARED_CEILING, 0),
9603 SHARED_LIMIT("vic_floor.cbus", "tegra_vic03", "vic_floor", &tegra_clk_c2bus, NULL, 0, 0, TEGRA210_CLK_ID_CXBUS_VIC_FLOOR_USER),
9605 DUAL_CBUS_CLK("msenc.cbus", "tegra_msenc", "msenc", &tegra_clk_c3bus, "msenc", 0, 0, TEGRA210_CLK_ID_CXBUS_NVENC_USER),
9606 DUAL_CBUS_CLK("nvdec.cbus", "tegra_nvdec", "nvdec", &tegra_clk_c3bus, "nvdec", 0, 0, TEGRA210_CLK_ID_CXBUS_NVDEC_USER),
9607 SHARED_LIMIT("cap.c3bus", "cap.c3bus", NULL, &tegra_clk_c3bus, NULL, 0, SHARED_CEILING, 0),
9608 SHARED_LIMIT("cap.vcore.c3bus", "cap.vcore.c3bus", NULL, &tegra_clk_c3bus, NULL, 0, SHARED_CEILING, 0),
9609 SHARED_LIMIT("cap.throttle.c3bus", "cap_throttle", NULL, &tegra_clk_c3bus, NULL, 0, SHARED_CEILING, 0),
9610 SHARED_LIMIT("floor.c3bus", "floor.c3bus", NULL, &tegra_clk_c3bus, NULL, 0, 0, 0),
9611 SHARED_CLK("override.c3bus", "override.c3bus", NULL, &tegra_clk_c3bus, NULL, 0, SHARED_OVERRIDE, 0),
9613 SHARED_CLK("gm20b.gbus", "tegra_gpu.0", "gpu", &tegra_clk_gbus, NULL, 0, 0, TEGRA210_CLK_ID_GBUS_GM20B_USER),
9614 SHARED_LIMIT("cap.gbus", "cap.gbus", NULL, &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9615 SHARED_LIMIT("edp.gbus", "edp.gbus", NULL, &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9616 SHARED_LIMIT("battery.gbus", "battery_edp", "gpu", &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9617 SHARED_LIMIT("cap.vgpu.gbus", "cap.vgpu.gbus", NULL, &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9618 SHARED_LIMIT("cap.throttle.gbus", "cap_throttle", NULL, &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9619 SHARED_LIMIT("cap.profile.gbus", "profile.gbus", "cap", &tegra_clk_gbus, NULL, 0, SHARED_CEILING, 0),
9620 SHARED_CLK("override.gbus", "override.gbus", NULL, &tegra_clk_gbus, NULL, 0, SHARED_OVERRIDE, 0),
9621 SHARED_LIMIT("floor.gbus", "floor.gbus", NULL, &tegra_clk_gbus, NULL, 0, 0, 0),
9622 SHARED_LIMIT("floor.profile.gbus", "profile.gbus", "floor", &tegra_clk_gbus, NULL, 0, 0, 0),
9624 SHARED_CLK("nv.host1x", "tegra_host1x", "host1x", &tegra_clk_host1x, NULL, 0, 0, TEGRA210_CLK_ID_HOST1X_NV_USER),
9625 SHARED_CLK("vi.host1x", "tegra_vi", "host1x", &tegra_clk_host1x, NULL, 0, 0, TEGRA210_CLK_ID_HOST1X_VI_USER),
9626 SHARED_CLK("vii2c.host1x", "546c0000.i2c", "host1x", &tegra_clk_host1x, NULL, 0, 0, TEGRA210_CLK_ID_HOST1X_VII2C_USER),
9627 SHARED_LIMIT("cap.host1x", "cap.host1x", NULL, &tegra_clk_host1x, NULL, 0, SHARED_CEILING, 0),
9628 SHARED_LIMIT("cap.vcore.host1x", "cap.vcore.host1x", NULL, &tegra_clk_host1x, NULL, 0, SHARED_CEILING, 0),
9629 SHARED_LIMIT("floor.host1x", "floor.host1x", NULL, &tegra_clk_host1x, NULL, 0, 0, 0),
9630 SHARED_CLK("override.host1x", "override.host1x", NULL, &tegra_clk_host1x, NULL, 0, SHARED_OVERRIDE, 0),
9632 SHARED_CLK("cpu.mselect", "cpu", "mselect", &tegra_clk_mselect, NULL, 0, 0, TEGRA210_CLK_ID_MSELECT_CPU_USER),
9633 SHARED_CLK("pcie.mselect", "tegra_pcie", "mselect", &tegra_clk_mselect, NULL, 0, 0, TEGRA210_CLK_ID_MSELECT_PCIE_USER),
9634 SHARED_LIMIT("cap.vcore.mselect", "cap.vcore.mselect", NULL, &tegra_clk_mselect, NULL, 0, SHARED_CEILING, 0),
9635 SHARED_CLK("override.mselect", "override.mselect", NULL, &tegra_clk_mselect, NULL, 0, SHARED_OVERRIDE, 0),
9637 SHARED_CLK("adma.ape", NULL, "adma.ape", &tegra_clk_ape, NULL, 0, 0, TEGRA210_CLK_ID_APE_ADMA_USER),
9638 SHARED_CLK("adsp.ape", NULL, "adsp.ape", &tegra_clk_ape, NULL, 0, 0, TEGRA210_CLK_ID_APE_ADSP_USER),
9639 SHARED_CLK("xbar.ape", NULL, "xbar.ape", &tegra_clk_ape, NULL, 0, 0, TEGRA210_CLK_ID_APE_XBAR_USER),
9640 SHARED_LIMIT("cap.vcore.ape", "cap.vcore.ape", NULL, &tegra_clk_ape, NULL, 0, SHARED_CEILING, 0),
9641 SHARED_CLK("override.ape", "override.ape", NULL, &tegra_clk_ape, NULL, 0, SHARED_OVERRIDE, 0),
9643 SHARED_CLK("adsp_cpu.abus", NULL, "adsp_cpu", &tegra_clk_virtual_adsp_bus, NULL, 0, 0, TEGRA210_CLK_ID_ADSP_CPU),
9644 SHARED_LIMIT("cap.vcore.abus", "cap.vcore.abus", NULL, &tegra_clk_virtual_adsp_bus, NULL, 0, SHARED_CEILING, 0),
9645 SHARED_CLK("override.abus", "override.abus", NULL, &tegra_clk_virtual_adsp_bus, NULL, 0, SHARED_OVERRIDE, 0),
9649 static struct clk tegra_visp_clks[] = {
9650 SHARED_CONNECT("vi.cbus", "vi.cbus", NULL, &tegra_clk_cbus, "vi", 0, 0, TEGRA210_CLK_ID_CXBUS_VI_USER),
9651 SHARED_CONNECT("isp.cbus", "isp.cbus", NULL, &tegra_clk_cbus, "isp", 0, 0, TEGRA210_CLK_ID_CXBUS_ISP_USER),
9652 SHARED_CLK("override.cbus", "override.cbus", NULL, &tegra_clk_cbus, NULL, 0, SHARED_OVERRIDE, 0),
9653 SHARED_LIMIT("cap.vcore.cbus", "cap.vcore.cbus", NULL, &tegra_clk_cbus, NULL, 0, SHARED_CEILING, 0),
9655 #ifndef CONFIG_VI_ONE_DEVICE
9656 SHARED_CLK("via.vi.cbus", "via.vi", NULL, &tegra_visp_clks[0], NULL, 0, 0, TEGRA210_CLK_ID_CXBUS_VI_VIA_USER),
9657 SHARED_CLK("vib.vi.cbus", "vib.vi", NULL, &tegra_visp_clks[0], NULL, 0, 0, TEGRA210_CLK_ID_CXBUS_VI_VIB_USER),
9660 SHARED_CLK("ispa.isp.cbus", "ispa.isp", NULL, &tegra_visp_clks[1], "ispa", 0, 0, TEGRA210_CLK_ID_CXBUS_ISP_ISPA_USER),
9661 SHARED_CLK("ispb.isp.cbus", "ispb.isp", NULL, &tegra_visp_clks[1], "ispb", 0, 0, TEGRA210_CLK_ID_CXBUS_ISP_ISPB_USER),
9665 #define XUSB_ID "tegra-xhci"
9666 #define XUDC_ID "tegra-xudc"
9667 /* xusb common clock gate - enabled on init and never disabled */
9668 static void tegra21_xusb_gate_clk_init(struct clk *c)
9670 tegra21_periph_clk_enable(c);
9673 static struct clk_ops tegra_xusb_gate_clk_ops = {
9674 .init = tegra21_xusb_gate_clk_init,
9677 static struct clk tegra_clk_xusb_gate = {
9678 .name = "xusb_gate",
9679 .clk_id = TEGRA210_CLK_ID_XUSB_GATE,
9680 .flags = ENABLE_ON_INIT | PERIPH_NO_RESET,
9681 .ops = &tegra_xusb_gate_clk_ops,
9682 .parent = &tegra_clk_osc,
9684 .max_rate = 48000000,
9690 static struct clk tegra_xusb_source_clks[] = {
9691 PERIPH_CLK("xusb_host_src", XUSB_ID, "host_src", 143, 0x600, 112000000, mux_clkm_pllp_pllre, MUX | DIV_U71 | PERIPH_NO_RESET | PERIPH_ON_APB, TEGRA210_CLK_ID_XUSB_HOST_SRC),
9692 PERIPH_CLK("xusb_falcon_src", XUSB_ID, "falcon_src", 143, 0x604, 336000000, mux_clkm_pllp_pllre, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_XUSB_FALCON_SRC),
9693 PERIPH_CLK("xusb_fs_src", NULL, "fs_src", 143, 0x608, 48000000, mux_clkm_48M_pllp_480M, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_XUSB_FS_SRC),
9694 PERIPH_CLK_EX("xusb_ss_src", NULL, "ss_src", 143, 0x610, 120000000, mux_clkm_pllre_clk32_480M, MUX | DIV_U71 | PERIPH_NO_RESET, TEGRA210_CLK_ID_XUSB_SS_SRC, &tegra_xusb_ss_ops),
9695 PERIPH_CLK("xusb_dev_src", XUDC_ID, "dev_src", 95, 0x60c, 112000000, mux_clkm_pllp_pllre, MUX | DIV_U71 | PERIPH_ON_APB, TEGRA210_CLK_ID_XUSB_DEV_SRC),
9696 SHARED_EMC_CLK("xusb.emc", XUSB_ID, "emc", &tegra_clk_emc, NULL, 0, SHARED_BW, 0, TEGRA210_CLK_ID_EMC_XUSB_USER),
9699 static struct clk_mux_sel mux_ss_clk_m[] = {
9700 { .input = &tegra_xusb_source_clks[3], .value = 0},
9701 { .input = &tegra_clk_m, .value = 1},
9705 static struct clk tegra_xusb_ssp_src = {
9706 .name = "xusb_ssp_src",
9707 .clk_id = TEGRA210_CLK_ID_XUSB_SSP_SRC,
9710 .con_id = "ssp_src",
9712 .ops = &tegra_xusb_ss_ops,
9714 .inputs = mux_ss_clk_m,
9715 .flags = MUX | PERIPH_NO_ENB | PERIPH_NO_RESET,
9716 .max_rate = 120000000,
9718 .src_mask = 0x1 << 24,
9723 static struct clk tegra_xusb_ss_div2 = {
9724 .name = "xusb_ss_div2",
9725 .clk_id = TEGRA210_CLK_ID_XUSB_SS_DIV2,
9726 .ops = &tegra_clk_m_div_ops,
9727 .parent = &tegra_xusb_source_clks[3],
9731 .max_rate = 60000000,
9734 static struct clk_mux_sel mux_ss_div2_pllu_60M[] = {
9735 { .input = &tegra_xusb_ss_div2, .value = 0},
9736 { .input = &tegra_pll_u_60M, .value = 1},
9737 { .input = &tegra_xusb_source_clks[3], .value = 2},
9738 { .input = &tegra_xusb_source_clks[3], .value = 3},
9742 static struct clk tegra_xusb_hs_src = {
9743 .name = "xusb_hs_src",
9744 .clk_id = TEGRA210_CLK_ID_XUSB_HS_SRC,
9749 .ops = &tegra_xusb_ss_ops,
9751 .inputs = mux_ss_div2_pllu_60M,
9752 .flags = MUX | PLLU | PERIPH_NO_ENB | PERIPH_NO_RESET,
9753 .max_rate = 120000000,
9755 .src_mask = 0x3 << 25,
9760 static struct clk_mux_sel mux_xusb_host[] = {
9761 { .input = &tegra_xusb_source_clks[0], .value = 0},
9762 { .input = &tegra_xusb_source_clks[1], .value = 1},
9763 { .input = &tegra_xusb_source_clks[2], .value = 2},
9764 { .input = &tegra_xusb_hs_src, .value = 5},
9768 static struct clk_mux_sel mux_xusb_ss[] = {
9769 { .input = &tegra_xusb_ssp_src, .value = 3},
9770 { .input = &tegra_xusb_source_clks[0], .value = 0},
9771 { .input = &tegra_xusb_source_clks[1], .value = 1},
9775 static struct clk_mux_sel mux_xusb_dev[] = {
9776 { .input = &tegra_xusb_source_clks[4], .value = 4},
9777 { .input = &tegra_xusb_source_clks[2], .value = 2},
9778 { .input = &tegra_xusb_ssp_src, .value = 3},
9779 { .input = &tegra_xusb_hs_src, .value = 5},
9783 static struct clk tegra_xusb_coupled_clks[] = {
9784 PERIPH_CLK_EX("xusb_host", XUSB_ID, "host", 89, 0, 336000000, mux_xusb_host, 0, TEGRA210_CLK_ID_XUSB_HOST, &tegra_clk_coupled_gate_ops),
9785 PERIPH_CLK_EX("xusb_ss", NULL, "ss", 156, 0, 336000000, mux_xusb_ss, 0, TEGRA210_CLK_ID_XUSB_SS, &tegra_clk_coupled_gate_ops),
9786 PERIPH_CLK_EX("xusb_dev", XUDC_ID, "dev", 95, 0, 120000000, mux_xusb_dev, 0, TEGRA210_CLK_ID_XUSB_DEV, &tegra_clk_coupled_gate_ops),
9789 #define SLCG_CLK(_root_name, _name_ext, _dev, _con, _reg, _bit) \
9791 .name = _root_name "_slcg_ovr" _name_ext, \
9796 .ops = &tegra_clk_slcg_ops, \
9798 .max_rate = 38400000, /* replaced by root max */ \
9804 static struct clk tegra_slcg_clks[] = {
9805 SLCG_CLK("disp2", "", "tegradc.1", "slcg", 0xf8, 2),
9806 SLCG_CLK("disp1", "", "tegradc.0", "slcg", 0xf8, 1),
9808 SLCG_CLK("vi", "", "tegra_vi", "slcg", 0xf8, 15),
9809 SLCG_CLK("ispa", "", "tegra_isp.0", "slcg", 0x554, 3),
9810 SLCG_CLK("ispb", "", "tegra_isp.1", "slcg", 0x3a4, 22),
9812 SLCG_CLK("nvdec", "", "tegra_nvdec", "slcg", 0x554, 31),
9813 SLCG_CLK("msenc", "", "tegra_msenc", "slcg", 0x554, 29),
9814 SLCG_CLK("nvjpg", "", "tegra_nvjpg", "slcg", 0x554, 9),
9815 SLCG_CLK("vic03", "", "tegra_vic03", "slcg", 0x554, 5),
9817 SLCG_CLK("xusb_dev", "", XUDC_ID, "slcg", 0x3a0, 31),
9818 SLCG_CLK("xusb_host", "", XUSB_ID, "slcg", 0x3a0, 30),
9819 SLCG_CLK("sata", "_fpci", "tegra_sata", "slcg_fpci", 0x3a0, 19),
9820 SLCG_CLK("sata", "_ipfs", "tegra_sata", "slcg_ipfs", 0x3a0, 17),
9821 SLCG_CLK("sata", "", "tegra_sata", "slcg", 0x3a0, 0),
9823 SLCG_CLK("d_audio", "", "tegra210-axbar", "slcg", 0x3a0, 1),
9824 SLCG_CLK("adsp", "", NULL, "slcg_adsp", 0x554, 11),
9825 SLCG_CLK("ape", "", NULL, "slcg_ape", 0x554, 10),
9828 #define CLK_DUPLICATE(_name, _dev, _con) \
9837 /* Some clocks may be used by different drivers depending on the board
9838 * configuration. List those here to register them twice in the clock lookup
9839 * table under two names.
9841 static struct clk_duplicate tegra_clk_duplicates[] = {
9842 CLK_DUPLICATE("uarta", "serial8250.0", NULL),
9843 CLK_DUPLICATE("uartb", "serial8250.1", NULL),
9844 CLK_DUPLICATE("uartc", "serial8250.2", NULL),
9845 CLK_DUPLICATE("uartd", "serial8250.3", NULL),
9846 CLK_DUPLICATE("usbd", XUSB_ID, "utmip-pad"),
9847 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
9848 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
9849 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
9850 CLK_DUPLICATE("disp1", "tegra_dc_dsi_vs1.0", NULL),
9851 CLK_DUPLICATE("disp1.emc", "tegra_dc_dsi_vs1.0", "emc"),
9852 CLK_DUPLICATE("disp1", "tegra_dc_dsi_vs1.1", NULL),
9853 CLK_DUPLICATE("disp1.emc", "tegra_dc_dsi_vs1.1", "emc"),
9854 CLK_DUPLICATE("dsib", "tegradc.0", "dsib"),
9855 CLK_DUPLICATE("dsia", "tegradc.1", "dsia"),
9856 CLK_DUPLICATE("dsiblp", "tegradc.0", "dsiblp"),
9857 CLK_DUPLICATE("dsialp", "tegradc.1", "dsialp"),
9858 CLK_DUPLICATE("dsia", "tegra_dc_dsi_vs1.0", "dsia"),
9859 CLK_DUPLICATE("dsia", "tegra_dc_dsi_vs1.1", "dsia"),
9860 CLK_DUPLICATE("dsialp", "tegra_dc_dsi_vs1.0", "dsialp"),
9861 CLK_DUPLICATE("dsialp", "tegra_dc_dsi_vs1.1", "dsialp"),
9862 CLK_DUPLICATE("dsi1-fixed", "tegra_dc_dsi_vs1.0", "dsi-fixed"),
9863 CLK_DUPLICATE("dsi1-fixed", "tegra_dc_dsi_vs1.1", "dsi-fixed"),
9864 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
9865 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
9866 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
9867 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
9868 CLK_DUPLICATE("cop", "nvavp", "cop"),
9869 CLK_DUPLICATE("bsev", "nvavp", "bsev"),
9870 CLK_DUPLICATE("cml1", "tegra_sata_cml", NULL),
9871 CLK_DUPLICATE("cml0", "tegra_pcie", "cml"),
9872 CLK_DUPLICATE("pciex", "tegra_pcie", "pciex"),
9873 CLK_DUPLICATE("pex_uphy", "tegra_pcie", "pex_uphy"),
9874 CLK_DUPLICATE("clk_m", NULL, "apb_pclk"),
9875 CLK_DUPLICATE("i2c1", "tegra-i2c-slave.0", NULL),
9876 CLK_DUPLICATE("i2c2", "tegra-i2c-slave.1", NULL),
9877 CLK_DUPLICATE("i2c3", "tegra-i2c-slave.2", NULL),
9878 CLK_DUPLICATE("i2c4", "tegra-i2c-slave.3", NULL),
9879 CLK_DUPLICATE("i2c5", "tegra-i2c-slave.4", NULL),
9880 CLK_DUPLICATE("cl_dvfs_ref", "7000d000.i2c", NULL),
9881 CLK_DUPLICATE("cl_dvfs_soc", "7000d000.i2c", NULL),
9882 CLK_DUPLICATE("sbc1", "tegra11-spi-slave.0", NULL),
9883 CLK_DUPLICATE("sbc2", "tegra11-spi-slave.1", NULL),
9884 CLK_DUPLICATE("sbc3", "tegra11-spi-slave.2", NULL),
9885 CLK_DUPLICATE("sbc4", "tegra11-spi-slave.3", NULL),
9886 CLK_DUPLICATE("pll_p", "7000d400.spi", "pll_p"),
9887 CLK_DUPLICATE("pll_p", "7000d600.spi", "pll_p"),
9888 CLK_DUPLICATE("pll_p", "7000d800.spi", "pll_p"),
9889 CLK_DUPLICATE("pll_p", "7000da00.spi", "pll_p"),
9890 CLK_DUPLICATE("pll_p", "7000dc00.spi", "pll_p"),
9891 CLK_DUPLICATE("pll_p", "7000de00.spi", "pll_p"),
9892 CLK_DUPLICATE("clk_m", "7000d400.spi", "clk_m"),
9893 CLK_DUPLICATE("clk_m", "7000d600.spi", "clk_m"),
9894 CLK_DUPLICATE("clk_m", "7000d800.spi", "clk_m"),
9895 CLK_DUPLICATE("clk_m", "7000da00.spi", "clk_m"),
9896 CLK_DUPLICATE("clk_m", "7000dc00.spi", "clk_m"),
9897 CLK_DUPLICATE("clk_m", "7000de00.spi", "clk_m"),
9898 CLK_DUPLICATE("i2c5", "tegra_cl_dvfs", "i2c"),
9899 CLK_DUPLICATE("cpu_g", "tegra_cl_dvfs", "safe_dvfs"),
9900 CLK_DUPLICATE("actmon", "tegra_host1x", "actmon"),
9901 CLK_DUPLICATE("gpu_ref", "tegra_gpu.0", "PLLG_ref"),
9902 CLK_DUPLICATE("pll_p_out5", "tegra_gpu.0", "pwr"),
9903 CLK_DUPLICATE("ispa.isp.cbus", "tegra_isp.0", "isp"),
9904 CLK_DUPLICATE("ispb.isp.cbus", "tegra_isp.1", "isp"),
9905 CLK_DUPLICATE("vii2c", "tegra_vi", "vii2c"),
9906 CLK_DUPLICATE("i2cslow", "tegra_vi", "i2cslow"),
9907 CLK_DUPLICATE("mclk3", NULL, "cam_mclk1"),
9908 CLK_DUPLICATE("mclk", NULL, "cam_mclk2"),
9909 CLK_DUPLICATE("mclk2", NULL, "cam_mclk3"),
9910 #ifdef CONFIG_VI_ONE_DEVICE
9911 CLK_DUPLICATE("vi.cbus", "tegra_vi", "vi"),
9912 CLK_DUPLICATE("csi", "tegra_vi", "csi"),
9913 CLK_DUPLICATE("csus", "tegra_vi", "csus"),
9914 CLK_DUPLICATE("vim2_clk", "tegra_vi", "vim2_clk"),
9915 CLK_DUPLICATE("cilab", "tegra_vi", "cilab"),
9916 CLK_DUPLICATE("cilcd", "tegra_vi", "cilcd"),
9917 CLK_DUPLICATE("cile", "tegra_vi", "cile"),
9919 CLK_DUPLICATE("via.vi.cbus", "tegra_vi", "vi"),
9920 CLK_DUPLICATE("vib.vi.cbus", "tegra_vi.1", "vi"),
9921 CLK_DUPLICATE("csi", "tegra_vi", "csi"),
9922 CLK_DUPLICATE("csi", "tegra_vi.1", "csi"),
9923 CLK_DUPLICATE("csus", "tegra_vi", "csus"),
9924 CLK_DUPLICATE("vim2_clk", "tegra_vi.1", "vim2_clk"),
9925 CLK_DUPLICATE("cilab", "tegra_vi", "cilab"),
9926 CLK_DUPLICATE("cilcd", "tegra_vi.1", "cilcd"),
9927 CLK_DUPLICATE("cile", "tegra_vi.1", "cile"),
9928 CLK_DUPLICATE("via.emc", "tegra_vi", "emc"),
9930 CLK_DUPLICATE("spdif_in", NULL, "spdif_in"),
9931 CLK_DUPLICATE("dmic1", "tegra-dmic.0", NULL),
9932 CLK_DUPLICATE("dmic2", "tegra-dmic.1", NULL),
9933 CLK_DUPLICATE("dmic3", "tegra-dmic.2", NULL),
9934 CLK_DUPLICATE("d_audio", "tegra210-adma", NULL),
9935 CLK_DUPLICATE("d_audio", "nvadsp", "ahub"),
9936 CLK_DUPLICATE("mclk", NULL, "default_mclk"),
9937 CLK_DUPLICATE("uart_mipi_cal", "clk72mhz", NULL),
9941 static struct clk *tegra_main_clks[] = {
9947 static struct clk *tegra_ptr_clks[] = {
9959 &tegra_pll_p_out_adsp,
9960 &tegra_pll_p_out_cpu,
9961 &tegra_pll_p_out_hsio,
9962 &tegra_pll_p_out_xusb,
9967 &tegra_pll_p_out_sor,
9969 &tegra_pll_a_out_adsp,
9971 &tegra_pll_a_out0_out_adsp,
9974 &tegra_clk_xusb_gate,
9999 &tegra_pex_uphy_clk,
10001 &tegra_clk_cclk_lp,
10002 &tegra_clk_sclk_mux,
10003 &tegra_clk_sclk_div,
10007 &tegra_clk_aclk_adsp,
10008 &tegra_clk_virtual_adsp_bus,
10009 &tegra_clk_virtual_cpu_g,
10010 &tegra_clk_virtual_cpu_lp,
10011 &tegra_clk_cpu_cmplx,
10014 &tegra_clk_sbus_cmplx,
10020 &tegra_clk_mselect,
10024 &tegra_clk_gpu_gate,
10025 &tegra_clk_gpu_ref,
10029 &tegra_clk_sor1_src,
10030 &tegra_clk_sor0_brick,
10031 &tegra_clk_sor1_brick,
10032 &tegra_clk_xusb_padctl,
10034 &tegra_sata_aux_clk,
10035 &tegra_clk_sata_uphy,
10036 &tegra_clk_usb2_hsic_trk,
10037 &tegra_clk_hda2codec_2x,
10040 static struct clk *tegra_ptr_camera_mclks[] = {
10041 &tegra_camera_mclk,
10042 &tegra_camera_mclk2,
10043 &tegra_camera_mclk3,
10044 &tegra_camera_mipical,
10047 #ifdef CONFIG_DEBUG_FS
10048 static struct tegra_pto_table ptodefs[] = {
10049 { .name = "pll_c", .divider = 2, .pto_id = 1, .presel_reg = 0x088, .presel_value = BIT(3), .presel_mask = BIT(3) },
10050 { .name = "pll_a1", .divider = 2, .pto_id = 85, .presel_reg = 0x6a8, .presel_value = BIT(3), .presel_mask = BIT(3) },
10051 { .name = "pll_c2", .divider = 2, .pto_id = 88, .presel_reg = 0x4ec, .presel_value = BIT(3), .presel_mask = BIT(3) },
10052 { .name = "pll_c3", .divider = 2, .pto_id = 89, .presel_reg = 0x500, .presel_value = BIT(3), .presel_mask = BIT(3) },
10054 { .name = "pll_a", .divider = 2, .pto_id = 4, .presel_reg = 0x0bc, .presel_value = BIT(29), .presel_mask = BIT(29) },
10055 { .name = "pll_x", .divider = 2, .pto_id = 5, .presel_reg = 0x0e4, .presel_value = BIT(22), .presel_mask = BIT(22) },
10057 { .name = "pll_d", .divider = 2, .pto_id = 203, .presel_reg = 0x0dc, .presel_value = BIT(25), .presel_mask = BIT(25) },
10058 { .name = "pll_d2", .divider = 2, .pto_id = 205, .presel_reg = 0x4b8, .presel_value = BIT(16), .presel_mask = BIT(16) },
10059 { .name = "pll_dp", .divider = 2, .pto_id = 207, .presel_reg = 0x590, .presel_value = BIT(16), .presel_mask = BIT(16) },
10060 { .name = "pll_c4", .divider = 2, .pto_id = 81, .presel_reg = 0x5a4, .presel_value = BIT(16), .presel_mask = BIT(16) },
10062 { .name = "pll_m", .divider = 2, .pto_id = 2, .presel_reg = 0x9c, .presel_value = BIT(8), .presel_mask = BIT(8) },
10063 { .name = "pll_mb", .divider = 2, .pto_id = 37, .presel_reg = 0x9c, .presel_value = BIT(9), .presel_mask = BIT(9) },
10065 { .name = "pll_u", .divider = 2, .pto_id = 269, .presel_reg = 0xcc, .presel_value = BIT(27), .presel_mask = BIT(27) },
10066 { .name = "pll_re_vco", .divider = 2, .pto_id = 271, .presel_reg = 0x4c8, .presel_value = BIT(26), .presel_mask = BIT(26) },
10068 { .name = "cpu", .divider = 1, .pto_id = 18, },
10075 * Handle special clocks to check if they can be set to safe rate
10077 static void check_isp_reset(void)
10079 struct clk *isp = &tegra_clk_isp;
10080 struct clk *ispa = tegra_get_clock_by_name("ispa");
10081 struct clk *ispb = tegra_get_clock_by_name("ispb");
10083 if (periph_clk_can_force_safe_rate(ispa) &&
10084 periph_clk_can_force_safe_rate(ispb))
10085 tegra_periph_clk_safe_rate_init(isp);
10088 static void tegra21_periph_check_special_reset(void)
10093 /* DFLL late init called with CPU clock lock taken */
10094 static void __init tegra21_dfll_cpu_late_init(struct clk *c)
10096 #ifdef CONFIG_ARCH_TEGRA_HAS_CL_DVFS
10098 struct clk *cpu = &tegra_clk_virtual_cpu_g;
10099 unsigned long int dfll_boot_req_khz = tegra_dfll_boot_req_khz();
10101 if (!cpu || !cpu->dvfs) {
10102 pr_err("%s: CPU dvfs is not present\n", __func__);
10105 tegra_dvfs_set_dfll_tune_trimmers(cpu->dvfs, tune_cpu_trimmers);
10107 /* release dfll clock source reset */
10108 tegra_periph_reset_deassert(c);
10111 * Init DFLL control logic (cl_dvfs):
10112 * - if CPU is already set on DFLL by boot-loader, this call would sync
10113 * cl_dvfs driver with cl_dvfs h/w state.
10114 * - if CPU booted on PLLX this call initializes cl_dvfs h/w, so DFLL
10115 * can be used as CPU source.
10117 ret = tegra_init_cl_dvfs();
10121 * cl_dvfs device may not be present in DT for virtualized platform.
10123 if (dfll_boot_req_khz) {
10124 if (!ret || (ret == -ENODEV)) {
10125 c->u.dfll.consumer = cpu;
10127 use_dfll = DFLL_RANGE_ALL_RATES;
10128 tegra_dvfs_set_dfll_range(cpu->dvfs, use_dfll);
10130 /* To read regulator (not cache), set volatile mode */
10131 tegra_dvfs_rail_set_reg_volatile(tegra_cpu_rail, true);
10134 tegra_cl_dvfs_debug_init(c);
10136 pr_info("Tegra CPU DFLL booted with use_dfll = %d\n",
10140 pr_err("Tegra CPU DFLL failed to sync boot state\n");
10146 c->u.dfll.consumer = cpu;
10148 if (tegra_platform_is_silicon())
10149 use_dfll = CONFIG_TEGRA_USE_DFLL_RANGE;
10150 tegra_dvfs_set_dfll_range(cpu->dvfs, use_dfll);
10151 tegra_cl_dvfs_debug_init(c);
10152 pr_info("Tegra CPU DFLL is initialized with use_dfll = %d\n",
10159 * Tegra21 clock policy: PLLC4 is a fixed frequency PLL with VCO output catered
10160 * to maximum eMMC rate. By default PLLC4 VCO is fixed at ~1GHz, that provides
10161 * target rates for DDR HS667 mode (PLLC4_OUT1 = VCO/3), DDR HS400 mode, and SDR
10162 * HS200 mode (PLLC4_OUT2 = VCO/5). For other possible eMMC rate targets VCO
10163 * rate is tabulated below.
10165 * PLLC4 post-divider PLLC_OUT0 and secondary divider PLLC_OUT3 ratios specified
10166 * in the table are selected to provide max input frequency to downstream module
10167 * dividers (fort better granularity of possible rates).
10169 * Commonly PLLC_OUT3 is also used as second clock source (along with PLLP) for
10172 struct pllc4_sdmmc_map {
10173 unsigned long sdmmc_max_rate;
10174 unsigned long vco_rate;
10177 struct clk *bus_source;
10180 static struct pllc4_sdmmc_map tegra21_pllc4_sdmmc_map[] = {
10181 { 0, 1000000000, 1, 1, &tegra_pll_c4_out3 }, /* default cfg */
10182 { 266000000, 798000000, 4, 1, &tegra_pll_c4_out1 },
10185 static void pllc4_set_fixed_rates(unsigned long cf)
10189 struct device_node *dn;
10190 unsigned long rate, sdmmc_max_rate = 0;
10191 struct pllc4_sdmmc_map *pllc4_cfg = &tegra21_pllc4_sdmmc_map[0];
10193 for_each_compatible_node(dn, NULL, "nvidia,tegra210-sdhci") {
10194 if (!of_device_is_available(dn))
10197 if (!of_property_read_u32(dn, "max-clk-limit", &val)
10198 && (sdmmc_max_rate < val))
10199 sdmmc_max_rate = val;
10202 if (sdmmc_max_rate) {
10203 for (i = 1; i < ARRAY_SIZE(tegra21_pllc4_sdmmc_map); i++) {
10204 struct pllc4_sdmmc_map *m = &tegra21_pllc4_sdmmc_map[i];
10205 if (m->sdmmc_max_rate == sdmmc_max_rate) {
10212 /* Align VCO rate on comparison frequency boundary */
10213 rate = (pllc4_cfg->vco_rate / cf) * cf;
10214 tegra_pll_c4_vco.u.pll.fixed_rate = rate;
10215 tegra_pll_c4_vco.flags |= PLL_FIXED;
10217 rate = DIV_ROUND_UP(rate, pllc4_cfg->out0_ratio);
10218 tegra_pll_c4_out0.u.pll.fixed_rate = rate;
10219 tegra_pll_c4_out0.flags |= PLL_FIXED;
10221 rate = DIV_ROUND_UP(rate, pllc4_cfg->out3_ratio);
10222 tegra_pll_c4_out3.u.pll_div.default_rate = rate;
10224 tegra_clk_sbus_cmplx.u.system.sclk_high = pllc4_cfg->bus_source;
10226 pr_info("pll_c4 rates match %lu max sdmmc: vco=%lu out0=%lu out3=%lu\n",
10228 tegra_pll_c4_vco.u.pll.fixed_rate,
10229 tegra_pll_c4_out0.u.pll.fixed_rate,
10230 tegra_pll_c4_out3.u.pll_div.default_rate);
10234 * Backup pll is used as transitional CPU clock source while main pll is
10235 * relocking; in addition all CPU rates below backup level are sourced from
10236 * backup pll only. Target backup levels for each CPU mode are selected high
10237 * enough to avoid voltage droop when CPU clock is switched between backup and
10238 * main plls. Actual backup rates will be rounded to match backup source fixed
10239 * frequency. Backup rates are also used as stay-on-backup thresholds, and must
10240 * be kept the same in G and LP mode (will need to add a separate stay-on-backup
10241 * parameter to allow different backup rates if necessary).
10243 * Sbus threshold must be exact factor of pll_p rate.
10245 #define CPU_G_BACKUP_RATE_TARGET 200000000
10246 #define CPU_LP_BACKUP_RATE_TARGET 200000000
10248 static void tegra21_pllp_init_dependencies(unsigned long pllp_rate)
10251 unsigned long backup_rate;
10252 unsigned long adsp_backup_rate;
10254 switch (pllp_rate) {
10256 tegra_pll_p_out3.u.pll_div.default_rate = 72000000;
10257 tegra_pll_p_out4.u.pll_div.default_rate = 108000000;
10258 tegra_pll_p_out5.u.pll_div.default_rate = 108000000;
10259 tegra_clk_sbus_cmplx.u.system.threshold = 108000000;
10260 tegra_clk_host1x.u.periph.threshold = 108000000;
10261 adsp_backup_rate = 108000000;
10264 tegra_pll_p_out3.u.pll_div.default_rate = 102000000;
10265 tegra_pll_p_out4.u.pll_div.default_rate = 204000000;
10266 tegra_pll_p_out5.u.pll_div.default_rate = 204000000;
10267 tegra_clk_sbus_cmplx.u.system.threshold = 204000000;
10268 tegra_clk_host1x.u.periph.threshold = 204000000;
10269 adsp_backup_rate = 136000000;
10272 tegra_pll_p_out3.u.pll_div.default_rate = 102000000;
10273 tegra_pll_p_out4.u.pll_div.default_rate = 204000000;
10274 tegra_pll_p_out5.u.pll_div.default_rate = 204000000;
10275 tegra_clk_sbus_cmplx.u.system.threshold = 204000000;
10276 tegra_clk_host1x.u.periph.threshold = 204000000;
10277 adsp_backup_rate = 102000000;
10280 pr_err("tegra: PLLP rate: %lu is not supported\n", pllp_rate);
10283 pr_info("tegra: PLLP fixed rate: %lu\n", pllp_rate);
10285 div = pllp_rate / CPU_G_BACKUP_RATE_TARGET;
10286 backup_rate = pllp_rate / div;
10287 tegra_clk_virtual_cpu_g.u.cpu.backup_rate = backup_rate;
10289 div = pllp_rate / CPU_LP_BACKUP_RATE_TARGET;
10290 backup_rate = pllp_rate / div;
10291 tegra_clk_virtual_cpu_lp.u.cpu.backup_rate = backup_rate;
10293 div = pllp_rate / adsp_backup_rate;
10294 tegra_clk_aclk_adsp.u.cclk.div71 = 2 * div - 2; /* reg settings */
10295 backup_rate = pllp_rate / div;
10296 tegra_clk_virtual_adsp_bus.u.cpu.backup_rate = adsp_backup_rate;
10299 static void tegra21_init_one_clock(struct clk *c)
10302 INIT_LIST_HEAD(&c->shared_bus_list);
10303 if (!c->lookup.dev_id && !c->lookup.con_id)
10304 c->lookup.con_id = c->name;
10306 clkdev_add(&c->lookup);
10308 /* Sanity check for clock IDs within CLK_OUT_ENB_NUM */
10309 if (c->clk_id && (c->clk_id < CLK_OUT_ENB_NUM * 32) &&
10310 (c->clk_id != c->u.periph.clk_num))
10311 WARN(1, "%s clock id %u does not match enable bit %u\n",
10312 c->name, c->clk_id, c->u.periph.clk_num);
10315 void tegra_edp_throttle_cpu_now(u8 factor)
10317 /* empty definition for tegra21 */
10321 bool tegra_clk_is_parent_allowed(struct clk *c, struct clk *p)
10324 * Most of the Tegra21 multimedia and peripheral muxes include pll_c2
10325 * and pll_c3 as possible inputs. However, per clock policy these plls
10326 * are allowed to be used only by handful devices aggregated on cbus.
10327 * For all others, instead of enforcing policy at run-time in this
10328 * function, we simply stripped out pll_c2 and pll_c3 options from the
10329 * respective muxes statically. Similarly pll_a1 is removed from the
10330 * set of possible parents of non-cbus modules.
10332 * Traditionally ubiquitous on tegra chips pll_c is allowed to be used
10333 * as parent for cbus modules only as well, but it is not stripped out
10334 * from muxes statically, and the respective policy is enforced by this
10337 if ((p == &tegra_pll_c) && (c != &tegra_pll_c_out1))
10338 return c->flags & PERIPH_ON_CBUS;
10341 * On Tegra21 both PLLM and PLLMB are statically connected to EMC mux
10342 * only. However, PLLMB allowed to be used only if PLLM is in default
10343 * configuration (i.e., all overrides are disabled).
10345 if (p == &tegra_pll_mb)
10346 return tegra_pll_m.u.pll.defaults_set;
10351 /* Internal LA may request some clocks to be enabled on init via TRANSACTION
10352 SCRATCH register settings */
10353 static void __init tegra21x_clk_init_la(void)
10356 u32 reg = readl((void *)
10357 ((uintptr_t)misc_gp_base + MISC_GP_TRANSACTOR_SCRATCH_0));
10359 if (!(reg & MISC_GP_TRANSACTOR_SCRATCH_LA_ENABLE))
10362 c = tegra_get_clock_by_name("la");
10363 if (WARN(!c, "%s: could not find la clk\n", __func__))
10365 tegra_clk_prepare_enable(c);
10367 if (reg & MISC_GP_TRANSACTOR_SCRATCH_DP2_ENABLE) {
10368 c = tegra_get_clock_by_name("dp2");
10369 if (WARN(!c, "%s: could not find dp2 clk\n", __func__))
10371 tegra_clk_prepare_enable(c);
10375 #ifdef CONFIG_PM_SLEEP
10376 static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
10377 PERIPH_CLK_SOURCE_NUM + 25];
10379 static int tegra21_clk_suspend(void)
10382 u32 *ctx = clk_rst_suspend;
10384 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_OSC_FREQ_MASK;
10385 *ctx++ = clk_readl(CPU_SOFTRST_CTRL);
10386 *ctx++ = clk_readl(CPU_SOFTRST_CTRL1);
10387 *ctx++ = clk_readl(CPU_SOFTRST_CTRL2);
10389 *ctx++ = clk_readl(SPARE_REG);
10390 *ctx++ = clk_readl(MISC_CLK_ENB);
10391 *ctx++ = clk_readl(CLK_MASK_ARM);
10393 *ctx++ = clk_readl(tegra_pll_p_out3.reg);
10394 *ctx++ = clk_readl(tegra_pll_p_out5.reg);
10395 *ctx++ = clk_readl(tegra_pll_p_out_hsio.reg);
10397 *ctx++ = clk_readl(tegra_pll_u_out1.reg);
10398 *ctx++ = clk_readl(tegra_pll_u_vco.reg);
10400 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
10401 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
10402 *ctx++ = clk_readl(tegra_pll_c4_out3.reg);
10403 *ctx++ = clk_readl(tegra_pll_re_out1.reg);
10405 *ctx++ = clk_readl(tegra_clk_sclk.reg);
10406 *ctx++ = clk_readl(tegra_clk_sclk_div.reg);
10407 *ctx++ = clk_readl(tegra_clk_sclk_mux.reg);
10408 *ctx++ = clk_readl(tegra_clk_pclk.reg);
10410 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_LA;
10412 if (off == PERIPH_CLK_SOURCE_EMC)
10414 *ctx++ = clk_readl(off);
10416 for (off = PERIPH_CLK_SOURCE_MSELECT; off <= PERIPH_CLK_SOURCE_SE;
10418 *ctx++ = clk_readl(off);
10420 for (off = AUDIO_DLY_CLK; off <= AUDIO_SYNC_CLK_SPDIF; off+=4) {
10421 *ctx++ = clk_readl(off);
10423 for (off = AUDIO_SYNC_CLK_DMIC1;
10424 off <= AUDIO_SYNC_CLK_DMIC2; off += 4) {
10425 *ctx++ = clk_readl(off);
10427 for (off = PERIPH_CLK_SOURCE_XUSB_HOST;
10428 off <= PERIPH_CLK_SOURCE_VIC; off += 4) {
10429 if (off == PERIPH_CLK_SOURCE_EMC_DLL)
10431 *ctx++ = clk_readl(off);
10433 for (off = PERIPH_CLK_SOURCE_SDMMC_LEGACY;
10434 off <= PERIPH_CLK_SOURCE_NVENC; off += 4) {
10435 *ctx++ = clk_readl(off);
10437 for (off = AUDIO_SYNC_CLK_DMIC3;
10438 off <= PERIPH_CLK_SOURCE_DBGAPB; off += 4) {
10439 *ctx++ = clk_readl(off);
10442 *ctx++ = clk_readl(RST_DEVICES_L);
10443 *ctx++ = clk_readl(RST_DEVICES_H);
10444 *ctx++ = clk_readl(RST_DEVICES_U);
10445 *ctx++ = clk_readl(RST_DEVICES_V);
10446 *ctx++ = clk_readl(RST_DEVICES_W);
10447 *ctx++ = clk_readl(RST_DEVICES_X);
10448 *ctx++ = clk_readl(RST_DEVICES_Y);
10450 *ctx++ = clk_readl(CLK_OUT_ENB_L);
10451 *ctx++ = clk_readl(CLK_OUT_ENB_H);
10452 *ctx++ = clk_readl(CLK_OUT_ENB_U);
10453 *ctx++ = clk_readl(CLK_OUT_ENB_V);
10454 *ctx++ = clk_readl(CLK_OUT_ENB_W);
10455 *ctx++ = clk_readl(CLK_OUT_ENB_X);
10456 *ctx++ = clk_readl(CLK_OUT_ENB_Y);
10458 *ctx++ = clk_readl(tegra_clk_cclk_g.reg);
10459 *ctx++ = clk_readl(tegra_clk_cclk_g.reg + SUPER_CLK_DIVIDER);
10461 *ctx++ = clk_readl(tegra_clk_cclk_lp.reg);
10462 *ctx++ = clk_readl(tegra_clk_cclk_lp.reg + SUPER_CLK_DIVIDER);
10464 *ctx = clk_get_rate_all_locked(&tegra_clk_emc);
10465 tegra21_emc_clk_suspend(&tegra_clk_emc, *ctx++);
10467 pr_debug("%s: suspend entries: %d, suspend array: %u\n", __func__,
10468 (s32)(ctx - clk_rst_suspend), (u32)ARRAY_SIZE(clk_rst_suspend));
10469 BUG_ON((ctx - clk_rst_suspend) > ARRAY_SIZE(clk_rst_suspend));
10473 static void tegra21_clk_resume(void)
10475 unsigned long off, rate;
10476 const u32 *ctx = clk_rst_suspend;
10477 u32 val, clk_y, pll_u_mask, pll_u_base, pll_u_out12;
10478 u32 pll_p_out_hsio, pll_p_out_mask, pll_p_out34;
10479 u32 pll_a_out0, pll_c_out1, pll_c4_out3, pll_re_out1;
10482 pll_p_out_mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN;
10483 pll_u_mask = (1 << tegra_pll_u_480M.reg_shift) |
10484 (1 << tegra_pll_u_60M.reg_shift) |
10485 (1 << tegra_pll_u_48M.reg_shift);
10488 * OSC frequency selection should be already restored by warm boot
10489 * code, but just in case make sure it does not change across suspend.
10491 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
10493 clk_writel(val, OSC_CTRL);
10494 clk_writel(*ctx++, CPU_SOFTRST_CTRL);
10495 clk_writel(*ctx++, CPU_SOFTRST_CTRL1);
10496 clk_writel(*ctx++, CPU_SOFTRST_CTRL2);
10498 clk_writel(*ctx++, SPARE_REG);
10499 clk_writel(*ctx++, MISC_CLK_ENB);
10500 clk_writel(*ctx++, CLK_MASK_ARM);
10502 /* Since we are going to reset devices and switch clock sources in this
10503 * function, plls and secondary dividers is required to be enabled. The
10504 * actual value will be restored back later. Note that boot plls: pllm,
10505 * and pllp, are already configured and enabled
10507 tegra_pllp_out_resume_enable(&tegra_pll_p_out2); /* expected: NOP */
10508 val = PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
10510 pll_p_out34 = *ctx++;
10511 clk_writel(pll_p_out34 | val, tegra_pll_p_out3.reg);
10513 /* Restore as is, GPU is rail-gated, anyway */
10514 clk_writel(*ctx++, tegra_pll_p_out5.reg);
10516 pll_p_out_hsio = *ctx++;
10517 val = clk_readl(tegra_pll_p_out_hsio.reg) | pll_p_out_mask;
10518 clk_writel(val, tegra_pll_p_out_hsio.reg);
10520 tegra_pllu_out_resume_enable(&tegra_pll_u_out);
10521 val = PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
10522 pll_u_out12 = *ctx++;
10523 clk_writel(pll_u_out12 | val, tegra_pll_u_out1.reg);
10525 pll_u_base = *ctx++;
10526 val = clk_readl(tegra_pll_u_vco.reg) | pll_u_mask;
10527 clk_writel(val, tegra_pll_u_vco.reg);
10529 tegra_pll_clk_resume_enable(&tegra_pll_c);
10530 tegra_pll_clk_resume_enable(&tegra_pll_c2);
10531 tegra_pll_clk_resume_enable(&tegra_pll_c3);
10532 tegra_pll_clk_resume_enable(&tegra_pll_a1);
10533 tegra_pll_clk_resume_enable(&tegra_pll_a);
10534 tegra_pll_clk_resume_enable(&tegra_pll_d);
10535 tegra_pll_clk_resume_enable(&tegra_pll_d2);
10536 tegra_pll_clk_resume_enable(&tegra_pll_dp);
10537 tegra_pll_clk_resume_enable(&tegra_pll_x);
10538 tegra_pll_out_resume_enable(&tegra_pll_c4_out0);
10539 tegra_pll_out_resume_enable(&tegra_pll_re_out);
10543 val = PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
10544 pll_a_out0 = *ctx++;
10545 clk_writel(pll_a_out0 | val, tegra_pll_a_out0.reg);
10546 pll_c_out1 = *ctx++;
10547 clk_writel(pll_c_out1 | val, tegra_pll_c_out1.reg);
10548 pll_c4_out3 = *ctx++;
10549 clk_writel(pll_c4_out3 | val, tegra_pll_c4_out3.reg);
10550 pll_re_out1 = *ctx++;
10551 clk_writel(pll_re_out1 | val, tegra_pll_re_out1.reg);
10554 * To make sure system bus is not over-clocked during restoration:
10555 * - use fixed safe 1:1:2 SCLK:HCLK:PCLK ratio until SCLK source is set
10556 * - defer SCLK divider restoration after SCLK source is restored if
10557 * divider set by boot-rom is above saved value.
10559 clk_writel(0x01, tegra_clk_pclk.reg);
10560 clk_writel_delay(*ctx++, tegra_clk_sclk.reg);
10562 if (val > clk_readl(tegra_clk_sclk_div.reg))
10563 clk_writel_delay(val, tegra_clk_sclk_div.reg);
10564 clk_writel_delay(*ctx++, tegra_clk_sclk_mux.reg);
10565 if (val != clk_readl(tegra_clk_sclk_div.reg))
10566 clk_writel_delay(val, tegra_clk_sclk_div.reg);
10567 clk_writel(*ctx++, tegra_clk_pclk.reg);
10569 /* enable all clocks before configuring clock sources */
10570 clk_writel(CLK_OUT_ENB_L_RESET_MASK, CLK_OUT_ENB_L);
10571 clk_writel(CLK_OUT_ENB_H_RESET_MASK, CLK_OUT_ENB_H);
10572 clk_writel(CLK_OUT_ENB_U_RESET_MASK, CLK_OUT_ENB_U);
10573 clk_writel(CLK_OUT_ENB_V_RESET_MASK, CLK_OUT_ENB_V);
10574 clk_writel(CLK_OUT_ENB_W_RESET_MASK, CLK_OUT_ENB_W);
10575 clk_writel(CLK_OUT_ENB_X_RESET_MASK, CLK_OUT_ENB_X);
10576 clk_writel_delay(CLK_OUT_ENB_Y_RESET_MASK, CLK_OUT_ENB_Y);
10578 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_LA;
10580 if (off == PERIPH_CLK_SOURCE_EMC)
10582 clk_writel(*ctx++, off);
10584 for (off = PERIPH_CLK_SOURCE_MSELECT; off <= PERIPH_CLK_SOURCE_SE;
10586 clk_writel(*ctx++, off);
10588 for (off = AUDIO_DLY_CLK; off <= AUDIO_SYNC_CLK_SPDIF; off+=4) {
10589 clk_writel(*ctx++, off);
10591 for (off = AUDIO_SYNC_CLK_DMIC1;
10592 off <= AUDIO_SYNC_CLK_DMIC2; off += 4) {
10593 clk_writel(*ctx++, off);
10595 for (off = PERIPH_CLK_SOURCE_XUSB_HOST;
10596 off <= PERIPH_CLK_SOURCE_VIC; off += 4) {
10597 if (off == PERIPH_CLK_SOURCE_EMC_DLL)
10599 clk_writel(*ctx++, off);
10601 for (off = PERIPH_CLK_SOURCE_SDMMC_LEGACY;
10602 off <= PERIPH_CLK_SOURCE_NVENC; off += 4) {
10603 clk_writel(*ctx++, off);
10605 for (off = AUDIO_SYNC_CLK_DMIC3;
10606 off <= PERIPH_CLK_SOURCE_DBGAPB; off += 4) {
10607 clk_writel(*ctx++, off);
10611 udelay(RESET_PROPAGATION_DELAY);
10613 clk_writel(*ctx++, RST_DEVICES_L);
10614 clk_writel(*ctx++, RST_DEVICES_H);
10615 clk_writel(*ctx++, RST_DEVICES_U);
10616 clk_writel(*ctx++, RST_DEVICES_V);
10617 clk_writel(*ctx++, RST_DEVICES_W);
10618 clk_writel(*ctx++, RST_DEVICES_X);
10619 clk_writel_delay(*ctx++, RST_DEVICES_Y);
10621 clk_writel(*ctx++, CLK_OUT_ENB_L);
10622 clk_writel(*ctx++, CLK_OUT_ENB_H);
10623 clk_writel(*ctx++, CLK_OUT_ENB_U);
10624 clk_writel(*ctx++, CLK_OUT_ENB_V);
10625 clk_writel(*ctx++, CLK_OUT_ENB_W);
10626 clk_writel(*ctx++, CLK_OUT_ENB_X);
10628 /* Keep pllp_out_cpu enabled */
10630 val = 1 << (tegra_pll_p_out_cpu.u.periph.clk_num % 32);
10631 clk_writel_delay(clk_y | val, CLK_OUT_ENB_Y);
10633 /* DFLL resume after cl_dvfs and i2c5 clocks are resumed */
10634 tegra21_dfll_clk_resume(&tegra_dfll_cpu);
10636 /* CPU G clock restored after DFLL and PLLs */
10637 clk_writel(*ctx++, tegra_clk_cclk_g.reg);
10638 clk_writel(*ctx++, tegra_clk_cclk_g.reg + SUPER_CLK_DIVIDER);
10640 /* CPU LP clock restored after PLLs and pllp_out_cpu branch */
10641 clk_writel(*ctx++, tegra_clk_cclk_lp.reg);
10642 clk_writel_delay(*ctx++, tegra_clk_cclk_lp.reg + SUPER_CLK_DIVIDER);
10644 /* Restore back the actual pll and secondary divider values */
10645 clk_writel(pll_p_out34, tegra_pll_p_out3.reg);
10646 val = clk_readl(tegra_pll_p_out_hsio.reg) & (~pll_p_out_mask);
10647 val |= pll_p_out_hsio & pll_p_out_mask;
10648 clk_writel(val, tegra_pll_p_out_hsio.reg);
10650 clk_writel(pll_u_out12, tegra_pll_u_out1.reg);
10651 val = clk_readl(tegra_pll_u_vco.reg) & (~pll_u_mask);
10652 clk_writel(val | (pll_u_base & pll_u_mask), tegra_pll_u_vco.reg);
10654 clk_writel_delay(clk_y, CLK_OUT_ENB_Y);
10657 if (p->state == OFF)
10658 p->ops->disable(p);
10660 if (p->state == OFF)
10661 p->ops->disable(p);
10663 if (p->state == OFF)
10664 p->ops->disable(p);
10666 if (p->state == OFF)
10667 p->ops->disable(p);
10669 if (p->state == OFF)
10670 p->ops->disable(p);
10672 if (p->state == OFF)
10673 p->ops->disable(p);
10675 if (p->state == OFF)
10676 p->ops->disable(p);
10678 if (p->state == OFF)
10679 p->ops->disable(p);
10681 if (p->state == OFF)
10682 p->ops->disable(p);
10683 p = &tegra_pll_c4_vco;
10684 if (p->state == OFF)
10685 p->ops->disable(p);
10686 p = &tegra_pll_re_vco;
10687 if (p->state == OFF)
10688 p->ops->disable(p);
10690 clk_writel(pll_a_out0, tegra_pll_a_out0.reg);
10691 clk_writel(pll_c_out1, tegra_pll_c_out1.reg);
10692 clk_writel(pll_c4_out3, tegra_pll_c4_out3.reg);
10693 clk_writel(pll_re_out1, tegra_pll_re_out1.reg);
10695 /* Since EMC clock is not restored, and may not preserve parent across
10696 suspend, update current state, and mark EMC DFS as out of sync */
10697 p = tegra_clk_emc.parent;
10698 tegra21_periph_clk_init(&tegra_clk_emc);
10700 /* Turn Off pll_m if it was OFF before suspend, and emc was not switched
10701 to pll_m across suspend; re-init pll_m to sync s/w and h/w states */
10702 if ((tegra_pll_m.state == OFF) &&
10703 (&tegra_pll_m != tegra_clk_emc.parent))
10704 tegra21_pllm_clk_disable(&tegra_pll_m);
10705 tegra21_pllm_clk_init(&tegra_pll_m);
10707 /* Resume pll_mb (FIXME: don't need to enable/disable) */
10708 tegra_pll_clk_resume_enable(&tegra_pll_mb);
10709 if (tegra_pll_mb.state == OFF)
10710 tegra_pll_mb.ops->disable(&tegra_pll_mb);
10712 if (p != tegra_clk_emc.parent) {
10713 pr_debug("EMC parent(refcount) across suspend: %s(%d) : %s(%d)",
10714 p->name, p->refcnt, tegra_clk_emc.parent->name,
10715 tegra_clk_emc.parent->refcnt);
10717 /* emc switched to the new parent by low level code, but ref
10718 count and s/w state need to be updated */
10719 clk_disable_locked(p);
10720 clk_enable_locked(tegra_clk_emc.parent);
10723 /* update DVFS voltage requirements */
10724 rate = clk_get_rate_all_locked(&tegra_clk_emc);
10725 if (*ctx != rate) {
10726 tegra_dvfs_set_rate(&tegra_clk_emc, rate);
10727 if (p == tegra_clk_emc.parent) {
10728 rate = clk_get_rate_all_locked(p);
10729 tegra_dvfs_set_rate(p, rate);
10732 tegra_emc_timing_invalidate();
10734 tegra21_pllu_hw_ctrl_set(&tegra_pll_u_vco); /* PLLU, UTMIP h/w ctrl */
10737 static struct syscore_ops tegra_clk_syscore_ops = {
10738 .suspend = tegra21_clk_suspend,
10739 .resume = tegra21_clk_resume,
10740 .save = tegra21_clk_suspend,
10741 .restore = tegra21_clk_resume,
10745 static void tegra21_init_xusb_clocks(void)
10749 for (i = 0; i < ARRAY_SIZE(tegra_xusb_source_clks); i++)
10750 tegra21_init_one_clock(&tegra_xusb_source_clks[i]);
10752 tegra21_init_one_clock(&tegra_xusb_ss_div2);
10753 tegra21_init_one_clock(&tegra_xusb_hs_src);
10754 tegra21_init_one_clock(&tegra_xusb_ssp_src);
10756 for (i = 0; i < ARRAY_SIZE(tegra_xusb_coupled_clks); i++)
10757 tegra21_init_one_clock(&tegra_xusb_coupled_clks[i]);
10761 * Check if arch timer frequency specified either in DT or in CNTFRQ register is
10762 * matching actual clk_m rate.
10764 static void tegra21_check_timer_clock(u32 clk_m_rate)
10767 struct device_node *dn;
10769 u32 timer_rate = 0;
10771 for_each_compatible_node(dn, NULL, "arm,armv8-timer") {
10772 if (!of_device_is_available(dn))
10775 if (!of_property_read_u32(dn, "clock-frequency", &dt_rate))
10776 timer_rate = dt_rate;
10781 WARN(1, "No arch timer node in DT\n");
10786 timer_rate = arch_timer_get_cntfrq();
10788 if (timer_rate == clk_m_rate)
10791 WARN(1, "Arch timer %s rate %u doesn't match clk_m %u - kernel timing is broken\n",
10792 dt_rate ? "DT" : "CNTFRQ", timer_rate, clk_m_rate);
10796 * The udelay() is implemented based on arch timers, using loops_per_jiffy as
10797 * scaling factor. To make it functional during early clock initialization -
10798 * before timers are initialized - set loops_per_jiffy here.
10800 static void tegra21_init_main_clock(void)
10803 unsigned long clk_m_rate;
10805 for (i = 0; i < ARRAY_SIZE(tegra_main_clks); i++)
10806 tegra21_init_one_clock(tegra_main_clks[i]);
10808 clk_m_rate = clk_get_rate_all_locked(&tegra_clk_m);
10810 loops_per_jiffy = clk_m_rate / HZ;
10812 tegra21_check_timer_clock(clk_m_rate);
10815 void __init tegra21x_init_clocks(void)
10820 #ifndef CONFIG_TEGRA_DUAL_CBUS
10823 tegra21_init_main_clock();
10825 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
10826 tegra21_init_one_clock(tegra_ptr_clks[i]);
10828 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
10829 tegra21_init_one_clock(&tegra_list_clks[i]);
10831 for (i = 0; i < ARRAY_SIZE(tegra_visp_clks); i++)
10832 tegra21_init_one_clock(&tegra_visp_clks[i]);
10834 for (i = 0; i < ARRAY_SIZE(tegra_ptr_camera_mclks); i++)
10835 tegra21_init_one_clock(tegra_ptr_camera_mclks[i]);
10837 for (i = 0; i < ARRAY_SIZE(tegra_sync_source_list); i++)
10838 tegra21_init_one_clock(&tegra_sync_source_list[i]);
10839 for (i = 0; i < ARRAY_SIZE(tegra_clk_audio_list); i++)
10840 tegra21_init_one_clock(&tegra_clk_audio_list[i]);
10841 for (i = 0; i < ARRAY_SIZE(tegra_clk_audio_2x_list); i++)
10842 tegra21_init_one_clock(&tegra_clk_audio_2x_list[i]);
10843 for (i = 0; i < ARRAY_SIZE(tegra_clk_audio_dmic_list); i++)
10844 tegra21_init_one_clock(&tegra_clk_audio_dmic_list[i]);
10846 init_clk_out_mux();
10847 for (i = 0; i < ARRAY_SIZE(tegra_clk_out_list); i++)
10848 tegra21_init_one_clock(&tegra_clk_out_list[i]);
10850 tegra21_init_xusb_clocks();
10852 for (i = 0; i < ARRAY_SIZE(tegra_slcg_clks); i++)
10853 tegra21_init_one_clock(&tegra_slcg_clks[i]);
10855 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
10856 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
10858 pr_err("%s: Unknown duplicate clock %s\n", __func__,
10859 tegra_clk_duplicates[i].name);
10863 tegra_clk_duplicates[i].lookup.clk = c;
10864 clkdev_add(&tegra_clk_duplicates[i].lookup);
10867 /* Check/apply safe rate to clocks with reset dependency on others */
10868 tegra21_periph_check_special_reset();
10870 /* Make sure at list one of dual PLLM/PLLMB is disabled */
10871 tegra21_emc_sync_plls(&tegra_clk_emc, &tegra_pll_m, &tegra_pll_mb);
10873 /* Tegra21 allows to change dividers of disabled clocks */
10874 tegra_clk_set_disabled_div_all();
10876 #ifdef CONFIG_PM_SLEEP
10877 register_syscore_ops(&tegra_clk_syscore_ops);
10880 #ifdef CONFIG_DEBUG_FS
10881 tegra_clk_add_pto_entries(ptodefs);
10885 static int __init tegra21x_clk_late_init(void)
10887 tegra_clk_disable_unprepare(&tegra_pll_re_vco);
10888 tegra_clk_disable_unprepare(tegra_get_clock_by_name("boot.apb.sclk"));
10891 late_initcall(tegra21x_clk_late_init);