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/clkdev.h>
27 #include <linux/clk.h>
29 #include <mach/iomap.h>
30 #include <mach/suspend.h>
34 #include "tegra2_emc.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
77 #define SDMMC_CLK_INT_FB_SEL (1 << 23)
78 #define SDMMC_CLK_INT_FB_DLY_SHIFT 16
79 #define SDMMC_CLK_INT_FB_DLY_MASK (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT)
82 #define PLL_BASE_BYPASS (1<<31)
83 #define PLL_BASE_ENABLE (1<<30)
84 #define PLL_BASE_REF_ENABLE (1<<29)
85 #define PLL_BASE_OVERRIDE (1<<28)
86 #define PLL_BASE_DIVP_MASK (0x7<<20)
87 #define PLL_BASE_DIVP_SHIFT 20
88 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
89 #define PLL_BASE_DIVN_SHIFT 8
90 #define PLL_BASE_DIVM_MASK (0x1F)
91 #define PLL_BASE_DIVM_SHIFT 0
93 #define PLL_OUT_RATIO_MASK (0xFF<<8)
94 #define PLL_OUT_RATIO_SHIFT 8
95 #define PLL_OUT_OVERRIDE (1<<2)
96 #define PLL_OUT_CLKEN (1<<1)
97 #define PLL_OUT_RESET_DISABLE (1<<0)
99 #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
101 #define PLL_MISC_DCCON_SHIFT 20
102 #define PLL_MISC_CPCON_SHIFT 8
103 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
104 #define PLL_MISC_LFCON_SHIFT 4
105 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
106 #define PLL_MISC_VCOCON_SHIFT 0
107 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
109 #define PLLU_BASE_POST_DIV (1<<20)
111 #define PLLD_MISC_CLKENABLE (1<<30)
112 #define PLLD_MISC_DIV_RST (1<<23)
113 #define PLLD_MISC_DCCON_SHIFT 12
115 #define PLLE_MISC_READY (1 << 15)
117 #define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
118 #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
119 #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
121 #define SUPER_CLK_MUX 0x00
122 #define SUPER_STATE_SHIFT 28
123 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
124 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
125 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
126 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
127 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
128 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
129 #define SUPER_SOURCE_MASK 0xF
130 #define SUPER_FIQ_SOURCE_SHIFT 12
131 #define SUPER_IRQ_SOURCE_SHIFT 8
132 #define SUPER_RUN_SOURCE_SHIFT 4
133 #define SUPER_IDLE_SOURCE_SHIFT 0
135 #define SUPER_CLK_DIVIDER 0x04
137 #define BUS_CLK_DISABLE (1<<3)
138 #define BUS_CLK_DIV_MASK 0x3
141 #define PMC_CTRL_BLINK_ENB (1 << 7)
143 #define PMC_DPD_PADS_ORIDE 0x1c
144 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
146 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
147 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
148 #define PMC_BLINK_TIMER_ENB (1 << 15)
149 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
150 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
152 static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
153 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
156 * Some clocks share a register with other clocks. Any clock op that
157 * non-atomically modifies a register used by another clock must lock
158 * clock_register_lock first.
160 static DEFINE_SPINLOCK(clock_register_lock);
162 #define clk_writel(value, reg) \
163 __raw_writel(value, (u32)reg_clk_base + (reg))
164 #define clk_readl(reg) \
165 __raw_readl((u32)reg_clk_base + (reg))
166 #define pmc_writel(value, reg) \
167 __raw_writel(value, (u32)reg_pmc_base + (reg))
168 #define pmc_readl(reg) \
169 __raw_readl((u32)reg_pmc_base + (reg))
171 unsigned long clk_measure_input_freq(void)
173 u32 clock_autodetect;
174 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
175 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
176 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
177 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
179 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
181 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
183 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
186 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
192 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
194 s64 divider_u71 = parent_rate * 2;
195 divider_u71 += rate - 1;
196 do_div(divider_u71, rate);
198 if (divider_u71 - 2 < 0)
201 if (divider_u71 - 2 > 255)
204 return divider_u71 - 2;
207 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
211 divider_u16 = parent_rate;
212 divider_u16 += rate - 1;
213 do_div(divider_u16, rate);
215 if (divider_u16 - 1 < 0)
218 if (divider_u16 - 1 > 255)
221 return divider_u16 - 1;
224 /* clk_m functions */
225 static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
227 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
229 c->rate = clk_measure_input_freq();
232 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
235 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
238 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
241 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
244 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
247 clk_writel(auto_clock_control, OSC_CTRL);
251 static void tegra2_clk_m_init(struct clk *c)
253 pr_debug("%s on clock %s\n", __func__, c->name);
254 tegra2_clk_m_autodetect_rate(c);
257 static int tegra2_clk_m_enable(struct clk *c)
259 pr_debug("%s on clock %s\n", __func__, c->name);
263 static void tegra2_clk_m_disable(struct clk *c)
265 pr_debug("%s on clock %s\n", __func__, c->name);
269 static struct clk_ops tegra_clk_m_ops = {
270 .init = tegra2_clk_m_init,
271 .enable = tegra2_clk_m_enable,
272 .disable = tegra2_clk_m_disable,
275 void tegra2_periph_reset_assert(struct clk *c)
277 BUG_ON(!c->ops->reset);
278 c->ops->reset(c, true);
281 void tegra2_periph_reset_deassert(struct clk *c)
283 BUG_ON(!c->ops->reset);
284 c->ops->reset(c, false);
287 /* super clock functions */
288 /* "super clocks" on tegra have two-stage muxes and a clock skipping
289 * super divider. We will ignore the clock skipping divider, since we
290 * can't lower the voltage when using the clock skip, but we can if we
291 * lower the PLL frequency.
293 static void tegra2_super_clk_init(struct clk *c)
298 const struct clk_mux_sel *sel;
299 val = clk_readl(c->reg + SUPER_CLK_MUX);
301 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
302 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
303 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
304 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
305 source = (val >> shift) & SUPER_SOURCE_MASK;
306 for (sel = c->inputs; sel->input != NULL; sel++) {
307 if (sel->value == source)
310 BUG_ON(sel->input == NULL);
311 c->parent = sel->input;
314 static int tegra2_super_clk_enable(struct clk *c)
316 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
320 static void tegra2_super_clk_disable(struct clk *c)
322 pr_debug("%s on clock %s\n", __func__, c->name);
324 /* oops - don't disable the CPU clock! */
328 static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
331 const struct clk_mux_sel *sel;
334 val = clk_readl(c->reg + SUPER_CLK_MUX);;
335 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
336 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
337 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
338 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
339 for (sel = c->inputs; sel->input != NULL; sel++) {
340 if (sel->input == p) {
341 val &= ~(SUPER_SOURCE_MASK << shift);
342 val |= sel->value << shift;
347 clk_writel(val, c->reg);
349 if (c->refcnt && c->parent)
350 clk_disable(c->parent);
359 static struct clk_ops tegra_super_ops = {
360 .init = tegra2_super_clk_init,
361 .enable = tegra2_super_clk_enable,
362 .disable = tegra2_super_clk_disable,
363 .set_parent = tegra2_super_clk_set_parent,
366 /* virtual cpu clock functions */
367 /* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
368 To change the frequency of these clocks, the parent pll may need to be
369 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
370 and then the clock moved back to the pll. To hide this sequence, a virtual
373 static void tegra2_cpu_clk_init(struct clk *c)
377 static int tegra2_cpu_clk_enable(struct clk *c)
382 static void tegra2_cpu_clk_disable(struct clk *c)
384 pr_debug("%s on clock %s\n", __func__, c->name);
386 /* oops - don't disable the CPU clock! */
390 static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
394 * Take an extra reference to the main pll so it doesn't turn
395 * off when we move the cpu off of it
397 clk_enable(c->u.cpu.main);
399 ret = clk_set_parent(c->parent, c->u.cpu.backup);
401 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
405 if (rate == clk_get_rate(c->u.cpu.backup))
408 ret = clk_set_rate(c->u.cpu.main, rate);
410 pr_err("Failed to change cpu pll to %lu\n", rate);
414 ret = clk_set_parent(c->parent, c->u.cpu.main);
416 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
421 clk_disable(c->u.cpu.main);
425 static struct clk_ops tegra_cpu_ops = {
426 .init = tegra2_cpu_clk_init,
427 .enable = tegra2_cpu_clk_enable,
428 .disable = tegra2_cpu_clk_disable,
429 .set_rate = tegra2_cpu_clk_set_rate,
432 /* bus clock functions */
433 static void tegra2_bus_clk_init(struct clk *c)
435 u32 val = clk_readl(c->reg);
436 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
437 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
441 static int tegra2_bus_clk_enable(struct clk *c)
446 spin_lock_irqsave(&clock_register_lock, flags);
448 val = clk_readl(c->reg);
449 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
450 clk_writel(val, c->reg);
452 spin_unlock_irqrestore(&clock_register_lock, flags);
457 static void tegra2_bus_clk_disable(struct clk *c)
462 spin_lock_irqsave(&clock_register_lock, flags);
464 val = clk_readl(c->reg);
465 val |= BUS_CLK_DISABLE << c->reg_shift;
466 clk_writel(val, c->reg);
468 spin_unlock_irqrestore(&clock_register_lock, flags);
471 static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
474 unsigned long parent_rate = clk_get_rate(c->parent);
479 spin_lock_irqsave(&clock_register_lock, flags);
481 val = clk_readl(c->reg);
482 for (i = 1; i <= 4; i++) {
483 if (rate == parent_rate / i) {
484 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
485 val |= (i - 1) << c->reg_shift;
486 clk_writel(val, c->reg);
494 spin_unlock_irqrestore(&clock_register_lock, flags);
499 static struct clk_ops tegra_bus_ops = {
500 .init = tegra2_bus_clk_init,
501 .enable = tegra2_bus_clk_enable,
502 .disable = tegra2_bus_clk_disable,
503 .set_rate = tegra2_bus_clk_set_rate,
506 /* Blink output functions */
508 static void tegra2_blink_clk_init(struct clk *c)
512 val = pmc_readl(PMC_CTRL);
513 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
515 val = pmc_readl(c->reg);
517 if (val & PMC_BLINK_TIMER_ENB) {
520 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
521 PMC_BLINK_TIMER_DATA_ON_MASK;
522 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
523 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
525 /* each tick in the blink timer is 4 32KHz clocks */
532 static int tegra2_blink_clk_enable(struct clk *c)
536 val = pmc_readl(PMC_DPD_PADS_ORIDE);
537 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
539 val = pmc_readl(PMC_CTRL);
540 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
545 static void tegra2_blink_clk_disable(struct clk *c)
549 val = pmc_readl(PMC_CTRL);
550 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
552 val = pmc_readl(PMC_DPD_PADS_ORIDE);
553 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
556 static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
558 unsigned long parent_rate = clk_get_rate(c->parent);
559 if (rate >= parent_rate) {
561 pmc_writel(0, c->reg);
566 on_off = DIV_ROUND_UP(parent_rate / 8, rate);
569 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
570 PMC_BLINK_TIMER_DATA_ON_SHIFT;
571 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
572 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
574 val |= PMC_BLINK_TIMER_ENB;
575 pmc_writel(val, c->reg);
581 static struct clk_ops tegra_blink_clk_ops = {
582 .init = &tegra2_blink_clk_init,
583 .enable = &tegra2_blink_clk_enable,
584 .disable = &tegra2_blink_clk_disable,
585 .set_rate = &tegra2_blink_clk_set_rate,
589 static int tegra2_pll_clk_wait_for_lock(struct clk *c)
591 udelay(c->u.pll.lock_delay);
596 static void tegra2_pll_clk_init(struct clk *c)
598 u32 val = clk_readl(c->reg + PLL_BASE);
600 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
602 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
603 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
606 } else if (val & PLL_BASE_BYPASS) {
610 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
611 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
613 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
615 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
619 static int tegra2_pll_clk_enable(struct clk *c)
622 pr_debug("%s on clock %s\n", __func__, c->name);
624 val = clk_readl(c->reg + PLL_BASE);
625 val &= ~PLL_BASE_BYPASS;
626 val |= PLL_BASE_ENABLE;
627 clk_writel(val, c->reg + PLL_BASE);
629 tegra2_pll_clk_wait_for_lock(c);
634 static void tegra2_pll_clk_disable(struct clk *c)
637 pr_debug("%s on clock %s\n", __func__, c->name);
639 val = clk_readl(c->reg);
640 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
641 clk_writel(val, c->reg);
644 static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
647 unsigned long input_rate;
648 const struct clk_pll_freq_table *sel;
650 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
652 input_rate = clk_get_rate(c->parent);
653 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
654 if (sel->input_rate == input_rate && sel->output_rate == rate) {
656 c->div = sel->m * sel->p;
658 val = clk_readl(c->reg + PLL_BASE);
659 if (c->flags & PLL_FIXED)
660 val |= PLL_BASE_OVERRIDE;
661 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
663 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
664 (sel->n << PLL_BASE_DIVN_SHIFT);
665 BUG_ON(sel->p < 1 || sel->p > 2);
666 if (c->flags & PLLU) {
668 val |= PLLU_BASE_POST_DIV;
671 val |= 1 << PLL_BASE_DIVP_SHIFT;
673 clk_writel(val, c->reg + PLL_BASE);
675 if (c->flags & PLL_HAS_CPCON) {
676 val = clk_readl(c->reg + PLL_MISC(c));
677 val &= ~PLL_MISC_CPCON_MASK;
678 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
679 clk_writel(val, c->reg + PLL_MISC(c));
683 tegra2_pll_clk_enable(c);
691 static struct clk_ops tegra_pll_ops = {
692 .init = tegra2_pll_clk_init,
693 .enable = tegra2_pll_clk_enable,
694 .disable = tegra2_pll_clk_disable,
695 .set_rate = tegra2_pll_clk_set_rate,
698 static void tegra2_pllx_clk_init(struct clk *c)
700 tegra2_pll_clk_init(c);
702 if (tegra_sku_id() == 7)
703 c->max_rate = 750000000;
706 static struct clk_ops tegra_pllx_ops = {
707 .init = tegra2_pllx_clk_init,
708 .enable = tegra2_pll_clk_enable,
709 .disable = tegra2_pll_clk_disable,
710 .set_rate = tegra2_pll_clk_set_rate,
713 static int tegra2_plle_clk_enable(struct clk *c)
717 pr_debug("%s on clock %s\n", __func__, c->name);
721 val = clk_readl(c->reg + PLL_BASE);
722 if (!(val & PLLE_MISC_READY))
725 val = clk_readl(c->reg + PLL_BASE);
726 val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS;
727 clk_writel(val, c->reg + PLL_BASE);
732 static struct clk_ops tegra_plle_ops = {
733 .init = tegra2_pll_clk_init,
734 .enable = tegra2_plle_clk_enable,
735 .set_rate = tegra2_pll_clk_set_rate,
738 /* Clock divider ops */
739 static void tegra2_pll_div_clk_init(struct clk *c)
741 u32 val = clk_readl(c->reg);
743 val >>= c->reg_shift;
744 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
745 if (!(val & PLL_OUT_RESET_DISABLE))
748 if (c->flags & DIV_U71) {
749 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
750 c->div = (divu71 + 2);
752 } else if (c->flags & DIV_2) {
761 static int tegra2_pll_div_clk_enable(struct clk *c)
767 pr_debug("%s: %s\n", __func__, c->name);
768 if (c->flags & DIV_U71) {
769 spin_lock_irqsave(&clock_register_lock, flags);
770 val = clk_readl(c->reg);
771 new_val = val >> c->reg_shift;
774 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
776 val &= ~(0xFFFF << c->reg_shift);
777 val |= new_val << c->reg_shift;
778 clk_writel(val, c->reg);
779 spin_unlock_irqrestore(&clock_register_lock, flags);
781 } else if (c->flags & DIV_2) {
782 BUG_ON(!(c->flags & PLLD));
783 spin_lock_irqsave(&clock_register_lock, flags);
784 val = clk_readl(c->reg);
785 val &= ~PLLD_MISC_DIV_RST;
786 clk_writel(val, c->reg);
787 spin_unlock_irqrestore(&clock_register_lock, flags);
793 static void tegra2_pll_div_clk_disable(struct clk *c)
799 pr_debug("%s: %s\n", __func__, c->name);
800 if (c->flags & DIV_U71) {
801 spin_lock_irqsave(&clock_register_lock, flags);
802 val = clk_readl(c->reg);
803 new_val = val >> c->reg_shift;
806 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
808 val &= ~(0xFFFF << c->reg_shift);
809 val |= new_val << c->reg_shift;
810 clk_writel(val, c->reg);
811 spin_unlock_irqrestore(&clock_register_lock, flags);
812 } else if (c->flags & DIV_2) {
813 BUG_ON(!(c->flags & PLLD));
814 spin_lock_irqsave(&clock_register_lock, flags);
815 val = clk_readl(c->reg);
816 val |= PLLD_MISC_DIV_RST;
817 clk_writel(val, c->reg);
818 spin_unlock_irqrestore(&clock_register_lock, flags);
822 static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
827 unsigned long parent_rate = clk_get_rate(c->parent);
830 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
831 if (c->flags & DIV_U71) {
832 divider_u71 = clk_div71_get_divider(parent_rate, rate);
833 if (divider_u71 >= 0) {
834 spin_lock_irqsave(&clock_register_lock, flags);
835 val = clk_readl(c->reg);
836 new_val = val >> c->reg_shift;
838 if (c->flags & DIV_U71_FIXED)
839 new_val |= PLL_OUT_OVERRIDE;
840 new_val &= ~PLL_OUT_RATIO_MASK;
841 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
843 val &= ~(0xFFFF << c->reg_shift);
844 val |= new_val << c->reg_shift;
845 clk_writel(val, c->reg);
846 c->div = divider_u71 + 2;
848 spin_unlock_irqrestore(&clock_register_lock, flags);
851 } else if (c->flags & DIV_2) {
852 if (parent_rate == rate * 2)
858 static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
861 unsigned long parent_rate = clk_get_rate(c->parent);
862 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
864 if (c->flags & DIV_U71) {
865 divider = clk_div71_get_divider(parent_rate, rate);
868 return parent_rate * 2 / (divider + 2);
869 } else if (c->flags & DIV_2) {
870 return parent_rate / 2;
875 static struct clk_ops tegra_pll_div_ops = {
876 .init = tegra2_pll_div_clk_init,
877 .enable = tegra2_pll_div_clk_enable,
878 .disable = tegra2_pll_div_clk_disable,
879 .set_rate = tegra2_pll_div_clk_set_rate,
880 .round_rate = tegra2_pll_div_clk_round_rate,
885 static void tegra2_periph_clk_init(struct clk *c)
887 u32 val = clk_readl(c->reg);
888 const struct clk_mux_sel *mux = 0;
889 const struct clk_mux_sel *sel;
890 if (c->flags & MUX) {
891 for (sel = c->inputs; sel->input != NULL; sel++) {
892 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
897 c->parent = mux->input;
899 c->parent = c->inputs[0].input;
902 if (c->flags & DIV_U71) {
903 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
906 } else if (c->flags & DIV_U16) {
907 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
916 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
917 PERIPH_CLK_TO_ENB_BIT(c)))
919 if (!(c->flags & PERIPH_NO_RESET))
920 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
921 PERIPH_CLK_TO_ENB_BIT(c))
925 static int tegra2_periph_clk_enable(struct clk *c)
928 pr_debug("%s on clock %s\n", __func__, c->name);
930 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
931 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
932 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
933 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
934 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
935 if (c->flags & PERIPH_EMC_ENB) {
936 /* The EMC peripheral clock has 2 extra enable bits */
937 /* FIXME: Do they need to be disabled? */
938 val = clk_readl(c->reg);
940 clk_writel(val, c->reg);
945 static void tegra2_periph_clk_disable(struct clk *c)
947 pr_debug("%s on clock %s\n", __func__, c->name);
949 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
950 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
953 static void tegra2_periph_clk_reset(struct clk *c, bool assert)
955 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
957 pr_debug("%s %s on clock %s\n", __func__,
958 assert ? "assert" : "deassert", c->name);
959 if (!(c->flags & PERIPH_NO_RESET))
960 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
961 base + PERIPH_CLK_TO_ENB_SET_REG(c));
964 static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
967 const struct clk_mux_sel *sel;
968 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
969 for (sel = c->inputs; sel->input != NULL; sel++) {
970 if (sel->input == p) {
971 val = clk_readl(c->reg);
972 val &= ~PERIPH_CLK_SOURCE_MASK;
973 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
978 clk_writel(val, c->reg);
980 if (c->refcnt && c->parent)
981 clk_disable(c->parent);
991 static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
995 unsigned long parent_rate = clk_get_rate(c->parent);
997 if (c->flags & DIV_U71) {
998 divider = clk_div71_get_divider(parent_rate, rate);
1000 val = clk_readl(c->reg);
1001 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
1003 clk_writel(val, c->reg);
1004 c->div = divider + 2;
1008 } else if (c->flags & DIV_U16) {
1009 divider = clk_div16_get_divider(parent_rate, rate);
1011 val = clk_readl(c->reg);
1012 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
1014 clk_writel(val, c->reg);
1015 c->div = divider + 1;
1019 } else if (parent_rate <= rate) {
1027 static long tegra2_periph_clk_round_rate(struct clk *c,
1031 unsigned long parent_rate = clk_get_rate(c->parent);
1032 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
1034 if (c->flags & DIV_U71) {
1035 divider = clk_div71_get_divider(parent_rate, rate);
1039 return parent_rate * 2 / (divider + 2);
1040 } else if (c->flags & DIV_U16) {
1041 divider = clk_div16_get_divider(parent_rate, rate);
1044 return parent_rate / (divider + 1);
1049 static struct clk_ops tegra_periph_clk_ops = {
1050 .init = &tegra2_periph_clk_init,
1051 .enable = &tegra2_periph_clk_enable,
1052 .disable = &tegra2_periph_clk_disable,
1053 .set_parent = &tegra2_periph_clk_set_parent,
1054 .set_rate = &tegra2_periph_clk_set_rate,
1055 .round_rate = &tegra2_periph_clk_round_rate,
1056 .reset = &tegra2_periph_clk_reset,
1059 /* The SDMMC controllers have extra bits in the clock source register that
1060 * adjust the delay between the clock and data to compenstate for delays
1062 void tegra2_sdmmc_tap_delay(struct clk *c, int delay)
1066 delay = clamp(delay, 0, 15);
1067 reg = clk_readl(c->reg);
1068 reg &= ~SDMMC_CLK_INT_FB_DLY_MASK;
1069 reg |= SDMMC_CLK_INT_FB_SEL;
1070 reg |= delay << SDMMC_CLK_INT_FB_DLY_SHIFT;
1071 clk_writel(reg, c->reg);
1074 /* External memory controller clock ops */
1075 static void tegra2_emc_clk_init(struct clk *c)
1077 tegra2_periph_clk_init(c);
1078 c->max_rate = clk_get_rate_locked(c);
1081 static long tegra2_emc_clk_round_rate(struct clk *c, unsigned long rate)
1083 long new_rate = rate;
1085 new_rate = tegra_emc_round_rate(new_rate);
1089 BUG_ON(new_rate != tegra2_periph_clk_round_rate(c, new_rate));
1094 static int tegra2_emc_clk_set_rate(struct clk *c, unsigned long rate)
1098 * The Tegra2 memory controller has an interlock with the clock
1099 * block that allows memory shadowed registers to be updated,
1100 * and then transfer them to the main registers at the same
1101 * time as the clock update without glitches.
1103 ret = tegra_emc_set_rate(rate);
1107 ret = tegra2_periph_clk_set_rate(c, rate);
1113 static struct clk_ops tegra_emc_clk_ops = {
1114 .init = &tegra2_emc_clk_init,
1115 .enable = &tegra2_periph_clk_enable,
1116 .disable = &tegra2_periph_clk_disable,
1117 .set_parent = &tegra2_periph_clk_set_parent,
1118 .set_rate = &tegra2_emc_clk_set_rate,
1119 .round_rate = &tegra2_emc_clk_round_rate,
1120 .reset = &tegra2_periph_clk_reset,
1123 /* Clock doubler ops */
1124 static void tegra2_clk_double_init(struct clk *c)
1129 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1130 PERIPH_CLK_TO_ENB_BIT(c)))
1134 static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1136 if (rate != 2 * clk_get_rate(c->parent))
1143 static struct clk_ops tegra_clk_double_ops = {
1144 .init = &tegra2_clk_double_init,
1145 .enable = &tegra2_periph_clk_enable,
1146 .disable = &tegra2_periph_clk_disable,
1147 .set_rate = &tegra2_clk_double_set_rate,
1150 /* Audio sync clock ops */
1151 static void tegra2_audio_sync_clk_init(struct clk *c)
1154 const struct clk_mux_sel *sel;
1155 u32 val = clk_readl(c->reg);
1156 c->state = (val & (1<<4)) ? OFF : ON;
1158 for (sel = c->inputs; sel->input != NULL; sel++)
1159 if (sel->value == source)
1161 BUG_ON(sel->input == NULL);
1162 c->parent = sel->input;
1165 static int tegra2_audio_sync_clk_enable(struct clk *c)
1167 clk_writel(0, c->reg);
1171 static void tegra2_audio_sync_clk_disable(struct clk *c)
1173 clk_writel(1, c->reg);
1176 static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1179 const struct clk_mux_sel *sel;
1180 for (sel = c->inputs; sel->input != NULL; sel++) {
1181 if (sel->input == p) {
1182 val = clk_readl(c->reg);
1189 clk_writel(val, c->reg);
1191 if (c->refcnt && c->parent)
1192 clk_disable(c->parent);
1202 static int tegra2_audio_sync_clk_set_rate(struct clk *c, unsigned long rate)
1204 unsigned long parent_rate;
1206 pr_err("%s: clock has no parent\n", __func__);
1209 parent_rate = c->parent->rate;
1210 if (rate != parent_rate) {
1211 pr_err("%s: %s/%ld differs from parent %s/%ld\n",
1214 c->parent->name, parent_rate);
1217 c->rate = parent_rate;
1221 static struct clk_ops tegra_audio_sync_clk_ops = {
1222 .init = tegra2_audio_sync_clk_init,
1223 .enable = tegra2_audio_sync_clk_enable,
1224 .disable = tegra2_audio_sync_clk_disable,
1225 .set_rate = tegra2_audio_sync_clk_set_rate,
1226 .set_parent = tegra2_audio_sync_clk_set_parent,
1229 /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1231 static void tegra2_cdev_clk_init(struct clk *c)
1233 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1234 * currently done in the pinmux code. */
1236 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1237 PERIPH_CLK_TO_ENB_BIT(c)))
1241 static int tegra2_cdev_clk_enable(struct clk *c)
1243 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1244 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1248 static void tegra2_cdev_clk_disable(struct clk *c)
1250 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1251 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1254 static struct clk_ops tegra_cdev_clk_ops = {
1255 .init = &tegra2_cdev_clk_init,
1256 .enable = &tegra2_cdev_clk_enable,
1257 .disable = &tegra2_cdev_clk_disable,
1260 /* shared bus ops */
1262 * Some clocks may have multiple downstream users that need to request a
1263 * higher clock rate. Shared bus clocks provide a unique shared_bus_user
1264 * clock to each user. The frequency of the bus is set to the highest
1265 * enabled shared_bus_user clock, with a minimum value set by the
1268 static int tegra_clk_shared_bus_update(struct clk *bus)
1271 unsigned long rate = bus->min_rate;
1273 list_for_each_entry(c, &bus->shared_bus_list, u.shared_bus_user.node)
1274 if (c->u.shared_bus_user.enabled)
1275 rate = max(c->u.shared_bus_user.rate, rate);
1277 if (rate == clk_get_rate_locked(bus))
1280 return clk_set_rate_locked(bus, rate);
1283 static void tegra_clk_shared_bus_init(struct clk *c)
1285 unsigned long flags;
1287 c->max_rate = c->parent->max_rate;
1288 c->u.shared_bus_user.rate = c->parent->max_rate;
1292 spin_lock_irqsave(&c->parent->spinlock, flags);
1294 list_add_tail(&c->u.shared_bus_user.node,
1295 &c->parent->shared_bus_list);
1297 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1300 static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate)
1302 unsigned long flags;
1305 rate = clk_round_rate(c->parent, rate);
1309 spin_lock_irqsave(&c->parent->spinlock, flags);
1311 c->u.shared_bus_user.rate = rate;
1312 ret = tegra_clk_shared_bus_update(c->parent);
1314 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1319 static long tegra_clk_shared_bus_round_rate(struct clk *c, unsigned long rate)
1321 return clk_round_rate(c->parent, rate);
1324 static int tegra_clk_shared_bus_enable(struct clk *c)
1326 unsigned long flags;
1329 spin_lock_irqsave(&c->parent->spinlock, flags);
1331 c->u.shared_bus_user.enabled = true;
1332 ret = tegra_clk_shared_bus_update(c->parent);
1334 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1339 static void tegra_clk_shared_bus_disable(struct clk *c)
1341 unsigned long flags;
1344 spin_lock_irqsave(&c->parent->spinlock, flags);
1346 c->u.shared_bus_user.enabled = false;
1347 ret = tegra_clk_shared_bus_update(c->parent);
1350 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1353 static struct clk_ops tegra_clk_shared_bus_ops = {
1354 .init = tegra_clk_shared_bus_init,
1355 .enable = tegra_clk_shared_bus_enable,
1356 .disable = tegra_clk_shared_bus_disable,
1357 .set_rate = tegra_clk_shared_bus_set_rate,
1358 .round_rate = tegra_clk_shared_bus_round_rate,
1362 /* Clock definitions */
1363 static struct clk tegra_clk_32k = {
1370 static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
1371 {32768, 12000000, 366, 1, 1, 0},
1372 {32768, 13000000, 397, 1, 1, 0},
1373 {32768, 19200000, 586, 1, 1, 0},
1374 {32768, 26000000, 793, 1, 1, 0},
1378 static struct clk tegra_pll_s = {
1380 .flags = PLL_ALT_MISC_REG,
1381 .ops = &tegra_pll_ops,
1382 .parent = &tegra_clk_32k,
1383 .max_rate = 26000000,
1388 .cf_min = 0, /* FIXME */
1389 .cf_max = 0, /* FIXME */
1390 .vco_min = 12000000,
1391 .vco_max = 26000000,
1392 .freq_table = tegra_pll_s_freq_table,
1397 static struct clk_mux_sel tegra_clk_m_sel[] = {
1398 { .input = &tegra_clk_32k, .value = 0},
1399 { .input = &tegra_pll_s, .value = 1},
1403 static struct clk tegra_clk_m = {
1405 .flags = ENABLE_ON_INIT,
1406 .ops = &tegra_clk_m_ops,
1407 .inputs = tegra_clk_m_sel,
1410 .max_rate = 26000000,
1413 static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
1414 { 0, 0, 0, 0, 0, 0 },
1417 static struct clk tegra_pll_c = {
1419 .flags = PLL_HAS_CPCON,
1420 .ops = &tegra_pll_ops,
1422 .parent = &tegra_clk_m,
1423 .max_rate = 600000000,
1425 .input_min = 2000000,
1426 .input_max = 31000000,
1429 .vco_min = 20000000,
1430 .vco_max = 1400000000,
1431 .freq_table = tegra_pll_c_freq_table,
1436 static struct clk tegra_pll_c_out1 = {
1437 .name = "pll_c_out1",
1438 .ops = &tegra_pll_div_ops,
1440 .parent = &tegra_pll_c,
1443 .max_rate = 600000000,
1446 static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
1447 { 12000000, 666000000, 666, 12, 1, 8},
1448 { 13000000, 666000000, 666, 13, 1, 8},
1449 { 19200000, 666000000, 555, 16, 1, 8},
1450 { 26000000, 666000000, 666, 26, 1, 8},
1451 { 12000000, 600000000, 600, 12, 1, 8},
1452 { 13000000, 600000000, 600, 13, 1, 8},
1453 { 19200000, 600000000, 375, 12, 1, 6},
1454 { 26000000, 600000000, 600, 26, 1, 8},
1455 { 0, 0, 0, 0, 0, 0 },
1458 static struct clk tegra_pll_m = {
1460 .flags = PLL_HAS_CPCON,
1461 .ops = &tegra_pll_ops,
1463 .parent = &tegra_clk_m,
1464 .max_rate = 800000000,
1466 .input_min = 2000000,
1467 .input_max = 31000000,
1470 .vco_min = 20000000,
1471 .vco_max = 1200000000,
1472 .freq_table = tegra_pll_m_freq_table,
1477 static struct clk tegra_pll_m_out1 = {
1478 .name = "pll_m_out1",
1479 .ops = &tegra_pll_div_ops,
1481 .parent = &tegra_pll_m,
1484 .max_rate = 600000000,
1487 static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
1488 { 12000000, 216000000, 432, 12, 2, 8},
1489 { 13000000, 216000000, 432, 13, 2, 8},
1490 { 19200000, 216000000, 90, 4, 2, 1},
1491 { 26000000, 216000000, 432, 26, 2, 8},
1492 { 12000000, 432000000, 432, 12, 1, 8},
1493 { 13000000, 432000000, 432, 13, 1, 8},
1494 { 19200000, 432000000, 90, 4, 1, 1},
1495 { 26000000, 432000000, 432, 26, 1, 8},
1496 { 0, 0, 0, 0, 0, 0 },
1499 static struct clk tegra_pll_p = {
1501 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1502 .ops = &tegra_pll_ops,
1504 .parent = &tegra_clk_m,
1505 .max_rate = 432000000,
1507 .input_min = 2000000,
1508 .input_max = 31000000,
1511 .vco_min = 20000000,
1512 .vco_max = 1400000000,
1513 .freq_table = tegra_pll_p_freq_table,
1518 static struct clk tegra_pll_p_out1 = {
1519 .name = "pll_p_out1",
1520 .ops = &tegra_pll_div_ops,
1521 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1522 .parent = &tegra_pll_p,
1525 .max_rate = 432000000,
1528 static struct clk tegra_pll_p_out2 = {
1529 .name = "pll_p_out2",
1530 .ops = &tegra_pll_div_ops,
1531 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1532 .parent = &tegra_pll_p,
1535 .max_rate = 432000000,
1538 static struct clk tegra_pll_p_out3 = {
1539 .name = "pll_p_out3",
1540 .ops = &tegra_pll_div_ops,
1541 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1542 .parent = &tegra_pll_p,
1545 .max_rate = 432000000,
1548 static struct clk tegra_pll_p_out4 = {
1549 .name = "pll_p_out4",
1550 .ops = &tegra_pll_div_ops,
1551 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1552 .parent = &tegra_pll_p,
1555 .max_rate = 432000000,
1558 static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
1559 { 28800000, 56448000, 49, 25, 1, 1},
1560 { 28800000, 73728000, 64, 25, 1, 1},
1561 { 28800000, 11289600, 49, 25, 1, 1},
1562 { 28800000, 12288000, 64, 25, 1, 1},
1563 { 28800000, 24000000, 5, 6, 1, 1},
1564 { 0, 0, 0, 0, 0, 0 },
1567 static struct clk tegra_pll_a = {
1569 .flags = PLL_HAS_CPCON,
1570 .ops = &tegra_pll_ops,
1572 .parent = &tegra_pll_p_out1,
1573 .max_rate = 56448000,
1575 .input_min = 2000000,
1576 .input_max = 31000000,
1579 .vco_min = 20000000,
1580 .vco_max = 1400000000,
1581 .freq_table = tegra_pll_a_freq_table,
1586 static struct clk tegra_pll_a_out0 = {
1587 .name = "pll_a_out0",
1588 .ops = &tegra_pll_div_ops,
1590 .parent = &tegra_pll_a,
1593 .max_rate = 56448000,
1596 static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
1597 { 12000000, 216000000, 216, 12, 1, 4},
1598 { 13000000, 216000000, 216, 13, 1, 4},
1599 { 19200000, 216000000, 135, 12, 1, 3},
1600 { 26000000, 216000000, 216, 26, 1, 4},
1602 { 12000000, 594000000, 594, 12, 1, 8},
1603 { 13000000, 594000000, 594, 13, 1, 8},
1604 { 19200000, 594000000, 495, 16, 1, 8},
1605 { 26000000, 594000000, 594, 26, 1, 8},
1607 { 12000000, 1000000000, 1000, 12, 1, 12},
1608 { 13000000, 1000000000, 1000, 13, 1, 12},
1609 { 19200000, 1000000000, 625, 12, 1, 8},
1610 { 26000000, 1000000000, 1000, 26, 1, 12},
1612 { 0, 0, 0, 0, 0, 0 },
1615 static struct clk tegra_pll_d = {
1617 .flags = PLL_HAS_CPCON | PLLD,
1618 .ops = &tegra_pll_ops,
1620 .parent = &tegra_clk_m,
1621 .max_rate = 1000000000,
1623 .input_min = 2000000,
1624 .input_max = 40000000,
1627 .vco_min = 40000000,
1628 .vco_max = 1000000000,
1629 .freq_table = tegra_pll_d_freq_table,
1634 static struct clk tegra_pll_d_out0 = {
1635 .name = "pll_d_out0",
1636 .ops = &tegra_pll_div_ops,
1637 .flags = DIV_2 | PLLD,
1638 .parent = &tegra_pll_d,
1639 .max_rate = 500000000,
1642 static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
1643 { 12000000, 480000000, 960, 12, 2, 0},
1644 { 13000000, 480000000, 960, 13, 2, 0},
1645 { 19200000, 480000000, 200, 4, 2, 0},
1646 { 26000000, 480000000, 960, 26, 2, 0},
1647 { 0, 0, 0, 0, 0, 0 },
1650 static struct clk tegra_pll_u = {
1653 .ops = &tegra_pll_ops,
1655 .parent = &tegra_clk_m,
1656 .max_rate = 480000000,
1658 .input_min = 2000000,
1659 .input_max = 40000000,
1662 .vco_min = 480000000,
1663 .vco_max = 960000000,
1664 .freq_table = tegra_pll_u_freq_table,
1669 static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
1671 { 12000000, 1000000000, 1000, 12, 1, 12},
1672 { 13000000, 1000000000, 1000, 13, 1, 12},
1673 { 19200000, 1000000000, 625, 12, 1, 8},
1674 { 26000000, 1000000000, 1000, 26, 1, 12},
1677 { 12000000, 912000000, 912, 12, 1, 12},
1678 { 13000000, 912000000, 912, 13, 1, 12},
1679 { 19200000, 912000000, 760, 16, 1, 8},
1680 { 26000000, 912000000, 912, 26, 1, 12},
1683 { 12000000, 816000000, 816, 12, 1, 12},
1684 { 13000000, 816000000, 816, 13, 1, 12},
1685 { 19200000, 816000000, 680, 16, 1, 8},
1686 { 26000000, 816000000, 816, 26, 1, 12},
1689 { 12000000, 760000000, 760, 12, 1, 12},
1690 { 13000000, 760000000, 760, 13, 1, 12},
1691 { 19200000, 760000000, 950, 24, 1, 8},
1692 { 26000000, 760000000, 760, 26, 1, 12},
1695 { 12000000, 608000000, 760, 12, 1, 12},
1696 { 13000000, 608000000, 760, 13, 1, 12},
1697 { 19200000, 608000000, 380, 12, 1, 8},
1698 { 26000000, 608000000, 760, 26, 1, 12},
1701 { 12000000, 456000000, 456, 12, 1, 12},
1702 { 13000000, 456000000, 456, 13, 1, 12},
1703 { 19200000, 456000000, 380, 16, 1, 8},
1704 { 26000000, 456000000, 456, 26, 1, 12},
1707 { 12000000, 312000000, 312, 12, 1, 12},
1708 { 13000000, 312000000, 312, 13, 1, 12},
1709 { 19200000, 312000000, 260, 16, 1, 8},
1710 { 26000000, 312000000, 312, 26, 1, 12},
1712 { 0, 0, 0, 0, 0, 0 },
1715 static struct clk tegra_pll_x = {
1717 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1718 .ops = &tegra_pllx_ops,
1720 .parent = &tegra_clk_m,
1721 .max_rate = 1000000000,
1723 .input_min = 2000000,
1724 .input_max = 31000000,
1727 .vco_min = 20000000,
1728 .vco_max = 1200000000,
1729 .freq_table = tegra_pll_x_freq_table,
1734 static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
1735 { 12000000, 100000000, 200, 24, 1, 0 },
1736 { 0, 0, 0, 0, 0, 0 },
1739 static struct clk tegra_pll_e = {
1741 .flags = PLL_ALT_MISC_REG,
1742 .ops = &tegra_plle_ops,
1743 .parent = &tegra_clk_m,
1745 .max_rate = 100000000,
1747 .input_min = 12000000,
1748 .input_max = 12000000,
1749 .freq_table = tegra_pll_e_freq_table,
1753 static struct clk tegra_clk_d = {
1755 .flags = PERIPH_NO_RESET,
1756 .ops = &tegra_clk_double_ops,
1759 .parent = &tegra_clk_m,
1760 .max_rate = 52000000,
1766 /* dap_mclk1, belongs to the cdev1 pingroup. */
1767 static struct clk tegra_dev1_clk = {
1769 .ops = &tegra_cdev_clk_ops,
1771 .max_rate = 26000000,
1777 /* dap_mclk2, belongs to the cdev2 pingroup. */
1778 static struct clk tegra_dev2_clk = {
1780 .ops = &tegra_cdev_clk_ops,
1782 .max_rate = 26000000,
1788 /* initialized before peripheral clocks */
1789 static struct clk_mux_sel mux_audio_sync_clk[8+1];
1790 static const struct audio_sources {
1793 } mux_audio_sync_clk_sources[] = {
1794 { .name = "spdif_in", .value = 0 },
1795 { .name = "i2s1", .value = 1 },
1796 { .name = "i2s2", .value = 2 },
1797 { .name = "pll_a_out0", .value = 4 },
1798 #if 0 /* FIXME: not implemented */
1799 { .name = "ac97", .value = 3 },
1800 { .name = "ext_audio_clk2", .value = 5 },
1801 { .name = "ext_audio_clk1", .value = 6 },
1802 { .name = "ext_vimclk", .value = 7 },
1807 static struct clk tegra_clk_audio = {
1809 .inputs = mux_audio_sync_clk,
1811 .max_rate = 24000000,
1812 .ops = &tegra_audio_sync_clk_ops
1815 static struct clk tegra_clk_audio_2x = {
1817 .flags = PERIPH_NO_RESET,
1818 .max_rate = 48000000,
1819 .ops = &tegra_clk_double_ops,
1822 .parent = &tegra_clk_audio,
1828 struct clk_lookup tegra_audio_clk_lookups[] = {
1829 { .con_id = "audio", .clk = &tegra_clk_audio },
1830 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1833 /* This is called after peripheral clocks are initialized, as the
1834 * audio_sync clock depends on some of the peripheral clocks.
1837 static void init_audio_sync_clock_mux(void)
1840 struct clk_mux_sel *sel = mux_audio_sync_clk;
1841 const struct audio_sources *src = mux_audio_sync_clk_sources;
1842 struct clk_lookup *lookup;
1844 for (i = 0; src->name; i++, sel++, src++) {
1845 sel->input = tegra_get_clock_by_name(src->name);
1847 pr_err("%s: could not find clk %s\n", __func__,
1849 sel->value = src->value;
1852 lookup = tegra_audio_clk_lookups;
1853 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1854 clk_init(lookup->clk);
1859 static struct clk_mux_sel mux_cclk[] = {
1860 { .input = &tegra_clk_m, .value = 0},
1861 { .input = &tegra_pll_c, .value = 1},
1862 { .input = &tegra_clk_32k, .value = 2},
1863 { .input = &tegra_pll_m, .value = 3},
1864 { .input = &tegra_pll_p, .value = 4},
1865 { .input = &tegra_pll_p_out4, .value = 5},
1866 { .input = &tegra_pll_p_out3, .value = 6},
1867 { .input = &tegra_clk_d, .value = 7},
1868 { .input = &tegra_pll_x, .value = 8},
1872 static struct clk_mux_sel mux_sclk[] = {
1873 { .input = &tegra_clk_m, .value = 0},
1874 { .input = &tegra_pll_c_out1, .value = 1},
1875 { .input = &tegra_pll_p_out4, .value = 2},
1876 { .input = &tegra_pll_p_out3, .value = 3},
1877 { .input = &tegra_pll_p_out2, .value = 4},
1878 { .input = &tegra_clk_d, .value = 5},
1879 { .input = &tegra_clk_32k, .value = 6},
1880 { .input = &tegra_pll_m_out1, .value = 7},
1884 static struct clk tegra_clk_cclk = {
1888 .ops = &tegra_super_ops,
1889 .max_rate = 1000000000,
1892 static struct clk tegra_clk_sclk = {
1896 .ops = &tegra_super_ops,
1897 .max_rate = 600000000,
1900 static struct clk tegra_clk_virtual_cpu = {
1902 .parent = &tegra_clk_cclk,
1903 .ops = &tegra_cpu_ops,
1904 .max_rate = 1000000000,
1906 .main = &tegra_pll_x,
1907 .backup = &tegra_pll_p,
1911 static struct clk tegra_clk_hclk = {
1914 .parent = &tegra_clk_sclk,
1917 .ops = &tegra_bus_ops,
1918 .max_rate = 240000000,
1921 static struct clk tegra_clk_pclk = {
1924 .parent = &tegra_clk_hclk,
1927 .ops = &tegra_bus_ops,
1928 .max_rate = 108000000,
1931 static struct clk tegra_clk_blink = {
1933 .parent = &tegra_clk_32k,
1935 .ops = &tegra_blink_clk_ops,
1939 static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1940 { .input = &tegra_pll_m, .value = 0},
1941 { .input = &tegra_pll_c, .value = 1},
1942 { .input = &tegra_pll_p, .value = 2},
1943 { .input = &tegra_pll_a_out0, .value = 3},
1947 static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1948 { .input = &tegra_pll_m, .value = 0},
1949 { .input = &tegra_pll_c, .value = 1},
1950 { .input = &tegra_pll_p, .value = 2},
1951 { .input = &tegra_clk_m, .value = 3},
1955 static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1956 { .input = &tegra_pll_p, .value = 0},
1957 { .input = &tegra_pll_c, .value = 1},
1958 { .input = &tegra_pll_m, .value = 2},
1959 { .input = &tegra_clk_m, .value = 3},
1963 static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1964 {.input = &tegra_pll_a_out0, .value = 0},
1965 {.input = &tegra_clk_audio_2x, .value = 1},
1966 {.input = &tegra_pll_p, .value = 2},
1967 {.input = &tegra_clk_m, .value = 3},
1971 static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1972 {.input = &tegra_pll_p, .value = 0},
1973 {.input = &tegra_pll_d_out0, .value = 1},
1974 {.input = &tegra_pll_c, .value = 2},
1975 {.input = &tegra_clk_m, .value = 3},
1979 static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1980 {.input = &tegra_pll_p, .value = 0},
1981 {.input = &tegra_pll_c, .value = 1},
1982 {.input = &tegra_clk_audio, .value = 2},
1983 {.input = &tegra_clk_m, .value = 3},
1984 {.input = &tegra_clk_32k, .value = 4},
1988 static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1989 {.input = &tegra_pll_p, .value = 0},
1990 {.input = &tegra_pll_c, .value = 1},
1991 {.input = &tegra_pll_m, .value = 2},
1995 static struct clk_mux_sel mux_clk_m[] = {
1996 { .input = &tegra_clk_m, .value = 0},
2000 static struct clk_mux_sel mux_pllp_out3[] = {
2001 { .input = &tegra_pll_p_out3, .value = 0},
2005 static struct clk_mux_sel mux_plld[] = {
2006 { .input = &tegra_pll_d, .value = 0},
2010 static struct clk_mux_sel mux_clk_32k[] = {
2011 { .input = &tegra_clk_32k, .value = 0},
2015 static struct clk_mux_sel mux_pclk[] = {
2016 { .input = &tegra_clk_pclk, .value = 0},
2020 static struct clk tegra_clk_emc = {
2022 .ops = &tegra_emc_clk_ops,
2024 .max_rate = 800000000,
2025 .inputs = mux_pllm_pllc_pllp_clkm,
2026 .flags = MUX | DIV_U71 | PERIPH_EMC_ENB,
2032 #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
2039 .ops = &tegra_periph_clk_ops, \
2041 .inputs = _inputs, \
2045 .clk_num = _clk_num, \
2049 #define SHARED_CLK(_name, _dev, _con, _parent) \
2056 .ops = &tegra_clk_shared_bus_ops, \
2057 .parent = _parent, \
2060 struct clk tegra_list_clks[] = {
2061 PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0),
2062 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
2063 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
2064 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2065 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2066 /* FIXME: spdif has 2 clocks but 1 enable */
2067 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2068 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
2069 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
2070 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2071 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2072 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2073 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2074 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2075 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2076 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2077 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
2078 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2079 /* FIXME: vfir shares an enable with uartb */
2080 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2081 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2082 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2083 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2084 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2085 PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2086 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
2087 /* FIXME: what is la? */
2088 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2089 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2090 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
2091 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2092 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2093 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2094 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2095 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2096 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2097 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2098 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2099 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2100 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2101 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2102 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2103 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2104 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2105 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 */
2106 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2107 /* FIXME: vi and vi_sensor share an enable */
2108 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2109 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 */
2110 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2111 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2112 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2113 /* FIXME: cve and tvo share an enable */
2114 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2115 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2116 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2117 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2118 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2119 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2120 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2121 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2122 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2123 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
2124 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
2125 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
2126 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
2127 PERIPH_CLK("pex", NULL, "pex", 70, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
2128 PERIPH_CLK("afi", NULL, "afi", 72, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
2129 PERIPH_CLK("pcie_xclk", NULL, "pcie_xclk", 74, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
2132 #define CLK_DUPLICATE(_name, _dev, _con) \
2141 /* Some clocks may be used by different drivers depending on the board
2142 * configuration. List those here to register them twice in the clock lookup
2143 * table under two names.
2145 struct clk_duplicate tegra_clk_duplicates[] = {
2146 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
2147 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
2148 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
2149 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
2150 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
2151 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
2152 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
2153 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
2154 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
2155 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
2156 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
2157 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
2158 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
2159 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
2162 #define CLK(dev, con, ck) \
2169 struct clk *tegra_ptr_clks[] = {
2196 &tegra_clk_virtual_cpu,
2201 static void tegra2_init_one_clock(struct clk *c)
2204 INIT_LIST_HEAD(&c->shared_bus_list);
2205 if (!c->lookup.dev_id && !c->lookup.con_id)
2206 c->lookup.con_id = c->name;
2208 clkdev_add(&c->lookup);
2211 void __init tegra2_init_clocks(void)
2216 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
2217 tegra2_init_one_clock(tegra_ptr_clks[i]);
2219 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
2220 tegra2_init_one_clock(&tegra_list_clks[i]);
2222 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
2223 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
2225 pr_err("%s: Unknown duplicate clock %s\n", __func__,
2226 tegra_clk_duplicates[i].name);
2230 tegra_clk_duplicates[i].lookup.clk = c;
2231 clkdev_add(&tegra_clk_duplicates[i].lookup);
2234 init_audio_sync_clock_mux();
2238 static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
2239 PERIPH_CLK_SOURCE_NUM + 19];
2241 void tegra_clk_suspend(void)
2243 unsigned long off, i;
2244 u32 *ctx = clk_rst_suspend;
2246 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
2247 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_BASE);
2248 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
2249 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
2250 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2251 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
2252 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2254 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
2255 *ctx++ = clk_readl(tegra_pll_p_out1.reg);
2256 *ctx++ = clk_readl(tegra_pll_p_out3.reg);
2257 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
2258 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
2260 *ctx++ = clk_readl(tegra_clk_cclk.reg);
2261 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2263 *ctx++ = clk_readl(tegra_clk_sclk.reg);
2264 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2265 *ctx++ = clk_readl(tegra_clk_pclk.reg);
2267 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2269 if (off == PERIPH_CLK_SOURCE_EMC)
2271 *ctx++ = clk_readl(off);
2275 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2276 *ctx++ = clk_readl(off);
2279 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2280 *ctx++ = clk_readl(off);
2282 *ctx++ = clk_readl(MISC_CLK_ENB);
2283 *ctx++ = clk_readl(CLK_MASK_ARM);
2286 void tegra_clk_resume(void)
2288 unsigned long off, i;
2289 const u32 *ctx = clk_rst_suspend;
2292 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2294 clk_writel(val, OSC_CTRL);
2296 clk_writel(*ctx++, tegra_pll_p.reg + PLL_BASE);
2297 clk_writel(*ctx++, tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
2298 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2299 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2300 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2301 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2304 clk_writel(*ctx++, tegra_pll_m_out1.reg);
2305 clk_writel(*ctx++, tegra_pll_p_out1.reg);
2306 clk_writel(*ctx++, tegra_pll_p_out3.reg);
2307 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2308 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2310 clk_writel(*ctx++, tegra_clk_cclk.reg);
2311 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2313 clk_writel(*ctx++, tegra_clk_sclk.reg);
2314 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2315 clk_writel(*ctx++, tegra_clk_pclk.reg);
2317 /* enable all clocks before configuring clock sources */
2318 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2319 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2320 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2323 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2325 if (off == PERIPH_CLK_SOURCE_EMC)
2327 clk_writel(*ctx++, off);
2332 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2333 clk_writel(*ctx++, off);
2337 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2338 clk_writel(*ctx++, off);
2341 clk_writel(*ctx++, MISC_CLK_ENB);
2342 clk_writel(*ctx++, CLK_MASK_ARM);