2 * arch/arm/mach-tegra/tegra2_clocks.c
4 * Copyright (C) 2010 Google, Inc.
7 * Colin Cross <ccross@google.com>
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/list.h>
23 #include <linux/spinlock.h>
24 #include <linux/delay.h>
26 #include <linux/clk.h>
28 #include <asm/clkdev.h>
30 #include <mach/iomap.h>
31 #include <mach/suspend.h>
36 #define RST_DEVICES 0x004
37 #define RST_DEVICES_SET 0x300
38 #define RST_DEVICES_CLR 0x304
39 #define RST_DEVICES_NUM 3
41 #define CLK_OUT_ENB 0x010
42 #define CLK_OUT_ENB_SET 0x320
43 #define CLK_OUT_ENB_CLR 0x324
44 #define CLK_OUT_ENB_NUM 3
46 #define CLK_MASK_ARM 0x44
47 #define MISC_CLK_ENB 0x48
50 #define OSC_CTRL_OSC_FREQ_MASK (3<<30)
51 #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
52 #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
53 #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
54 #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
55 #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
57 #define OSC_FREQ_DET 0x58
58 #define OSC_FREQ_DET_TRIG (1<<31)
60 #define OSC_FREQ_DET_STATUS 0x5C
61 #define OSC_FREQ_DET_BUSY (1<<31)
62 #define OSC_FREQ_DET_CNT_MASK 0xFFFF
64 #define PERIPH_CLK_SOURCE_I2S1 0x100
65 #define PERIPH_CLK_SOURCE_EMC 0x19c
66 #define PERIPH_CLK_SOURCE_OSC 0x1fc
67 #define PERIPH_CLK_SOURCE_NUM \
68 ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4)
70 #define PERIPH_CLK_SOURCE_MASK (3<<30)
71 #define PERIPH_CLK_SOURCE_SHIFT 30
72 #define PERIPH_CLK_SOURCE_ENABLE (1<<28)
73 #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
74 #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
75 #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
78 #define PLL_BASE_BYPASS (1<<31)
79 #define PLL_BASE_ENABLE (1<<30)
80 #define PLL_BASE_REF_ENABLE (1<<29)
81 #define PLL_BASE_OVERRIDE (1<<28)
82 #define PLL_BASE_DIVP_MASK (0x7<<20)
83 #define PLL_BASE_DIVP_SHIFT 20
84 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
85 #define PLL_BASE_DIVN_SHIFT 8
86 #define PLL_BASE_DIVM_MASK (0x1F)
87 #define PLL_BASE_DIVM_SHIFT 0
89 #define PLL_OUT_RATIO_MASK (0xFF<<8)
90 #define PLL_OUT_RATIO_SHIFT 8
91 #define PLL_OUT_OVERRIDE (1<<2)
92 #define PLL_OUT_CLKEN (1<<1)
93 #define PLL_OUT_RESET_DISABLE (1<<0)
95 #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
97 #define PLL_MISC_DCCON_SHIFT 20
98 #define PLL_MISC_CPCON_SHIFT 8
99 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
100 #define PLL_MISC_LFCON_SHIFT 4
101 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
102 #define PLL_MISC_VCOCON_SHIFT 0
103 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
105 #define PLLU_BASE_POST_DIV (1<<20)
107 #define PLLD_MISC_CLKENABLE (1<<30)
108 #define PLLD_MISC_DIV_RST (1<<23)
109 #define PLLD_MISC_DCCON_SHIFT 12
111 #define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
112 #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
113 #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
115 #define SUPER_CLK_MUX 0x00
116 #define SUPER_STATE_SHIFT 28
117 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
118 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
119 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
120 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
121 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
122 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
123 #define SUPER_SOURCE_MASK 0xF
124 #define SUPER_FIQ_SOURCE_SHIFT 12
125 #define SUPER_IRQ_SOURCE_SHIFT 8
126 #define SUPER_RUN_SOURCE_SHIFT 4
127 #define SUPER_IDLE_SOURCE_SHIFT 0
129 #define SUPER_CLK_DIVIDER 0x04
131 #define BUS_CLK_DISABLE (1<<3)
132 #define BUS_CLK_DIV_MASK 0x3
135 #define PMC_CTRL_BLINK_ENB (1 << 7)
137 #define PMC_DPD_PADS_ORIDE 0x1c
138 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
140 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
141 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
142 #define PMC_BLINK_TIMER_ENB (1 << 15)
143 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
144 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
146 static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
147 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
150 * Some peripheral clocks share an enable bit, so refcount the enable bits
151 * in registers CLK_ENABLE_L, CLK_ENABLE_H, and CLK_ENABLE_U
153 static int tegra_periph_clk_enable_refcount[3 * 32];
155 #define clk_writel(value, reg) \
156 __raw_writel(value, (u32)reg_clk_base + (reg))
157 #define clk_readl(reg) \
158 __raw_readl((u32)reg_clk_base + (reg))
159 #define pmc_writel(value, reg) \
160 __raw_writel(value, (u32)reg_pmc_base + (reg))
161 #define pmc_readl(reg) \
162 __raw_readl((u32)reg_pmc_base + (reg))
164 unsigned long clk_measure_input_freq(void)
166 u32 clock_autodetect;
167 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
168 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
169 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
170 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
172 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
174 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
176 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
179 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
185 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
187 s64 divider_u71 = parent_rate * 2;
188 divider_u71 += rate - 1;
189 do_div(divider_u71, rate);
191 if (divider_u71 - 2 < 0)
194 if (divider_u71 - 2 > 255)
197 return divider_u71 - 2;
200 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
204 divider_u16 = parent_rate;
205 divider_u16 += rate - 1;
206 do_div(divider_u16, rate);
208 if (divider_u16 - 1 < 0)
211 if (divider_u16 - 1 > 255)
214 return divider_u16 - 1;
217 /* clk_m functions */
218 static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
220 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
222 c->rate = clk_measure_input_freq();
225 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
228 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
231 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
234 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
237 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
240 clk_writel(auto_clock_control, OSC_CTRL);
244 static void tegra2_clk_m_init(struct clk *c)
246 pr_debug("%s on clock %s\n", __func__, c->name);
247 tegra2_clk_m_autodetect_rate(c);
250 static int tegra2_clk_m_enable(struct clk *c)
252 pr_debug("%s on clock %s\n", __func__, c->name);
256 static void tegra2_clk_m_disable(struct clk *c)
258 pr_debug("%s on clock %s\n", __func__, c->name);
262 static struct clk_ops tegra_clk_m_ops = {
263 .init = tegra2_clk_m_init,
264 .enable = tegra2_clk_m_enable,
265 .disable = tegra2_clk_m_disable,
268 void tegra2_periph_reset_assert(struct clk *c)
270 BUG_ON(!c->ops->reset);
271 c->ops->reset(c, true);
274 void tegra2_periph_reset_deassert(struct clk *c)
276 BUG_ON(!c->ops->reset);
277 c->ops->reset(c, false);
280 /* super clock functions */
281 /* "super clocks" on tegra have two-stage muxes and a clock skipping
282 * super divider. We will ignore the clock skipping divider, since we
283 * can't lower the voltage when using the clock skip, but we can if we
284 * lower the PLL frequency.
286 static void tegra2_super_clk_init(struct clk *c)
291 const struct clk_mux_sel *sel;
292 val = clk_readl(c->reg + SUPER_CLK_MUX);
294 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
295 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
296 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
297 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
298 source = (val >> shift) & SUPER_SOURCE_MASK;
299 for (sel = c->inputs; sel->input != NULL; sel++) {
300 if (sel->value == source)
303 BUG_ON(sel->input == NULL);
304 c->parent = sel->input;
307 static int tegra2_super_clk_enable(struct clk *c)
309 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
313 static void tegra2_super_clk_disable(struct clk *c)
315 pr_debug("%s on clock %s\n", __func__, c->name);
317 /* oops - don't disable the CPU clock! */
321 static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
324 const struct clk_mux_sel *sel;
327 val = clk_readl(c->reg + SUPER_CLK_MUX);;
328 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
329 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
330 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
331 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
332 for (sel = c->inputs; sel->input != NULL; sel++) {
333 if (sel->input == p) {
334 val &= ~(SUPER_SOURCE_MASK << shift);
335 val |= sel->value << shift;
340 clk_writel(val, c->reg);
342 if (c->refcnt && c->parent)
343 clk_disable(c->parent);
353 * Super clocks have "clock skippers" instead of dividers. Dividing using
354 * a clock skipper does not allow the voltage to be scaled down, so instead
355 * adjust the rate of the parent clock. This requires that the parent of a
356 * super clock have no other children, otherwise the rate will change
357 * underneath the other children.
359 static int tegra2_super_clk_set_rate(struct clk *c, unsigned long rate)
361 return clk_set_rate(c->parent, rate);
364 static struct clk_ops tegra_super_ops = {
365 .init = tegra2_super_clk_init,
366 .enable = tegra2_super_clk_enable,
367 .disable = tegra2_super_clk_disable,
368 .set_parent = tegra2_super_clk_set_parent,
369 .set_rate = tegra2_super_clk_set_rate,
372 /* virtual cpu clock functions */
373 /* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
374 To change the frequency of these clocks, the parent pll may need to be
375 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
376 and then the clock moved back to the pll. To hide this sequence, a virtual
379 static void tegra2_cpu_clk_init(struct clk *c)
383 static int tegra2_cpu_clk_enable(struct clk *c)
388 static void tegra2_cpu_clk_disable(struct clk *c)
390 pr_debug("%s on clock %s\n", __func__, c->name);
392 /* oops - don't disable the CPU clock! */
396 static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
400 * Take an extra reference to the main pll so it doesn't turn
401 * off when we move the cpu off of it
403 clk_enable(c->u.cpu.main);
405 ret = clk_set_parent(c->parent, c->u.cpu.backup);
407 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
411 if (rate == clk_get_rate(c->u.cpu.backup))
414 ret = clk_set_rate(c->u.cpu.main, rate);
416 pr_err("Failed to change cpu pll to %lu\n", rate);
420 ret = clk_set_parent(c->parent, c->u.cpu.main);
422 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
427 clk_disable(c->u.cpu.main);
431 static struct clk_ops tegra_cpu_ops = {
432 .init = tegra2_cpu_clk_init,
433 .enable = tegra2_cpu_clk_enable,
434 .disable = tegra2_cpu_clk_disable,
435 .set_rate = tegra2_cpu_clk_set_rate,
438 /* virtual cop clock functions. Used to acquire the fake 'cop' clock to
439 * reset the COP block (i.e. AVP) */
440 static void tegra2_cop_clk_reset(struct clk *c, bool assert)
442 unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
444 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
445 clk_writel(1 << 1, reg);
448 static struct clk_ops tegra_cop_ops = {
449 .reset = tegra2_cop_clk_reset,
452 /* bus clock functions */
453 static void tegra2_bus_clk_init(struct clk *c)
455 u32 val = clk_readl(c->reg);
456 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
457 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
461 static int tegra2_bus_clk_enable(struct clk *c)
463 u32 val = clk_readl(c->reg);
464 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
465 clk_writel(val, c->reg);
469 static void tegra2_bus_clk_disable(struct clk *c)
471 u32 val = clk_readl(c->reg);
472 val |= BUS_CLK_DISABLE << c->reg_shift;
473 clk_writel(val, c->reg);
476 static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
478 u32 val = clk_readl(c->reg);
479 unsigned long parent_rate = clk_get_rate(c->parent);
481 for (i = 1; i <= 4; i++) {
482 if (rate == parent_rate / i) {
483 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
484 val |= (i - 1) << c->reg_shift;
485 clk_writel(val, c->reg);
494 static struct clk_ops tegra_bus_ops = {
495 .init = tegra2_bus_clk_init,
496 .enable = tegra2_bus_clk_enable,
497 .disable = tegra2_bus_clk_disable,
498 .set_rate = tegra2_bus_clk_set_rate,
501 /* Blink output functions */
503 static void tegra2_blink_clk_init(struct clk *c)
507 val = pmc_readl(PMC_CTRL);
508 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
510 val = pmc_readl(c->reg);
512 if (val & PMC_BLINK_TIMER_ENB) {
515 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
516 PMC_BLINK_TIMER_DATA_ON_MASK;
517 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
518 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
520 /* each tick in the blink timer is 4 32KHz clocks */
527 static int tegra2_blink_clk_enable(struct clk *c)
531 val = pmc_readl(PMC_DPD_PADS_ORIDE);
532 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
534 val = pmc_readl(PMC_CTRL);
535 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
540 static void tegra2_blink_clk_disable(struct clk *c)
544 val = pmc_readl(PMC_CTRL);
545 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
547 val = pmc_readl(PMC_DPD_PADS_ORIDE);
548 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
551 static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
553 unsigned long parent_rate = clk_get_rate(c->parent);
554 if (rate >= parent_rate) {
556 pmc_writel(0, c->reg);
561 on_off = DIV_ROUND_UP(parent_rate / 8, rate);
564 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
565 PMC_BLINK_TIMER_DATA_ON_SHIFT;
566 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
567 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
569 val |= PMC_BLINK_TIMER_ENB;
570 pmc_writel(val, c->reg);
576 static struct clk_ops tegra_blink_clk_ops = {
577 .init = &tegra2_blink_clk_init,
578 .enable = &tegra2_blink_clk_enable,
579 .disable = &tegra2_blink_clk_disable,
580 .set_rate = &tegra2_blink_clk_set_rate,
584 static int tegra2_pll_clk_wait_for_lock(struct clk *c)
586 udelay(c->u.pll.lock_delay);
591 static void tegra2_pll_clk_init(struct clk *c)
593 u32 val = clk_readl(c->reg + PLL_BASE);
595 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
597 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
598 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
601 } else if (val & PLL_BASE_BYPASS) {
605 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
606 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
608 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
610 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
614 static int tegra2_pll_clk_enable(struct clk *c)
617 pr_debug("%s on clock %s\n", __func__, c->name);
619 val = clk_readl(c->reg + PLL_BASE);
620 val &= ~PLL_BASE_BYPASS;
621 val |= PLL_BASE_ENABLE;
622 clk_writel(val, c->reg + PLL_BASE);
624 tegra2_pll_clk_wait_for_lock(c);
629 static void tegra2_pll_clk_disable(struct clk *c)
632 pr_debug("%s on clock %s\n", __func__, c->name);
634 val = clk_readl(c->reg);
635 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
636 clk_writel(val, c->reg);
639 static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
642 unsigned long input_rate;
643 const struct clk_pll_freq_table *sel;
645 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
647 input_rate = clk_get_rate(c->parent);
648 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
649 if (sel->input_rate == input_rate && sel->output_rate == rate) {
651 c->div = sel->m * sel->p;
653 val = clk_readl(c->reg + PLL_BASE);
654 if (c->flags & PLL_FIXED)
655 val |= PLL_BASE_OVERRIDE;
656 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
658 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
659 (sel->n << PLL_BASE_DIVN_SHIFT);
660 BUG_ON(sel->p < 1 || sel->p > 2);
661 if (c->flags & PLLU) {
663 val |= PLLU_BASE_POST_DIV;
666 val |= 1 << PLL_BASE_DIVP_SHIFT;
668 clk_writel(val, c->reg + PLL_BASE);
670 if (c->flags & PLL_HAS_CPCON) {
671 val = clk_readl(c->reg + PLL_MISC(c));
672 val &= ~PLL_MISC_CPCON_MASK;
673 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
674 clk_writel(val, c->reg + PLL_MISC(c));
678 tegra2_pll_clk_enable(c);
686 static struct clk_ops tegra_pll_ops = {
687 .init = tegra2_pll_clk_init,
688 .enable = tegra2_pll_clk_enable,
689 .disable = tegra2_pll_clk_disable,
690 .set_rate = tegra2_pll_clk_set_rate,
693 static void tegra2_pllx_clk_init(struct clk *c)
695 tegra2_pll_clk_init(c);
697 if (tegra_sku_id() == 7)
698 c->max_rate = 750000000;
701 static struct clk_ops tegra_pllx_ops = {
702 .init = tegra2_pllx_clk_init,
703 .enable = tegra2_pll_clk_enable,
704 .disable = tegra2_pll_clk_disable,
705 .set_rate = tegra2_pll_clk_set_rate,
708 /* Clock divider ops */
709 static void tegra2_pll_div_clk_init(struct clk *c)
711 u32 val = clk_readl(c->reg);
713 val >>= c->reg_shift;
714 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
715 if (!(val & PLL_OUT_RESET_DISABLE))
718 if (c->flags & DIV_U71) {
719 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
720 c->div = (divu71 + 2);
722 } else if (c->flags & DIV_2) {
731 static int tegra2_pll_div_clk_enable(struct clk *c)
736 pr_debug("%s: %s\n", __func__, c->name);
737 if (c->flags & DIV_U71) {
738 val = clk_readl(c->reg);
739 new_val = val >> c->reg_shift;
742 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
744 val &= ~(0xFFFF << c->reg_shift);
745 val |= new_val << c->reg_shift;
746 clk_writel(val, c->reg);
748 } else if (c->flags & DIV_2) {
749 BUG_ON(!(c->flags & PLLD));
750 val = clk_readl(c->reg);
751 val &= ~PLLD_MISC_DIV_RST;
752 clk_writel(val, c->reg);
758 static void tegra2_pll_div_clk_disable(struct clk *c)
763 pr_debug("%s: %s\n", __func__, c->name);
764 if (c->flags & DIV_U71) {
765 val = clk_readl(c->reg);
766 new_val = val >> c->reg_shift;
769 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
771 val &= ~(0xFFFF << c->reg_shift);
772 val |= new_val << c->reg_shift;
773 clk_writel(val, c->reg);
774 } else if (c->flags & DIV_2) {
775 BUG_ON(!(c->flags & PLLD));
776 val = clk_readl(c->reg);
777 val |= PLLD_MISC_DIV_RST;
778 clk_writel(val, c->reg);
782 static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
787 unsigned long parent_rate = clk_get_rate(c->parent);
789 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
790 if (c->flags & DIV_U71) {
791 divider_u71 = clk_div71_get_divider(parent_rate, rate);
792 if (divider_u71 >= 0) {
793 val = clk_readl(c->reg);
794 new_val = val >> c->reg_shift;
796 if (c->flags & DIV_U71_FIXED)
797 new_val |= PLL_OUT_OVERRIDE;
798 new_val &= ~PLL_OUT_RATIO_MASK;
799 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
801 val &= ~(0xFFFF << c->reg_shift);
802 val |= new_val << c->reg_shift;
803 clk_writel(val, c->reg);
804 c->div = divider_u71 + 2;
808 } else if (c->flags & DIV_2) {
809 if (parent_rate == rate * 2)
815 static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
818 unsigned long parent_rate = clk_get_rate(c->parent);
819 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
821 if (c->flags & DIV_U71) {
822 divider = clk_div71_get_divider(parent_rate, rate);
825 return parent_rate * 2 / (divider + 2);
826 } else if (c->flags & DIV_2) {
827 return parent_rate / 2;
832 static struct clk_ops tegra_pll_div_ops = {
833 .init = tegra2_pll_div_clk_init,
834 .enable = tegra2_pll_div_clk_enable,
835 .disable = tegra2_pll_div_clk_disable,
836 .set_rate = tegra2_pll_div_clk_set_rate,
837 .round_rate = tegra2_pll_div_clk_round_rate,
842 static void tegra2_periph_clk_init(struct clk *c)
844 u32 val = clk_readl(c->reg);
845 const struct clk_mux_sel *mux = 0;
846 const struct clk_mux_sel *sel;
847 if (c->flags & MUX) {
848 for (sel = c->inputs; sel->input != NULL; sel++) {
849 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
854 c->parent = mux->input;
856 c->parent = c->inputs[0].input;
859 if (c->flags & DIV_U71) {
860 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
863 } else if (c->flags & DIV_U16) {
864 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
873 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
874 PERIPH_CLK_TO_ENB_BIT(c)))
876 if (!(c->flags & PERIPH_NO_RESET))
877 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
878 PERIPH_CLK_TO_ENB_BIT(c))
882 static int tegra2_periph_clk_enable(struct clk *c)
885 pr_debug("%s on clock %s\n", __func__, c->name);
887 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
888 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1)
891 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
892 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
893 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
894 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
895 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
896 if (c->flags & PERIPH_EMC_ENB) {
897 /* The EMC peripheral clock has 2 extra enable bits */
898 /* FIXME: Do they need to be disabled? */
899 val = clk_readl(c->reg);
901 clk_writel(val, c->reg);
906 static void tegra2_periph_clk_disable(struct clk *c)
908 pr_debug("%s on clock %s\n", __func__, c->name);
911 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
913 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] == 0)
914 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
915 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
918 static void tegra2_periph_clk_reset(struct clk *c, bool assert)
920 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
922 pr_debug("%s %s on clock %s\n", __func__,
923 assert ? "assert" : "deassert", c->name);
924 if (!(c->flags & PERIPH_NO_RESET))
925 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
926 base + PERIPH_CLK_TO_ENB_SET_REG(c));
929 static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
932 const struct clk_mux_sel *sel;
933 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
934 for (sel = c->inputs; sel->input != NULL; sel++) {
935 if (sel->input == p) {
936 val = clk_readl(c->reg);
937 val &= ~PERIPH_CLK_SOURCE_MASK;
938 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
943 clk_writel(val, c->reg);
945 if (c->refcnt && c->parent)
946 clk_disable(c->parent);
956 static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
960 unsigned long parent_rate = clk_get_rate(c->parent);
962 if (c->flags & DIV_U71) {
963 divider = clk_div71_get_divider(parent_rate, rate);
965 val = clk_readl(c->reg);
966 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
968 clk_writel(val, c->reg);
969 c->div = divider + 2;
973 } else if (c->flags & DIV_U16) {
974 divider = clk_div16_get_divider(parent_rate, rate);
976 val = clk_readl(c->reg);
977 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
979 clk_writel(val, c->reg);
980 c->div = divider + 1;
984 } else if (parent_rate <= rate) {
992 static long tegra2_periph_clk_round_rate(struct clk *c,
996 unsigned long parent_rate = clk_get_rate(c->parent);
997 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
999 if (c->flags & DIV_U71) {
1000 divider = clk_div71_get_divider(parent_rate, rate);
1004 return parent_rate * 2 / (divider + 2);
1005 } else if (c->flags & DIV_U16) {
1006 divider = clk_div16_get_divider(parent_rate, rate);
1009 return parent_rate / (divider + 1);
1014 static struct clk_ops tegra_periph_clk_ops = {
1015 .init = &tegra2_periph_clk_init,
1016 .enable = &tegra2_periph_clk_enable,
1017 .disable = &tegra2_periph_clk_disable,
1018 .set_parent = &tegra2_periph_clk_set_parent,
1019 .set_rate = &tegra2_periph_clk_set_rate,
1020 .round_rate = &tegra2_periph_clk_round_rate,
1021 .reset = &tegra2_periph_clk_reset,
1024 /* Clock doubler ops */
1025 static void tegra2_clk_double_init(struct clk *c)
1030 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1031 PERIPH_CLK_TO_ENB_BIT(c)))
1035 static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1037 if (rate != 2 * clk_get_rate(c->parent))
1044 static struct clk_ops tegra_clk_double_ops = {
1045 .init = &tegra2_clk_double_init,
1046 .enable = &tegra2_periph_clk_enable,
1047 .disable = &tegra2_periph_clk_disable,
1048 .set_rate = &tegra2_clk_double_set_rate,
1051 /* Audio sync clock ops */
1052 static void tegra2_audio_sync_clk_init(struct clk *c)
1055 const struct clk_mux_sel *sel;
1056 u32 val = clk_readl(c->reg);
1057 c->state = (val & (1<<4)) ? OFF : ON;
1059 for (sel = c->inputs; sel->input != NULL; sel++)
1060 if (sel->value == source)
1062 BUG_ON(sel->input == NULL);
1063 c->parent = sel->input;
1066 static int tegra2_audio_sync_clk_enable(struct clk *c)
1068 clk_writel(0, c->reg);
1072 static void tegra2_audio_sync_clk_disable(struct clk *c)
1074 clk_writel(1, c->reg);
1077 static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1080 const struct clk_mux_sel *sel;
1081 for (sel = c->inputs; sel->input != NULL; sel++) {
1082 if (sel->input == p) {
1083 val = clk_readl(c->reg);
1090 clk_writel(val, c->reg);
1092 if (c->refcnt && c->parent)
1093 clk_disable(c->parent);
1103 static struct clk_ops tegra_audio_sync_clk_ops = {
1104 .init = tegra2_audio_sync_clk_init,
1105 .enable = tegra2_audio_sync_clk_enable,
1106 .disable = tegra2_audio_sync_clk_disable,
1107 .set_parent = tegra2_audio_sync_clk_set_parent,
1110 /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1112 static void tegra2_cdev_clk_init(struct clk *c)
1114 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1115 * currently done in the pinmux code. */
1117 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1118 PERIPH_CLK_TO_ENB_BIT(c)))
1122 static int tegra2_cdev_clk_enable(struct clk *c)
1124 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1125 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1129 static void tegra2_cdev_clk_disable(struct clk *c)
1131 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1132 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1135 static struct clk_ops tegra_cdev_clk_ops = {
1136 .init = &tegra2_cdev_clk_init,
1137 .enable = &tegra2_cdev_clk_enable,
1138 .disable = &tegra2_cdev_clk_disable,
1141 /* shared bus ops */
1143 * Some clocks may have multiple downstream users that need to request a
1144 * higher clock rate. Shared bus clocks provide a unique shared_bus_user
1145 * clock to each user. The frequency of the bus is set to the highest
1146 * enabled shared_bus_user clock, with a minimum value set by the
1149 static void tegra_clk_shared_bus_update(struct clk *bus)
1152 unsigned long rate = bus->min_rate;
1154 list_for_each_entry(c, &bus->shared_bus_list,
1155 u.shared_bus_user.node) {
1156 if (c->u.shared_bus_user.enabled)
1157 rate = max(c->u.shared_bus_user.rate, rate);
1160 clk_set_rate(bus, rate);
1163 static void tegra_clk_shared_bus_init(struct clk *c)
1165 c->max_rate = c->parent->max_rate;
1166 c->u.shared_bus_user.rate = c->parent->max_rate;
1170 list_add_tail(&c->u.shared_bus_user.node,
1171 &c->parent->shared_bus_list);
1174 static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate)
1176 c->u.shared_bus_user.rate = rate;
1177 tegra_clk_shared_bus_update(c->parent);
1181 static int tegra_clk_shared_bus_enable(struct clk *c)
1183 c->u.shared_bus_user.enabled = true;
1184 tegra_clk_shared_bus_update(c->parent);
1188 static void tegra_clk_shared_bus_disable(struct clk *c)
1190 c->u.shared_bus_user.enabled = false;
1191 tegra_clk_shared_bus_update(c->parent);
1194 static struct clk_ops tegra_clk_shared_bus_ops = {
1195 .init = tegra_clk_shared_bus_init,
1196 .enable = tegra_clk_shared_bus_enable,
1197 .disable = tegra_clk_shared_bus_disable,
1198 .set_rate = tegra_clk_shared_bus_set_rate,
1202 /* Clock definitions */
1203 static struct clk tegra_clk_32k = {
1210 static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
1211 {32768, 12000000, 366, 1, 1, 0},
1212 {32768, 13000000, 397, 1, 1, 0},
1213 {32768, 19200000, 586, 1, 1, 0},
1214 {32768, 26000000, 793, 1, 1, 0},
1218 static struct clk tegra_pll_s = {
1220 .flags = PLL_ALT_MISC_REG,
1221 .ops = &tegra_pll_ops,
1222 .parent = &tegra_clk_32k,
1223 .max_rate = 26000000,
1228 .cf_min = 0, /* FIXME */
1229 .cf_max = 0, /* FIXME */
1230 .vco_min = 12000000,
1231 .vco_max = 26000000,
1232 .freq_table = tegra_pll_s_freq_table,
1237 static struct clk_mux_sel tegra_clk_m_sel[] = {
1238 { .input = &tegra_clk_32k, .value = 0},
1239 { .input = &tegra_pll_s, .value = 1},
1243 static struct clk tegra_clk_m = {
1245 .flags = ENABLE_ON_INIT,
1246 .ops = &tegra_clk_m_ops,
1247 .inputs = tegra_clk_m_sel,
1250 .max_rate = 26000000,
1253 static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
1254 { 0, 0, 0, 0, 0, 0 },
1257 static struct clk tegra_pll_c = {
1259 .flags = PLL_HAS_CPCON,
1260 .ops = &tegra_pll_ops,
1262 .parent = &tegra_clk_m,
1263 .max_rate = 600000000,
1265 .input_min = 2000000,
1266 .input_max = 31000000,
1269 .vco_min = 20000000,
1270 .vco_max = 1400000000,
1271 .freq_table = tegra_pll_c_freq_table,
1276 static struct clk tegra_pll_c_out1 = {
1277 .name = "pll_c_out1",
1278 .ops = &tegra_pll_div_ops,
1280 .parent = &tegra_pll_c,
1283 .max_rate = 600000000,
1286 static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
1287 { 12000000, 666000000, 666, 12, 1, 8},
1288 { 13000000, 666000000, 666, 13, 1, 8},
1289 { 19200000, 666000000, 555, 16, 1, 8},
1290 { 26000000, 666000000, 666, 26, 1, 8},
1291 { 12000000, 600000000, 600, 12, 1, 8},
1292 { 13000000, 600000000, 600, 13, 1, 8},
1293 { 19200000, 600000000, 375, 12, 1, 6},
1294 { 26000000, 600000000, 600, 26, 1, 8},
1295 { 0, 0, 0, 0, 0, 0 },
1298 static struct clk tegra_pll_m = {
1300 .flags = PLL_HAS_CPCON,
1301 .ops = &tegra_pll_ops,
1303 .parent = &tegra_clk_m,
1304 .max_rate = 800000000,
1306 .input_min = 2000000,
1307 .input_max = 31000000,
1310 .vco_min = 20000000,
1311 .vco_max = 1200000000,
1312 .freq_table = tegra_pll_m_freq_table,
1317 static struct clk tegra_pll_m_out1 = {
1318 .name = "pll_m_out1",
1319 .ops = &tegra_pll_div_ops,
1321 .parent = &tegra_pll_m,
1324 .max_rate = 600000000,
1327 static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
1328 { 12000000, 216000000, 432, 12, 2, 8},
1329 { 13000000, 216000000, 432, 13, 2, 8},
1330 { 19200000, 216000000, 90, 4, 2, 1},
1331 { 26000000, 216000000, 432, 26, 2, 8},
1332 { 12000000, 432000000, 432, 12, 1, 8},
1333 { 13000000, 432000000, 432, 13, 1, 8},
1334 { 19200000, 432000000, 90, 4, 1, 1},
1335 { 26000000, 432000000, 432, 26, 1, 8},
1336 { 0, 0, 0, 0, 0, 0 },
1339 static struct clk tegra_pll_p = {
1341 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1342 .ops = &tegra_pll_ops,
1344 .parent = &tegra_clk_m,
1345 .max_rate = 432000000,
1347 .input_min = 2000000,
1348 .input_max = 31000000,
1351 .vco_min = 20000000,
1352 .vco_max = 1400000000,
1353 .freq_table = tegra_pll_p_freq_table,
1358 static struct clk tegra_pll_p_out1 = {
1359 .name = "pll_p_out1",
1360 .ops = &tegra_pll_div_ops,
1361 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1362 .parent = &tegra_pll_p,
1365 .max_rate = 432000000,
1368 static struct clk tegra_pll_p_out2 = {
1369 .name = "pll_p_out2",
1370 .ops = &tegra_pll_div_ops,
1371 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1372 .parent = &tegra_pll_p,
1375 .max_rate = 432000000,
1378 static struct clk tegra_pll_p_out3 = {
1379 .name = "pll_p_out3",
1380 .ops = &tegra_pll_div_ops,
1381 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1382 .parent = &tegra_pll_p,
1385 .max_rate = 432000000,
1388 static struct clk tegra_pll_p_out4 = {
1389 .name = "pll_p_out4",
1390 .ops = &tegra_pll_div_ops,
1391 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1392 .parent = &tegra_pll_p,
1395 .max_rate = 432000000,
1398 static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
1399 { 28800000, 56448000, 49, 25, 1, 1},
1400 { 28800000, 73728000, 64, 25, 1, 1},
1401 { 28800000, 24000000, 5, 6, 1, 1},
1402 { 0, 0, 0, 0, 0, 0 },
1405 static struct clk tegra_pll_a = {
1407 .flags = PLL_HAS_CPCON,
1408 .ops = &tegra_pll_ops,
1410 .parent = &tegra_pll_p_out1,
1411 .max_rate = 56448000,
1413 .input_min = 2000000,
1414 .input_max = 31000000,
1417 .vco_min = 20000000,
1418 .vco_max = 1400000000,
1419 .freq_table = tegra_pll_a_freq_table,
1424 static struct clk tegra_pll_a_out0 = {
1425 .name = "pll_a_out0",
1426 .ops = &tegra_pll_div_ops,
1428 .parent = &tegra_pll_a,
1431 .max_rate = 56448000,
1434 static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
1435 { 12000000, 216000000, 216, 12, 1, 4},
1436 { 13000000, 216000000, 216, 13, 1, 4},
1437 { 19200000, 216000000, 135, 12, 1, 3},
1438 { 26000000, 216000000, 216, 26, 1, 4},
1440 { 12000000, 594000000, 594, 12, 1, 8},
1441 { 13000000, 594000000, 594, 13, 1, 8},
1442 { 19200000, 594000000, 495, 16, 1, 8},
1443 { 26000000, 594000000, 594, 26, 1, 8},
1445 { 12000000, 1000000000, 1000, 12, 1, 12},
1446 { 13000000, 1000000000, 1000, 13, 1, 12},
1447 { 19200000, 1000000000, 625, 12, 1, 8},
1448 { 26000000, 1000000000, 1000, 26, 1, 12},
1450 { 0, 0, 0, 0, 0, 0 },
1453 static struct clk tegra_pll_d = {
1455 .flags = PLL_HAS_CPCON | PLLD,
1456 .ops = &tegra_pll_ops,
1458 .parent = &tegra_clk_m,
1459 .max_rate = 1000000000,
1461 .input_min = 2000000,
1462 .input_max = 40000000,
1465 .vco_min = 40000000,
1466 .vco_max = 1000000000,
1467 .freq_table = tegra_pll_d_freq_table,
1472 static struct clk tegra_pll_d_out0 = {
1473 .name = "pll_d_out0",
1474 .ops = &tegra_pll_div_ops,
1475 .flags = DIV_2 | PLLD,
1476 .parent = &tegra_pll_d,
1477 .max_rate = 500000000,
1480 static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
1481 { 12000000, 480000000, 960, 12, 2, 0},
1482 { 13000000, 480000000, 960, 13, 2, 0},
1483 { 19200000, 480000000, 200, 4, 2, 0},
1484 { 26000000, 480000000, 960, 26, 2, 0},
1485 { 0, 0, 0, 0, 0, 0 },
1488 static struct clk tegra_pll_u = {
1491 .ops = &tegra_pll_ops,
1493 .parent = &tegra_clk_m,
1494 .max_rate = 480000000,
1496 .input_min = 2000000,
1497 .input_max = 40000000,
1500 .vco_min = 480000000,
1501 .vco_max = 960000000,
1502 .freq_table = tegra_pll_u_freq_table,
1507 static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
1509 { 12000000, 1000000000, 1000, 12, 1, 12},
1510 { 13000000, 1000000000, 1000, 13, 1, 12},
1511 { 19200000, 1000000000, 625, 12, 1, 8},
1512 { 26000000, 1000000000, 1000, 26, 1, 12},
1515 { 12000000, 912000000, 912, 12, 1, 12},
1516 { 13000000, 912000000, 912, 13, 1, 12},
1517 { 19200000, 912000000, 760, 16, 1, 8},
1518 { 26000000, 912000000, 912, 26, 1, 12},
1521 { 12000000, 816000000, 816, 12, 1, 12},
1522 { 13000000, 816000000, 816, 13, 1, 12},
1523 { 19200000, 816000000, 680, 16, 1, 8},
1524 { 26000000, 816000000, 816, 26, 1, 12},
1527 { 12000000, 760000000, 760, 12, 1, 12},
1528 { 13000000, 760000000, 760, 13, 1, 12},
1529 { 19200000, 760000000, 950, 24, 1, 8},
1530 { 26000000, 760000000, 760, 26, 1, 12},
1533 { 12000000, 608000000, 608, 12, 1, 12},
1534 { 13000000, 608000000, 608, 13, 1, 12},
1535 { 19200000, 608000000, 380, 12, 1, 8},
1536 { 26000000, 608000000, 608, 26, 1, 12},
1539 { 12000000, 456000000, 456, 12, 1, 12},
1540 { 13000000, 456000000, 456, 13, 1, 12},
1541 { 19200000, 456000000, 380, 16, 1, 8},
1542 { 26000000, 456000000, 456, 26, 1, 12},
1545 { 12000000, 312000000, 312, 12, 1, 12},
1546 { 13000000, 312000000, 312, 13, 1, 12},
1547 { 19200000, 312000000, 260, 16, 1, 8},
1548 { 26000000, 312000000, 312, 26, 1, 12},
1550 { 0, 0, 0, 0, 0, 0 },
1553 static struct clk tegra_pll_x = {
1555 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1556 .ops = &tegra_pllx_ops,
1558 .parent = &tegra_clk_m,
1559 .max_rate = 1000000000,
1561 .input_min = 2000000,
1562 .input_max = 31000000,
1565 .vco_min = 20000000,
1566 .vco_max = 1200000000,
1567 .freq_table = tegra_pll_x_freq_table,
1572 static struct clk tegra_clk_d = {
1574 .flags = PERIPH_NO_RESET,
1575 .ops = &tegra_clk_double_ops,
1578 .parent = &tegra_clk_m,
1579 .max_rate = 52000000,
1585 /* dap_mclk1, belongs to the cdev1 pingroup. */
1586 static struct clk tegra_dev1_clk = {
1588 .ops = &tegra_cdev_clk_ops,
1590 .max_rate = 26000000,
1596 /* dap_mclk2, belongs to the cdev2 pingroup. */
1597 static struct clk tegra_dev2_clk = {
1599 .ops = &tegra_cdev_clk_ops,
1601 .max_rate = 26000000,
1607 /* initialized before peripheral clocks */
1608 static struct clk_mux_sel mux_audio_sync_clk[8+1];
1609 static const struct audio_sources {
1612 } mux_audio_sync_clk_sources[] = {
1613 { .name = "spdif_in", .value = 0 },
1614 { .name = "i2s1", .value = 1 },
1615 { .name = "i2s2", .value = 2 },
1616 { .name = "pll_a_out0", .value = 4 },
1617 #if 0 /* FIXME: not implemented */
1618 { .name = "ac97", .value = 3 },
1619 { .name = "ext_audio_clk2", .value = 5 },
1620 { .name = "ext_audio_clk1", .value = 6 },
1621 { .name = "ext_vimclk", .value = 7 },
1626 static struct clk tegra_clk_audio = {
1628 .inputs = mux_audio_sync_clk,
1630 .max_rate = 24000000,
1631 .ops = &tegra_audio_sync_clk_ops
1634 static struct clk tegra_clk_audio_2x = {
1636 .flags = PERIPH_NO_RESET,
1637 .max_rate = 48000000,
1638 .ops = &tegra_clk_double_ops,
1641 .parent = &tegra_clk_audio,
1647 struct clk_lookup tegra_audio_clk_lookups[] = {
1648 { .con_id = "audio", .clk = &tegra_clk_audio },
1649 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1652 /* This is called after peripheral clocks are initialized, as the
1653 * audio_sync clock depends on some of the peripheral clocks.
1656 static void init_audio_sync_clock_mux(void)
1659 struct clk_mux_sel *sel = mux_audio_sync_clk;
1660 const struct audio_sources *src = mux_audio_sync_clk_sources;
1661 struct clk_lookup *lookup;
1663 for (i = 0; src->name; i++, sel++, src++) {
1664 sel->input = tegra_get_clock_by_name(src->name);
1666 pr_err("%s: could not find clk %s\n", __func__,
1668 sel->value = src->value;
1671 lookup = tegra_audio_clk_lookups;
1672 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1673 clk_init(lookup->clk);
1678 static struct clk_mux_sel mux_cclk[] = {
1679 { .input = &tegra_clk_m, .value = 0},
1680 { .input = &tegra_pll_c, .value = 1},
1681 { .input = &tegra_clk_32k, .value = 2},
1682 { .input = &tegra_pll_m, .value = 3},
1683 { .input = &tegra_pll_p, .value = 4},
1684 { .input = &tegra_pll_p_out4, .value = 5},
1685 { .input = &tegra_pll_p_out3, .value = 6},
1686 { .input = &tegra_clk_d, .value = 7},
1687 { .input = &tegra_pll_x, .value = 8},
1691 static struct clk_mux_sel mux_sclk[] = {
1692 { .input = &tegra_clk_m, .value = 0},
1693 { .input = &tegra_pll_c_out1, .value = 1},
1694 { .input = &tegra_pll_p_out4, .value = 2},
1695 { .input = &tegra_pll_p_out3, .value = 3},
1696 { .input = &tegra_pll_p_out2, .value = 4},
1697 { .input = &tegra_clk_d, .value = 5},
1698 { .input = &tegra_clk_32k, .value = 6},
1699 { .input = &tegra_pll_m_out1, .value = 7},
1703 static struct clk tegra_clk_cclk = {
1707 .ops = &tegra_super_ops,
1708 .max_rate = 1000000000,
1711 static struct clk tegra_clk_sclk = {
1715 .ops = &tegra_super_ops,
1716 .max_rate = 240000000,
1717 .min_rate = 120000000,
1720 static struct clk tegra_clk_virtual_cpu = {
1722 .parent = &tegra_clk_cclk,
1723 .ops = &tegra_cpu_ops,
1724 .max_rate = 1000000000,
1726 .main = &tegra_pll_x,
1727 .backup = &tegra_pll_p,
1731 static struct clk tegra_clk_cop = {
1733 .parent = &tegra_clk_sclk,
1734 .ops = &tegra_cop_ops,
1735 .max_rate = 240000000,
1738 static struct clk tegra_clk_hclk = {
1741 .parent = &tegra_clk_sclk,
1744 .ops = &tegra_bus_ops,
1745 .max_rate = 240000000,
1748 static struct clk tegra_clk_pclk = {
1751 .parent = &tegra_clk_hclk,
1754 .ops = &tegra_bus_ops,
1755 .max_rate = 120000000,
1758 static struct clk tegra_clk_blink = {
1760 .parent = &tegra_clk_32k,
1762 .ops = &tegra_blink_clk_ops,
1766 static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1767 { .input = &tegra_pll_m, .value = 0},
1768 { .input = &tegra_pll_c, .value = 1},
1769 { .input = &tegra_pll_p, .value = 2},
1770 { .input = &tegra_pll_a_out0, .value = 3},
1774 static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1775 { .input = &tegra_pll_m, .value = 0},
1776 { .input = &tegra_pll_c, .value = 1},
1777 { .input = &tegra_pll_p, .value = 2},
1778 { .input = &tegra_clk_m, .value = 3},
1782 static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1783 { .input = &tegra_pll_p, .value = 0},
1784 { .input = &tegra_pll_c, .value = 1},
1785 { .input = &tegra_pll_m, .value = 2},
1786 { .input = &tegra_clk_m, .value = 3},
1790 static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1791 {.input = &tegra_pll_a_out0, .value = 0},
1792 {.input = &tegra_clk_audio_2x, .value = 1},
1793 {.input = &tegra_pll_p, .value = 2},
1794 {.input = &tegra_clk_m, .value = 3},
1798 static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1799 {.input = &tegra_pll_p, .value = 0},
1800 {.input = &tegra_pll_d_out0, .value = 1},
1801 {.input = &tegra_pll_c, .value = 2},
1802 {.input = &tegra_clk_m, .value = 3},
1806 static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1807 {.input = &tegra_pll_p, .value = 0},
1808 {.input = &tegra_pll_c, .value = 1},
1809 {.input = &tegra_clk_audio, .value = 2},
1810 {.input = &tegra_clk_m, .value = 3},
1811 {.input = &tegra_clk_32k, .value = 4},
1815 static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1816 {.input = &tegra_pll_p, .value = 0},
1817 {.input = &tegra_pll_c, .value = 1},
1818 {.input = &tegra_pll_m, .value = 2},
1822 static struct clk_mux_sel mux_clk_m[] = {
1823 { .input = &tegra_clk_m, .value = 0},
1827 static struct clk_mux_sel mux_pllp_out3[] = {
1828 { .input = &tegra_pll_p_out3, .value = 0},
1832 static struct clk_mux_sel mux_plld[] = {
1833 { .input = &tegra_pll_d, .value = 0},
1837 static struct clk_mux_sel mux_clk_32k[] = {
1838 { .input = &tegra_clk_32k, .value = 0},
1842 #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
1849 .ops = &tegra_periph_clk_ops, \
1851 .inputs = _inputs, \
1855 .clk_num = _clk_num, \
1859 #define SHARED_CLK(_name, _dev, _con, _parent) \
1866 .ops = &tegra_clk_shared_bus_ops, \
1867 .parent = _parent, \
1870 struct clk tegra_list_clks[] = {
1871 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
1872 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
1873 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1874 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1875 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1876 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
1877 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
1878 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1879 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1880 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1881 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1882 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1883 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1884 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1885 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1886 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1887 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1888 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1889 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1890 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1891 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1892 PERIPH_CLK("vcp", "tegra-avp", "vcp", 29, 0, 250000000, mux_clk_m, 0),
1893 PERIPH_CLK("bsea", "tegra-avp", "bsea", 62, 0, 250000000, mux_clk_m, 0),
1894 PERIPH_CLK("vde", "tegra-avp", "vde", 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1895 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
1896 /* FIXME: what is la? */
1897 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1898 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1899 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1900 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1901 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1902 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1903 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1904 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1905 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1906 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1907 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1908 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1909 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1910 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1911 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1912 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1913 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1914 PERIPH_CLK("3d", "3d", NULL, 24, 0x158, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_MANUAL_RESET), /* scales with voltage and process_id */
1915 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1916 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1917 PERIPH_CLK("vi_sensor", "tegra_camera", "vi_sensor", 20, 0x1a8, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_NO_RESET), /* scales with voltage and process_id */
1918 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1919 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1920 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1921 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1922 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1923 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1924 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1925 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1926 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1927 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1928 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1929 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1930 PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, 800000000, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB),
1931 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
1932 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
1933 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
1934 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
1936 SHARED_CLK("avp.sclk", "tegra-avp", "sclk", &tegra_clk_sclk),
1939 #define CLK_DUPLICATE(_name, _dev, _con) \
1948 /* Some clocks may be used by different drivers depending on the board
1949 * configuration. List those here to register them twice in the clock lookup
1950 * table under two names.
1952 struct clk_duplicate tegra_clk_duplicates[] = {
1953 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
1954 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
1955 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
1956 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
1957 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
1958 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
1959 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
1960 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
1961 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
1962 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
1963 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
1964 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
1965 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
1966 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
1967 CLK_DUPLICATE("host1x", "tegra_grhost", "host1x"),
1968 CLK_DUPLICATE("2d", "tegra_grhost", "gr2d"),
1969 CLK_DUPLICATE("3d", "tegra_grhost", "gr3d"),
1970 CLK_DUPLICATE("epp", "tegra_grhost", "epp"),
1971 CLK_DUPLICATE("mpe", "tegra_grhost", "mpe"),
1972 CLK_DUPLICATE("cop", "tegra-avp", "cop"),
1975 #define CLK(dev, con, ck) \
1982 struct clk *tegra_ptr_clks[] = {
2008 &tegra_clk_virtual_cpu,
2013 static void tegra2_init_one_clock(struct clk *c)
2016 INIT_LIST_HEAD(&c->shared_bus_list);
2017 if (!c->lookup.dev_id && !c->lookup.con_id)
2018 c->lookup.con_id = c->name;
2020 clkdev_add(&c->lookup);
2023 void __init tegra2_init_clocks(void)
2028 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
2029 tegra2_init_one_clock(tegra_ptr_clks[i]);
2031 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
2032 tegra2_init_one_clock(&tegra_list_clks[i]);
2034 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
2035 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
2037 pr_err("%s: Unknown duplicate clock %s\n", __func__,
2038 tegra_clk_duplicates[i].name);
2042 tegra_clk_duplicates[i].lookup.clk = c;
2043 clkdev_add(&tegra_clk_duplicates[i].lookup);
2046 init_audio_sync_clock_mux();
2050 static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
2051 PERIPH_CLK_SOURCE_NUM + 15];
2053 void tegra_clk_suspend(void)
2055 unsigned long off, i;
2056 u32 *ctx = clk_rst_suspend;
2058 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
2059 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
2060 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2061 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
2062 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2064 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
2065 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
2066 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
2068 *ctx++ = clk_readl(tegra_clk_cclk.reg);
2069 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2071 *ctx++ = clk_readl(tegra_clk_sclk.reg);
2072 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2073 *ctx++ = clk_readl(tegra_clk_pclk.reg);
2075 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2077 if (off == PERIPH_CLK_SOURCE_EMC)
2079 *ctx++ = clk_readl(off);
2083 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2084 *ctx++ = clk_readl(off);
2087 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2088 *ctx++ = clk_readl(off);
2090 *ctx++ = clk_readl(MISC_CLK_ENB);
2091 *ctx++ = clk_readl(CLK_MASK_ARM);
2094 void tegra_clk_resume(void)
2096 unsigned long off, i;
2097 const u32 *ctx = clk_rst_suspend;
2100 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2102 clk_writel(val, OSC_CTRL);
2104 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2105 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2106 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2107 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2110 clk_writel(*ctx++, tegra_pll_m_out1.reg);
2111 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2112 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2114 clk_writel(*ctx++, tegra_clk_cclk.reg);
2115 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2117 clk_writel(*ctx++, tegra_clk_sclk.reg);
2118 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2119 clk_writel(*ctx++, tegra_clk_pclk.reg);
2121 /* enable all clocks before configuring clock sources */
2122 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2123 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2124 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2127 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2129 if (off == PERIPH_CLK_SOURCE_EMC)
2131 clk_writel(*ctx++, off);
2136 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2137 clk_writel(*ctx++, off);
2141 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2142 clk_writel(*ctx++, off);
2145 clk_writel(*ctx++, MISC_CLK_ENB);
2146 clk_writel(*ctx++, CLK_MASK_ARM);