2 * (C) Copyright 2013-2015
3 * NVIDIA Corporation <www.nvidia.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 /* Tegra210 Clock control functions */
12 #include <asm/arch/clock.h>
13 #include <asm/arch/sysctr.h>
14 #include <asm/arch/tegra.h>
15 #include <asm/arch-tegra/clk_rst.h>
16 #include <asm/arch-tegra/timer.h>
21 * Clock types that we can use as a source. The Tegra210 has muxes for the
22 * peripheral clocks, and in most cases there are four options for the clock
23 * source. This gives us a clock 'type' and exploits what commonality exists
26 * Letters are obvious, except for T which means CLK_M, and S which means the
27 * clock derived from 32KHz. Beware that CLK_M (also called OSC in the
28 * datasheet) and PLL_M are different things. The former is the basic
29 * clock supplied to the SOC from an external oscillator. The latter is the
32 * See definitions in clock_id in the header file.
35 CLOCK_TYPE_AXPT, /* PLL_A, PLL_X, PLL_P, CLK_M */
36 CLOCK_TYPE_MCPA, /* and so on */
49 CLOCK_TYPE_PC2CC3M_T16, /* PC2CC3M_T, but w/16-bit divisor (I2C) */
52 CLOCK_TYPE_MCPTM2C2C3,
54 CLOCK_TYPE_AC2CC3P_TS2,
55 CLOCK_TYPE_PC01C00_C42C41TC40,
58 CLOCK_TYPE_NONE = -1, /* invalid clock type */
62 CLOCK_MAX_MUX = 8 /* number of source options for each clock */
66 * Clock source mux for each clock type. This just converts our enum into
67 * a list of mux sources for use by the code.
70 * The extra column in each clock source array is used to store the mask
71 * bits in its register for the source.
73 #define CLK(x) CLOCK_ID_ ## x
74 static enum clock_id clock_source[CLOCK_TYPE_COUNT][CLOCK_MAX_MUX+1] = {
75 { CLK(AUDIO), CLK(XCPU), CLK(PERIPH), CLK(OSC),
76 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
78 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(AUDIO),
79 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
81 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
82 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
84 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(NONE),
85 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
87 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC),
88 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
90 { CLK(PERIPH), CLK(DISPLAY), CLK(CGENERAL), CLK(OSC),
91 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
93 { CLK(AUDIO), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
94 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
96 { CLK(AUDIO), CLK(SFROM32KHZ), CLK(PERIPH), CLK(OSC),
97 CLK(EPCI), CLK(NONE), CLK(NONE), CLK(NONE),
99 { CLK(PERIPH), CLK(MEMORY), CLK(DISPLAY), CLK(AUDIO),
100 CLK(CGENERAL), CLK(DISPLAY2), CLK(OSC), CLK(NONE),
102 { CLK(PERIPH), CLK(CGENERAL), CLK(SFROM32KHZ), CLK(OSC),
103 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
106 /* Additional clock types on Tegra114+ */
107 /* CLOCK_TYPE_PC2CC3M */
108 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
109 CLK(MEMORY), CLK(NONE), CLK(NONE), CLK(NONE),
111 /* CLOCK_TYPE_PC2CC3S_T */
112 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
113 CLK(SFROM32KHZ), CLK(NONE), CLK(OSC), CLK(NONE),
115 /* CLOCK_TYPE_PC2CC3M_T */
116 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
117 CLK(MEMORY), CLK(NONE), CLK(OSC), CLK(NONE),
119 /* CLOCK_TYPE_PC2CC3M_T, w/16-bit divisor (I2C) */
120 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
121 CLK(MEMORY), CLK(NONE), CLK(OSC), CLK(NONE),
123 /* CLOCK_TYPE_MC2CC3P_A */
124 { CLK(MEMORY), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
125 CLK(PERIPH), CLK(NONE), CLK(AUDIO), CLK(NONE),
128 { CLK(MEMORY), CLK(NONE), CLK(NONE), CLK(NONE),
129 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
131 /* CLOCK_TYPE_MCPTM2C2C3 */
132 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
133 CLK(MEMORY2), CLK(CGENERAL2), CLK(CGENERAL3), CLK(NONE),
135 /* CLOCK_TYPE_PC2CC3T_S */
136 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
137 CLK(OSC), CLK(NONE), CLK(SFROM32KHZ), CLK(NONE),
139 /* CLOCK_TYPE_AC2CC3P_TS2 */
140 { CLK(AUDIO), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
141 CLK(PERIPH), CLK(NONE), CLK(OSC), CLK(SRC2),
143 /* CLOCK_TYPE_PC01C00_C42C41TC40 */
144 { CLK(PERIPH), CLK(CGENERAL_1), CLK(CGENERAL_0), CLK(NONE),
145 CLK(CGENERAL4_2), CLK(CGENERAL4_1), CLK(OSC), CLK(CGENERAL4_0),
150 * Clock type for each peripheral clock source. We put the name in each
151 * record just so it is easy to match things up
153 #define TYPE(name, type) type
154 static enum clock_type_id clock_periph_type[PERIPHC_COUNT] = {
156 TYPE(PERIPHC_I2S2, CLOCK_TYPE_AXPT),
157 TYPE(PERIPHC_I2S3, CLOCK_TYPE_AXPT),
158 TYPE(PERIPHC_SPDIF_OUT, CLOCK_TYPE_AXPT),
159 TYPE(PERIPHC_SPDIF_IN, CLOCK_TYPE_PC2CC3M),
160 TYPE(PERIPHC_PWM, CLOCK_TYPE_PC2CC3S_T),
161 TYPE(PERIPHC_05h, CLOCK_TYPE_NONE),
162 TYPE(PERIPHC_SBC2, CLOCK_TYPE_PC2CC3M_T),
163 TYPE(PERIPHC_SBC3, CLOCK_TYPE_PC2CC3M_T),
166 TYPE(PERIPHC_08h, CLOCK_TYPE_NONE),
167 TYPE(PERIPHC_I2C1, CLOCK_TYPE_PC2CC3M_T16),
168 TYPE(PERIPHC_I2C5, CLOCK_TYPE_PC2CC3M_T16),
169 TYPE(PERIPHC_0bh, CLOCK_TYPE_NONE),
170 TYPE(PERIPHC_0ch, CLOCK_TYPE_NONE),
171 TYPE(PERIPHC_SBC1, CLOCK_TYPE_PC2CC3M_T),
172 TYPE(PERIPHC_DISP1, CLOCK_TYPE_PMDACD2T),
173 TYPE(PERIPHC_DISP2, CLOCK_TYPE_PMDACD2T),
176 TYPE(PERIPHC_10h, CLOCK_TYPE_NONE),
177 TYPE(PERIPHC_11h, CLOCK_TYPE_NONE),
178 TYPE(PERIPHC_VI, CLOCK_TYPE_MC2CC3P_A),
179 TYPE(PERIPHC_13h, CLOCK_TYPE_NONE),
180 TYPE(PERIPHC_SDMMC1, CLOCK_TYPE_PC2CC3M_T),
181 TYPE(PERIPHC_SDMMC2, CLOCK_TYPE_PC2CC3M_T),
182 TYPE(PERIPHC_16h, CLOCK_TYPE_NONE),
183 TYPE(PERIPHC_17h, CLOCK_TYPE_NONE),
186 TYPE(PERIPHC_18h, CLOCK_TYPE_NONE),
187 TYPE(PERIPHC_SDMMC4, CLOCK_TYPE_PC2CC3M_T),
188 TYPE(PERIPHC_VFIR, CLOCK_TYPE_PC2CC3M_T),
189 TYPE(PERIPHC_1Bh, CLOCK_TYPE_NONE),
190 TYPE(PERIPHC_1Ch, CLOCK_TYPE_NONE),
191 TYPE(PERIPHC_HSI, CLOCK_TYPE_PC2CC3M_T),
192 TYPE(PERIPHC_UART1, CLOCK_TYPE_PC2CC3M_T),
193 TYPE(PERIPHC_UART2, CLOCK_TYPE_PC2CC3M_T),
196 TYPE(PERIPHC_HOST1X, CLOCK_TYPE_MC2CC3P_A),
197 TYPE(PERIPHC_21h, CLOCK_TYPE_NONE),
198 TYPE(PERIPHC_22h, CLOCK_TYPE_NONE),
199 TYPE(PERIPHC_23h, CLOCK_TYPE_NONE),
200 TYPE(PERIPHC_24h, CLOCK_TYPE_NONE),
201 TYPE(PERIPHC_25h, CLOCK_TYPE_NONE),
202 TYPE(PERIPHC_I2C2, CLOCK_TYPE_PC2CC3M_T16),
203 TYPE(PERIPHC_EMC, CLOCK_TYPE_MCPTM2C2C3),
206 TYPE(PERIPHC_UART3, CLOCK_TYPE_PC2CC3M_T),
207 TYPE(PERIPHC_29h, CLOCK_TYPE_NONE),
208 TYPE(PERIPHC_VI_SENSOR, CLOCK_TYPE_MC2CC3P_A),
209 TYPE(PERIPHC_2bh, CLOCK_TYPE_NONE),
210 TYPE(PERIPHC_2ch, CLOCK_TYPE_NONE),
211 TYPE(PERIPHC_SBC4, CLOCK_TYPE_PC2CC3M_T),
212 TYPE(PERIPHC_I2C3, CLOCK_TYPE_PC2CC3M_T16),
213 TYPE(PERIPHC_SDMMC3, CLOCK_TYPE_PC2CC3M_T),
216 TYPE(PERIPHC_UART4, CLOCK_TYPE_PC2CC3M_T),
217 TYPE(PERIPHC_UART5, CLOCK_TYPE_PC2CC3M_T),
218 TYPE(PERIPHC_VDE, CLOCK_TYPE_PC2CC3M_T),
219 TYPE(PERIPHC_OWR, CLOCK_TYPE_PC2CC3M_T),
220 TYPE(PERIPHC_NOR, CLOCK_TYPE_PC2CC3M_T),
221 TYPE(PERIPHC_CSITE, CLOCK_TYPE_PC2CC3M_T),
222 TYPE(PERIPHC_I2S1, CLOCK_TYPE_AXPT),
223 TYPE(PERIPHC_DTV, CLOCK_TYPE_NONE),
226 TYPE(PERIPHC_38h, CLOCK_TYPE_NONE),
227 TYPE(PERIPHC_39h, CLOCK_TYPE_NONE),
228 TYPE(PERIPHC_3ah, CLOCK_TYPE_NONE),
229 TYPE(PERIPHC_3bh, CLOCK_TYPE_NONE),
230 TYPE(PERIPHC_MSENC, CLOCK_TYPE_MC2CC3P_A),
231 TYPE(PERIPHC_TSEC, CLOCK_TYPE_PC2CC3M_T),
232 TYPE(PERIPHC_3eh, CLOCK_TYPE_NONE),
233 TYPE(PERIPHC_OSC, CLOCK_TYPE_NONE),
236 TYPE(PERIPHC_40h, CLOCK_TYPE_NONE), /* start with 0x3b0 */
237 TYPE(PERIPHC_MSELECT, CLOCK_TYPE_PC2CC3M_T),
238 TYPE(PERIPHC_TSENSOR, CLOCK_TYPE_PC2CC3T_S),
239 TYPE(PERIPHC_I2S4, CLOCK_TYPE_AXPT),
240 TYPE(PERIPHC_I2S5, CLOCK_TYPE_AXPT),
241 TYPE(PERIPHC_I2C4, CLOCK_TYPE_PC2CC3M_T16),
242 TYPE(PERIPHC_SBC5, CLOCK_TYPE_PC2CC3M_T),
243 TYPE(PERIPHC_SBC6, CLOCK_TYPE_PC2CC3M_T),
246 TYPE(PERIPHC_AUDIO, CLOCK_TYPE_AC2CC3P_TS2),
247 TYPE(PERIPHC_49h, CLOCK_TYPE_NONE),
248 TYPE(PERIPHC_4ah, CLOCK_TYPE_NONE),
249 TYPE(PERIPHC_4bh, CLOCK_TYPE_NONE),
250 TYPE(PERIPHC_4ch, CLOCK_TYPE_NONE),
251 TYPE(PERIPHC_HDA2CODEC2X, CLOCK_TYPE_PC2CC3M_T),
252 TYPE(PERIPHC_ACTMON, CLOCK_TYPE_PC2CC3S_T),
253 TYPE(PERIPHC_EXTPERIPH1, CLOCK_TYPE_ASPTE),
256 TYPE(PERIPHC_EXTPERIPH2, CLOCK_TYPE_ASPTE),
257 TYPE(PERIPHC_EXTPERIPH3, CLOCK_TYPE_ASPTE),
258 TYPE(PERIPHC_52h, CLOCK_TYPE_NONE),
259 TYPE(PERIPHC_I2CSLOW, CLOCK_TYPE_PC2CC3S_T),
260 TYPE(PERIPHC_SYS, CLOCK_TYPE_NONE),
261 TYPE(PERIPHC_55h, CLOCK_TYPE_NONE),
262 TYPE(PERIPHC_56h, CLOCK_TYPE_NONE),
263 TYPE(PERIPHC_57h, CLOCK_TYPE_NONE),
266 TYPE(PERIPHC_58h, CLOCK_TYPE_NONE),
267 TYPE(PERIPHC_59h, CLOCK_TYPE_NONE),
268 TYPE(PERIPHC_5ah, CLOCK_TYPE_NONE),
269 TYPE(PERIPHC_5bh, CLOCK_TYPE_NONE),
270 TYPE(PERIPHC_SATAOOB, CLOCK_TYPE_PCMT),
271 TYPE(PERIPHC_SATA, CLOCK_TYPE_PCMT),
272 TYPE(PERIPHC_HDA, CLOCK_TYPE_PC2CC3M_T),
273 TYPE(PERIPHC_5fh, CLOCK_TYPE_NONE),
276 TYPE(PERIPHC_XUSB_CORE_HOST, CLOCK_TYPE_NONE),
277 TYPE(PERIPHC_XUSB_FALCON, CLOCK_TYPE_NONE),
278 TYPE(PERIPHC_XUSB_FS, CLOCK_TYPE_NONE),
279 TYPE(PERIPHC_XUSB_CORE_DEV, CLOCK_TYPE_NONE),
280 TYPE(PERIPHC_XUSB_SS, CLOCK_TYPE_NONE),
281 TYPE(PERIPHC_CILAB, CLOCK_TYPE_NONE),
282 TYPE(PERIPHC_CILCD, CLOCK_TYPE_NONE),
283 TYPE(PERIPHC_CILE, CLOCK_TYPE_NONE),
286 TYPE(PERIPHC_DSIA_LP, CLOCK_TYPE_NONE),
287 TYPE(PERIPHC_DSIB_LP, CLOCK_TYPE_NONE),
288 TYPE(PERIPHC_ENTROPY, CLOCK_TYPE_NONE),
289 TYPE(PERIPHC_DVFS_REF, CLOCK_TYPE_NONE),
290 TYPE(PERIPHC_DVFS_SOC, CLOCK_TYPE_NONE),
291 TYPE(PERIPHC_TRACECLKIN, CLOCK_TYPE_NONE),
292 TYPE(PERIPHC_6eh, CLOCK_TYPE_NONE),
293 TYPE(PERIPHC_6fh, CLOCK_TYPE_NONE),
296 TYPE(PERIPHC_EMC_LATENCY, CLOCK_TYPE_NONE),
297 TYPE(PERIPHC_SOC_THERM, CLOCK_TYPE_NONE),
298 TYPE(PERIPHC_72h, CLOCK_TYPE_NONE),
299 TYPE(PERIPHC_73h, CLOCK_TYPE_NONE),
300 TYPE(PERIPHC_74h, CLOCK_TYPE_NONE),
301 TYPE(PERIPHC_75h, CLOCK_TYPE_NONE),
302 TYPE(PERIPHC_VI_SENSOR2, CLOCK_TYPE_NONE),
303 TYPE(PERIPHC_I2C6, CLOCK_TYPE_PC2CC3M_T16),
306 TYPE(PERIPHC_78h, CLOCK_TYPE_NONE),
307 TYPE(PERIPHC_EMC_DLL, CLOCK_TYPE_MCPTM2C2C3),
308 TYPE(PERIPHC_7ah, CLOCK_TYPE_NONE),
309 TYPE(PERIPHC_CLK72MHZ, CLOCK_TYPE_NONE),
310 TYPE(PERIPHC_7ch, CLOCK_TYPE_NONE),
311 TYPE(PERIPHC_7dh, CLOCK_TYPE_NONE),
312 TYPE(PERIPHC_VIC, CLOCK_TYPE_NONE),
313 TYPE(PERIPHC_7Fh, CLOCK_TYPE_NONE),
316 TYPE(PERIPHC_SDMMC_LEGACY_TM, CLOCK_TYPE_NONE),
317 TYPE(PERIPHC_NVDEC, CLOCK_TYPE_NONE),
318 TYPE(PERIPHC_NVJPG, CLOCK_TYPE_NONE),
319 TYPE(PERIPHC_NVENC, CLOCK_TYPE_NONE),
320 TYPE(PERIPHC_84h, CLOCK_TYPE_NONE),
321 TYPE(PERIPHC_85h, CLOCK_TYPE_NONE),
322 TYPE(PERIPHC_86h, CLOCK_TYPE_NONE),
323 TYPE(PERIPHC_87h, CLOCK_TYPE_NONE),
326 TYPE(PERIPHC_88h, CLOCK_TYPE_NONE),
327 TYPE(PERIPHC_89h, CLOCK_TYPE_NONE),
328 TYPE(PERIPHC_DMIC3, CLOCK_TYPE_NONE),
329 TYPE(PERIPHC_APE, CLOCK_TYPE_NONE),
330 TYPE(PERIPHC_QSPI, CLOCK_TYPE_PC01C00_C42C41TC40),
331 TYPE(PERIPHC_VI_I2C, CLOCK_TYPE_NONE),
332 TYPE(PERIPHC_USB2_HSIC_TRK, CLOCK_TYPE_NONE),
333 TYPE(PERIPHC_PEX_SATA_USB_RX_BYP, CLOCK_TYPE_NONE),
336 TYPE(PERIPHC_MAUD, CLOCK_TYPE_NONE),
337 TYPE(PERIPHC_TSECB, CLOCK_TYPE_NONE),
341 * This array translates a periph_id to a periphc_internal_id
343 * Not present/matched up:
344 * uint vi_sensor; _VI_SENSOR_0, 0x1A8
345 * SPDIF - which is both 0x08 and 0x0c
348 #define NONE(name) (-1)
349 #define OFFSET(name, value) PERIPHC_ ## name
350 #define INTERNAL_ID(id) (id & 0x000000ff)
351 static s8 periph_id_to_internal_id[PERIPH_ID_COUNT] = {
360 PERIPHC_UART2, /* and vfir 0x68 */
392 /* Middle word: 63:32 */
404 PERIPHC_SBC1, /* SBCx = SPIx */
432 /* Upper word 95:64 */
592 /* Y: 192 (192 - 223) */
594 PERIPHC_SDMMC_LEGACY_TM,
598 PERIPHC_DMIC3, /* 197 */
599 PERIPHC_APE, /* 198 */
613 PERIPHC_VI_I2C, /* 208 */
616 PERIPHC_QSPI, /* 211 */
626 PERIPHC_NVENC, /* 219 */
634 * PLL divider shift/mask tables for all PLL IDs.
636 struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = {
638 * NOTE: If kcp_mask/kvco_mask == 0, they're not used in that PLL (PLLC, etc.)
639 * If lock_ena or lock_det are >31, they're not used in that PLL (PLLC, etc.)
641 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 10, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x1F,
642 .lock_ena = 32, .lock_det = 27, .kcp_shift = 0, .kcp_mask = 0, .kvco_shift = 0, .kvco_mask = 0 }, /* PLLC */
643 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x1F,
644 .lock_ena = 4, .lock_det = 27, .kcp_shift = 1, .kcp_mask = 3, .kvco_shift = 0, .kvco_mask = 1 }, /* PLLM */
645 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 10, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x1F,
646 .lock_ena = 18, .lock_det = 27, .kcp_shift = 0, .kcp_mask = 3, .kvco_shift = 2, .kvco_mask = 1 }, /* PLLP */
647 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x1F,
648 .lock_ena = 28, .lock_det = 27, .kcp_shift = 25, .kcp_mask = 3, .kvco_shift = 24, .kvco_mask = 1 }, /* PLLA */
649 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 16, .p_mask = 0x1F,
650 .lock_ena = 29, .lock_det = 27, .kcp_shift = 25, .kcp_mask = 3, .kvco_shift = 24, .kvco_mask = 1 }, /* PLLU */
651 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 11, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x07,
652 .lock_ena = 18, .lock_det = 27, .kcp_shift = 23, .kcp_mask = 3, .kvco_shift = 22, .kvco_mask = 1 }, /* PLLD */
653 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x1F,
654 .lock_ena = 18, .lock_det = 27, .kcp_shift = 1, .kcp_mask = 3, .kvco_shift = 0, .kvco_mask = 1 }, /* PLLX */
655 { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 0, .p_mask = 0,
656 .lock_ena = 9, .lock_det = 11, .kcp_shift = 6, .kcp_mask = 3, .kvco_shift = 0, .kvco_mask = 1 }, /* PLLE */
657 { .m_shift = 0, .m_mask = 0, .n_shift = 0, .n_mask = 0, .p_shift = 0, .p_mask = 0,
658 .lock_ena = 0, .lock_det = 0, .kcp_shift = 0, .kcp_mask = 0, .kvco_shift = 0, .kvco_mask = 0 }, /* PLLS (gone)*/
662 * Get the oscillator frequency, from the corresponding hardware configuration
663 * field. Note that Tegra30+ support 3 new higher freqs, but we map back
664 * to the old T20 freqs. Support for the higher oscillators is TBD.
666 enum clock_osc_freq clock_get_osc_freq(void)
668 struct clk_rst_ctlr *clkrst =
669 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
672 reg = readl(&clkrst->crc_osc_ctrl);
673 reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
675 * 0 = 13MHz, 1 = 16.8MHz, 4 = 19.2MHz, 5 = 38.4MHz,
676 * 8 = 12MHz, 9 = 48MHz, 12 = 26MHz
679 debug("OSC_FREQ is 38.4MHz (%d) ...\n", reg);
680 /* Map it to the 5th CLOCK_OSC_ enum, i.e. 4 */
685 * Map to most common (T20) freqs (except 38.4, handled above):
686 * 13/16.8 = 0, 19.2 = 1, 12/48 = 2, 26 = 3
691 /* Returns a pointer to the clock source register for a peripheral */
692 u32 *get_periph_source_reg(enum periph_id periph_id)
694 struct clk_rst_ctlr *clkrst =
695 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
696 enum periphc_internal_id internal_id;
698 /* Coresight is a special case */
699 if (periph_id == PERIPH_ID_CSI)
700 return &clkrst->crc_clk_src[PERIPH_ID_CSI+1];
702 assert(periph_id >= PERIPH_ID_FIRST && periph_id < PERIPH_ID_COUNT);
703 internal_id = INTERNAL_ID(periph_id_to_internal_id[periph_id]);
704 assert(internal_id != -1);
706 if (internal_id < PERIPHC_VW_FIRST)
708 return &clkrst->crc_clk_src[internal_id];
710 if (internal_id < PERIPHC_X_FIRST) {
712 internal_id -= PERIPHC_VW_FIRST;
713 return &clkrst->crc_clk_src_vw[internal_id];
716 if (internal_id < PERIPHC_Y_FIRST) {
718 internal_id -= PERIPHC_X_FIRST;
719 return &clkrst->crc_clk_src_x[internal_id];
723 internal_id -= PERIPHC_Y_FIRST;
724 return &clkrst->crc_clk_src_y[internal_id];
728 * Given a peripheral ID and the required source clock, this returns which
729 * value should be programmed into the source mux for that peripheral.
731 * There is special code here to handle the one source type with 5 sources.
733 * @param periph_id peripheral to start
734 * @param source PLL id of required parent clock
735 * @param mux_bits Set to number of bits in mux register: 2 or 4
736 * @param divider_bits Set to number of divider bits (8 or 16)
737 * @return mux value (0-4, or -1 if not found)
739 int get_periph_clock_source(enum periph_id periph_id,
740 enum clock_id parent, int *mux_bits, int *divider_bits)
742 enum clock_type_id type;
743 enum periphc_internal_id internal_id;
746 assert(clock_periph_id_isvalid(periph_id));
748 internal_id = INTERNAL_ID(periph_id_to_internal_id[periph_id]);
749 assert(periphc_internal_id_isvalid(internal_id));
751 type = clock_periph_type[internal_id];
752 assert(clock_type_id_isvalid(type));
754 *mux_bits = clock_source[type][CLOCK_MAX_MUX];
756 if (type == CLOCK_TYPE_PC2CC3M_T16)
761 for (mux = 0; mux < CLOCK_MAX_MUX; mux++)
762 if (clock_source[type][mux] == parent)
765 /* if we get here, either us or the caller has made a mistake */
766 printf("Caller requested bad clock: periph=%d, parent=%d\n", periph_id,
771 void clock_set_enable(enum periph_id periph_id, int enable)
773 struct clk_rst_ctlr *clkrst =
774 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
778 /* Enable/disable the clock to this peripheral */
779 assert(clock_periph_id_isvalid(periph_id));
780 if ((int)periph_id < (int)PERIPH_ID_VW_FIRST)
781 clk = &clkrst->crc_clk_out_enb[PERIPH_REG(periph_id)];
782 else if ((int)periph_id < (int)PERIPH_ID_X_FIRST)
783 clk = &clkrst->crc_clk_out_enb_vw[PERIPH_REG(periph_id)];
784 else if ((int)periph_id < (int)PERIPH_ID_Y_FIRST)
785 clk = &clkrst->crc_clk_out_enb_x;
787 clk = &clkrst->crc_clk_out_enb_y;
791 reg |= PERIPH_MASK(periph_id);
793 reg &= ~PERIPH_MASK(periph_id);
797 void reset_set_enable(enum periph_id periph_id, int enable)
799 struct clk_rst_ctlr *clkrst =
800 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
804 /* Enable/disable reset to the peripheral */
805 assert(clock_periph_id_isvalid(periph_id));
806 if (periph_id < PERIPH_ID_VW_FIRST)
807 reset = &clkrst->crc_rst_dev[PERIPH_REG(periph_id)];
808 else if ((int)periph_id < (int)PERIPH_ID_X_FIRST)
809 reset = &clkrst->crc_rst_dev_vw[PERIPH_REG(periph_id)];
810 else if ((int)periph_id < (int)PERIPH_ID_Y_FIRST)
811 reset = &clkrst->crc_rst_devices_x;
813 reset = &clkrst->crc_rst_devices_y;
817 reg |= PERIPH_MASK(periph_id);
819 reg &= ~PERIPH_MASK(periph_id);
823 #ifdef CONFIG_OF_CONTROL
825 * Convert a device tree clock ID to our peripheral ID. They are mostly
826 * the same but we are very cautious so we check that a valid clock ID is
829 * @param clk_id Clock ID according to tegra210 device tree binding
830 * @return peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid
832 enum periph_id clk_id_to_periph_id(int clk_id)
834 if (clk_id > PERIPH_ID_COUNT)
835 return PERIPH_ID_NONE;
838 case PERIPH_ID_RESERVED4:
839 case PERIPH_ID_RESERVED25:
840 case PERIPH_ID_RESERVED35:
841 case PERIPH_ID_RESERVED36:
842 case PERIPH_ID_RESERVED38:
843 case PERIPH_ID_RESERVED43:
844 case PERIPH_ID_RESERVED49:
845 case PERIPH_ID_RESERVED53:
846 case PERIPH_ID_RESERVED64:
847 case PERIPH_ID_RESERVED84:
848 case PERIPH_ID_RESERVED85:
849 case PERIPH_ID_RESERVED86:
850 case PERIPH_ID_RESERVED88:
851 case PERIPH_ID_RESERVED90:
852 case PERIPH_ID_RESERVED92:
853 case PERIPH_ID_RESERVED93:
854 case PERIPH_ID_RESERVED94:
855 case PERIPH_ID_V_RESERVED2:
856 case PERIPH_ID_V_RESERVED4:
857 case PERIPH_ID_V_RESERVED17:
858 case PERIPH_ID_V_RESERVED18:
859 case PERIPH_ID_V_RESERVED19:
860 case PERIPH_ID_V_RESERVED20:
861 case PERIPH_ID_V_RESERVED21:
862 case PERIPH_ID_V_RESERVED22:
863 case PERIPH_ID_W_RESERVED2:
864 case PERIPH_ID_W_RESERVED3:
865 case PERIPH_ID_W_RESERVED4:
866 case PERIPH_ID_W_RESERVED5:
867 case PERIPH_ID_W_RESERVED6:
868 case PERIPH_ID_W_RESERVED7:
869 case PERIPH_ID_W_RESERVED9:
870 case PERIPH_ID_W_RESERVED10:
871 case PERIPH_ID_W_RESERVED11:
872 case PERIPH_ID_W_RESERVED12:
873 case PERIPH_ID_W_RESERVED13:
874 case PERIPH_ID_W_RESERVED15:
875 case PERIPH_ID_W_RESERVED16:
876 case PERIPH_ID_W_RESERVED17:
877 case PERIPH_ID_W_RESERVED18:
878 case PERIPH_ID_W_RESERVED19:
879 case PERIPH_ID_W_RESERVED20:
880 case PERIPH_ID_W_RESERVED23:
881 case PERIPH_ID_W_RESERVED29:
882 case PERIPH_ID_W_RESERVED30:
883 case PERIPH_ID_W_RESERVED31:
884 return PERIPH_ID_NONE;
889 #endif /* CONFIG_OF_CONTROL */
892 * T210 redefines PLLP_OUT2 as PLLP_VCO/DIVP, so do different OUT1-4 setup here.
893 * PLLP_BASE/MISC/etc. is already set up for 408MHz in the BootROM.
895 void tegra210_setup_pllp(void)
897 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
900 /* Set PLLP_OUT1, 3 & 4 freqs to 9.6, 102 & 204MHz */
903 /* Assert RSTN before enable */
904 reg = PLLP_OUT1_RSTN_EN;
905 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[0]);
906 /* Set divisor and reenable */
907 reg = (IN_408_OUT_9_6_DIVISOR << PLLP_OUT1_RATIO)
908 | PLLP_OUT1_OVR | PLLP_OUT1_CLKEN | PLLP_OUT1_RSTN_DIS;
909 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[0]);
912 /* Assert RSTN before enable */
913 reg = PLLP_OUT4_RSTN_EN | PLLP_OUT3_RSTN_EN;
914 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[1]);
915 /* Set divisor and reenable */
916 reg = (IN_408_OUT_204_DIVISOR << PLLP_OUT4_RATIO)
917 | PLLP_OUT4_OVR | PLLP_OUT4_CLKEN | PLLP_OUT4_RSTN_DIS
918 | (IN_408_OUT_102_DIVISOR << PLLP_OUT3_RATIO)
919 | PLLP_OUT3_OVR | PLLP_OUT3_CLKEN | PLLP_OUT3_RSTN_DIS;
920 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[1]);
923 * NOTE: If you want to change PLLP_OUT2 away from 204MHz,
924 * you can change PLLP_BASE DIVP here. Currently defaults
925 * to 1, which is 2^1, or 2, so PLLP_OUT2 is 204MHz.
926 * See Table 13 in section 5.1.4 in T210 TRM for more info.
930 void clock_early_init(void)
932 struct clk_rst_ctlr *clkrst =
933 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
934 struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_DISPLAY];
937 tegra210_setup_pllp();
940 * PLLC output frequency set to 600Mhz
941 * PLLD output frequency set to 925Mhz
943 switch (clock_get_osc_freq()) {
944 case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
945 clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
946 clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
949 case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */
950 clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8);
951 clock_set_rate(CLOCK_ID_DISPLAY, 925, 26, 0, 12);
954 case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
955 clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
956 clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
958 case CLOCK_OSC_FREQ_19_2:
959 clock_set_rate(CLOCK_ID_CGENERAL, 125, 4, 0, 0);
960 clock_set_rate(CLOCK_ID_DISPLAY, 96, 2, 0, 12);
962 case CLOCK_OSC_FREQ_38_4:
963 clock_set_rate(CLOCK_ID_CGENERAL, 125, 8, 0, 0);
964 clock_set_rate(CLOCK_ID_DISPLAY, 96, 4, 0, 0);
968 * These are not supported. It is too early to print a
969 * message and the UART likely won't work anyway due to the
970 * oscillator being wrong.
975 /* PLLC_MISC1: Turn IDDQ off. NOTE: T210 PLLC_MISC_1 maps to pll_misc */
976 clrbits_le32(&clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc,
981 * PLLC_MISC: Take PLLC out of reset. NOTE: T210 PLLC_MISC maps
984 clrbits_le32(&clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_out[1],
988 /* PLLD_MISC: Set CLKENABLE and LOCK_DETECT bits */
989 data = (1 << PLLD_ENABLE_CLK) | (1 << pllinfo->lock_ena);
990 writel(data, &clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_misc);
994 void arch_timer_init(void)
996 struct sysctr_ctlr *sysctr = (struct sysctr_ctlr *)NV_PA_TSC_BASE;
999 freq = clock_get_rate(CLOCK_ID_OSC);
1000 debug("%s: osc freq is %dHz [0x%08X]\n", __func__, freq, freq);
1003 #ifndef CONFIG_ARM64
1004 asm("mcr p15, 0, %0, c14, c0, 0\n" : : "r" (freq));
1007 /* Only Tegra114+ has the System Counter regs */
1008 debug("%s: setting CNTFID0 to 0x%08X\n", __func__, freq);
1009 writel(freq, &sysctr->cntfid0);
1011 val = readl(&sysctr->cntcr);
1012 val |= TSC_CNTCR_ENABLE | TSC_CNTCR_HDBG;
1013 writel(val, &sysctr->cntcr);
1014 debug("%s: TSC CNTCR = 0x%08X\n", __func__, val);
1017 #define PLLE_SS_CNTL 0x68
1018 #define PLLE_SS_CNTL_SSCINCINTR(x) (((x) & 0x3f) << 24)
1019 #define PLLE_SS_CNTL_SSCINC(x) (((x) & 0xff) << 16)
1020 #define PLLE_SS_CNTL_SSCINVERT (1 << 15)
1021 #define PLLE_SS_CNTL_SSCCENTER (1 << 14)
1022 #define PLLE_SS_CNTL_SSCBYP (1 << 12)
1023 #define PLLE_SS_CNTL_INTERP_RESET (1 << 11)
1024 #define PLLE_SS_CNTL_BYPASS_SS (1 << 10)
1025 #define PLLE_SS_CNTL_SSCMAX(x) (((x) & 0x1ff) << 0)
1027 #define PLLE_BASE 0x0e8
1028 #define PLLE_BASE_ENABLE (1 << 30)
1029 #define PLLE_BASE_LOCK_OVERRIDE (1 << 29)
1030 #define PLLE_BASE_PLDIV_CML(x) (((x) & 0xf) << 24)
1031 #define PLLE_BASE_NDIV(x) (((x) & 0xff) << 8)
1032 #define PLLE_BASE_MDIV(x) (((x) & 0xff) << 0)
1034 #define PLLE_MISC 0x0ec
1035 #define PLLE_MISC_IDDQ_SWCTL (1 << 14)
1036 #define PLLE_MISC_IDDQ_OVERRIDE (1 << 13)
1037 #define PLLE_MISC_LOCK_ENABLE (1 << 9)
1038 #define PLLE_MISC_PTS (1 << 8)
1039 #define PLLE_MISC_VREG_BG_CTRL(x) (((x) & 0x3) << 4)
1040 #define PLLE_MISC_VREG_CTRL(x) (((x) & 0x3) << 2)
1042 #define PLLE_AUX 0x48c
1043 #define PLLE_AUX_SEQ_ENABLE (1 << 24)
1044 #define PLLE_AUX_ENABLE_SWCTL (1 << 4)
1046 int tegra_plle_enable(void)
1048 unsigned int m = 1, n = 200, cpcon = 13;
1051 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
1052 value &= ~PLLE_BASE_LOCK_OVERRIDE;
1053 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
1055 value = readl(NV_PA_CLK_RST_BASE + PLLE_AUX);
1056 value |= PLLE_AUX_ENABLE_SWCTL;
1057 value &= ~PLLE_AUX_SEQ_ENABLE;
1058 writel(value, NV_PA_CLK_RST_BASE + PLLE_AUX);
1062 value = readl(NV_PA_CLK_RST_BASE + PLLE_MISC);
1063 value |= PLLE_MISC_IDDQ_SWCTL;
1064 value &= ~PLLE_MISC_IDDQ_OVERRIDE;
1065 value |= PLLE_MISC_LOCK_ENABLE;
1066 value |= PLLE_MISC_PTS;
1067 value |= PLLE_MISC_VREG_BG_CTRL(3);
1068 value |= PLLE_MISC_VREG_CTRL(2);
1069 writel(value, NV_PA_CLK_RST_BASE + PLLE_MISC);
1073 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1074 value |= PLLE_SS_CNTL_SSCBYP | PLLE_SS_CNTL_INTERP_RESET |
1075 PLLE_SS_CNTL_BYPASS_SS;
1076 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1078 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
1079 value &= ~PLLE_BASE_PLDIV_CML(0xf);
1080 value &= ~PLLE_BASE_NDIV(0xff);
1081 value &= ~PLLE_BASE_MDIV(0xff);
1082 value |= PLLE_BASE_PLDIV_CML(cpcon);
1083 value |= PLLE_BASE_NDIV(n);
1084 value |= PLLE_BASE_MDIV(m);
1085 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
1089 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
1090 value |= PLLE_BASE_ENABLE;
1091 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
1096 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1097 value &= ~PLLE_SS_CNTL_SSCINVERT;
1098 value &= ~PLLE_SS_CNTL_SSCCENTER;
1100 value &= ~PLLE_SS_CNTL_SSCINCINTR(0x3f);
1101 value &= ~PLLE_SS_CNTL_SSCINC(0xff);
1102 value &= ~PLLE_SS_CNTL_SSCMAX(0x1ff);
1104 value |= PLLE_SS_CNTL_SSCINCINTR(0x20);
1105 value |= PLLE_SS_CNTL_SSCINC(0x01);
1106 value |= PLLE_SS_CNTL_SSCMAX(0x25);
1108 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1110 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1111 value &= ~PLLE_SS_CNTL_SSCBYP;
1112 value &= ~PLLE_SS_CNTL_BYPASS_SS;
1113 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1117 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
1118 value &= ~PLLE_SS_CNTL_INTERP_RESET;
1119 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);