blob: 324c4d33ad163889165b0e9eb828cb745567477c [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>
26#include <linux/hrtimer.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010027#include <linux/clkdev.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 Crossd8611962010-01-28 16:40:29 -080034
35#define RST_DEVICES 0x004
36#define RST_DEVICES_SET 0x300
37#define RST_DEVICES_CLR 0x304
Colin Cross71fc84c2010-06-07 20:49:46 -070038#define RST_DEVICES_NUM 3
Colin Crossd8611962010-01-28 16:40:29 -080039
40#define CLK_OUT_ENB 0x010
41#define CLK_OUT_ENB_SET 0x320
42#define CLK_OUT_ENB_CLR 0x324
Colin Cross71fc84c2010-06-07 20:49:46 -070043#define CLK_OUT_ENB_NUM 3
44
45#define CLK_MASK_ARM 0x44
46#define MISC_CLK_ENB 0x48
Colin Crossd8611962010-01-28 16:40:29 -080047
48#define OSC_CTRL 0x50
49#define OSC_CTRL_OSC_FREQ_MASK (3<<30)
50#define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
51#define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
52#define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
53#define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
Colin Crosscea62c82010-10-04 11:49:26 -070054#define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
Colin Crossd8611962010-01-28 16:40:29 -080055
56#define OSC_FREQ_DET 0x58
57#define OSC_FREQ_DET_TRIG (1<<31)
58
59#define OSC_FREQ_DET_STATUS 0x5C
60#define OSC_FREQ_DET_BUSY (1<<31)
61#define OSC_FREQ_DET_CNT_MASK 0xFFFF
62
Colin Cross71fc84c2010-06-07 20:49:46 -070063#define PERIPH_CLK_SOURCE_I2S1 0x100
64#define PERIPH_CLK_SOURCE_EMC 0x19c
65#define PERIPH_CLK_SOURCE_OSC 0x1fc
66#define PERIPH_CLK_SOURCE_NUM \
67 ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4)
68
Colin Crossd8611962010-01-28 16:40:29 -080069#define PERIPH_CLK_SOURCE_MASK (3<<30)
70#define PERIPH_CLK_SOURCE_SHIFT 30
71#define PERIPH_CLK_SOURCE_ENABLE (1<<28)
Colin Cross71fc84c2010-06-07 20:49:46 -070072#define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF
73#define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF
Colin Crossd8611962010-01-28 16:40:29 -080074#define PERIPH_CLK_SOURCE_DIV_SHIFT 0
75
76#define PLL_BASE 0x0
77#define PLL_BASE_BYPASS (1<<31)
78#define PLL_BASE_ENABLE (1<<30)
79#define PLL_BASE_REF_ENABLE (1<<29)
80#define PLL_BASE_OVERRIDE (1<<28)
Colin Crossd8611962010-01-28 16:40:29 -080081#define PLL_BASE_DIVP_MASK (0x7<<20)
82#define PLL_BASE_DIVP_SHIFT 20
83#define PLL_BASE_DIVN_MASK (0x3FF<<8)
84#define PLL_BASE_DIVN_SHIFT 8
85#define PLL_BASE_DIVM_MASK (0x1F)
86#define PLL_BASE_DIVM_SHIFT 0
87
88#define PLL_OUT_RATIO_MASK (0xFF<<8)
89#define PLL_OUT_RATIO_SHIFT 8
90#define PLL_OUT_OVERRIDE (1<<2)
91#define PLL_OUT_CLKEN (1<<1)
92#define PLL_OUT_RESET_DISABLE (1<<0)
93
94#define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
Colin Cross71fc84c2010-06-07 20:49:46 -070095
Colin Crossd8611962010-01-28 16:40:29 -080096#define PLL_MISC_DCCON_SHIFT 20
Colin Crossd8611962010-01-28 16:40:29 -080097#define PLL_MISC_CPCON_SHIFT 8
98#define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
99#define PLL_MISC_LFCON_SHIFT 4
100#define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
101#define PLL_MISC_VCOCON_SHIFT 0
102#define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
103
Colin Cross71fc84c2010-06-07 20:49:46 -0700104#define PLLU_BASE_POST_DIV (1<<20)
105
Colin Crossd8611962010-01-28 16:40:29 -0800106#define PLLD_MISC_CLKENABLE (1<<30)
107#define PLLD_MISC_DIV_RST (1<<23)
108#define PLLD_MISC_DCCON_SHIFT 12
109
Mike Rapoport8d685bc2010-09-27 11:26:32 +0200110#define PLLE_MISC_READY (1 << 15)
111
Colin Crossf1519612011-02-12 16:05:31 -0800112#define PERIPH_CLK_TO_ENB_REG(c) ((c->u.periph.clk_num / 32) * 4)
113#define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->u.periph.clk_num / 32) * 8)
114#define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->u.periph.clk_num % 32))
Colin Crossd8611962010-01-28 16:40:29 -0800115
116#define SUPER_CLK_MUX 0x00
117#define SUPER_STATE_SHIFT 28
118#define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
119#define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
120#define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
121#define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
122#define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
123#define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
124#define SUPER_SOURCE_MASK 0xF
125#define SUPER_FIQ_SOURCE_SHIFT 12
126#define SUPER_IRQ_SOURCE_SHIFT 8
127#define SUPER_RUN_SOURCE_SHIFT 4
128#define SUPER_IDLE_SOURCE_SHIFT 0
129
130#define SUPER_CLK_DIVIDER 0x04
131
132#define BUS_CLK_DISABLE (1<<3)
133#define BUS_CLK_DIV_MASK 0x3
134
Colin Crosscea62c82010-10-04 11:49:26 -0700135#define PMC_CTRL 0x0
136 #define PMC_CTRL_BLINK_ENB (1 << 7)
137
138#define PMC_DPD_PADS_ORIDE 0x1c
139 #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20)
140
141#define PMC_BLINK_TIMER_DATA_ON_SHIFT 0
142#define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff
143#define PMC_BLINK_TIMER_ENB (1 << 15)
144#define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16
145#define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff
146
Colin Crossd8611962010-01-28 16:40:29 -0800147static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
Colin Crosscea62c82010-10-04 11:49:26 -0700148static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE);
Colin Crossd8611962010-01-28 16:40:29 -0800149
150#define clk_writel(value, reg) \
151 __raw_writel(value, (u32)reg_clk_base + (reg))
152#define clk_readl(reg) \
153 __raw_readl((u32)reg_clk_base + (reg))
Colin Crosscea62c82010-10-04 11:49:26 -0700154#define pmc_writel(value, reg) \
155 __raw_writel(value, (u32)reg_pmc_base + (reg))
156#define pmc_readl(reg) \
157 __raw_readl((u32)reg_pmc_base + (reg))
Colin Crossd8611962010-01-28 16:40:29 -0800158
159unsigned long clk_measure_input_freq(void)
160{
161 u32 clock_autodetect;
162 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
163 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
164 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
165 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
166 return 12000000;
167 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
168 return 13000000;
169 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
170 return 19200000;
171 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
172 return 26000000;
173 } else {
174 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
175 BUG();
176 return 0;
177 }
178}
179
Colin Cross71fc84c2010-06-07 20:49:46 -0700180static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate)
Colin Crossd8611962010-01-28 16:40:29 -0800181{
Colin Cross71fc84c2010-06-07 20:49:46 -0700182 s64 divider_u71 = parent_rate * 2;
183 divider_u71 += rate - 1;
184 do_div(divider_u71, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800185
Colin Cross71fc84c2010-06-07 20:49:46 -0700186 if (divider_u71 - 2 < 0)
187 return 0;
Colin Crossd8611962010-01-28 16:40:29 -0800188
Colin Cross71fc84c2010-06-07 20:49:46 -0700189 if (divider_u71 - 2 > 255)
Colin Crossd8611962010-01-28 16:40:29 -0800190 return -EINVAL;
191
192 return divider_u71 - 2;
193}
194
Colin Cross71fc84c2010-06-07 20:49:46 -0700195static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate)
Colin Crossd8611962010-01-28 16:40:29 -0800196{
Colin Cross71fc84c2010-06-07 20:49:46 -0700197 s64 divider_u16;
Colin Crossd8611962010-01-28 16:40:29 -0800198
Colin Cross71fc84c2010-06-07 20:49:46 -0700199 divider_u16 = parent_rate;
200 divider_u16 += rate - 1;
201 do_div(divider_u16, rate);
202
203 if (divider_u16 - 1 < 0)
204 return 0;
205
206 if (divider_u16 - 1 > 255)
207 return -EINVAL;
208
209 return divider_u16 - 1;
Colin Crossd8611962010-01-28 16:40:29 -0800210}
211
Colin Crossd8611962010-01-28 16:40:29 -0800212/* clk_m functions */
213static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
214{
215 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
216
217 c->rate = clk_measure_input_freq();
218 switch (c->rate) {
219 case 12000000:
220 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
221 break;
222 case 13000000:
223 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
224 break;
225 case 19200000:
226 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
227 break;
228 case 26000000:
229 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
230 break;
231 default:
232 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
233 BUG();
234 }
235 clk_writel(auto_clock_control, OSC_CTRL);
236 return c->rate;
237}
238
239static void tegra2_clk_m_init(struct clk *c)
240{
241 pr_debug("%s on clock %s\n", __func__, c->name);
242 tegra2_clk_m_autodetect_rate(c);
243}
244
245static int tegra2_clk_m_enable(struct clk *c)
246{
247 pr_debug("%s on clock %s\n", __func__, c->name);
248 return 0;
249}
250
251static void tegra2_clk_m_disable(struct clk *c)
252{
253 pr_debug("%s on clock %s\n", __func__, c->name);
254 BUG();
255}
256
257static struct clk_ops tegra_clk_m_ops = {
258 .init = tegra2_clk_m_init,
259 .enable = tegra2_clk_m_enable,
260 .disable = tegra2_clk_m_disable,
261};
262
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700263void tegra2_periph_reset_assert(struct clk *c)
264{
265 BUG_ON(!c->ops->reset);
266 c->ops->reset(c, true);
267}
268
269void tegra2_periph_reset_deassert(struct clk *c)
270{
271 BUG_ON(!c->ops->reset);
272 c->ops->reset(c, false);
273}
274
Colin Crossd8611962010-01-28 16:40:29 -0800275/* super clock functions */
276/* "super clocks" on tegra have two-stage muxes and a clock skipping
277 * super divider. We will ignore the clock skipping divider, since we
278 * can't lower the voltage when using the clock skip, but we can if we
279 * lower the PLL frequency.
280 */
281static void tegra2_super_clk_init(struct clk *c)
282{
283 u32 val;
284 int source;
285 int shift;
286 const struct clk_mux_sel *sel;
287 val = clk_readl(c->reg + SUPER_CLK_MUX);
288 c->state = ON;
289 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
290 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
291 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
292 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
293 source = (val >> shift) & SUPER_SOURCE_MASK;
294 for (sel = c->inputs; sel->input != NULL; sel++) {
295 if (sel->value == source)
296 break;
297 }
298 BUG_ON(sel->input == NULL);
299 c->parent = sel->input;
Colin Crossd8611962010-01-28 16:40:29 -0800300}
301
302static int tegra2_super_clk_enable(struct clk *c)
303{
304 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
305 return 0;
306}
307
308static void tegra2_super_clk_disable(struct clk *c)
309{
310 pr_debug("%s on clock %s\n", __func__, c->name);
311
312 /* oops - don't disable the CPU clock! */
313 BUG();
314}
315
316static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
317{
318 u32 val;
319 const struct clk_mux_sel *sel;
320 int shift;
Colin Cross71fc84c2010-06-07 20:49:46 -0700321
Colin Crossd8611962010-01-28 16:40:29 -0800322 val = clk_readl(c->reg + SUPER_CLK_MUX);;
323 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
324 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
325 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
326 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
327 for (sel = c->inputs; sel->input != NULL; sel++) {
328 if (sel->input == p) {
Colin Crossd8611962010-01-28 16:40:29 -0800329 val &= ~(SUPER_SOURCE_MASK << shift);
330 val |= sel->value << shift;
Colin Cross71fc84c2010-06-07 20:49:46 -0700331
332 if (c->refcnt)
333 clk_enable_locked(p);
334
Colin Crossd8611962010-01-28 16:40:29 -0800335 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -0700336
337 if (c->refcnt && c->parent)
338 clk_disable_locked(c->parent);
339
340 clk_reparent(c, p);
Colin Crossd8611962010-01-28 16:40:29 -0800341 return 0;
342 }
343 }
344 return -EINVAL;
345}
346
347static struct clk_ops tegra_super_ops = {
348 .init = tegra2_super_clk_init,
349 .enable = tegra2_super_clk_enable,
350 .disable = tegra2_super_clk_disable,
351 .set_parent = tegra2_super_clk_set_parent,
Colin Cross71fc84c2010-06-07 20:49:46 -0700352};
353
354/* virtual cpu clock functions */
355/* some clocks can not be stopped (cpu, memory bus) while the SoC is running.
356 To change the frequency of these clocks, the parent pll may need to be
357 reprogrammed, so the clock must be moved off the pll, the pll reprogrammed,
358 and then the clock moved back to the pll. To hide this sequence, a virtual
359 clock handles it.
360 */
361static void tegra2_cpu_clk_init(struct clk *c)
362{
363}
364
365static int tegra2_cpu_clk_enable(struct clk *c)
366{
367 return 0;
368}
369
370static void tegra2_cpu_clk_disable(struct clk *c)
371{
372 pr_debug("%s on clock %s\n", __func__, c->name);
373
374 /* oops - don't disable the CPU clock! */
375 BUG();
376}
377
378static int tegra2_cpu_clk_set_rate(struct clk *c, unsigned long rate)
379{
380 int ret;
Colin Crossf1519612011-02-12 16:05:31 -0800381 ret = clk_set_parent_locked(c->parent, c->u.cpu.backup);
Colin Cross71fc84c2010-06-07 20:49:46 -0700382 if (ret) {
Colin Crossf1519612011-02-12 16:05:31 -0800383 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.backup->name);
Colin Cross71fc84c2010-06-07 20:49:46 -0700384 return ret;
385 }
386
Colin Crossf1519612011-02-12 16:05:31 -0800387 if (rate == c->u.cpu.backup->rate)
Colin Crosscea62c82010-10-04 11:49:26 -0700388 goto out;
389
Colin Crossf1519612011-02-12 16:05:31 -0800390 ret = clk_set_rate_locked(c->u.cpu.main, rate);
Colin Cross71fc84c2010-06-07 20:49:46 -0700391 if (ret) {
392 pr_err("Failed to change cpu pll to %lu\n", rate);
393 return ret;
394 }
395
Colin Crossf1519612011-02-12 16:05:31 -0800396 ret = clk_set_parent_locked(c->parent, c->u.cpu.main);
Colin Cross71fc84c2010-06-07 20:49:46 -0700397 if (ret) {
Colin Crossf1519612011-02-12 16:05:31 -0800398 pr_err("Failed to switch cpu to clock %s\n", c->u.cpu.main->name);
Colin Cross71fc84c2010-06-07 20:49:46 -0700399 return ret;
400 }
401
Colin Crosscea62c82010-10-04 11:49:26 -0700402out:
Colin Cross71fc84c2010-06-07 20:49:46 -0700403 return 0;
404}
405
406static struct clk_ops tegra_cpu_ops = {
407 .init = tegra2_cpu_clk_init,
408 .enable = tegra2_cpu_clk_enable,
409 .disable = tegra2_cpu_clk_disable,
410 .set_rate = tegra2_cpu_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800411};
412
413/* bus clock functions */
414static void tegra2_bus_clk_init(struct clk *c)
415{
416 u32 val = clk_readl(c->reg);
417 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
418 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
419 c->mul = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800420}
421
422static int tegra2_bus_clk_enable(struct clk *c)
423{
424 u32 val = clk_readl(c->reg);
425 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
426 clk_writel(val, c->reg);
427 return 0;
428}
429
430static void tegra2_bus_clk_disable(struct clk *c)
431{
432 u32 val = clk_readl(c->reg);
433 val |= BUS_CLK_DISABLE << c->reg_shift;
434 clk_writel(val, c->reg);
435}
436
437static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
438{
439 u32 val = clk_readl(c->reg);
440 unsigned long parent_rate = c->parent->rate;
441 int i;
442 for (i = 1; i <= 4; i++) {
443 if (rate == parent_rate / i) {
444 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
445 val |= (i - 1) << c->reg_shift;
446 clk_writel(val, c->reg);
447 c->div = i;
448 c->mul = 1;
449 return 0;
450 }
451 }
452 return -EINVAL;
453}
454
455static struct clk_ops tegra_bus_ops = {
456 .init = tegra2_bus_clk_init,
457 .enable = tegra2_bus_clk_enable,
458 .disable = tegra2_bus_clk_disable,
459 .set_rate = tegra2_bus_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800460};
461
Colin Crosscea62c82010-10-04 11:49:26 -0700462/* Blink output functions */
463
464static void tegra2_blink_clk_init(struct clk *c)
465{
466 u32 val;
467
468 val = pmc_readl(PMC_CTRL);
469 c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF;
470 c->mul = 1;
471 val = pmc_readl(c->reg);
472
473 if (val & PMC_BLINK_TIMER_ENB) {
474 unsigned int on_off;
475
476 on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) &
477 PMC_BLINK_TIMER_DATA_ON_MASK;
478 val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
479 val &= PMC_BLINK_TIMER_DATA_OFF_MASK;
480 on_off += val;
481 /* each tick in the blink timer is 4 32KHz clocks */
482 c->div = on_off * 4;
483 } else {
484 c->div = 1;
485 }
486}
487
488static int tegra2_blink_clk_enable(struct clk *c)
489{
490 u32 val;
491
492 val = pmc_readl(PMC_DPD_PADS_ORIDE);
493 pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
494
495 val = pmc_readl(PMC_CTRL);
496 pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL);
497
498 return 0;
499}
500
501static void tegra2_blink_clk_disable(struct clk *c)
502{
503 u32 val;
504
505 val = pmc_readl(PMC_CTRL);
506 pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL);
507
508 val = pmc_readl(PMC_DPD_PADS_ORIDE);
509 pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE);
510}
511
512static int tegra2_blink_clk_set_rate(struct clk *c, unsigned long rate)
513{
514 if (rate >= c->parent->rate) {
515 c->div = 1;
516 pmc_writel(0, c->reg);
517 } else {
518 unsigned int on_off;
519 u32 val;
520
521 on_off = DIV_ROUND_UP(c->parent->rate / 8, rate);
522 c->div = on_off * 8;
523
524 val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) <<
525 PMC_BLINK_TIMER_DATA_ON_SHIFT;
526 on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK;
527 on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT;
528 val |= on_off;
529 val |= PMC_BLINK_TIMER_ENB;
530 pmc_writel(val, c->reg);
531 }
532
533 return 0;
534}
535
536static struct clk_ops tegra_blink_clk_ops = {
537 .init = &tegra2_blink_clk_init,
538 .enable = &tegra2_blink_clk_enable,
539 .disable = &tegra2_blink_clk_disable,
540 .set_rate = &tegra2_blink_clk_set_rate,
541};
542
Colin Crossd8611962010-01-28 16:40:29 -0800543/* PLL Functions */
Colin Crossd8611962010-01-28 16:40:29 -0800544static int tegra2_pll_clk_wait_for_lock(struct clk *c)
545{
Colin Crossf1519612011-02-12 16:05:31 -0800546 udelay(c->u.pll.lock_delay);
Colin Crossd8611962010-01-28 16:40:29 -0800547
548 return 0;
549}
550
551static void tegra2_pll_clk_init(struct clk *c)
552{
553 u32 val = clk_readl(c->reg + PLL_BASE);
554
555 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
556
557 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
558 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
Colin Cross71fc84c2010-06-07 20:49:46 -0700559 c->mul = 1;
560 c->div = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800561 } else if (val & PLL_BASE_BYPASS) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700562 c->mul = 1;
563 c->div = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800564 } else {
Colin Cross71fc84c2010-06-07 20:49:46 -0700565 c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
566 c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
567 if (c->flags & PLLU)
568 c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2;
569 else
570 c->div *= (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
Colin Crossd8611962010-01-28 16:40:29 -0800571 }
Colin Crossd8611962010-01-28 16:40:29 -0800572}
573
574static int tegra2_pll_clk_enable(struct clk *c)
575{
576 u32 val;
577 pr_debug("%s on clock %s\n", __func__, c->name);
578
579 val = clk_readl(c->reg + PLL_BASE);
580 val &= ~PLL_BASE_BYPASS;
581 val |= PLL_BASE_ENABLE;
582 clk_writel(val, c->reg + PLL_BASE);
583
Colin Crossd8611962010-01-28 16:40:29 -0800584 tegra2_pll_clk_wait_for_lock(c);
585
586 return 0;
587}
588
589static void tegra2_pll_clk_disable(struct clk *c)
590{
591 u32 val;
592 pr_debug("%s on clock %s\n", __func__, c->name);
593
594 val = clk_readl(c->reg);
595 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
596 clk_writel(val, c->reg);
597}
598
599static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
600{
601 u32 val;
602 unsigned long input_rate;
Colin Crossf1519612011-02-12 16:05:31 -0800603 const struct clk_pll_freq_table *sel;
Colin Crossd8611962010-01-28 16:40:29 -0800604
605 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800606
607 input_rate = c->parent->rate;
Colin Crossf1519612011-02-12 16:05:31 -0800608 for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) {
Colin Crossd8611962010-01-28 16:40:29 -0800609 if (sel->input_rate == input_rate && sel->output_rate == rate) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700610 c->mul = sel->n;
611 c->div = sel->m * sel->p;
Colin Crossd8611962010-01-28 16:40:29 -0800612
613 val = clk_readl(c->reg + PLL_BASE);
614 if (c->flags & PLL_FIXED)
615 val |= PLL_BASE_OVERRIDE;
616 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
617 PLL_BASE_DIVM_MASK);
Colin Cross71fc84c2010-06-07 20:49:46 -0700618 val |= (sel->m << PLL_BASE_DIVM_SHIFT) |
619 (sel->n << PLL_BASE_DIVN_SHIFT);
620 BUG_ON(sel->p < 1 || sel->p > 2);
621 if (c->flags & PLLU) {
622 if (sel->p == 1)
623 val |= PLLU_BASE_POST_DIV;
624 } else {
625 if (sel->p == 2)
626 val |= 1 << PLL_BASE_DIVP_SHIFT;
627 }
Colin Crossd8611962010-01-28 16:40:29 -0800628 clk_writel(val, c->reg + PLL_BASE);
629
630 if (c->flags & PLL_HAS_CPCON) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700631 val = clk_readl(c->reg + PLL_MISC(c));
632 val &= ~PLL_MISC_CPCON_MASK;
633 val |= sel->cpcon << PLL_MISC_CPCON_SHIFT;
Colin Crossd8611962010-01-28 16:40:29 -0800634 clk_writel(val, c->reg + PLL_MISC(c));
635 }
636
637 if (c->state == ON)
638 tegra2_pll_clk_enable(c);
639
Colin Crossd8611962010-01-28 16:40:29 -0800640 return 0;
641 }
642 }
643 return -EINVAL;
644}
645
646static struct clk_ops tegra_pll_ops = {
647 .init = tegra2_pll_clk_init,
648 .enable = tegra2_pll_clk_enable,
649 .disable = tegra2_pll_clk_disable,
650 .set_rate = tegra2_pll_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700651};
652
653static void tegra2_pllx_clk_init(struct clk *c)
654{
655 tegra2_pll_clk_init(c);
656
657 if (tegra_sku_id() == 7)
658 c->max_rate = 750000000;
659}
660
661static struct clk_ops tegra_pllx_ops = {
662 .init = tegra2_pllx_clk_init,
663 .enable = tegra2_pll_clk_enable,
664 .disable = tegra2_pll_clk_disable,
665 .set_rate = tegra2_pll_clk_set_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800666};
667
Mike Rapoport8d685bc2010-09-27 11:26:32 +0200668static int tegra2_plle_clk_enable(struct clk *c)
669{
670 u32 val;
671
672 pr_debug("%s on clock %s\n", __func__, c->name);
673
674 mdelay(1);
675
676 val = clk_readl(c->reg + PLL_BASE);
677 if (!(val & PLLE_MISC_READY))
678 return -EBUSY;
679
680 val = clk_readl(c->reg + PLL_BASE);
681 val |= PLL_BASE_ENABLE | PLL_BASE_BYPASS;
682 clk_writel(val, c->reg + PLL_BASE);
683
684 return 0;
685}
686
687static struct clk_ops tegra_plle_ops = {
688 .init = tegra2_pll_clk_init,
689 .enable = tegra2_plle_clk_enable,
690 .set_rate = tegra2_pll_clk_set_rate,
691};
692
Colin Crossd8611962010-01-28 16:40:29 -0800693/* Clock divider ops */
694static void tegra2_pll_div_clk_init(struct clk *c)
695{
696 u32 val = clk_readl(c->reg);
697 u32 divu71;
698 val >>= c->reg_shift;
699 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
700 if (!(val & PLL_OUT_RESET_DISABLE))
701 c->state = OFF;
702
703 if (c->flags & DIV_U71) {
704 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
705 c->div = (divu71 + 2);
706 c->mul = 2;
707 } else if (c->flags & DIV_2) {
708 c->div = 2;
709 c->mul = 1;
710 } else {
711 c->div = 1;
712 c->mul = 1;
713 }
Colin Crossd8611962010-01-28 16:40:29 -0800714}
715
716static int tegra2_pll_div_clk_enable(struct clk *c)
717{
718 u32 val;
719 u32 new_val;
720
721 pr_debug("%s: %s\n", __func__, c->name);
722 if (c->flags & DIV_U71) {
723 val = clk_readl(c->reg);
724 new_val = val >> c->reg_shift;
725 new_val &= 0xFFFF;
726
727 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
728
729 val &= ~(0xFFFF << c->reg_shift);
730 val |= new_val << c->reg_shift;
731 clk_writel(val, c->reg);
732 return 0;
733 } else if (c->flags & DIV_2) {
734 BUG_ON(!(c->flags & PLLD));
735 val = clk_readl(c->reg);
736 val &= ~PLLD_MISC_DIV_RST;
737 clk_writel(val, c->reg);
738 return 0;
739 }
740 return -EINVAL;
741}
742
743static void tegra2_pll_div_clk_disable(struct clk *c)
744{
745 u32 val;
746 u32 new_val;
747
748 pr_debug("%s: %s\n", __func__, c->name);
749 if (c->flags & DIV_U71) {
750 val = clk_readl(c->reg);
751 new_val = val >> c->reg_shift;
752 new_val &= 0xFFFF;
753
754 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
755
756 val &= ~(0xFFFF << c->reg_shift);
757 val |= new_val << c->reg_shift;
758 clk_writel(val, c->reg);
759 } else if (c->flags & DIV_2) {
760 BUG_ON(!(c->flags & PLLD));
761 val = clk_readl(c->reg);
762 val |= PLLD_MISC_DIV_RST;
763 clk_writel(val, c->reg);
764 }
765}
766
767static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
768{
769 u32 val;
770 u32 new_val;
771 int divider_u71;
772 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
773 if (c->flags & DIV_U71) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700774 divider_u71 = clk_div71_get_divider(c->parent->rate, rate);
Colin Crossd8611962010-01-28 16:40:29 -0800775 if (divider_u71 >= 0) {
776 val = clk_readl(c->reg);
777 new_val = val >> c->reg_shift;
778 new_val &= 0xFFFF;
779 if (c->flags & DIV_U71_FIXED)
780 new_val |= PLL_OUT_OVERRIDE;
781 new_val &= ~PLL_OUT_RATIO_MASK;
782 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
783
784 val &= ~(0xFFFF << c->reg_shift);
785 val |= new_val << c->reg_shift;
786 clk_writel(val, c->reg);
787 c->div = divider_u71 + 2;
788 c->mul = 2;
Colin Crossd8611962010-01-28 16:40:29 -0800789 return 0;
790 }
791 } else if (c->flags & DIV_2) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700792 if (c->parent->rate == rate * 2)
Colin Crossd8611962010-01-28 16:40:29 -0800793 return 0;
Colin Crossd8611962010-01-28 16:40:29 -0800794 }
795 return -EINVAL;
796}
797
Colin Cross71fc84c2010-06-07 20:49:46 -0700798static long tegra2_pll_div_clk_round_rate(struct clk *c, unsigned long rate)
799{
800 int divider;
801 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
802
803 if (c->flags & DIV_U71) {
804 divider = clk_div71_get_divider(c->parent->rate, rate);
805 if (divider < 0)
806 return divider;
807 return c->parent->rate * 2 / (divider + 2);
808 } else if (c->flags & DIV_2) {
809 return c->parent->rate / 2;
810 }
811 return -EINVAL;
812}
Colin Crossd8611962010-01-28 16:40:29 -0800813
814static struct clk_ops tegra_pll_div_ops = {
815 .init = tegra2_pll_div_clk_init,
816 .enable = tegra2_pll_div_clk_enable,
817 .disable = tegra2_pll_div_clk_disable,
818 .set_rate = tegra2_pll_div_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700819 .round_rate = tegra2_pll_div_clk_round_rate,
Colin Crossd8611962010-01-28 16:40:29 -0800820};
821
822/* Periph clk ops */
823
824static void tegra2_periph_clk_init(struct clk *c)
825{
826 u32 val = clk_readl(c->reg);
827 const struct clk_mux_sel *mux = 0;
828 const struct clk_mux_sel *sel;
829 if (c->flags & MUX) {
830 for (sel = c->inputs; sel->input != NULL; sel++) {
831 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
832 mux = sel;
833 }
834 BUG_ON(!mux);
835
836 c->parent = mux->input;
837 } else {
838 c->parent = c->inputs[0].input;
839 }
840
841 if (c->flags & DIV_U71) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700842 u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK;
Colin Crossd8611962010-01-28 16:40:29 -0800843 c->div = divu71 + 2;
844 c->mul = 2;
Colin Cross71fc84c2010-06-07 20:49:46 -0700845 } else if (c->flags & DIV_U16) {
846 u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK;
847 c->div = divu16 + 1;
848 c->mul = 1;
Colin Crossd8611962010-01-28 16:40:29 -0800849 } else {
850 c->div = 1;
851 c->mul = 1;
852 }
853
854 c->state = ON;
855 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
856 PERIPH_CLK_TO_ENB_BIT(c)))
857 c->state = OFF;
858 if (!(c->flags & PERIPH_NO_RESET))
859 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
860 PERIPH_CLK_TO_ENB_BIT(c))
861 c->state = OFF;
Colin Crossd8611962010-01-28 16:40:29 -0800862}
863
864static int tegra2_periph_clk_enable(struct clk *c)
865{
866 u32 val;
867 pr_debug("%s on clock %s\n", __func__, c->name);
868
869 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
870 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
871 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
872 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
873 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
874 if (c->flags & PERIPH_EMC_ENB) {
875 /* The EMC peripheral clock has 2 extra enable bits */
876 /* FIXME: Do they need to be disabled? */
877 val = clk_readl(c->reg);
878 val |= 0x3 << 24;
879 clk_writel(val, c->reg);
880 }
881 return 0;
882}
883
884static void tegra2_periph_clk_disable(struct clk *c)
885{
886 pr_debug("%s on clock %s\n", __func__, c->name);
887
888 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
889 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
890}
891
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700892static void tegra2_periph_clk_reset(struct clk *c, bool assert)
Colin Crossd8611962010-01-28 16:40:29 -0800893{
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700894 unsigned long base = assert ? RST_DEVICES_SET : RST_DEVICES_CLR;
895
896 pr_debug("%s %s on clock %s\n", __func__,
897 assert ? "assert" : "deassert", c->name);
Colin Crossd8611962010-01-28 16:40:29 -0800898 if (!(c->flags & PERIPH_NO_RESET))
899 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700900 base + PERIPH_CLK_TO_ENB_SET_REG(c));
Colin Crossd8611962010-01-28 16:40:29 -0800901}
902
Colin Crossd8611962010-01-28 16:40:29 -0800903static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
904{
905 u32 val;
906 const struct clk_mux_sel *sel;
907 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
908 for (sel = c->inputs; sel->input != NULL; sel++) {
909 if (sel->input == p) {
Colin Crossd8611962010-01-28 16:40:29 -0800910 val = clk_readl(c->reg);
911 val &= ~PERIPH_CLK_SOURCE_MASK;
912 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
Colin Cross71fc84c2010-06-07 20:49:46 -0700913
914 if (c->refcnt)
915 clk_enable_locked(p);
916
Colin Crossd8611962010-01-28 16:40:29 -0800917 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -0700918
919 if (c->refcnt && c->parent)
920 clk_disable_locked(c->parent);
921
922 clk_reparent(c, p);
Colin Crossd8611962010-01-28 16:40:29 -0800923 return 0;
924 }
925 }
926
927 return -EINVAL;
928}
929
930static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
931{
932 u32 val;
Colin Cross71fc84c2010-06-07 20:49:46 -0700933 int divider;
Colin Crossd8611962010-01-28 16:40:29 -0800934 pr_debug("%s: %lu\n", __func__, rate);
935 if (c->flags & DIV_U71) {
Colin Cross71fc84c2010-06-07 20:49:46 -0700936 divider = clk_div71_get_divider(c->parent->rate, rate);
937 if (divider >= 0) {
Colin Crossd8611962010-01-28 16:40:29 -0800938 val = clk_readl(c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -0700939 val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK;
940 val |= divider;
Colin Crossd8611962010-01-28 16:40:29 -0800941 clk_writel(val, c->reg);
Colin Cross71fc84c2010-06-07 20:49:46 -0700942 c->div = divider + 2;
Colin Crossd8611962010-01-28 16:40:29 -0800943 c->mul = 2;
Colin Crossd8611962010-01-28 16:40:29 -0800944 return 0;
945 }
Colin Cross71fc84c2010-06-07 20:49:46 -0700946 } else if (c->flags & DIV_U16) {
947 divider = clk_div16_get_divider(c->parent->rate, rate);
948 if (divider >= 0) {
949 val = clk_readl(c->reg);
950 val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK;
951 val |= divider;
952 clk_writel(val, c->reg);
953 c->div = divider + 1;
954 c->mul = 1;
955 return 0;
956 }
957 } else if (c->parent->rate <= rate) {
958 c->div = 1;
959 c->mul = 1;
960 return 0;
961 }
962 return -EINVAL;
963}
964
965static long tegra2_periph_clk_round_rate(struct clk *c,
966 unsigned long rate)
967{
968 int divider;
969 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
970
971 if (c->flags & DIV_U71) {
972 divider = clk_div71_get_divider(c->parent->rate, rate);
973 if (divider < 0)
974 return divider;
975
976 return c->parent->rate * 2 / (divider + 2);
977 } else if (c->flags & DIV_U16) {
978 divider = clk_div16_get_divider(c->parent->rate, rate);
979 if (divider < 0)
980 return divider;
981 return c->parent->rate / (divider + 1);
Colin Crossd8611962010-01-28 16:40:29 -0800982 }
983 return -EINVAL;
984}
985
986static struct clk_ops tegra_periph_clk_ops = {
987 .init = &tegra2_periph_clk_init,
988 .enable = &tegra2_periph_clk_enable,
989 .disable = &tegra2_periph_clk_disable,
990 .set_parent = &tegra2_periph_clk_set_parent,
991 .set_rate = &tegra2_periph_clk_set_rate,
Colin Cross71fc84c2010-06-07 20:49:46 -0700992 .round_rate = &tegra2_periph_clk_round_rate,
Dima Zavin2b84cb4f2010-09-02 19:11:11 -0700993 .reset = &tegra2_periph_clk_reset,
Colin Crossd8611962010-01-28 16:40:29 -0800994};
995
996/* Clock doubler ops */
997static void tegra2_clk_double_init(struct clk *c)
998{
999 c->mul = 2;
1000 c->div = 1;
1001 c->state = ON;
1002 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1003 PERIPH_CLK_TO_ENB_BIT(c)))
1004 c->state = OFF;
Colin Crossd8611962010-01-28 16:40:29 -08001005};
1006
Colin Cross71fc84c2010-06-07 20:49:46 -07001007static int tegra2_clk_double_set_rate(struct clk *c, unsigned long rate)
1008{
1009 if (rate != 2 * c->parent->rate)
1010 return -EINVAL;
1011 c->mul = 2;
1012 c->div = 1;
1013 return 0;
1014}
1015
Colin Crossd8611962010-01-28 16:40:29 -08001016static struct clk_ops tegra_clk_double_ops = {
1017 .init = &tegra2_clk_double_init,
1018 .enable = &tegra2_periph_clk_enable,
1019 .disable = &tegra2_periph_clk_disable,
Colin Cross71fc84c2010-06-07 20:49:46 -07001020 .set_rate = &tegra2_clk_double_set_rate,
1021};
1022
Colin Crosscea62c82010-10-04 11:49:26 -07001023/* Audio sync clock ops */
Colin Cross71fc84c2010-06-07 20:49:46 -07001024static void tegra2_audio_sync_clk_init(struct clk *c)
1025{
1026 int source;
1027 const struct clk_mux_sel *sel;
1028 u32 val = clk_readl(c->reg);
1029 c->state = (val & (1<<4)) ? OFF : ON;
1030 source = val & 0xf;
1031 for (sel = c->inputs; sel->input != NULL; sel++)
1032 if (sel->value == source)
1033 break;
1034 BUG_ON(sel->input == NULL);
1035 c->parent = sel->input;
1036}
1037
1038static int tegra2_audio_sync_clk_enable(struct clk *c)
1039{
1040 clk_writel(0, c->reg);
1041 return 0;
1042}
1043
1044static void tegra2_audio_sync_clk_disable(struct clk *c)
1045{
1046 clk_writel(1, c->reg);
1047}
1048
1049static int tegra2_audio_sync_clk_set_parent(struct clk *c, struct clk *p)
1050{
1051 u32 val;
1052 const struct clk_mux_sel *sel;
1053 for (sel = c->inputs; sel->input != NULL; sel++) {
1054 if (sel->input == p) {
1055 val = clk_readl(c->reg);
1056 val &= ~0xf;
1057 val |= sel->value;
1058
1059 if (c->refcnt)
1060 clk_enable_locked(p);
1061
1062 clk_writel(val, c->reg);
1063
1064 if (c->refcnt && c->parent)
1065 clk_disable_locked(c->parent);
1066
1067 clk_reparent(c, p);
1068 return 0;
1069 }
1070 }
1071
1072 return -EINVAL;
1073}
1074
1075static int tegra2_audio_sync_clk_set_rate(struct clk *c, unsigned long rate)
1076{
1077 unsigned long parent_rate;
1078 if (!c->parent) {
1079 pr_err("%s: clock has no parent\n", __func__);
1080 return -EINVAL;
1081 }
1082 parent_rate = c->parent->rate;
1083 if (rate != parent_rate) {
1084 pr_err("%s: %s/%ld differs from parent %s/%ld\n",
1085 __func__,
1086 c->name, rate,
1087 c->parent->name, parent_rate);
1088 return -EINVAL;
1089 }
1090 c->rate = parent_rate;
1091 return 0;
1092}
1093
1094static struct clk_ops tegra_audio_sync_clk_ops = {
1095 .init = tegra2_audio_sync_clk_init,
1096 .enable = tegra2_audio_sync_clk_enable,
1097 .disable = tegra2_audio_sync_clk_disable,
1098 .set_rate = tegra2_audio_sync_clk_set_rate,
1099 .set_parent = tegra2_audio_sync_clk_set_parent,
Colin Crossd8611962010-01-28 16:40:29 -08001100};
1101
Colin Crosscea62c82010-10-04 11:49:26 -07001102/* cdev1 and cdev2 (dap_mclk1 and dap_mclk2) ops */
1103
1104static void tegra2_cdev_clk_init(struct clk *c)
1105{
1106 /* We could un-tristate the cdev1 or cdev2 pingroup here; this is
1107 * currently done in the pinmux code. */
1108 c->state = ON;
1109 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
1110 PERIPH_CLK_TO_ENB_BIT(c)))
1111 c->state = OFF;
1112}
1113
1114static int tegra2_cdev_clk_enable(struct clk *c)
1115{
1116 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1117 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
1118 return 0;
1119}
1120
1121static void tegra2_cdev_clk_disable(struct clk *c)
1122{
1123 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
1124 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
1125}
1126
1127static struct clk_ops tegra_cdev_clk_ops = {
1128 .init = &tegra2_cdev_clk_init,
1129 .enable = &tegra2_cdev_clk_enable,
1130 .disable = &tegra2_cdev_clk_disable,
1131};
1132
Colin Crossd8611962010-01-28 16:40:29 -08001133/* Clock definitions */
1134static struct clk tegra_clk_32k = {
1135 .name = "clk_32k",
Colin Cross71fc84c2010-06-07 20:49:46 -07001136 .rate = 32768,
Colin Crossd8611962010-01-28 16:40:29 -08001137 .ops = NULL,
Colin Cross71fc84c2010-06-07 20:49:46 -07001138 .max_rate = 32768,
Colin Crossd8611962010-01-28 16:40:29 -08001139};
1140
Colin Crossf1519612011-02-12 16:05:31 -08001141static struct clk_pll_freq_table tegra_pll_s_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001142 {32768, 12000000, 366, 1, 1, 0},
1143 {32768, 13000000, 397, 1, 1, 0},
1144 {32768, 19200000, 586, 1, 1, 0},
1145 {32768, 26000000, 793, 1, 1, 0},
1146 {0, 0, 0, 0, 0, 0},
1147};
1148
1149static struct clk tegra_pll_s = {
1150 .name = "pll_s",
1151 .flags = PLL_ALT_MISC_REG,
1152 .ops = &tegra_pll_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001153 .parent = &tegra_clk_32k,
Colin Cross71fc84c2010-06-07 20:49:46 -07001154 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001155 .reg = 0xf0,
1156 .u.pll = {
1157 .input_min = 32768,
1158 .input_max = 32768,
1159 .cf_min = 0, /* FIXME */
1160 .cf_max = 0, /* FIXME */
1161 .vco_min = 12000000,
1162 .vco_max = 26000000,
1163 .freq_table = tegra_pll_s_freq_table,
1164 .lock_delay = 300,
1165 },
Colin Crossd8611962010-01-28 16:40:29 -08001166};
1167
1168static struct clk_mux_sel tegra_clk_m_sel[] = {
1169 { .input = &tegra_clk_32k, .value = 0},
1170 { .input = &tegra_pll_s, .value = 1},
1171 { 0, 0},
1172};
Colin Crossf1519612011-02-12 16:05:31 -08001173
Colin Crossd8611962010-01-28 16:40:29 -08001174static struct clk tegra_clk_m = {
1175 .name = "clk_m",
1176 .flags = ENABLE_ON_INIT,
1177 .ops = &tegra_clk_m_ops,
1178 .inputs = tegra_clk_m_sel,
1179 .reg = 0x1fc,
Colin Crossd8611962010-01-28 16:40:29 -08001180 .reg_shift = 28,
Colin Cross71fc84c2010-06-07 20:49:46 -07001181 .max_rate = 26000000,
Colin Crossd8611962010-01-28 16:40:29 -08001182};
1183
Colin Crossf1519612011-02-12 16:05:31 -08001184static struct clk_pll_freq_table tegra_pll_c_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001185 { 0, 0, 0, 0, 0, 0 },
1186};
1187
1188static struct clk tegra_pll_c = {
1189 .name = "pll_c",
1190 .flags = PLL_HAS_CPCON,
1191 .ops = &tegra_pll_ops,
1192 .reg = 0x80,
Colin Crossd8611962010-01-28 16:40:29 -08001193 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001194 .max_rate = 600000000,
Colin Crossf1519612011-02-12 16:05:31 -08001195 .u.pll = {
1196 .input_min = 2000000,
1197 .input_max = 31000000,
1198 .cf_min = 1000000,
1199 .cf_max = 6000000,
1200 .vco_min = 20000000,
1201 .vco_max = 1400000000,
1202 .freq_table = tegra_pll_c_freq_table,
1203 .lock_delay = 300,
1204 },
Colin Crossd8611962010-01-28 16:40:29 -08001205};
1206
1207static struct clk tegra_pll_c_out1 = {
1208 .name = "pll_c_out1",
1209 .ops = &tegra_pll_div_ops,
1210 .flags = DIV_U71,
1211 .parent = &tegra_pll_c,
1212 .reg = 0x84,
1213 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001214 .max_rate = 600000000,
Colin Crossd8611962010-01-28 16:40:29 -08001215};
1216
Colin Crossf1519612011-02-12 16:05:31 -08001217static struct clk_pll_freq_table tegra_pll_m_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001218 { 12000000, 666000000, 666, 12, 1, 8},
1219 { 13000000, 666000000, 666, 13, 1, 8},
1220 { 19200000, 666000000, 555, 16, 1, 8},
1221 { 26000000, 666000000, 666, 26, 1, 8},
1222 { 12000000, 600000000, 600, 12, 1, 8},
1223 { 13000000, 600000000, 600, 13, 1, 8},
1224 { 19200000, 600000000, 375, 12, 1, 6},
1225 { 26000000, 600000000, 600, 26, 1, 8},
Colin Crossd8611962010-01-28 16:40:29 -08001226 { 0, 0, 0, 0, 0, 0 },
1227};
1228
1229static struct clk tegra_pll_m = {
1230 .name = "pll_m",
1231 .flags = PLL_HAS_CPCON,
1232 .ops = &tegra_pll_ops,
1233 .reg = 0x90,
Colin Crossd8611962010-01-28 16:40:29 -08001234 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001235 .max_rate = 800000000,
Colin Crossf1519612011-02-12 16:05:31 -08001236 .u.pll = {
1237 .input_min = 2000000,
1238 .input_max = 31000000,
1239 .cf_min = 1000000,
1240 .cf_max = 6000000,
1241 .vco_min = 20000000,
1242 .vco_max = 1200000000,
1243 .freq_table = tegra_pll_m_freq_table,
1244 .lock_delay = 300,
1245 },
Colin Crossd8611962010-01-28 16:40:29 -08001246};
1247
1248static struct clk tegra_pll_m_out1 = {
1249 .name = "pll_m_out1",
1250 .ops = &tegra_pll_div_ops,
1251 .flags = DIV_U71,
1252 .parent = &tegra_pll_m,
1253 .reg = 0x94,
1254 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001255 .max_rate = 600000000,
Colin Crossd8611962010-01-28 16:40:29 -08001256};
1257
Colin Crossf1519612011-02-12 16:05:31 -08001258static struct clk_pll_freq_table tegra_pll_p_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001259 { 12000000, 216000000, 432, 12, 2, 8},
1260 { 13000000, 216000000, 432, 13, 2, 8},
1261 { 19200000, 216000000, 90, 4, 2, 1},
1262 { 26000000, 216000000, 432, 26, 2, 8},
1263 { 12000000, 432000000, 432, 12, 1, 8},
1264 { 13000000, 432000000, 432, 13, 1, 8},
1265 { 19200000, 432000000, 90, 4, 1, 1},
1266 { 26000000, 432000000, 432, 26, 1, 8},
1267 { 0, 0, 0, 0, 0, 0 },
1268};
1269
1270static struct clk tegra_pll_p = {
1271 .name = "pll_p",
1272 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
1273 .ops = &tegra_pll_ops,
1274 .reg = 0xa0,
Colin Crossd8611962010-01-28 16:40:29 -08001275 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001276 .max_rate = 432000000,
Colin Crossf1519612011-02-12 16:05:31 -08001277 .u.pll = {
1278 .input_min = 2000000,
1279 .input_max = 31000000,
1280 .cf_min = 1000000,
1281 .cf_max = 6000000,
1282 .vco_min = 20000000,
1283 .vco_max = 1400000000,
1284 .freq_table = tegra_pll_p_freq_table,
1285 .lock_delay = 300,
1286 },
Colin Crossd8611962010-01-28 16:40:29 -08001287};
1288
1289static struct clk tegra_pll_p_out1 = {
1290 .name = "pll_p_out1",
1291 .ops = &tegra_pll_div_ops,
1292 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1293 .parent = &tegra_pll_p,
1294 .reg = 0xa4,
1295 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001296 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001297};
1298
1299static struct clk tegra_pll_p_out2 = {
1300 .name = "pll_p_out2",
1301 .ops = &tegra_pll_div_ops,
1302 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1303 .parent = &tegra_pll_p,
1304 .reg = 0xa4,
1305 .reg_shift = 16,
Colin Cross71fc84c2010-06-07 20:49:46 -07001306 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001307};
1308
1309static struct clk tegra_pll_p_out3 = {
1310 .name = "pll_p_out3",
1311 .ops = &tegra_pll_div_ops,
1312 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1313 .parent = &tegra_pll_p,
1314 .reg = 0xa8,
1315 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001316 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001317};
1318
1319static struct clk tegra_pll_p_out4 = {
1320 .name = "pll_p_out4",
1321 .ops = &tegra_pll_div_ops,
1322 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
1323 .parent = &tegra_pll_p,
1324 .reg = 0xa8,
1325 .reg_shift = 16,
Colin Cross71fc84c2010-06-07 20:49:46 -07001326 .max_rate = 432000000,
Colin Crossd8611962010-01-28 16:40:29 -08001327};
1328
Colin Crossf1519612011-02-12 16:05:31 -08001329static struct clk_pll_freq_table tegra_pll_a_freq_table[] = {
Colin Crossd8611962010-01-28 16:40:29 -08001330 { 28800000, 56448000, 49, 25, 1, 1},
1331 { 28800000, 73728000, 64, 25, 1, 1},
1332 { 28800000, 11289600, 49, 25, 1, 1},
1333 { 28800000, 12288000, 64, 25, 1, 1},
Colin Cross71fc84c2010-06-07 20:49:46 -07001334 { 28800000, 24000000, 5, 6, 1, 1},
Colin Crossd8611962010-01-28 16:40:29 -08001335 { 0, 0, 0, 0, 0, 0 },
1336};
1337
1338static struct clk tegra_pll_a = {
1339 .name = "pll_a",
1340 .flags = PLL_HAS_CPCON,
1341 .ops = &tegra_pll_ops,
1342 .reg = 0xb0,
Colin Crossd8611962010-01-28 16:40:29 -08001343 .parent = &tegra_pll_p_out1,
Colin Cross71fc84c2010-06-07 20:49:46 -07001344 .max_rate = 56448000,
Colin Crossf1519612011-02-12 16:05:31 -08001345 .u.pll = {
1346 .input_min = 2000000,
1347 .input_max = 31000000,
1348 .cf_min = 1000000,
1349 .cf_max = 6000000,
1350 .vco_min = 20000000,
1351 .vco_max = 1400000000,
1352 .freq_table = tegra_pll_a_freq_table,
1353 .lock_delay = 300,
1354 },
Colin Crossd8611962010-01-28 16:40:29 -08001355};
1356
1357static struct clk tegra_pll_a_out0 = {
1358 .name = "pll_a_out0",
1359 .ops = &tegra_pll_div_ops,
1360 .flags = DIV_U71,
1361 .parent = &tegra_pll_a,
1362 .reg = 0xb4,
1363 .reg_shift = 0,
Colin Cross71fc84c2010-06-07 20:49:46 -07001364 .max_rate = 56448000,
Colin Crossd8611962010-01-28 16:40:29 -08001365};
1366
Colin Crossf1519612011-02-12 16:05:31 -08001367static struct clk_pll_freq_table tegra_pll_d_freq_table[] = {
Colin Crosscea62c82010-10-04 11:49:26 -07001368 { 12000000, 216000000, 216, 12, 1, 4},
1369 { 13000000, 216000000, 216, 13, 1, 4},
1370 { 19200000, 216000000, 135, 12, 1, 3},
1371 { 26000000, 216000000, 216, 26, 1, 4},
1372
1373 { 12000000, 594000000, 594, 12, 1, 8},
1374 { 13000000, 594000000, 594, 13, 1, 8},
1375 { 19200000, 594000000, 495, 16, 1, 8},
1376 { 26000000, 594000000, 594, 26, 1, 8},
1377
Colin Crossd8611962010-01-28 16:40:29 -08001378 { 12000000, 1000000000, 1000, 12, 1, 12},
1379 { 13000000, 1000000000, 1000, 13, 1, 12},
1380 { 19200000, 1000000000, 625, 12, 1, 8},
1381 { 26000000, 1000000000, 1000, 26, 1, 12},
Colin Crosscea62c82010-10-04 11:49:26 -07001382
Colin Crossd8611962010-01-28 16:40:29 -08001383 { 0, 0, 0, 0, 0, 0 },
1384};
1385
1386static struct clk tegra_pll_d = {
1387 .name = "pll_d",
1388 .flags = PLL_HAS_CPCON | PLLD,
1389 .ops = &tegra_pll_ops,
1390 .reg = 0xd0,
Colin Crossd8611962010-01-28 16:40:29 -08001391 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001392 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001393 .u.pll = {
1394 .input_min = 2000000,
1395 .input_max = 40000000,
1396 .cf_min = 1000000,
1397 .cf_max = 6000000,
1398 .vco_min = 40000000,
1399 .vco_max = 1000000000,
1400 .freq_table = tegra_pll_d_freq_table,
1401 .lock_delay = 1000,
1402 },
Colin Crossd8611962010-01-28 16:40:29 -08001403};
1404
1405static struct clk tegra_pll_d_out0 = {
1406 .name = "pll_d_out0",
1407 .ops = &tegra_pll_div_ops,
1408 .flags = DIV_2 | PLLD,
1409 .parent = &tegra_pll_d,
Colin Cross71fc84c2010-06-07 20:49:46 -07001410 .max_rate = 500000000,
Colin Crossd8611962010-01-28 16:40:29 -08001411};
1412
Colin Crossf1519612011-02-12 16:05:31 -08001413static struct clk_pll_freq_table tegra_pll_u_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001414 { 12000000, 480000000, 960, 12, 2, 0},
1415 { 13000000, 480000000, 960, 13, 2, 0},
1416 { 19200000, 480000000, 200, 4, 2, 0},
1417 { 26000000, 480000000, 960, 26, 2, 0},
Colin Crossd8611962010-01-28 16:40:29 -08001418 { 0, 0, 0, 0, 0, 0 },
1419};
1420
1421static struct clk tegra_pll_u = {
1422 .name = "pll_u",
Colin Cross71fc84c2010-06-07 20:49:46 -07001423 .flags = PLLU,
Colin Crossd8611962010-01-28 16:40:29 -08001424 .ops = &tegra_pll_ops,
1425 .reg = 0xc0,
Colin Crossd8611962010-01-28 16:40:29 -08001426 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001427 .max_rate = 480000000,
Colin Crossf1519612011-02-12 16:05:31 -08001428 .u.pll = {
1429 .input_min = 2000000,
1430 .input_max = 40000000,
1431 .cf_min = 1000000,
1432 .cf_max = 6000000,
1433 .vco_min = 480000000,
1434 .vco_max = 960000000,
1435 .freq_table = tegra_pll_u_freq_table,
1436 .lock_delay = 1000,
1437 },
Colin Crossd8611962010-01-28 16:40:29 -08001438};
1439
Colin Crossf1519612011-02-12 16:05:31 -08001440static struct clk_pll_freq_table tegra_pll_x_freq_table[] = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001441 /* 1 GHz */
Colin Crossd8611962010-01-28 16:40:29 -08001442 { 12000000, 1000000000, 1000, 12, 1, 12},
1443 { 13000000, 1000000000, 1000, 13, 1, 12},
1444 { 19200000, 1000000000, 625, 12, 1, 8},
1445 { 26000000, 1000000000, 1000, 26, 1, 12},
Colin Cross71fc84c2010-06-07 20:49:46 -07001446
1447 /* 912 MHz */
1448 { 12000000, 912000000, 912, 12, 1, 12},
1449 { 13000000, 912000000, 912, 13, 1, 12},
1450 { 19200000, 912000000, 760, 16, 1, 8},
1451 { 26000000, 912000000, 912, 26, 1, 12},
1452
1453 /* 816 MHz */
1454 { 12000000, 816000000, 816, 12, 1, 12},
1455 { 13000000, 816000000, 816, 13, 1, 12},
1456 { 19200000, 816000000, 680, 16, 1, 8},
1457 { 26000000, 816000000, 816, 26, 1, 12},
1458
1459 /* 760 MHz */
1460 { 12000000, 760000000, 760, 12, 1, 12},
1461 { 13000000, 760000000, 760, 13, 1, 12},
1462 { 19200000, 760000000, 950, 24, 1, 8},
1463 { 26000000, 760000000, 760, 26, 1, 12},
1464
1465 /* 608 MHz */
1466 { 12000000, 608000000, 760, 12, 1, 12},
1467 { 13000000, 608000000, 760, 13, 1, 12},
1468 { 19200000, 608000000, 380, 12, 1, 8},
1469 { 26000000, 608000000, 760, 26, 1, 12},
1470
1471 /* 456 MHz */
1472 { 12000000, 456000000, 456, 12, 1, 12},
1473 { 13000000, 456000000, 456, 13, 1, 12},
1474 { 19200000, 456000000, 380, 16, 1, 8},
1475 { 26000000, 456000000, 456, 26, 1, 12},
1476
1477 /* 312 MHz */
1478 { 12000000, 312000000, 312, 12, 1, 12},
1479 { 13000000, 312000000, 312, 13, 1, 12},
1480 { 19200000, 312000000, 260, 16, 1, 8},
1481 { 26000000, 312000000, 312, 26, 1, 12},
1482
Colin Crossd8611962010-01-28 16:40:29 -08001483 { 0, 0, 0, 0, 0, 0 },
1484};
1485
1486static struct clk tegra_pll_x = {
1487 .name = "pll_x",
1488 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
Colin Cross71fc84c2010-06-07 20:49:46 -07001489 .ops = &tegra_pllx_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001490 .reg = 0xe0,
Colin Crossd8611962010-01-28 16:40:29 -08001491 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001492 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001493 .u.pll = {
1494 .input_min = 2000000,
1495 .input_max = 31000000,
1496 .cf_min = 1000000,
1497 .cf_max = 6000000,
1498 .vco_min = 20000000,
1499 .vco_max = 1200000000,
1500 .freq_table = tegra_pll_x_freq_table,
1501 .lock_delay = 300,
1502 },
Colin Crossd8611962010-01-28 16:40:29 -08001503};
1504
Colin Crossf1519612011-02-12 16:05:31 -08001505static struct clk_pll_freq_table tegra_pll_e_freq_table[] = {
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001506 { 12000000, 100000000, 200, 24, 1, 0 },
1507 { 0, 0, 0, 0, 0, 0 },
1508};
1509
1510static struct clk tegra_pll_e = {
1511 .name = "pll_e",
1512 .flags = PLL_ALT_MISC_REG,
1513 .ops = &tegra_plle_ops,
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001514 .parent = &tegra_clk_m,
1515 .reg = 0xe8,
Colin Crossf1519612011-02-12 16:05:31 -08001516 .max_rate = 100000000,
1517 .u.pll = {
1518 .input_min = 12000000,
1519 .input_max = 12000000,
1520 .freq_table = tegra_pll_e_freq_table,
1521 },
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001522};
1523
Colin Crossd8611962010-01-28 16:40:29 -08001524static struct clk tegra_clk_d = {
1525 .name = "clk_d",
1526 .flags = PERIPH_NO_RESET,
1527 .ops = &tegra_clk_double_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001528 .reg = 0x34,
1529 .reg_shift = 12,
1530 .parent = &tegra_clk_m,
Colin Cross71fc84c2010-06-07 20:49:46 -07001531 .max_rate = 52000000,
Colin Crossf1519612011-02-12 16:05:31 -08001532 .u.periph = {
1533 .clk_num = 90,
1534 },
Colin Crossd8611962010-01-28 16:40:29 -08001535};
1536
Colin Crosscea62c82010-10-04 11:49:26 -07001537/* dap_mclk1, belongs to the cdev1 pingroup. */
1538static struct clk tegra_dev1_clk = {
1539 .name = "clk_dev1",
1540 .ops = &tegra_cdev_clk_ops,
Colin Crosscea62c82010-10-04 11:49:26 -07001541 .rate = 26000000,
1542 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001543 .u.periph = {
1544 .clk_num = 94,
1545 },
Colin Crosscea62c82010-10-04 11:49:26 -07001546};
1547
1548/* dap_mclk2, belongs to the cdev2 pingroup. */
1549static struct clk tegra_dev2_clk = {
1550 .name = "clk_dev2",
1551 .ops = &tegra_cdev_clk_ops,
Colin Crosscea62c82010-10-04 11:49:26 -07001552 .rate = 26000000,
1553 .max_rate = 26000000,
Colin Crossf1519612011-02-12 16:05:31 -08001554 .u.periph = {
1555 .clk_num = 93,
1556 },
Colin Crosscea62c82010-10-04 11:49:26 -07001557};
1558
Colin Cross71fc84c2010-06-07 20:49:46 -07001559/* initialized before peripheral clocks */
1560static struct clk_mux_sel mux_audio_sync_clk[8+1];
1561static const struct audio_sources {
1562 const char *name;
1563 int value;
1564} mux_audio_sync_clk_sources[] = {
1565 { .name = "spdif_in", .value = 0 },
1566 { .name = "i2s1", .value = 1 },
1567 { .name = "i2s2", .value = 2 },
1568 { .name = "pll_a_out0", .value = 4 },
1569#if 0 /* FIXME: not implemented */
1570 { .name = "ac97", .value = 3 },
1571 { .name = "ext_audio_clk2", .value = 5 },
1572 { .name = "ext_audio_clk1", .value = 6 },
1573 { .name = "ext_vimclk", .value = 7 },
1574#endif
1575 { 0, 0 }
1576};
1577
1578static struct clk tegra_clk_audio = {
1579 .name = "audio",
1580 .inputs = mux_audio_sync_clk,
1581 .reg = 0x38,
1582 .max_rate = 24000000,
1583 .ops = &tegra_audio_sync_clk_ops
1584};
1585
Colin Crossd8611962010-01-28 16:40:29 -08001586static struct clk tegra_clk_audio_2x = {
Colin Cross71fc84c2010-06-07 20:49:46 -07001587 .name = "audio_2x",
Colin Crossd8611962010-01-28 16:40:29 -08001588 .flags = PERIPH_NO_RESET,
Colin Cross71fc84c2010-06-07 20:49:46 -07001589 .max_rate = 48000000,
Colin Crossd8611962010-01-28 16:40:29 -08001590 .ops = &tegra_clk_double_ops,
Colin Crossd8611962010-01-28 16:40:29 -08001591 .reg = 0x34,
1592 .reg_shift = 8,
Colin Cross71fc84c2010-06-07 20:49:46 -07001593 .parent = &tegra_clk_audio,
Colin Crossf1519612011-02-12 16:05:31 -08001594 .u.periph = {
1595 .clk_num = 89,
1596 },
Colin Cross71fc84c2010-06-07 20:49:46 -07001597};
1598
1599struct clk_lookup tegra_audio_clk_lookups[] = {
1600 { .con_id = "audio", .clk = &tegra_clk_audio },
1601 { .con_id = "audio_2x", .clk = &tegra_clk_audio_2x }
1602};
1603
1604/* This is called after peripheral clocks are initialized, as the
1605 * audio_sync clock depends on some of the peripheral clocks.
1606 */
1607
1608static void init_audio_sync_clock_mux(void)
1609{
1610 int i;
1611 struct clk_mux_sel *sel = mux_audio_sync_clk;
1612 const struct audio_sources *src = mux_audio_sync_clk_sources;
1613 struct clk_lookup *lookup;
1614
1615 for (i = 0; src->name; i++, sel++, src++) {
1616 sel->input = tegra_get_clock_by_name(src->name);
1617 if (!sel->input)
1618 pr_err("%s: could not find clk %s\n", __func__,
1619 src->name);
1620 sel->value = src->value;
1621 }
1622
1623 lookup = tegra_audio_clk_lookups;
1624 for (i = 0; i < ARRAY_SIZE(tegra_audio_clk_lookups); i++, lookup++) {
1625 clk_init(lookup->clk);
1626 clkdev_add(lookup);
1627 }
Colin Crossd8611962010-01-28 16:40:29 -08001628}
Colin Crossd8611962010-01-28 16:40:29 -08001629
1630static struct clk_mux_sel mux_cclk[] = {
1631 { .input = &tegra_clk_m, .value = 0},
1632 { .input = &tegra_pll_c, .value = 1},
1633 { .input = &tegra_clk_32k, .value = 2},
1634 { .input = &tegra_pll_m, .value = 3},
1635 { .input = &tegra_pll_p, .value = 4},
1636 { .input = &tegra_pll_p_out4, .value = 5},
1637 { .input = &tegra_pll_p_out3, .value = 6},
1638 { .input = &tegra_clk_d, .value = 7},
1639 { .input = &tegra_pll_x, .value = 8},
1640 { 0, 0},
1641};
1642
1643static struct clk_mux_sel mux_sclk[] = {
1644 { .input = &tegra_clk_m, .value = 0},
1645 { .input = &tegra_pll_c_out1, .value = 1},
1646 { .input = &tegra_pll_p_out4, .value = 2},
1647 { .input = &tegra_pll_p_out3, .value = 3},
1648 { .input = &tegra_pll_p_out2, .value = 4},
1649 { .input = &tegra_clk_d, .value = 5},
1650 { .input = &tegra_clk_32k, .value = 6},
1651 { .input = &tegra_pll_m_out1, .value = 7},
1652 { 0, 0},
1653};
1654
Colin Cross71fc84c2010-06-07 20:49:46 -07001655static struct clk tegra_clk_cclk = {
1656 .name = "cclk",
Colin Crossd8611962010-01-28 16:40:29 -08001657 .inputs = mux_cclk,
1658 .reg = 0x20,
1659 .ops = &tegra_super_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001660 .max_rate = 1000000000,
Colin Crossd8611962010-01-28 16:40:29 -08001661};
1662
Colin Cross71fc84c2010-06-07 20:49:46 -07001663static struct clk tegra_clk_sclk = {
1664 .name = "sclk",
Colin Crossd8611962010-01-28 16:40:29 -08001665 .inputs = mux_sclk,
1666 .reg = 0x28,
1667 .ops = &tegra_super_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001668 .max_rate = 600000000,
1669};
1670
1671static struct clk tegra_clk_virtual_cpu = {
1672 .name = "cpu",
1673 .parent = &tegra_clk_cclk,
Colin Cross71fc84c2010-06-07 20:49:46 -07001674 .ops = &tegra_cpu_ops,
1675 .max_rate = 1000000000,
Colin Crossf1519612011-02-12 16:05:31 -08001676 .u.cpu = {
1677 .main = &tegra_pll_x,
1678 .backup = &tegra_pll_p,
1679 },
Colin Crossd8611962010-01-28 16:40:29 -08001680};
1681
1682static struct clk tegra_clk_hclk = {
1683 .name = "hclk",
1684 .flags = DIV_BUS,
Colin Cross71fc84c2010-06-07 20:49:46 -07001685 .parent = &tegra_clk_sclk,
Colin Crossd8611962010-01-28 16:40:29 -08001686 .reg = 0x30,
1687 .reg_shift = 4,
1688 .ops = &tegra_bus_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001689 .max_rate = 240000000,
Colin Crossd8611962010-01-28 16:40:29 -08001690};
1691
1692static struct clk tegra_clk_pclk = {
1693 .name = "pclk",
1694 .flags = DIV_BUS,
1695 .parent = &tegra_clk_hclk,
1696 .reg = 0x30,
1697 .reg_shift = 0,
1698 .ops = &tegra_bus_ops,
Colin Cross71fc84c2010-06-07 20:49:46 -07001699 .max_rate = 108000000,
Colin Crossd8611962010-01-28 16:40:29 -08001700};
1701
Colin Crosscea62c82010-10-04 11:49:26 -07001702static struct clk tegra_clk_blink = {
1703 .name = "blink",
1704 .parent = &tegra_clk_32k,
1705 .reg = 0x40,
1706 .ops = &tegra_blink_clk_ops,
1707 .max_rate = 32768,
1708};
1709
Colin Crossd8611962010-01-28 16:40:29 -08001710static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1711 { .input = &tegra_pll_m, .value = 0},
1712 { .input = &tegra_pll_c, .value = 1},
1713 { .input = &tegra_pll_p, .value = 2},
1714 { .input = &tegra_pll_a_out0, .value = 3},
1715 { 0, 0},
1716};
1717
1718static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1719 { .input = &tegra_pll_m, .value = 0},
1720 { .input = &tegra_pll_c, .value = 1},
1721 { .input = &tegra_pll_p, .value = 2},
1722 { .input = &tegra_clk_m, .value = 3},
1723 { 0, 0},
1724};
1725
1726static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1727 { .input = &tegra_pll_p, .value = 0},
1728 { .input = &tegra_pll_c, .value = 1},
1729 { .input = &tegra_pll_m, .value = 2},
1730 { .input = &tegra_clk_m, .value = 3},
1731 { 0, 0},
1732};
1733
Colin Cross71fc84c2010-06-07 20:49:46 -07001734static struct clk_mux_sel mux_pllaout0_audio2x_pllp_clkm[] = {
1735 {.input = &tegra_pll_a_out0, .value = 0},
1736 {.input = &tegra_clk_audio_2x, .value = 1},
Colin Crossd8611962010-01-28 16:40:29 -08001737 {.input = &tegra_pll_p, .value = 2},
1738 {.input = &tegra_clk_m, .value = 3},
1739 { 0, 0},
1740};
1741
1742static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1743 {.input = &tegra_pll_p, .value = 0},
1744 {.input = &tegra_pll_d_out0, .value = 1},
1745 {.input = &tegra_pll_c, .value = 2},
1746 {.input = &tegra_clk_m, .value = 3},
1747 { 0, 0},
1748};
1749
1750static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1751 {.input = &tegra_pll_p, .value = 0},
1752 {.input = &tegra_pll_c, .value = 1},
Colin Cross71fc84c2010-06-07 20:49:46 -07001753 {.input = &tegra_clk_audio, .value = 2},
Colin Crossd8611962010-01-28 16:40:29 -08001754 {.input = &tegra_clk_m, .value = 3},
1755 {.input = &tegra_clk_32k, .value = 4},
1756 { 0, 0},
1757};
1758
1759static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1760 {.input = &tegra_pll_p, .value = 0},
1761 {.input = &tegra_pll_c, .value = 1},
1762 {.input = &tegra_pll_m, .value = 2},
1763 { 0, 0},
1764};
1765
1766static struct clk_mux_sel mux_clk_m[] = {
1767 { .input = &tegra_clk_m, .value = 0},
1768 { 0, 0},
1769};
1770
1771static struct clk_mux_sel mux_pllp_out3[] = {
1772 { .input = &tegra_pll_p_out3, .value = 0},
1773 { 0, 0},
1774};
1775
1776static struct clk_mux_sel mux_plld[] = {
1777 { .input = &tegra_pll_d, .value = 0},
1778 { 0, 0},
1779};
1780
1781static struct clk_mux_sel mux_clk_32k[] = {
1782 { .input = &tegra_clk_32k, .value = 0},
1783 { 0, 0},
1784};
1785
Stephen Warren1ca00342011-01-05 14:32:20 -07001786static struct clk_mux_sel mux_pclk[] = {
1787 { .input = &tegra_clk_pclk, .value = 0},
1788 { 0, 0},
1789};
1790
Colin Cross71fc84c2010-06-07 20:49:46 -07001791#define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _max, _inputs, _flags) \
Colin Crossd8611962010-01-28 16:40:29 -08001792 { \
1793 .name = _name, \
1794 .lookup = { \
1795 .dev_id = _dev, \
1796 .con_id = _con, \
1797 }, \
1798 .ops = &tegra_periph_clk_ops, \
Colin Crossd8611962010-01-28 16:40:29 -08001799 .reg = _reg, \
1800 .inputs = _inputs, \
1801 .flags = _flags, \
Colin Cross71fc84c2010-06-07 20:49:46 -07001802 .max_rate = _max, \
Colin Crossf1519612011-02-12 16:05:31 -08001803 .u.periph = { \
1804 .clk_num = _clk_num, \
1805 }, \
Colin Crossd8611962010-01-28 16:40:29 -08001806 }
1807
Colin Cross3ec349f2011-02-12 15:52:56 -08001808struct clk tegra_list_clks[] = {
Stephen Warren1ca00342011-01-05 14:32:20 -07001809 PERIPH_CLK("apbdma", "tegra-dma", NULL, 34, 0, 108000000, mux_pclk, 0),
Colin Cross71fc84c2010-06-07 20:49:46 -07001810 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, 32768, mux_clk_32k, PERIPH_NO_RESET),
1811 PERIPH_CLK("timer", "timer", NULL, 5, 0, 26000000, mux_clk_m, 0),
1812 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1813 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, 26000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
Colin Crossd8611962010-01-28 16:40:29 -08001814 /* FIXME: spdif has 2 clocks but 1 enable */
Colin Cross71fc84c2010-06-07 20:49:46 -07001815 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, 100000000, mux_pllaout0_audio2x_pllp_clkm, MUX | DIV_U71),
1816 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, 100000000, mux_pllp_pllc_pllm, MUX | DIV_U71),
1817 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, 432000000, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
1818 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, 40000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1819 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1820 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, 150000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1821 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1822 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1823 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1824 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, 160000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1825 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, 100000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1826 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 -08001827 /* FIXME: vfir shares an enable with uartb */
Colin Cross71fc84c2010-06-07 20:49:46 -07001828 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, 72000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1829 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1830 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1831 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 -07001832 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x164, 52000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
Colin Cross71fc84c2010-06-07 20:49:46 -07001833 PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, 250000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1834 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 -08001835 /* FIXME: what is la? */
Colin Cross71fc84c2010-06-07 20:49:46 -07001836 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1837 PERIPH_CLK("owr", "tegra_w1", NULL, 71, 0x1cc, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1838 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, 92000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* requires min voltage */
1839 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, 60000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71), /* scales with voltage */
1840 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1841 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1842 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1843 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, 26000000, mux_pllp_pllc_pllm_clkm, MUX | DIV_U16),
1844 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1845 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1846 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
1847 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, 72000000, mux_pllp_out3, 0),
Colin Crosscea62c82010-10-04 11:49:26 -07001848 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1849 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1850 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1851 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
1852 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, 600000000, mux_pllp_pllc_pllm_clkm, MUX),
Colin Cross71fc84c2010-06-07 20:49:46 -07001853 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 */
1854 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 -08001855 /* FIXME: vi and vi_sensor share an enable */
Colin Crosscea62c82010-10-04 11:49:26 -07001856 PERIPH_CLK("vi", "tegra_camera", "vi", 20, 0x148, 150000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1857 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 -07001858 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, 300000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1859 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, 250000000, mux_pllm_pllc_pllp_plla, MUX | DIV_U71), /* scales with voltage and process_id */
1860 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 -08001861 /* FIXME: cve and tvo share an enable */
Colin Cross71fc84c2010-06-07 20:49:46 -07001862 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, 250000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* requires min voltage */
1863 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 -07001864 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 -07001865 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 -07001866 PERIPH_CLK("disp1", "tegradc.0", NULL, 27, 0x138, 600000000, mux_pllp_plld_pllc_clkm, MUX | DIV_U71), /* scales with voltage and process_id */
1867 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 -07001868 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1869 PERIPH_CLK("usb2", "tegra-ehci.1", NULL, 58, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1870 PERIPH_CLK("usb3", "tegra-ehci.2", NULL, 59, 0, 480000000, mux_clk_m, 0), /* requires min voltage */
1871 PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, 800000000, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB),
1872 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, 500000000, mux_plld, 0), /* scales with voltage */
Colin Crosscea62c82010-10-04 11:49:26 -07001873 PERIPH_CLK("csi", "tegra_camera", "csi", 52, 0, 72000000, mux_pllp_out3, 0),
1874 PERIPH_CLK("isp", "tegra_camera", "isp", 23, 0, 150000000, mux_clk_m, 0), /* same frequency as VI */
1875 PERIPH_CLK("csus", "tegra_camera", "csus", 92, 0, 150000000, mux_clk_m, PERIPH_NO_RESET),
Mike Rapoport8d685bc2010-09-27 11:26:32 +02001876 PERIPH_CLK("pex", NULL, "pex", 70, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
1877 PERIPH_CLK("afi", NULL, "afi", 72, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
1878 PERIPH_CLK("pcie_xclk", NULL, "pcie_xclk", 74, 0, 26000000, mux_clk_m, PERIPH_MANUAL_RESET),
Colin Crossd8611962010-01-28 16:40:29 -08001879};
1880
1881#define CLK_DUPLICATE(_name, _dev, _con) \
1882 { \
1883 .name = _name, \
1884 .lookup = { \
1885 .dev_id = _dev, \
1886 .con_id = _con, \
1887 }, \
1888 }
1889
1890/* Some clocks may be used by different drivers depending on the board
1891 * configuration. List those here to register them twice in the clock lookup
1892 * table under two names.
1893 */
1894struct clk_duplicate tegra_clk_duplicates[] = {
1895 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
1896 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
1897 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
1898 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
1899 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
Colin Crosscea62c82010-10-04 11:49:26 -07001900 CLK_DUPLICATE("usbd", "utmip-pad", NULL),
Colin Cross71fc84c2010-06-07 20:49:46 -07001901 CLK_DUPLICATE("usbd", "tegra-ehci.0", NULL),
Colin Crosscea62c82010-10-04 11:49:26 -07001902 CLK_DUPLICATE("usbd", "tegra-otg", NULL),
1903 CLK_DUPLICATE("hdmi", "tegradc.0", "hdmi"),
1904 CLK_DUPLICATE("hdmi", "tegradc.1", "hdmi"),
1905 CLK_DUPLICATE("pwm", "tegra_pwm.0", NULL),
1906 CLK_DUPLICATE("pwm", "tegra_pwm.1", NULL),
1907 CLK_DUPLICATE("pwm", "tegra_pwm.2", NULL),
1908 CLK_DUPLICATE("pwm", "tegra_pwm.3", NULL),
Colin Crossd8611962010-01-28 16:40:29 -08001909};
1910
1911#define CLK(dev, con, ck) \
1912 { \
1913 .dev_id = dev, \
1914 .con_id = con, \
1915 .clk = ck, \
1916 }
1917
Colin Cross3ec349f2011-02-12 15:52:56 -08001918struct clk *tegra_ptr_clks[] = {
1919 &tegra_clk_32k,
1920 &tegra_pll_s,
1921 &tegra_clk_m,
1922 &tegra_pll_m,
1923 &tegra_pll_m_out1,
1924 &tegra_pll_c,
1925 &tegra_pll_c_out1,
1926 &tegra_pll_p,
1927 &tegra_pll_p_out1,
1928 &tegra_pll_p_out2,
1929 &tegra_pll_p_out3,
1930 &tegra_pll_p_out4,
1931 &tegra_pll_a,
1932 &tegra_pll_a_out0,
1933 &tegra_pll_d,
1934 &tegra_pll_d_out0,
1935 &tegra_pll_u,
1936 &tegra_pll_x,
1937 &tegra_pll_e,
1938 &tegra_clk_cclk,
1939 &tegra_clk_sclk,
1940 &tegra_clk_hclk,
1941 &tegra_clk_pclk,
1942 &tegra_clk_d,
1943 &tegra_dev1_clk,
1944 &tegra_dev2_clk,
1945 &tegra_clk_virtual_cpu,
1946 &tegra_clk_blink,
Colin Crossd8611962010-01-28 16:40:29 -08001947};
1948
Colin Cross3ec349f2011-02-12 15:52:56 -08001949static void tegra2_init_one_clock(struct clk *c)
1950{
1951 clk_init(c);
1952 if (!c->lookup.dev_id && !c->lookup.con_id)
1953 c->lookup.con_id = c->name;
1954 c->lookup.clk = c;
1955 clkdev_add(&c->lookup);
1956}
1957
Colin Crossd8611962010-01-28 16:40:29 -08001958void __init tegra2_init_clocks(void)
1959{
1960 int i;
Colin Crossd8611962010-01-28 16:40:29 -08001961 struct clk *c;
Colin Crossd8611962010-01-28 16:40:29 -08001962
Colin Cross3ec349f2011-02-12 15:52:56 -08001963 for (i = 0; i < ARRAY_SIZE(tegra_ptr_clks); i++)
1964 tegra2_init_one_clock(tegra_ptr_clks[i]);
Colin Crossd8611962010-01-28 16:40:29 -08001965
Colin Cross3ec349f2011-02-12 15:52:56 -08001966 for (i = 0; i < ARRAY_SIZE(tegra_list_clks); i++)
1967 tegra2_init_one_clock(&tegra_list_clks[i]);
Colin Crossd8611962010-01-28 16:40:29 -08001968
1969 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
Colin Cross3ec349f2011-02-12 15:52:56 -08001970 c = tegra_get_clock_by_name(tegra_clk_duplicates[i].name);
1971 if (!c) {
Colin Crossd8611962010-01-28 16:40:29 -08001972 pr_err("%s: Unknown duplicate clock %s\n", __func__,
Colin Cross3ec349f2011-02-12 15:52:56 -08001973 tegra_clk_duplicates[i].name);
1974 continue;
Colin Crossd8611962010-01-28 16:40:29 -08001975 }
Colin Cross3ec349f2011-02-12 15:52:56 -08001976
1977 tegra_clk_duplicates[i].lookup.clk = c;
1978 clkdev_add(&tegra_clk_duplicates[i].lookup);
Colin Crossd8611962010-01-28 16:40:29 -08001979 }
Colin Cross71fc84c2010-06-07 20:49:46 -07001980
1981 init_audio_sync_clock_mux();
Colin Crossd8611962010-01-28 16:40:29 -08001982}
Colin Cross71fc84c2010-06-07 20:49:46 -07001983
1984#ifdef CONFIG_PM
1985static u32 clk_rst_suspend[RST_DEVICES_NUM + CLK_OUT_ENB_NUM +
Colin Crosscea62c82010-10-04 11:49:26 -07001986 PERIPH_CLK_SOURCE_NUM + 19];
Colin Cross71fc84c2010-06-07 20:49:46 -07001987
1988void tegra_clk_suspend(void)
1989{
1990 unsigned long off, i;
1991 u32 *ctx = clk_rst_suspend;
1992
1993 *ctx++ = clk_readl(OSC_CTRL) & OSC_CTRL_MASK;
Colin Crosscea62c82010-10-04 11:49:26 -07001994 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_BASE);
1995 *ctx++ = clk_readl(tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
1996 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_BASE);
1997 *ctx++ = clk_readl(tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
1998 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_BASE);
1999 *ctx++ = clk_readl(tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2000
2001 *ctx++ = clk_readl(tegra_pll_m_out1.reg);
2002 *ctx++ = clk_readl(tegra_pll_p_out1.reg);
2003 *ctx++ = clk_readl(tegra_pll_p_out3.reg);
2004 *ctx++ = clk_readl(tegra_pll_a_out0.reg);
2005 *ctx++ = clk_readl(tegra_pll_c_out1.reg);
2006
2007 *ctx++ = clk_readl(tegra_clk_cclk.reg);
2008 *ctx++ = clk_readl(tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2009
2010 *ctx++ = clk_readl(tegra_clk_sclk.reg);
2011 *ctx++ = clk_readl(tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2012 *ctx++ = clk_readl(tegra_clk_pclk.reg);
Colin Cross71fc84c2010-06-07 20:49:46 -07002013
2014 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2015 off += 4) {
2016 if (off == PERIPH_CLK_SOURCE_EMC)
2017 continue;
2018 *ctx++ = clk_readl(off);
2019 }
2020
2021 off = RST_DEVICES;
2022 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2023 *ctx++ = clk_readl(off);
2024
2025 off = CLK_OUT_ENB;
2026 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2027 *ctx++ = clk_readl(off);
2028
2029 *ctx++ = clk_readl(MISC_CLK_ENB);
2030 *ctx++ = clk_readl(CLK_MASK_ARM);
2031}
2032
2033void tegra_clk_resume(void)
2034{
2035 unsigned long off, i;
2036 const u32 *ctx = clk_rst_suspend;
2037 u32 val;
2038
2039 val = clk_readl(OSC_CTRL) & ~OSC_CTRL_MASK;
2040 val |= *ctx++;
2041 clk_writel(val, OSC_CTRL);
2042
Colin Crosscea62c82010-10-04 11:49:26 -07002043 clk_writel(*ctx++, tegra_pll_p.reg + PLL_BASE);
2044 clk_writel(*ctx++, tegra_pll_p.reg + PLL_MISC(&tegra_pll_p));
2045 clk_writel(*ctx++, tegra_pll_c.reg + PLL_BASE);
2046 clk_writel(*ctx++, tegra_pll_c.reg + PLL_MISC(&tegra_pll_c));
2047 clk_writel(*ctx++, tegra_pll_a.reg + PLL_BASE);
2048 clk_writel(*ctx++, tegra_pll_a.reg + PLL_MISC(&tegra_pll_a));
2049 udelay(300);
2050
2051 clk_writel(*ctx++, tegra_pll_m_out1.reg);
2052 clk_writel(*ctx++, tegra_pll_p_out1.reg);
2053 clk_writel(*ctx++, tegra_pll_p_out3.reg);
2054 clk_writel(*ctx++, tegra_pll_a_out0.reg);
2055 clk_writel(*ctx++, tegra_pll_c_out1.reg);
2056
2057 clk_writel(*ctx++, tegra_clk_cclk.reg);
2058 clk_writel(*ctx++, tegra_clk_cclk.reg + SUPER_CLK_DIVIDER);
2059
2060 clk_writel(*ctx++, tegra_clk_sclk.reg);
2061 clk_writel(*ctx++, tegra_clk_sclk.reg + SUPER_CLK_DIVIDER);
2062 clk_writel(*ctx++, tegra_clk_pclk.reg);
2063
Colin Cross71fc84c2010-06-07 20:49:46 -07002064 /* enable all clocks before configuring clock sources */
2065 clk_writel(0xbffffff9ul, CLK_OUT_ENB);
2066 clk_writel(0xfefffff7ul, CLK_OUT_ENB + 4);
2067 clk_writel(0x77f01bfful, CLK_OUT_ENB + 8);
2068 wmb();
2069
2070 for (off = PERIPH_CLK_SOURCE_I2S1; off <= PERIPH_CLK_SOURCE_OSC;
2071 off += 4) {
2072 if (off == PERIPH_CLK_SOURCE_EMC)
2073 continue;
2074 clk_writel(*ctx++, off);
2075 }
2076 wmb();
2077
2078 off = RST_DEVICES;
2079 for (i = 0; i < RST_DEVICES_NUM; i++, off += 4)
2080 clk_writel(*ctx++, off);
2081 wmb();
2082
2083 off = CLK_OUT_ENB;
2084 for (i = 0; i < CLK_OUT_ENB_NUM; i++, off += 4)
2085 clk_writel(*ctx++, off);
2086 wmb();
2087
2088 clk_writel(*ctx++, MISC_CLK_ENB);
2089 clk_writel(*ctx++, CLK_MASK_ARM);
2090}
2091#endif