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