blob: 59e77ba9580231d2cd6993e1f752263694950339 [file] [log] [blame]
Colin Crossd8611962010-01-28 16:40:29 -08001/*
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>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010026#include <linux/clkdev.h>
Colin Cross4729fd72011-02-12 16:43:05 -080027#include <linux/clk.h>
Colin Crossd8611962010-01-28 16:40:29 -080028
29#include <mach/iomap.h>
Colin Cross2ea67fd2010-10-04 08:49:49 -070030#include <mach/suspend.h>
Colin Crossd8611962010-01-28 16:40:29 -080031
32#include "clock.h"
Colin Cross71fc84c2010-06-07 20:49:46 -070033#include "fuse.h"
Colin Cross6d296822010-11-22 18:37:54 -080034#include "tegra2_emc.h"
Colin Crossd8611962010-01-28 16:40:29 -080035
36#define RST_DEVICES 0x004
37#define RST_DEVICES_SET 0x300
38#define RST_DEVICES_CLR 0x304
Colin Cross71fc84c2010-06-07 20:49:46 -070039#define RST_DEVICES_NUM 3
Colin Crossd8611962010-01-28 16:40:29 -080040
41#define CLK_OUT_ENB 0x010
42#define CLK_OUT_ENB_SET 0x320
43#define CLK_OUT_ENB_CLR 0x324
Colin Cross71fc84c2010-06-07 20:49:46 -070044#define CLK_OUT_ENB_NUM 3
45
46#define CLK_MASK_ARM 0x44
47#define MISC_CLK_ENB 0x48
Colin Crossd8611962010-01-28 16:40:29 -080048
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 Crosscea62c82010-10-04 11:49:26 -070055#define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
Colin Crossd8611962010-01-28 16:40:29 -080056
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 Cross71fc84c2010-06-07 20:49:46 -070064#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 Crossd8611962010-01-28 16:40:29 -080070#define PERIPH_CLK_SOURCE_MASK (3<<30)
71#define PERIPH_CLK_SOURCE_SHIFT 30
72#define PERIPH_CLK_SOURCE_ENABLE (1<<28)
Colin Cross71fc84c2010-06-07 20:49:46 -070073#define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
74#define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
Colin Crossd8611962010-01-28 16:40:29 -080075#define PERIPH_CLK_SOURCE_DIV_SHIFT 0
76
Colin Cross9743b382011-02-12 18:24:32 -080077#define SDMMC_CLK_INT_FB_SEL (1 << 23)
78#define SDMMC_CLK_INT_FB_DLY_SHIFT 16
79#define SDMMC_CLK_INT_FB_DLY_MASK (0xF << SDMMC_CLK_INT_FB_DLY_SHIFT)
80
Colin Crossd8611962010-01-28 16:40:29 -080081#define PLL_BASE 0x0
82#define PLL_BASE_BYPASS (1<<31)
83#define PLL_BASE_ENABLE (1<<30)
84#define PLL_BASE_REF_ENABLE (1<<29)
85#define PLL_BASE_OVERRIDE (1<<28)
Colin Crossd8611962010-01-28 16:40:29 -080086#define PLL_BASE_DIVP_MASK (0x7<<20)
87#define PLL_BASE_DIVP_SHIFT 20
88#define PLL_BASE_DIVN_MASK (0x3FF<<8)
89#define PLL_BASE_DIVN_SHIFT 8
90#define PLL_BASE_DIVM_MASK (0x1F)
91#define PLL_BASE_DIVM_SHIFT 0
92
93#define PLL_OUT_RATIO_MASK (0xFF<<8)
94#define PLL_OUT_RATIO_SHIFT 8
95#define PLL_OUT_OVERRIDE (1<<2)
96#define PLL_OUT_CLKEN (1<<1)
97#define PLL_OUT_RESET_DISABLE (1<<0)
98
99#define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
Colin Cross71fc84c2010-06-07 20:49:46 -0700100
Colin Crossd8611962010-01-28 16:40:29 -0800101#define PLL_MISC_DCCON_SHIFT 20
Colin Crossd8611962010-01-28 16:40:29 -0800102#define PLL_MISC_CPCON_SHIFT 8
103#define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
104#define PLL_MISC_LFCON_SHIFT 4
105#define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
106#define PLL_MISC_VCOCON_SHIFT 0
107#define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
108
Colin Cross71fc84c2010-06-07 20:49:46 -0700109#define PLLU_BASE_POST_DIV (1<<20)
110
Colin Crossd8611962010-01-28 16:40:29 -0800111#define PLLD_MISC_CLKENABLE (1<<30)
112#define PLLD_MISC_DIV_RST (1<<23)
113#define PLLD_MISC_DCCON_SHIFT 12
114
Mike Rapoport8d685bc2010-09-27 11:26:32 +0200115#define PLLE_MISC_READY (1 << 15)
116
Colin Crossf1519612011-02-12 16:05:31 -0800117#define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
118#define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
119#define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
Colin Crossd8611962010-01-28 16:40:29 -0800120
121#define SUPER_CLK_MUX 0x00
122#define SUPER_STATE_SHIFT 28
123#define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
124#define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
125#define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
126#define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
127#define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
128#define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
129#define SUPER_SOURCE_MASK 0xF
130#define SUPER_FIQ_SOURCE_SHIFT 12
131#define SUPER_IRQ_SOURCE_SHIFT 8
132#define SUPER_RUN_SOURCE_SHIFT 4
133#define SUPER_IDLE_SOURCE_SHIFT 0
134
135#define SUPER_CLK_DIVIDER 0x04
136
137#define BUS_CLK_DISABLE (1<<3)
138#define BUS_CLK_DIV_MASK 0x3
139
Colin Crosscea62c82010-10-04 11:49:26 -0700140#define PMC_CTRL 0x0
141 #define PMC_CTRL_BLINK_ENB (1 << 7)
142
143#define PMC_DPD_PADS_ORIDE 0x1c
144 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
145
146#define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
147#define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
148#define PMC_BLINK_TIMER_ENB (1 << 15)
149#define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
150#define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
151
Colin Crossd8611962010-01-28 16:40:29 -0800152static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
Colin Crosscea62c82010-10-04 11:49:26 -0700153static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
Colin Crossd8611962010-01-28 16:40:29 -0800154
Colin Cross4729fd72011-02-12 16:43:05 -0800155/*
156 * Some clocks share a register with other clocks. Any clock op that
157 * non-atomically modifies a register used by another clock must lock
158 * clock_register_lock first.
159 */
160static DEFINE_SPINLOCK(clock_register_lock);
161
Colin Crossd8611962010-01-28 16:40:29 -0800162#define clk_writel(value, reg) \
163 __raw_writel(value, (u32)reg_clk_base + (reg))
164#define clk_readl(reg) \
165 __raw_readl((u32)reg_clk_base + (reg))
Colin Crosscea62c82010-10-04 11:49:26 -0700166#define pmc_writel(value, reg) \
167 __raw_writel(value, (u32)reg_pmc_base + (reg))
168#define pmc_readl(reg) \
169 __raw_readl((u32)reg_pmc_base + (reg))
Colin Crossd8611962010-01-28 16:40:29 -0800170
171unsigned long clk_measure_input_freq(void)
172{
173 u32 clock_autodetect;
174 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
175 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
176 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
177 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
178 return 12000000;
179 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
180 return 13000000;
181 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
182 return 19200000;
183 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
184 return 26000000;
185 } else {
186 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
187 BUG();
188 return 0;
189 }
190}
191
Colin Cross71fc84c2010-06-07 20:49:46 -0700192static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
Colin Crossd8611962010-01-28 16:40:29 -0800193{
Colin Cross71fc84c2010-06-07 20:49:46 -0700194 s64 divider_u71 = parent_rate * 2;
195 divider_u71 += rate - 1;
196 do_div(divider_u71, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800197
Colin Cross71fc84c2010-06-07 20:49:46 -0700198 if (divider_u71 - 2 < 0)
199 return 0;
Colin Crossd8611962010-01-28 16:40:29 -0800200
Colin Cross71fc84c2010-06-07 20:49:46 -0700201 if (divider_u71 - 2 > 255)
Colin Crossd8611962010-01-28 16:40:29 -0800202 return -EINVAL;
203
204 return divider_u71 - 2;
205}
206
Colin Cross71fc84c2010-06-07 20:49:46 -0700207static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
Colin Crossd8611962010-01-28 16:40:29 -0800208{
Colin Cross71fc84c2010-06-07 20:49:46 -0700209 s64 divider_u16;
Colin Crossd8611962010-01-28 16:40:29 -0800210
Colin Cross71fc84c2010-06-07 20:49:46 -0700211 divider_u16 = parent_rate;
212 divider_u16 += rate - 1;
213 do_div(divider_u16, rate);
214
215 if (divider_u16 - 1 < 0)
216 return 0;
217
218 if (divider_u16 - 1 > 255)
219 return -EINVAL;
220
221 return divider_u16 - 1;
Colin Crossd8611962010-01-28 16:40:29 -0800222}
223
Colin Crossd8611962010-01-28 16:40:29 -0800224/* clk_m functions */
225static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
226{
227 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
228
229 c->rate = clk_measure_input_freq();
230 switch (c->rate) {
231 case 12000000:
232 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
233 break;
234 case 13000000:
235 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
236 break;
237 case 19200000:
238 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
239 break;
240 case 26000000:
241 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
242 break;
243 default:
244 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
245 BUG();
246 }
247 clk_writel(auto_clock_control, OSC_CTRL);
248 return c->rate;
249}
250
251static void tegra2_clk_m_init(struct clk *c)
252{
253 pr_debug("%s on clock %s\n", __func__, c->name);
254 tegra2_clk_m_autodetect_rate(c);
255}
256
257static int tegra2_clk_m_enable(struct clk *c)
258{
259 pr_debug("%s on clock %s\n", __func__, c->name);
260 return 0;
261}
262
263static void tegra2_clk_m_disable(struct clk *c)
264{
265 pr_debug("%s on clock %s\n", __func__, c->name);
266 BUG();
267}
268
269static struct clk_ops tegra_clk_m_ops = {
270 .init = tegra2_clk_m_init,
271 .enable = tegra2_clk_m_enable,
272 .disable = tegra2_clk_m_disable,
273};
274
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700275void tegra2_periph_reset_assert(struct clk *c)
276{
277 BUG_ON(!c->ops->reset);
278 c->ops->reset(c, true);
279}
280
281void tegra2_periph_reset_deassert(struct clk *c)
282{
283 BUG_ON(!c->ops->reset);
284 c->ops->reset(c, false);
285}
286
Colin Crossd8611962010-01-28 16:40:29 -0800287/* super clock functions */
288/* "super clocks" on tegra have two-stage muxes and a clock skipping
289 * super divider. We will ignore the clock skipping divider, since we
290 * can't lower the voltage when using the clock skip, but we can if we
291 * lower the PLL frequency.
292 */
293static void tegra2_super_clk_init(struct clk *c)
294{
295 u32 val;
296 int source;
297 int shift;
298 const struct clk_mux_sel *sel;
299 val = clk_readl(c->reg + SUPER_CLK_MUX);
300 c->state = ON;
301 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
302 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
303 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
304 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
305 source = (val >> shift) & SUPER_SOURCE_MASK;
306 for (sel = c->inputs; sel->input != NULL; sel++) {
307 if (sel->value == source)
308 break;
309 }
310 BUG_ON(sel->input == NULL);
311 c->parent = sel->input;
Colin Crossd8611962010-01-28 16:40:29 -0800312}
313
314static int tegra2_super_clk_enable(struct clk *c)
315{
316 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
317 return 0;
318}
319
320static void tegra2_super_clk_disable(struct clk *c)
321{
322 pr_debug("%s on clock %s\n", __func__, c->name);
323
324 /* oops - don't disable the CPU clock! */
325 BUG();
326}
327
328static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
329{
330 u32 val;
331 const struct clk_mux_sel *sel;
332 int shift;
Colin Cross71fc84c2010-06-07 20:49:46 -0700333
Colin Crossd8611962010-01-28 16:40:29 -0800334 val = clk_readl(c->reg + SUPER_CLK_MUX);;
335 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
336 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
337 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
338 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
339 for (sel = c->inputs; sel->input != NULL; sel++) {
340 if (sel->input == p) {
Colin Crossd8611962010-01-28 16:40:29 -0800341 val &= ~(SUPER_SOURCE_MASK << shift);
342 val |= sel->value << shift;
Colin Cross71fc84c2010-06-07 20:49:46 -0700343
344 if (c->refcnt)
Colin Cross4729fd72011-02-12 16:43:05 -0800345 clk_enable(p);
Colin Cross71fc84c2010-06-07 20:49:46 -0700346
Colin Crossd8611962010-01-28 16:40:29 -0800347 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -0700348
349 if (c->refcnt && c->parent)
Colin Cross4729fd72011-02-12 16:43:05 -0800350 clk_disable(c->parent);
Colin Cross71fc84c2010-06-07 20:49:46 -0700351
352 clk_reparent(c, p);
Colin Crossd8611962010-01-28 16:40:29 -0800353 return 0;
354 }
355 }
356 return -EINVAL;
357}
358
Colin Cross9c7dc562011-02-12 21:25:23 -0800359/*
360 * Super clocks have "clock skippers" instead of dividers. Dividing using
361 * a clock skipper does not allow the voltage to be scaled down, so instead
362 * adjust the rate of the parent clock. This requires that the parent of a
363 * super clock have no other children, otherwise the rate will change
364 * underneath the other children.
365 */
366static int tegra2_super_clk_set_rate(struct clk *c, unsigned long rate)
367{
368 return clk_set_rate(c->parent, rate);
369}
370
Colin Crossd8611962010-01-28 16:40:29 -0800371static struct clk_ops tegra_super_ops = {
372 .init = tegra2_super_clk_init,
373 .enable = tegra2_super_clk_enable,
374 .disable = tegra2_super_clk_disable,
375 .set_parent = tegra2_super_clk_set_parent,
Colin Cross9c7dc562011-02-12 21:25:23 -0800376 .set_rate = tegra2_super_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700377};
378
379/* virtual cpu clock functions */
380/* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
381 To change the frequency of these clocks, the parent pll may need to be
382 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
383 and then the clock moved back to the pll. To hide this sequence, a virtual
384 clock handles it.
385 */
386static void tegra2_cpu_clk_init(struct clk *c)
387{
388}
389
390static int tegra2_cpu_clk_enable(struct clk *c)
391{
392 return 0;
393}
394
395static void tegra2_cpu_clk_disable(struct clk *c)
396{
397 pr_debug("%s on clock %s\n", __func__, c->name);
398
399 /* oops - don't disable the CPU clock! */
400 BUG();
401}
402
403static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
404{
405 int ret;
Colin Cross89a5fb82010-10-20 17:47:59 -0700406 /*
407 * Take an extra reference to the main pll so it doesn't turn
408 * off when we move the cpu off of it
409 */
410 clk_enable(c->u.cpu.main);
411
Colin Cross4729fd72011-02-12 16:43:05 -0800412 ret = clk_set_parent(c->parent, c->u.cpu.backup);
Colin Cross71fc84c2010-06-07 20:49:46 -0700413 if (ret) {
Colin Crossf1519612011-02-12 16:05:31 -0800414 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
Colin Cross89a5fb82010-10-20 17:47:59 -0700415 goto out;
Colin Cross71fc84c2010-06-07 20:49:46 -0700416 }
417
Colin Cross4729fd72011-02-12 16:43:05 -0800418 if (rate == clk_get_rate(c->u.cpu.backup))
Colin Crosscea62c82010-10-04 11:49:26 -0700419 goto out;
420
Colin Cross4729fd72011-02-12 16:43:05 -0800421 ret = clk_set_rate(c->u.cpu.main, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -0700422 if (ret) {
423 pr_err("Failed to change cpu pll to %lu\n", rate);
Colin Cross89a5fb82010-10-20 17:47:59 -0700424 goto out;
Colin Cross71fc84c2010-06-07 20:49:46 -0700425 }
426
Colin Cross4729fd72011-02-12 16:43:05 -0800427 ret = clk_set_parent(c->parent, c->u.cpu.main);
Colin Cross71fc84c2010-06-07 20:49:46 -0700428 if (ret) {
Colin Crossf1519612011-02-12 16:05:31 -0800429 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
Colin Cross89a5fb82010-10-20 17:47:59 -0700430 goto out;
Colin Cross71fc84c2010-06-07 20:49:46 -0700431 }
432
Colin Crosscea62c82010-10-04 11:49:26 -0700433out:
Colin Cross89a5fb82010-10-20 17:47:59 -0700434 clk_disable(c->u.cpu.main);
435 return ret;
Colin Cross71fc84c2010-06-07 20:49:46 -0700436}
437
438static struct clk_ops tegra_cpu_ops = {
439 .init = tegra2_cpu_clk_init,
440 .enable = tegra2_cpu_clk_enable,
441 .disable = tegra2_cpu_clk_disable,
442 .set_rate = tegra2_cpu_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800443};
444
Colin Cross9c7dc562011-02-12 21:25:23 -0800445/* virtual cop clock functions. Used to acquire the fake 'cop' clock to
446 * reset the COP block (i.e. AVP) */
447static void tegra2_cop_clk_reset(struct clk *c, bool assert)
448{
449 unsigned long reg = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
450
451 pr_debug("%s %s\n", __func__, assert ? "assert" : "deassert");
452 clk_writel(1 << 1, reg);
453}
454
455static struct clk_ops tegra_cop_ops = {
456 .reset = tegra2_cop_clk_reset,
457};
458
Colin Crossd8611962010-01-28 16:40:29 -0800459/* bus clock functions */
460static void tegra2_bus_clk_init(struct clk *c)
461{
462 u32 val = clk_readl(c->reg);
463 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
464 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
465 c->mul = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800466}
467
468static int tegra2_bus_clk_enable(struct clk *c)
469{
Colin Cross4729fd72011-02-12 16:43:05 -0800470 u32 val;
471 unsigned long flags;
472
473 spin_lock_irqsave(&clock_register_lock, flags);
474
475 val = clk_readl(c->reg);
Colin Crossd8611962010-01-28 16:40:29 -0800476 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
477 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800478
479 spin_unlock_irqrestore(&clock_register_lock, flags);
480
Colin Crossd8611962010-01-28 16:40:29 -0800481 return 0;
482}
483
484static void tegra2_bus_clk_disable(struct clk *c)
485{
Colin Cross4729fd72011-02-12 16:43:05 -0800486 u32 val;
487 unsigned long flags;
488
489 spin_lock_irqsave(&clock_register_lock, flags);
490
491 val = clk_readl(c->reg);
Colin Crossd8611962010-01-28 16:40:29 -0800492 val |= BUS_CLK_DISABLE << c->reg_shift;
493 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800494
495 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800496}
497
498static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
499{
Colin Cross4729fd72011-02-12 16:43:05 -0800500 u32 val;
501 unsigned long parent_rate = clk_get_rate(c->parent);
502 unsigned long flags;
503 int ret = -EINVAL;
Colin Crossd8611962010-01-28 16:40:29 -0800504 int i;
Colin Cross4729fd72011-02-12 16:43:05 -0800505
506 spin_lock_irqsave(&clock_register_lock, flags);
507
508 val = clk_readl(c->reg);
Colin Crossd8611962010-01-28 16:40:29 -0800509 for (i = 1; i <= 4; i++) {
510 if (rate == parent_rate / i) {
511 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
512 val |= (i - 1) << c->reg_shift;
513 clk_writel(val, c->reg);
514 c->div = i;
515 c->mul = 1;
Colin Cross4729fd72011-02-12 16:43:05 -0800516 ret = 0;
517 break;
Colin Crossd8611962010-01-28 16:40:29 -0800518 }
519 }
Colin Cross4729fd72011-02-12 16:43:05 -0800520
521 spin_unlock_irqrestore(&clock_register_lock, flags);
522
523 return ret;
Colin Crossd8611962010-01-28 16:40:29 -0800524}
525
526static struct clk_ops tegra_bus_ops = {
527 .init = tegra2_bus_clk_init,
528 .enable = tegra2_bus_clk_enable,
529 .disable = tegra2_bus_clk_disable,
530 .set_rate = tegra2_bus_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800531};
532
Colin Crosscea62c82010-10-04 11:49:26 -0700533/* Blink output functions */
534
535static void tegra2_blink_clk_init(struct clk *c)
536{
537 u32 val;
538
539 val = pmc_readl(PMC_CTRL);
540 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
541 c->mul = 1;
542 val = pmc_readl(c->reg);
543
544 if (val & PMC_BLINK_TIMER_ENB) {
545 unsigned int on_off;
546
547 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
548 PMC_BLINK_TIMER_DATA_ON_MASK;
549 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
550 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
551 on_off += val;
552 /* each tick in the blink timer is 4 32KHz clocks */
553 c->div = on_off * 4;
554 } else {
555 c->div = 1;
556 }
557}
558
559static int tegra2_blink_clk_enable(struct clk *c)
560{
561 u32 val;
562
563 val = pmc_readl(PMC_DPD_PADS_ORIDE);
564 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
565
566 val = pmc_readl(PMC_CTRL);
567 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
568
569 return 0;
570}
571
572static void tegra2_blink_clk_disable(struct clk *c)
573{
574 u32 val;
575
576 val = pmc_readl(PMC_CTRL);
577 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
578
579 val = pmc_readl(PMC_DPD_PADS_ORIDE);
580 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
581}
582
583static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
584{
Colin Cross4729fd72011-02-12 16:43:05 -0800585 unsigned long parent_rate = clk_get_rate(c->parent);
586 if (rate >= parent_rate) {
Colin Crosscea62c82010-10-04 11:49:26 -0700587 c->div = 1;
588 pmc_writel(0, c->reg);
589 } else {
590 unsigned int on_off;
591 u32 val;
592
Colin Cross4729fd72011-02-12 16:43:05 -0800593 on_off = DIV_ROUND_UP(parent_rate / 8, rate);
Colin Crosscea62c82010-10-04 11:49:26 -0700594 c->div = on_off * 8;
595
596 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
597 PMC_BLINK_TIMER_DATA_ON_SHIFT;
598 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
599 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
600 val |= on_off;
601 val |= PMC_BLINK_TIMER_ENB;
602 pmc_writel(val, c->reg);
603 }
604
605 return 0;
606}
607
608static struct clk_ops tegra_blink_clk_ops = {
609 .init = &tegra2_blink_clk_init,
610 .enable = &tegra2_blink_clk_enable,
611 .disable = &tegra2_blink_clk_disable,
612 .set_rate = &tegra2_blink_clk_set_rate,
613};
614
Colin Crossd8611962010-01-28 16:40:29 -0800615/* PLL Functions */
Colin Crossd8611962010-01-28 16:40:29 -0800616static int tegra2_pll_clk_wait_for_lock(struct clk *c)
617{
Colin Crossf1519612011-02-12 16:05:31 -0800618 udelay(c->u.pll.lock_delay);
Colin Crossd8611962010-01-28 16:40:29 -0800619
620 return 0;
621}
622
623static void tegra2_pll_clk_init(struct clk *c)
624{
625 u32 val = clk_readl(c->reg + PLL_BASE);
626
627 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
628
629 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
630 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
Colin Cross71fc84c2010-06-07 20:49:46 -0700631 c->mul = 1;
632 c->div = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800633 } else if (val & PLL_BASE_BYPASS) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700634 c->mul = 1;
635 c->div = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800636 } else {
Colin Cross71fc84c2010-06-07 20:49:46 -0700637 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
638 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
639 if (c->flags & PLLU)
640 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
641 else
642 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
Colin Crossd8611962010-01-28 16:40:29 -0800643 }
Colin Crossd8611962010-01-28 16:40:29 -0800644}
645
646static int tegra2_pll_clk_enable(struct clk *c)
647{
648 u32 val;
649 pr_debug("%s on clock %s\n", __func__, c->name);
650
651 val = clk_readl(c->reg + PLL_BASE);
652 val &= ~PLL_BASE_BYPASS;
653 val |= PLL_BASE_ENABLE;
654 clk_writel(val, c->reg + PLL_BASE);
655
Colin Crossd8611962010-01-28 16:40:29 -0800656 tegra2_pll_clk_wait_for_lock(c);
657
658 return 0;
659}
660
661static void tegra2_pll_clk_disable(struct clk *c)
662{
663 u32 val;
664 pr_debug("%s on clock %s\n", __func__, c->name);
665
666 val = clk_readl(c->reg);
667 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
668 clk_writel(val, c->reg);
669}
670
671static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
672{
673 u32 val;
674 unsigned long input_rate;
Colin Crossf1519612011-02-12 16:05:31 -0800675 const struct clk_pll_freq_table *sel;
Colin Crossd8611962010-01-28 16:40:29 -0800676
677 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800678
Colin Cross4729fd72011-02-12 16:43:05 -0800679 input_rate = clk_get_rate(c->parent);
Colin Crossf1519612011-02-12 16:05:31 -0800680 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
Colin Crossd8611962010-01-28 16:40:29 -0800681 if (sel->input_rate == input_rate && sel->output_rate == rate) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700682 c->mul = sel->n;
683 c->div = sel->m * sel->p;
Colin Crossd8611962010-01-28 16:40:29 -0800684
685 val = clk_readl(c->reg + PLL_BASE);
686 if (c->flags & PLL_FIXED)
687 val |= PLL_BASE_OVERRIDE;
688 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
689 PLL_BASE_DIVM_MASK);
Colin Cross71fc84c2010-06-07 20:49:46 -0700690 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
691 (sel->n << PLL_BASE_DIVN_SHIFT);
692 BUG_ON(sel->p < 1 || sel->p > 2);
693 if (c->flags & PLLU) {
694 if (sel->p == 1)
695 val |= PLLU_BASE_POST_DIV;
696 } else {
697 if (sel->p == 2)
698 val |= 1 << PLL_BASE_DIVP_SHIFT;
699 }
Colin Crossd8611962010-01-28 16:40:29 -0800700 clk_writel(val, c->reg + PLL_BASE);
701
702 if (c->flags & PLL_HAS_CPCON) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700703 val = clk_readl(c->reg + PLL_MISC(c));
704 val &= ~PLL_MISC_CPCON_MASK;
705 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
Colin Crossd8611962010-01-28 16:40:29 -0800706 clk_writel(val, c->reg + PLL_MISC(c));
707 }
708
709 if (c->state == ON)
710 tegra2_pll_clk_enable(c);
711
Colin Crossd8611962010-01-28 16:40:29 -0800712 return 0;
713 }
714 }
715 return -EINVAL;
716}
717
718static struct clk_ops tegra_pll_ops = {
719 .init = tegra2_pll_clk_init,
720 .enable = tegra2_pll_clk_enable,
721 .disable = tegra2_pll_clk_disable,
722 .set_rate = tegra2_pll_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700723};
724
725static void tegra2_pllx_clk_init(struct clk *c)
726{
727 tegra2_pll_clk_init(c);
728
729 if (tegra_sku_id() == 7)
730 c->max_rate = 750000000;
731}
732
733static struct clk_ops tegra_pllx_ops = {
734 .init = tegra2_pllx_clk_init,
735 .enable = tegra2_pll_clk_enable,
736 .disable = tegra2_pll_clk_disable,
737 .set_rate = tegra2_pll_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800738};
739
Mike Rapoport8d685bc2010-09-27 11:26:32 +0200740static int tegra2_plle_clk_enable(struct clk *c)
741{
742 u32 val;
743
744 pr_debug("%s on clock %s\n", __func__, c->name);
745
746 mdelay(1);
747
748 val = clk_readl(c->reg + PLL_BASE);
749 if (!(val & PLLE_MISC_READY))
750 return -EBUSY;
751
752 val = clk_readl(c->reg + PLL_BASE);
753 val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS;
754 clk_writel(val, c->reg + PLL_BASE);
755
756 return 0;
757}
758
759static struct clk_ops tegra_plle_ops = {
760 .init = tegra2_pll_clk_init,
761 .enable = tegra2_plle_clk_enable,
762 .set_rate = tegra2_pll_clk_set_rate,
763};
764
Colin Crossd8611962010-01-28 16:40:29 -0800765/* Clock divider ops */
766static void tegra2_pll_div_clk_init(struct clk *c)
767{
768 u32 val = clk_readl(c->reg);
769 u32 divu71;
770 val >>= c->reg_shift;
771 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
772 if (!(val & PLL_OUT_RESET_DISABLE))
773 c->state = OFF;
774
775 if (c->flags & DIV_U71) {
776 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
777 c->div = (divu71 + 2);
778 c->mul = 2;
779 } else if (c->flags & DIV_2) {
780 c->div = 2;
781 c->mul = 1;
782 } else {
783 c->div = 1;
784 c->mul = 1;
785 }
Colin Crossd8611962010-01-28 16:40:29 -0800786}
787
788static int tegra2_pll_div_clk_enable(struct clk *c)
789{
790 u32 val;
791 u32 new_val;
Colin Cross4729fd72011-02-12 16:43:05 -0800792 unsigned long flags;
Colin Crossd8611962010-01-28 16:40:29 -0800793
794 pr_debug("%s: %s\n", __func__, c->name);
795 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -0800796 spin_lock_irqsave(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800797 val = clk_readl(c->reg);
798 new_val = val >> c->reg_shift;
799 new_val &= 0xFFFF;
800
801 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
802
803 val &= ~(0xFFFF << c->reg_shift);
804 val |= new_val << c->reg_shift;
805 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800806 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800807 return 0;
808 } else if (c->flags & DIV_2) {
809 BUG_ON(!(c->flags & PLLD));
Colin Cross4729fd72011-02-12 16:43:05 -0800810 spin_lock_irqsave(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800811 val = clk_readl(c->reg);
812 val &= ~PLLD_MISC_DIV_RST;
813 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800814 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800815 return 0;
816 }
817 return -EINVAL;
818}
819
820static void tegra2_pll_div_clk_disable(struct clk *c)
821{
822 u32 val;
823 u32 new_val;
Colin Cross4729fd72011-02-12 16:43:05 -0800824 unsigned long flags;
Colin Crossd8611962010-01-28 16:40:29 -0800825
826 pr_debug("%s: %s\n", __func__, c->name);
827 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -0800828 spin_lock_irqsave(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800829 val = clk_readl(c->reg);
830 new_val = val >> c->reg_shift;
831 new_val &= 0xFFFF;
832
833 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
834
835 val &= ~(0xFFFF << c->reg_shift);
836 val |= new_val << c->reg_shift;
837 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800838 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800839 } else if (c->flags & DIV_2) {
840 BUG_ON(!(c->flags & PLLD));
Colin Cross4729fd72011-02-12 16:43:05 -0800841 spin_lock_irqsave(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800842 val = clk_readl(c->reg);
843 val |= PLLD_MISC_DIV_RST;
844 clk_writel(val, c->reg);
Colin Cross4729fd72011-02-12 16:43:05 -0800845 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800846 }
847}
848
849static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
850{
851 u32 val;
852 u32 new_val;
853 int divider_u71;
Colin Cross4729fd72011-02-12 16:43:05 -0800854 unsigned long parent_rate = clk_get_rate(c->parent);
855 unsigned long flags;
856
Colin Crossd8611962010-01-28 16:40:29 -0800857 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
858 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -0800859 divider_u71 = clk_div71_get_divider(parent_rate, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800860 if (divider_u71 >= 0) {
Colin Cross4729fd72011-02-12 16:43:05 -0800861 spin_lock_irqsave(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800862 val = clk_readl(c->reg);
863 new_val = val >> c->reg_shift;
864 new_val &= 0xFFFF;
865 if (c->flags & DIV_U71_FIXED)
866 new_val |= PLL_OUT_OVERRIDE;
867 new_val &= ~PLL_OUT_RATIO_MASK;
868 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
869
870 val &= ~(0xFFFF << c->reg_shift);
871 val |= new_val << c->reg_shift;
872 clk_writel(val, c->reg);
873 c->div = divider_u71 + 2;
874 c->mul = 2;
Colin Cross4729fd72011-02-12 16:43:05 -0800875 spin_unlock_irqrestore(&clock_register_lock, flags);
Colin Crossd8611962010-01-28 16:40:29 -0800876 return 0;
877 }
878 } else if (c->flags & DIV_2) {
Colin Cross4729fd72011-02-12 16:43:05 -0800879 if (parent_rate == rate * 2)
Colin Crossd8611962010-01-28 16:40:29 -0800880 return 0;
Colin Crossd8611962010-01-28 16:40:29 -0800881 }
882 return -EINVAL;
883}
884
Colin Cross71fc84c2010-06-07 20:49:46 -0700885static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
886{
887 int divider;
Colin Cross4729fd72011-02-12 16:43:05 -0800888 unsigned long parent_rate = clk_get_rate(c->parent);
Colin Cross71fc84c2010-06-07 20:49:46 -0700889 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
890
891 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -0800892 divider = clk_div71_get_divider(parent_rate, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -0700893 if (divider < 0)
894 return divider;
Colin Cross4729fd72011-02-12 16:43:05 -0800895 return parent_rate * 2 / (divider + 2);
Colin Cross71fc84c2010-06-07 20:49:46 -0700896 } else if (c->flags & DIV_2) {
Colin Cross4729fd72011-02-12 16:43:05 -0800897 return parent_rate / 2;
Colin Cross71fc84c2010-06-07 20:49:46 -0700898 }
899 return -EINVAL;
900}
Colin Crossd8611962010-01-28 16:40:29 -0800901
902static struct clk_ops tegra_pll_div_ops = {
903 .init = tegra2_pll_div_clk_init,
904 .enable = tegra2_pll_div_clk_enable,
905 .disable = tegra2_pll_div_clk_disable,
906 .set_rate = tegra2_pll_div_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700907 .round_rate = tegra2_pll_div_clk_round_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800908};
909
910/* Periph clk ops */
911
912static void tegra2_periph_clk_init(struct clk *c)
913{
914 u32 val = clk_readl(c->reg);
915 const struct clk_mux_sel *mux = 0;
916 const struct clk_mux_sel *sel;
917 if (c->flags & MUX) {
918 for (sel = c->inputs; sel->input != NULL; sel++) {
919 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
920 mux = sel;
921 }
922 BUG_ON(!mux);
923
924 c->parent = mux->input;
925 } else {
926 c->parent = c->inputs[0].input;
927 }
928
929 if (c->flags & DIV_U71) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700930 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
Colin Crossd8611962010-01-28 16:40:29 -0800931 c->div = divu71 + 2;
932 c->mul = 2;
Colin Cross71fc84c2010-06-07 20:49:46 -0700933 } else if (c->flags & DIV_U16) {
934 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
935 c->div = divu16 + 1;
936 c->mul = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800937 } else {
938 c->div = 1;
939 c->mul = 1;
940 }
941
942 c->state = ON;
943 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
944 PERIPH_CLK_TO_ENB_BIT(c)))
945 c->state = OFF;
946 if (!(c->flags & PERIPH_NO_RESET))
947 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
948 PERIPH_CLK_TO_ENB_BIT(c))
949 c->state = OFF;
Colin Crossd8611962010-01-28 16:40:29 -0800950}
951
952static int tegra2_periph_clk_enable(struct clk *c)
953{
954 u32 val;
955 pr_debug("%s on clock %s\n", __func__, c->name);
956
957 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
958 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
959 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
960 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
961 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
962 if (c->flags & PERIPH_EMC_ENB) {
963 /* The EMC peripheral clock has 2 extra enable bits */
964 /* FIXME: Do they need to be disabled? */
965 val = clk_readl(c->reg);
966 val |= 0x3 << 24;
967 clk_writel(val, c->reg);
968 }
969 return 0;
970}
971
972static void tegra2_periph_clk_disable(struct clk *c)
973{
974 pr_debug("%s on clock %s\n", __func__, c->name);
975
976 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
977 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
978}
979
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700980static void tegra2_periph_clk_reset(struct clk *c, bool assert)
Colin Crossd8611962010-01-28 16:40:29 -0800981{
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700982 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
983
984 pr_debug("%s %s on clock %s\n", __func__,
985 assert ? "assert" : "deassert", c->name);
Colin Crossd8611962010-01-28 16:40:29 -0800986 if (!(c->flags & PERIPH_NO_RESET))
987 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700988 base + PERIPH_CLK_TO_ENB_SET_REG(c));
Colin Crossd8611962010-01-28 16:40:29 -0800989}
990
Colin Crossd8611962010-01-28 16:40:29 -0800991static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
992{
993 u32 val;
994 const struct clk_mux_sel *sel;
995 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
996 for (sel = c->inputs; sel->input != NULL; sel++) {
997 if (sel->input == p) {
Colin Crossd8611962010-01-28 16:40:29 -0800998 val = clk_readl(c->reg);
999 val &= ~PERIPH_CLK_SOURCE_MASK;
1000 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
Colin Cross71fc84c2010-06-07 20:49:46 -07001001
1002 if (c->refcnt)
Colin Cross4729fd72011-02-12 16:43:05 -08001003 clk_enable(p);
Colin Cross71fc84c2010-06-07 20:49:46 -07001004
Colin Crossd8611962010-01-28 16:40:29 -08001005 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -07001006
1007 if (c->refcnt && c->parent)
Colin Cross4729fd72011-02-12 16:43:05 -08001008 clk_disable(c->parent);
Colin Cross71fc84c2010-06-07 20:49:46 -07001009
1010 clk_reparent(c, p);
Colin Crossd8611962010-01-28 16:40:29 -08001011 return 0;
1012 }
1013 }
1014
1015 return -EINVAL;
1016}
1017
1018static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
1019{
1020 u32 val;
Colin Cross71fc84c2010-06-07 20:49:46 -07001021 int divider;
Colin Cross4729fd72011-02-12 16:43:05 -08001022 unsigned long parent_rate = clk_get_rate(c->parent);
1023
Colin Crossd8611962010-01-28 16:40:29 -08001024 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -08001025 divider = clk_div71_get_divider(parent_rate, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -07001026 if (divider >= 0) {
Colin Crossd8611962010-01-28 16:40:29 -08001027 val = clk_readl(c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -07001028 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
1029 val |= divider;
Colin Crossd8611962010-01-28 16:40:29 -08001030 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -07001031 c->div = divider + 2;
Colin Crossd8611962010-01-28 16:40:29 -08001032 c->mul = 2;
Colin Crossd8611962010-01-28 16:40:29 -08001033 return 0;
1034 }
Colin Cross71fc84c2010-06-07 20:49:46 -07001035 } else if (c->flags & DIV_U16) {
Colin Cross4729fd72011-02-12 16:43:05 -08001036 divider = clk_div16_get_divider(parent_rate, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -07001037 if (divider >= 0) {
1038 val = clk_readl(c->reg);
1039 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
1040 val |= divider;
1041 clk_writel(val, c->reg);
1042 c->div = divider + 1;
1043 c->mul = 1;
1044 return 0;
1045 }
Colin Cross4729fd72011-02-12 16:43:05 -08001046 } else if (parent_rate <= rate) {
Colin Cross71fc84c2010-06-07 20:49:46 -07001047 c->div = 1;
1048 c->mul = 1;
1049 return 0;
1050 }
1051 return -EINVAL;
1052}
1053
1054static long tegra2_periph_clk_round_rate(struct clk *c,
1055 unsigned long rate)
1056{
1057 int divider;
Colin Cross4729fd72011-02-12 16:43:05 -08001058 unsigned long parent_rate = clk_get_rate(c->parent);
Colin Cross71fc84c2010-06-07 20:49:46 -07001059 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
1060
1061 if (c->flags & DIV_U71) {
Colin Cross4729fd72011-02-12 16:43:05 -08001062 divider = clk_div71_get_divider(parent_rate, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -07001063 if (divider < 0)
1064 return divider;
1065
Colin Cross4729fd72011-02-12 16:43:05 -08001066 return parent_rate * 2 / (divider + 2);
Colin Cross71fc84c2010-06-07 20:49:46 -07001067 } else if (c->flags & DIV_U16) {
Colin Cross4729fd72011-02-12 16:43:05 -08001068 divider = clk_div16_get_divider(parent_rate, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -07001069 if (divider < 0)
1070 return divider;
Colin Cross4729fd72011-02-12 16:43:05 -08001071 return parent_rate / (divider + 1);
Colin Crossd8611962010-01-28 16:40:29 -08001072 }
1073 return -EINVAL;
1074}
1075
1076static struct clk_ops tegra_periph_clk_ops = {
1077 .init = &tegra2_periph_clk_init,
1078 .enable = &tegra2_periph_clk_enable,
1079 .disable = &tegra2_periph_clk_disable,
1080 .set_parent = &tegra2_periph_clk_set_parent,
1081 .set_rate = &tegra2_periph_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -07001082 .round_rate = &tegra2_periph_clk_round_rate,
Dima Zavin2b84cb4f2010-09-02 19:11:11 -07001083 .reset = &tegra2_periph_clk_reset,
Colin Crossd8611962010-01-28 16:40:29 -08001084};
1085
Colin Cross9743b382011-02-12 18:24:32 -08001086/* The SDMMC controllers have extra bits in the clock source register that
1087 * adjust the delay between the clock and data to compenstate for delays
1088 * on the PCB. */
1089void tegra2_sdmmc_tap_delay(struct clk *c, int delay)
1090{
1091 u32 reg;
1092
1093 delay = clamp(delay, 0, 15);
1094 reg = clk_readl(c->reg);
1095 reg &= ~SDMMC_CLK_INT_FB_DLY_MASK;
1096 reg |= SDMMC_CLK_INT_FB_SEL;
1097 reg |= delay << SDMMC_CLK_INT_FB_DLY_SHIFT;
1098 clk_writel(reg, c->reg);
1099}
1100
Colin Cross6d296822010-11-22 18:37:54 -08001101/* External memory controller clock ops */
1102static void tegra2_emc_clk_init(struct clk *c)
1103{
1104 tegra2_periph_clk_init(c);
1105 c->max_rate = clk_get_rate_locked(c);
1106}
1107
1108static long tegra2_emc_clk_round_rate(struct clk *c, unsigned long rate)
1109{
1110 long new_rate = rate;
1111
1112 new_rate = tegra_emc_round_rate(new_rate);
1113 if (new_rate < 0)
1114 return c->max_rate;
1115
1116 BUG_ON(new_rate != tegra2_periph_clk_round_rate(c, new_rate));
1117
1118 return new_rate;
1119}
1120
1121static int tegra2_emc_clk_set_rate(struct clk *c, unsigned long rate)
1122{
1123 int ret;
1124 /*
1125 * The Tegra2 memory controller has an interlock with the clock
1126 * block that allows memory shadowed registers to be updated,
1127 * and then transfer them to the main registers at the same
1128 * time as the clock update without glitches.
1129 */
1130 ret = tegra_emc_set_rate(rate);
1131 if (ret < 0)
1132 return ret;
1133
1134 ret = tegra2_periph_clk_set_rate(c, rate);
1135 udelay(1);
1136
1137 return ret;
1138}
1139
1140static struct clk_ops tegra_emc_clk_ops = {
1141 .init = &tegra2_emc_clk_init,
1142 .enable = &tegra2_periph_clk_enable,
1143 .disable = &tegra2_periph_clk_disable,
1144 .set_parent = &tegra2_periph_clk_set_parent,
1145 .set_rate = &tegra2_emc_clk_set_rate,
1146 .round_rate = &tegra2_emc_clk_round_rate,
1147 .reset = &tegra2_periph_clk_reset,
1148};
1149
Colin Crossd8611962010-01-28 16:40:29 -08001150/* Clock doubler ops */
1151static void tegra2_clk_double_init(struct clk *c)
1152{
1153 c->mul = 2;
1154 c->div = 1;
1155 c->state = ON;
1156 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1157 PERIPH_CLK_TO_ENB_BIT(c)))
1158 c->state = OFF;
Colin Crossd8611962010-01-28 16:40:29 -08001159};
1160
Colin Cross71fc84c2010-06-07 20:49:46 -07001161static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1162{
Colin Cross4729fd72011-02-12 16:43:05 -08001163 if (rate != 2 * clk_get_rate(c->parent))
Colin Cross71fc84c2010-06-07 20:49:46 -07001164 return -EINVAL;
1165 c->mul = 2;
1166 c->div = 1;
1167 return 0;
1168}
1169
Colin Crossd8611962010-01-28 16:40:29 -08001170static struct clk_ops tegra_clk_double_ops = {
1171 .init = &tegra2_clk_double_init,
1172 .enable = &tegra2_periph_clk_enable,
1173 .disable = &tegra2_periph_clk_disable,
Colin Cross71fc84c2010-06-07 20:49:46 -07001174 .set_rate = &tegra2_clk_double_set_rate,
1175};
1176
Colin Crosscea62c82010-10-04 11:49:26 -07001177/* Audio sync clock ops */
Colin Cross71fc84c2010-06-07 20:49:46 -07001178static void tegra2_audio_sync_clk_init(struct clk *c)
1179{
1180 int source;
1181 const struct clk_mux_sel *sel;
1182 u32 val = clk_readl(c->reg);
1183 c->state = (val & (1<<4)) ? OFF : ON;
1184 source = val & 0xf;
1185 for (sel = c->inputs; sel->input != NULL; sel++)
1186 if (sel->value == source)
1187 break;
1188 BUG_ON(sel->input == NULL);
1189 c->parent = sel->input;
1190}
1191
1192static int tegra2_audio_sync_clk_enable(struct clk *c)
1193{
1194 clk_writel(0, c->reg);
1195 return 0;
1196}
1197
1198static void tegra2_audio_sync_clk_disable(struct clk *c)
1199{
1200 clk_writel(1, c->reg);
1201}
1202
1203static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1204{
1205 u32 val;
1206 const struct clk_mux_sel *sel;
1207 for (sel = c->inputs; sel->input != NULL; sel++) {
1208 if (sel->input == p) {
1209 val = clk_readl(c->reg);
1210 val &= ~0xf;
1211 val |= sel->value;
1212
1213 if (c->refcnt)
Colin Cross4729fd72011-02-12 16:43:05 -08001214 clk_enable(p);
Colin Cross71fc84c2010-06-07 20:49:46 -07001215
1216 clk_writel(val, c->reg);
1217
1218 if (c->refcnt && c->parent)
Colin Cross4729fd72011-02-12 16:43:05 -08001219 clk_disable(c->parent);
Colin Cross71fc84c2010-06-07 20:49:46 -07001220
1221 clk_reparent(c, p);
1222 return 0;
1223 }
1224 }
1225
1226 return -EINVAL;
1227}
1228
Colin Cross71fc84c2010-06-07 20:49:46 -07001229static struct clk_ops tegra_audio_sync_clk_ops = {
1230 .init = tegra2_audio_sync_clk_init,
1231 .enable = tegra2_audio_sync_clk_enable,
1232 .disable = tegra2_audio_sync_clk_disable,
Colin Cross71fc84c2010-06-07 20:49:46 -07001233 .set_parent = tegra2_audio_sync_clk_set_parent,
Colin Crossd8611962010-01-28 16:40:29 -08001234};
1235
Colin Crosscea62c82010-10-04 11:49:26 -07001236/* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1237
1238static void tegra2_cdev_clk_init(struct clk *c)
1239{
1240 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1241 * currently done in the pinmux code. */
1242 c->state = ON;
1243 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1244 PERIPH_CLK_TO_ENB_BIT(c)))
1245 c->state = OFF;
1246}
1247
1248static int tegra2_cdev_clk_enable(struct clk *c)
1249{
1250 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1251 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1252 return 0;
1253}
1254
1255static void tegra2_cdev_clk_disable(struct clk *c)
1256{
1257 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1258 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1259}
1260
1261static struct clk_ops tegra_cdev_clk_ops = {
1262 .init = &tegra2_cdev_clk_init,
1263 .enable = &tegra2_cdev_clk_enable,
1264 .disable = &tegra2_cdev_clk_disable,
1265};
1266
Colin Cross310992c2011-02-12 16:14:03 -08001267/* shared bus ops */
1268/*
1269 * Some clocks may have multiple downstream users that need to request a
1270 * higher clock rate. Shared bus clocks provide a unique shared_bus_user
1271 * clock to each user. The frequency of the bus is set to the highest
1272 * enabled shared_bus_user clock, with a minimum value set by the
1273 * shared bus.
1274 */
1275static int tegra_clk_shared_bus_update(struct clk *bus)
1276{
1277 struct clk *c;
1278 unsigned long rate = bus->min_rate;
1279
1280 list_for_each_entry(c, &bus->shared_bus_list, u.shared_bus_user.node)
1281 if (c->u.shared_bus_user.enabled)
1282 rate = max(c->u.shared_bus_user.rate, rate);
1283
1284 if (rate == clk_get_rate_locked(bus))
1285 return 0;
1286
1287 return clk_set_rate_locked(bus, rate);
1288};
1289
1290static void tegra_clk_shared_bus_init(struct clk *c)
1291{
1292 unsigned long flags;
1293
1294 c->max_rate = c->parent->max_rate;
1295 c->u.shared_bus_user.rate = c->parent->max_rate;
1296 c->state = OFF;
Colin Cross310992c2011-02-12 16:14:03 -08001297 c->set = true;
Colin Cross310992c2011-02-12 16:14:03 -08001298
1299 spin_lock_irqsave(&c->parent->spinlock, flags);
1300
1301 list_add_tail(&c->u.shared_bus_user.node,
1302 &c->parent->shared_bus_list);
1303
1304 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1305}
1306
1307static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate)
1308{
1309 unsigned long flags;
1310 int ret;
1311
1312 rate = clk_round_rate(c->parent, rate);
1313 if (rate < 0)
1314 return rate;
1315
1316 spin_lock_irqsave(&c->parent->spinlock, flags);
1317
1318 c->u.shared_bus_user.rate = rate;
1319 ret = tegra_clk_shared_bus_update(c->parent);
1320
1321 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1322
1323 return ret;
1324}
1325
1326static long tegra_clk_shared_bus_round_rate(struct clk *c, unsigned long rate)
1327{
1328 return clk_round_rate(c->parent, rate);
1329}
1330
1331static int tegra_clk_shared_bus_enable(struct clk *c)
1332{
1333 unsigned long flags;
1334 int ret;
1335
1336 spin_lock_irqsave(&c->parent->spinlock, flags);
1337
1338 c->u.shared_bus_user.enabled = true;
1339 ret = tegra_clk_shared_bus_update(c->parent);
1340
1341 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1342
1343 return ret;
1344}
1345
1346static void tegra_clk_shared_bus_disable(struct clk *c)
1347{
1348 unsigned long flags;
1349 int ret;
1350
1351 spin_lock_irqsave(&c->parent->spinlock, flags);
1352
1353 c->u.shared_bus_user.enabled = false;
1354 ret = tegra_clk_shared_bus_update(c->parent);
1355 WARN_ON_ONCE(ret);
1356
1357 spin_unlock_irqrestore(&c->parent->spinlock, flags);
1358}
1359
1360static struct clk_ops tegra_clk_shared_bus_ops = {
1361 .init = tegra_clk_shared_bus_init,
1362 .enable = tegra_clk_shared_bus_enable,
1363 .disable = tegra_clk_shared_bus_disable,
1364 .set_rate = tegra_clk_shared_bus_set_rate,
1365 .round_rate = tegra_clk_shared_bus_round_rate,
1366};
1367
1368
Colin Crossd8611962010-01-28 16:40:29 -08001369/* Clock definitions */
1370static struct clk tegra_clk_32k = {
1371 .name = "clk_32k",
Colin Cross71fc84c2010-06-07 20:49:46 -07001372 .rate = 32768,
Colin Crossd8611962010-01-28 16:40:29 -08001373 .ops = NULL,
Colin Cross71fc84c2010-06-07 20:49:46 -07001374 .max_rate = 32768,
Colin Crossd8611962010-01-28 16:40:29 -08001375};
1376
Colin Crossf1519612011-02-12 16:05:31 -08001377static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001378 {32768, 12000000, 366, 1, 1, 0},
1379 {32768, 13000000, 397, 1, 1, 0},
1380 {32768, 19200000, 586, 1, 1, 0},
1381 {32768, 26000000, 793, 1, 1, 0},
1382 {0, 0, 0, 0, 0, 0},
1383};
1384
1385static struct clk tegra_pll_s = {
1386 .name = "pll_s",
1387 .flags = PLL_ALT_MISC_REG,
1388 .ops = &tegra_pll_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001389 .parent = &tegra_clk_32k,
Colin Cross71fc84c2010-06-07 20:49:46 -07001390 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001391 .reg = 0xf0,
1392 .u.pll = {
1393 .input_min = 32768,
1394 .input_max = 32768,
1395 .cf_min = 0, /* FIXME */
1396 .cf_max = 0, /* FIXME */
1397 .vco_min = 12000000,
1398 .vco_max = 26000000,
1399 .freq_table = tegra_pll_s_freq_table,
1400 .lock_delay = 300,
1401 },
Colin Crossd8611962010-01-28 16:40:29 -08001402};
1403
1404static struct clk_mux_sel tegra_clk_m_sel[] = {
1405 { .input = &tegra_clk_32k, .value = 0},
1406 { .input = &tegra_pll_s, .value = 1},
1407 { 0, 0},
1408};
Colin Crossf1519612011-02-12 16:05:31 -08001409
Colin Crossd8611962010-01-28 16:40:29 -08001410static struct clk tegra_clk_m = {
1411 .name = "clk_m",
1412 .flags = ENABLE_ON_INIT,
1413 .ops = &tegra_clk_m_ops,
1414 .inputs = tegra_clk_m_sel,
1415 .reg = 0x1fc,
Colin Crossd8611962010-01-28 16:40:29 -08001416 .reg_shift = 28,
Colin Cross71fc84c2010-06-07 20:49:46 -07001417 .max_rate = 26000000,
Colin Crossd8611962010-01-28 16:40:29 -08001418};
1419
Colin Crossf1519612011-02-12 16:05:31 -08001420static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001421 { 0, 0, 0, 0, 0, 0 },
1422};
1423
1424static struct clk tegra_pll_c = {
1425 .name = "pll_c",
1426 .flags = PLL_HAS_CPCON,
1427 .ops = &tegra_pll_ops,
1428 .reg = 0x80,
Colin Crossd8611962010-01-28 16:40:29 -08001429 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001430 .max_rate = 600000000,
Colin Crossf1519612011-02-12 16:05:31 -08001431 .u.pll = {
1432 .input_min = 2000000,
1433 .input_max = 31000000,
1434 .cf_min = 1000000,
1435 .cf_max = 6000000,
1436 .vco_min = 20000000,
1437 .vco_max = 1400000000,
1438 .freq_table = tegra_pll_c_freq_table,
1439 .lock_delay = 300,
1440 },
Colin Crossd8611962010-01-28 16:40:29 -08001441};
1442
1443static struct clk tegra_pll_c_out1 = {
1444 .name = "pll_c_out1",
1445 .ops = &tegra_pll_div_ops,
1446 .flags = DIV_U71,
1447 .parent = &tegra_pll_c,
1448 .reg = 0x84,
1449 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001450 .max_rate = 600000000,
Colin Crossd8611962010-01-28 16:40:29 -08001451};
1452
Colin Crossf1519612011-02-12 16:05:31 -08001453static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001454 { 12000000, 666000000, 666, 12, 1, 8},
1455 { 13000000, 666000000, 666, 13, 1, 8},
1456 { 19200000, 666000000, 555, 16, 1, 8},
1457 { 26000000, 666000000, 666, 26, 1, 8},
1458 { 12000000, 600000000, 600, 12, 1, 8},
1459 { 13000000, 600000000, 600, 13, 1, 8},
1460 { 19200000, 600000000, 375, 12, 1, 6},
1461 { 26000000, 600000000, 600, 26, 1, 8},
Colin Crossd8611962010-01-28 16:40:29 -08001462 { 0, 0, 0, 0, 0, 0 },
1463};
1464
1465static struct clk tegra_pll_m = {
1466 .name = "pll_m",
1467 .flags = PLL_HAS_CPCON,
1468 .ops = &tegra_pll_ops,
1469 .reg = 0x90,
Colin Crossd8611962010-01-28 16:40:29 -08001470 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001471 .max_rate = 800000000,
Colin Crossf1519612011-02-12 16:05:31 -08001472 .u.pll = {
1473 .input_min = 2000000,
1474 .input_max = 31000000,
1475 .cf_min = 1000000,
1476 .cf_max = 6000000,
1477 .vco_min = 20000000,
1478 .vco_max = 1200000000,
1479 .freq_table = tegra_pll_m_freq_table,
1480 .lock_delay = 300,
1481 },
Colin Crossd8611962010-01-28 16:40:29 -08001482};
1483
1484static struct clk tegra_pll_m_out1 = {
1485 .name = "pll_m_out1",
1486 .ops = &tegra_pll_div_ops,
1487 .flags = DIV_U71,
1488 .parent = &tegra_pll_m,
1489 .reg = 0x94,
1490 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001491 .max_rate = 600000000,
Colin Crossd8611962010-01-28 16:40:29 -08001492};
1493
Colin Crossf1519612011-02-12 16:05:31 -08001494static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001495 { 12000000, 216000000, 432, 12, 2, 8},
1496 { 13000000, 216000000, 432, 13, 2, 8},
1497 { 19200000, 216000000, 90, 4, 2, 1},
1498 { 26000000, 216000000, 432, 26, 2, 8},
1499 { 12000000, 432000000, 432, 12, 1, 8},
1500 { 13000000, 432000000, 432, 13, 1, 8},
1501 { 19200000, 432000000, 90, 4, 1, 1},
1502 { 26000000, 432000000, 432, 26, 1, 8},
1503 { 0, 0, 0, 0, 0, 0 },
1504};
1505
1506static struct clk tegra_pll_p = {
1507 .name = "pll_p",
1508 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1509 .ops = &tegra_pll_ops,
1510 .reg = 0xa0,
Colin Crossd8611962010-01-28 16:40:29 -08001511 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001512 .max_rate = 432000000,
Colin Crossf1519612011-02-12 16:05:31 -08001513 .u.pll = {
1514 .input_min = 2000000,
1515 .input_max = 31000000,
1516 .cf_min = 1000000,
1517 .cf_max = 6000000,
1518 .vco_min = 20000000,
1519 .vco_max = 1400000000,
1520 .freq_table = tegra_pll_p_freq_table,
1521 .lock_delay = 300,
1522 },
Colin Crossd8611962010-01-28 16:40:29 -08001523};
1524
1525static struct clk tegra_pll_p_out1 = {
1526 .name = "pll_p_out1",
1527 .ops = &tegra_pll_div_ops,
1528 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1529 .parent = &tegra_pll_p,
1530 .reg = 0xa4,
1531 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001532 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001533};
1534
1535static struct clk tegra_pll_p_out2 = {
1536 .name = "pll_p_out2",
1537 .ops = &tegra_pll_div_ops,
1538 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1539 .parent = &tegra_pll_p,
1540 .reg = 0xa4,
1541 .reg_shift = 16,
Colin Cross71fc84c2010-06-07 20:49:46 -07001542 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001543};
1544
1545static struct clk tegra_pll_p_out3 = {
1546 .name = "pll_p_out3",
1547 .ops = &tegra_pll_div_ops,
1548 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1549 .parent = &tegra_pll_p,
1550 .reg = 0xa8,
1551 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001552 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001553};
1554
1555static struct clk tegra_pll_p_out4 = {
1556 .name = "pll_p_out4",
1557 .ops = &tegra_pll_div_ops,
1558 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1559 .parent = &tegra_pll_p,
1560 .reg = 0xa8,
1561 .reg_shift = 16,
Colin Cross71fc84c2010-06-07 20:49:46 -07001562 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001563};
1564
Colin Crossf1519612011-02-12 16:05:31 -08001565static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001566 { 28800000, 56448000, 49, 25, 1, 1},
1567 { 28800000, 73728000, 64, 25, 1, 1},
Colin Cross71fc84c2010-06-07 20:49:46 -07001568 { 28800000, 24000000, 5, 6, 1, 1},
Colin Crossd8611962010-01-28 16:40:29 -08001569 { 0, 0, 0, 0, 0, 0 },
1570};
1571
1572static struct clk tegra_pll_a = {
1573 .name = "pll_a",
1574 .flags = PLL_HAS_CPCON,
1575 .ops = &tegra_pll_ops,
1576 .reg = 0xb0,
Colin Crossd8611962010-01-28 16:40:29 -08001577 .parent = &tegra_pll_p_out1,
Colin Cross9c7dc562011-02-12 21:25:23 -08001578 .max_rate = 73728000,
Colin Crossf1519612011-02-12 16:05:31 -08001579 .u.pll = {
1580 .input_min = 2000000,
1581 .input_max = 31000000,
1582 .cf_min = 1000000,
1583 .cf_max = 6000000,
1584 .vco_min = 20000000,
1585 .vco_max = 1400000000,
1586 .freq_table = tegra_pll_a_freq_table,
1587 .lock_delay = 300,
1588 },
Colin Crossd8611962010-01-28 16:40:29 -08001589};
1590
1591static struct clk tegra_pll_a_out0 = {
1592 .name = "pll_a_out0",
1593 .ops = &tegra_pll_div_ops,
1594 .flags = DIV_U71,
1595 .parent = &tegra_pll_a,
1596 .reg = 0xb4,
1597 .reg_shift = 0,
Colin Cross9c7dc562011-02-12 21:25:23 -08001598 .max_rate = 73728000,
Colin Crossd8611962010-01-28 16:40:29 -08001599};
1600
Colin Crossf1519612011-02-12 16:05:31 -08001601static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
Colin Crosscea62c82010-10-04 11:49:26 -07001602 { 12000000, 216000000, 216, 12, 1, 4},
1603 { 13000000, 216000000, 216, 13, 1, 4},
1604 { 19200000, 216000000, 135, 12, 1, 3},
1605 { 26000000, 216000000, 216, 26, 1, 4},
1606
1607 { 12000000, 594000000, 594, 12, 1, 8},
1608 { 13000000, 594000000, 594, 13, 1, 8},
1609 { 19200000, 594000000, 495, 16, 1, 8},
1610 { 26000000, 594000000, 594, 26, 1, 8},
1611
Colin Crossd8611962010-01-28 16:40:29 -08001612 { 12000000, 1000000000, 1000, 12, 1, 12},
1613 { 13000000, 1000000000, 1000, 13, 1, 12},
1614 { 19200000, 1000000000, 625, 12, 1, 8},
1615 { 26000000, 1000000000, 1000, 26, 1, 12},
Colin Crosscea62c82010-10-04 11:49:26 -07001616
Colin Crossd8611962010-01-28 16:40:29 -08001617 { 0, 0, 0, 0, 0, 0 },
1618};
1619
1620static struct clk tegra_pll_d = {
1621 .name = "pll_d",
1622 .flags = PLL_HAS_CPCON | PLLD,
1623 .ops = &tegra_pll_ops,
1624 .reg = 0xd0,
Colin Crossd8611962010-01-28 16:40:29 -08001625 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001626 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001627 .u.pll = {
1628 .input_min = 2000000,
1629 .input_max = 40000000,
1630 .cf_min = 1000000,
1631 .cf_max = 6000000,
1632 .vco_min = 40000000,
1633 .vco_max = 1000000000,
1634 .freq_table = tegra_pll_d_freq_table,
1635 .lock_delay = 1000,
1636 },
Colin Crossd8611962010-01-28 16:40:29 -08001637};
1638
1639static struct clk tegra_pll_d_out0 = {
1640 .name = "pll_d_out0",
1641 .ops = &tegra_pll_div_ops,
1642 .flags = DIV_2 | PLLD,
1643 .parent = &tegra_pll_d,
Colin Cross71fc84c2010-06-07 20:49:46 -07001644 .max_rate = 500000000,
Colin Crossd8611962010-01-28 16:40:29 -08001645};
1646
Colin Crossf1519612011-02-12 16:05:31 -08001647static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001648 { 12000000, 480000000, 960, 12, 2, 0},
1649 { 13000000, 480000000, 960, 13, 2, 0},
1650 { 19200000, 480000000, 200, 4, 2, 0},
1651 { 26000000, 480000000, 960, 26, 2, 0},
Colin Crossd8611962010-01-28 16:40:29 -08001652 { 0, 0, 0, 0, 0, 0 },
1653};
1654
1655static struct clk tegra_pll_u = {
1656 .name = "pll_u",
Colin Cross71fc84c2010-06-07 20:49:46 -07001657 .flags = PLLU,
Colin Crossd8611962010-01-28 16:40:29 -08001658 .ops = &tegra_pll_ops,
1659 .reg = 0xc0,
Colin Crossd8611962010-01-28 16:40:29 -08001660 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001661 .max_rate = 480000000,
Colin Crossf1519612011-02-12 16:05:31 -08001662 .u.pll = {
1663 .input_min = 2000000,
1664 .input_max = 40000000,
1665 .cf_min = 1000000,
1666 .cf_max = 6000000,
1667 .vco_min = 480000000,
1668 .vco_max = 960000000,
1669 .freq_table = tegra_pll_u_freq_table,
1670 .lock_delay = 1000,
1671 },
Colin Crossd8611962010-01-28 16:40:29 -08001672};
1673
Colin Crossf1519612011-02-12 16:05:31 -08001674static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001675 /* 1 GHz */
Colin Crossd8611962010-01-28 16:40:29 -08001676 { 12000000, 1000000000, 1000, 12, 1, 12},
1677 { 13000000, 1000000000, 1000, 13, 1, 12},
1678 { 19200000, 1000000000, 625, 12, 1, 8},
1679 { 26000000, 1000000000, 1000, 26, 1, 12},
Colin Cross71fc84c2010-06-07 20:49:46 -07001680
1681 /* 912 MHz */
1682 { 12000000, 912000000, 912, 12, 1, 12},
1683 { 13000000, 912000000, 912, 13, 1, 12},
1684 { 19200000, 912000000, 760, 16, 1, 8},
1685 { 26000000, 912000000, 912, 26, 1, 12},
1686
1687 /* 816 MHz */
1688 { 12000000, 816000000, 816, 12, 1, 12},
1689 { 13000000, 816000000, 816, 13, 1, 12},
1690 { 19200000, 816000000, 680, 16, 1, 8},
1691 { 26000000, 816000000, 816, 26, 1, 12},
1692
1693 /* 760 MHz */
1694 { 12000000, 760000000, 760, 12, 1, 12},
1695 { 13000000, 760000000, 760, 13, 1, 12},
1696 { 19200000, 760000000, 950, 24, 1, 8},
1697 { 26000000, 760000000, 760, 26, 1, 12},
1698
1699 /* 608 MHz */
Colin Cross9c7dc562011-02-12 21:25:23 -08001700 { 12000000, 608000000, 608, 12, 1, 12},
1701 { 13000000, 608000000, 608, 13, 1, 12},
Colin Cross71fc84c2010-06-07 20:49:46 -07001702 { 19200000, 608000000, 380, 12, 1, 8},
Colin Cross9c7dc562011-02-12 21:25:23 -08001703 { 26000000, 608000000, 608, 26, 1, 12},
Colin Cross71fc84c2010-06-07 20:49:46 -07001704
1705 /* 456 MHz */
1706 { 12000000, 456000000, 456, 12, 1, 12},
1707 { 13000000, 456000000, 456, 13, 1, 12},
1708 { 19200000, 456000000, 380, 16, 1, 8},
1709 { 26000000, 456000000, 456, 26, 1, 12},
1710
1711 /* 312 MHz */
1712 { 12000000, 312000000, 312, 12, 1, 12},
1713 { 13000000, 312000000, 312, 13, 1, 12},
1714 { 19200000, 312000000, 260, 16, 1, 8},
1715 { 26000000, 312000000, 312, 26, 1, 12},
1716
Colin Crossd8611962010-01-28 16:40:29 -08001717 { 0, 0, 0, 0, 0, 0 },
1718};
1719
1720static struct clk tegra_pll_x = {
1721 .name = "pll_x",
1722 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
Colin Cross71fc84c2010-06-07 20:49:46 -07001723 .ops = &tegra_pllx_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001724 .reg = 0xe0,
Colin Crossd8611962010-01-28 16:40:29 -08001725 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001726 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001727 .u.pll = {
1728 .input_min = 2000000,
1729 .input_max = 31000000,
1730 .cf_min = 1000000,
1731 .cf_max = 6000000,
1732 .vco_min = 20000000,
1733 .vco_max = 1200000000,
1734 .freq_table = tegra_pll_x_freq_table,
1735 .lock_delay = 300,
1736 },
Colin Crossd8611962010-01-28 16:40:29 -08001737};
1738
Colin Crossf1519612011-02-12 16:05:31 -08001739static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001740 { 12000000, 100000000, 200, 24, 1, 0 },
1741 { 0, 0, 0, 0, 0, 0 },
1742};
1743
1744static struct clk tegra_pll_e = {
1745 .name = "pll_e",
1746 .flags = PLL_ALT_MISC_REG,
1747 .ops = &tegra_plle_ops,
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001748 .parent = &tegra_clk_m,
1749 .reg = 0xe8,
Colin Crossf1519612011-02-12 16:05:31 -08001750 .max_rate = 100000000,
1751 .u.pll = {
1752 .input_min = 12000000,
1753 .input_max = 12000000,
1754 .freq_table = tegra_pll_e_freq_table,
1755 },
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001756};
1757
Colin Crossd8611962010-01-28 16:40:29 -08001758static struct clk tegra_clk_d = {
1759 .name = "clk_d",
1760 .flags = PERIPH_NO_RESET,
1761 .ops = &tegra_clk_double_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001762 .reg = 0x34,
1763 .reg_shift = 12,
1764 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001765 .max_rate = 52000000,
Colin Crossf1519612011-02-12 16:05:31 -08001766 .u.periph = {
1767 .clk_num = 90,
1768 },
Colin Crossd8611962010-01-28 16:40:29 -08001769};
1770
Colin Crosscea62c82010-10-04 11:49:26 -07001771/* dap_mclk1, belongs to the cdev1 pingroup. */
1772static struct clk tegra_dev1_clk = {
1773 .name = "clk_dev1",
1774 .ops = &tegra_cdev_clk_ops,
Colin Crosscea62c82010-10-04 11:49:26 -07001775 .rate = 26000000,
1776 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001777 .u.periph = {
1778 .clk_num = 94,
1779 },
Colin Crosscea62c82010-10-04 11:49:26 -07001780};
1781
1782/* dap_mclk2, belongs to the cdev2 pingroup. */
1783static struct clk tegra_dev2_clk = {
1784 .name = "clk_dev2",
1785 .ops = &tegra_cdev_clk_ops,
Colin Crosscea62c82010-10-04 11:49:26 -07001786 .rate = 26000000,
1787 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001788 .u.periph = {
1789 .clk_num = 93,
1790 },
Colin Crosscea62c82010-10-04 11:49:26 -07001791};
1792
Colin Cross71fc84c2010-06-07 20:49:46 -07001793/* initialized before peripheral clocks */
1794static struct clk_mux_sel mux_audio_sync_clk[8+1];
1795static const struct audio_sources {
1796 const char *name;
1797 int value;
1798} mux_audio_sync_clk_sources[] = {
1799 { .name = "spdif_in", .value = 0 },
1800 { .name = "i2s1", .value = 1 },
1801 { .name = "i2s2", .value = 2 },
1802 { .name = "pll_a_out0", .value = 4 },
1803#if 0 /* FIXME: not implemented */
1804 { .name = "ac97", .value = 3 },
1805 { .name = "ext_audio_clk2", .value = 5 },
1806 { .name = "ext_audio_clk1", .value = 6 },
1807 { .name = "ext_vimclk", .value = 7 },
1808#endif
1809 { 0, 0 }
1810};
1811
1812static struct clk tegra_clk_audio = {
1813 .name = "audio",
1814 .inputs = mux_audio_sync_clk,
1815 .reg = 0x38,
Colin Cross9c7dc562011-02-12 21:25:23 -08001816 .max_rate = 73728000,
Colin Cross71fc84c2010-06-07 20:49:46 -07001817 .ops = &tegra_audio_sync_clk_ops
1818};
1819
Colin Crossd8611962010-01-28 16:40:29 -08001820static struct clk tegra_clk_audio_2x = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001821 .name = "audio_2x",
Colin Crossd8611962010-01-28 16:40:29 -08001822 .flags = PERIPH_NO_RESET,
Colin Cross71fc84c2010-06-07 20:49:46 -07001823 .max_rate = 48000000,
Colin Crossd8611962010-01-28 16:40:29 -08001824 .ops = &tegra_clk_double_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001825 .reg = 0x34,
1826 .reg_shift = 8,
Colin Cross71fc84c2010-06-07 20:49:46 -07001827 .parent = &tegra_clk_audio,
Colin Crossf1519612011-02-12 16:05:31 -08001828 .u.periph = {
1829 .clk_num = 89,
1830 },
Colin Cross71fc84c2010-06-07 20:49:46 -07001831};
1832
1833struct clk_lookup tegra_audio_clk_lookups[] = {
1834 { .con_id = "audio", .clk = &tegra_clk_audio },
1835 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1836};
1837
1838/* This is called after peripheral clocks are initialized, as the
1839 * audio_sync clock depends on some of the peripheral clocks.
1840 */
1841
1842static void init_audio_sync_clock_mux(void)
1843{
1844 int i;
1845 struct clk_mux_sel *sel = mux_audio_sync_clk;
1846 const struct audio_sources *src = mux_audio_sync_clk_sources;
1847 struct clk_lookup *lookup;
1848
1849 for (i = 0; src->name; i++, sel++, src++) {
1850 sel->input = tegra_get_clock_by_name(src->name);
1851 if (!sel->input)
1852 pr_err("%s: could not find clk %s\n", __func__,
1853 src->name);
1854 sel->value = src->value;
1855 }
1856
1857 lookup = tegra_audio_clk_lookups;
1858 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1859 clk_init(lookup->clk);
1860 clkdev_add(lookup);
1861 }
Colin Crossd8611962010-01-28 16:40:29 -08001862}
Colin Crossd8611962010-01-28 16:40:29 -08001863
1864static struct clk_mux_sel mux_cclk[] = {
1865 { .input = &tegra_clk_m, .value = 0},
1866 { .input = &tegra_pll_c, .value = 1},
1867 { .input = &tegra_clk_32k, .value = 2},
1868 { .input = &tegra_pll_m, .value = 3},
1869 { .input = &tegra_pll_p, .value = 4},
1870 { .input = &tegra_pll_p_out4, .value = 5},
1871 { .input = &tegra_pll_p_out3, .value = 6},
1872 { .input = &tegra_clk_d, .value = 7},
1873 { .input = &tegra_pll_x, .value = 8},
1874 { 0, 0},
1875};
1876
1877static struct clk_mux_sel mux_sclk[] = {
1878 { .input = &tegra_clk_m, .value = 0},
1879 { .input = &tegra_pll_c_out1, .value = 1},
1880 { .input = &tegra_pll_p_out4, .value = 2},
1881 { .input = &tegra_pll_p_out3, .value = 3},
1882 { .input = &tegra_pll_p_out2, .value = 4},
1883 { .input = &tegra_clk_d, .value = 5},
1884 { .input = &tegra_clk_32k, .value = 6},
1885 { .input = &tegra_pll_m_out1, .value = 7},
1886 { 0, 0},
1887};
1888
Colin Cross71fc84c2010-06-07 20:49:46 -07001889static struct clk tegra_clk_cclk = {
1890 .name = "cclk",
Colin Crossd8611962010-01-28 16:40:29 -08001891 .inputs = mux_cclk,
1892 .reg = 0x20,
1893 .ops = &tegra_super_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001894 .max_rate = 1000000000,
Colin Crossd8611962010-01-28 16:40:29 -08001895};
1896
Colin Cross71fc84c2010-06-07 20:49:46 -07001897static struct clk tegra_clk_sclk = {
1898 .name = "sclk",
Colin Crossd8611962010-01-28 16:40:29 -08001899 .inputs = mux_sclk,
1900 .reg = 0x28,
1901 .ops = &tegra_super_ops,
Colin Cross9c7dc562011-02-12 21:25:23 -08001902 .max_rate = 240000000,
1903 .min_rate = 120000000,
Colin Cross71fc84c2010-06-07 20:49:46 -07001904};
1905
1906static struct clk tegra_clk_virtual_cpu = {
1907 .name = "cpu",
1908 .parent = &tegra_clk_cclk,
Colin Cross71fc84c2010-06-07 20:49:46 -07001909 .ops = &tegra_cpu_ops,
1910 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001911 .u.cpu = {
1912 .main = &tegra_pll_x,
1913 .backup = &tegra_pll_p,
1914 },
Colin Crossd8611962010-01-28 16:40:29 -08001915};
1916
Colin Cross9c7dc562011-02-12 21:25:23 -08001917static struct clk tegra_clk_cop = {
1918 .name = "cop",
1919 .parent = &tegra_clk_sclk,
1920 .ops = &tegra_cop_ops,
1921 .max_rate = 240000000,
1922};
1923
Colin Crossd8611962010-01-28 16:40:29 -08001924static struct clk tegra_clk_hclk = {
1925 .name = "hclk",
1926 .flags = DIV_BUS,
Colin Cross71fc84c2010-06-07 20:49:46 -07001927 .parent = &tegra_clk_sclk,
Colin Crossd8611962010-01-28 16:40:29 -08001928 .reg = 0x30,
1929 .reg_shift = 4,
1930 .ops = &tegra_bus_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001931 .max_rate = 240000000,
Colin Crossd8611962010-01-28 16:40:29 -08001932};
1933
1934static struct clk tegra_clk_pclk = {
1935 .name = "pclk",
1936 .flags = DIV_BUS,
1937 .parent = &tegra_clk_hclk,
1938 .reg = 0x30,
1939 .reg_shift = 0,
1940 .ops = &tegra_bus_ops,
Colin Cross9c7dc562011-02-12 21:25:23 -08001941 .max_rate = 120000000,
Colin Crossd8611962010-01-28 16:40:29 -08001942};
1943
Colin Crosscea62c82010-10-04 11:49:26 -07001944static struct clk tegra_clk_blink = {
1945 .name = "blink",
1946 .parent = &tegra_clk_32k,
1947 .reg = 0x40,
1948 .ops = &tegra_blink_clk_ops,
1949 .max_rate = 32768,
1950};
1951
Colin Crossd8611962010-01-28 16:40:29 -08001952static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1953 { .input = &tegra_pll_m, .value = 0},
1954 { .input = &tegra_pll_c, .value = 1},
1955 { .input = &tegra_pll_p, .value = 2},
1956 { .input = &tegra_pll_a_out0, .value = 3},
1957 { 0, 0},
1958};
1959
1960static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1961 { .input = &tegra_pll_m, .value = 0},
1962 { .input = &tegra_pll_c, .value = 1},
1963 { .input = &tegra_pll_p, .value = 2},
1964 { .input = &tegra_clk_m, .value = 3},
1965 { 0, 0},
1966};
1967
1968static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1969 { .input = &tegra_pll_p, .value = 0},
1970 { .input = &tegra_pll_c, .value = 1},
1971 { .input = &tegra_pll_m, .value = 2},
1972 { .input = &tegra_clk_m, .value = 3},
1973 { 0, 0},
1974};
1975
Colin Cross71fc84c2010-06-07 20:49:46 -07001976static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1977 {.input = &tegra_pll_a_out0, .value = 0},
1978 {.input = &tegra_clk_audio_2x, .value = 1},
Colin Crossd8611962010-01-28 16:40:29 -08001979 {.input = &tegra_pll_p, .value = 2},
1980 {.input = &tegra_clk_m, .value = 3},
1981 { 0, 0},
1982};
1983
1984static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1985 {.input = &tegra_pll_p, .value = 0},
1986 {.input = &tegra_pll_d_out0, .value = 1},
1987 {.input = &tegra_pll_c, .value = 2},
1988 {.input = &tegra_clk_m, .value = 3},
1989 { 0, 0},
1990};
1991
1992static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1993 {.input = &tegra_pll_p, .value = 0},
1994 {.input = &tegra_pll_c, .value = 1},
Colin Cross71fc84c2010-06-07 20:49:46 -07001995 {.input = &tegra_clk_audio, .value = 2},
Colin Crossd8611962010-01-28 16:40:29 -08001996 {.input = &tegra_clk_m, .value = 3},
1997 {.input = &tegra_clk_32k, .value = 4},
1998 { 0, 0},
1999};
2000
2001static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
2002 {.input = &tegra_pll_p, .value = 0},
2003 {.input = &tegra_pll_c, .value = 1},
2004 {.input = &tegra_pll_m, .value = 2},
2005 { 0, 0},
2006};
2007
2008static struct clk_mux_sel mux_clk_m[] = {
2009 { .input = &tegra_clk_m, .value = 0},
2010 { 0, 0},
2011};
2012
2013static struct clk_mux_sel mux_pllp_out3[] = {
2014 { .input = &tegra_pll_p_out3, .value = 0},
2015 { 0, 0},
2016};
2017
2018static struct clk_mux_sel mux_plld[] = {
2019 { .input = &tegra_pll_d, .value = 0},
2020 { 0, 0},
2021};
2022
2023static struct clk_mux_sel mux_clk_32k[] = {
2024 { .input = &tegra_clk_32k, .value = 0},
2025 { 0, 0},
2026};
2027
Stephen Warren1ca00342011-01-05 14:32:20 -07002028static struct clk_mux_sel mux_pclk[] = {
2029 { .input = &tegra_clk_pclk, .value = 0},
2030 { 0, 0},
2031};
2032
Colin Cross6d296822010-11-22 18:37:54 -08002033static struct clk tegra_clk_emc = {
2034 .name = "emc",
2035 .ops = &tegra_emc_clk_ops,
2036 .reg = 0x19c,
2037 .max_rate = 800000000,
2038 .inputs = mux_pllm_pllc_pllp_clkm,
2039 .flags = MUX | DIV_U71 | PERIPH_EMC_ENB,
2040 .u.periph = {
2041 .clk_num = 57,
2042 },
2043};
2044
Colin Cross71fc84c2010-06-07 20:49:46 -07002045#define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
Colin Crossd8611962010-01-28 16:40:29 -08002046 { \
2047 .name = _name, \
2048 .lookup = { \
2049 .dev_id = _dev, \
2050 .con_id = _con, \
2051 }, \
2052 .ops = &tegra_periph_clk_ops, \
Colin Crossd8611962010-01-28 16:40:29 -08002053 .reg = _reg, \
2054 .inputs = _inputs, \
2055 .flags = _flags, \
Colin Cross71fc84c2010-06-07 20:49:46 -07002056 .max_rate = _max, \
Colin Crossf1519612011-02-12 16:05:31 -08002057 .u.periph = { \
2058 .clk_num = _clk_num, \
2059 }, \
Colin Crossd8611962010-01-28 16:40:29 -08002060 }
2061
Colin Cross310992c2011-02-12 16:14:03 -08002062#define SHARED_CLK(_name, _dev, _con, _parent) \
2063 { \
2064 .name = _name, \
2065 .lookup = { \
2066 .dev_id = _dev, \
2067 .con_id = _con, \
2068 }, \
2069 .ops = &tegra_clk_shared_bus_ops, \
2070 .parent = _parent, \
2071 }
2072
Colin Cross3ec349f2011-02-12 15:52:56 -08002073struct clk tegra_list_clks[] = {
Stephen Warren1ca00342011-01-05 14:32:20 -07002074 PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0),
Colin Cross71fc84c2010-06-07 20:49:46 -07002075 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
2076 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
2077 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2078 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
Colin Crossd8611962010-01-28 16:40:29 -08002079 /* FIXME: spdif has 2 clocks but 1 enable */
Colin Cross71fc84c2010-06-07 20:49:46 -07002080 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
2081 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
2082 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
2083 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2084 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2085 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2086 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2087 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2088 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2089 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2090 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
2091 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, 164000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
Colin Crossd8611962010-01-28 16:40:29 -08002092 /* FIXME: vfir shares an enable with uartb */
Colin Cross71fc84c2010-06-07 20:49:46 -07002093 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2094 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2095 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2096 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
Colin Crosscea62c82010-10-04 11:49:26 -07002097 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
Colin Cross9c7dc562011-02-12 21:25:23 -08002098 PERIPH_CLK("vcp", "tegra-avp", "vcp", 29, 0, 250000000, mux_clk_m, 0),
2099 PERIPH_CLK("bsea", "tegra-avp", "bsea", 62, 0, 250000000, mux_clk_m, 0),
2100 PERIPH_CLK("bsev", "tegra-aes", "bsev", 63, 0, 250000000, mux_clk_m, 0),
2101 PERIPH_CLK("vde", "tegra-avp", "vde", 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
Colin Cross71fc84c2010-06-07 20:49:46 -07002102 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, 144000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* max rate ??? */
Colin Crossd8611962010-01-28 16:40:29 -08002103 /* FIXME: what is la? */
Colin Cross71fc84c2010-06-07 20:49:46 -07002104 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2105 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
2106 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
2107 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
2108 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2109 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2110 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2111 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
2112 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2113 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2114 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
2115 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
Colin Crosscea62c82010-10-04 11:49:26 -07002116 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2117 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2118 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2119 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
2120 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
Colin Cross71fc84c2010-06-07 20:49:46 -07002121 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 */
2122 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
Colin Crossd8611962010-01-28 16:40:29 -08002123 /* FIXME: vi and vi_sensor share an enable */
Colin Crosscea62c82010-10-04 11:49:26 -07002124 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2125 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 Cross71fc84c2010-06-07 20:49:46 -07002126 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2127 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
2128 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, 166000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
Colin Crossd8611962010-01-28 16:40:29 -08002129 /* FIXME: cve and tvo share an enable */
Colin Cross71fc84c2010-06-07 20:49:46 -07002130 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
2131 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
Colin Crosscea62c82010-10-04 11:49:26 -07002132 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
Colin Cross71fc84c2010-06-07 20:49:46 -07002133 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
Colin Crosscea62c82010-10-04 11:49:26 -07002134 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
2135 PERIPH_CLK("disp2", "tegradc.1", NULL, 26, 0x13c, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
Colin Cross71fc84c2010-06-07 20:49:46 -07002136 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2137 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
2138 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
Colin Cross71fc84c2010-06-07 20:49:46 -07002139 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
Colin Crosscea62c82010-10-04 11:49:26 -07002140 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
2141 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
2142 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
Mike Rapoport8d685bc2010-09-27 11:26:32 +02002143 PERIPH_CLK("pex", NULL, "pex", 70, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
2144 PERIPH_CLK("afi", NULL, "afi", 72, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
2145 PERIPH_CLK("pcie_xclk", NULL, "pcie_xclk", 74, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
Colin Cross9c7dc562011-02-12 21:25:23 -08002146
2147 SHARED_CLK("avp.sclk", "tegra-avp", "sclk", &tegra_clk_sclk),
2148 SHARED_CLK("avp.emc", "tegra-avp", "emc", &tegra_clk_emc),
2149 SHARED_CLK("cpu.emc", "cpu", "emc", &tegra_clk_emc),
2150 SHARED_CLK("disp1.emc", "tegradc.0", "emc", &tegra_clk_emc),
2151 SHARED_CLK("disp2.emc", "tegradc.1", "emc", &tegra_clk_emc),
2152 SHARED_CLK("hdmi.emc", "hdmi", "emc", &tegra_clk_emc),
2153 SHARED_CLK("host.emc", "tegra_grhost", "emc", &tegra_clk_emc),
2154 SHARED_CLK("usbd.emc", "fsl-tegra-udc", "emc", &tegra_clk_emc),
2155 SHARED_CLK("usb1.emc", "tegra-ehci.0", "emc", &tegra_clk_emc),
2156 SHARED_CLK("usb2.emc", "tegra-ehci.1", "emc", &tegra_clk_emc),
2157 SHARED_CLK("usb3.emc", "tegra-ehci.2", "emc", &tegra_clk_emc),
Colin Crossd8611962010-01-28 16:40:29 -08002158};
2159
2160#define CLK_DUPLICATE(_name, _dev, _con) \
2161 { \
2162 .name = _name, \
2163 .lookup = { \
2164 .dev_id = _dev, \
2165 .con_id = _con, \
2166 }, \
2167 }
2168
2169/* Some clocks may be used by different drivers depending on the board
2170 * configuration. List those here to register them twice in the clock lookup
2171 * table under two names.
2172 */
2173struct clk_duplicate tegra_clk_duplicates[] = {
2174 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
2175 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
2176 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
2177 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
2178 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
Colin Crosscea62c82010-10-04 11:49:26 -07002179 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
Colin Cross71fc84c2010-06-07 20:49:46 -07002180 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
Colin Crosscea62c82010-10-04 11:49:26 -07002181 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
2182 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
2183 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
2184 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
2185 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
2186 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
2187 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
Colin Cross9c7dc562011-02-12 21:25:23 -08002188 CLK_DUPLICATE("host1x", "tegra_grhost", "host1x"),
2189 CLK_DUPLICATE("2d", "tegra_grhost", "gr2d"),
2190 CLK_DUPLICATE("3d", "tegra_grhost", "gr3d"),
2191 CLK_DUPLICATE("epp", "tegra_grhost", "epp"),
2192 CLK_DUPLICATE("mpe", "tegra_grhost", "mpe"),
2193 CLK_DUPLICATE("cop", "tegra-avp", "cop"),
2194 CLK_DUPLICATE("vde", "tegra-aes", "vde"),
Colin Crossd8611962010-01-28 16:40:29 -08002195};
2196
2197#define CLK(dev, con, ck) \
2198 { \
2199 .dev_id = dev, \
2200 .con_id = con, \
2201 .clk = ck, \
2202 }
2203
Colin Cross3ec349f2011-02-12 15:52:56 -08002204struct clk *tegra_ptr_clks[] = {
2205 &tegra_clk_32k,
2206 &tegra_pll_s,
2207 &tegra_clk_m,
2208 &tegra_pll_m,
2209 &tegra_pll_m_out1,
2210 &tegra_pll_c,
2211 &tegra_pll_c_out1,
2212 &tegra_pll_p,
2213 &tegra_pll_p_out1,
2214 &tegra_pll_p_out2,
2215 &tegra_pll_p_out3,
2216 &tegra_pll_p_out4,
2217 &tegra_pll_a,
2218 &tegra_pll_a_out0,
2219 &tegra_pll_d,
2220 &tegra_pll_d_out0,
2221 &tegra_pll_u,
2222 &tegra_pll_x,
2223 &tegra_pll_e,
2224 &tegra_clk_cclk,
2225 &tegra_clk_sclk,
2226 &tegra_clk_hclk,
2227 &tegra_clk_pclk,
2228 &tegra_clk_d,
2229 &tegra_dev1_clk,
2230 &tegra_dev2_clk,
2231 &tegra_clk_virtual_cpu,
2232 &tegra_clk_blink,
Colin Cross9c7dc562011-02-12 21:25:23 -08002233 &tegra_clk_cop,
Colin Cross6d296822010-11-22 18:37:54 -08002234 &tegra_clk_emc,
Colin Crossd8611962010-01-28 16:40:29 -08002235};
2236
Colin Cross3ec349f2011-02-12 15:52:56 -08002237static void tegra2_init_one_clock(struct clk *c)
2238{
2239 clk_init(c);
Colin Cross310992c2011-02-12 16:14:03 -08002240 INIT_LIST_HEAD(&c->shared_bus_list);
Colin Cross3ec349f2011-02-12 15:52:56 -08002241 if (!c->lookup.dev_id && !c->lookup.con_id)
2242 c->lookup.con_id = c->name;
2243 c->lookup.clk = c;
2244 clkdev_add(&c->lookup);
2245}
2246
Colin Crossd8611962010-01-28 16:40:29 -08002247void __init tegra2_init_clocks(void)
2248{
2249 int i;
Colin Crossd8611962010-01-28 16:40:29 -08002250 struct clk *c;
Colin Crossd8611962010-01-28 16:40:29 -08002251
Colin Cross3ec349f2011-02-12 15:52:56 -08002252 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
2253 tegra2_init_one_clock(tegra_ptr_clks[i]);
Colin Crossd8611962010-01-28 16:40:29 -08002254
Colin Cross3ec349f2011-02-12 15:52:56 -08002255 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
2256 tegra2_init_one_clock(&tegra_list_clks[i]);
Colin Crossd8611962010-01-28 16:40:29 -08002257
2258 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
Colin Cross3ec349f2011-02-12 15:52:56 -08002259 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
2260 if (!c) {
Colin Crossd8611962010-01-28 16:40:29 -08002261 pr_err("%s: Unknown duplicate clock %s\n", __func__,
Colin Cross3ec349f2011-02-12 15:52:56 -08002262 tegra_clk_duplicates[i].name);
2263 continue;
Colin Crossd8611962010-01-28 16:40:29 -08002264 }
Colin Cross3ec349f2011-02-12 15:52:56 -08002265
2266 tegra_clk_duplicates[i].lookup.clk = c;
2267 clkdev_add(&tegra_clk_duplicates[i].lookup);
Colin Crossd8611962010-01-28 16:40:29 -08002268 }
Colin Cross71fc84c2010-06-07 20:49:46 -07002269
2270 init_audio_sync_clock_mux();
Colin Crossd8611962010-01-28 16:40:29 -08002271}
Colin Cross71fc84c2010-06-07 20:49:46 -07002272
2273#ifdef CONFIG_PM
2274static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
Colin Crossc2f44a92010-10-26 17:33:31 -07002275 PERIPH_CLK_SOURCE_NUM + 22];
Colin Cross71fc84c2010-06-07 20:49:46 -07002276
2277void tegra_clk_suspend(void)
2278{
2279 unsigned long off, i;
2280 u32 *ctx = clk_rst_suspend;
2281
2282 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
Colin Crosscea62c82010-10-04 11:49:26 -07002283 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
2284 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2285 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
2286 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
Colin Crossc2f44a92010-10-26 17:33:31 -07002287 *ctx++ = clk_readl(tegra_pll_s.reg + PLL_BASE);
2288 *ctx++ = clk_readl(tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
2289 *ctx++ = clk_readl(tegra_pll_d.reg + PLL_BASE);
2290 *ctx++ = clk_readl(tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
2291 *ctx++ = clk_readl(tegra_pll_u.reg + PLL_BASE);
2292 *ctx++ = clk_readl(tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
Colin Crosscea62c82010-10-04 11:49:26 -07002293
2294 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
Colin Crosscea62c82010-10-04 11:49:26 -07002295 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
2296 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
2297
2298 *ctx++ = clk_readl(tegra_clk_cclk.reg);
2299 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2300
2301 *ctx++ = clk_readl(tegra_clk_sclk.reg);
2302 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2303 *ctx++ = clk_readl(tegra_clk_pclk.reg);
Colin Cross71fc84c2010-06-07 20:49:46 -07002304
Colin Crossc2f44a92010-10-26 17:33:31 -07002305 *ctx++ = clk_readl(tegra_clk_audio.reg);
2306
Colin Cross71fc84c2010-06-07 20:49:46 -07002307 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2308 off += 4) {
2309 if (off == PERIPH_CLK_SOURCE_EMC)
2310 continue;
2311 *ctx++ = clk_readl(off);
2312 }
2313
2314 off = RST_DEVICES;
2315 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2316 *ctx++ = clk_readl(off);
2317
2318 off = CLK_OUT_ENB;
2319 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2320 *ctx++ = clk_readl(off);
2321
2322 *ctx++ = clk_readl(MISC_CLK_ENB);
2323 *ctx++ = clk_readl(CLK_MASK_ARM);
Colin Crossc2f44a92010-10-26 17:33:31 -07002324
2325 BUG_ON(ctx - clk_rst_suspend != ARRAY_SIZE(clk_rst_suspend));
Colin Cross71fc84c2010-06-07 20:49:46 -07002326}
2327
2328void tegra_clk_resume(void)
2329{
2330 unsigned long off, i;
2331 const u32 *ctx = clk_rst_suspend;
2332 u32 val;
2333
2334 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2335 val |= *ctx++;
2336 clk_writel(val, OSC_CTRL);
2337
Colin Crosscea62c82010-10-04 11:49:26 -07002338 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2339 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2340 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2341 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
Colin Crossc2f44a92010-10-26 17:33:31 -07002342 clk_writel(*ctx++, tegra_pll_s.reg + PLL_BASE);
2343 clk_writel(*ctx++, tegra_pll_s.reg + PLL_MISC(&tegra_pll_s));
2344 clk_writel(*ctx++, tegra_pll_d.reg + PLL_BASE);
2345 clk_writel(*ctx++, tegra_pll_d.reg + PLL_MISC(&tegra_pll_d));
2346 clk_writel(*ctx++, tegra_pll_u.reg + PLL_BASE);
2347 clk_writel(*ctx++, tegra_pll_u.reg + PLL_MISC(&tegra_pll_u));
2348 udelay(1000);
Colin Crosscea62c82010-10-04 11:49:26 -07002349
2350 clk_writel(*ctx++, tegra_pll_m_out1.reg);
Colin Crosscea62c82010-10-04 11:49:26 -07002351 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2352 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2353
2354 clk_writel(*ctx++, tegra_clk_cclk.reg);
2355 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2356
2357 clk_writel(*ctx++, tegra_clk_sclk.reg);
2358 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2359 clk_writel(*ctx++, tegra_clk_pclk.reg);
2360
Colin Crossc2f44a92010-10-26 17:33:31 -07002361 clk_writel(*ctx++, tegra_clk_audio.reg);
2362
Colin Cross71fc84c2010-06-07 20:49:46 -07002363 /* enable all clocks before configuring clock sources */
2364 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2365 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2366 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2367 wmb();
2368
2369 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2370 off += 4) {
2371 if (off == PERIPH_CLK_SOURCE_EMC)
2372 continue;
2373 clk_writel(*ctx++, off);
2374 }
2375 wmb();
2376
2377 off = RST_DEVICES;
2378 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2379 clk_writel(*ctx++, off);
2380 wmb();
2381
2382 off = CLK_OUT_ENB;
2383 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2384 clk_writel(*ctx++, off);
2385 wmb();
2386
2387 clk_writel(*ctx++, MISC_CLK_ENB);
2388 clk_writel(*ctx++, CLK_MASK_ARM);
2389}
2390#endif