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/hrtimer.h>
28 #include <asm/clkdev.h>
30 #include <mach/iomap.h>
31 #include <mach/suspend.h>
35 #include "tegra2_dvfs.h"
37 #define RST_DEVICES 0x004
38 #define RST_DEVICES_SET 0x300
39 #define RST_DEVICES_CLR 0x304
40 #define RST_DEVICES_NUM 3
42 #define CLK_OUT_ENB 0x010
43 #define CLK_OUT_ENB_SET 0x320
44 #define CLK_OUT_ENB_CLR 0x324
45 #define CLK_OUT_ENB_NUM 3
47 #define CLK_MASK_ARM 0x44
48 #define MISC_CLK_ENB 0x48
51 #define OSC_CTRL_OSC_FREQ_MASK (3<<30)
52 #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
53 #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
54 #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
55 #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
56 #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
58 #define OSC_FREQ_DET 0x58
59 #define OSC_FREQ_DET_TRIG (1<<31)
61 #define OSC_FREQ_DET_STATUS 0x5C
62 #define OSC_FREQ_DET_BUSY (1<<31)
63 #define OSC_FREQ_DET_CNT_MASK 0xFFFF
65 #define PERIPH_CLK_SOURCE_I2S1 0x100
66 #define PERIPH_CLK_SOURCE_EMC 0x19c
67 #define PERIPH_CLK_SOURCE_OSC 0x1fc
68 #define PERIPH_CLK_SOURCE_NUM \
69 ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4)
71 #define PERIPH_CLK_SOURCE_MASK (3<<30)
72 #define PERIPH_CLK_SOURCE_SHIFT 30
73 #define PERIPH_CLK_SOURCE_ENABLE (1<<28)
74 #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
75 #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
76 #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
79 #define PLL_BASE_BYPASS (1<<31)
80 #define PLL_BASE_ENABLE (1<<30)
81 #define PLL_BASE_REF_ENABLE (1<<29)
82 #define PLL_BASE_OVERRIDE (1<<28)
83 #define PLL_BASE_LOCK (1<<27)
84 #define PLL_BASE_DIVP_MASK (0x7<<20)
85 #define PLL_BASE_DIVP_SHIFT 20
86 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
87 #define PLL_BASE_DIVN_SHIFT 8
88 #define PLL_BASE_DIVM_MASK (0x1F)
89 #define PLL_BASE_DIVM_SHIFT 0
91 #define PLL_OUT_RATIO_MASK (0xFF<<8)
92 #define PLL_OUT_RATIO_SHIFT 8
93 #define PLL_OUT_OVERRIDE (1<<2)
94 #define PLL_OUT_CLKEN (1<<1)
95 #define PLL_OUT_RESET_DISABLE (1<<0)
97 #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
98 #define PLL_MISC_LOCK_ENABLE(c) (((c)->flags & PLLU) ? (1<<22) : (1<<18))
100 #define PLL_MISC_DCCON_SHIFT 20
101 #define PLL_MISC_CPCON_SHIFT 8
102 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
103 #define PLL_MISC_LFCON_SHIFT 4
104 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
105 #define PLL_MISC_VCOCON_SHIFT 0
106 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
108 #define PLLU_BASE_POST_DIV (1<<20)
110 #define PLLD_MISC_CLKENABLE (1<<30)
111 #define PLLD_MISC_DIV_RST (1<<23)
112 #define PLLD_MISC_DCCON_SHIFT 12
114 #define PERIPH_CLK_TO_ENB_REG(c) ((c->clk_num / 32) * 4)
115 #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->clk_num / 32) * 8)
116 #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->clk_num % 32))
118 #define SUPER_CLK_MUX 0x00
119 #define SUPER_STATE_SHIFT 28
120 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
121 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
122 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
123 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
124 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
125 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
126 #define SUPER_SOURCE_MASK 0xF
127 #define SUPER_FIQ_SOURCE_SHIFT 12
128 #define SUPER_IRQ_SOURCE_SHIFT 8
129 #define SUPER_RUN_SOURCE_SHIFT 4
130 #define SUPER_IDLE_SOURCE_SHIFT 0
132 #define SUPER_CLK_DIVIDER 0x04
134 #define BUS_CLK_DISABLE (1<<3)
135 #define BUS_CLK_DIV_MASK 0x3
138 #define PMC_CTRL_BLINK_ENB (1 << 7)
140 #define PMC_DPD_PADS_ORIDE 0x1c
141 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
143 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
144 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
145 #define PMC_BLINK_TIMER_ENB (1 << 15)
146 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
147 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
149 static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
150 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
152 #define clk_writel(value, reg) \
153 __raw_writel(value, (u32)reg_clk_base + (reg))
154 #define clk_readl(reg) \
155 __raw_readl((u32)reg_clk_base + (reg))
156 #define pmc_writel(value, reg) \
157 __raw_writel(value, (u32)reg_pmc_base + (reg))
158 #define pmc_readl(reg) \
159 __raw_readl((u32)reg_pmc_base + (reg))
161 unsigned long clk_measure_input_freq(void)
163 u32 clock_autodetect;
164 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
165 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
166 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
167 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
169 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
171 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
173 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
176 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
182 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
184 s64 divider_u71 = parent_rate * 2;
185 divider_u71 += rate - 1;
186 do_div(divider_u71, rate);
188 if (divider_u71 - 2 < 0)
191 if (divider_u71 - 2 > 255)
194 return divider_u71 - 2;
197 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
201 divider_u16 = parent_rate;
202 divider_u16 += rate - 1;
203 do_div(divider_u16, rate);
205 if (divider_u16 - 1 < 0)
208 if (divider_u16 - 1 > 255)
211 return divider_u16 - 1;
214 /* clk_m functions */
215 static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
217 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
219 c->rate = clk_measure_input_freq();
222 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
225 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
228 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
231 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
234 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
237 clk_writel(auto_clock_control, OSC_CTRL);
241 static void tegra2_clk_m_init(struct clk *c)
243 pr_debug("%s on clock %s\n", __func__, c->name);
244 tegra2_clk_m_autodetect_rate(c);
247 static int tegra2_clk_m_enable(struct clk *c)
249 pr_debug("%s on clock %s\n", __func__, c->name);
253 static void tegra2_clk_m_disable(struct clk *c)
255 pr_debug("%s on clock %s\n", __func__, c->name);
259 static struct clk_ops tegra_clk_m_ops = {
260 .init = tegra2_clk_m_init,
261 .enable = tegra2_clk_m_enable,
262 .disable = tegra2_clk_m_disable,
265 void tegra2_periph_reset_assert(struct clk *c)
267 BUG_ON(!c->ops->reset);
268 c->ops->reset(c, true);
271 void tegra2_periph_reset_deassert(struct clk *c)
273 BUG_ON(!c->ops->reset);
274 c->ops->reset(c, false);
277 /* super clock functions */
278 /* "super clocks" on tegra have two-stage muxes and a clock skipping
279 * super divider. We will ignore the clock skipping divider, since we
280 * can't lower the voltage when using the clock skip, but we can if we
281 * lower the PLL frequency.
283 static void tegra2_super_clk_init(struct clk *c)
288 const struct clk_mux_sel *sel;
289 val = clk_readl(c->reg + SUPER_CLK_MUX);
291 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
292 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
293 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
294 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
295 source = (val >> shift) & SUPER_SOURCE_MASK;
296 for (sel = c->inputs; sel->input != NULL; sel++) {
297 if (sel->value == source)
300 BUG_ON(sel->input == NULL);
301 c->parent = sel->input;
304 static int tegra2_super_clk_enable(struct clk *c)
306 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
310 static void tegra2_super_clk_disable(struct clk *c)
312 pr_debug("%s on clock %s\n", __func__, c->name);
314 /* oops - don't disable the CPU clock! */
318 static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
321 const struct clk_mux_sel *sel;
324 val = clk_readl(c->reg + SUPER_CLK_MUX);;
325 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
326 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
327 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
328 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
329 for (sel = c->inputs; sel->input != NULL; sel++) {
330 if (sel->input == p) {
331 val &= ~(SUPER_SOURCE_MASK << shift);
332 val |= sel->value << shift;
335 clk_enable_locked(p);
337 clk_writel(val, c->reg);
339 if (c->refcnt && c->parent)
340 clk_disable_locked(c->parent);
349 static struct clk_ops tegra_super_ops = {
350 .init = tegra2_super_clk_init,
351 .enable = tegra2_super_clk_enable,
352 .disable = tegra2_super_clk_disable,
353 .set_parent = tegra2_super_clk_set_parent,
356 /* virtual cpu clock functions */
357 /* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
358 To change the frequency of these clocks, the parent pll may need to be
359 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
360 and then the clock moved back to the pll. To hide this sequence, a virtual
363 static void tegra2_cpu_clk_init(struct clk *c)
367 static int tegra2_cpu_clk_enable(struct clk *c)
372 static void tegra2_cpu_clk_disable(struct clk *c)
374 pr_debug("%s on clock %s\n", __func__, c->name);
376 /* oops - don't disable the CPU clock! */
380 static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
383 ret = clk_set_parent_locked(c->parent, c->backup);
385 pr_err("Failed to switch cpu to clock %s\n", c->backup->name);
389 if (rate == c->backup->rate)
392 ret = clk_set_rate_locked(c->main, rate);
394 pr_err("Failed to change cpu pll to %lu\n", rate);
398 ret = clk_set_parent_locked(c->parent, c->main);
400 pr_err("Failed to switch cpu to clock %s\n", c->main->name);
408 static struct clk_ops tegra_cpu_ops = {
409 .init = tegra2_cpu_clk_init,
410 .enable = tegra2_cpu_clk_enable,
411 .disable = tegra2_cpu_clk_disable,
412 .set_rate = tegra2_cpu_clk_set_rate,
415 /* virtual cop clock functions. Used to acquire the fake 'cop' clock to
416 * reset the COP block (i.e. AVP) */
417 static void tegra2_cop_clk_init(struct clk *c)
419 c->state = c->parent->state;
422 static int tegra2_cop_clk_enable(struct clk *c)
427 static void tegra2_cop_clk_reset(struct clk *c, bool assert)
429 unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
431 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
432 clk_writel(1 << 1, reg);
435 static struct clk_ops tegra_cop_ops = {
436 .init = tegra2_cop_clk_init,
437 .enable = tegra2_cop_clk_enable,
438 .reset = tegra2_cop_clk_reset,
441 /* bus clock functions */
442 static void tegra2_bus_clk_init(struct clk *c)
444 u32 val = clk_readl(c->reg);
445 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
446 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
450 static int tegra2_bus_clk_enable(struct clk *c)
452 u32 val = clk_readl(c->reg);
453 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
454 clk_writel(val, c->reg);
458 static void tegra2_bus_clk_disable(struct clk *c)
460 u32 val = clk_readl(c->reg);
461 val |= BUS_CLK_DISABLE << c->reg_shift;
462 clk_writel(val, c->reg);
465 static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
467 u32 val = clk_readl(c->reg);
468 unsigned long parent_rate = c->parent->rate;
470 for (i = 1; i <= 4; i++) {
471 if (rate == parent_rate / i) {
472 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
473 val |= (i - 1) << c->reg_shift;
474 clk_writel(val, c->reg);
483 static struct clk_ops tegra_bus_ops = {
484 .init = tegra2_bus_clk_init,
485 .enable = tegra2_bus_clk_enable,
486 .disable = tegra2_bus_clk_disable,
487 .set_rate = tegra2_bus_clk_set_rate,
490 /* Blink output functions */
492 static void tegra2_blink_clk_init(struct clk *c)
496 val = pmc_readl(PMC_CTRL);
497 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
499 val = pmc_readl(c->reg);
501 if (val & PMC_BLINK_TIMER_ENB) {
504 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
505 PMC_BLINK_TIMER_DATA_ON_MASK;
506 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
507 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
509 /* each tick in the blink timer is 4 32KHz clocks */
516 static int tegra2_blink_clk_enable(struct clk *c)
520 val = pmc_readl(PMC_DPD_PADS_ORIDE);
521 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
523 val = pmc_readl(PMC_CTRL);
524 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
529 static void tegra2_blink_clk_disable(struct clk *c)
533 val = pmc_readl(PMC_CTRL);
534 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
536 val = pmc_readl(PMC_DPD_PADS_ORIDE);
537 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
540 static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
542 if (rate >= c->parent->rate) {
544 pmc_writel(0, c->reg);
549 on_off = DIV_ROUND_UP(c->parent->rate / 8, rate);
552 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
553 PMC_BLINK_TIMER_DATA_ON_SHIFT;
554 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
555 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
557 val |= PMC_BLINK_TIMER_ENB;
558 pmc_writel(val, c->reg);
564 static struct clk_ops tegra_blink_clk_ops = {
565 .init = &tegra2_blink_clk_init,
566 .enable = &tegra2_blink_clk_enable,
567 .disable = &tegra2_blink_clk_disable,
568 .set_rate = &tegra2_blink_clk_set_rate,
572 static int tegra2_pll_clk_wait_for_lock(struct clk *c)
576 before = ktime_get();
578 while (!(clk_readl(c->reg + PLL_BASE) & PLL_BASE_LOCK)) {
579 if (ktime_us_delta(ktime_get(), before) > 5000) {
580 pr_err("Timed out waiting for lock bit on pll %s",
589 static void tegra2_pll_clk_init(struct clk *c)
591 u32 val = clk_readl(c->reg + PLL_BASE);
593 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
595 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
596 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
599 } else if (val & PLL_BASE_BYPASS) {
603 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
604 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
606 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
608 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
612 static int tegra2_pll_clk_enable(struct clk *c)
615 pr_debug("%s on clock %s\n", __func__, c->name);
617 val = clk_readl(c->reg + PLL_BASE);
618 val &= ~PLL_BASE_BYPASS;
619 val |= PLL_BASE_ENABLE;
620 clk_writel(val, c->reg + PLL_BASE);
622 val = clk_readl(c->reg + PLL_MISC(c));
623 val |= PLL_MISC_LOCK_ENABLE(c);
624 clk_writel(val, c->reg + PLL_MISC(c));
626 tegra2_pll_clk_wait_for_lock(c);
631 static void tegra2_pll_clk_disable(struct clk *c)
634 pr_debug("%s on clock %s\n", __func__, c->name);
636 val = clk_readl(c->reg);
637 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
638 clk_writel(val, c->reg);
641 static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
644 unsigned long input_rate;
645 const struct clk_pll_table *sel;
647 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
648 BUG_ON(c->refcnt != 0);
650 input_rate = c->parent->rate;
651 for (sel = c->pll_table; sel->input_rate != 0; sel++) {
652 if (sel->input_rate == input_rate && sel->output_rate == rate) {
654 c->div = sel->m * sel->p;
656 val = clk_readl(c->reg + PLL_BASE);
657 if (c->flags & PLL_FIXED)
658 val |= PLL_BASE_OVERRIDE;
659 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
661 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
662 (sel->n << PLL_BASE_DIVN_SHIFT);
663 BUG_ON(sel->p < 1 || sel->p > 2);
664 if (c->flags & PLLU) {
666 val |= PLLU_BASE_POST_DIV;
669 val |= 1 << PLL_BASE_DIVP_SHIFT;
671 clk_writel(val, c->reg + PLL_BASE);
673 if (c->flags & PLL_HAS_CPCON) {
674 val = clk_readl(c->reg + PLL_MISC(c));
675 val &= ~PLL_MISC_CPCON_MASK;
676 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
677 clk_writel(val, c->reg + PLL_MISC(c));
681 tegra2_pll_clk_enable(c);
689 static struct clk_ops tegra_pll_ops = {
690 .init = tegra2_pll_clk_init,
691 .enable = tegra2_pll_clk_enable,
692 .disable = tegra2_pll_clk_disable,
693 .set_rate = tegra2_pll_clk_set_rate,
696 static void tegra2_pllx_clk_init(struct clk *c)
698 tegra2_pll_clk_init(c);
700 if (tegra_sku_id() == 7)
701 c->max_rate = 750000000;
704 static struct clk_ops tegra_pllx_ops = {
705 .init = tegra2_pllx_clk_init,
706 .enable = tegra2_pll_clk_enable,
707 .disable = tegra2_pll_clk_disable,
708 .set_rate = tegra2_pll_clk_set_rate,
711 /* Clock divider ops */
712 static void tegra2_pll_div_clk_init(struct clk *c)
714 u32 val = clk_readl(c->reg);
716 val >>= c->reg_shift;
717 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
718 if (!(val & PLL_OUT_RESET_DISABLE))
721 if (c->flags & DIV_U71) {
722 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
723 c->div = (divu71 + 2);
725 } else if (c->flags & DIV_2) {
734 static int tegra2_pll_div_clk_enable(struct clk *c)
739 pr_debug("%s: %s\n", __func__, c->name);
740 if (c->flags & DIV_U71) {
741 val = clk_readl(c->reg);
742 new_val = val >> c->reg_shift;
745 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
747 val &= ~(0xFFFF << c->reg_shift);
748 val |= new_val << c->reg_shift;
749 clk_writel(val, c->reg);
751 } else if (c->flags & DIV_2) {
752 BUG_ON(!(c->flags & PLLD));
753 val = clk_readl(c->reg);
754 val &= ~PLLD_MISC_DIV_RST;
755 clk_writel(val, c->reg);
761 static void tegra2_pll_div_clk_disable(struct clk *c)
766 pr_debug("%s: %s\n", __func__, c->name);
767 if (c->flags & DIV_U71) {
768 val = clk_readl(c->reg);
769 new_val = val >> c->reg_shift;
772 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
774 val &= ~(0xFFFF << c->reg_shift);
775 val |= new_val << c->reg_shift;
776 clk_writel(val, c->reg);
777 } else if (c->flags & DIV_2) {
778 BUG_ON(!(c->flags & PLLD));
779 val = clk_readl(c->reg);
780 val |= PLLD_MISC_DIV_RST;
781 clk_writel(val, c->reg);
785 static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
790 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
791 if (c->flags & DIV_U71) {
792 divider_u71 = clk_div71_get_divider(c->parent->rate, rate);
793 if (divider_u71 >= 0) {
794 val = clk_readl(c->reg);
795 new_val = val >> c->reg_shift;
797 if (c->flags & DIV_U71_FIXED)
798 new_val |= PLL_OUT_OVERRIDE;
799 new_val &= ~PLL_OUT_RATIO_MASK;
800 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
802 val &= ~(0xFFFF << c->reg_shift);
803 val |= new_val << c->reg_shift;
804 clk_writel(val, c->reg);
805 c->div = divider_u71 + 2;
809 } else if (c->flags & DIV_2) {
810 if (c->parent->rate == rate * 2)
816 static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
819 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
821 if (c->flags & DIV_U71) {
822 divider = clk_div71_get_divider(c->parent->rate, rate);
825 return c->parent->rate * 2 / (divider + 2);
826 } else if (c->flags & DIV_2) {
827 return c->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 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
888 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
889 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
890 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
891 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
892 if (c->flags & PERIPH_EMC_ENB) {
893 /* The EMC peripheral clock has 2 extra enable bits */
894 /* FIXME: Do they need to be disabled? */
895 val = clk_readl(c->reg);
897 clk_writel(val, c->reg);
902 static void tegra2_periph_clk_disable(struct clk *c)
904 pr_debug("%s on clock %s\n", __func__, c->name);
906 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
907 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
910 static void tegra2_periph_clk_reset(struct clk *c, bool assert)
912 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
914 pr_debug("%s %s on clock %s\n", __func__,
915 assert ? "assert" : "deassert", c->name);
916 if (!(c->flags & PERIPH_NO_RESET))
917 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
918 base + PERIPH_CLK_TO_ENB_SET_REG(c));
921 static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
924 const struct clk_mux_sel *sel;
925 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
926 for (sel = c->inputs; sel->input != NULL; sel++) {
927 if (sel->input == p) {
928 val = clk_readl(c->reg);
929 val &= ~PERIPH_CLK_SOURCE_MASK;
930 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
933 clk_enable_locked(p);
935 clk_writel(val, c->reg);
937 if (c->refcnt && c->parent)
938 clk_disable_locked(c->parent);
948 static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
952 pr_debug("%s: %lu\n", __func__, rate);
953 if (c->flags & DIV_U71) {
954 divider = clk_div71_get_divider(c->parent->rate, rate);
956 val = clk_readl(c->reg);
957 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
959 clk_writel(val, c->reg);
960 c->div = divider + 2;
964 } else if (c->flags & DIV_U16) {
965 divider = clk_div16_get_divider(c->parent->rate, rate);
967 val = clk_readl(c->reg);
968 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
970 clk_writel(val, c->reg);
971 c->div = divider + 1;
975 } else if (c->parent->rate <= rate) {
983 static long tegra2_periph_clk_round_rate(struct clk *c,
987 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
989 if (c->flags & DIV_U71) {
990 divider = clk_div71_get_divider(c->parent->rate, rate);
994 return c->parent->rate * 2 / (divider + 2);
995 } else if (c->flags & DIV_U16) {
996 divider = clk_div16_get_divider(c->parent->rate, rate);
999 return c->parent->rate / (divider + 1);
1004 static struct clk_ops tegra_periph_clk_ops = {
1005 .init = &tegra2_periph_clk_init,
1006 .enable = &tegra2_periph_clk_enable,
1007 .disable = &tegra2_periph_clk_disable,
1008 .set_parent = &tegra2_periph_clk_set_parent,
1009 .set_rate = &tegra2_periph_clk_set_rate,
1010 .round_rate = &tegra2_periph_clk_round_rate,
1011 .reset = &tegra2_periph_clk_reset,
1014 /* Clock doubler ops */
1015 static void tegra2_clk_double_init(struct clk *c)
1020 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1021 PERIPH_CLK_TO_ENB_BIT(c)))
1025 static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1027 if (rate != 2 * c->parent->rate)
1034 static struct clk_ops tegra_clk_double_ops = {
1035 .init = &tegra2_clk_double_init,
1036 .enable = &tegra2_periph_clk_enable,
1037 .disable = &tegra2_periph_clk_disable,
1038 .set_rate = &tegra2_clk_double_set_rate,
1041 /* Audio sync clock ops */
1042 static void tegra2_audio_sync_clk_init(struct clk *c)
1045 const struct clk_mux_sel *sel;
1046 u32 val = clk_readl(c->reg);
1047 c->state = (val & (1<<4)) ? OFF : ON;
1049 for (sel = c->inputs; sel->input != NULL; sel++)
1050 if (sel->value == source)
1052 BUG_ON(sel->input == NULL);
1053 c->parent = sel->input;
1056 static int tegra2_audio_sync_clk_enable(struct clk *c)
1058 clk_writel(0, c->reg);
1062 static void tegra2_audio_sync_clk_disable(struct clk *c)
1064 clk_writel(1, c->reg);
1067 static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1070 const struct clk_mux_sel *sel;
1071 for (sel = c->inputs; sel->input != NULL; sel++) {
1072 if (sel->input == p) {
1073 val = clk_readl(c->reg);
1078 clk_enable_locked(p);
1080 clk_writel(val, c->reg);
1082 if (c->refcnt && c->parent)
1083 clk_disable_locked(c->parent);
1093 static int tegra2_audio_sync_clk_set_rate(struct clk *c, unsigned long rate)
1095 unsigned long parent_rate;
1097 pr_err("%s: clock has no parent\n", __func__);
1100 parent_rate = c->parent->rate;
1101 if (rate != parent_rate) {
1102 pr_err("%s: %s/%ld differs from parent %s/%ld\n",
1105 c->parent->name, parent_rate);
1108 c->rate = parent_rate;
1112 static struct clk_ops tegra_audio_sync_clk_ops = {
1113 .init = tegra2_audio_sync_clk_init,
1114 .enable = tegra2_audio_sync_clk_enable,
1115 .disable = tegra2_audio_sync_clk_disable,
1116 .set_rate = tegra2_audio_sync_clk_set_rate,
1117 .set_parent = tegra2_audio_sync_clk_set_parent,
1120 /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1122 static void tegra2_cdev_clk_init(struct clk *c)
1124 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1125 * currently done in the pinmux code. */
1127 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1128 PERIPH_CLK_TO_ENB_BIT(c)))
1132 static int tegra2_cdev_clk_enable(struct clk *c)
1134 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1135 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1139 static void tegra2_cdev_clk_disable(struct clk *c)
1141 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1142 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1145 static struct clk_ops tegra_cdev_clk_ops = {
1146 .init = &tegra2_cdev_clk_init,
1147 .enable = &tegra2_cdev_clk_enable,
1148 .disable = &tegra2_cdev_clk_disable,
1151 /* Clock definitions */
1152 static struct clk tegra_clk_32k = {
1159 static struct clk_pll_table tegra_pll_s_table[] = {
1160 {32768, 12000000, 366, 1, 1, 0},
1161 {32768, 13000000, 397, 1, 1, 0},
1162 {32768, 19200000, 586, 1, 1, 0},
1163 {32768, 26000000, 793, 1, 1, 0},
1167 static struct clk tegra_pll_s = {
1169 .flags = PLL_ALT_MISC_REG,
1170 .ops = &tegra_pll_ops,
1174 .parent = &tegra_clk_32k,
1175 .cf_min = 0, /* FIXME */
1176 .cf_max = 0, /* FIXME */
1177 .vco_min = 12000000,
1178 .vco_max = 26000000,
1179 .pll_table = tegra_pll_s_table,
1180 .max_rate = 26000000,
1183 static struct clk_mux_sel tegra_clk_m_sel[] = {
1184 { .input = &tegra_clk_32k, .value = 0},
1185 { .input = &tegra_pll_s, .value = 1},
1188 static struct clk tegra_clk_m = {
1190 .flags = ENABLE_ON_INIT,
1191 .ops = &tegra_clk_m_ops,
1192 .inputs = tegra_clk_m_sel,
1194 .reg_mask = (1<<28),
1196 .max_rate = 26000000,
1199 static struct clk_pll_table tegra_pll_c_table[] = {
1200 { 0, 0, 0, 0, 0, 0 },
1203 static struct clk tegra_pll_c = {
1205 .flags = PLL_HAS_CPCON,
1206 .ops = &tegra_pll_ops,
1208 .input_min = 2000000,
1209 .input_max = 31000000,
1210 .parent = &tegra_clk_m,
1213 .vco_min = 20000000,
1214 .vco_max = 1400000000,
1215 .pll_table = tegra_pll_c_table,
1216 .max_rate = 600000000,
1219 static struct clk tegra_pll_c_out1 = {
1220 .name = "pll_c_out1",
1221 .ops = &tegra_pll_div_ops,
1223 .parent = &tegra_pll_c,
1226 .max_rate = 600000000,
1229 static struct clk_pll_table tegra_pll_m_table[] = {
1230 { 12000000, 666000000, 666, 12, 1, 8},
1231 { 13000000, 666000000, 666, 13, 1, 8},
1232 { 19200000, 666000000, 555, 16, 1, 8},
1233 { 26000000, 666000000, 666, 26, 1, 8},
1234 { 12000000, 600000000, 600, 12, 1, 8},
1235 { 13000000, 600000000, 600, 13, 1, 8},
1236 { 19200000, 600000000, 375, 12, 1, 6},
1237 { 26000000, 600000000, 600, 26, 1, 8},
1238 { 0, 0, 0, 0, 0, 0 },
1241 static struct clk tegra_pll_m = {
1243 .flags = PLL_HAS_CPCON,
1244 .ops = &tegra_pll_ops,
1246 .input_min = 2000000,
1247 .input_max = 31000000,
1248 .parent = &tegra_clk_m,
1251 .vco_min = 20000000,
1252 .vco_max = 1200000000,
1253 .pll_table = tegra_pll_m_table,
1254 .max_rate = 800000000,
1257 static struct clk tegra_pll_m_out1 = {
1258 .name = "pll_m_out1",
1259 .ops = &tegra_pll_div_ops,
1261 .parent = &tegra_pll_m,
1264 .max_rate = 600000000,
1267 static struct clk_pll_table tegra_pll_p_table[] = {
1268 { 12000000, 216000000, 432, 12, 2, 8},
1269 { 13000000, 216000000, 432, 13, 2, 8},
1270 { 19200000, 216000000, 90, 4, 2, 1},
1271 { 26000000, 216000000, 432, 26, 2, 8},
1272 { 12000000, 432000000, 432, 12, 1, 8},
1273 { 13000000, 432000000, 432, 13, 1, 8},
1274 { 19200000, 432000000, 90, 4, 1, 1},
1275 { 26000000, 432000000, 432, 26, 1, 8},
1276 { 0, 0, 0, 0, 0, 0 },
1279 static struct clk tegra_pll_p = {
1281 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1282 .ops = &tegra_pll_ops,
1284 .input_min = 2000000,
1285 .input_max = 31000000,
1286 .parent = &tegra_clk_m,
1289 .vco_min = 20000000,
1290 .vco_max = 1400000000,
1291 .pll_table = tegra_pll_p_table,
1292 .max_rate = 432000000,
1295 static struct clk tegra_pll_p_out1 = {
1296 .name = "pll_p_out1",
1297 .ops = &tegra_pll_div_ops,
1298 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1299 .parent = &tegra_pll_p,
1302 .max_rate = 432000000,
1305 static struct clk tegra_pll_p_out2 = {
1306 .name = "pll_p_out2",
1307 .ops = &tegra_pll_div_ops,
1308 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1309 .parent = &tegra_pll_p,
1312 .max_rate = 432000000,
1315 static struct clk tegra_pll_p_out3 = {
1316 .name = "pll_p_out3",
1317 .ops = &tegra_pll_div_ops,
1318 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1319 .parent = &tegra_pll_p,
1322 .max_rate = 432000000,
1325 static struct clk tegra_pll_p_out4 = {
1326 .name = "pll_p_out4",
1327 .ops = &tegra_pll_div_ops,
1328 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1329 .parent = &tegra_pll_p,
1332 .max_rate = 432000000,
1335 static struct clk_pll_table tegra_pll_a_table[] = {
1336 { 28800000, 56448000, 49, 25, 1, 1},
1337 { 28800000, 73728000, 64, 25, 1, 1},
1338 { 28800000, 11289600, 49, 25, 1, 1},
1339 { 28800000, 12288000, 64, 25, 1, 1},
1340 { 28800000, 24000000, 5, 6, 1, 1},
1341 { 0, 0, 0, 0, 0, 0 },
1344 static struct clk tegra_pll_a = {
1346 .flags = PLL_HAS_CPCON,
1347 .ops = &tegra_pll_ops,
1349 .input_min = 2000000,
1350 .input_max = 31000000,
1351 .parent = &tegra_pll_p_out1,
1354 .vco_min = 20000000,
1355 .vco_max = 1400000000,
1356 .pll_table = tegra_pll_a_table,
1357 .max_rate = 56448000,
1360 static struct clk tegra_pll_a_out0 = {
1361 .name = "pll_a_out0",
1362 .ops = &tegra_pll_div_ops,
1364 .parent = &tegra_pll_a,
1367 .max_rate = 56448000,
1370 static struct clk_pll_table tegra_pll_d_table[] = {
1371 { 12000000, 216000000, 216, 12, 1, 4},
1372 { 13000000, 216000000, 216, 13, 1, 4},
1373 { 19200000, 216000000, 135, 12, 1, 3},
1374 { 26000000, 216000000, 216, 26, 1, 4},
1376 { 12000000, 594000000, 594, 12, 1, 8},
1377 { 13000000, 594000000, 594, 13, 1, 8},
1378 { 19200000, 594000000, 495, 16, 1, 8},
1379 { 26000000, 594000000, 594, 26, 1, 8},
1381 { 12000000, 1000000000, 1000, 12, 1, 12},
1382 { 13000000, 1000000000, 1000, 13, 1, 12},
1383 { 19200000, 1000000000, 625, 12, 1, 8},
1384 { 26000000, 1000000000, 1000, 26, 1, 12},
1386 { 0, 0, 0, 0, 0, 0 },
1389 static struct clk tegra_pll_d = {
1391 .flags = PLL_HAS_CPCON | PLLD,
1392 .ops = &tegra_pll_ops,
1394 .input_min = 2000000,
1395 .input_max = 40000000,
1396 .parent = &tegra_clk_m,
1399 .vco_min = 40000000,
1400 .vco_max = 1000000000,
1401 .pll_table = tegra_pll_d_table,
1402 .max_rate = 1000000000,
1405 static struct clk tegra_pll_d_out0 = {
1406 .name = "pll_d_out0",
1407 .ops = &tegra_pll_div_ops,
1408 .flags = DIV_2 | PLLD,
1409 .parent = &tegra_pll_d,
1410 .max_rate = 500000000,
1413 static struct clk_pll_table tegra_pll_u_table[] = {
1414 { 12000000, 480000000, 960, 12, 2, 0},
1415 { 13000000, 480000000, 960, 13, 2, 0},
1416 { 19200000, 480000000, 200, 4, 2, 0},
1417 { 26000000, 480000000, 960, 26, 2, 0},
1418 { 0, 0, 0, 0, 0, 0 },
1421 static struct clk tegra_pll_u = {
1424 .ops = &tegra_pll_ops,
1426 .input_min = 2000000,
1427 .input_max = 40000000,
1428 .parent = &tegra_clk_m,
1431 .vco_min = 480000000,
1432 .vco_max = 960000000,
1433 .pll_table = tegra_pll_u_table,
1434 .max_rate = 480000000,
1437 static struct clk_pll_table tegra_pll_x_table[] = {
1439 { 12000000, 1000000000, 1000, 12, 1, 12},
1440 { 13000000, 1000000000, 1000, 13, 1, 12},
1441 { 19200000, 1000000000, 625, 12, 1, 8},
1442 { 26000000, 1000000000, 1000, 26, 1, 12},
1445 { 12000000, 912000000, 912, 12, 1, 12},
1446 { 13000000, 912000000, 912, 13, 1, 12},
1447 { 19200000, 912000000, 760, 16, 1, 8},
1448 { 26000000, 912000000, 912, 26, 1, 12},
1451 { 12000000, 816000000, 816, 12, 1, 12},
1452 { 13000000, 816000000, 816, 13, 1, 12},
1453 { 19200000, 816000000, 680, 16, 1, 8},
1454 { 26000000, 816000000, 816, 26, 1, 12},
1457 { 12000000, 760000000, 760, 12, 1, 12},
1458 { 13000000, 760000000, 760, 13, 1, 12},
1459 { 19200000, 760000000, 950, 24, 1, 8},
1460 { 26000000, 760000000, 760, 26, 1, 12},
1463 { 12000000, 608000000, 760, 12, 1, 12},
1464 { 13000000, 608000000, 760, 13, 1, 12},
1465 { 19200000, 608000000, 380, 12, 1, 8},
1466 { 26000000, 608000000, 760, 26, 1, 12},
1469 { 12000000, 456000000, 456, 12, 1, 12},
1470 { 13000000, 456000000, 456, 13, 1, 12},
1471 { 19200000, 456000000, 380, 16, 1, 8},
1472 { 26000000, 456000000, 456, 26, 1, 12},
1475 { 12000000, 312000000, 312, 12, 1, 12},
1476 { 13000000, 312000000, 312, 13, 1, 12},
1477 { 19200000, 312000000, 260, 16, 1, 8},
1478 { 26000000, 312000000, 312, 26, 1, 12},
1480 { 0, 0, 0, 0, 0, 0 },
1483 static struct clk tegra_pll_x = {
1485 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1486 .ops = &tegra_pllx_ops,
1488 .input_min = 2000000,
1489 .input_max = 31000000,
1490 .parent = &tegra_clk_m,
1493 .vco_min = 20000000,
1494 .vco_max = 1200000000,
1495 .pll_table = tegra_pll_x_table,
1496 .max_rate = 1000000000,
1499 static struct clk tegra_clk_d = {
1501 .flags = PERIPH_NO_RESET,
1502 .ops = &tegra_clk_double_ops,
1506 .parent = &tegra_clk_m,
1507 .max_rate = 52000000,
1510 /* dap_mclk1, belongs to the cdev1 pingroup. */
1511 static struct clk tegra_dev1_clk = {
1513 .ops = &tegra_cdev_clk_ops,
1516 .max_rate = 26000000,
1519 /* dap_mclk2, belongs to the cdev2 pingroup. */
1520 static struct clk tegra_dev2_clk = {
1522 .ops = &tegra_cdev_clk_ops,
1525 .max_rate = 26000000,
1528 /* initialized before peripheral clocks */
1529 static struct clk_mux_sel mux_audio_sync_clk[8+1];
1530 static const struct audio_sources {
1533 } mux_audio_sync_clk_sources[] = {
1534 { .name = "spdif_in", .value = 0 },
1535 { .name = "i2s1", .value = 1 },
1536 { .name = "i2s2", .value = 2 },
1537 { .name = "pll_a_out0", .value = 4 },
1538 #if 0 /* FIXME: not implemented */
1539 { .name = "ac97", .value = 3 },
1540 { .name = "ext_audio_clk2", .value = 5 },
1541 { .name = "ext_audio_clk1", .value = 6 },
1542 { .name = "ext_vimclk", .value = 7 },
1547 static struct clk tegra_clk_audio = {
1549 .inputs = mux_audio_sync_clk,
1551 .max_rate = 24000000,
1552 .ops = &tegra_audio_sync_clk_ops
1555 static struct clk tegra_clk_audio_2x = {
1557 .flags = PERIPH_NO_RESET,
1558 .max_rate = 48000000,
1559 .ops = &tegra_clk_double_ops,
1563 .parent = &tegra_clk_audio,
1566 struct clk_lookup tegra_audio_clk_lookups[] = {
1567 { .con_id = "audio", .clk = &tegra_clk_audio },
1568 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1571 /* This is called after peripheral clocks are initialized, as the
1572 * audio_sync clock depends on some of the peripheral clocks.
1575 static void init_audio_sync_clock_mux(void)
1578 struct clk_mux_sel *sel = mux_audio_sync_clk;
1579 const struct audio_sources *src = mux_audio_sync_clk_sources;
1580 struct clk_lookup *lookup;
1582 for (i = 0; src->name; i++, sel++, src++) {
1583 sel->input = tegra_get_clock_by_name(src->name);
1585 pr_err("%s: could not find clk %s\n", __func__,
1587 sel->value = src->value;
1590 lookup = tegra_audio_clk_lookups;
1591 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1592 clk_init(lookup->clk);
1597 static struct clk_mux_sel mux_cclk[] = {
1598 { .input = &tegra_clk_m, .value = 0},
1599 { .input = &tegra_pll_c, .value = 1},
1600 { .input = &tegra_clk_32k, .value = 2},
1601 { .input = &tegra_pll_m, .value = 3},
1602 { .input = &tegra_pll_p, .value = 4},
1603 { .input = &tegra_pll_p_out4, .value = 5},
1604 { .input = &tegra_pll_p_out3, .value = 6},
1605 { .input = &tegra_clk_d, .value = 7},
1606 { .input = &tegra_pll_x, .value = 8},
1610 static struct clk_mux_sel mux_sclk[] = {
1611 { .input = &tegra_clk_m, .value = 0},
1612 { .input = &tegra_pll_c_out1, .value = 1},
1613 { .input = &tegra_pll_p_out4, .value = 2},
1614 { .input = &tegra_pll_p_out3, .value = 3},
1615 { .input = &tegra_pll_p_out2, .value = 4},
1616 { .input = &tegra_clk_d, .value = 5},
1617 { .input = &tegra_clk_32k, .value = 6},
1618 { .input = &tegra_pll_m_out1, .value = 7},
1622 static struct clk tegra_clk_cclk = {
1626 .ops = &tegra_super_ops,
1627 .max_rate = 1000000000,
1630 static struct clk tegra_clk_sclk = {
1634 .ops = &tegra_super_ops,
1635 .max_rate = 240000000,
1638 static struct clk tegra_clk_virtual_cpu = {
1640 .parent = &tegra_clk_cclk,
1641 .main = &tegra_pll_x,
1642 .backup = &tegra_pll_p,
1643 .ops = &tegra_cpu_ops,
1644 .max_rate = 1000000000,
1645 .dvfs = &tegra_dvfs_virtual_cpu_dvfs,
1648 static struct clk tegra_clk_cop = {
1650 .parent = &tegra_clk_sclk,
1651 .ops = &tegra_cop_ops,
1652 .max_rate = 240000000,
1655 static struct clk tegra_clk_hclk = {
1658 .parent = &tegra_clk_sclk,
1661 .ops = &tegra_bus_ops,
1662 .max_rate = 240000000,
1665 static struct clk tegra_clk_pclk = {
1668 .parent = &tegra_clk_hclk,
1671 .ops = &tegra_bus_ops,
1672 .max_rate = 120000000,
1675 static struct clk tegra_clk_blink = {
1677 .parent = &tegra_clk_32k,
1679 .ops = &tegra_blink_clk_ops,
1683 static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1684 { .input = &tegra_pll_m, .value = 0},
1685 { .input = &tegra_pll_c, .value = 1},
1686 { .input = &tegra_pll_p, .value = 2},
1687 { .input = &tegra_pll_a_out0, .value = 3},
1691 static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1692 { .input = &tegra_pll_m, .value = 0},
1693 { .input = &tegra_pll_c, .value = 1},
1694 { .input = &tegra_pll_p, .value = 2},
1695 { .input = &tegra_clk_m, .value = 3},
1699 static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1700 { .input = &tegra_pll_p, .value = 0},
1701 { .input = &tegra_pll_c, .value = 1},
1702 { .input = &tegra_pll_m, .value = 2},
1703 { .input = &tegra_clk_m, .value = 3},
1707 static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1708 {.input = &tegra_pll_a_out0, .value = 0},
1709 {.input = &tegra_clk_audio_2x, .value = 1},
1710 {.input = &tegra_pll_p, .value = 2},
1711 {.input = &tegra_clk_m, .value = 3},
1715 static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1716 {.input = &tegra_pll_p, .value = 0},
1717 {.input = &tegra_pll_d_out0, .value = 1},
1718 {.input = &tegra_pll_c, .value = 2},
1719 {.input = &tegra_clk_m, .value = 3},
1723 static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1724 {.input = &tegra_pll_p, .value = 0},
1725 {.input = &tegra_pll_c, .value = 1},
1726 {.input = &tegra_clk_audio, .value = 2},
1727 {.input = &tegra_clk_m, .value = 3},
1728 {.input = &tegra_clk_32k, .value = 4},
1732 static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1733 {.input = &tegra_pll_p, .value = 0},
1734 {.input = &tegra_pll_c, .value = 1},
1735 {.input = &tegra_pll_m, .value = 2},
1739 static struct clk_mux_sel mux_clk_m[] = {
1740 { .input = &tegra_clk_m, .value = 0},
1744 static struct clk_mux_sel mux_pllp_out3[] = {
1745 { .input = &tegra_pll_p_out3, .value = 0},
1749 static struct clk_mux_sel mux_plld[] = {
1750 { .input = &tegra_pll_d, .value = 0},
1754 static struct clk_mux_sel mux_clk_32k[] = {
1755 { .input = &tegra_clk_32k, .value = 0},
1759 #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
1766 .ops = &tegra_periph_clk_ops, \
1767 .clk_num = _clk_num, \
1769 .inputs = _inputs, \
1774 struct clk tegra_periph_clks[] = {
1775 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
1776 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
1777 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1778 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1779 /* FIXME: spdif has 2 clocks but 1 enable */
1780 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1781 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
1782 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
1783 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1784 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1785 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1786 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1787 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1788 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1789 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1790 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1791 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1792 /* FIXME: vfir shares an enable with uartb */
1793 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1794 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1795 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1796 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1797 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1798 PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1799 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
1800 /* FIXME: what is la? */
1801 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1802 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1803 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1804 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1805 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1806 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1807 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1808 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1809 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1810 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1811 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1812 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1813 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1814 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1815 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1816 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1817 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1818 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 */
1819 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1820 /* FIXME: vi and vi_sensor share an enable */
1821 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1822 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 */
1823 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1824 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1825 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1826 /* FIXME: cve and tvo share an enable */
1827 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1828 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1829 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1830 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1831 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1832 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1833 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1834 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1835 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1836 PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, 800000000, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB),
1837 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
1838 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
1839 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
1840 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
1843 #define CLK_DUPLICATE(_name, _dev, _con) \
1852 /* Some clocks may be used by different drivers depending on the board
1853 * configuration. List those here to register them twice in the clock lookup
1854 * table under two names.
1856 struct clk_duplicate tegra_clk_duplicates[] = {
1857 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
1858 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
1859 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
1860 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
1861 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
1862 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
1863 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
1864 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
1865 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
1866 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
1867 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
1868 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
1869 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
1870 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
1873 #define CLK(dev, con, ck) \
1880 struct clk_lookup tegra_clk_lookups[] = {
1881 /* external root sources */
1882 CLK(NULL, "32k_clk", &tegra_clk_32k),
1883 CLK(NULL, "pll_s", &tegra_pll_s),
1884 CLK(NULL, "clk_m", &tegra_clk_m),
1885 CLK(NULL, "pll_m", &tegra_pll_m),
1886 CLK(NULL, "pll_m_out1", &tegra_pll_m_out1),
1887 CLK(NULL, "pll_c", &tegra_pll_c),
1888 CLK(NULL, "pll_c_out1", &tegra_pll_c_out1),
1889 CLK(NULL, "pll_p", &tegra_pll_p),
1890 CLK(NULL, "pll_p_out1", &tegra_pll_p_out1),
1891 CLK(NULL, "pll_p_out2", &tegra_pll_p_out2),
1892 CLK(NULL, "pll_p_out3", &tegra_pll_p_out3),
1893 CLK(NULL, "pll_p_out4", &tegra_pll_p_out4),
1894 CLK(NULL, "pll_a", &tegra_pll_a),
1895 CLK(NULL, "pll_a_out0", &tegra_pll_a_out0),
1896 CLK(NULL, "pll_d", &tegra_pll_d),
1897 CLK(NULL, "pll_d_out0", &tegra_pll_d_out0),
1898 CLK(NULL, "pll_u", &tegra_pll_u),
1899 CLK(NULL, "pll_x", &tegra_pll_x),
1900 CLK(NULL, "cclk", &tegra_clk_cclk),
1901 CLK(NULL, "sclk", &tegra_clk_sclk),
1902 CLK(NULL, "hclk", &tegra_clk_hclk),
1903 CLK(NULL, "pclk", &tegra_clk_pclk),
1904 CLK(NULL, "clk_d", &tegra_clk_d),
1905 CLK(NULL, "clk_dev1", &tegra_dev1_clk),
1906 CLK(NULL, "clk_dev2", &tegra_dev2_clk),
1907 CLK(NULL, "cpu", &tegra_clk_virtual_cpu),
1908 CLK(NULL, "blink", &tegra_clk_blink),
1909 CLK("tegra-avp", "cop", &tegra_clk_cop),
1912 void __init tegra2_init_clocks(void)
1915 struct clk_lookup *cl;
1917 struct clk_duplicate *cd;
1919 for (i = 0; i < ARRAY_SIZE(tegra_clk_lookups); i++) {
1920 cl = &tegra_clk_lookups[i];
1925 for (i = 0; i < ARRAY_SIZE(tegra_periph_clks); i++) {
1926 c = &tegra_periph_clks[i];
1934 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
1935 cd = &tegra_clk_duplicates[i];
1936 c = tegra_get_clock_by_name(cd->name);
1942 pr_err("%s: Unknown duplicate clock %s\n", __func__,
1947 init_audio_sync_clock_mux();
1951 static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
1952 PERIPH_CLK_SOURCE_NUM + 19];
1954 void tegra_clk_suspend(void)
1956 unsigned long off, i;
1958 u32 *ctx = clk_rst_suspend;
1960 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
1961 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_BASE);
1962 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
1963 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
1964 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
1965 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
1966 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
1968 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
1969 *ctx++ = clk_readl(tegra_pll_p_out1.reg);
1970 *ctx++ = clk_readl(tegra_pll_p_out3.reg);
1971 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
1972 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
1974 *ctx++ = clk_readl(tegra_clk_cclk.reg);
1975 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
1977 *ctx++ = clk_readl(tegra_clk_sclk.reg);
1978 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
1979 *ctx++ = clk_readl(tegra_clk_pclk.reg);
1981 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
1983 if (off == PERIPH_CLK_SOURCE_EMC)
1985 *ctx++ = clk_readl(off);
1989 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
1990 *ctx++ = clk_readl(off);
1993 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
1994 *ctx++ = clk_readl(off);
1996 *ctx++ = clk_readl(MISC_CLK_ENB);
1997 *ctx++ = clk_readl(CLK_MASK_ARM);
1999 pllx_misc = clk_readl(tegra_pll_x.reg + PLL_MISC(&tegra_pll_x));
2000 pllx_misc &= ~PLL_MISC_LOCK_ENABLE(&tegra_pll_x);
2001 clk_writel(pllx_misc, tegra_pll_x.reg + PLL_MISC(&tegra_pll_x));
2004 void tegra_clk_resume(void)
2006 unsigned long off, i;
2007 const u32 *ctx = clk_rst_suspend;
2010 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2012 clk_writel(val, OSC_CTRL);
2014 clk_writel(*ctx++, tegra_pll_p.reg + PLL_BASE);
2015 clk_writel(*ctx++, tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
2016 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2017 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2018 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2019 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2022 clk_writel(*ctx++, tegra_pll_m_out1.reg);
2023 clk_writel(*ctx++, tegra_pll_p_out1.reg);
2024 clk_writel(*ctx++, tegra_pll_p_out3.reg);
2025 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2026 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2028 clk_writel(*ctx++, tegra_clk_cclk.reg);
2029 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2031 clk_writel(*ctx++, tegra_clk_sclk.reg);
2032 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2033 clk_writel(*ctx++, tegra_clk_pclk.reg);
2035 /* enable all clocks before configuring clock sources */
2036 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2037 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2038 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2041 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2043 if (off == PERIPH_CLK_SOURCE_EMC)
2045 clk_writel(*ctx++, off);
2050 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2051 clk_writel(*ctx++, off);
2055 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2056 clk_writel(*ctx++, off);
2059 clk_writel(*ctx++, MISC_CLK_ENB);
2060 clk_writel(*ctx++, CLK_MASK_ARM);