Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-tegra/tegra2_clocks.c |
| 3 | * |
| 4 | * Copyright (C) 2010 Google, Inc. |
| 5 | * |
| 6 | * Author: |
| 7 | * Colin Cross <ccross@google.com> |
| 8 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 18 | */ |
| 19 | |
| 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> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/hrtimer.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 27 | #include <linux/clkdev.h> |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 28 | |
| 29 | #include <mach/iomap.h> |
Colin Cross | 2ea67fd | 2010-10-04 08:49:49 -0700 | [diff] [blame] | 30 | #include <mach/suspend.h> |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 31 | |
| 32 | #include "clock.h" |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 33 | #include "fuse.h" |
| 34 | #include "tegra2_dvfs.h" |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 35 | |
| 36 | #define RST_DEVICES 0x004 |
| 37 | #define RST_DEVICES_SET 0x300 |
| 38 | #define RST_DEVICES_CLR 0x304 |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 39 | #define RST_DEVICES_NUM 3 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 40 | |
| 41 | #define CLK_OUT_ENB 0x010 |
| 42 | #define CLK_OUT_ENB_SET 0x320 |
| 43 | #define CLK_OUT_ENB_CLR 0x324 |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 44 | #define CLK_OUT_ENB_NUM 3 |
| 45 | |
| 46 | #define CLK_MASK_ARM 0x44 |
| 47 | #define MISC_CLK_ENB 0x48 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 48 | |
| 49 | #define OSC_CTRL 0x50 |
| 50 | #define OSC_CTRL_OSC_FREQ_MASK (3<<30) |
| 51 | #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30) |
| 52 | #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30) |
| 53 | #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30) |
| 54 | #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 55 | #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 56 | |
| 57 | #define OSC_FREQ_DET 0x58 |
| 58 | #define OSC_FREQ_DET_TRIG (1<<31) |
| 59 | |
| 60 | #define OSC_FREQ_DET_STATUS 0x5C |
| 61 | #define OSC_FREQ_DET_BUSY (1<<31) |
| 62 | #define OSC_FREQ_DET_CNT_MASK 0xFFFF |
| 63 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 64 | #define PERIPH_CLK_SOURCE_I2S1 0x100 |
| 65 | #define PERIPH_CLK_SOURCE_EMC 0x19c |
| 66 | #define PERIPH_CLK_SOURCE_OSC 0x1fc |
| 67 | #define PERIPH_CLK_SOURCE_NUM \ |
| 68 | ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4) |
| 69 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 70 | #define PERIPH_CLK_SOURCE_MASK (3<<30) |
| 71 | #define PERIPH_CLK_SOURCE_SHIFT 30 |
| 72 | #define PERIPH_CLK_SOURCE_ENABLE (1<<28) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 73 | #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF |
| 74 | #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 75 | #define PERIPH_CLK_SOURCE_DIV_SHIFT 0 |
| 76 | |
| 77 | #define PLL_BASE 0x0 |
| 78 | #define PLL_BASE_BYPASS (1<<31) |
| 79 | #define PLL_BASE_ENABLE (1<<30) |
| 80 | #define PLL_BASE_REF_ENABLE (1<<29) |
| 81 | #define PLL_BASE_OVERRIDE (1<<28) |
| 82 | #define PLL_BASE_LOCK (1<<27) |
| 83 | #define PLL_BASE_DIVP_MASK (0x7<<20) |
| 84 | #define PLL_BASE_DIVP_SHIFT 20 |
| 85 | #define PLL_BASE_DIVN_MASK (0x3FF<<8) |
| 86 | #define PLL_BASE_DIVN_SHIFT 8 |
| 87 | #define PLL_BASE_DIVM_MASK (0x1F) |
| 88 | #define PLL_BASE_DIVM_SHIFT 0 |
| 89 | |
| 90 | #define PLL_OUT_RATIO_MASK (0xFF<<8) |
| 91 | #define PLL_OUT_RATIO_SHIFT 8 |
| 92 | #define PLL_OUT_OVERRIDE (1<<2) |
| 93 | #define PLL_OUT_CLKEN (1<<1) |
| 94 | #define PLL_OUT_RESET_DISABLE (1<<0) |
| 95 | |
| 96 | #define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc) |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 97 | #define PLL_MISC_LOCK_ENABLE(c) (((c)->flags & PLLU) ? (1<<22) : (1<<18)) |
| 98 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 99 | #define PLL_MISC_DCCON_SHIFT 20 |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 100 | #define PLL_MISC_CPCON_SHIFT 8 |
| 101 | #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT) |
| 102 | #define PLL_MISC_LFCON_SHIFT 4 |
| 103 | #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT) |
| 104 | #define PLL_MISC_VCOCON_SHIFT 0 |
| 105 | #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT) |
| 106 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 107 | #define PLLU_BASE_POST_DIV (1<<20) |
| 108 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 109 | #define PLLD_MISC_CLKENABLE (1<<30) |
| 110 | #define PLLD_MISC_DIV_RST (1<<23) |
| 111 | #define PLLD_MISC_DCCON_SHIFT 12 |
| 112 | |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 113 | #define PLLE_MISC_READY (1 << 15) |
| 114 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 115 | #define PERIPH_CLK_TO_ENB_REG(c) ((c->clk_num / 32) * 4) |
| 116 | #define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->clk_num / 32) * 8) |
| 117 | #define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->clk_num % 32)) |
| 118 | |
| 119 | #define SUPER_CLK_MUX 0x00 |
| 120 | #define SUPER_STATE_SHIFT 28 |
| 121 | #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT) |
| 122 | #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT) |
| 123 | #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT) |
| 124 | #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT) |
| 125 | #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT) |
| 126 | #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT) |
| 127 | #define SUPER_SOURCE_MASK 0xF |
| 128 | #define SUPER_FIQ_SOURCE_SHIFT 12 |
| 129 | #define SUPER_IRQ_SOURCE_SHIFT 8 |
| 130 | #define SUPER_RUN_SOURCE_SHIFT 4 |
| 131 | #define SUPER_IDLE_SOURCE_SHIFT 0 |
| 132 | |
| 133 | #define SUPER_CLK_DIVIDER 0x04 |
| 134 | |
| 135 | #define BUS_CLK_DISABLE (1<<3) |
| 136 | #define BUS_CLK_DIV_MASK 0x3 |
| 137 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 138 | #define PMC_CTRL 0x0 |
| 139 | #define PMC_CTRL_BLINK_ENB (1 << 7) |
| 140 | |
| 141 | #define PMC_DPD_PADS_ORIDE 0x1c |
| 142 | #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20) |
| 143 | |
| 144 | #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0 |
| 145 | #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff |
| 146 | #define PMC_BLINK_TIMER_ENB (1 << 15) |
| 147 | #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16 |
| 148 | #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff |
| 149 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 150 | static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 151 | static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 152 | |
| 153 | #define clk_writel(value, reg) \ |
| 154 | __raw_writel(value, (u32)reg_clk_base + (reg)) |
| 155 | #define clk_readl(reg) \ |
| 156 | __raw_readl((u32)reg_clk_base + (reg)) |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 157 | #define pmc_writel(value, reg) \ |
| 158 | __raw_writel(value, (u32)reg_pmc_base + (reg)) |
| 159 | #define pmc_readl(reg) \ |
| 160 | __raw_readl((u32)reg_pmc_base + (reg)) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 161 | |
| 162 | unsigned long clk_measure_input_freq(void) |
| 163 | { |
| 164 | u32 clock_autodetect; |
| 165 | clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET); |
| 166 | do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY); |
| 167 | clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS); |
| 168 | if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) { |
| 169 | return 12000000; |
| 170 | } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) { |
| 171 | return 13000000; |
| 172 | } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) { |
| 173 | return 19200000; |
| 174 | } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) { |
| 175 | return 26000000; |
| 176 | } else { |
| 177 | pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect); |
| 178 | BUG(); |
| 179 | return 0; |
| 180 | } |
| 181 | } |
| 182 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 183 | static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 184 | { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 185 | s64 divider_u71 = parent_rate * 2; |
| 186 | divider_u71 += rate - 1; |
| 187 | do_div(divider_u71, rate); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 188 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 189 | if (divider_u71 - 2 < 0) |
| 190 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 191 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 192 | if (divider_u71 - 2 > 255) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 193 | return -EINVAL; |
| 194 | |
| 195 | return divider_u71 - 2; |
| 196 | } |
| 197 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 198 | static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 199 | { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 200 | s64 divider_u16; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 201 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 202 | divider_u16 = parent_rate; |
| 203 | divider_u16 += rate - 1; |
| 204 | do_div(divider_u16, rate); |
| 205 | |
| 206 | if (divider_u16 - 1 < 0) |
| 207 | return 0; |
| 208 | |
| 209 | if (divider_u16 - 1 > 255) |
| 210 | return -EINVAL; |
| 211 | |
| 212 | return divider_u16 - 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 215 | /* clk_m functions */ |
| 216 | static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c) |
| 217 | { |
| 218 | u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK; |
| 219 | |
| 220 | c->rate = clk_measure_input_freq(); |
| 221 | switch (c->rate) { |
| 222 | case 12000000: |
| 223 | auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ; |
| 224 | break; |
| 225 | case 13000000: |
| 226 | auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ; |
| 227 | break; |
| 228 | case 19200000: |
| 229 | auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ; |
| 230 | break; |
| 231 | case 26000000: |
| 232 | auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ; |
| 233 | break; |
| 234 | default: |
| 235 | pr_err("%s: Unexpected clock rate %ld", __func__, c->rate); |
| 236 | BUG(); |
| 237 | } |
| 238 | clk_writel(auto_clock_control, OSC_CTRL); |
| 239 | return c->rate; |
| 240 | } |
| 241 | |
| 242 | static void tegra2_clk_m_init(struct clk *c) |
| 243 | { |
| 244 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 245 | tegra2_clk_m_autodetect_rate(c); |
| 246 | } |
| 247 | |
| 248 | static int tegra2_clk_m_enable(struct clk *c) |
| 249 | { |
| 250 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static void tegra2_clk_m_disable(struct clk *c) |
| 255 | { |
| 256 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 257 | BUG(); |
| 258 | } |
| 259 | |
| 260 | static struct clk_ops tegra_clk_m_ops = { |
| 261 | .init = tegra2_clk_m_init, |
| 262 | .enable = tegra2_clk_m_enable, |
| 263 | .disable = tegra2_clk_m_disable, |
| 264 | }; |
| 265 | |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame^] | 266 | void tegra2_periph_reset_assert(struct clk *c) |
| 267 | { |
| 268 | BUG_ON(!c->ops->reset); |
| 269 | c->ops->reset(c, true); |
| 270 | } |
| 271 | |
| 272 | void tegra2_periph_reset_deassert(struct clk *c) |
| 273 | { |
| 274 | BUG_ON(!c->ops->reset); |
| 275 | c->ops->reset(c, false); |
| 276 | } |
| 277 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 278 | /* super clock functions */ |
| 279 | /* "super clocks" on tegra have two-stage muxes and a clock skipping |
| 280 | * super divider. We will ignore the clock skipping divider, since we |
| 281 | * can't lower the voltage when using the clock skip, but we can if we |
| 282 | * lower the PLL frequency. |
| 283 | */ |
| 284 | static void tegra2_super_clk_init(struct clk *c) |
| 285 | { |
| 286 | u32 val; |
| 287 | int source; |
| 288 | int shift; |
| 289 | const struct clk_mux_sel *sel; |
| 290 | val = clk_readl(c->reg + SUPER_CLK_MUX); |
| 291 | c->state = ON; |
| 292 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 293 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 294 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 295 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
| 296 | source = (val >> shift) & SUPER_SOURCE_MASK; |
| 297 | for (sel = c->inputs; sel->input != NULL; sel++) { |
| 298 | if (sel->value == source) |
| 299 | break; |
| 300 | } |
| 301 | BUG_ON(sel->input == NULL); |
| 302 | c->parent = sel->input; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | static int tegra2_super_clk_enable(struct clk *c) |
| 306 | { |
| 307 | clk_writel(0, c->reg + SUPER_CLK_DIVIDER); |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static void tegra2_super_clk_disable(struct clk *c) |
| 312 | { |
| 313 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 314 | |
| 315 | /* oops - don't disable the CPU clock! */ |
| 316 | BUG(); |
| 317 | } |
| 318 | |
| 319 | static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p) |
| 320 | { |
| 321 | u32 val; |
| 322 | const struct clk_mux_sel *sel; |
| 323 | int shift; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 324 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 325 | val = clk_readl(c->reg + SUPER_CLK_MUX);; |
| 326 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 327 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 328 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 329 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
| 330 | for (sel = c->inputs; sel->input != NULL; sel++) { |
| 331 | if (sel->input == p) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 332 | val &= ~(SUPER_SOURCE_MASK << shift); |
| 333 | val |= sel->value << shift; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 334 | |
| 335 | if (c->refcnt) |
| 336 | clk_enable_locked(p); |
| 337 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 338 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 339 | |
| 340 | if (c->refcnt && c->parent) |
| 341 | clk_disable_locked(c->parent); |
| 342 | |
| 343 | clk_reparent(c, p); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 344 | return 0; |
| 345 | } |
| 346 | } |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | static struct clk_ops tegra_super_ops = { |
| 351 | .init = tegra2_super_clk_init, |
| 352 | .enable = tegra2_super_clk_enable, |
| 353 | .disable = tegra2_super_clk_disable, |
| 354 | .set_parent = tegra2_super_clk_set_parent, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | /* virtual cpu clock functions */ |
| 358 | /* some clocks can not be stopped (cpu, memory bus) while the SoC is running. |
| 359 | To change the frequency of these clocks, the parent pll may need to be |
| 360 | reprogrammed, so the clock must be moved off the pll, the pll reprogrammed, |
| 361 | and then the clock moved back to the pll. To hide this sequence, a virtual |
| 362 | clock handles it. |
| 363 | */ |
| 364 | static void tegra2_cpu_clk_init(struct clk *c) |
| 365 | { |
| 366 | } |
| 367 | |
| 368 | static int tegra2_cpu_clk_enable(struct clk *c) |
| 369 | { |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static void tegra2_cpu_clk_disable(struct clk *c) |
| 374 | { |
| 375 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 376 | |
| 377 | /* oops - don't disable the CPU clock! */ |
| 378 | BUG(); |
| 379 | } |
| 380 | |
| 381 | static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate) |
| 382 | { |
| 383 | int ret; |
| 384 | ret = clk_set_parent_locked(c->parent, c->backup); |
| 385 | if (ret) { |
| 386 | pr_err("Failed to switch cpu to clock %s\n", c->backup->name); |
| 387 | return ret; |
| 388 | } |
| 389 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 390 | if (rate == c->backup->rate) |
| 391 | goto out; |
| 392 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 393 | ret = clk_set_rate_locked(c->main, rate); |
| 394 | if (ret) { |
| 395 | pr_err("Failed to change cpu pll to %lu\n", rate); |
| 396 | return ret; |
| 397 | } |
| 398 | |
| 399 | ret = clk_set_parent_locked(c->parent, c->main); |
| 400 | if (ret) { |
| 401 | pr_err("Failed to switch cpu to clock %s\n", c->main->name); |
| 402 | return ret; |
| 403 | } |
| 404 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 405 | out: |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | static struct clk_ops tegra_cpu_ops = { |
| 410 | .init = tegra2_cpu_clk_init, |
| 411 | .enable = tegra2_cpu_clk_enable, |
| 412 | .disable = tegra2_cpu_clk_disable, |
| 413 | .set_rate = tegra2_cpu_clk_set_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 414 | }; |
| 415 | |
| 416 | /* bus clock functions */ |
| 417 | static void tegra2_bus_clk_init(struct clk *c) |
| 418 | { |
| 419 | u32 val = clk_readl(c->reg); |
| 420 | c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON; |
| 421 | c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1; |
| 422 | c->mul = 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static int tegra2_bus_clk_enable(struct clk *c) |
| 426 | { |
| 427 | u32 val = clk_readl(c->reg); |
| 428 | val &= ~(BUS_CLK_DISABLE << c->reg_shift); |
| 429 | clk_writel(val, c->reg); |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static void tegra2_bus_clk_disable(struct clk *c) |
| 434 | { |
| 435 | u32 val = clk_readl(c->reg); |
| 436 | val |= BUS_CLK_DISABLE << c->reg_shift; |
| 437 | clk_writel(val, c->reg); |
| 438 | } |
| 439 | |
| 440 | static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate) |
| 441 | { |
| 442 | u32 val = clk_readl(c->reg); |
| 443 | unsigned long parent_rate = c->parent->rate; |
| 444 | int i; |
| 445 | for (i = 1; i <= 4; i++) { |
| 446 | if (rate == parent_rate / i) { |
| 447 | val &= ~(BUS_CLK_DIV_MASK << c->reg_shift); |
| 448 | val |= (i - 1) << c->reg_shift; |
| 449 | clk_writel(val, c->reg); |
| 450 | c->div = i; |
| 451 | c->mul = 1; |
| 452 | return 0; |
| 453 | } |
| 454 | } |
| 455 | return -EINVAL; |
| 456 | } |
| 457 | |
| 458 | static struct clk_ops tegra_bus_ops = { |
| 459 | .init = tegra2_bus_clk_init, |
| 460 | .enable = tegra2_bus_clk_enable, |
| 461 | .disable = tegra2_bus_clk_disable, |
| 462 | .set_rate = tegra2_bus_clk_set_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 463 | }; |
| 464 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 465 | /* Blink output functions */ |
| 466 | |
| 467 | static void tegra2_blink_clk_init(struct clk *c) |
| 468 | { |
| 469 | u32 val; |
| 470 | |
| 471 | val = pmc_readl(PMC_CTRL); |
| 472 | c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF; |
| 473 | c->mul = 1; |
| 474 | val = pmc_readl(c->reg); |
| 475 | |
| 476 | if (val & PMC_BLINK_TIMER_ENB) { |
| 477 | unsigned int on_off; |
| 478 | |
| 479 | on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) & |
| 480 | PMC_BLINK_TIMER_DATA_ON_MASK; |
| 481 | val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 482 | val &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 483 | on_off += val; |
| 484 | /* each tick in the blink timer is 4 32KHz clocks */ |
| 485 | c->div = on_off * 4; |
| 486 | } else { |
| 487 | c->div = 1; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | static int tegra2_blink_clk_enable(struct clk *c) |
| 492 | { |
| 493 | u32 val; |
| 494 | |
| 495 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 496 | pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 497 | |
| 498 | val = pmc_readl(PMC_CTRL); |
| 499 | pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | static void tegra2_blink_clk_disable(struct clk *c) |
| 505 | { |
| 506 | u32 val; |
| 507 | |
| 508 | val = pmc_readl(PMC_CTRL); |
| 509 | pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 510 | |
| 511 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 512 | pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 513 | } |
| 514 | |
| 515 | static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate) |
| 516 | { |
| 517 | if (rate >= c->parent->rate) { |
| 518 | c->div = 1; |
| 519 | pmc_writel(0, c->reg); |
| 520 | } else { |
| 521 | unsigned int on_off; |
| 522 | u32 val; |
| 523 | |
| 524 | on_off = DIV_ROUND_UP(c->parent->rate / 8, rate); |
| 525 | c->div = on_off * 8; |
| 526 | |
| 527 | val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) << |
| 528 | PMC_BLINK_TIMER_DATA_ON_SHIFT; |
| 529 | on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 530 | on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 531 | val |= on_off; |
| 532 | val |= PMC_BLINK_TIMER_ENB; |
| 533 | pmc_writel(val, c->reg); |
| 534 | } |
| 535 | |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static struct clk_ops tegra_blink_clk_ops = { |
| 540 | .init = &tegra2_blink_clk_init, |
| 541 | .enable = &tegra2_blink_clk_enable, |
| 542 | .disable = &tegra2_blink_clk_disable, |
| 543 | .set_rate = &tegra2_blink_clk_set_rate, |
| 544 | }; |
| 545 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 546 | /* PLL Functions */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 547 | static int tegra2_pll_clk_wait_for_lock(struct clk *c) |
| 548 | { |
| 549 | ktime_t before; |
| 550 | |
| 551 | before = ktime_get(); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 552 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 553 | while (!(clk_readl(c->reg + PLL_BASE) & PLL_BASE_LOCK)) { |
| 554 | if (ktime_us_delta(ktime_get(), before) > 5000) { |
| 555 | pr_err("Timed out waiting for lock bit on pll %s", |
| 556 | c->name); |
| 557 | return -1; |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
| 564 | static void tegra2_pll_clk_init(struct clk *c) |
| 565 | { |
| 566 | u32 val = clk_readl(c->reg + PLL_BASE); |
| 567 | |
| 568 | c->state = (val & PLL_BASE_ENABLE) ? ON : OFF; |
| 569 | |
| 570 | if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) { |
| 571 | pr_warning("Clock %s has unknown fixed frequency\n", c->name); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 572 | c->mul = 1; |
| 573 | c->div = 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 574 | } else if (val & PLL_BASE_BYPASS) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 575 | c->mul = 1; |
| 576 | c->div = 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 577 | } else { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 578 | c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT; |
| 579 | c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT; |
| 580 | if (c->flags & PLLU) |
| 581 | c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2; |
| 582 | else |
| 583 | c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 584 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static int tegra2_pll_clk_enable(struct clk *c) |
| 588 | { |
| 589 | u32 val; |
| 590 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 591 | |
| 592 | val = clk_readl(c->reg + PLL_BASE); |
| 593 | val &= ~PLL_BASE_BYPASS; |
| 594 | val |= PLL_BASE_ENABLE; |
| 595 | clk_writel(val, c->reg + PLL_BASE); |
| 596 | |
| 597 | val = clk_readl(c->reg + PLL_MISC(c)); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 598 | val |= PLL_MISC_LOCK_ENABLE(c); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 599 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 600 | |
| 601 | tegra2_pll_clk_wait_for_lock(c); |
| 602 | |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | static void tegra2_pll_clk_disable(struct clk *c) |
| 607 | { |
| 608 | u32 val; |
| 609 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 610 | |
| 611 | val = clk_readl(c->reg); |
| 612 | val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE); |
| 613 | clk_writel(val, c->reg); |
| 614 | } |
| 615 | |
| 616 | static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate) |
| 617 | { |
| 618 | u32 val; |
| 619 | unsigned long input_rate; |
| 620 | const struct clk_pll_table *sel; |
| 621 | |
| 622 | pr_debug("%s: %s %lu\n", __func__, c->name, rate); |
| 623 | BUG_ON(c->refcnt != 0); |
| 624 | |
| 625 | input_rate = c->parent->rate; |
| 626 | for (sel = c->pll_table; sel->input_rate != 0; sel++) { |
| 627 | if (sel->input_rate == input_rate && sel->output_rate == rate) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 628 | c->mul = sel->n; |
| 629 | c->div = sel->m * sel->p; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 630 | |
| 631 | val = clk_readl(c->reg + PLL_BASE); |
| 632 | if (c->flags & PLL_FIXED) |
| 633 | val |= PLL_BASE_OVERRIDE; |
| 634 | val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK | |
| 635 | PLL_BASE_DIVM_MASK); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 636 | val |= (sel->m << PLL_BASE_DIVM_SHIFT) | |
| 637 | (sel->n << PLL_BASE_DIVN_SHIFT); |
| 638 | BUG_ON(sel->p < 1 || sel->p > 2); |
| 639 | if (c->flags & PLLU) { |
| 640 | if (sel->p == 1) |
| 641 | val |= PLLU_BASE_POST_DIV; |
| 642 | } else { |
| 643 | if (sel->p == 2) |
| 644 | val |= 1 << PLL_BASE_DIVP_SHIFT; |
| 645 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 646 | clk_writel(val, c->reg + PLL_BASE); |
| 647 | |
| 648 | if (c->flags & PLL_HAS_CPCON) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 649 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 650 | val &= ~PLL_MISC_CPCON_MASK; |
| 651 | val |= sel->cpcon << PLL_MISC_CPCON_SHIFT; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 652 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 653 | } |
| 654 | |
| 655 | if (c->state == ON) |
| 656 | tegra2_pll_clk_enable(c); |
| 657 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | } |
| 661 | return -EINVAL; |
| 662 | } |
| 663 | |
| 664 | static struct clk_ops tegra_pll_ops = { |
| 665 | .init = tegra2_pll_clk_init, |
| 666 | .enable = tegra2_pll_clk_enable, |
| 667 | .disable = tegra2_pll_clk_disable, |
| 668 | .set_rate = tegra2_pll_clk_set_rate, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 669 | }; |
| 670 | |
| 671 | static void tegra2_pllx_clk_init(struct clk *c) |
| 672 | { |
| 673 | tegra2_pll_clk_init(c); |
| 674 | |
| 675 | if (tegra_sku_id() == 7) |
| 676 | c->max_rate = 750000000; |
| 677 | } |
| 678 | |
| 679 | static struct clk_ops tegra_pllx_ops = { |
| 680 | .init = tegra2_pllx_clk_init, |
| 681 | .enable = tegra2_pll_clk_enable, |
| 682 | .disable = tegra2_pll_clk_disable, |
| 683 | .set_rate = tegra2_pll_clk_set_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 684 | }; |
| 685 | |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 686 | static int tegra2_plle_clk_enable(struct clk *c) |
| 687 | { |
| 688 | u32 val; |
| 689 | |
| 690 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 691 | |
| 692 | mdelay(1); |
| 693 | |
| 694 | val = clk_readl(c->reg + PLL_BASE); |
| 695 | if (!(val & PLLE_MISC_READY)) |
| 696 | return -EBUSY; |
| 697 | |
| 698 | val = clk_readl(c->reg + PLL_BASE); |
| 699 | val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS; |
| 700 | clk_writel(val, c->reg + PLL_BASE); |
| 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static struct clk_ops tegra_plle_ops = { |
| 706 | .init = tegra2_pll_clk_init, |
| 707 | .enable = tegra2_plle_clk_enable, |
| 708 | .set_rate = tegra2_pll_clk_set_rate, |
| 709 | }; |
| 710 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 711 | /* Clock divider ops */ |
| 712 | static void tegra2_pll_div_clk_init(struct clk *c) |
| 713 | { |
| 714 | u32 val = clk_readl(c->reg); |
| 715 | u32 divu71; |
| 716 | val >>= c->reg_shift; |
| 717 | c->state = (val & PLL_OUT_CLKEN) ? ON : OFF; |
| 718 | if (!(val & PLL_OUT_RESET_DISABLE)) |
| 719 | c->state = OFF; |
| 720 | |
| 721 | if (c->flags & DIV_U71) { |
| 722 | divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT; |
| 723 | c->div = (divu71 + 2); |
| 724 | c->mul = 2; |
| 725 | } else if (c->flags & DIV_2) { |
| 726 | c->div = 2; |
| 727 | c->mul = 1; |
| 728 | } else { |
| 729 | c->div = 1; |
| 730 | c->mul = 1; |
| 731 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static int tegra2_pll_div_clk_enable(struct clk *c) |
| 735 | { |
| 736 | u32 val; |
| 737 | u32 new_val; |
| 738 | |
| 739 | pr_debug("%s: %s\n", __func__, c->name); |
| 740 | if (c->flags & DIV_U71) { |
| 741 | val = clk_readl(c->reg); |
| 742 | new_val = val >> c->reg_shift; |
| 743 | new_val &= 0xFFFF; |
| 744 | |
| 745 | new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE; |
| 746 | |
| 747 | val &= ~(0xFFFF << c->reg_shift); |
| 748 | val |= new_val << c->reg_shift; |
| 749 | clk_writel(val, c->reg); |
| 750 | return 0; |
| 751 | } else if (c->flags & DIV_2) { |
| 752 | BUG_ON(!(c->flags & PLLD)); |
| 753 | val = clk_readl(c->reg); |
| 754 | val &= ~PLLD_MISC_DIV_RST; |
| 755 | clk_writel(val, c->reg); |
| 756 | return 0; |
| 757 | } |
| 758 | return -EINVAL; |
| 759 | } |
| 760 | |
| 761 | static void tegra2_pll_div_clk_disable(struct clk *c) |
| 762 | { |
| 763 | u32 val; |
| 764 | u32 new_val; |
| 765 | |
| 766 | pr_debug("%s: %s\n", __func__, c->name); |
| 767 | if (c->flags & DIV_U71) { |
| 768 | val = clk_readl(c->reg); |
| 769 | new_val = val >> c->reg_shift; |
| 770 | new_val &= 0xFFFF; |
| 771 | |
| 772 | new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE); |
| 773 | |
| 774 | val &= ~(0xFFFF << c->reg_shift); |
| 775 | val |= new_val << c->reg_shift; |
| 776 | clk_writel(val, c->reg); |
| 777 | } else if (c->flags & DIV_2) { |
| 778 | BUG_ON(!(c->flags & PLLD)); |
| 779 | val = clk_readl(c->reg); |
| 780 | val |= PLLD_MISC_DIV_RST; |
| 781 | clk_writel(val, c->reg); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate) |
| 786 | { |
| 787 | u32 val; |
| 788 | u32 new_val; |
| 789 | int divider_u71; |
| 790 | pr_debug("%s: %s %lu\n", __func__, c->name, rate); |
| 791 | if (c->flags & DIV_U71) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 792 | divider_u71 = clk_div71_get_divider(c->parent->rate, rate); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 793 | if (divider_u71 >= 0) { |
| 794 | val = clk_readl(c->reg); |
| 795 | new_val = val >> c->reg_shift; |
| 796 | new_val &= 0xFFFF; |
| 797 | if (c->flags & DIV_U71_FIXED) |
| 798 | new_val |= PLL_OUT_OVERRIDE; |
| 799 | new_val &= ~PLL_OUT_RATIO_MASK; |
| 800 | new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT; |
| 801 | |
| 802 | val &= ~(0xFFFF << c->reg_shift); |
| 803 | val |= new_val << c->reg_shift; |
| 804 | clk_writel(val, c->reg); |
| 805 | c->div = divider_u71 + 2; |
| 806 | c->mul = 2; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 807 | return 0; |
| 808 | } |
| 809 | } else if (c->flags & DIV_2) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 810 | if (c->parent->rate == rate * 2) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 811 | return 0; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 812 | } |
| 813 | return -EINVAL; |
| 814 | } |
| 815 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 816 | static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate) |
| 817 | { |
| 818 | int divider; |
| 819 | pr_debug("%s: %s %lu\n", __func__, c->name, rate); |
| 820 | |
| 821 | if (c->flags & DIV_U71) { |
| 822 | divider = clk_div71_get_divider(c->parent->rate, rate); |
| 823 | if (divider < 0) |
| 824 | return divider; |
| 825 | return c->parent->rate * 2 / (divider + 2); |
| 826 | } else if (c->flags & DIV_2) { |
| 827 | return c->parent->rate / 2; |
| 828 | } |
| 829 | return -EINVAL; |
| 830 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 831 | |
| 832 | static struct clk_ops tegra_pll_div_ops = { |
| 833 | .init = tegra2_pll_div_clk_init, |
| 834 | .enable = tegra2_pll_div_clk_enable, |
| 835 | .disable = tegra2_pll_div_clk_disable, |
| 836 | .set_rate = tegra2_pll_div_clk_set_rate, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 837 | .round_rate = tegra2_pll_div_clk_round_rate, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 838 | }; |
| 839 | |
| 840 | /* Periph clk ops */ |
| 841 | |
| 842 | static void tegra2_periph_clk_init(struct clk *c) |
| 843 | { |
| 844 | u32 val = clk_readl(c->reg); |
| 845 | const struct clk_mux_sel *mux = 0; |
| 846 | const struct clk_mux_sel *sel; |
| 847 | if (c->flags & MUX) { |
| 848 | for (sel = c->inputs; sel->input != NULL; sel++) { |
| 849 | if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value) |
| 850 | mux = sel; |
| 851 | } |
| 852 | BUG_ON(!mux); |
| 853 | |
| 854 | c->parent = mux->input; |
| 855 | } else { |
| 856 | c->parent = c->inputs[0].input; |
| 857 | } |
| 858 | |
| 859 | if (c->flags & DIV_U71) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 860 | u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 861 | c->div = divu71 + 2; |
| 862 | c->mul = 2; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 863 | } else if (c->flags & DIV_U16) { |
| 864 | u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 865 | c->div = divu16 + 1; |
| 866 | c->mul = 1; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 867 | } else { |
| 868 | c->div = 1; |
| 869 | c->mul = 1; |
| 870 | } |
| 871 | |
| 872 | c->state = ON; |
| 873 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 874 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 875 | c->state = OFF; |
| 876 | if (!(c->flags & PERIPH_NO_RESET)) |
| 877 | if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) & |
| 878 | PERIPH_CLK_TO_ENB_BIT(c)) |
| 879 | c->state = OFF; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static int tegra2_periph_clk_enable(struct clk *c) |
| 883 | { |
| 884 | u32 val; |
| 885 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 886 | |
| 887 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 888 | CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 889 | if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET)) |
| 890 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 891 | RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 892 | if (c->flags & PERIPH_EMC_ENB) { |
| 893 | /* The EMC peripheral clock has 2 extra enable bits */ |
| 894 | /* FIXME: Do they need to be disabled? */ |
| 895 | val = clk_readl(c->reg); |
| 896 | val |= 0x3 << 24; |
| 897 | clk_writel(val, c->reg); |
| 898 | } |
| 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static void tegra2_periph_clk_disable(struct clk *c) |
| 903 | { |
| 904 | pr_debug("%s on clock %s\n", __func__, c->name); |
| 905 | |
| 906 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 907 | CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 908 | } |
| 909 | |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame^] | 910 | static void tegra2_periph_clk_reset(struct clk *c, bool assert) |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 911 | { |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame^] | 912 | unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR; |
| 913 | |
| 914 | pr_debug("%s %s on clock %s\n", __func__, |
| 915 | assert ? "assert" : "deassert", c->name); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 916 | if (!(c->flags & PERIPH_NO_RESET)) |
| 917 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame^] | 918 | base + PERIPH_CLK_TO_ENB_SET_REG(c)); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 919 | } |
| 920 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 921 | static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p) |
| 922 | { |
| 923 | u32 val; |
| 924 | const struct clk_mux_sel *sel; |
| 925 | pr_debug("%s: %s %s\n", __func__, c->name, p->name); |
| 926 | for (sel = c->inputs; sel->input != NULL; sel++) { |
| 927 | if (sel->input == p) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 928 | val = clk_readl(c->reg); |
| 929 | val &= ~PERIPH_CLK_SOURCE_MASK; |
| 930 | val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 931 | |
| 932 | if (c->refcnt) |
| 933 | clk_enable_locked(p); |
| 934 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 935 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 936 | |
| 937 | if (c->refcnt && c->parent) |
| 938 | clk_disable_locked(c->parent); |
| 939 | |
| 940 | clk_reparent(c, p); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 941 | return 0; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | return -EINVAL; |
| 946 | } |
| 947 | |
| 948 | static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate) |
| 949 | { |
| 950 | u32 val; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 951 | int divider; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 952 | pr_debug("%s: %lu\n", __func__, rate); |
| 953 | if (c->flags & DIV_U71) { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 954 | divider = clk_div71_get_divider(c->parent->rate, rate); |
| 955 | if (divider >= 0) { |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 956 | val = clk_readl(c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 957 | val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK; |
| 958 | val |= divider; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 959 | clk_writel(val, c->reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 960 | c->div = divider + 2; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 961 | c->mul = 2; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 962 | return 0; |
| 963 | } |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 964 | } else if (c->flags & DIV_U16) { |
| 965 | divider = clk_div16_get_divider(c->parent->rate, rate); |
| 966 | if (divider >= 0) { |
| 967 | val = clk_readl(c->reg); |
| 968 | val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 969 | val |= divider; |
| 970 | clk_writel(val, c->reg); |
| 971 | c->div = divider + 1; |
| 972 | c->mul = 1; |
| 973 | return 0; |
| 974 | } |
| 975 | } else if (c->parent->rate <= rate) { |
| 976 | c->div = 1; |
| 977 | c->mul = 1; |
| 978 | return 0; |
| 979 | } |
| 980 | return -EINVAL; |
| 981 | } |
| 982 | |
| 983 | static long tegra2_periph_clk_round_rate(struct clk *c, |
| 984 | unsigned long rate) |
| 985 | { |
| 986 | int divider; |
| 987 | pr_debug("%s: %s %lu\n", __func__, c->name, rate); |
| 988 | |
| 989 | if (c->flags & DIV_U71) { |
| 990 | divider = clk_div71_get_divider(c->parent->rate, rate); |
| 991 | if (divider < 0) |
| 992 | return divider; |
| 993 | |
| 994 | return c->parent->rate * 2 / (divider + 2); |
| 995 | } else if (c->flags & DIV_U16) { |
| 996 | divider = clk_div16_get_divider(c->parent->rate, rate); |
| 997 | if (divider < 0) |
| 998 | return divider; |
| 999 | return c->parent->rate / (divider + 1); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1000 | } |
| 1001 | return -EINVAL; |
| 1002 | } |
| 1003 | |
| 1004 | static struct clk_ops tegra_periph_clk_ops = { |
| 1005 | .init = &tegra2_periph_clk_init, |
| 1006 | .enable = &tegra2_periph_clk_enable, |
| 1007 | .disable = &tegra2_periph_clk_disable, |
| 1008 | .set_parent = &tegra2_periph_clk_set_parent, |
| 1009 | .set_rate = &tegra2_periph_clk_set_rate, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1010 | .round_rate = &tegra2_periph_clk_round_rate, |
Dima Zavin | 2b84cb4f | 2010-09-02 19:11:11 -0700 | [diff] [blame^] | 1011 | .reset = &tegra2_periph_clk_reset, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1012 | }; |
| 1013 | |
| 1014 | /* Clock doubler ops */ |
| 1015 | static void tegra2_clk_double_init(struct clk *c) |
| 1016 | { |
| 1017 | c->mul = 2; |
| 1018 | c->div = 1; |
| 1019 | c->state = ON; |
| 1020 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1021 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 1022 | c->state = OFF; |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1023 | }; |
| 1024 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1025 | static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate) |
| 1026 | { |
| 1027 | if (rate != 2 * c->parent->rate) |
| 1028 | return -EINVAL; |
| 1029 | c->mul = 2; |
| 1030 | c->div = 1; |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1034 | static struct clk_ops tegra_clk_double_ops = { |
| 1035 | .init = &tegra2_clk_double_init, |
| 1036 | .enable = &tegra2_periph_clk_enable, |
| 1037 | .disable = &tegra2_periph_clk_disable, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1038 | .set_rate = &tegra2_clk_double_set_rate, |
| 1039 | }; |
| 1040 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1041 | /* Audio sync clock ops */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1042 | static void tegra2_audio_sync_clk_init(struct clk *c) |
| 1043 | { |
| 1044 | int source; |
| 1045 | const struct clk_mux_sel *sel; |
| 1046 | u32 val = clk_readl(c->reg); |
| 1047 | c->state = (val & (1<<4)) ? OFF : ON; |
| 1048 | source = val & 0xf; |
| 1049 | for (sel = c->inputs; sel->input != NULL; sel++) |
| 1050 | if (sel->value == source) |
| 1051 | break; |
| 1052 | BUG_ON(sel->input == NULL); |
| 1053 | c->parent = sel->input; |
| 1054 | } |
| 1055 | |
| 1056 | static int tegra2_audio_sync_clk_enable(struct clk *c) |
| 1057 | { |
| 1058 | clk_writel(0, c->reg); |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static void tegra2_audio_sync_clk_disable(struct clk *c) |
| 1063 | { |
| 1064 | clk_writel(1, c->reg); |
| 1065 | } |
| 1066 | |
| 1067 | static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p) |
| 1068 | { |
| 1069 | u32 val; |
| 1070 | const struct clk_mux_sel *sel; |
| 1071 | for (sel = c->inputs; sel->input != NULL; sel++) { |
| 1072 | if (sel->input == p) { |
| 1073 | val = clk_readl(c->reg); |
| 1074 | val &= ~0xf; |
| 1075 | val |= sel->value; |
| 1076 | |
| 1077 | if (c->refcnt) |
| 1078 | clk_enable_locked(p); |
| 1079 | |
| 1080 | clk_writel(val, c->reg); |
| 1081 | |
| 1082 | if (c->refcnt && c->parent) |
| 1083 | clk_disable_locked(c->parent); |
| 1084 | |
| 1085 | clk_reparent(c, p); |
| 1086 | return 0; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | return -EINVAL; |
| 1091 | } |
| 1092 | |
| 1093 | static int tegra2_audio_sync_clk_set_rate(struct clk *c, unsigned long rate) |
| 1094 | { |
| 1095 | unsigned long parent_rate; |
| 1096 | if (!c->parent) { |
| 1097 | pr_err("%s: clock has no parent\n", __func__); |
| 1098 | return -EINVAL; |
| 1099 | } |
| 1100 | parent_rate = c->parent->rate; |
| 1101 | if (rate != parent_rate) { |
| 1102 | pr_err("%s: %s/%ld differs from parent %s/%ld\n", |
| 1103 | __func__, |
| 1104 | c->name, rate, |
| 1105 | c->parent->name, parent_rate); |
| 1106 | return -EINVAL; |
| 1107 | } |
| 1108 | c->rate = parent_rate; |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
| 1112 | static struct clk_ops tegra_audio_sync_clk_ops = { |
| 1113 | .init = tegra2_audio_sync_clk_init, |
| 1114 | .enable = tegra2_audio_sync_clk_enable, |
| 1115 | .disable = tegra2_audio_sync_clk_disable, |
| 1116 | .set_rate = tegra2_audio_sync_clk_set_rate, |
| 1117 | .set_parent = tegra2_audio_sync_clk_set_parent, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1118 | }; |
| 1119 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1120 | /* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */ |
| 1121 | |
| 1122 | static void tegra2_cdev_clk_init(struct clk *c) |
| 1123 | { |
| 1124 | /* We could un-tristate the cdev1 or cdev2 pingroup here; this is |
| 1125 | * currently done in the pinmux code. */ |
| 1126 | c->state = ON; |
| 1127 | if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) & |
| 1128 | PERIPH_CLK_TO_ENB_BIT(c))) |
| 1129 | c->state = OFF; |
| 1130 | } |
| 1131 | |
| 1132 | static int tegra2_cdev_clk_enable(struct clk *c) |
| 1133 | { |
| 1134 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1135 | CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static void tegra2_cdev_clk_disable(struct clk *c) |
| 1140 | { |
| 1141 | clk_writel(PERIPH_CLK_TO_ENB_BIT(c), |
| 1142 | CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1143 | } |
| 1144 | |
| 1145 | static struct clk_ops tegra_cdev_clk_ops = { |
| 1146 | .init = &tegra2_cdev_clk_init, |
| 1147 | .enable = &tegra2_cdev_clk_enable, |
| 1148 | .disable = &tegra2_cdev_clk_disable, |
| 1149 | }; |
| 1150 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1151 | /* Clock definitions */ |
| 1152 | static struct clk tegra_clk_32k = { |
| 1153 | .name = "clk_32k", |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1154 | .rate = 32768, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1155 | .ops = NULL, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1156 | .max_rate = 32768, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1157 | }; |
| 1158 | |
| 1159 | static struct clk_pll_table tegra_pll_s_table[] = { |
| 1160 | {32768, 12000000, 366, 1, 1, 0}, |
| 1161 | {32768, 13000000, 397, 1, 1, 0}, |
| 1162 | {32768, 19200000, 586, 1, 1, 0}, |
| 1163 | {32768, 26000000, 793, 1, 1, 0}, |
| 1164 | {0, 0, 0, 0, 0, 0}, |
| 1165 | }; |
| 1166 | |
| 1167 | static struct clk tegra_pll_s = { |
| 1168 | .name = "pll_s", |
| 1169 | .flags = PLL_ALT_MISC_REG, |
| 1170 | .ops = &tegra_pll_ops, |
| 1171 | .reg = 0xf0, |
| 1172 | .input_min = 32768, |
| 1173 | .input_max = 32768, |
| 1174 | .parent = &tegra_clk_32k, |
| 1175 | .cf_min = 0, /* FIXME */ |
| 1176 | .cf_max = 0, /* FIXME */ |
| 1177 | .vco_min = 12000000, |
| 1178 | .vco_max = 26000000, |
| 1179 | .pll_table = tegra_pll_s_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1180 | .max_rate = 26000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1181 | }; |
| 1182 | |
| 1183 | static struct clk_mux_sel tegra_clk_m_sel[] = { |
| 1184 | { .input = &tegra_clk_32k, .value = 0}, |
| 1185 | { .input = &tegra_pll_s, .value = 1}, |
| 1186 | { 0, 0}, |
| 1187 | }; |
| 1188 | static struct clk tegra_clk_m = { |
| 1189 | .name = "clk_m", |
| 1190 | .flags = ENABLE_ON_INIT, |
| 1191 | .ops = &tegra_clk_m_ops, |
| 1192 | .inputs = tegra_clk_m_sel, |
| 1193 | .reg = 0x1fc, |
| 1194 | .reg_mask = (1<<28), |
| 1195 | .reg_shift = 28, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1196 | .max_rate = 26000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1197 | }; |
| 1198 | |
| 1199 | static struct clk_pll_table tegra_pll_c_table[] = { |
| 1200 | { 0, 0, 0, 0, 0, 0 }, |
| 1201 | }; |
| 1202 | |
| 1203 | static struct clk tegra_pll_c = { |
| 1204 | .name = "pll_c", |
| 1205 | .flags = PLL_HAS_CPCON, |
| 1206 | .ops = &tegra_pll_ops, |
| 1207 | .reg = 0x80, |
| 1208 | .input_min = 2000000, |
| 1209 | .input_max = 31000000, |
| 1210 | .parent = &tegra_clk_m, |
| 1211 | .cf_min = 1000000, |
| 1212 | .cf_max = 6000000, |
| 1213 | .vco_min = 20000000, |
| 1214 | .vco_max = 1400000000, |
| 1215 | .pll_table = tegra_pll_c_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1216 | .max_rate = 600000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | static struct clk tegra_pll_c_out1 = { |
| 1220 | .name = "pll_c_out1", |
| 1221 | .ops = &tegra_pll_div_ops, |
| 1222 | .flags = DIV_U71, |
| 1223 | .parent = &tegra_pll_c, |
| 1224 | .reg = 0x84, |
| 1225 | .reg_shift = 0, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1226 | .max_rate = 600000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1227 | }; |
| 1228 | |
| 1229 | static struct clk_pll_table tegra_pll_m_table[] = { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1230 | { 12000000, 666000000, 666, 12, 1, 8}, |
| 1231 | { 13000000, 666000000, 666, 13, 1, 8}, |
| 1232 | { 19200000, 666000000, 555, 16, 1, 8}, |
| 1233 | { 26000000, 666000000, 666, 26, 1, 8}, |
| 1234 | { 12000000, 600000000, 600, 12, 1, 8}, |
| 1235 | { 13000000, 600000000, 600, 13, 1, 8}, |
| 1236 | { 19200000, 600000000, 375, 12, 1, 6}, |
| 1237 | { 26000000, 600000000, 600, 26, 1, 8}, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1238 | { 0, 0, 0, 0, 0, 0 }, |
| 1239 | }; |
| 1240 | |
| 1241 | static struct clk tegra_pll_m = { |
| 1242 | .name = "pll_m", |
| 1243 | .flags = PLL_HAS_CPCON, |
| 1244 | .ops = &tegra_pll_ops, |
| 1245 | .reg = 0x90, |
| 1246 | .input_min = 2000000, |
| 1247 | .input_max = 31000000, |
| 1248 | .parent = &tegra_clk_m, |
| 1249 | .cf_min = 1000000, |
| 1250 | .cf_max = 6000000, |
| 1251 | .vco_min = 20000000, |
| 1252 | .vco_max = 1200000000, |
| 1253 | .pll_table = tegra_pll_m_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1254 | .max_rate = 800000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1255 | }; |
| 1256 | |
| 1257 | static struct clk tegra_pll_m_out1 = { |
| 1258 | .name = "pll_m_out1", |
| 1259 | .ops = &tegra_pll_div_ops, |
| 1260 | .flags = DIV_U71, |
| 1261 | .parent = &tegra_pll_m, |
| 1262 | .reg = 0x94, |
| 1263 | .reg_shift = 0, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1264 | .max_rate = 600000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1265 | }; |
| 1266 | |
| 1267 | static struct clk_pll_table tegra_pll_p_table[] = { |
| 1268 | { 12000000, 216000000, 432, 12, 2, 8}, |
| 1269 | { 13000000, 216000000, 432, 13, 2, 8}, |
| 1270 | { 19200000, 216000000, 90, 4, 2, 1}, |
| 1271 | { 26000000, 216000000, 432, 26, 2, 8}, |
| 1272 | { 12000000, 432000000, 432, 12, 1, 8}, |
| 1273 | { 13000000, 432000000, 432, 13, 1, 8}, |
| 1274 | { 19200000, 432000000, 90, 4, 1, 1}, |
| 1275 | { 26000000, 432000000, 432, 26, 1, 8}, |
| 1276 | { 0, 0, 0, 0, 0, 0 }, |
| 1277 | }; |
| 1278 | |
| 1279 | static struct clk tegra_pll_p = { |
| 1280 | .name = "pll_p", |
| 1281 | .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON, |
| 1282 | .ops = &tegra_pll_ops, |
| 1283 | .reg = 0xa0, |
| 1284 | .input_min = 2000000, |
| 1285 | .input_max = 31000000, |
| 1286 | .parent = &tegra_clk_m, |
| 1287 | .cf_min = 1000000, |
| 1288 | .cf_max = 6000000, |
| 1289 | .vco_min = 20000000, |
| 1290 | .vco_max = 1400000000, |
| 1291 | .pll_table = tegra_pll_p_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1292 | .max_rate = 432000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1293 | }; |
| 1294 | |
| 1295 | static struct clk tegra_pll_p_out1 = { |
| 1296 | .name = "pll_p_out1", |
| 1297 | .ops = &tegra_pll_div_ops, |
| 1298 | .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED, |
| 1299 | .parent = &tegra_pll_p, |
| 1300 | .reg = 0xa4, |
| 1301 | .reg_shift = 0, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1302 | .max_rate = 432000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1303 | }; |
| 1304 | |
| 1305 | static struct clk tegra_pll_p_out2 = { |
| 1306 | .name = "pll_p_out2", |
| 1307 | .ops = &tegra_pll_div_ops, |
| 1308 | .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED, |
| 1309 | .parent = &tegra_pll_p, |
| 1310 | .reg = 0xa4, |
| 1311 | .reg_shift = 16, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1312 | .max_rate = 432000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1313 | }; |
| 1314 | |
| 1315 | static struct clk tegra_pll_p_out3 = { |
| 1316 | .name = "pll_p_out3", |
| 1317 | .ops = &tegra_pll_div_ops, |
| 1318 | .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED, |
| 1319 | .parent = &tegra_pll_p, |
| 1320 | .reg = 0xa8, |
| 1321 | .reg_shift = 0, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1322 | .max_rate = 432000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1323 | }; |
| 1324 | |
| 1325 | static struct clk tegra_pll_p_out4 = { |
| 1326 | .name = "pll_p_out4", |
| 1327 | .ops = &tegra_pll_div_ops, |
| 1328 | .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED, |
| 1329 | .parent = &tegra_pll_p, |
| 1330 | .reg = 0xa8, |
| 1331 | .reg_shift = 16, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1332 | .max_rate = 432000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1333 | }; |
| 1334 | |
| 1335 | static struct clk_pll_table tegra_pll_a_table[] = { |
| 1336 | { 28800000, 56448000, 49, 25, 1, 1}, |
| 1337 | { 28800000, 73728000, 64, 25, 1, 1}, |
| 1338 | { 28800000, 11289600, 49, 25, 1, 1}, |
| 1339 | { 28800000, 12288000, 64, 25, 1, 1}, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1340 | { 28800000, 24000000, 5, 6, 1, 1}, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1341 | { 0, 0, 0, 0, 0, 0 }, |
| 1342 | }; |
| 1343 | |
| 1344 | static struct clk tegra_pll_a = { |
| 1345 | .name = "pll_a", |
| 1346 | .flags = PLL_HAS_CPCON, |
| 1347 | .ops = &tegra_pll_ops, |
| 1348 | .reg = 0xb0, |
| 1349 | .input_min = 2000000, |
| 1350 | .input_max = 31000000, |
| 1351 | .parent = &tegra_pll_p_out1, |
| 1352 | .cf_min = 1000000, |
| 1353 | .cf_max = 6000000, |
| 1354 | .vco_min = 20000000, |
| 1355 | .vco_max = 1400000000, |
| 1356 | .pll_table = tegra_pll_a_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1357 | .max_rate = 56448000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1358 | }; |
| 1359 | |
| 1360 | static struct clk tegra_pll_a_out0 = { |
| 1361 | .name = "pll_a_out0", |
| 1362 | .ops = &tegra_pll_div_ops, |
| 1363 | .flags = DIV_U71, |
| 1364 | .parent = &tegra_pll_a, |
| 1365 | .reg = 0xb4, |
| 1366 | .reg_shift = 0, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1367 | .max_rate = 56448000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1368 | }; |
| 1369 | |
| 1370 | static struct clk_pll_table tegra_pll_d_table[] = { |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1371 | { 12000000, 216000000, 216, 12, 1, 4}, |
| 1372 | { 13000000, 216000000, 216, 13, 1, 4}, |
| 1373 | { 19200000, 216000000, 135, 12, 1, 3}, |
| 1374 | { 26000000, 216000000, 216, 26, 1, 4}, |
| 1375 | |
| 1376 | { 12000000, 594000000, 594, 12, 1, 8}, |
| 1377 | { 13000000, 594000000, 594, 13, 1, 8}, |
| 1378 | { 19200000, 594000000, 495, 16, 1, 8}, |
| 1379 | { 26000000, 594000000, 594, 26, 1, 8}, |
| 1380 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1381 | { 12000000, 1000000000, 1000, 12, 1, 12}, |
| 1382 | { 13000000, 1000000000, 1000, 13, 1, 12}, |
| 1383 | { 19200000, 1000000000, 625, 12, 1, 8}, |
| 1384 | { 26000000, 1000000000, 1000, 26, 1, 12}, |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1385 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1386 | { 0, 0, 0, 0, 0, 0 }, |
| 1387 | }; |
| 1388 | |
| 1389 | static struct clk tegra_pll_d = { |
| 1390 | .name = "pll_d", |
| 1391 | .flags = PLL_HAS_CPCON | PLLD, |
| 1392 | .ops = &tegra_pll_ops, |
| 1393 | .reg = 0xd0, |
| 1394 | .input_min = 2000000, |
| 1395 | .input_max = 40000000, |
| 1396 | .parent = &tegra_clk_m, |
| 1397 | .cf_min = 1000000, |
| 1398 | .cf_max = 6000000, |
| 1399 | .vco_min = 40000000, |
| 1400 | .vco_max = 1000000000, |
| 1401 | .pll_table = tegra_pll_d_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1402 | .max_rate = 1000000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1403 | }; |
| 1404 | |
| 1405 | static struct clk tegra_pll_d_out0 = { |
| 1406 | .name = "pll_d_out0", |
| 1407 | .ops = &tegra_pll_div_ops, |
| 1408 | .flags = DIV_2 | PLLD, |
| 1409 | .parent = &tegra_pll_d, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1410 | .max_rate = 500000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1411 | }; |
| 1412 | |
| 1413 | static struct clk_pll_table tegra_pll_u_table[] = { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1414 | { 12000000, 480000000, 960, 12, 2, 0}, |
| 1415 | { 13000000, 480000000, 960, 13, 2, 0}, |
| 1416 | { 19200000, 480000000, 200, 4, 2, 0}, |
| 1417 | { 26000000, 480000000, 960, 26, 2, 0}, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1418 | { 0, 0, 0, 0, 0, 0 }, |
| 1419 | }; |
| 1420 | |
| 1421 | static struct clk tegra_pll_u = { |
| 1422 | .name = "pll_u", |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1423 | .flags = PLLU, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1424 | .ops = &tegra_pll_ops, |
| 1425 | .reg = 0xc0, |
| 1426 | .input_min = 2000000, |
| 1427 | .input_max = 40000000, |
| 1428 | .parent = &tegra_clk_m, |
| 1429 | .cf_min = 1000000, |
| 1430 | .cf_max = 6000000, |
| 1431 | .vco_min = 480000000, |
| 1432 | .vco_max = 960000000, |
| 1433 | .pll_table = tegra_pll_u_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1434 | .max_rate = 480000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1435 | }; |
| 1436 | |
| 1437 | static struct clk_pll_table tegra_pll_x_table[] = { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1438 | /* 1 GHz */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1439 | { 12000000, 1000000000, 1000, 12, 1, 12}, |
| 1440 | { 13000000, 1000000000, 1000, 13, 1, 12}, |
| 1441 | { 19200000, 1000000000, 625, 12, 1, 8}, |
| 1442 | { 26000000, 1000000000, 1000, 26, 1, 12}, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1443 | |
| 1444 | /* 912 MHz */ |
| 1445 | { 12000000, 912000000, 912, 12, 1, 12}, |
| 1446 | { 13000000, 912000000, 912, 13, 1, 12}, |
| 1447 | { 19200000, 912000000, 760, 16, 1, 8}, |
| 1448 | { 26000000, 912000000, 912, 26, 1, 12}, |
| 1449 | |
| 1450 | /* 816 MHz */ |
| 1451 | { 12000000, 816000000, 816, 12, 1, 12}, |
| 1452 | { 13000000, 816000000, 816, 13, 1, 12}, |
| 1453 | { 19200000, 816000000, 680, 16, 1, 8}, |
| 1454 | { 26000000, 816000000, 816, 26, 1, 12}, |
| 1455 | |
| 1456 | /* 760 MHz */ |
| 1457 | { 12000000, 760000000, 760, 12, 1, 12}, |
| 1458 | { 13000000, 760000000, 760, 13, 1, 12}, |
| 1459 | { 19200000, 760000000, 950, 24, 1, 8}, |
| 1460 | { 26000000, 760000000, 760, 26, 1, 12}, |
| 1461 | |
| 1462 | /* 608 MHz */ |
| 1463 | { 12000000, 608000000, 760, 12, 1, 12}, |
| 1464 | { 13000000, 608000000, 760, 13, 1, 12}, |
| 1465 | { 19200000, 608000000, 380, 12, 1, 8}, |
| 1466 | { 26000000, 608000000, 760, 26, 1, 12}, |
| 1467 | |
| 1468 | /* 456 MHz */ |
| 1469 | { 12000000, 456000000, 456, 12, 1, 12}, |
| 1470 | { 13000000, 456000000, 456, 13, 1, 12}, |
| 1471 | { 19200000, 456000000, 380, 16, 1, 8}, |
| 1472 | { 26000000, 456000000, 456, 26, 1, 12}, |
| 1473 | |
| 1474 | /* 312 MHz */ |
| 1475 | { 12000000, 312000000, 312, 12, 1, 12}, |
| 1476 | { 13000000, 312000000, 312, 13, 1, 12}, |
| 1477 | { 19200000, 312000000, 260, 16, 1, 8}, |
| 1478 | { 26000000, 312000000, 312, 26, 1, 12}, |
| 1479 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1480 | { 0, 0, 0, 0, 0, 0 }, |
| 1481 | }; |
| 1482 | |
| 1483 | static struct clk tegra_pll_x = { |
| 1484 | .name = "pll_x", |
| 1485 | .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1486 | .ops = &tegra_pllx_ops, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1487 | .reg = 0xe0, |
| 1488 | .input_min = 2000000, |
| 1489 | .input_max = 31000000, |
| 1490 | .parent = &tegra_clk_m, |
| 1491 | .cf_min = 1000000, |
| 1492 | .cf_max = 6000000, |
| 1493 | .vco_min = 20000000, |
| 1494 | .vco_max = 1200000000, |
| 1495 | .pll_table = tegra_pll_x_table, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1496 | .max_rate = 1000000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1497 | }; |
| 1498 | |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 1499 | static struct clk_pll_table tegra_pll_e_table[] = { |
| 1500 | { 12000000, 100000000, 200, 24, 1, 0 }, |
| 1501 | { 0, 0, 0, 0, 0, 0 }, |
| 1502 | }; |
| 1503 | |
| 1504 | static struct clk tegra_pll_e = { |
| 1505 | .name = "pll_e", |
| 1506 | .flags = PLL_ALT_MISC_REG, |
| 1507 | .ops = &tegra_plle_ops, |
| 1508 | .input_min = 12000000, |
| 1509 | .input_max = 12000000, |
| 1510 | .max_rate = 100000000, |
| 1511 | .parent = &tegra_clk_m, |
| 1512 | .reg = 0xe8, |
| 1513 | .pll_table = tegra_pll_e_table, |
| 1514 | }; |
| 1515 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1516 | static struct clk tegra_clk_d = { |
| 1517 | .name = "clk_d", |
| 1518 | .flags = PERIPH_NO_RESET, |
| 1519 | .ops = &tegra_clk_double_ops, |
| 1520 | .clk_num = 90, |
| 1521 | .reg = 0x34, |
| 1522 | .reg_shift = 12, |
| 1523 | .parent = &tegra_clk_m, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1524 | .max_rate = 52000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1525 | }; |
| 1526 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1527 | /* dap_mclk1, belongs to the cdev1 pingroup. */ |
| 1528 | static struct clk tegra_dev1_clk = { |
| 1529 | .name = "clk_dev1", |
| 1530 | .ops = &tegra_cdev_clk_ops, |
| 1531 | .clk_num = 94, |
| 1532 | .rate = 26000000, |
| 1533 | .max_rate = 26000000, |
| 1534 | }; |
| 1535 | |
| 1536 | /* dap_mclk2, belongs to the cdev2 pingroup. */ |
| 1537 | static struct clk tegra_dev2_clk = { |
| 1538 | .name = "clk_dev2", |
| 1539 | .ops = &tegra_cdev_clk_ops, |
| 1540 | .clk_num = 93, |
| 1541 | .rate = 26000000, |
| 1542 | .max_rate = 26000000, |
| 1543 | }; |
| 1544 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1545 | /* initialized before peripheral clocks */ |
| 1546 | static struct clk_mux_sel mux_audio_sync_clk[8+1]; |
| 1547 | static const struct audio_sources { |
| 1548 | const char *name; |
| 1549 | int value; |
| 1550 | } mux_audio_sync_clk_sources[] = { |
| 1551 | { .name = "spdif_in", .value = 0 }, |
| 1552 | { .name = "i2s1", .value = 1 }, |
| 1553 | { .name = "i2s2", .value = 2 }, |
| 1554 | { .name = "pll_a_out0", .value = 4 }, |
| 1555 | #if 0 /* FIXME: not implemented */ |
| 1556 | { .name = "ac97", .value = 3 }, |
| 1557 | { .name = "ext_audio_clk2", .value = 5 }, |
| 1558 | { .name = "ext_audio_clk1", .value = 6 }, |
| 1559 | { .name = "ext_vimclk", .value = 7 }, |
| 1560 | #endif |
| 1561 | { 0, 0 } |
| 1562 | }; |
| 1563 | |
| 1564 | static struct clk tegra_clk_audio = { |
| 1565 | .name = "audio", |
| 1566 | .inputs = mux_audio_sync_clk, |
| 1567 | .reg = 0x38, |
| 1568 | .max_rate = 24000000, |
| 1569 | .ops = &tegra_audio_sync_clk_ops |
| 1570 | }; |
| 1571 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1572 | static struct clk tegra_clk_audio_2x = { |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1573 | .name = "audio_2x", |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1574 | .flags = PERIPH_NO_RESET, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1575 | .max_rate = 48000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1576 | .ops = &tegra_clk_double_ops, |
| 1577 | .clk_num = 89, |
| 1578 | .reg = 0x34, |
| 1579 | .reg_shift = 8, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1580 | .parent = &tegra_clk_audio, |
| 1581 | }; |
| 1582 | |
| 1583 | struct clk_lookup tegra_audio_clk_lookups[] = { |
| 1584 | { .con_id = "audio", .clk = &tegra_clk_audio }, |
| 1585 | { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x } |
| 1586 | }; |
| 1587 | |
| 1588 | /* This is called after peripheral clocks are initialized, as the |
| 1589 | * audio_sync clock depends on some of the peripheral clocks. |
| 1590 | */ |
| 1591 | |
| 1592 | static void init_audio_sync_clock_mux(void) |
| 1593 | { |
| 1594 | int i; |
| 1595 | struct clk_mux_sel *sel = mux_audio_sync_clk; |
| 1596 | const struct audio_sources *src = mux_audio_sync_clk_sources; |
| 1597 | struct clk_lookup *lookup; |
| 1598 | |
| 1599 | for (i = 0; src->name; i++, sel++, src++) { |
| 1600 | sel->input = tegra_get_clock_by_name(src->name); |
| 1601 | if (!sel->input) |
| 1602 | pr_err("%s: could not find clk %s\n", __func__, |
| 1603 | src->name); |
| 1604 | sel->value = src->value; |
| 1605 | } |
| 1606 | |
| 1607 | lookup = tegra_audio_clk_lookups; |
| 1608 | for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) { |
| 1609 | clk_init(lookup->clk); |
| 1610 | clkdev_add(lookup); |
| 1611 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1612 | } |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1613 | |
| 1614 | static struct clk_mux_sel mux_cclk[] = { |
| 1615 | { .input = &tegra_clk_m, .value = 0}, |
| 1616 | { .input = &tegra_pll_c, .value = 1}, |
| 1617 | { .input = &tegra_clk_32k, .value = 2}, |
| 1618 | { .input = &tegra_pll_m, .value = 3}, |
| 1619 | { .input = &tegra_pll_p, .value = 4}, |
| 1620 | { .input = &tegra_pll_p_out4, .value = 5}, |
| 1621 | { .input = &tegra_pll_p_out3, .value = 6}, |
| 1622 | { .input = &tegra_clk_d, .value = 7}, |
| 1623 | { .input = &tegra_pll_x, .value = 8}, |
| 1624 | { 0, 0}, |
| 1625 | }; |
| 1626 | |
| 1627 | static struct clk_mux_sel mux_sclk[] = { |
| 1628 | { .input = &tegra_clk_m, .value = 0}, |
| 1629 | { .input = &tegra_pll_c_out1, .value = 1}, |
| 1630 | { .input = &tegra_pll_p_out4, .value = 2}, |
| 1631 | { .input = &tegra_pll_p_out3, .value = 3}, |
| 1632 | { .input = &tegra_pll_p_out2, .value = 4}, |
| 1633 | { .input = &tegra_clk_d, .value = 5}, |
| 1634 | { .input = &tegra_clk_32k, .value = 6}, |
| 1635 | { .input = &tegra_pll_m_out1, .value = 7}, |
| 1636 | { 0, 0}, |
| 1637 | }; |
| 1638 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1639 | static struct clk tegra_clk_cclk = { |
| 1640 | .name = "cclk", |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1641 | .inputs = mux_cclk, |
| 1642 | .reg = 0x20, |
| 1643 | .ops = &tegra_super_ops, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1644 | .max_rate = 1000000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1645 | }; |
| 1646 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1647 | static struct clk tegra_clk_sclk = { |
| 1648 | .name = "sclk", |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1649 | .inputs = mux_sclk, |
| 1650 | .reg = 0x28, |
| 1651 | .ops = &tegra_super_ops, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1652 | .max_rate = 600000000, |
| 1653 | }; |
| 1654 | |
| 1655 | static struct clk tegra_clk_virtual_cpu = { |
| 1656 | .name = "cpu", |
| 1657 | .parent = &tegra_clk_cclk, |
| 1658 | .main = &tegra_pll_x, |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1659 | .backup = &tegra_pll_p, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1660 | .ops = &tegra_cpu_ops, |
| 1661 | .max_rate = 1000000000, |
| 1662 | .dvfs = &tegra_dvfs_virtual_cpu_dvfs, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1663 | }; |
| 1664 | |
| 1665 | static struct clk tegra_clk_hclk = { |
| 1666 | .name = "hclk", |
| 1667 | .flags = DIV_BUS, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1668 | .parent = &tegra_clk_sclk, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1669 | .reg = 0x30, |
| 1670 | .reg_shift = 4, |
| 1671 | .ops = &tegra_bus_ops, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1672 | .max_rate = 240000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1673 | }; |
| 1674 | |
| 1675 | static struct clk tegra_clk_pclk = { |
| 1676 | .name = "pclk", |
| 1677 | .flags = DIV_BUS, |
| 1678 | .parent = &tegra_clk_hclk, |
| 1679 | .reg = 0x30, |
| 1680 | .reg_shift = 0, |
| 1681 | .ops = &tegra_bus_ops, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1682 | .max_rate = 108000000, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1683 | }; |
| 1684 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1685 | static struct clk tegra_clk_blink = { |
| 1686 | .name = "blink", |
| 1687 | .parent = &tegra_clk_32k, |
| 1688 | .reg = 0x40, |
| 1689 | .ops = &tegra_blink_clk_ops, |
| 1690 | .max_rate = 32768, |
| 1691 | }; |
| 1692 | |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1693 | static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = { |
| 1694 | { .input = &tegra_pll_m, .value = 0}, |
| 1695 | { .input = &tegra_pll_c, .value = 1}, |
| 1696 | { .input = &tegra_pll_p, .value = 2}, |
| 1697 | { .input = &tegra_pll_a_out0, .value = 3}, |
| 1698 | { 0, 0}, |
| 1699 | }; |
| 1700 | |
| 1701 | static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = { |
| 1702 | { .input = &tegra_pll_m, .value = 0}, |
| 1703 | { .input = &tegra_pll_c, .value = 1}, |
| 1704 | { .input = &tegra_pll_p, .value = 2}, |
| 1705 | { .input = &tegra_clk_m, .value = 3}, |
| 1706 | { 0, 0}, |
| 1707 | }; |
| 1708 | |
| 1709 | static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = { |
| 1710 | { .input = &tegra_pll_p, .value = 0}, |
| 1711 | { .input = &tegra_pll_c, .value = 1}, |
| 1712 | { .input = &tegra_pll_m, .value = 2}, |
| 1713 | { .input = &tegra_clk_m, .value = 3}, |
| 1714 | { 0, 0}, |
| 1715 | }; |
| 1716 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1717 | static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = { |
| 1718 | {.input = &tegra_pll_a_out0, .value = 0}, |
| 1719 | {.input = &tegra_clk_audio_2x, .value = 1}, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1720 | {.input = &tegra_pll_p, .value = 2}, |
| 1721 | {.input = &tegra_clk_m, .value = 3}, |
| 1722 | { 0, 0}, |
| 1723 | }; |
| 1724 | |
| 1725 | static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = { |
| 1726 | {.input = &tegra_pll_p, .value = 0}, |
| 1727 | {.input = &tegra_pll_d_out0, .value = 1}, |
| 1728 | {.input = &tegra_pll_c, .value = 2}, |
| 1729 | {.input = &tegra_clk_m, .value = 3}, |
| 1730 | { 0, 0}, |
| 1731 | }; |
| 1732 | |
| 1733 | static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = { |
| 1734 | {.input = &tegra_pll_p, .value = 0}, |
| 1735 | {.input = &tegra_pll_c, .value = 1}, |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1736 | {.input = &tegra_clk_audio, .value = 2}, |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1737 | {.input = &tegra_clk_m, .value = 3}, |
| 1738 | {.input = &tegra_clk_32k, .value = 4}, |
| 1739 | { 0, 0}, |
| 1740 | }; |
| 1741 | |
| 1742 | static struct clk_mux_sel mux_pllp_pllc_pllm[] = { |
| 1743 | {.input = &tegra_pll_p, .value = 0}, |
| 1744 | {.input = &tegra_pll_c, .value = 1}, |
| 1745 | {.input = &tegra_pll_m, .value = 2}, |
| 1746 | { 0, 0}, |
| 1747 | }; |
| 1748 | |
| 1749 | static struct clk_mux_sel mux_clk_m[] = { |
| 1750 | { .input = &tegra_clk_m, .value = 0}, |
| 1751 | { 0, 0}, |
| 1752 | }; |
| 1753 | |
| 1754 | static struct clk_mux_sel mux_pllp_out3[] = { |
| 1755 | { .input = &tegra_pll_p_out3, .value = 0}, |
| 1756 | { 0, 0}, |
| 1757 | }; |
| 1758 | |
| 1759 | static struct clk_mux_sel mux_plld[] = { |
| 1760 | { .input = &tegra_pll_d, .value = 0}, |
| 1761 | { 0, 0}, |
| 1762 | }; |
| 1763 | |
| 1764 | static struct clk_mux_sel mux_clk_32k[] = { |
| 1765 | { .input = &tegra_clk_32k, .value = 0}, |
| 1766 | { 0, 0}, |
| 1767 | }; |
| 1768 | |
Stephen Warren | 1ca0034 | 2011-01-05 14:32:20 -0700 | [diff] [blame] | 1769 | static struct clk_mux_sel mux_pclk[] = { |
| 1770 | { .input = &tegra_clk_pclk, .value = 0}, |
| 1771 | { 0, 0}, |
| 1772 | }; |
| 1773 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1774 | #define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1775 | { \ |
| 1776 | .name = _name, \ |
| 1777 | .lookup = { \ |
| 1778 | .dev_id = _dev, \ |
| 1779 | .con_id = _con, \ |
| 1780 | }, \ |
| 1781 | .ops = &tegra_periph_clk_ops, \ |
| 1782 | .clk_num = _clk_num, \ |
| 1783 | .reg = _reg, \ |
| 1784 | .inputs = _inputs, \ |
| 1785 | .flags = _flags, \ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1786 | .max_rate = _max, \ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | struct clk tegra_periph_clks[] = { |
Stephen Warren | 1ca0034 | 2011-01-05 14:32:20 -0700 | [diff] [blame] | 1790 | PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0), |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1791 | PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET), |
| 1792 | PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0), |
| 1793 | PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), |
| 1794 | PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1795 | /* FIXME: spdif has 2 clocks but 1 enable */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1796 | PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71), |
| 1797 | PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71), |
| 1798 | PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71), |
| 1799 | PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1800 | PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1801 | PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1802 | PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1803 | PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1804 | PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1805 | PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1806 | PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */ |
| 1807 | PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1808 | /* FIXME: vfir shares an enable with uartb */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1809 | PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1810 | PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
| 1811 | PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
| 1812 | PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1813 | PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1814 | PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */ |
| 1815 | PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1816 | /* FIXME: what is la? */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1817 | PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1818 | PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), |
| 1819 | PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */ |
| 1820 | PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */ |
| 1821 | PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16), |
| 1822 | PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16), |
| 1823 | PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16), |
| 1824 | PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16), |
| 1825 | PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0), |
| 1826 | PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0), |
| 1827 | PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0), |
| 1828 | PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0), |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1829 | PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX), |
| 1830 | PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX), |
| 1831 | PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX), |
| 1832 | PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX), |
| 1833 | PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX), |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1834 | 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 */ |
| 1835 | PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1836 | /* FIXME: vi and vi_sensor share an enable */ |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1837 | PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */ |
| 1838 | 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 */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1839 | PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */ |
| 1840 | PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */ |
| 1841 | PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */ |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1842 | /* FIXME: cve and tvo share an enable */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1843 | PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */ |
| 1844 | PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */ |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1845 | PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1846 | PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */ |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1847 | PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */ |
| 1848 | PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */ |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1849 | PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */ |
| 1850 | PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */ |
| 1851 | PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */ |
| 1852 | PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, 800000000, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB), |
| 1853 | PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */ |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1854 | PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0), |
| 1855 | PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */ |
| 1856 | PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET), |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 1857 | PERIPH_CLK("pex", NULL, "pex", 70, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET), |
| 1858 | PERIPH_CLK("afi", NULL, "afi", 72, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET), |
| 1859 | PERIPH_CLK("pcie_xclk", NULL, "pcie_xclk", 74, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET), |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1860 | }; |
| 1861 | |
| 1862 | #define CLK_DUPLICATE(_name, _dev, _con) \ |
| 1863 | { \ |
| 1864 | .name = _name, \ |
| 1865 | .lookup = { \ |
| 1866 | .dev_id = _dev, \ |
| 1867 | .con_id = _con, \ |
| 1868 | }, \ |
| 1869 | } |
| 1870 | |
| 1871 | /* Some clocks may be used by different drivers depending on the board |
| 1872 | * configuration. List those here to register them twice in the clock lookup |
| 1873 | * table under two names. |
| 1874 | */ |
| 1875 | struct clk_duplicate tegra_clk_duplicates[] = { |
| 1876 | CLK_DUPLICATE("uarta", "tegra_uart.0", NULL), |
| 1877 | CLK_DUPLICATE("uartb", "tegra_uart.1", NULL), |
| 1878 | CLK_DUPLICATE("uartc", "tegra_uart.2", NULL), |
| 1879 | CLK_DUPLICATE("uartd", "tegra_uart.3", NULL), |
| 1880 | CLK_DUPLICATE("uarte", "tegra_uart.4", NULL), |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1881 | CLK_DUPLICATE("usbd", "utmip-pad", NULL), |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1882 | CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL), |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1883 | CLK_DUPLICATE("usbd", "tegra-otg", NULL), |
| 1884 | CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"), |
| 1885 | CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"), |
| 1886 | CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL), |
| 1887 | CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL), |
| 1888 | CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL), |
| 1889 | CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL), |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1890 | }; |
| 1891 | |
| 1892 | #define CLK(dev, con, ck) \ |
| 1893 | { \ |
| 1894 | .dev_id = dev, \ |
| 1895 | .con_id = con, \ |
| 1896 | .clk = ck, \ |
| 1897 | } |
| 1898 | |
| 1899 | struct clk_lookup tegra_clk_lookups[] = { |
| 1900 | /* external root sources */ |
| 1901 | CLK(NULL, "32k_clk", &tegra_clk_32k), |
| 1902 | CLK(NULL, "pll_s", &tegra_pll_s), |
| 1903 | CLK(NULL, "clk_m", &tegra_clk_m), |
| 1904 | CLK(NULL, "pll_m", &tegra_pll_m), |
| 1905 | CLK(NULL, "pll_m_out1", &tegra_pll_m_out1), |
| 1906 | CLK(NULL, "pll_c", &tegra_pll_c), |
| 1907 | CLK(NULL, "pll_c_out1", &tegra_pll_c_out1), |
| 1908 | CLK(NULL, "pll_p", &tegra_pll_p), |
| 1909 | CLK(NULL, "pll_p_out1", &tegra_pll_p_out1), |
| 1910 | CLK(NULL, "pll_p_out2", &tegra_pll_p_out2), |
| 1911 | CLK(NULL, "pll_p_out3", &tegra_pll_p_out3), |
| 1912 | CLK(NULL, "pll_p_out4", &tegra_pll_p_out4), |
| 1913 | CLK(NULL, "pll_a", &tegra_pll_a), |
| 1914 | CLK(NULL, "pll_a_out0", &tegra_pll_a_out0), |
| 1915 | CLK(NULL, "pll_d", &tegra_pll_d), |
| 1916 | CLK(NULL, "pll_d_out0", &tegra_pll_d_out0), |
| 1917 | CLK(NULL, "pll_u", &tegra_pll_u), |
| 1918 | CLK(NULL, "pll_x", &tegra_pll_x), |
Mike Rapoport | 8d685bc | 2010-09-27 11:26:32 +0200 | [diff] [blame] | 1919 | CLK(NULL, "pll_e", &tegra_pll_e), |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1920 | CLK(NULL, "cclk", &tegra_clk_cclk), |
| 1921 | CLK(NULL, "sclk", &tegra_clk_sclk), |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1922 | CLK(NULL, "hclk", &tegra_clk_hclk), |
| 1923 | CLK(NULL, "pclk", &tegra_clk_pclk), |
| 1924 | CLK(NULL, "clk_d", &tegra_clk_d), |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1925 | CLK(NULL, "clk_dev1", &tegra_dev1_clk), |
| 1926 | CLK(NULL, "clk_dev2", &tegra_dev2_clk), |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1927 | CLK(NULL, "cpu", &tegra_clk_virtual_cpu), |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1928 | CLK(NULL, "blink", &tegra_clk_blink), |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1929 | }; |
| 1930 | |
| 1931 | void __init tegra2_init_clocks(void) |
| 1932 | { |
| 1933 | int i; |
| 1934 | struct clk_lookup *cl; |
| 1935 | struct clk *c; |
| 1936 | struct clk_duplicate *cd; |
| 1937 | |
| 1938 | for (i = 0; i < ARRAY_SIZE(tegra_clk_lookups); i++) { |
| 1939 | cl = &tegra_clk_lookups[i]; |
| 1940 | clk_init(cl->clk); |
| 1941 | clkdev_add(cl); |
| 1942 | } |
| 1943 | |
| 1944 | for (i = 0; i < ARRAY_SIZE(tegra_periph_clks); i++) { |
| 1945 | c = &tegra_periph_clks[i]; |
| 1946 | cl = &c->lookup; |
| 1947 | cl->clk = c; |
| 1948 | |
| 1949 | clk_init(cl->clk); |
| 1950 | clkdev_add(cl); |
| 1951 | } |
| 1952 | |
| 1953 | for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) { |
| 1954 | cd = &tegra_clk_duplicates[i]; |
| 1955 | c = tegra_get_clock_by_name(cd->name); |
| 1956 | if (c) { |
| 1957 | cl = &cd->lookup; |
| 1958 | cl->clk = c; |
| 1959 | clkdev_add(cl); |
| 1960 | } else { |
| 1961 | pr_err("%s: Unknown duplicate clock %s\n", __func__, |
| 1962 | cd->name); |
| 1963 | } |
| 1964 | } |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1965 | |
| 1966 | init_audio_sync_clock_mux(); |
Colin Cross | d861196 | 2010-01-28 16:40:29 -0800 | [diff] [blame] | 1967 | } |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1968 | |
| 1969 | #ifdef CONFIG_PM |
| 1970 | static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM + |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1971 | PERIPH_CLK_SOURCE_NUM + 19]; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1972 | |
| 1973 | void tegra_clk_suspend(void) |
| 1974 | { |
| 1975 | unsigned long off, i; |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1976 | u32 pllx_misc; |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1977 | u32 *ctx = clk_rst_suspend; |
| 1978 | |
| 1979 | *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK; |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 1980 | *ctx++ = clk_readl(tegra_pll_p.reg + PLL_BASE); |
| 1981 | *ctx++ = clk_readl(tegra_pll_p.reg + PLL_MISC(&tegra_pll_p)); |
| 1982 | *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE); |
| 1983 | *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c)); |
| 1984 | *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE); |
| 1985 | *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a)); |
| 1986 | |
| 1987 | *ctx++ = clk_readl(tegra_pll_m_out1.reg); |
| 1988 | *ctx++ = clk_readl(tegra_pll_p_out1.reg); |
| 1989 | *ctx++ = clk_readl(tegra_pll_p_out3.reg); |
| 1990 | *ctx++ = clk_readl(tegra_pll_a_out0.reg); |
| 1991 | *ctx++ = clk_readl(tegra_pll_c_out1.reg); |
| 1992 | |
| 1993 | *ctx++ = clk_readl(tegra_clk_cclk.reg); |
| 1994 | *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER); |
| 1995 | |
| 1996 | *ctx++ = clk_readl(tegra_clk_sclk.reg); |
| 1997 | *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER); |
| 1998 | *ctx++ = clk_readl(tegra_clk_pclk.reg); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 1999 | |
| 2000 | for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC; |
| 2001 | off += 4) { |
| 2002 | if (off == PERIPH_CLK_SOURCE_EMC) |
| 2003 | continue; |
| 2004 | *ctx++ = clk_readl(off); |
| 2005 | } |
| 2006 | |
| 2007 | off = RST_DEVICES; |
| 2008 | for (i = 0; i < RST_DEVICES_NUM; i++, off += 4) |
| 2009 | *ctx++ = clk_readl(off); |
| 2010 | |
| 2011 | off = CLK_OUT_ENB; |
| 2012 | for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4) |
| 2013 | *ctx++ = clk_readl(off); |
| 2014 | |
| 2015 | *ctx++ = clk_readl(MISC_CLK_ENB); |
| 2016 | *ctx++ = clk_readl(CLK_MASK_ARM); |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 2017 | |
| 2018 | pllx_misc = clk_readl(tegra_pll_x.reg + PLL_MISC(&tegra_pll_x)); |
| 2019 | pllx_misc &= ~PLL_MISC_LOCK_ENABLE(&tegra_pll_x); |
| 2020 | clk_writel(pllx_misc, tegra_pll_x.reg + PLL_MISC(&tegra_pll_x)); |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void tegra_clk_resume(void) |
| 2024 | { |
| 2025 | unsigned long off, i; |
| 2026 | const u32 *ctx = clk_rst_suspend; |
| 2027 | u32 val; |
| 2028 | |
| 2029 | val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK; |
| 2030 | val |= *ctx++; |
| 2031 | clk_writel(val, OSC_CTRL); |
| 2032 | |
Colin Cross | cea62c8 | 2010-10-04 11:49:26 -0700 | [diff] [blame] | 2033 | clk_writel(*ctx++, tegra_pll_p.reg + PLL_BASE); |
| 2034 | clk_writel(*ctx++, tegra_pll_p.reg + PLL_MISC(&tegra_pll_p)); |
| 2035 | clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE); |
| 2036 | clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c)); |
| 2037 | clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE); |
| 2038 | clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a)); |
| 2039 | udelay(300); |
| 2040 | |
| 2041 | clk_writel(*ctx++, tegra_pll_m_out1.reg); |
| 2042 | clk_writel(*ctx++, tegra_pll_p_out1.reg); |
| 2043 | clk_writel(*ctx++, tegra_pll_p_out3.reg); |
| 2044 | clk_writel(*ctx++, tegra_pll_a_out0.reg); |
| 2045 | clk_writel(*ctx++, tegra_pll_c_out1.reg); |
| 2046 | |
| 2047 | clk_writel(*ctx++, tegra_clk_cclk.reg); |
| 2048 | clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER); |
| 2049 | |
| 2050 | clk_writel(*ctx++, tegra_clk_sclk.reg); |
| 2051 | clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER); |
| 2052 | clk_writel(*ctx++, tegra_clk_pclk.reg); |
| 2053 | |
Colin Cross | 71fc84c | 2010-06-07 20:49:46 -0700 | [diff] [blame] | 2054 | /* enable all clocks before configuring clock sources */ |
| 2055 | clk_writel(0xbffffff9ul, CLK_OUT_ENB); |
| 2056 | clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4); |
| 2057 | clk_writel(0x77f01bfful, CLK_OUT_ENB + 8); |
| 2058 | wmb(); |
| 2059 | |
| 2060 | for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC; |
| 2061 | off += 4) { |
| 2062 | if (off == PERIPH_CLK_SOURCE_EMC) |
| 2063 | continue; |
| 2064 | clk_writel(*ctx++, off); |
| 2065 | } |
| 2066 | wmb(); |
| 2067 | |
| 2068 | off = RST_DEVICES; |
| 2069 | for (i = 0; i < RST_DEVICES_NUM; i++, off += 4) |
| 2070 | clk_writel(*ctx++, off); |
| 2071 | wmb(); |
| 2072 | |
| 2073 | off = CLK_OUT_ENB; |
| 2074 | for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4) |
| 2075 | clk_writel(*ctx++, off); |
| 2076 | wmb(); |
| 2077 | |
| 2078 | clk_writel(*ctx++, MISC_CLK_ENB); |
| 2079 | clk_writel(*ctx++, CLK_MASK_ARM); |
| 2080 | } |
| 2081 | #endif |