2 * arch/arm/mach-tegra/tegra20_clocks.c
4 * Copyright (C) 2010 Google, Inc.
5 * Copyright (c) 2010-2012 NVIDIA CORPORATION. All rights reserved.
8 * Colin Cross <ccross@google.com>
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/list.h>
24 #include <linux/spinlock.h>
25 #include <linux/delay.h>
27 #include <linux/clkdev.h>
28 #include <linux/clk.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_PWM_MASK (7<<28)
74 #define PERIPH_CLK_SOURCE_PWM_SHIFT 28
75 #define PERIPH_CLK_SOURCE_ENABLE (1<<28)
76 #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
77 #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
78 #define PERIPH_CLK_SOURCE_DIV_SHIFT 0
80 #define SDMMC_CLK_INT_FB_SEL (1 << 23)
81 #define SDMMC_CLK_INT_FB_DLY_SHIFT 16
82 #define SDMMC_CLK_INT_FB_DLY_MASK (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT)
85 #define PLL_BASE_BYPASS (1<<31)
86 #define PLL_BASE_ENABLE (1<<30)
87 #define PLL_BASE_REF_ENABLE (1<<29)
88 #define PLL_BASE_OVERRIDE (1<<28)
89 #define PLL_BASE_DIVP_MASK (0x7<<20)
90 #define PLL_BASE_DIVP_SHIFT 20
91 #define PLL_BASE_DIVN_MASK (0x3FF<<8)
92 #define PLL_BASE_DIVN_SHIFT 8
93 #define PLL_BASE_DIVM_MASK (0x1F)
94 #define PLL_BASE_DIVM_SHIFT 0
96 #define PLL_OUT_RATIO_MASK (0xFF<<8)
97 #define PLL_OUT_RATIO_SHIFT 8
98 #define PLL_OUT_OVERRIDE (1<<2)
99 #define PLL_OUT_CLKEN (1<<1)
100 #define PLL_OUT_RESET_DISABLE (1<<0)
102 #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
104 #define PLL_MISC_DCCON_SHIFT 20
105 #define PLL_MISC_CPCON_SHIFT 8
106 #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
107 #define PLL_MISC_LFCON_SHIFT 4
108 #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
109 #define PLL_MISC_VCOCON_SHIFT 0
110 #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
112 #define PLLU_BASE_POST_DIV (1<<20)
114 #define PLLD_MISC_CLKENABLE (1<<30)
115 #define PLLD_MISC_DIV_RST (1<<23)
116 #define PLLD_MISC_DCCON_SHIFT 12
118 #define PLLE_MISC_READY (1 << 15)
120 #define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
121 #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
122 #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
124 #define SUPER_CLK_MUX 0x00
125 #define SUPER_STATE_SHIFT 28
126 #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
127 #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
128 #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
129 #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
130 #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
131 #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
132 #define SUPER_SOURCE_MASK 0xF
133 #define SUPER_FIQ_SOURCE_SHIFT 12
134 #define SUPER_IRQ_SOURCE_SHIFT 8
135 #define SUPER_RUN_SOURCE_SHIFT 4
136 #define SUPER_IDLE_SOURCE_SHIFT 0
138 #define SUPER_CLK_DIVIDER 0x04
140 #define BUS_CLK_DISABLE (1<<3)
141 #define BUS_CLK_DIV_MASK 0x3
144 #define PMC_CTRL_BLINK_ENB (1 << 7)
146 #define PMC_DPD_PADS_ORIDE 0x1c
147 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
149 #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
150 #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
151 #define PMC_BLINK_TIMER_ENB (1 << 15)
152 #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
153 #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
155 static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
156 static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
159 * Some clocks share a register with other clocks. Any clock op that
160 * non-atomically modifies a register used by another clock must lock
161 * clock_register_lock first.
163 static DEFINE_SPINLOCK(clock_register_lock);
166 * Some peripheral clocks share an enable bit, so refcount the enable bits
167 * in registers CLK_ENABLE_L, CLK_ENABLE_H, and CLK_ENABLE_U
169 static int tegra_periph_clk_enable_refcount[3 * 32];
171 #define clk_writel(value, reg) \
172 __raw_writel(value, reg_clk_base + (reg))
173 #define clk_readl(reg) \
174 __raw_readl(reg_clk_base + (reg))
175 #define pmc_writel(value, reg) \
176 __raw_writel(value, reg_pmc_base + (reg))
177 #define pmc_readl(reg) \
178 __raw_readl(reg_pmc_base + (reg))
180 static unsigned long clk_measure_input_freq(void)
182 u32 clock_autodetect;
183 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
184 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
185 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
186 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
188 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
190 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
192 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
195 pr_err("%s: Unexpected clock autodetect value %d",
196 __func__, clock_autodetect);
202 static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
204 s64 divider_u71 = parent_rate * 2;
205 divider_u71 += rate - 1;
206 do_div(divider_u71, rate);
208 if (divider_u71 - 2 < 0)
211 if (divider_u71 - 2 > 255)
214 return divider_u71 - 2;
217 static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
221 divider_u16 = parent_rate;
222 divider_u16 += rate - 1;
223 do_div(divider_u16, rate);
225 if (divider_u16 - 1 < 0)
228 if (divider_u16 - 1 > 0xFFFF)
231 return divider_u16 - 1;
234 static unsigned long tegra_clk_fixed_recalc_rate(struct clk_hw *hw,
235 unsigned long parent_rate)
237 return to_clk_tegra(hw)->fixed_rate;
240 struct clk_ops tegra_clk_32k_ops = {
241 .recalc_rate = tegra_clk_fixed_recalc_rate,
244 /* clk_m functions */
245 static unsigned long tegra20_clk_m_recalc_rate(struct clk_hw *hw,
248 if (!to_clk_tegra(hw)->fixed_rate)
249 to_clk_tegra(hw)->fixed_rate = clk_measure_input_freq();
250 return to_clk_tegra(hw)->fixed_rate;
253 static void tegra20_clk_m_init(struct clk_hw *hw)
255 struct clk_tegra *c = to_clk_tegra(hw);
256 u32 osc_ctrl = clk_readl(OSC_CTRL);
257 u32 auto_clock_control = osc_ctrl & ~OSC_CTRL_OSC_FREQ_MASK;
259 switch (c->fixed_rate) {
261 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
264 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
267 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
270 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
275 clk_writel(auto_clock_control, OSC_CTRL);
278 struct clk_ops tegra_clk_m_ops = {
279 .init = tegra20_clk_m_init,
280 .recalc_rate = tegra20_clk_m_recalc_rate,
283 /* super clock functions */
284 /* "super clocks" on tegra have two-stage muxes and a clock skipping
285 * super divider. We will ignore the clock skipping divider, since we
286 * can't lower the voltage when using the clock skip, but we can if we
287 * lower the PLL frequency.
289 static int tegra20_super_clk_is_enabled(struct clk_hw *hw)
291 struct clk_tegra *c = to_clk_tegra(hw);
294 val = clk_readl(c->reg + SUPER_CLK_MUX);
295 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
296 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
301 static int tegra20_super_clk_enable(struct clk_hw *hw)
303 struct clk_tegra *c = to_clk_tegra(hw);
304 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
308 static void tegra20_super_clk_disable(struct clk_hw *hw)
310 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
312 /* oops - don't disable the CPU clock! */
316 static u8 tegra20_super_clk_get_parent(struct clk_hw *hw)
318 struct clk_tegra *c = to_clk_tegra(hw);
319 int val = clk_readl(c->reg + SUPER_CLK_MUX);
323 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
324 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
325 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
326 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
327 source = (val >> shift) & SUPER_SOURCE_MASK;
331 static int tegra20_super_clk_set_parent(struct clk_hw *hw, u8 index)
333 struct clk_tegra *c = to_clk_tegra(hw);
334 u32 val = clk_readl(c->reg + SUPER_CLK_MUX);
337 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
338 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
339 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
340 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
341 val &= ~(SUPER_SOURCE_MASK << shift);
342 val |= index << shift;
344 clk_writel(val, c->reg);
349 /* FIX ME: Need to switch parents to change the source PLL rate */
350 static unsigned long tegra20_super_clk_recalc_rate(struct clk_hw *hw,
356 static long tegra20_super_clk_round_rate(struct clk_hw *hw, unsigned long rate,
357 unsigned long *prate)
362 static int tegra20_super_clk_set_rate(struct clk_hw *hw, unsigned long rate,
363 unsigned long parent_rate)
368 struct clk_ops tegra_super_ops = {
369 .is_enabled = tegra20_super_clk_is_enabled,
370 .enable = tegra20_super_clk_enable,
371 .disable = tegra20_super_clk_disable,
372 .set_parent = tegra20_super_clk_set_parent,
373 .get_parent = tegra20_super_clk_get_parent,
374 .set_rate = tegra20_super_clk_set_rate,
375 .round_rate = tegra20_super_clk_round_rate,
376 .recalc_rate = tegra20_super_clk_recalc_rate,
379 static unsigned long tegra20_twd_clk_recalc_rate(struct clk_hw *hw,
380 unsigned long parent_rate)
382 struct clk_tegra *c = to_clk_tegra(hw);
383 u64 rate = parent_rate;
385 if (c->mul != 0 && c->div != 0) {
387 rate += c->div - 1; /* round up */
388 do_div(rate, c->div);
394 struct clk_ops tegra_twd_ops = {
395 .recalc_rate = tegra20_twd_clk_recalc_rate,
398 static u8 tegra20_cop_clk_get_parent(struct clk_hw *hw)
403 struct clk_ops tegra_cop_ops = {
404 .get_parent = tegra20_cop_clk_get_parent,
407 /* virtual cop clock functions. Used to acquire the fake 'cop' clock to
408 * reset the COP block (i.e. AVP) */
409 void tegra2_cop_clk_reset(struct clk_hw *hw, bool assert)
411 unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
413 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
414 clk_writel(1 << 1, reg);
417 /* bus clock functions */
418 static int tegra20_bus_clk_is_enabled(struct clk_hw *hw)
420 struct clk_tegra *c = to_clk_tegra(hw);
421 u32 val = clk_readl(c->reg);
423 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
427 static int tegra20_bus_clk_enable(struct clk_hw *hw)
429 struct clk_tegra *c = to_clk_tegra(hw);
433 spin_lock_irqsave(&clock_register_lock, flags);
435 val = clk_readl(c->reg);
436 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
437 clk_writel(val, c->reg);
439 spin_unlock_irqrestore(&clock_register_lock, flags);
444 static void tegra20_bus_clk_disable(struct clk_hw *hw)
446 struct clk_tegra *c = to_clk_tegra(hw);
450 spin_lock_irqsave(&clock_register_lock, flags);
452 val = clk_readl(c->reg);
453 val |= BUS_CLK_DISABLE << c->reg_shift;
454 clk_writel(val, c->reg);
456 spin_unlock_irqrestore(&clock_register_lock, flags);
459 static unsigned long tegra20_bus_clk_recalc_rate(struct clk_hw *hw,
462 struct clk_tegra *c = to_clk_tegra(hw);
463 u32 val = clk_readl(c->reg);
466 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
469 if (c->mul != 0 && c->div != 0) {
471 rate += c->div - 1; /* round up */
472 do_div(rate, c->div);
477 static int tegra20_bus_clk_set_rate(struct clk_hw *hw, unsigned long rate,
478 unsigned long parent_rate)
480 struct clk_tegra *c = to_clk_tegra(hw);
486 spin_lock_irqsave(&clock_register_lock, flags);
488 val = clk_readl(c->reg);
489 for (i = 1; i <= 4; i++) {
490 if (rate == parent_rate / i) {
491 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
492 val |= (i - 1) << c->reg_shift;
493 clk_writel(val, c->reg);
501 spin_unlock_irqrestore(&clock_register_lock, flags);
506 static long tegra20_bus_clk_round_rate(struct clk_hw *hw, unsigned long rate,
507 unsigned long *prate)
509 unsigned long parent_rate = *prate;
512 if (rate >= parent_rate)
515 divider = parent_rate;
517 do_div(divider, rate);
524 do_div(parent_rate, divider);
529 struct clk_ops tegra_bus_ops = {
530 .is_enabled = tegra20_bus_clk_is_enabled,
531 .enable = tegra20_bus_clk_enable,
532 .disable = tegra20_bus_clk_disable,
533 .set_rate = tegra20_bus_clk_set_rate,
534 .round_rate = tegra20_bus_clk_round_rate,
535 .recalc_rate = tegra20_bus_clk_recalc_rate,
538 /* Blink output functions */
539 static int tegra20_blink_clk_is_enabled(struct clk_hw *hw)
541 struct clk_tegra *c = to_clk_tegra(hw);
544 val = pmc_readl(PMC_CTRL);
545 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
549 static unsigned long tegra20_blink_clk_recalc_rate(struct clk_hw *hw,
552 struct clk_tegra *c = to_clk_tegra(hw);
557 val = pmc_readl(c->reg);
559 if (val & PMC_BLINK_TIMER_ENB) {
562 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
563 PMC_BLINK_TIMER_DATA_ON_MASK;
564 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
565 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
567 /* each tick in the blink timer is 4 32KHz clocks */
573 if (c->mul != 0 && c->div != 0) {
575 rate += c->div - 1; /* round up */
576 do_div(rate, c->div);
581 static int tegra20_blink_clk_enable(struct clk_hw *hw)
585 val = pmc_readl(PMC_DPD_PADS_ORIDE);
586 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
588 val = pmc_readl(PMC_CTRL);
589 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
594 static void tegra20_blink_clk_disable(struct clk_hw *hw)
598 val = pmc_readl(PMC_CTRL);
599 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
601 val = pmc_readl(PMC_DPD_PADS_ORIDE);
602 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
605 static int tegra20_blink_clk_set_rate(struct clk_hw *hw, unsigned long rate,
606 unsigned long parent_rate)
608 struct clk_tegra *c = to_clk_tegra(hw);
610 if (rate >= parent_rate) {
612 pmc_writel(0, c->reg);
617 on_off = DIV_ROUND_UP(parent_rate / 8, rate);
620 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
621 PMC_BLINK_TIMER_DATA_ON_SHIFT;
622 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
623 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
625 val |= PMC_BLINK_TIMER_ENB;
626 pmc_writel(val, c->reg);
632 static long tegra20_blink_clk_round_rate(struct clk_hw *hw, unsigned long rate,
633 unsigned long *prate)
637 long round_rate = *prate;
641 if (rate >= *prate) {
644 div = DIV_ROUND_UP(*prate / 8, rate);
649 round_rate += div - 1;
650 do_div(round_rate, div);
655 struct clk_ops tegra_blink_clk_ops = {
656 .is_enabled = tegra20_blink_clk_is_enabled,
657 .enable = tegra20_blink_clk_enable,
658 .disable = tegra20_blink_clk_disable,
659 .set_rate = tegra20_blink_clk_set_rate,
660 .round_rate = tegra20_blink_clk_round_rate,
661 .recalc_rate = tegra20_blink_clk_recalc_rate,
665 static int tegra20_pll_clk_wait_for_lock(struct clk_tegra *c)
667 udelay(c->u.pll.lock_delay);
671 static int tegra20_pll_clk_is_enabled(struct clk_hw *hw)
673 struct clk_tegra *c = to_clk_tegra(hw);
674 u32 val = clk_readl(c->reg + PLL_BASE);
676 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
680 static unsigned long tegra20_pll_clk_recalc_rate(struct clk_hw *hw,
683 struct clk_tegra *c = to_clk_tegra(hw);
684 u32 val = clk_readl(c->reg + PLL_BASE);
687 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
688 const struct clk_pll_freq_table *sel;
689 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
690 if (sel->input_rate == prate &&
691 sel->output_rate == c->u.pll.fixed_rate) {
693 c->div = sel->m * sel->p;
697 pr_err("Clock %s has unknown fixed frequency\n",
698 __clk_get_name(hw->clk));
700 } else if (val & PLL_BASE_BYPASS) {
704 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
705 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
707 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
709 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
712 if (c->mul != 0 && c->div != 0) {
714 rate += c->div - 1; /* round up */
715 do_div(rate, c->div);
720 static int tegra20_pll_clk_enable(struct clk_hw *hw)
722 struct clk_tegra *c = to_clk_tegra(hw);
724 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
726 val = clk_readl(c->reg + PLL_BASE);
727 val &= ~PLL_BASE_BYPASS;
728 val |= PLL_BASE_ENABLE;
729 clk_writel(val, c->reg + PLL_BASE);
731 tegra20_pll_clk_wait_for_lock(c);
736 static void tegra20_pll_clk_disable(struct clk_hw *hw)
738 struct clk_tegra *c = to_clk_tegra(hw);
740 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
742 val = clk_readl(c->reg);
743 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
744 clk_writel(val, c->reg);
747 static int tegra20_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate,
748 unsigned long parent_rate)
750 struct clk_tegra *c = to_clk_tegra(hw);
751 unsigned long input_rate = parent_rate;
752 const struct clk_pll_freq_table *sel;
755 pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate);
757 if (c->flags & PLL_FIXED) {
759 if (rate != c->u.pll.fixed_rate) {
760 pr_err("%s: Can not change %s fixed rate %lu to %lu\n",
761 __func__, __clk_get_name(hw->clk),
762 c->u.pll.fixed_rate, rate);
768 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
769 if (sel->input_rate == input_rate && sel->output_rate == rate) {
771 c->div = sel->m * sel->p;
773 val = clk_readl(c->reg + PLL_BASE);
774 if (c->flags & PLL_FIXED)
775 val |= PLL_BASE_OVERRIDE;
776 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
778 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
779 (sel->n << PLL_BASE_DIVN_SHIFT);
780 BUG_ON(sel->p < 1 || sel->p > 2);
781 if (c->flags & PLLU) {
783 val |= PLLU_BASE_POST_DIV;
786 val |= 1 << PLL_BASE_DIVP_SHIFT;
788 clk_writel(val, c->reg + PLL_BASE);
790 if (c->flags & PLL_HAS_CPCON) {
791 val = clk_readl(c->reg + PLL_MISC(c));
792 val &= ~PLL_MISC_CPCON_MASK;
793 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
794 clk_writel(val, c->reg + PLL_MISC(c));
798 tegra20_pll_clk_enable(hw);
805 static long tegra20_pll_clk_round_rate(struct clk_hw *hw, unsigned long rate,
806 unsigned long *prate)
808 struct clk_tegra *c = to_clk_tegra(hw);
809 const struct clk_pll_freq_table *sel;
810 unsigned long input_rate = *prate;
811 u64 output_rate = *prate;
815 if (c->flags & PLL_FIXED)
816 return c->u.pll.fixed_rate;
818 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++)
819 if (sel->input_rate == input_rate && sel->output_rate == rate) {
821 div = sel->m * sel->p;
825 if (sel->input_rate == 0)
829 output_rate += div - 1; /* round up */
830 do_div(output_rate, div);
835 struct clk_ops tegra_pll_ops = {
836 .is_enabled = tegra20_pll_clk_is_enabled,
837 .enable = tegra20_pll_clk_enable,
838 .disable = tegra20_pll_clk_disable,
839 .set_rate = tegra20_pll_clk_set_rate,
840 .recalc_rate = tegra20_pll_clk_recalc_rate,
841 .round_rate = tegra20_pll_clk_round_rate,
844 static void tegra20_pllx_clk_init(struct clk_hw *hw)
846 struct clk_tegra *c = to_clk_tegra(hw);
848 if (tegra_sku_id == 7)
849 c->max_rate = 750000000;
852 struct clk_ops tegra_pllx_ops = {
853 .init = tegra20_pllx_clk_init,
854 .is_enabled = tegra20_pll_clk_is_enabled,
855 .enable = tegra20_pll_clk_enable,
856 .disable = tegra20_pll_clk_disable,
857 .set_rate = tegra20_pll_clk_set_rate,
858 .recalc_rate = tegra20_pll_clk_recalc_rate,
859 .round_rate = tegra20_pll_clk_round_rate,
862 static int tegra20_plle_clk_enable(struct clk_hw *hw)
864 struct clk_tegra *c = to_clk_tegra(hw);
867 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
871 val = clk_readl(c->reg + PLL_BASE);
872 if (!(val & PLLE_MISC_READY))
875 val = clk_readl(c->reg + PLL_BASE);
876 val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS;
877 clk_writel(val, c->reg + PLL_BASE);
882 struct clk_ops tegra_plle_ops = {
883 .is_enabled = tegra20_pll_clk_is_enabled,
884 .enable = tegra20_plle_clk_enable,
885 .set_rate = tegra20_pll_clk_set_rate,
886 .recalc_rate = tegra20_pll_clk_recalc_rate,
887 .round_rate = tegra20_pll_clk_round_rate,
890 /* Clock divider ops */
891 static int tegra20_pll_div_clk_is_enabled(struct clk_hw *hw)
893 struct clk_tegra *c = to_clk_tegra(hw);
894 u32 val = clk_readl(c->reg);
896 val >>= c->reg_shift;
897 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
898 if (!(val & PLL_OUT_RESET_DISABLE))
903 static unsigned long tegra20_pll_div_clk_recalc_rate(struct clk_hw *hw,
906 struct clk_tegra *c = to_clk_tegra(hw);
908 u32 val = clk_readl(c->reg);
911 val >>= c->reg_shift;
913 if (c->flags & DIV_U71) {
914 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
915 c->div = (divu71 + 2);
917 } else if (c->flags & DIV_2) {
926 rate += c->div - 1; /* round up */
927 do_div(rate, c->div);
932 static int tegra20_pll_div_clk_enable(struct clk_hw *hw)
934 struct clk_tegra *c = to_clk_tegra(hw);
939 pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk));
941 if (c->flags & DIV_U71) {
942 spin_lock_irqsave(&clock_register_lock, flags);
943 val = clk_readl(c->reg);
944 new_val = val >> c->reg_shift;
947 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
949 val &= ~(0xFFFF << c->reg_shift);
950 val |= new_val << c->reg_shift;
951 clk_writel(val, c->reg);
952 spin_unlock_irqrestore(&clock_register_lock, flags);
954 } else if (c->flags & DIV_2) {
955 BUG_ON(!(c->flags & PLLD));
956 spin_lock_irqsave(&clock_register_lock, flags);
957 val = clk_readl(c->reg);
958 val &= ~PLLD_MISC_DIV_RST;
959 clk_writel(val, c->reg);
960 spin_unlock_irqrestore(&clock_register_lock, flags);
966 static void tegra20_pll_div_clk_disable(struct clk_hw *hw)
968 struct clk_tegra *c = to_clk_tegra(hw);
973 pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk));
975 if (c->flags & DIV_U71) {
976 spin_lock_irqsave(&clock_register_lock, flags);
977 val = clk_readl(c->reg);
978 new_val = val >> c->reg_shift;
981 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
983 val &= ~(0xFFFF << c->reg_shift);
984 val |= new_val << c->reg_shift;
985 clk_writel(val, c->reg);
986 spin_unlock_irqrestore(&clock_register_lock, flags);
987 } else if (c->flags & DIV_2) {
988 BUG_ON(!(c->flags & PLLD));
989 spin_lock_irqsave(&clock_register_lock, flags);
990 val = clk_readl(c->reg);
991 val |= PLLD_MISC_DIV_RST;
992 clk_writel(val, c->reg);
993 spin_unlock_irqrestore(&clock_register_lock, flags);
997 static int tegra20_pll_div_clk_set_rate(struct clk_hw *hw, unsigned long rate,
998 unsigned long parent_rate)
1000 struct clk_tegra *c = to_clk_tegra(hw);
1001 unsigned long flags;
1006 pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate);
1008 if (c->flags & DIV_U71) {
1009 divider_u71 = clk_div71_get_divider(parent_rate, rate);
1010 if (divider_u71 >= 0) {
1011 spin_lock_irqsave(&clock_register_lock, flags);
1012 val = clk_readl(c->reg);
1013 new_val = val >> c->reg_shift;
1015 if (c->flags & DIV_U71_FIXED)
1016 new_val |= PLL_OUT_OVERRIDE;
1017 new_val &= ~PLL_OUT_RATIO_MASK;
1018 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
1020 val &= ~(0xFFFF << c->reg_shift);
1021 val |= new_val << c->reg_shift;
1022 clk_writel(val, c->reg);
1023 c->div = divider_u71 + 2;
1025 spin_unlock_irqrestore(&clock_register_lock, flags);
1028 } else if (c->flags & DIV_2) {
1029 if (parent_rate == rate * 2)
1035 static long tegra20_pll_div_clk_round_rate(struct clk_hw *hw, unsigned long rate,
1036 unsigned long *prate)
1038 struct clk_tegra *c = to_clk_tegra(hw);
1039 unsigned long parent_rate = *prate;
1042 pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate);
1044 if (c->flags & DIV_U71) {
1045 divider = clk_div71_get_divider(parent_rate, rate);
1048 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
1049 } else if (c->flags & DIV_2) {
1050 return DIV_ROUND_UP(parent_rate, 2);
1055 struct clk_ops tegra_pll_div_ops = {
1056 .is_enabled = tegra20_pll_div_clk_is_enabled,
1057 .enable = tegra20_pll_div_clk_enable,
1058 .disable = tegra20_pll_div_clk_disable,
1059 .set_rate = tegra20_pll_div_clk_set_rate,
1060 .round_rate = tegra20_pll_div_clk_round_rate,
1061 .recalc_rate = tegra20_pll_div_clk_recalc_rate,
1064 /* Periph clk ops */
1066 static int tegra20_periph_clk_is_enabled(struct clk_hw *hw)
1068 struct clk_tegra *c = to_clk_tegra(hw);
1072 if (!c->u.periph.clk_num)
1075 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1076 PERIPH_CLK_TO_ENB_BIT(c)))
1079 if (!(c->flags & PERIPH_NO_RESET))
1080 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
1081 PERIPH_CLK_TO_ENB_BIT(c))
1088 static int tegra20_periph_clk_enable(struct clk_hw *hw)
1090 struct clk_tegra *c = to_clk_tegra(hw);
1091 unsigned long flags;
1094 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
1096 if (!c->u.periph.clk_num)
1099 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++;
1100 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1)
1103 spin_lock_irqsave(&clock_register_lock, flags);
1105 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1106 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1107 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
1108 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1109 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1110 if (c->flags & PERIPH_EMC_ENB) {
1111 /* The EMC peripheral clock has 2 extra enable bits */
1112 /* FIXME: Do they need to be disabled? */
1113 val = clk_readl(c->reg);
1115 clk_writel(val, c->reg);
1118 spin_unlock_irqrestore(&clock_register_lock, flags);
1123 static void tegra20_periph_clk_disable(struct clk_hw *hw)
1125 struct clk_tegra *c = to_clk_tegra(hw);
1126 unsigned long flags;
1128 pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk));
1130 if (!c->u.periph.clk_num)
1133 tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--;
1135 if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 0)
1138 spin_lock_irqsave(&clock_register_lock, flags);
1140 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1141 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1143 spin_unlock_irqrestore(&clock_register_lock, flags);
1146 void tegra2_periph_clk_reset(struct clk_hw *hw, bool assert)
1148 struct clk_tegra *c = to_clk_tegra(hw);
1149 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
1151 pr_debug("%s %s on clock %s\n", __func__,
1152 assert ? "assert" : "deassert", __clk_get_name(hw->clk));
1154 BUG_ON(!c->u.periph.clk_num);
1156 if (!(c->flags & PERIPH_NO_RESET))
1157 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1158 base + PERIPH_CLK_TO_ENB_SET_REG(c));
1161 static int tegra20_periph_clk_set_parent(struct clk_hw *hw, u8 index)
1163 struct clk_tegra *c = to_clk_tegra(hw);
1168 pr_debug("%s: %s %d\n", __func__, __clk_get_name(hw->clk), index);
1170 if (c->flags & MUX_PWM) {
1171 shift = PERIPH_CLK_SOURCE_PWM_SHIFT;
1172 mask = PERIPH_CLK_SOURCE_PWM_MASK;
1174 shift = PERIPH_CLK_SOURCE_SHIFT;
1175 mask = PERIPH_CLK_SOURCE_MASK;
1178 val = clk_readl(c->reg);
1180 val |= (index) << shift;
1182 clk_writel(val, c->reg);
1187 static u8 tegra20_periph_clk_get_parent(struct clk_hw *hw)
1189 struct clk_tegra *c = to_clk_tegra(hw);
1190 u32 val = clk_readl(c->reg);
1194 if (c->flags & MUX_PWM) {
1195 shift = PERIPH_CLK_SOURCE_PWM_SHIFT;
1196 mask = PERIPH_CLK_SOURCE_PWM_MASK;
1198 shift = PERIPH_CLK_SOURCE_SHIFT;
1199 mask = PERIPH_CLK_SOURCE_MASK;
1203 return (val & mask) >> shift;
1208 static unsigned long tegra20_periph_clk_recalc_rate(struct clk_hw *hw,
1209 unsigned long prate)
1211 struct clk_tegra *c = to_clk_tegra(hw);
1212 unsigned long rate = prate;
1213 u32 val = clk_readl(c->reg);
1215 if (c->flags & DIV_U71) {
1216 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
1217 c->div = divu71 + 2;
1219 } else if (c->flags & DIV_U16) {
1220 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
1221 c->div = divu16 + 1;
1229 if (c->mul != 0 && c->div != 0) {
1231 rate += c->div - 1; /* round up */
1232 do_div(rate, c->div);
1238 static int tegra20_periph_clk_set_rate(struct clk_hw *hw, unsigned long rate,
1239 unsigned long parent_rate)
1241 struct clk_tegra *c = to_clk_tegra(hw);
1245 val = clk_readl(c->reg);
1247 if (c->flags & DIV_U71) {
1248 divider = clk_div71_get_divider(parent_rate, rate);
1251 val = clk_readl(c->reg);
1252 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
1254 clk_writel(val, c->reg);
1255 c->div = divider + 2;
1259 } else if (c->flags & DIV_U16) {
1260 divider = clk_div16_get_divider(parent_rate, rate);
1262 val = clk_readl(c->reg);
1263 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
1265 clk_writel(val, c->reg);
1266 c->div = divider + 1;
1270 } else if (parent_rate <= rate) {
1279 static long tegra20_periph_clk_round_rate(struct clk_hw *hw,
1280 unsigned long rate, unsigned long *prate)
1282 struct clk_tegra *c = to_clk_tegra(hw);
1283 unsigned long parent_rate = __clk_get_rate(__clk_get_parent(hw->clk));
1286 pr_debug("%s: %s %lu\n", __func__, __clk_get_name(hw->clk), rate);
1289 parent_rate = *prate;
1291 if (c->flags & DIV_U71) {
1292 divider = clk_div71_get_divider(parent_rate, rate);
1296 return DIV_ROUND_UP(parent_rate * 2, divider + 2);
1297 } else if (c->flags & DIV_U16) {
1298 divider = clk_div16_get_divider(parent_rate, rate);
1301 return DIV_ROUND_UP(parent_rate, divider + 1);
1306 struct clk_ops tegra_periph_clk_ops = {
1307 .is_enabled = tegra20_periph_clk_is_enabled,
1308 .enable = tegra20_periph_clk_enable,
1309 .disable = tegra20_periph_clk_disable,
1310 .set_parent = tegra20_periph_clk_set_parent,
1311 .get_parent = tegra20_periph_clk_get_parent,
1312 .set_rate = tegra20_periph_clk_set_rate,
1313 .round_rate = tegra20_periph_clk_round_rate,
1314 .recalc_rate = tegra20_periph_clk_recalc_rate,
1317 /* External memory controller clock ops */
1318 static void tegra20_emc_clk_init(struct clk_hw *hw)
1320 struct clk_tegra *c = to_clk_tegra(hw);
1321 c->max_rate = __clk_get_rate(hw->clk);
1324 static long tegra20_emc_clk_round_rate(struct clk_hw *hw, unsigned long rate,
1325 unsigned long *prate)
1327 struct clk_tegra *c = to_clk_tegra(hw);
1332 * The slowest entry in the EMC clock table that is at least as
1335 emc_rate = tegra_emc_round_rate(rate);
1340 * The fastest rate the PLL will generate that is at most the
1343 clk_rate = tegra20_periph_clk_round_rate(hw, emc_rate, NULL);
1346 * If this fails, and emc_rate > clk_rate, it's because the maximum
1347 * rate in the EMC tables is larger than the maximum rate of the EMC
1348 * clock. The EMC clock's max rate is the rate it was running when the
1349 * kernel booted. Such a mismatch is probably due to using the wrong
1350 * BCT, i.e. using a Tegra20 BCT with an EMC table written for Tegra25.
1352 WARN_ONCE(emc_rate != clk_rate,
1353 "emc_rate %ld != clk_rate %ld",
1354 emc_rate, clk_rate);
1359 static int tegra20_emc_clk_set_rate(struct clk_hw *hw, unsigned long rate,
1360 unsigned long parent_rate)
1365 * The Tegra2 memory controller has an interlock with the clock
1366 * block that allows memory shadowed registers to be updated,
1367 * and then transfer them to the main registers at the same
1368 * time as the clock update without glitches.
1370 ret = tegra_emc_set_rate(rate);
1374 ret = tegra20_periph_clk_set_rate(hw, rate, parent_rate);
1380 struct clk_ops tegra_emc_clk_ops = {
1381 .init = tegra20_emc_clk_init,
1382 .is_enabled = tegra20_periph_clk_is_enabled,
1383 .enable = tegra20_periph_clk_enable,
1384 .disable = tegra20_periph_clk_disable,
1385 .set_parent = tegra20_periph_clk_set_parent,
1386 .get_parent = tegra20_periph_clk_get_parent,
1387 .set_rate = tegra20_emc_clk_set_rate,
1388 .round_rate = tegra20_emc_clk_round_rate,
1389 .recalc_rate = tegra20_periph_clk_recalc_rate,
1392 /* Clock doubler ops */
1393 static int tegra20_clk_double_is_enabled(struct clk_hw *hw)
1395 struct clk_tegra *c = to_clk_tegra(hw);
1399 if (!c->u.periph.clk_num)
1402 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1403 PERIPH_CLK_TO_ENB_BIT(c)))
1410 static unsigned long tegra20_clk_double_recalc_rate(struct clk_hw *hw,
1411 unsigned long prate)
1413 struct clk_tegra *c = to_clk_tegra(hw);
1420 rate += c->div - 1; /* round up */
1421 do_div(rate, c->div);
1426 static long tegra20_clk_double_round_rate(struct clk_hw *hw, unsigned long rate,
1427 unsigned long *prate)
1429 unsigned long output_rate = *prate;
1431 do_div(output_rate, 2);
1435 static int tegra20_clk_double_set_rate(struct clk_hw *hw, unsigned long rate,
1436 unsigned long parent_rate)
1438 if (rate != 2 * parent_rate)
1443 struct clk_ops tegra_clk_double_ops = {
1444 .is_enabled = tegra20_clk_double_is_enabled,
1445 .enable = tegra20_periph_clk_enable,
1446 .disable = tegra20_periph_clk_disable,
1447 .set_rate = tegra20_clk_double_set_rate,
1448 .recalc_rate = tegra20_clk_double_recalc_rate,
1449 .round_rate = tegra20_clk_double_round_rate,
1452 /* Audio sync clock ops */
1453 static int tegra20_audio_sync_clk_is_enabled(struct clk_hw *hw)
1455 struct clk_tegra *c = to_clk_tegra(hw);
1456 u32 val = clk_readl(c->reg);
1458 c->state = (val & (1<<4)) ? OFF : ON;
1462 static int tegra20_audio_sync_clk_enable(struct clk_hw *hw)
1464 struct clk_tegra *c = to_clk_tegra(hw);
1466 clk_writel(0, c->reg);
1470 static void tegra20_audio_sync_clk_disable(struct clk_hw *hw)
1472 struct clk_tegra *c = to_clk_tegra(hw);
1473 clk_writel(1, c->reg);
1476 static u8 tegra20_audio_sync_clk_get_parent(struct clk_hw *hw)
1478 struct clk_tegra *c = to_clk_tegra(hw);
1479 u32 val = clk_readl(c->reg);
1486 static int tegra20_audio_sync_clk_set_parent(struct clk_hw *hw, u8 index)
1488 struct clk_tegra *c = to_clk_tegra(hw);
1491 val = clk_readl(c->reg);
1495 clk_writel(val, c->reg);
1500 struct clk_ops tegra_audio_sync_clk_ops = {
1501 .is_enabled = tegra20_audio_sync_clk_is_enabled,
1502 .enable = tegra20_audio_sync_clk_enable,
1503 .disable = tegra20_audio_sync_clk_disable,
1504 .set_parent = tegra20_audio_sync_clk_set_parent,
1505 .get_parent = tegra20_audio_sync_clk_get_parent,
1508 /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1510 static int tegra20_cdev_clk_is_enabled(struct clk_hw *hw)
1512 struct clk_tegra *c = to_clk_tegra(hw);
1513 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1514 * currently done in the pinmux code. */
1517 BUG_ON(!c->u.periph.clk_num);
1519 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1520 PERIPH_CLK_TO_ENB_BIT(c)))
1525 static int tegra20_cdev_clk_enable(struct clk_hw *hw)
1527 struct clk_tegra *c = to_clk_tegra(hw);
1528 BUG_ON(!c->u.periph.clk_num);
1530 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1531 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1535 static void tegra20_cdev_clk_disable(struct clk_hw *hw)
1537 struct clk_tegra *c = to_clk_tegra(hw);
1538 BUG_ON(!c->u.periph.clk_num);
1540 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1541 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1544 static unsigned long tegra20_cdev_recalc_rate(struct clk_hw *hw,
1545 unsigned long prate)
1547 return to_clk_tegra(hw)->fixed_rate;
1550 struct clk_ops tegra_cdev_clk_ops = {
1551 .is_enabled = tegra20_cdev_clk_is_enabled,
1552 .enable = tegra20_cdev_clk_enable,
1553 .disable = tegra20_cdev_clk_disable,
1554 .recalc_rate = tegra20_cdev_recalc_rate,