3 * NVIDIA Corporation <www.nvidia.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 /* Tegra124 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 Tegra124 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,
57 CLOCK_TYPE_NONE = -1, /* invalid clock type */
61 CLOCK_MAX_MUX = 8 /* number of source options for each clock */
65 * Clock source mux for each clock type. This just converts our enum into
66 * a list of mux sources for use by the code.
69 * The extra column in each clock source array is used to store the mask
70 * bits in its register for the source.
72 #define CLK(x) CLOCK_ID_ ## x
73 static enum clock_id clock_source[CLOCK_TYPE_COUNT][CLOCK_MAX_MUX+1] = {
74 { CLK(AUDIO), CLK(XCPU), CLK(PERIPH), CLK(OSC),
75 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
77 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(AUDIO),
78 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
80 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
81 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
83 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(NONE),
84 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
86 { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC),
87 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
89 { CLK(PERIPH), CLK(DISPLAY), CLK(CGENERAL), CLK(OSC),
90 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
92 { CLK(AUDIO), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
93 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
95 { CLK(AUDIO), CLK(SFROM32KHZ), CLK(PERIPH), CLK(OSC),
96 CLK(EPCI), CLK(NONE), CLK(NONE), CLK(NONE),
98 { CLK(PERIPH), CLK(MEMORY), CLK(DISPLAY), CLK(AUDIO),
99 CLK(CGENERAL), CLK(DISPLAY2), CLK(OSC), CLK(NONE),
101 { CLK(PERIPH), CLK(CGENERAL), CLK(SFROM32KHZ), CLK(OSC),
102 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
105 /* Additional clock types on Tegra114+ */
106 /* CLOCK_TYPE_PC2CC3M */
107 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
108 CLK(MEMORY), CLK(NONE), CLK(NONE), CLK(NONE),
110 /* CLOCK_TYPE_PC2CC3S_T */
111 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
112 CLK(SFROM32KHZ), CLK(NONE), CLK(OSC), CLK(NONE),
114 /* CLOCK_TYPE_PC2CC3M_T */
115 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
116 CLK(MEMORY), CLK(NONE), CLK(OSC), CLK(NONE),
118 /* CLOCK_TYPE_PC2CC3M_T, w/16-bit divisor (I2C) */
119 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
120 CLK(MEMORY), CLK(NONE), CLK(OSC), CLK(NONE),
122 /* CLOCK_TYPE_MC2CC3P_A */
123 { CLK(MEMORY), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
124 CLK(PERIPH), CLK(NONE), CLK(AUDIO), CLK(NONE),
127 { CLK(MEMORY), CLK(NONE), CLK(NONE), CLK(NONE),
128 CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE),
130 /* CLOCK_TYPE_MCPTM2C2C3 */
131 { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC),
132 CLK(MEMORY2), CLK(CGENERAL2), CLK(CGENERAL3), CLK(NONE),
134 /* CLOCK_TYPE_PC2CC3T_S */
135 { CLK(PERIPH), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
136 CLK(OSC), CLK(NONE), CLK(SFROM32KHZ), CLK(NONE),
138 /* CLOCK_TYPE_AC2CC3P_TS2 */
139 { CLK(AUDIO), CLK(CGENERAL2), CLK(CGENERAL), CLK(CGENERAL3),
140 CLK(PERIPH), CLK(NONE), CLK(OSC), CLK(SRC2),
145 * Clock type for each peripheral clock source. We put the name in each
146 * record just so it is easy to match things up
148 #define TYPE(name, type) type
149 static enum clock_type_id clock_periph_type[PERIPHC_COUNT] = {
151 TYPE(PERIPHC_I2S1, CLOCK_TYPE_AXPT),
152 TYPE(PERIPHC_I2S2, CLOCK_TYPE_AXPT),
153 TYPE(PERIPHC_SPDIF_OUT, CLOCK_TYPE_AXPT),
154 TYPE(PERIPHC_SPDIF_IN, CLOCK_TYPE_PC2CC3M),
155 TYPE(PERIPHC_PWM, CLOCK_TYPE_PC2CC3S_T),
156 TYPE(PERIPHC_05h, CLOCK_TYPE_NONE),
157 TYPE(PERIPHC_SBC2, CLOCK_TYPE_PC2CC3M_T),
158 TYPE(PERIPHC_SBC3, CLOCK_TYPE_PC2CC3M_T),
161 TYPE(PERIPHC_08h, CLOCK_TYPE_NONE),
162 TYPE(PERIPHC_I2C1, CLOCK_TYPE_PC2CC3M_T16),
163 TYPE(PERIPHC_I2C5, CLOCK_TYPE_PC2CC3M_T16),
164 TYPE(PERIPHC_0bh, CLOCK_TYPE_NONE),
165 TYPE(PERIPHC_0ch, CLOCK_TYPE_NONE),
166 TYPE(PERIPHC_SBC1, CLOCK_TYPE_PC2CC3M_T),
167 TYPE(PERIPHC_DISP1, CLOCK_TYPE_PMDACD2T),
168 TYPE(PERIPHC_DISP2, CLOCK_TYPE_PMDACD2T),
171 TYPE(PERIPHC_10h, CLOCK_TYPE_NONE),
172 TYPE(PERIPHC_11h, CLOCK_TYPE_NONE),
173 TYPE(PERIPHC_VI, CLOCK_TYPE_MC2CC3P_A),
174 TYPE(PERIPHC_13h, CLOCK_TYPE_NONE),
175 TYPE(PERIPHC_SDMMC1, CLOCK_TYPE_PC2CC3M_T),
176 TYPE(PERIPHC_SDMMC2, CLOCK_TYPE_PC2CC3M_T),
177 TYPE(PERIPHC_16h, CLOCK_TYPE_NONE),
178 TYPE(PERIPHC_17h, CLOCK_TYPE_NONE),
181 TYPE(PERIPHC_18h, CLOCK_TYPE_NONE),
182 TYPE(PERIPHC_SDMMC4, CLOCK_TYPE_PC2CC3M_T),
183 TYPE(PERIPHC_VFIR, CLOCK_TYPE_PC2CC3M_T),
184 TYPE(PERIPHC_1Bh, CLOCK_TYPE_NONE),
185 TYPE(PERIPHC_1Ch, CLOCK_TYPE_NONE),
186 TYPE(PERIPHC_HSI, CLOCK_TYPE_PC2CC3M_T),
187 TYPE(PERIPHC_UART1, CLOCK_TYPE_PC2CC3M_T),
188 TYPE(PERIPHC_UART2, CLOCK_TYPE_PC2CC3M_T),
191 TYPE(PERIPHC_HOST1X, CLOCK_TYPE_MC2CC3P_A),
192 TYPE(PERIPHC_21h, CLOCK_TYPE_NONE),
193 TYPE(PERIPHC_22h, CLOCK_TYPE_NONE),
194 TYPE(PERIPHC_HDMI, CLOCK_TYPE_PMDACD2T),
195 TYPE(PERIPHC_24h, CLOCK_TYPE_NONE),
196 TYPE(PERIPHC_25h, CLOCK_TYPE_NONE),
197 TYPE(PERIPHC_I2C2, CLOCK_TYPE_PC2CC3M_T16),
198 TYPE(PERIPHC_EMC, CLOCK_TYPE_MCPTM2C2C3),
201 TYPE(PERIPHC_UART3, CLOCK_TYPE_PC2CC3M_T),
202 TYPE(PERIPHC_29h, CLOCK_TYPE_NONE),
203 TYPE(PERIPHC_VI_SENSOR, CLOCK_TYPE_MC2CC3P_A),
204 TYPE(PERIPHC_2bh, CLOCK_TYPE_NONE),
205 TYPE(PERIPHC_2ch, CLOCK_TYPE_NONE),
206 TYPE(PERIPHC_SBC4, CLOCK_TYPE_PC2CC3M_T),
207 TYPE(PERIPHC_I2C3, CLOCK_TYPE_PC2CC3M_T16),
208 TYPE(PERIPHC_SDMMC3, CLOCK_TYPE_PC2CC3M_T),
211 TYPE(PERIPHC_UART4, CLOCK_TYPE_PC2CC3M_T),
212 TYPE(PERIPHC_UART5, CLOCK_TYPE_PC2CC3M_T),
213 TYPE(PERIPHC_VDE, CLOCK_TYPE_PC2CC3M_T),
214 TYPE(PERIPHC_OWR, CLOCK_TYPE_PC2CC3M_T),
215 TYPE(PERIPHC_NOR, CLOCK_TYPE_PC2CC3M_T),
216 TYPE(PERIPHC_CSITE, CLOCK_TYPE_PC2CC3M_T),
217 TYPE(PERIPHC_I2S0, CLOCK_TYPE_AXPT),
218 TYPE(PERIPHC_DTV, CLOCK_TYPE_NONE),
221 TYPE(PERIPHC_38h, CLOCK_TYPE_NONE),
222 TYPE(PERIPHC_39h, CLOCK_TYPE_NONE),
223 TYPE(PERIPHC_3ah, CLOCK_TYPE_NONE),
224 TYPE(PERIPHC_3bh, CLOCK_TYPE_NONE),
225 TYPE(PERIPHC_MSENC, CLOCK_TYPE_MC2CC3P_A),
226 TYPE(PERIPHC_TSEC, CLOCK_TYPE_PC2CC3M_T),
227 TYPE(PERIPHC_3eh, CLOCK_TYPE_NONE),
228 TYPE(PERIPHC_OSC, CLOCK_TYPE_NONE),
231 TYPE(PERIPHC_40h, CLOCK_TYPE_NONE), /* start with 0x3b0 */
232 TYPE(PERIPHC_MSELECT, CLOCK_TYPE_PC2CC3M_T),
233 TYPE(PERIPHC_TSENSOR, CLOCK_TYPE_PC2CC3T_S),
234 TYPE(PERIPHC_I2S3, CLOCK_TYPE_AXPT),
235 TYPE(PERIPHC_I2S4, CLOCK_TYPE_AXPT),
236 TYPE(PERIPHC_I2C4, CLOCK_TYPE_PC2CC3M_T16),
237 TYPE(PERIPHC_SBC5, CLOCK_TYPE_PC2CC3M_T),
238 TYPE(PERIPHC_SBC6, CLOCK_TYPE_PC2CC3M_T),
241 TYPE(PERIPHC_AUDIO, CLOCK_TYPE_AC2CC3P_TS2),
242 TYPE(PERIPHC_49h, CLOCK_TYPE_NONE),
243 TYPE(PERIPHC_DAM0, CLOCK_TYPE_AC2CC3P_TS2),
244 TYPE(PERIPHC_DAM1, CLOCK_TYPE_AC2CC3P_TS2),
245 TYPE(PERIPHC_DAM2, CLOCK_TYPE_AC2CC3P_TS2),
246 TYPE(PERIPHC_HDA2CODEC2X, CLOCK_TYPE_PC2CC3M_T),
247 TYPE(PERIPHC_ACTMON, CLOCK_TYPE_PC2CC3S_T),
248 TYPE(PERIPHC_EXTPERIPH1, CLOCK_TYPE_ASPTE),
251 TYPE(PERIPHC_EXTPERIPH2, CLOCK_TYPE_ASPTE),
252 TYPE(PERIPHC_EXTPERIPH3, CLOCK_TYPE_ASPTE),
253 TYPE(PERIPHC_52h, CLOCK_TYPE_NONE),
254 TYPE(PERIPHC_I2CSLOW, CLOCK_TYPE_PC2CC3S_T),
255 TYPE(PERIPHC_SYS, CLOCK_TYPE_NONE),
256 TYPE(PERIPHC_55h, CLOCK_TYPE_NONE),
257 TYPE(PERIPHC_56h, CLOCK_TYPE_NONE),
258 TYPE(PERIPHC_57h, CLOCK_TYPE_NONE),
261 TYPE(PERIPHC_58h, CLOCK_TYPE_NONE),
262 TYPE(PERIPHC_59h, CLOCK_TYPE_NONE),
263 TYPE(PERIPHC_5ah, CLOCK_TYPE_NONE),
264 TYPE(PERIPHC_5bh, CLOCK_TYPE_NONE),
265 TYPE(PERIPHC_SATAOOB, CLOCK_TYPE_PCMT),
266 TYPE(PERIPHC_SATA, CLOCK_TYPE_PCMT),
267 TYPE(PERIPHC_HDA, CLOCK_TYPE_PC2CC3M_T),
268 TYPE(PERIPHC_5fh, CLOCK_TYPE_NONE),
271 TYPE(PERIPHC_XUSB_CORE_HOST, CLOCK_TYPE_NONE),
272 TYPE(PERIPHC_XUSB_FALCON, CLOCK_TYPE_NONE),
273 TYPE(PERIPHC_XUSB_FS, CLOCK_TYPE_NONE),
274 TYPE(PERIPHC_XUSB_CORE_DEV, CLOCK_TYPE_NONE),
275 TYPE(PERIPHC_XUSB_SS, CLOCK_TYPE_NONE),
276 TYPE(PERIPHC_CILAB, CLOCK_TYPE_NONE),
277 TYPE(PERIPHC_CILCD, CLOCK_TYPE_NONE),
278 TYPE(PERIPHC_CILE, CLOCK_TYPE_NONE),
281 TYPE(PERIPHC_DSIA_LP, CLOCK_TYPE_NONE),
282 TYPE(PERIPHC_DSIB_LP, CLOCK_TYPE_NONE),
283 TYPE(PERIPHC_ENTROPY, CLOCK_TYPE_NONE),
284 TYPE(PERIPHC_DVFS_REF, CLOCK_TYPE_NONE),
285 TYPE(PERIPHC_DVFS_SOC, CLOCK_TYPE_NONE),
286 TYPE(PERIPHC_TRACECLKIN, CLOCK_TYPE_NONE),
287 TYPE(PERIPHC_ADX0, CLOCK_TYPE_NONE),
288 TYPE(PERIPHC_AMX0, CLOCK_TYPE_NONE),
291 TYPE(PERIPHC_EMC_LATENCY, CLOCK_TYPE_NONE),
292 TYPE(PERIPHC_SOC_THERM, CLOCK_TYPE_NONE),
293 TYPE(PERIPHC_72h, CLOCK_TYPE_NONE),
294 TYPE(PERIPHC_73h, CLOCK_TYPE_NONE),
295 TYPE(PERIPHC_74h, CLOCK_TYPE_NONE),
296 TYPE(PERIPHC_75h, CLOCK_TYPE_NONE),
297 TYPE(PERIPHC_VI_SENSOR2, CLOCK_TYPE_NONE),
298 TYPE(PERIPHC_I2C6, CLOCK_TYPE_PC2CC3M_T16),
301 TYPE(PERIPHC_78h, CLOCK_TYPE_NONE),
302 TYPE(PERIPHC_EMC_DLL, CLOCK_TYPE_MCPTM2C2C3),
303 TYPE(PERIPHC_HDMI_AUDIO, CLOCK_TYPE_NONE),
304 TYPE(PERIPHC_CLK72MHZ, CLOCK_TYPE_NONE),
305 TYPE(PERIPHC_ADX1, CLOCK_TYPE_AC2CC3P_TS2),
306 TYPE(PERIPHC_AMX1, CLOCK_TYPE_AC2CC3P_TS2),
307 TYPE(PERIPHC_VIC, CLOCK_TYPE_NONE),
308 TYPE(PERIPHC_7Fh, CLOCK_TYPE_NONE),
312 * This array translates a periph_id to a periphc_internal_id
314 * Not present/matched up:
315 * uint vi_sensor; _VI_SENSOR_0, 0x1A8
316 * SPDIF - which is both 0x08 and 0x0c
319 #define NONE(name) (-1)
320 #define OFFSET(name, value) PERIPHC_ ## name
321 static s8 periph_id_to_internal_id[PERIPH_ID_COUNT] = {
330 PERIPHC_UART2, /* and vfir 0x68 */
362 /* Middle word: 63:32 */
374 PERIPHC_SBC1, /* SBCx = SPIx */
402 /* Upper word 95:64 */
564 * Get the oscillator frequency, from the corresponding hardware configuration
565 * field. Note that Tegra30+ support 3 new higher freqs, but we map back
566 * to the old T20 freqs. Support for the higher oscillators is TBD.
568 enum clock_osc_freq clock_get_osc_freq(void)
570 struct clk_rst_ctlr *clkrst =
571 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
574 reg = readl(&clkrst->crc_osc_ctrl);
575 reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT;
577 if (reg & 1) /* one of the newer freqs */
578 printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg);
580 return reg >> 2; /* Map to most common (T20) freqs */
583 /* Returns a pointer to the clock source register for a peripheral */
584 u32 *get_periph_source_reg(enum periph_id periph_id)
586 struct clk_rst_ctlr *clkrst =
587 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
588 enum periphc_internal_id internal_id;
590 /* Coresight is a special case */
591 if (periph_id == PERIPH_ID_CSI)
592 return &clkrst->crc_clk_src[PERIPH_ID_CSI+1];
594 assert(periph_id >= PERIPH_ID_FIRST && periph_id < PERIPH_ID_COUNT);
595 internal_id = periph_id_to_internal_id[periph_id];
596 assert(internal_id != -1);
597 if (internal_id >= PERIPHC_VW_FIRST) {
598 internal_id -= PERIPHC_VW_FIRST;
599 return &clkrst->crc_clk_src_vw[internal_id];
601 return &clkrst->crc_clk_src[internal_id];
606 * Given a peripheral ID and the required source clock, this returns which
607 * value should be programmed into the source mux for that peripheral.
609 * There is special code here to handle the one source type with 5 sources.
611 * @param periph_id peripheral to start
612 * @param source PLL id of required parent clock
613 * @param mux_bits Set to number of bits in mux register: 2 or 4
614 * @param divider_bits Set to number of divider bits (8 or 16)
615 * @return mux value (0-4, or -1 if not found)
617 int get_periph_clock_source(enum periph_id periph_id,
618 enum clock_id parent, int *mux_bits, int *divider_bits)
620 enum clock_type_id type;
621 enum periphc_internal_id internal_id;
624 assert(clock_periph_id_isvalid(periph_id));
626 internal_id = periph_id_to_internal_id[periph_id];
627 assert(periphc_internal_id_isvalid(internal_id));
629 type = clock_periph_type[internal_id];
630 assert(clock_type_id_isvalid(type));
632 *mux_bits = clock_source[type][CLOCK_MAX_MUX];
634 if (type == CLOCK_TYPE_PC2CC3M_T16)
639 for (mux = 0; mux < CLOCK_MAX_MUX; mux++)
640 if (clock_source[type][mux] == parent)
643 /* if we get here, either us or the caller has made a mistake */
644 printf("Caller requested bad clock: periph=%d, parent=%d\n", periph_id,
649 void clock_set_enable(enum periph_id periph_id, int enable)
651 struct clk_rst_ctlr *clkrst =
652 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
656 /* Enable/disable the clock to this peripheral */
657 assert(clock_periph_id_isvalid(periph_id));
658 if ((int)periph_id < (int)PERIPH_ID_VW_FIRST)
659 clk = &clkrst->crc_clk_out_enb[PERIPH_REG(periph_id)];
661 clk = &clkrst->crc_clk_out_enb_vw[PERIPH_REG(periph_id)];
664 reg |= PERIPH_MASK(periph_id);
666 reg &= ~PERIPH_MASK(periph_id);
670 void reset_set_enable(enum periph_id periph_id, int enable)
672 struct clk_rst_ctlr *clkrst =
673 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
677 /* Enable/disable reset to the peripheral */
678 assert(clock_periph_id_isvalid(periph_id));
679 if (periph_id < PERIPH_ID_VW_FIRST)
680 reset = &clkrst->crc_rst_dev[PERIPH_REG(periph_id)];
682 reset = &clkrst->crc_rst_dev_vw[PERIPH_REG(periph_id)];
685 reg |= PERIPH_MASK(periph_id);
687 reg &= ~PERIPH_MASK(periph_id);
691 #ifdef CONFIG_OF_CONTROL
693 * Convert a device tree clock ID to our peripheral ID. They are mostly
694 * the same but we are very cautious so we check that a valid clock ID is
697 * @param clk_id Clock ID according to tegra124 device tree binding
698 * @return peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid
700 enum periph_id clk_id_to_periph_id(int clk_id)
702 if (clk_id > PERIPH_ID_COUNT)
703 return PERIPH_ID_NONE;
706 case PERIPH_ID_RESERVED4:
707 case PERIPH_ID_RESERVED25:
708 case PERIPH_ID_RESERVED35:
709 case PERIPH_ID_RESERVED36:
710 case PERIPH_ID_RESERVED38:
711 case PERIPH_ID_RESERVED43:
712 case PERIPH_ID_RESERVED49:
713 case PERIPH_ID_RESERVED53:
714 case PERIPH_ID_RESERVED64:
715 case PERIPH_ID_RESERVED84:
716 case PERIPH_ID_RESERVED85:
717 case PERIPH_ID_RESERVED86:
718 case PERIPH_ID_RESERVED88:
719 case PERIPH_ID_RESERVED90:
720 case PERIPH_ID_RESERVED92:
721 case PERIPH_ID_RESERVED93:
722 case PERIPH_ID_RESERVED94:
723 case PERIPH_ID_V_RESERVED2:
724 case PERIPH_ID_V_RESERVED4:
725 case PERIPH_ID_V_RESERVED17:
726 case PERIPH_ID_V_RESERVED18:
727 case PERIPH_ID_V_RESERVED19:
728 case PERIPH_ID_V_RESERVED20:
729 case PERIPH_ID_V_RESERVED21:
730 case PERIPH_ID_V_RESERVED22:
731 case PERIPH_ID_W_RESERVED2:
732 case PERIPH_ID_W_RESERVED3:
733 case PERIPH_ID_W_RESERVED4:
734 case PERIPH_ID_W_RESERVED5:
735 case PERIPH_ID_W_RESERVED6:
736 case PERIPH_ID_W_RESERVED7:
737 case PERIPH_ID_W_RESERVED9:
738 case PERIPH_ID_W_RESERVED10:
739 case PERIPH_ID_W_RESERVED11:
740 case PERIPH_ID_W_RESERVED12:
741 case PERIPH_ID_W_RESERVED13:
742 case PERIPH_ID_W_RESERVED15:
743 case PERIPH_ID_W_RESERVED16:
744 case PERIPH_ID_W_RESERVED17:
745 case PERIPH_ID_W_RESERVED18:
746 case PERIPH_ID_W_RESERVED19:
747 case PERIPH_ID_W_RESERVED20:
748 case PERIPH_ID_W_RESERVED23:
749 case PERIPH_ID_W_RESERVED29:
750 case PERIPH_ID_W_RESERVED30:
751 case PERIPH_ID_W_RESERVED31:
752 return PERIPH_ID_NONE;
757 #endif /* CONFIG_OF_CONTROL */
759 void clock_early_init(void)
761 struct clk_rst_ctlr *clkrst =
762 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
764 tegra30_set_up_pllp();
767 * PLLC output frequency set to 600Mhz
768 * PLLD output frequency set to 925Mhz
770 switch (clock_get_osc_freq()) {
771 case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
772 clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8);
773 clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12);
776 case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */
777 clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8);
778 clock_set_rate(CLOCK_ID_DISPLAY, 925, 26, 0, 12);
781 case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
782 clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
783 clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12);
785 case CLOCK_OSC_FREQ_19_2:
788 * These are not supported. It is too early to print a
789 * message and the UART likely won't work anyway due to the
790 * oscillator being wrong.
795 /* PLLC_MISC2: Set dynramp_stepA/B. MISC2 maps to pll_out[1] */
796 writel(0x00561600, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_out[1]);
798 /* PLLC_MISC: Set LOCK_ENABLE */
799 writel(0x01000000, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc);
802 /* PLLD_MISC: Set CLKENABLE, CPCON 12, LFCON 1 */
803 writel(0x40000C10, &clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_misc);
807 void arch_timer_init(void)
809 struct sysctr_ctlr *sysctr = (struct sysctr_ctlr *)NV_PA_TSC_BASE;
812 freq = clock_get_rate(CLOCK_ID_OSC);
813 debug("%s: osc freq is %dHz [0x%08X]\n", __func__, freq, freq);
816 asm("mcr p15, 0, %0, c14, c0, 0\n" : : "r" (freq));
818 /* Only Tegra114+ has the System Counter regs */
819 debug("%s: setting CNTFID0 to 0x%08X\n", __func__, freq);
820 writel(freq, &sysctr->cntfid0);
822 val = readl(&sysctr->cntcr);
823 val |= TSC_CNTCR_ENABLE | TSC_CNTCR_HDBG;
824 writel(val, &sysctr->cntcr);
825 debug("%s: TSC CNTCR = 0x%08X\n", __func__, val);
828 #define PLLE_SS_CNTL 0x68
829 #define PLLE_SS_CNTL_SSCINCINTR(x) (((x) & 0x3f) << 24)
830 #define PLLE_SS_CNTL_SSCINC(x) (((x) & 0xff) << 16)
831 #define PLLE_SS_CNTL_SSCINVERT (1 << 15)
832 #define PLLE_SS_CNTL_SSCCENTER (1 << 14)
833 #define PLLE_SS_CNTL_SSCBYP (1 << 12)
834 #define PLLE_SS_CNTL_INTERP_RESET (1 << 11)
835 #define PLLE_SS_CNTL_BYPASS_SS (1 << 10)
836 #define PLLE_SS_CNTL_SSCMAX(x) (((x) & 0x1ff) << 0)
838 #define PLLE_BASE 0x0e8
839 #define PLLE_BASE_ENABLE (1 << 30)
840 #define PLLE_BASE_LOCK_OVERRIDE (1 << 29)
841 #define PLLE_BASE_PLDIV_CML(x) (((x) & 0xf) << 24)
842 #define PLLE_BASE_NDIV(x) (((x) & 0xff) << 8)
843 #define PLLE_BASE_MDIV(x) (((x) & 0xff) << 0)
845 #define PLLE_MISC 0x0ec
846 #define PLLE_MISC_IDDQ_SWCTL (1 << 14)
847 #define PLLE_MISC_IDDQ_OVERRIDE (1 << 13)
848 #define PLLE_MISC_LOCK_ENABLE (1 << 9)
849 #define PLLE_MISC_PTS (1 << 8)
850 #define PLLE_MISC_VREG_BG_CTRL(x) (((x) & 0x3) << 4)
851 #define PLLE_MISC_VREG_CTRL(x) (((x) & 0x3) << 2)
853 #define PLLE_AUX 0x48c
854 #define PLLE_AUX_SEQ_ENABLE (1 << 24)
855 #define PLLE_AUX_ENABLE_SWCTL (1 << 4)
857 int tegra_plle_enable(void)
859 unsigned int m = 1, n = 200, cpcon = 13;
862 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
863 value &= ~PLLE_BASE_LOCK_OVERRIDE;
864 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
866 value = readl(NV_PA_CLK_RST_BASE + PLLE_AUX);
867 value |= PLLE_AUX_ENABLE_SWCTL;
868 value &= ~PLLE_AUX_SEQ_ENABLE;
869 writel(value, NV_PA_CLK_RST_BASE + PLLE_AUX);
873 value = readl(NV_PA_CLK_RST_BASE + PLLE_MISC);
874 value |= PLLE_MISC_IDDQ_SWCTL;
875 value &= ~PLLE_MISC_IDDQ_OVERRIDE;
876 value |= PLLE_MISC_LOCK_ENABLE;
877 value |= PLLE_MISC_PTS;
878 value |= PLLE_MISC_VREG_BG_CTRL(3);
879 value |= PLLE_MISC_VREG_CTRL(2);
880 writel(value, NV_PA_CLK_RST_BASE + PLLE_MISC);
884 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
885 value |= PLLE_SS_CNTL_SSCBYP | PLLE_SS_CNTL_INTERP_RESET |
886 PLLE_SS_CNTL_BYPASS_SS;
887 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
889 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
890 value &= ~PLLE_BASE_PLDIV_CML(0xf);
891 value &= ~PLLE_BASE_NDIV(0xff);
892 value &= ~PLLE_BASE_MDIV(0xff);
893 value |= PLLE_BASE_PLDIV_CML(cpcon);
894 value |= PLLE_BASE_NDIV(n);
895 value |= PLLE_BASE_MDIV(m);
896 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
900 value = readl(NV_PA_CLK_RST_BASE + PLLE_BASE);
901 value |= PLLE_BASE_ENABLE;
902 writel(value, NV_PA_CLK_RST_BASE + PLLE_BASE);
907 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
908 value &= ~PLLE_SS_CNTL_SSCINVERT;
909 value &= ~PLLE_SS_CNTL_SSCCENTER;
911 value &= ~PLLE_SS_CNTL_SSCINCINTR(0x3f);
912 value &= ~PLLE_SS_CNTL_SSCINC(0xff);
913 value &= ~PLLE_SS_CNTL_SSCMAX(0x1ff);
915 value |= PLLE_SS_CNTL_SSCINCINTR(0x20);
916 value |= PLLE_SS_CNTL_SSCINC(0x01);
917 value |= PLLE_SS_CNTL_SSCMAX(0x25);
919 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
921 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
922 value &= ~PLLE_SS_CNTL_SSCBYP;
923 value &= ~PLLE_SS_CNTL_BYPASS_SS;
924 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
928 value = readl(NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);
929 value &= ~PLLE_SS_CNTL_INTERP_RESET;
930 writel(value, NV_PA_CLK_RST_BASE + PLLE_SS_CNTL);