1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2010-2019, NVIDIA CORPORATION. All rights reserved.
6 /* Tegra SoC common clock control functions */
15 #include <asm/arch/clock.h>
16 #include <asm/arch/tegra.h>
17 #include <asm/arch-tegra/ap.h>
18 #include <asm/arch-tegra/clk_rst.h>
19 #include <asm/arch-tegra/pmc.h>
20 #include <asm/arch-tegra/timer.h>
21 #include <linux/delay.h>
24 * This is our record of the current clock rate of each clock. We don't
25 * fill all of these in since we are only really interested in clocks which
28 static unsigned pll_rate[CLOCK_ID_COUNT];
31 * The oscillator frequency is fixed to one of seven set values. Based on this
32 * the other clocks are set up appropriately.
34 static unsigned osc_freq[CLOCK_OSC_FREQ_COUNT] = {
50 /* return 1 if a peripheral ID is in range */
51 #define clock_type_id_isvalid(id) ((id) >= 0 && \
52 (id) < CLOCK_TYPE_COUNT)
54 char pllp_valid = 1; /* PLLP is set up correctly */
56 /* return 1 if a periphc_internal_id is in range */
57 #define periphc_internal_id_isvalid(id) ((id) >= 0 && \
60 /* number of clock outputs of a PLL */
61 static const u8 pll_num_clkouts[] = {
70 int clock_get_osc_bypass(void)
72 struct clk_rst_ctlr *clkrst =
73 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
76 reg = readl(&clkrst->crc_osc_ctrl);
77 return (reg & OSC_XOBP_MASK) >> OSC_XOBP_SHIFT;
80 /* Returns a pointer to the registers of the given pll */
81 static struct clk_pll *get_pll(enum clock_id clkid)
83 struct clk_rst_ctlr *clkrst =
84 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
86 assert(clock_id_is_pll(clkid));
87 if (clkid >= (enum clock_id)TEGRA_CLK_PLLS) {
88 debug("%s: Invalid PLL %d\n", __func__, clkid);
91 return &clkrst->crc_pll[clkid];
94 __weak struct clk_pll_simple *clock_get_simple_pll(enum clock_id clkid)
99 int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
100 u32 *divp, u32 *cpcon, u32 *lfcon)
102 struct clk_pll *pll = get_pll(clkid);
103 struct clk_pll_info *pllinfo = &tegra_pll_info_table[clkid];
106 assert(clkid != CLOCK_ID_USB);
108 /* Safety check, adds to code size but is small */
109 if (!clock_id_is_pll(clkid) || clkid == CLOCK_ID_USB)
111 data = readl(&pll->pll_base);
112 *divm = (data >> pllinfo->m_shift) & pllinfo->m_mask;
113 *divn = (data >> pllinfo->n_shift) & pllinfo->n_mask;
114 *divp = (data >> pllinfo->p_shift) & pllinfo->p_mask;
115 data = readl(&pll->pll_misc);
116 /* NOTE: On T210, cpcon/lfcon no longer exist, moved to KCP/KVCO */
117 *cpcon = (data >> pllinfo->kcp_shift) & pllinfo->kcp_mask;
118 *lfcon = (data >> pllinfo->kvco_shift) & pllinfo->kvco_mask;
123 unsigned long clock_start_pll(enum clock_id clkid, u32 divm, u32 divn,
124 u32 divp, u32 cpcon, u32 lfcon)
126 struct clk_pll *pll = NULL;
127 struct clk_pll_info *pllinfo = &tegra_pll_info_table[clkid];
128 struct clk_pll_simple *simple_pll = NULL;
131 if (clkid < (enum clock_id)TEGRA_CLK_PLLS) {
132 pll = get_pll(clkid);
134 simple_pll = clock_get_simple_pll(clkid);
136 debug("%s: Uknown simple PLL %d\n", __func__, clkid);
142 * pllinfo has the m/n/p and kcp/kvco mask and shift
143 * values for all of the PLLs used in U-Boot, with any
144 * SoC differences accounted for.
146 * Preserve EN_LOCKDET, etc.
149 misc_data = readl(&pll->pll_misc);
151 misc_data = readl(&simple_pll->pll_misc);
152 misc_data &= ~(pllinfo->kcp_mask << pllinfo->kcp_shift);
153 misc_data |= cpcon << pllinfo->kcp_shift;
154 misc_data &= ~(pllinfo->kvco_mask << pllinfo->kvco_shift);
155 misc_data |= lfcon << pllinfo->kvco_shift;
157 data = (divm << pllinfo->m_shift) | (divn << pllinfo->n_shift);
158 data |= divp << pllinfo->p_shift;
159 data |= (1 << PLL_ENABLE_SHIFT); /* BYPASS s/b 0 already */
162 writel(misc_data, &pll->pll_misc);
163 writel(data, &pll->pll_base);
165 writel(misc_data, &simple_pll->pll_misc);
166 writel(data, &simple_pll->pll_base);
169 /* calculate the stable time */
170 return timer_get_us() + CLOCK_PLL_STABLE_DELAY_US;
173 void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
176 u32 *reg = get_periph_source_reg(periph_id);
181 value &= ~OUT_CLK_SOURCE_31_30_MASK;
182 value |= source << OUT_CLK_SOURCE_31_30_SHIFT;
184 value &= ~OUT_CLK_DIVISOR_MASK;
185 value |= divisor << OUT_CLK_DIVISOR_SHIFT;
190 int clock_ll_set_source_bits(enum periph_id periph_id, int mux_bits,
193 u32 *reg = get_periph_source_reg(periph_id);
196 case MASK_BITS_31_30:
197 clrsetbits_le32(reg, OUT_CLK_SOURCE_31_30_MASK,
198 source << OUT_CLK_SOURCE_31_30_SHIFT);
201 case MASK_BITS_31_29:
202 clrsetbits_le32(reg, OUT_CLK_SOURCE_31_29_MASK,
203 source << OUT_CLK_SOURCE_31_29_SHIFT);
206 case MASK_BITS_31_28:
207 clrsetbits_le32(reg, OUT_CLK_SOURCE_31_28_MASK,
208 source << OUT_CLK_SOURCE_31_28_SHIFT);
218 static int clock_ll_get_source_bits(enum periph_id periph_id, int mux_bits)
220 u32 *reg = get_periph_source_reg(periph_id);
221 u32 val = readl(reg);
224 case MASK_BITS_31_30:
225 val >>= OUT_CLK_SOURCE_31_30_SHIFT;
226 val &= OUT_CLK_SOURCE_31_30_MASK;
228 case MASK_BITS_31_29:
229 val >>= OUT_CLK_SOURCE_31_29_SHIFT;
230 val &= OUT_CLK_SOURCE_31_29_MASK;
232 case MASK_BITS_31_28:
233 val >>= OUT_CLK_SOURCE_31_28_SHIFT;
234 val &= OUT_CLK_SOURCE_31_28_MASK;
241 void clock_ll_set_source(enum periph_id periph_id, unsigned source)
243 clock_ll_set_source_bits(periph_id, MASK_BITS_31_30, source);
247 * Given the parent's rate and the required rate for the children, this works
248 * out the peripheral clock divider to use, in 7.1 binary format.
250 * @param divider_bits number of divider bits (8 or 16)
251 * @param parent_rate clock rate of parent clock in Hz
252 * @param rate required clock rate for this clock
253 * Return: divider which should be used
255 static int clk_get_divider(unsigned divider_bits, unsigned long parent_rate,
258 u64 divider = parent_rate * 2;
259 unsigned max_divider = 1 << divider_bits;
262 do_div(divider, rate);
264 if ((s64)divider - 2 < 0)
267 if ((s64)divider - 2 >= max_divider)
273 int clock_set_pllout(enum clock_id clkid, enum pll_out_id pllout, unsigned rate)
275 struct clk_pll *pll = get_pll(clkid);
276 int data = 0, div = 0, offset = 0;
278 if (!clock_id_is_pll(clkid))
281 if (pllout + 1 > pll_num_clkouts[clkid])
284 div = clk_get_divider(8, pll_rate[clkid], rate);
289 /* out2 and out4 are in the high part of the register */
290 if (pllout == PLL_OUT2 || pllout == PLL_OUT4)
293 data = (div << PLL_OUT_RATIO_SHIFT) |
294 PLL_OUT_OVRRIDE | PLL_OUT_CLKEN | PLL_OUT_RSTN;
295 clrsetbits_le32(&pll->pll_out[pllout >> 1],
296 PLL_OUT_RATIO_MASK << offset, data << offset);
302 * Given the parent's rate and the divider in 7.1 format, this works out the
303 * resulting peripheral clock rate.
305 * @param parent_rate clock rate of parent clock in Hz
306 * @param divider which should be used in 7.1 format
307 * Return: effective clock rate of peripheral
309 static unsigned long get_rate_from_divider(unsigned long parent_rate,
314 rate = (u64)parent_rate * 2;
315 do_div(rate, divider + 2);
319 unsigned long clock_get_periph_rate(enum periph_id periph_id,
320 enum clock_id parent)
322 u32 *reg = get_periph_source_reg(periph_id);
323 unsigned parent_rate = pll_rate[parent];
324 int div = (readl(reg) & OUT_CLK_DIVISOR_MASK) >> OUT_CLK_DIVISOR_SHIFT;
327 case PERIPH_ID_UART1:
328 case PERIPH_ID_UART2:
329 case PERIPH_ID_UART3:
330 case PERIPH_ID_UART4:
331 case PERIPH_ID_UART5:
332 #ifdef CONFIG_TEGRA20
333 /* There's no divider for these clocks in this SoC. */
337 * This undoes the +2 in get_rate_from_divider() which I
338 * believe is incorrect. Ideally we would fix
339 * get_rate_from_divider(), but... Removing the +2 from
340 * get_rate_from_divider() would probably require remove the -2
341 * from the tail of clk_get_divider() since I believe that's
342 * only there to invert get_rate_from_divider()'s +2. Observe
343 * how find_best_divider() uses those two functions together.
344 * However, doing so breaks other stuff, such as Seaboard's
345 * display, likely due to clock_set_pllout()'s call to
346 * clk_get_divider(). Attempting to fix that by making
347 * clock_set_pllout() subtract 2 from clk_get_divider()'s
348 * return value doesn't help. In summary this clock driver is
349 * quite broken but I'm afraid I have no idea how to fix it
350 * without completely replacing it.
352 * Be careful to avoid a divide by zero error.
362 return get_rate_from_divider(parent_rate, div);
366 * Find the best available 7.1 format divisor given a parent clock rate and
367 * required child clock rate. This function assumes that a second-stage
368 * divisor is available which can divide by powers of 2 from 1 to 256.
370 * @param divider_bits number of divider bits (8 or 16)
371 * @param parent_rate clock rate of parent clock in Hz
372 * @param rate required clock rate for this clock
373 * @param extra_div value for the second-stage divisor (not set if this
374 * function returns -1.
375 * Return: divider which should be used, or -1 if nothing is valid
378 static int find_best_divider(unsigned divider_bits, unsigned long parent_rate,
379 unsigned long rate, int *extra_div)
382 int best_divider = -1;
383 int best_error = rate;
385 /* try dividers from 1 to 256 and find closest match */
386 for (shift = 0; shift <= 8 && best_error > 0; shift++) {
387 unsigned divided_parent = parent_rate >> shift;
388 int divider = clk_get_divider(divider_bits, divided_parent,
390 unsigned effective_rate = get_rate_from_divider(divided_parent,
392 int error = rate - effective_rate;
394 /* Given a valid divider, look for the lowest error */
395 if (divider != -1 && error < best_error) {
397 *extra_div = 1 << shift;
398 best_divider = divider;
402 /* return what we found - *extra_div will already be set */
407 * Adjust peripheral PLL to use the given divider and source.
409 * @param periph_id peripheral to adjust
410 * @param source Source number (0-3 or 0-7)
411 * @param mux_bits Number of mux bits (2 or 4)
412 * @param divider Required divider in 7.1 or 15.1 format
413 * Return: 0 if ok, -1 on error (requesting a parent clock which is not valid
414 * for this peripheral)
416 static int adjust_periph_pll(enum periph_id periph_id, int source,
417 int mux_bits, unsigned divider)
419 u32 *reg = get_periph_source_reg(periph_id);
421 clrsetbits_le32(reg, OUT_CLK_DIVISOR_MASK,
422 divider << OUT_CLK_DIVISOR_SHIFT);
425 /* work out the source clock and set it */
429 clock_ll_set_source_bits(periph_id, mux_bits, source);
435 enum clock_id clock_get_periph_parent(enum periph_id periph_id)
437 int err, mux_bits, divider_bits, type;
440 err = get_periph_clock_info(periph_id, &mux_bits, ÷r_bits, &type);
442 return CLOCK_ID_NONE;
444 source = clock_ll_get_source_bits(periph_id, mux_bits);
446 return get_periph_clock_id(periph_id, source);
449 unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
450 enum clock_id parent, unsigned rate, int *extra_div)
452 unsigned effective_rate;
453 int mux_bits, divider_bits, source;
457 /* work out the source clock and set it */
458 source = get_periph_clock_source(periph_id, parent, &mux_bits,
461 divider = find_best_divider(divider_bits, pll_rate[parent],
466 assert(divider >= 0);
467 if (adjust_periph_pll(periph_id, source, mux_bits, divider))
469 debug("periph %d, rate=%d, reg=%p = %x\n", periph_id, rate,
470 get_periph_source_reg(periph_id),
471 readl(get_periph_source_reg(periph_id)));
473 /* Check what we ended up with. This shouldn't matter though */
474 effective_rate = clock_get_periph_rate(periph_id, parent);
476 effective_rate /= *extra_div;
477 if (rate != effective_rate)
478 debug("Requested clock rate %u not honored (got %u)\n",
479 rate, effective_rate);
480 return effective_rate;
483 unsigned clock_start_periph_pll(enum periph_id periph_id,
484 enum clock_id parent, unsigned rate)
486 unsigned effective_rate;
488 reset_set_enable(periph_id, 1);
489 clock_enable(periph_id);
492 effective_rate = clock_adjust_periph_pll_div(periph_id, parent, rate,
495 reset_set_enable(periph_id, 0);
496 return effective_rate;
499 void clock_enable(enum periph_id clkid)
501 clock_set_enable(clkid, 1);
504 void clock_disable(enum periph_id clkid)
506 clock_set_enable(clkid, 0);
509 void reset_periph(enum periph_id periph_id, int us_delay)
511 /* Put peripheral into reset */
512 reset_set_enable(periph_id, 1);
516 reset_set_enable(periph_id, 0);
521 void reset_cmplx_set_enable(int cpu, int which, int reset)
523 struct clk_rst_ctlr *clkrst =
524 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
527 /* Form the mask, which depends on the cpu chosen (2 or 4) */
528 assert(cpu >= 0 && cpu < MAX_NUM_CPU);
531 /* either enable or disable those reset for that CPU */
533 writel(mask, &clkrst->crc_cpu_cmplx_set);
535 writel(mask, &clkrst->crc_cpu_cmplx_clr);
538 unsigned int __weak clk_m_get_rate(unsigned int parent_rate)
543 unsigned clock_get_rate(enum clock_id clkid)
547 u64 parent_rate, rate;
548 struct clk_pll_info *pllinfo = &tegra_pll_info_table[clkid];
550 parent_rate = osc_freq[clock_get_osc_freq()];
551 if (clkid == CLOCK_ID_OSC)
554 if (clkid == CLOCK_ID_CLK_M)
555 return clk_m_get_rate(parent_rate);
557 pll = get_pll(clkid);
560 base = readl(&pll->pll_base);
562 rate = parent_rate * ((base >> pllinfo->n_shift) & pllinfo->n_mask);
563 divm = (base >> pllinfo->m_shift) & pllinfo->m_mask;
565 * PLLU uses p_mask/p_shift for VCO on all but T210,
566 * T210 uses normal DIVP. Handled in pllinfo table.
568 #ifdef CONFIG_TEGRA210
570 * PLLP's primary output (pllP_out0) on T210 is the VCO, and divp is
571 * not applied. pllP_out2 does have divp applied. All other pllP_outN
572 * are divided down from pllP_out0. We only support pllP_out0 in
573 * U-Boot at the time of writing this comment.
575 if (clkid != CLOCK_ID_PERIPH)
577 divm <<= (base >> pllinfo->p_shift) & pllinfo->p_mask;
583 * Set the output frequency you want for each PLL clock.
584 * PLL output frequencies are programmed by setting their N, M and P values.
585 * The governing equations are:
586 * VCO = (Fi / m) * n, Fo = VCO / (2^p)
587 * where Fo is the output frequency from the PLL.
588 * Example: Set the output frequency to 216Mhz(Fo) with 12Mhz OSC(Fi)
589 * 216Mhz = ((12Mhz / m) * n) / (2^p) so n=432,m=12,p=1
590 * Please see Tegra TRM section 5.3 to get the detail for PLL Programming
592 * @param n PLL feedback divider(DIVN)
593 * @param m PLL input divider(DIVN)
594 * @param p post divider(DIVP)
595 * @param cpcon base PLL charge pump(CPCON)
596 * Return: 0 if ok, -1 on error (the requested PLL is incorrect and cannot
597 * be overridden), 1 if PLL is already correct
599 int clock_set_rate(enum clock_id clkid, u32 n, u32 m, u32 p, u32 cpcon)
601 u32 base_reg, misc_reg;
603 struct clk_pll_info *pllinfo = &tegra_pll_info_table[clkid];
605 pll = get_pll(clkid);
607 base_reg = readl(&pll->pll_base);
609 /* Set BYPASS, m, n and p to PLL_BASE */
610 base_reg &= ~(pllinfo->m_mask << pllinfo->m_shift);
611 base_reg |= m << pllinfo->m_shift;
613 base_reg &= ~(pllinfo->n_mask << pllinfo->n_shift);
614 base_reg |= n << pllinfo->n_shift;
616 base_reg &= ~(pllinfo->p_mask << pllinfo->p_shift);
617 base_reg |= p << pllinfo->p_shift;
619 if (clkid == CLOCK_ID_PERIPH) {
621 * If the PLL is already set up, check that it is correct
622 * and record this info for clock_verify() to check.
624 if (base_reg & PLL_BASE_OVRRIDE_MASK) {
625 base_reg |= PLL_ENABLE_MASK;
626 if (base_reg != readl(&pll->pll_base))
628 return pllp_valid ? 1 : -1;
630 base_reg |= PLL_BASE_OVRRIDE_MASK;
633 base_reg |= PLL_BYPASS_MASK;
634 writel(base_reg, &pll->pll_base);
636 /* Set cpcon (KCP) to PLL_MISC */
637 misc_reg = readl(&pll->pll_misc);
638 misc_reg &= ~(pllinfo->kcp_mask << pllinfo->kcp_shift);
639 misc_reg |= cpcon << pllinfo->kcp_shift;
640 writel(misc_reg, &pll->pll_misc);
643 base_reg |= PLL_ENABLE_MASK;
644 writel(base_reg, &pll->pll_base);
647 base_reg &= ~PLL_BYPASS_MASK;
648 writel(base_reg, &pll->pll_base);
653 void clock_ll_start_uart(enum periph_id periph_id)
655 /* Assert UART reset and enable clock */
656 reset_set_enable(periph_id, 1);
657 clock_enable(periph_id);
658 clock_ll_set_source(periph_id, 0); /* UARTx_CLK_SRC = 00, PLLP_OUT0 */
663 /* De-assert reset to UART */
664 reset_set_enable(periph_id, 0);
667 #if CONFIG_IS_ENABLED(OF_CONTROL)
668 int clock_decode_periph_id(struct udevice *dev)
674 err = dev_read_u32_array(dev, "clocks", cell, ARRAY_SIZE(cell));
677 id = clk_id_to_periph_id(cell[1]);
678 assert(clock_periph_id_isvalid(id));
683 * Get periph clock id and its parent from device tree.
685 * @param dev udevice associated with FDT node
686 * @param clk_id pointer to u32 array of 2 values
687 * first is periph clock, second is
688 * its PLL parent according to FDT.
690 int clock_decode_pair(struct udevice *dev, int *clk_id)
695 err = dev_read_u32_array(dev, "clocks", cell, ARRAY_SIZE(cell));
699 clk_id[0] = clk_id_to_periph_id(cell[1]);
700 clk_id[1] = clk_id_to_pll_id(cell[3]);
704 #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */
706 int clock_verify(void)
708 struct clk_pll *pll = get_pll(CLOCK_ID_PERIPH);
709 u32 reg = readl(&pll->pll_base);
712 printf("Warning: PLLP %x is not correct\n", reg);
715 debug("PLLP %x is correct\n", reg);
719 void clock_init(void)
723 pll_rate[CLOCK_ID_CGENERAL] = clock_get_rate(CLOCK_ID_CGENERAL);
724 pll_rate[CLOCK_ID_MEMORY] = clock_get_rate(CLOCK_ID_MEMORY);
725 pll_rate[CLOCK_ID_PERIPH] = clock_get_rate(CLOCK_ID_PERIPH);
726 pll_rate[CLOCK_ID_USB] = clock_get_rate(CLOCK_ID_USB);
727 pll_rate[CLOCK_ID_DISPLAY] = clock_get_rate(CLOCK_ID_DISPLAY);
728 pll_rate[CLOCK_ID_XCPU] = clock_get_rate(CLOCK_ID_XCPU);
729 pll_rate[CLOCK_ID_SFROM32KHZ] = 32768;
730 pll_rate[CLOCK_ID_OSC] = clock_get_rate(CLOCK_ID_OSC);
731 pll_rate[CLOCK_ID_CLK_M] = clock_get_rate(CLOCK_ID_CLK_M);
733 debug("Osc = %d\n", pll_rate[CLOCK_ID_OSC]);
734 debug("CLKM = %d\n", pll_rate[CLOCK_ID_CLK_M]);
735 debug("PLLC = %d\n", pll_rate[CLOCK_ID_CGENERAL]);
736 debug("PLLM = %d\n", pll_rate[CLOCK_ID_MEMORY]);
737 debug("PLLP = %d\n", pll_rate[CLOCK_ID_PERIPH]);
738 debug("PLLU = %d\n", pll_rate[CLOCK_ID_USB]);
739 debug("PLLD = %d\n", pll_rate[CLOCK_ID_DISPLAY]);
740 debug("PLLX = %d\n", pll_rate[CLOCK_ID_XCPU]);
742 for (i = 0; periph_clk_init_table[i].periph_id != -1; i++) {
743 enum periph_id periph_id;
744 enum clock_id parent;
745 int source, mux_bits, divider_bits;
747 periph_id = periph_clk_init_table[i].periph_id;
748 parent = periph_clk_init_table[i].parent_clock_id;
750 source = get_periph_clock_source(periph_id, parent, &mux_bits,
752 clock_ll_set_source_bits(periph_id, mux_bits, source);
756 static void set_avp_clock_source(u32 src)
758 struct clk_rst_ctlr *clkrst =
759 (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
762 val = (src << SCLK_SWAKEUP_FIQ_SOURCE_SHIFT) |
763 (src << SCLK_SWAKEUP_IRQ_SOURCE_SHIFT) |
764 (src << SCLK_SWAKEUP_RUN_SOURCE_SHIFT) |
765 (src << SCLK_SWAKEUP_IDLE_SOURCE_SHIFT) |
766 (SCLK_SYS_STATE_RUN << SCLK_SYS_STATE_SHIFT);
767 writel(val, &clkrst->crc_sclk_brst_pol);
772 * This function is useful on Tegra30, and any later SoCs that have compatible
773 * PLLP configuration registers.
774 * NOTE: Not used on Tegra210 - see tegra210_setup_pllp in T210 clock.c
776 void tegra30_set_up_pllp(void)
778 struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
782 * Based on the Tegra TRM, the system clock (which is the AVP clock) can
783 * run up to 275MHz. On power on, the default sytem clock source is set
784 * to PLLP_OUT0. This function sets PLLP's (hence PLLP_OUT0's) rate to
785 * 408MHz which is beyond system clock's upper limit.
787 * The fix is to set the system clock to CLK_M before initializing PLLP,
788 * and then switch back to PLLP_OUT4, which has an appropriate divider
789 * configured, after PLLP has been configured
791 set_avp_clock_source(SCLK_SOURCE_CLKM);
794 * PLLP output frequency set to 408Mhz
795 * PLLC output frequency set to 228Mhz
797 switch (clock_get_osc_freq()) {
798 case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */
799 case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */
800 clock_set_rate(CLOCK_ID_PERIPH, 408, 12, 0, 8);
801 clock_set_rate(CLOCK_ID_CGENERAL, 456, 12, 1, 8);
804 case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */
805 clock_set_rate(CLOCK_ID_PERIPH, 408, 26, 0, 8);
806 clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8);
809 case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */
810 case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */
811 clock_set_rate(CLOCK_ID_PERIPH, 408, 13, 0, 8);
812 clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8);
815 case CLOCK_OSC_FREQ_19_2:
816 case CLOCK_OSC_FREQ_38_4:
819 * These are not supported. It is too early to print a
820 * message and the UART likely won't work anyway due to the
821 * oscillator being wrong.
826 /* Set PLLP_OUT1, 2, 3 & 4 freqs to 9.6, 48, 102 & 204MHz */
829 /* Assert RSTN before enable */
830 reg = PLLP_OUT2_RSTN_EN | PLLP_OUT1_RSTN_EN;
831 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[0]);
832 /* Set divisor and reenable */
833 reg = (IN_408_OUT_48_DIVISOR << PLLP_OUT2_RATIO)
834 | PLLP_OUT2_OVR | PLLP_OUT2_CLKEN | PLLP_OUT2_RSTN_DIS
835 | (IN_408_OUT_9_6_DIVISOR << PLLP_OUT1_RATIO)
836 | PLLP_OUT1_OVR | PLLP_OUT1_CLKEN | PLLP_OUT1_RSTN_DIS;
837 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[0]);
840 /* Assert RSTN before enable */
841 reg = PLLP_OUT4_RSTN_EN | PLLP_OUT3_RSTN_EN;
842 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[1]);
843 /* Set divisor and reenable */
844 reg = (IN_408_OUT_204_DIVISOR << PLLP_OUT4_RATIO)
845 | PLLP_OUT4_OVR | PLLP_OUT4_CLKEN | PLLP_OUT4_RSTN_DIS
846 | (IN_408_OUT_102_DIVISOR << PLLP_OUT3_RATIO)
847 | PLLP_OUT3_OVR | PLLP_OUT3_CLKEN | PLLP_OUT3_RSTN_DIS;
848 writel(reg, &clkrst->crc_pll[CLOCK_ID_PERIPH].pll_out[1]);
850 set_avp_clock_source(SCLK_SOURCE_PLLP_OUT4);
853 int clock_external_output(int clk_id)
857 if (clk_id >= 1 && clk_id <= 3) {
858 val = tegra_pmc_readl(offsetof(struct pmc_ctlr,
860 val |= 1 << (2 + (clk_id - 1) * 8);
861 tegra_pmc_writel(val,
862 offsetof(struct pmc_ctlr,
866 printf("%s: Unknown output clock id %d\n", __func__, clk_id);
873 __weak bool clock_early_init_done(void)