2 * arch/arm/mach-tegra/tegra2_clocks.c
4 * Copyright (C) 2010 Google, Inc.
7 * Colin Cross <ccross@google.com>
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/list.h>
23 #include <linux/spinlock.h>
24 #include <linux/delay.h>
26 #include <linux/clk.h>
28 #include <asm/clkdev.h>
30 #include <mach/iomap.h>
31 #include <mach/suspend.h>
35 #include "tegra2_emc.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
78 #define SDMMC_CLK_INT_FB_SEL (1 << 23)
79 #define SDMMC_CLK_INT_FB_DLY_SHIFT 16
80 #define SDMMC_CLK_INT_FB_DLY_MASK (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT)
83 #define PLL_BASE_BYPASS (1<<31)
84 #define PLL_BASE_ENABLE (1<<30)
85 #define PLL_BASE_REF_ENABLE (1<<29)
86 #define PLL_BASE_OVERRIDE (1<<28)
87 #define PLL_BASE_DIVP_MASK (0x7<<20)
88 #define PLL_BASE_DIVP_SHIFT 20
89 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
90 #define PLL_BASE_DIVN_SHIFT 8
91 #define PLL_BASE_DIVM_MASK (0x1F)
92 #define PLL_BASE_DIVM_SHIFT 0
94 #define PLL_OUT_RATIO_MASK (0xFF<<8)
95 #define PLL_OUT_RATIO_SHIFT 8
96 #define PLL_OUT_OVERRIDE (1<<2)
97 #define PLL_OUT_CLKEN (1<<1)
98 #define PLL_OUT_RESET_DISABLE (1<<0)
100 #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
102 #define PLL_MISC_DCCON_SHIFT 20
103 #define PLL_MISC_CPCON_SHIFT 8
104 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
105 #define PLL_MISC_LFCON_SHIFT 4
106 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
107 #define PLL_MISC_VCOCON_SHIFT 0
108 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
110 #define PLLU_BASE_POST_DIV (1<<20)
112 #define PLLD_MISC_CLKENABLE (1<<30)
113 #define PLLD_MISC_DIV_RST (1<<23)
114 #define PLLD_MISC_DCCON_SHIFT 12
116 #define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
117 #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
118 #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
120 #define SUPER_CLK_MUX 0x00
121 #define SUPER_STATE_SHIFT 28
122 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
123 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
124 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
125 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
126 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
127 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
128 #define SUPER_SOURCE_MASK 0xF
129 #define SUPER_FIQ_SOURCE_SHIFT 12
130 #define SUPER_IRQ_SOURCE_SHIFT 8
131 #define SUPER_RUN_SOURCE_SHIFT 4
132 #define SUPER_IDLE_SOURCE_SHIFT 0
134 #define SUPER_CLK_DIVIDER 0x04
136 #define BUS_CLK_DISABLE (1<<3)
137 #define BUS_CLK_DIV_MASK 0x3
140 #define PMC_CTRL_BLINK_ENB (1 << 7)
142 #define PMC_DPD_PADS_ORIDE 0x1c
143 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
145 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
146 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
147 #define PMC_BLINK_TIMER_ENB (1 << 15)
148 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
149 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
151 static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
152 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
155 * Some peripheral clocks share an enable bit, so refcount the enable bits
156 * in registers CLK_ENABLE_L, CLK_ENABLE_H, and CLK_ENABLE_U
158 static int tegra_periph_clk_enable_refcount[3 * 32];
160 #define clk_writel(value, reg) \
161 __raw_writel(value, (u32)reg_clk_base + (reg))
162 #define clk_readl(reg) \
163 __raw_readl((u32)reg_clk_base + (reg))
164 #define pmc_writel(value, reg) \
165 __raw_writel(value, (u32)reg_pmc_base + (reg))
166 #define pmc_readl(reg) \
167 __raw_readl((u32)reg_pmc_base + (reg))
169 unsigned long clk_measure_input_freq(void)
171 u32 clock_autodetect;
172 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
173 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
174 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
175 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
177 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
179 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
181 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
184 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
190 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
192 s64 divider_u71 = parent_rate * 2;
193 divider_u71 += rate - 1;
194 do_div(divider_u71, rate);
196 if (divider_u71 - 2 < 0)
199 if (divider_u71 - 2 > 255)
202 return divider_u71 - 2;
205 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
209 divider_u16 = parent_rate;
210 divider_u16 += rate - 1;
211 do_div(divider_u16, rate);
213 if (divider_u16 - 1 < 0)
216 if (divider_u16 - 1 > 255)
219 return divider_u16 - 1;
222 /* clk_m functions */
223 static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
225 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
227 c->rate = clk_measure_input_freq();
230 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
233 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
236 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
239 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
242 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
245 clk_writel(auto_clock_control, OSC_CTRL);
249 static void tegra2_clk_m_init(struct clk *c)
251 pr_debug("%s on clock %s\n", __func__, c->name);
252 tegra2_clk_m_autodetect_rate(c);
255 static int tegra2_clk_m_enable(struct clk *c)
257 pr_debug("%s on clock %s\n", __func__, c->name);
261 static void tegra2_clk_m_disable(struct clk *c)
263 pr_debug("%s on clock %s\n", __func__, c->name);
267 static struct clk_ops tegra_clk_m_ops = {
268 .init = tegra2_clk_m_init,
269 .enable = tegra2_clk_m_enable,
270 .disable = tegra2_clk_m_disable,
273 void tegra2_periph_reset_assert(struct clk *c)
275 BUG_ON(!c->ops->reset);
276 c->ops->reset(c, true);
279 void tegra2_periph_reset_deassert(struct clk *c)
281 BUG_ON(!c->ops->reset);
282 c->ops->reset(c, false);
285 /* super clock functions */
286 /* "super clocks" on tegra have two-stage muxes and a clock skipping
287 * super divider. We will ignore the clock skipping divider, since we
288 * can't lower the voltage when using the clock skip, but we can if we
289 * lower the PLL frequency.
291 static void tegra2_super_clk_init(struct clk *c)
296 const struct clk_mux_sel *sel;
297 val = clk_readl(c->reg + SUPER_CLK_MUX);
299 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
300 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
301 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
302 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
303 source = (val >> shift) & SUPER_SOURCE_MASK;
304 for (sel = c->inputs; sel->input != NULL; sel++) {
305 if (sel->value == source)
308 BUG_ON(sel->input == NULL);
309 c->parent = sel->input;
312 static int tegra2_super_clk_enable(struct clk *c)
314 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
318 static void tegra2_super_clk_disable(struct clk *c)
320 pr_debug("%s on clock %s\n", __func__, c->name);
322 /* oops - don't disable the CPU clock! */
326 static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
329 const struct clk_mux_sel *sel;
332 val = clk_readl(c->reg + SUPER_CLK_MUX);;
333 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
334 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
335 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
336 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
337 for (sel = c->inputs; sel->input != NULL; sel++) {
338 if (sel->input == p) {
339 val &= ~(SUPER_SOURCE_MASK << shift);
340 val |= sel->value << shift;
345 clk_writel(val, c->reg);
347 if (c->refcnt && c->parent)
348 clk_disable(c->parent);
358 * Super clocks have "clock skippers" instead of dividers. Dividing using
359 * a clock skipper does not allow the voltage to be scaled down, so instead
360 * adjust the rate of the parent clock. This requires that the parent of a
361 * super clock have no other children, otherwise the rate will change
362 * underneath the other children.
364 static int tegra2_super_clk_set_rate(struct clk *c, unsigned long rate)
366 return clk_set_rate(c->parent, rate);
369 static struct clk_ops tegra_super_ops = {
370 .init = tegra2_super_clk_init,
371 .enable = tegra2_super_clk_enable,
372 .disable = tegra2_super_clk_disable,
373 .set_parent = tegra2_super_clk_set_parent,
374 .set_rate = tegra2_super_clk_set_rate,
377 /* virtual cpu clock functions */
378 /* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
379 To change the frequency of these clocks, the parent pll may need to be
380 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
381 and then the clock moved back to the pll. To hide this sequence, a virtual
384 static void tegra2_cpu_clk_init(struct clk *c)
388 static int tegra2_cpu_clk_enable(struct clk *c)
393 static void tegra2_cpu_clk_disable(struct clk *c)
395 pr_debug("%s on clock %s\n", __func__, c->name);
397 /* oops - don't disable the CPU clock! */
401 static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
405 * Take an extra reference to the main pll so it doesn't turn
406 * off when we move the cpu off of it
408 clk_enable(c->u.cpu.main);
410 ret = clk_set_parent(c->parent, c->u.cpu.backup);
412 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
416 if (rate == clk_get_rate(c->u.cpu.backup))
419 ret = clk_set_rate(c->u.cpu.main, rate);
421 pr_err("Failed to change cpu pll to %lu\n", rate);
425 ret = clk_set_parent(c->parent, c->u.cpu.main);
427 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
432 clk_disable(c->u.cpu.main);
436 static struct clk_ops tegra_cpu_ops = {
437 .init = tegra2_cpu_clk_init,
438 .enable = tegra2_cpu_clk_enable,
439 .disable = tegra2_cpu_clk_disable,
440 .set_rate = tegra2_cpu_clk_set_rate,
443 /* virtual cop clock functions. Used to acquire the fake 'cop' clock to
444 * reset the COP block (i.e. AVP) */
445 static void tegra2_cop_clk_reset(struct clk *c, bool assert)
447 unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
449 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
450 clk_writel(1 << 1, reg);
453 static struct clk_ops tegra_cop_ops = {
454 .reset = tegra2_cop_clk_reset,
457 /* bus clock functions */
458 static void tegra2_bus_clk_init(struct clk *c)
460 u32 val = clk_readl(c->reg);
461 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
462 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
466 static int tegra2_bus_clk_enable(struct clk *c)
468 u32 val = clk_readl(c->reg);
469 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
470 clk_writel(val, c->reg);
474 static void tegra2_bus_clk_disable(struct clk *c)
476 u32 val = clk_readl(c->reg);
477 val |= BUS_CLK_DISABLE << c->reg_shift;
478 clk_writel(val, c->reg);
481 static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
483 u32 val = clk_readl(c->reg);
484 unsigned long parent_rate = clk_get_rate(c->parent);
486 for (i = 1; i <= 4; i++) {
487 if (rate == parent_rate / i) {
488 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
489 val |= (i - 1) << c->reg_shift;
490 clk_writel(val, c->reg);
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 /* Clock divider ops */
714 static void tegra2_pll_div_clk_init(struct clk *c)
716 u32 val = clk_readl(c->reg);
718 val >>= c->reg_shift;
719 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
720 if (!(val & PLL_OUT_RESET_DISABLE))
723 if (c->flags & DIV_U71) {
724 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
725 c->div = (divu71 + 2);
727 } else if (c->flags & DIV_2) {
736 static int tegra2_pll_div_clk_enable(struct clk *c)
741 pr_debug("%s: %s\n", __func__, c->name);
742 if (c->flags & DIV_U71) {
743 val = clk_readl(c->reg);
744 new_val = val >> c->reg_shift;
747 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
749 val &= ~(0xFFFF << c->reg_shift);
750 val |= new_val << c->reg_shift;
751 clk_writel(val, c->reg);
753 } else if (c->flags & DIV_2) {
754 BUG_ON(!(c->flags & PLLD));
755 val = clk_readl(c->reg);
756 val &= ~PLLD_MISC_DIV_RST;
757 clk_writel(val, c->reg);
763 static void tegra2_pll_div_clk_disable(struct clk *c)
768 pr_debug("%s: %s\n", __func__, c->name);
769 if (c->flags & DIV_U71) {
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 } else if (c->flags & DIV_2) {
780 BUG_ON(!(c->flags & PLLD));
781 val = clk_readl(c->reg);
782 val |= PLLD_MISC_DIV_RST;
783 clk_writel(val, c->reg);
787 static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
792 unsigned long parent_rate = clk_get_rate(c->parent);
794 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
795 if (c->flags & DIV_U71) {
796 divider_u71 = clk_div71_get_divider(parent_rate, rate);
797 if (divider_u71 >= 0) {
798 val = clk_readl(c->reg);
799 new_val = val >> c->reg_shift;
801 if (c->flags & DIV_U71_FIXED)
802 new_val |= PLL_OUT_OVERRIDE;
803 new_val &= ~PLL_OUT_RATIO_MASK;
804 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
806 val &= ~(0xFFFF << c->reg_shift);
807 val |= new_val << c->reg_shift;
808 clk_writel(val, c->reg);
809 c->div = divider_u71 + 2;
813 } else if (c->flags & DIV_2) {
814 if (parent_rate == rate * 2)
820 static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
823 unsigned long parent_rate = clk_get_rate(c->parent);
824 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
826 if (c->flags & DIV_U71) {
827 divider = clk_div71_get_divider(parent_rate, rate);
830 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
831 } else if (c->flags & DIV_2) {
832 return DIV_ROUND_UP(parent_rate, 2);
837 static struct clk_ops tegra_pll_div_ops = {
838 .init = tegra2_pll_div_clk_init,
839 .enable = tegra2_pll_div_clk_enable,
840 .disable = tegra2_pll_div_clk_disable,
841 .set_rate = tegra2_pll_div_clk_set_rate,
842 .round_rate = tegra2_pll_div_clk_round_rate,
847 static void tegra2_periph_clk_init(struct clk *c)
849 u32 val = clk_readl(c->reg);
850 const struct clk_mux_sel *mux = 0;
851 const struct clk_mux_sel *sel;
852 if (c->flags & MUX) {
853 for (sel = c->inputs; sel->input != NULL; sel++) {
854 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
859 c->parent = mux->input;
861 c->parent = c->inputs[0].input;
864 if (c->flags & DIV_U71) {
865 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
868 } else if (c->flags & DIV_U16) {
869 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
878 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
879 PERIPH_CLK_TO_ENB_BIT(c)))
881 if (!(c->flags & PERIPH_NO_RESET))
882 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
883 PERIPH_CLK_TO_ENB_BIT(c))
887 static int tegra2_periph_clk_enable(struct clk *c)
890 pr_debug("%s on clock %s\n", __func__, c->name);
892 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
893 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1)
896 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
897 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
898 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
899 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
900 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
901 if (c->flags & PERIPH_EMC_ENB) {
902 /* The EMC peripheral clock has 2 extra enable bits */
903 /* FIXME: Do they need to be disabled? */
904 val = clk_readl(c->reg);
906 clk_writel(val, c->reg);
911 static void tegra2_periph_clk_disable(struct clk *c)
913 pr_debug("%s on clock %s\n", __func__, c->name);
916 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
918 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] == 0)
919 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
920 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
923 static void tegra2_periph_clk_reset(struct clk *c, bool assert)
925 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
927 pr_debug("%s %s on clock %s\n", __func__,
928 assert ? "assert" : "deassert", c->name);
929 if (!(c->flags & PERIPH_NO_RESET))
930 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
931 base + PERIPH_CLK_TO_ENB_SET_REG(c));
934 static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
937 const struct clk_mux_sel *sel;
938 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
939 for (sel = c->inputs; sel->input != NULL; sel++) {
940 if (sel->input == p) {
941 val = clk_readl(c->reg);
942 val &= ~PERIPH_CLK_SOURCE_MASK;
943 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
948 clk_writel(val, c->reg);
950 if (c->refcnt && c->parent)
951 clk_disable(c->parent);
961 static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
965 unsigned long parent_rate = clk_get_rate(c->parent);
967 if (c->flags & DIV_U71) {
968 divider = clk_div71_get_divider(parent_rate, rate);
970 val = clk_readl(c->reg);
971 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
973 clk_writel(val, c->reg);
974 c->div = divider + 2;
978 } else if (c->flags & DIV_U16) {
979 divider = clk_div16_get_divider(parent_rate, rate);
981 val = clk_readl(c->reg);
982 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
984 clk_writel(val, c->reg);
985 c->div = divider + 1;
989 } else if (parent_rate <= rate) {
997 static long tegra2_periph_clk_round_rate(struct clk *c,
1001 unsigned long parent_rate = clk_get_rate(c->parent);
1002 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
1004 if (c->flags & DIV_U71) {
1005 divider = clk_div71_get_divider(parent_rate, rate);
1009 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
1010 } else if (c->flags & DIV_U16) {
1011 divider = clk_div16_get_divider(parent_rate, rate);
1014 return DIV_ROUND_UP(parent_rate, divider + 1);
1019 static struct clk_ops tegra_periph_clk_ops = {
1020 .init = &tegra2_periph_clk_init,
1021 .enable = &tegra2_periph_clk_enable,
1022 .disable = &tegra2_periph_clk_disable,
1023 .set_parent = &tegra2_periph_clk_set_parent,
1024 .set_rate = &tegra2_periph_clk_set_rate,
1025 .round_rate = &tegra2_periph_clk_round_rate,
1026 .reset = &tegra2_periph_clk_reset,
1029 /* The SDMMC controllers have extra bits in the clock source register that
1030 * adjust the delay between the clock and data to compenstate for delays
1032 void tegra2_sdmmc_tap_delay(struct clk *c, int delay) {
1035 delay = clamp(delay, 0, 15);
1036 reg = clk_readl(c->reg);
1037 reg &= ~SDMMC_CLK_INT_FB_DLY_MASK;
1038 reg |= SDMMC_CLK_INT_FB_SEL;
1039 reg |= delay << SDMMC_CLK_INT_FB_DLY_SHIFT;
1040 clk_writel(reg, c->reg);
1043 /* External memory controller clock ops */
1044 static void tegra2_emc_clk_init(struct clk *c)
1046 tegra2_periph_clk_init(c);
1047 c->max_rate = clk_get_rate_locked(c);
1050 static long tegra2_emc_clk_round_rate(struct clk *c, unsigned long rate)
1052 long new_rate = rate;
1054 new_rate = tegra_emc_round_rate(new_rate);
1058 BUG_ON(new_rate != tegra2_periph_clk_round_rate(c, new_rate));
1063 static int tegra2_emc_clk_set_rate(struct clk *c, unsigned long rate)
1066 /* The Tegra2 memory controller has an interlock with the clock
1067 * block that allows memory shadowed registers to be updated,
1068 * and then transfer them to the main registers at the same
1069 * time as the clock update without glitches. */
1070 ret = tegra_emc_set_rate(rate);
1074 ret = tegra2_periph_clk_set_rate(c, rate);
1080 static struct clk_ops tegra_emc_clk_ops = {
1081 .init = &tegra2_emc_clk_init,
1082 .enable = &tegra2_periph_clk_enable,
1083 .disable = &tegra2_periph_clk_disable,
1084 .set_parent = &tegra2_periph_clk_set_parent,
1085 .set_rate = &tegra2_emc_clk_set_rate,
1086 .round_rate = &tegra2_emc_clk_round_rate,
1087 .reset = &tegra2_periph_clk_reset,
1090 /* Clock doubler ops */
1091 static void tegra2_clk_double_init(struct clk *c)
1096 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1097 PERIPH_CLK_TO_ENB_BIT(c)))
1101 static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1103 if (rate != 2 * clk_get_rate(c->parent))
1110 static struct clk_ops tegra_clk_double_ops = {
1111 .init = &tegra2_clk_double_init,
1112 .enable = &tegra2_periph_clk_enable,
1113 .disable = &tegra2_periph_clk_disable,
1114 .set_rate = &tegra2_clk_double_set_rate,
1117 /* Audio sync clock ops */
1118 static void tegra2_audio_sync_clk_init(struct clk *c)
1121 const struct clk_mux_sel *sel;
1122 u32 val = clk_readl(c->reg);
1123 c->state = (val & (1<<4)) ? OFF : ON;
1125 for (sel = c->inputs; sel->input != NULL; sel++)
1126 if (sel->value == source)
1128 BUG_ON(sel->input == NULL);
1129 c->parent = sel->input;
1132 static int tegra2_audio_sync_clk_enable(struct clk *c)
1134 clk_writel(0, c->reg);
1138 static void tegra2_audio_sync_clk_disable(struct clk *c)
1140 clk_writel(1, c->reg);
1143 static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1146 const struct clk_mux_sel *sel;
1147 for (sel = c->inputs; sel->input != NULL; sel++) {
1148 if (sel->input == p) {
1149 val = clk_readl(c->reg);
1156 clk_writel(val, c->reg);
1158 if (c->refcnt && c->parent)
1159 clk_disable(c->parent);
1169 static struct clk_ops tegra_audio_sync_clk_ops = {
1170 .init = tegra2_audio_sync_clk_init,
1171 .enable = tegra2_audio_sync_clk_enable,
1172 .disable = tegra2_audio_sync_clk_disable,
1173 .set_parent = tegra2_audio_sync_clk_set_parent,
1176 /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1178 static void tegra2_cdev_clk_init(struct clk *c)
1180 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1181 * currently done in the pinmux code. */
1183 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1184 PERIPH_CLK_TO_ENB_BIT(c)))
1188 static int tegra2_cdev_clk_enable(struct clk *c)
1190 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1191 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1195 static void tegra2_cdev_clk_disable(struct clk *c)
1197 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1198 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1201 static struct clk_ops tegra_cdev_clk_ops = {
1202 .init = &tegra2_cdev_clk_init,
1203 .enable = &tegra2_cdev_clk_enable,
1204 .disable = &tegra2_cdev_clk_disable,
1207 /* shared bus ops */
1209 * Some clocks may have multiple downstream users that need to request a
1210 * higher clock rate. Shared bus clocks provide a unique shared_bus_user
1211 * clock to each user. The frequency of the bus is set to the highest
1212 * enabled shared_bus_user clock, with a minimum value set by the
1215 static void tegra_clk_shared_bus_update(struct clk *bus)
1218 unsigned long rate = bus->min_rate;
1220 list_for_each_entry(c, &bus->shared_bus_list,
1221 u.shared_bus_user.node) {
1222 if (c->u.shared_bus_user.enabled)
1223 rate = max(c->u.shared_bus_user.rate, rate);
1226 if (rate != clk_get_rate(bus))
1227 clk_set_rate(bus, rate);
1230 static void tegra_clk_shared_bus_init(struct clk *c)
1232 c->max_rate = c->parent->max_rate;
1233 c->u.shared_bus_user.rate = c->parent->max_rate;
1237 list_add_tail(&c->u.shared_bus_user.node,
1238 &c->parent->shared_bus_list);
1241 static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate)
1243 c->u.shared_bus_user.rate = rate;
1244 tegra_clk_shared_bus_update(c->parent);
1248 static long tegra_clk_shared_bus_round_rate(struct clk *c, unsigned long rate)
1250 return clk_round_rate(c->parent, rate);
1253 static int tegra_clk_shared_bus_enable(struct clk *c)
1255 c->u.shared_bus_user.enabled = true;
1256 tegra_clk_shared_bus_update(c->parent);
1260 static void tegra_clk_shared_bus_disable(struct clk *c)
1262 c->u.shared_bus_user.enabled = false;
1263 tegra_clk_shared_bus_update(c->parent);
1266 static struct clk_ops tegra_clk_shared_bus_ops = {
1267 .init = tegra_clk_shared_bus_init,
1268 .enable = tegra_clk_shared_bus_enable,
1269 .disable = tegra_clk_shared_bus_disable,
1270 .set_rate = tegra_clk_shared_bus_set_rate,
1271 .round_rate = tegra_clk_shared_bus_round_rate,
1275 /* Clock definitions */
1276 static struct clk tegra_clk_32k = {
1283 static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
1284 {32768, 12000000, 366, 1, 1, 0},
1285 {32768, 13000000, 397, 1, 1, 0},
1286 {32768, 19200000, 586, 1, 1, 0},
1287 {32768, 26000000, 793, 1, 1, 0},
1291 static struct clk tegra_pll_s = {
1293 .flags = PLL_ALT_MISC_REG,
1294 .ops = &tegra_pll_ops,
1295 .parent = &tegra_clk_32k,
1296 .max_rate = 26000000,
1301 .cf_min = 0, /* FIXME */
1302 .cf_max = 0, /* FIXME */
1303 .vco_min = 12000000,
1304 .vco_max = 26000000,
1305 .freq_table = tegra_pll_s_freq_table,
1310 static struct clk_mux_sel tegra_clk_m_sel[] = {
1311 { .input = &tegra_clk_32k, .value = 0},
1312 { .input = &tegra_pll_s, .value = 1},
1316 static struct clk tegra_clk_m = {
1318 .flags = ENABLE_ON_INIT,
1319 .ops = &tegra_clk_m_ops,
1320 .inputs = tegra_clk_m_sel,
1323 .max_rate = 26000000,
1326 static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
1327 { 0, 0, 0, 0, 0, 0 },
1330 static struct clk tegra_pll_c = {
1332 .flags = PLL_HAS_CPCON,
1333 .ops = &tegra_pll_ops,
1335 .parent = &tegra_clk_m,
1336 .max_rate = 600000000,
1338 .input_min = 2000000,
1339 .input_max = 31000000,
1342 .vco_min = 20000000,
1343 .vco_max = 1400000000,
1344 .freq_table = tegra_pll_c_freq_table,
1349 static struct clk tegra_pll_c_out1 = {
1350 .name = "pll_c_out1",
1351 .ops = &tegra_pll_div_ops,
1353 .parent = &tegra_pll_c,
1356 .max_rate = 600000000,
1359 static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
1360 { 12000000, 666000000, 666, 12, 1, 8},
1361 { 13000000, 666000000, 666, 13, 1, 8},
1362 { 19200000, 666000000, 555, 16, 1, 8},
1363 { 26000000, 666000000, 666, 26, 1, 8},
1364 { 12000000, 600000000, 600, 12, 1, 8},
1365 { 13000000, 600000000, 600, 13, 1, 8},
1366 { 19200000, 600000000, 375, 12, 1, 6},
1367 { 26000000, 600000000, 600, 26, 1, 8},
1368 { 0, 0, 0, 0, 0, 0 },
1371 static struct clk tegra_pll_m = {
1373 .flags = PLL_HAS_CPCON,
1374 .ops = &tegra_pll_ops,
1376 .parent = &tegra_clk_m,
1377 .max_rate = 800000000,
1379 .input_min = 2000000,
1380 .input_max = 31000000,
1383 .vco_min = 20000000,
1384 .vco_max = 1200000000,
1385 .freq_table = tegra_pll_m_freq_table,
1390 static struct clk tegra_pll_m_out1 = {
1391 .name = "pll_m_out1",
1392 .ops = &tegra_pll_div_ops,
1394 .parent = &tegra_pll_m,
1397 .max_rate = 600000000,
1400 static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
1401 { 12000000, 216000000, 432, 12, 2, 8},
1402 { 13000000, 216000000, 432, 13, 2, 8},
1403 { 19200000, 216000000, 90, 4, 2, 1},
1404 { 26000000, 216000000, 432, 26, 2, 8},
1405 { 12000000, 432000000, 432, 12, 1, 8},
1406 { 13000000, 432000000, 432, 13, 1, 8},
1407 { 19200000, 432000000, 90, 4, 1, 1},
1408 { 26000000, 432000000, 432, 26, 1, 8},
1409 { 0, 0, 0, 0, 0, 0 },
1412 static struct clk tegra_pll_p = {
1414 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1415 .ops = &tegra_pll_ops,
1417 .parent = &tegra_clk_m,
1418 .max_rate = 432000000,
1420 .input_min = 2000000,
1421 .input_max = 31000000,
1424 .vco_min = 20000000,
1425 .vco_max = 1400000000,
1426 .freq_table = tegra_pll_p_freq_table,
1431 static struct clk tegra_pll_p_out1 = {
1432 .name = "pll_p_out1",
1433 .ops = &tegra_pll_div_ops,
1434 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1435 .parent = &tegra_pll_p,
1438 .max_rate = 432000000,
1441 static struct clk tegra_pll_p_out2 = {
1442 .name = "pll_p_out2",
1443 .ops = &tegra_pll_div_ops,
1444 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1445 .parent = &tegra_pll_p,
1448 .max_rate = 432000000,
1451 static struct clk tegra_pll_p_out3 = {
1452 .name = "pll_p_out3",
1453 .ops = &tegra_pll_div_ops,
1454 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1455 .parent = &tegra_pll_p,
1458 .max_rate = 432000000,
1461 static struct clk tegra_pll_p_out4 = {
1462 .name = "pll_p_out4",
1463 .ops = &tegra_pll_div_ops,
1464 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1465 .parent = &tegra_pll_p,
1468 .max_rate = 432000000,
1471 static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
1472 { 28800000, 56448000, 49, 25, 1, 1},
1473 { 28800000, 73728000, 64, 25, 1, 1},
1474 { 28800000, 24000000, 5, 6, 1, 1},
1475 { 0, 0, 0, 0, 0, 0 },
1478 static struct clk tegra_pll_a = {
1480 .flags = PLL_HAS_CPCON,
1481 .ops = &tegra_pll_ops,
1483 .parent = &tegra_pll_p_out1,
1484 .max_rate = 73728000,
1486 .input_min = 2000000,
1487 .input_max = 31000000,
1490 .vco_min = 20000000,
1491 .vco_max = 1400000000,
1492 .freq_table = tegra_pll_a_freq_table,
1497 static struct clk tegra_pll_a_out0 = {
1498 .name = "pll_a_out0",
1499 .ops = &tegra_pll_div_ops,
1501 .parent = &tegra_pll_a,
1504 .max_rate = 73728000,
1507 static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
1508 { 12000000, 216000000, 216, 12, 1, 4},
1509 { 13000000, 216000000, 216, 13, 1, 4},
1510 { 19200000, 216000000, 135, 12, 1, 3},
1511 { 26000000, 216000000, 216, 26, 1, 4},
1513 { 12000000, 594000000, 594, 12, 1, 8},
1514 { 13000000, 594000000, 594, 13, 1, 8},
1515 { 19200000, 594000000, 495, 16, 1, 8},
1516 { 26000000, 594000000, 594, 26, 1, 8},
1518 { 12000000, 1000000000, 1000, 12, 1, 12},
1519 { 13000000, 1000000000, 1000, 13, 1, 12},
1520 { 19200000, 1000000000, 625, 12, 1, 8},
1521 { 26000000, 1000000000, 1000, 26, 1, 12},
1523 { 0, 0, 0, 0, 0, 0 },
1526 static struct clk tegra_pll_d = {
1528 .flags = PLL_HAS_CPCON | PLLD,
1529 .ops = &tegra_pll_ops,
1531 .parent = &tegra_clk_m,
1532 .max_rate = 1000000000,
1534 .input_min = 2000000,
1535 .input_max = 40000000,
1538 .vco_min = 40000000,
1539 .vco_max = 1000000000,
1540 .freq_table = tegra_pll_d_freq_table,
1545 static struct clk tegra_pll_d_out0 = {
1546 .name = "pll_d_out0",
1547 .ops = &tegra_pll_div_ops,
1548 .flags = DIV_2 | PLLD,
1549 .parent = &tegra_pll_d,
1550 .max_rate = 500000000,
1553 static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
1554 { 12000000, 480000000, 960, 12, 2, 0},
1555 { 13000000, 480000000, 960, 13, 2, 0},
1556 { 19200000, 480000000, 200, 4, 2, 0},
1557 { 26000000, 480000000, 960, 26, 2, 0},
1558 { 0, 0, 0, 0, 0, 0 },
1561 static struct clk tegra_pll_u = {
1564 .ops = &tegra_pll_ops,
1566 .parent = &tegra_clk_m,
1567 .max_rate = 480000000,
1569 .input_min = 2000000,
1570 .input_max = 40000000,
1573 .vco_min = 480000000,
1574 .vco_max = 960000000,
1575 .freq_table = tegra_pll_u_freq_table,
1580 static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
1582 { 12000000, 1000000000, 1000, 12, 1, 12},
1583 { 13000000, 1000000000, 1000, 13, 1, 12},
1584 { 19200000, 1000000000, 625, 12, 1, 8},
1585 { 26000000, 1000000000, 1000, 26, 1, 12},
1588 { 12000000, 912000000, 912, 12, 1, 12},
1589 { 13000000, 912000000, 912, 13, 1, 12},
1590 { 19200000, 912000000, 760, 16, 1, 8},
1591 { 26000000, 912000000, 912, 26, 1, 12},
1594 { 12000000, 816000000, 816, 12, 1, 12},
1595 { 13000000, 816000000, 816, 13, 1, 12},
1596 { 19200000, 816000000, 680, 16, 1, 8},
1597 { 26000000, 816000000, 816, 26, 1, 12},
1600 { 12000000, 760000000, 760, 12, 1, 12},
1601 { 13000000, 760000000, 760, 13, 1, 12},
1602 { 19200000, 760000000, 950, 24, 1, 8},
1603 { 26000000, 760000000, 760, 26, 1, 12},
1606 { 12000000, 608000000, 608, 12, 1, 12},
1607 { 13000000, 608000000, 608, 13, 1, 12},
1608 { 19200000, 608000000, 380, 12, 1, 8},
1609 { 26000000, 608000000, 608, 26, 1, 12},
1612 { 12000000, 456000000, 456, 12, 1, 12},
1613 { 13000000, 456000000, 456, 13, 1, 12},
1614 { 19200000, 456000000, 380, 16, 1, 8},
1615 { 26000000, 456000000, 456, 26, 1, 12},
1618 { 12000000, 312000000, 312, 12, 1, 12},
1619 { 13000000, 312000000, 312, 13, 1, 12},
1620 { 19200000, 312000000, 260, 16, 1, 8},
1621 { 26000000, 312000000, 312, 26, 1, 12},
1623 { 0, 0, 0, 0, 0, 0 },
1626 static struct clk tegra_pll_x = {
1628 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1629 .ops = &tegra_pllx_ops,
1631 .parent = &tegra_clk_m,
1632 .max_rate = 1000000000,
1634 .input_min = 2000000,
1635 .input_max = 31000000,
1638 .vco_min = 20000000,
1639 .vco_max = 1200000000,
1640 .freq_table = tegra_pll_x_freq_table,
1645 static struct clk tegra_clk_d = {
1647 .flags = PERIPH_NO_RESET,
1648 .ops = &tegra_clk_double_ops,
1651 .parent = &tegra_clk_m,
1652 .max_rate = 52000000,
1658 /* dap_mclk1, belongs to the cdev1 pingroup. */
1659 static struct clk tegra_dev1_clk = {
1661 .ops = &tegra_cdev_clk_ops,
1663 .max_rate = 26000000,
1669 /* dap_mclk2, belongs to the cdev2 pingroup. */
1670 static struct clk tegra_dev2_clk = {
1672 .ops = &tegra_cdev_clk_ops,
1674 .max_rate = 26000000,
1680 /* initialized before peripheral clocks */
1681 static struct clk_mux_sel mux_audio_sync_clk[8+1];
1682 static const struct audio_sources {
1685 } mux_audio_sync_clk_sources[] = {
1686 { .name = "spdif_in", .value = 0 },
1687 { .name = "i2s1", .value = 1 },
1688 { .name = "i2s2", .value = 2 },
1689 { .name = "pll_a_out0", .value = 4 },
1690 #if 0 /* FIXME: not implemented */
1691 { .name = "ac97", .value = 3 },
1692 { .name = "ext_audio_clk2", .value = 5 },
1693 { .name = "ext_audio_clk1", .value = 6 },
1694 { .name = "ext_vimclk", .value = 7 },
1699 static struct clk tegra_clk_audio = {
1701 .inputs = mux_audio_sync_clk,
1703 .max_rate = 73728000,
1704 .ops = &tegra_audio_sync_clk_ops
1707 static struct clk tegra_clk_audio_2x = {
1709 .flags = PERIPH_NO_RESET,
1710 .max_rate = 48000000,
1711 .ops = &tegra_clk_double_ops,
1714 .parent = &tegra_clk_audio,
1720 struct clk_lookup tegra_audio_clk_lookups[] = {
1721 { .con_id = "audio", .clk = &tegra_clk_audio },
1722 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1725 /* This is called after peripheral clocks are initialized, as the
1726 * audio_sync clock depends on some of the peripheral clocks.
1729 static void init_audio_sync_clock_mux(void)
1732 struct clk_mux_sel *sel = mux_audio_sync_clk;
1733 const struct audio_sources *src = mux_audio_sync_clk_sources;
1734 struct clk_lookup *lookup;
1736 for (i = 0; src->name; i++, sel++, src++) {
1737 sel->input = tegra_get_clock_by_name(src->name);
1739 pr_err("%s: could not find clk %s\n", __func__,
1741 sel->value = src->value;
1744 lookup = tegra_audio_clk_lookups;
1745 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1746 clk_init(lookup->clk);
1751 static struct clk_mux_sel mux_cclk[] = {
1752 { .input = &tegra_clk_m, .value = 0},
1753 { .input = &tegra_pll_c, .value = 1},
1754 { .input = &tegra_clk_32k, .value = 2},
1755 { .input = &tegra_pll_m, .value = 3},
1756 { .input = &tegra_pll_p, .value = 4},
1757 { .input = &tegra_pll_p_out4, .value = 5},
1758 { .input = &tegra_pll_p_out3, .value = 6},
1759 { .input = &tegra_clk_d, .value = 7},
1760 { .input = &tegra_pll_x, .value = 8},
1764 static struct clk_mux_sel mux_sclk[] = {
1765 { .input = &tegra_clk_m, .value = 0},
1766 { .input = &tegra_pll_c_out1, .value = 1},
1767 { .input = &tegra_pll_p_out4, .value = 2},
1768 { .input = &tegra_pll_p_out3, .value = 3},
1769 { .input = &tegra_pll_p_out2, .value = 4},
1770 { .input = &tegra_clk_d, .value = 5},
1771 { .input = &tegra_clk_32k, .value = 6},
1772 { .input = &tegra_pll_m_out1, .value = 7},
1776 static struct clk tegra_clk_cclk = {
1780 .ops = &tegra_super_ops,
1781 .max_rate = 1000000000,
1784 static struct clk tegra_clk_sclk = {
1788 .ops = &tegra_super_ops,
1789 .max_rate = 240000000,
1790 .min_rate = 120000000,
1793 static struct clk tegra_clk_virtual_cpu = {
1795 .parent = &tegra_clk_cclk,
1796 .ops = &tegra_cpu_ops,
1797 .max_rate = 1000000000,
1799 .main = &tegra_pll_x,
1800 .backup = &tegra_pll_p,
1804 static struct clk tegra_clk_cop = {
1806 .parent = &tegra_clk_sclk,
1807 .ops = &tegra_cop_ops,
1808 .max_rate = 240000000,
1811 static struct clk tegra_clk_hclk = {
1814 .parent = &tegra_clk_sclk,
1817 .ops = &tegra_bus_ops,
1818 .max_rate = 240000000,
1821 static struct clk tegra_clk_pclk = {
1824 .parent = &tegra_clk_hclk,
1827 .ops = &tegra_bus_ops,
1828 .max_rate = 120000000,
1831 static struct clk tegra_clk_blink = {
1833 .parent = &tegra_clk_32k,
1835 .ops = &tegra_blink_clk_ops,
1839 static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1840 { .input = &tegra_pll_m, .value = 0},
1841 { .input = &tegra_pll_c, .value = 1},
1842 { .input = &tegra_pll_p, .value = 2},
1843 { .input = &tegra_pll_a_out0, .value = 3},
1847 static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1848 { .input = &tegra_pll_m, .value = 0},
1849 { .input = &tegra_pll_c, .value = 1},
1850 { .input = &tegra_pll_p, .value = 2},
1851 { .input = &tegra_clk_m, .value = 3},
1855 static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1856 { .input = &tegra_pll_p, .value = 0},
1857 { .input = &tegra_pll_c, .value = 1},
1858 { .input = &tegra_pll_m, .value = 2},
1859 { .input = &tegra_clk_m, .value = 3},
1863 static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1864 {.input = &tegra_pll_a_out0, .value = 0},
1865 {.input = &tegra_clk_audio_2x, .value = 1},
1866 {.input = &tegra_pll_p, .value = 2},
1867 {.input = &tegra_clk_m, .value = 3},
1871 static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1872 {.input = &tegra_pll_p, .value = 0},
1873 {.input = &tegra_pll_d_out0, .value = 1},
1874 {.input = &tegra_pll_c, .value = 2},
1875 {.input = &tegra_clk_m, .value = 3},
1879 static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1880 {.input = &tegra_pll_p, .value = 0},
1881 {.input = &tegra_pll_c, .value = 1},
1882 {.input = &tegra_clk_audio, .value = 2},
1883 {.input = &tegra_clk_m, .value = 3},
1884 {.input = &tegra_clk_32k, .value = 4},
1888 static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1889 {.input = &tegra_pll_p, .value = 0},
1890 {.input = &tegra_pll_c, .value = 1},
1891 {.input = &tegra_pll_m, .value = 2},
1895 static struct clk_mux_sel mux_clk_m[] = {
1896 { .input = &tegra_clk_m, .value = 0},
1900 static struct clk_mux_sel mux_pllp_out3[] = {
1901 { .input = &tegra_pll_p_out3, .value = 0},
1905 static struct clk_mux_sel mux_plld[] = {
1906 { .input = &tegra_pll_d, .value = 0},
1910 static struct clk_mux_sel mux_clk_32k[] = {
1911 { .input = &tegra_clk_32k, .value = 0},
1915 static struct clk tegra_clk_emc = {
1917 .ops = &tegra_emc_clk_ops,
1919 .max_rate = 800000000,
1920 .inputs = mux_pllm_pllc_pllp_clkm,
1921 .flags = MUX | DIV_U71 | PERIPH_EMC_ENB,
1927 #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
1934 .ops = &tegra_periph_clk_ops, \
1936 .inputs = _inputs, \
1940 .clk_num = _clk_num, \
1944 #define SHARED_CLK(_name, _dev, _con, _parent) \
1951 .ops = &tegra_clk_shared_bus_ops, \
1952 .parent = _parent, \
1955 struct clk tegra_list_clks[] = {
1956 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
1957 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
1958 PERIPH_CLK("kfuse", "kfuse-tegra", NULL, 40, 0, 26000000, mux_clk_m, 0),
1959 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1960 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1961 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1962 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
1963 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
1964 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1965 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1966 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1967 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1968 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1969 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1970 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1971 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1972 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1973 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1974 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1975 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1976 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1977 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1978 PERIPH_CLK("vcp", "tegra-avp", "vcp", 29, 0, 250000000, mux_clk_m, 0),
1979 PERIPH_CLK("bsea", "tegra-avp", "bsea", 62, 0, 250000000, mux_clk_m, 0),
1980 PERIPH_CLK("bsev", "tegra-aes", "bsev", 63, 0, 250000000, mux_clk_m, 0),
1981 PERIPH_CLK("vde", "tegra-avp", "vde", 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1982 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
1983 /* FIXME: what is la? */
1984 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1985 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1986 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1987 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1988 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1989 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1990 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1991 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1992 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1993 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1994 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1995 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1996 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1997 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1998 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1999 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2000 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2001 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 */
2002 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2003 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2004 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 */
2005 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2006 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2007 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2008 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2009 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2010 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2011 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2012 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2013 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2014 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2015 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2016 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2017 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
2018 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
2019 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
2020 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
2022 SHARED_CLK("avp.sclk", "tegra-avp", "sclk", &tegra_clk_sclk),
2023 SHARED_CLK("avp.emc", "tegra-avp", "emc", &tegra_clk_emc),
2024 SHARED_CLK("cpu.emc", "cpu", "emc", &tegra_clk_emc),
2025 SHARED_CLK("disp1.emc", "tegradc.0", "emc", &tegra_clk_emc),
2026 SHARED_CLK("disp2.emc", "tegradc.1", "emc", &tegra_clk_emc),
2027 SHARED_CLK("hdmi.emc", "hdmi", "emc", &tegra_clk_emc),
2028 SHARED_CLK("host.emc", "tegra_grhost", "emc", &tegra_clk_emc),
2029 SHARED_CLK("usbd.emc", "fsl-tegra-udc", "emc", &tegra_clk_emc),
2030 SHARED_CLK("usb1.emc", "tegra-ehci.0", "emc", &tegra_clk_emc),
2031 SHARED_CLK("usb2.emc", "tegra-ehci.1", "emc", &tegra_clk_emc),
2032 SHARED_CLK("usb3.emc", "tegra-ehci.2", "emc", &tegra_clk_emc),
2035 #define CLK_DUPLICATE(_name, _dev, _con) \
2044 /* Some clocks may be used by different drivers depending on the board
2045 * configuration. List those here to register them twice in the clock lookup
2046 * table under two names.
2048 struct clk_duplicate tegra_clk_duplicates[] = {
2049 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
2050 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
2051 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
2052 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
2053 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
2054 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
2055 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
2056 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
2057 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
2058 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
2059 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
2060 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
2061 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
2062 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
2063 CLK_DUPLICATE("host1x", "tegra_grhost", "host1x"),
2064 CLK_DUPLICATE("2d", "tegra_grhost", "gr2d"),
2065 CLK_DUPLICATE("3d", "tegra_grhost", "gr3d"),
2066 CLK_DUPLICATE("epp", "tegra_grhost", "epp"),
2067 CLK_DUPLICATE("mpe", "tegra_grhost", "mpe"),
2068 CLK_DUPLICATE("cop", "tegra-avp", "cop"),
2069 CLK_DUPLICATE("vde", "tegra-aes", "vde"),
2072 #define CLK(dev, con, ck) \
2079 struct clk *tegra_ptr_clks[] = {
2105 &tegra_clk_virtual_cpu,
2111 static void tegra2_init_one_clock(struct clk *c)
2114 INIT_LIST_HEAD(&c->shared_bus_list);
2115 if (!c->lookup.dev_id && !c->lookup.con_id)
2116 c->lookup.con_id = c->name;
2118 clkdev_add(&c->lookup);
2121 void __init tegra2_init_clocks(void)
2126 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
2127 tegra2_init_one_clock(tegra_ptr_clks[i]);
2129 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
2130 tegra2_init_one_clock(&tegra_list_clks[i]);
2132 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
2133 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
2135 pr_err("%s: Unknown duplicate clock %s\n", __func__,
2136 tegra_clk_duplicates[i].name);
2140 tegra_clk_duplicates[i].lookup.clk = c;
2141 clkdev_add(&tegra_clk_duplicates[i].lookup);
2144 init_audio_sync_clock_mux();
2148 static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
2149 PERIPH_CLK_SOURCE_NUM + 22];
2151 void tegra_clk_suspend(void)
2153 unsigned long off, i;
2154 u32 *ctx = clk_rst_suspend;
2156 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
2157 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
2158 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2159 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
2160 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2161 *ctx++ = clk_readl(tegra_pll_s.reg + PLL_BASE);
2162 *ctx++ = clk_readl(tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
2163 *ctx++ = clk_readl(tegra_pll_d.reg + PLL_BASE);
2164 *ctx++ = clk_readl(tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
2165 *ctx++ = clk_readl(tegra_pll_u.reg + PLL_BASE);
2166 *ctx++ = clk_readl(tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
2168 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
2169 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
2170 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
2172 *ctx++ = clk_readl(tegra_clk_cclk.reg);
2173 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2175 *ctx++ = clk_readl(tegra_clk_sclk.reg);
2176 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2177 *ctx++ = clk_readl(tegra_clk_pclk.reg);
2179 *ctx++ = clk_readl(tegra_clk_audio.reg);
2181 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2183 if (off == PERIPH_CLK_SOURCE_EMC)
2185 *ctx++ = clk_readl(off);
2189 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2190 *ctx++ = clk_readl(off);
2193 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2194 *ctx++ = clk_readl(off);
2196 *ctx++ = clk_readl(MISC_CLK_ENB);
2197 *ctx++ = clk_readl(CLK_MASK_ARM);
2199 BUG_ON(ctx - clk_rst_suspend != ARRAY_SIZE(clk_rst_suspend));
2202 void tegra_clk_resume(void)
2204 unsigned long off, i;
2205 const u32 *ctx = clk_rst_suspend;
2208 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2210 clk_writel(val, OSC_CTRL);
2212 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2213 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2214 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2215 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2216 clk_writel(*ctx++, tegra_pll_s.reg + PLL_BASE);
2217 clk_writel(*ctx++, tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
2218 clk_writel(*ctx++, tegra_pll_d.reg + PLL_BASE);
2219 clk_writel(*ctx++, tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
2220 clk_writel(*ctx++, tegra_pll_u.reg + PLL_BASE);
2221 clk_writel(*ctx++, tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
2224 clk_writel(*ctx++, tegra_pll_m_out1.reg);
2225 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2226 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2228 clk_writel(*ctx++, tegra_clk_cclk.reg);
2229 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2231 clk_writel(*ctx++, tegra_clk_sclk.reg);
2232 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2233 clk_writel(*ctx++, tegra_clk_pclk.reg);
2235 clk_writel(*ctx++, tegra_clk_audio.reg);
2237 /* enable all clocks before configuring clock sources */
2238 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2239 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2240 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2243 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2245 if (off == PERIPH_CLK_SOURCE_EMC)
2247 clk_writel(*ctx++, off);
2252 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2253 clk_writel(*ctx++, off);
2257 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2258 clk_writel(*ctx++, off);
2261 clk_writel(*ctx++, MISC_CLK_ENB);
2262 clk_writel(*ctx++, CLK_MASK_ARM);