aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-tegra
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-tegra')
-rw-r--r--arch/arm/mach-tegra/Makefile2
-rw-r--r--arch/arm/mach-tegra/clock.c488
-rw-r--r--arch/arm/mach-tegra/clock.h147
-rw-r--r--arch/arm/mach-tegra/common.c17
-rw-r--r--arch/arm/mach-tegra/include/mach/clk.h26
-rw-r--r--arch/arm/mach-tegra/include/mach/clkdev.h32
-rw-r--r--arch/arm/mach-tegra/tegra2_clocks.c1359
7 files changed, 2071 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/Makefile b/arch/arm/mach-tegra/Makefile
index a0d2c5ba6cd4..e20546ab2f5f 100644
--- a/arch/arm/mach-tegra/Makefile
+++ b/arch/arm/mach-tegra/Makefile
@@ -1,3 +1,5 @@
1obj-y += common.o 1obj-y += common.o
2obj-y += io.o 2obj-y += io.o
3obj-y += irq.o 3obj-y += irq.o
4obj-y += clock.o
5obj-$(CONFIG_ARCH_TEGRA_2x_SOC) += tegra2_clocks.o
diff --git a/arch/arm/mach-tegra/clock.c b/arch/arm/mach-tegra/clock.c
new file mode 100644
index 000000000000..03ad578349b9
--- /dev/null
+++ b/arch/arm/mach-tegra/clock.c
@@ -0,0 +1,488 @@
1/*
2 *
3 * Copyright (C) 2010 Google, Inc.
4 *
5 * Author:
6 * Colin Cross <ccross@google.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19#include <linux/kernel.h>
20#include <linux/clk.h>
21#include <linux/list.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/debugfs.h>
25#include <linux/slab.h>
26#include <linux/seq_file.h>
27#include <asm/clkdev.h>
28
29#include "clock.h"
30
31static LIST_HEAD(clocks);
32
33static DEFINE_SPINLOCK(clock_lock);
34
35struct clk *tegra_get_clock_by_name(const char *name)
36{
37 struct clk *c;
38 struct clk *ret = NULL;
39 unsigned long flags;
40 spin_lock_irqsave(&clock_lock, flags);
41 list_for_each_entry(c, &clocks, node) {
42 if (strcmp(c->name, name) == 0) {
43 ret = c;
44 break;
45 }
46 }
47 spin_unlock_irqrestore(&clock_lock, flags);
48 return ret;
49}
50
51int clk_reparent(struct clk *c, struct clk *parent)
52{
53 pr_debug("%s: %s\n", __func__, c->name);
54 if (c->refcnt && c->parent)
55 clk_disable_locked(c->parent);
56 c->parent = parent;
57 if (c->refcnt && c->parent)
58 clk_enable_locked(c->parent);
59 list_del(&c->sibling);
60 list_add_tail(&c->sibling, &parent->children);
61 return 0;
62}
63
64static void propagate_rate(struct clk *c)
65{
66 struct clk *clkp;
67 pr_debug("%s: %s\n", __func__, c->name);
68 list_for_each_entry(clkp, &c->children, sibling) {
69 pr_debug(" %s\n", clkp->name);
70 if (clkp->ops->recalculate_rate)
71 clkp->ops->recalculate_rate(clkp);
72 propagate_rate(clkp);
73 }
74}
75
76void clk_init(struct clk *c)
77{
78 unsigned long flags;
79
80 spin_lock_irqsave(&clock_lock, flags);
81
82 INIT_LIST_HEAD(&c->children);
83 INIT_LIST_HEAD(&c->sibling);
84
85 if (c->ops && c->ops->init)
86 c->ops->init(c);
87
88 list_add(&c->node, &clocks);
89
90 if (c->parent)
91 list_add_tail(&c->sibling, &c->parent->children);
92
93 spin_unlock_irqrestore(&clock_lock, flags);
94}
95
96int clk_enable_locked(struct clk *c)
97{
98 int ret;
99 pr_debug("%s: %s\n", __func__, c->name);
100 if (c->refcnt == 0) {
101 if (c->parent) {
102 ret = clk_enable_locked(c->parent);
103 if (ret)
104 return ret;
105 }
106
107 if (c->ops && c->ops->enable) {
108 ret = c->ops->enable(c);
109 if (ret) {
110 if (c->parent)
111 clk_disable_locked(c->parent);
112 return ret;
113 }
114 c->state = ON;
115#ifdef CONFIG_DEBUG_FS
116 c->set = 1;
117#endif
118 }
119 }
120 c->refcnt++;
121
122 return 0;
123}
124
125int clk_enable(struct clk *c)
126{
127 int ret;
128 unsigned long flags;
129 spin_lock_irqsave(&clock_lock, flags);
130 ret = clk_enable_locked(c);
131 spin_unlock_irqrestore(&clock_lock, flags);
132 return ret;
133}
134EXPORT_SYMBOL(clk_enable);
135
136void clk_disable_locked(struct clk *c)
137{
138 pr_debug("%s: %s\n", __func__, c->name);
139 if (c->refcnt == 0) {
140 WARN(1, "Attempting to disable clock %s with refcnt 0", c->name);
141 return;
142 }
143 if (c->refcnt == 1) {
144 if (c->ops && c->ops->disable)
145 c->ops->disable(c);
146
147 if (c->parent)
148 clk_disable_locked(c->parent);
149
150 c->state = OFF;
151 }
152 c->refcnt--;
153}
154
155void clk_disable(struct clk *c)
156{
157 unsigned long flags;
158 spin_lock_irqsave(&clock_lock, flags);
159 clk_disable_locked(c);
160 spin_unlock_irqrestore(&clock_lock, flags);
161}
162EXPORT_SYMBOL(clk_disable);
163
164int clk_set_parent_locked(struct clk *c, struct clk *parent)
165{
166 int ret;
167
168 pr_debug("%s: %s\n", __func__, c->name);
169
170 if (!c->ops || !c->ops->set_parent)
171 return -ENOSYS;
172
173 ret = c->ops->set_parent(c, parent);
174
175 if (ret)
176 return ret;
177
178 propagate_rate(c);
179
180 return 0;
181}
182
183int clk_set_parent(struct clk *c, struct clk *parent)
184{
185 int ret;
186 unsigned long flags;
187 spin_lock_irqsave(&clock_lock, flags);
188 ret = clk_set_parent_locked(c, parent);
189 spin_unlock_irqrestore(&clock_lock, flags);
190 return ret;
191}
192EXPORT_SYMBOL(clk_set_parent);
193
194struct clk *clk_get_parent(struct clk *c)
195{
196 return c->parent;
197}
198EXPORT_SYMBOL(clk_get_parent);
199
200int clk_set_rate(struct clk *c, unsigned long rate)
201{
202 int ret = 0;
203 unsigned long flags;
204
205 spin_lock_irqsave(&clock_lock, flags);
206
207 pr_debug("%s: %s\n", __func__, c->name);
208
209 if (c->ops && c->ops->set_rate)
210 ret = c->ops->set_rate(c, rate);
211 else
212 ret = -ENOSYS;
213
214 propagate_rate(c);
215
216 spin_unlock_irqrestore(&clock_lock, flags);
217
218 return ret;
219}
220EXPORT_SYMBOL(clk_set_rate);
221
222unsigned long clk_get_rate(struct clk *c)
223{
224 unsigned long flags;
225 unsigned long ret;
226
227 spin_lock_irqsave(&clock_lock, flags);
228
229 pr_debug("%s: %s\n", __func__, c->name);
230
231 ret = c->rate;
232
233 spin_unlock_irqrestore(&clock_lock, flags);
234 return ret;
235}
236EXPORT_SYMBOL(clk_get_rate);
237
238static int tegra_clk_init_one_from_table(struct tegra_clk_init_table *table)
239{
240 struct clk *c;
241 struct clk *p;
242
243 int ret = 0;
244
245 c = tegra_get_clock_by_name(table->name);
246
247 if (!c) {
248 pr_warning("Unable to initialize clock %s\n",
249 table->name);
250 return -ENODEV;
251 }
252
253 if (table->parent) {
254 p = tegra_get_clock_by_name(table->parent);
255 if (!p) {
256 pr_warning("Unable to find parent %s of clock %s\n",
257 table->parent, table->name);
258 return -ENODEV;
259 }
260
261 if (c->parent != p) {
262 ret = clk_set_parent(c, p);
263 if (ret) {
264 pr_warning("Unable to set parent %s of clock %s: %d\n",
265 table->parent, table->name, ret);
266 return -EINVAL;
267 }
268 }
269 }
270
271 if (table->rate && table->rate != clk_get_rate(c)) {
272 ret = clk_set_rate(c, table->rate);
273 if (ret) {
274 pr_warning("Unable to set clock %s to rate %lu: %d\n",
275 table->name, table->rate, ret);
276 return -EINVAL;
277 }
278 }
279
280 if (table->enabled) {
281 ret = clk_enable(c);
282 if (ret) {
283 pr_warning("Unable to enable clock %s: %d\n",
284 table->name, ret);
285 return -EINVAL;
286 }
287 }
288
289 return 0;
290}
291
292void tegra_clk_init_from_table(struct tegra_clk_init_table *table)
293{
294 for (; table->name; table++)
295 tegra_clk_init_one_from_table(table);
296}
297EXPORT_SYMBOL(tegra_clk_init_from_table);
298
299void tegra_periph_reset_deassert(struct clk *c)
300{
301 tegra2_periph_reset_deassert(c);
302}
303EXPORT_SYMBOL(tegra_periph_reset_deassert);
304
305void tegra_periph_reset_assert(struct clk *c)
306{
307 tegra2_periph_reset_assert(c);
308}
309EXPORT_SYMBOL(tegra_periph_reset_assert);
310
311int __init tegra_init_clock(void)
312{
313 tegra2_init_clocks();
314
315 return 0;
316}
317
318#ifdef CONFIG_DEBUG_FS
319static struct dentry *clk_debugfs_root;
320
321
322static void clock_tree_show_one(struct seq_file *s, struct clk *c, int level)
323{
324 struct clk *child;
325 struct clk *safe;
326 const char *state = "uninit";
327 char div[5] = {0};
328
329 if (c->state == ON)
330 state = "on";
331 else if (c->state == OFF)
332 state = "off";
333
334 if (c->mul != 0 && c->div != 0) {
335 BUG_ON(c->mul > 2);
336 if (c->mul > c->div)
337 snprintf(div, sizeof(div), "x%d", c->mul / c->div);
338 else
339 snprintf(div, sizeof(div), "%d%s", c->div / c->mul,
340 (c->div % c->mul) ? ".5" : "");
341 }
342
343 seq_printf(s, "%*s%-*s %-6s %-3d %-5s %-10lu\n",
344 level * 3 + 1, c->set ? "" : "*",
345 30 - level * 3, c->name,
346 state, c->refcnt, div, c->rate);
347 list_for_each_entry_safe(child, safe, &c->children, sibling) {
348 clock_tree_show_one(s, child, level + 1);
349 }
350}
351
352static int clock_tree_show(struct seq_file *s, void *data)
353{
354 struct clk *c;
355 unsigned long flags;
356 seq_printf(s, " clock state ref div rate \n");
357 seq_printf(s, "-----------------------------------------------------------\n");
358 spin_lock_irqsave(&clock_lock, flags);
359 list_for_each_entry(c, &clocks, node)
360 if (c->parent == NULL)
361 clock_tree_show_one(s, c, 0);
362 spin_unlock_irqrestore(&clock_lock, flags);
363 return 0;
364}
365
366static int clock_tree_open(struct inode *inode, struct file *file)
367{
368 return single_open(file, clock_tree_show, inode->i_private);
369}
370
371static const struct file_operations clock_tree_fops = {
372 .open = clock_tree_open,
373 .read = seq_read,
374 .llseek = seq_lseek,
375 .release = single_release,
376};
377
378static int possible_parents_show(struct seq_file *s, void *data)
379{
380 struct clk *c = s->private;
381 int i;
382
383 for (i = 0; c->inputs[i].input; i++) {
384 char *first = (i == 0) ? "" : " ";
385 seq_printf(s, "%s%s", first, c->inputs[i].input->name);
386 }
387 seq_printf(s, "\n");
388 return 0;
389}
390
391static int possible_parents_open(struct inode *inode, struct file *file)
392{
393 return single_open(file, possible_parents_show, inode->i_private);
394}
395
396static const struct file_operations possible_parents_fops = {
397 .open = possible_parents_open,
398 .read = seq_read,
399 .llseek = seq_lseek,
400 .release = single_release,
401};
402
403static int clk_debugfs_register_one(struct clk *c)
404{
405 struct dentry *d, *child, *child_tmp;
406
407 d = debugfs_create_dir(c->name, clk_debugfs_root);
408 if (!d)
409 return -ENOMEM;
410 c->dent = d;
411
412 d = debugfs_create_u8("refcnt", S_IRUGO, c->dent, (u8 *)&c->refcnt);
413 if (!d)
414 goto err_out;
415
416 d = debugfs_create_u32("rate", S_IRUGO, c->dent, (u32 *)&c->rate);
417 if (!d)
418 goto err_out;
419
420 d = debugfs_create_x32("flags", S_IRUGO, c->dent, (u32 *)&c->flags);
421 if (!d)
422 goto err_out;
423
424 if (c->inputs) {
425 d = debugfs_create_file("possible_parents", S_IRUGO, c->dent,
426 c, &possible_parents_fops);
427 if (!d)
428 goto err_out;
429 }
430
431 return 0;
432
433err_out:
434 d = c->dent;
435 list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
436 debugfs_remove(child);
437 debugfs_remove(c->dent);
438 return -ENOMEM;
439}
440
441static int clk_debugfs_register(struct clk *c)
442{
443 int err;
444 struct clk *pa = c->parent;
445
446 if (pa && !pa->dent) {
447 err = clk_debugfs_register(pa);
448 if (err)
449 return err;
450 }
451
452 if (!c->dent) {
453 err = clk_debugfs_register_one(c);
454 if (err)
455 return err;
456 }
457 return 0;
458}
459
460static int __init clk_debugfs_init(void)
461{
462 struct clk *c;
463 struct dentry *d;
464 int err = -ENOMEM;
465
466 d = debugfs_create_dir("clock", NULL);
467 if (!d)
468 return -ENOMEM;
469 clk_debugfs_root = d;
470
471 d = debugfs_create_file("clock_tree", S_IRUGO, clk_debugfs_root, NULL,
472 &clock_tree_fops);
473 if (!d)
474 goto err_out;
475
476 list_for_each_entry(c, &clocks, node) {
477 err = clk_debugfs_register(c);
478 if (err)
479 goto err_out;
480 }
481 return 0;
482err_out:
483 debugfs_remove_recursive(clk_debugfs_root);
484 return err;
485}
486
487late_initcall(clk_debugfs_init);
488#endif
diff --git a/arch/arm/mach-tegra/clock.h b/arch/arm/mach-tegra/clock.h
new file mode 100644
index 000000000000..af7c70e2a3ba
--- /dev/null
+++ b/arch/arm/mach-tegra/clock.h
@@ -0,0 +1,147 @@
1/*
2 * arch/arm/mach-tegra/include/mach/clock.h
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#ifndef __MACH_TEGRA_CLOCK_H
21#define __MACH_TEGRA_CLOCK_H
22
23#include <linux/list.h>
24#include <asm/clkdev.h>
25
26#define DIV_BUS (1 << 0)
27#define DIV_U71 (1 << 1)
28#define DIV_U71_FIXED (1 << 2)
29#define DIV_2 (1 << 3)
30#define PLL_FIXED (1 << 4)
31#define PLL_HAS_CPCON (1 << 5)
32#define MUX (1 << 6)
33#define PLLD (1 << 7)
34#define PERIPH_NO_RESET (1 << 8)
35#define PERIPH_NO_ENB (1 << 9)
36#define PERIPH_EMC_ENB (1 << 10)
37#define PERIPH_MANUAL_RESET (1 << 11)
38#define PLL_ALT_MISC_REG (1 << 12)
39#define ENABLE_ON_INIT (1 << 28)
40
41struct clk;
42
43struct clk_mux_sel {
44 struct clk *input;
45 u32 value;
46};
47
48struct clk_pll_table {
49 unsigned long input_rate;
50 unsigned long output_rate;
51 u16 n;
52 u16 m;
53 u8 p;
54 u8 cpcon;
55};
56
57struct clk_ops {
58 void (*init)(struct clk *);
59 int (*enable)(struct clk *);
60 void (*disable)(struct clk *);
61 void (*recalc)(struct clk *);
62 int (*set_parent)(struct clk *, struct clk *);
63 int (*set_rate)(struct clk *, unsigned long);
64 unsigned long (*get_rate)(struct clk *);
65 long (*round_rate)(struct clk *, unsigned long);
66 unsigned long (*recalculate_rate)(struct clk *);
67};
68
69enum clk_state {
70 UNINITIALIZED = 0,
71 ON,
72 OFF,
73};
74
75struct clk {
76 /* node for master clocks list */
77 struct list_head node;
78 struct list_head children; /* list of children */
79 struct list_head sibling; /* node for children */
80#ifdef CONFIG_DEBUG_FS
81 struct dentry *dent;
82 struct dentry *parent_dent;
83#endif
84 struct clk_ops *ops;
85 struct clk *parent;
86 struct clk_lookup lookup;
87 unsigned long rate;
88 u32 flags;
89 u32 refcnt;
90 const char *name;
91 u32 reg;
92 u32 reg_shift;
93 unsigned int clk_num;
94 enum clk_state state;
95#ifdef CONFIG_DEBUG_FS
96 bool set;
97#endif
98
99 /* PLL */
100 unsigned long input_min;
101 unsigned long input_max;
102 unsigned long cf_min;
103 unsigned long cf_max;
104 unsigned long vco_min;
105 unsigned long vco_max;
106 u32 m;
107 u32 n;
108 u32 p;
109 u32 cpcon;
110 const struct clk_pll_table *pll_table;
111
112 /* DIV */
113 u32 div;
114 u32 mul;
115
116 /* MUX */
117 const struct clk_mux_sel *inputs;
118 u32 sel;
119 u32 reg_mask;
120};
121
122
123struct clk_duplicate {
124 const char *name;
125 struct clk_lookup lookup;
126};
127
128struct tegra_clk_init_table {
129 const char *name;
130 const char *parent;
131 unsigned long rate;
132 bool enabled;
133};
134
135void tegra2_init_clocks(void);
136void tegra2_periph_reset_deassert(struct clk *c);
137void tegra2_periph_reset_assert(struct clk *c);
138void clk_init(struct clk *clk);
139struct clk *tegra_get_clock_by_name(const char *name);
140unsigned long clk_measure_input_freq(void);
141void clk_disable_locked(struct clk *c);
142int clk_enable_locked(struct clk *c);
143int clk_set_parent_locked(struct clk *c, struct clk *parent);
144int clk_reparent(struct clk *c, struct clk *parent);
145void tegra_clk_init_from_table(struct tegra_clk_init_table *table);
146
147#endif
diff --git a/arch/arm/mach-tegra/common.c b/arch/arm/mach-tegra/common.c
index 20875ee8f039..039a514b61ef 100644
--- a/arch/arm/mach-tegra/common.c
+++ b/arch/arm/mach-tegra/common.c
@@ -25,6 +25,21 @@
25#include <mach/iomap.h> 25#include <mach/iomap.h>
26 26
27#include "board.h" 27#include "board.h"
28#include "clock.h"
29
30static __initdata struct tegra_clk_init_table common_clk_init_table[] = {
31 /* name parent rate enabled */
32 { "clk_m", NULL, 0, true },
33 { "pll_p", "clk_m", 216000000, true },
34 { "pll_p_out1", "pll_p", 28800000, true },
35 { "pll_p_out2", "pll_p", 48000000, true },
36 { "pll_p_out3", "pll_p", 72000000, true },
37 { "pll_p_out4", "pll_p", 108000000, true },
38 { "sys", "pll_p_out4", 108000000, true },
39 { "hclk", "sys", 108000000, true },
40 { "pclk", "hclk", 54000000, true },
41 { NULL, NULL, 0, 0},
42};
28 43
29void __init tegra_init_cache(void) 44void __init tegra_init_cache(void)
30{ 45{
@@ -40,5 +55,7 @@ void __init tegra_init_cache(void)
40 55
41void __init tegra_common_init(void) 56void __init tegra_common_init(void)
42{ 57{
58 tegra_init_clock();
59 tegra_clk_init_from_table(common_clk_init_table);
43 tegra_init_cache(); 60 tegra_init_cache();
44} 61}
diff --git a/arch/arm/mach-tegra/include/mach/clk.h b/arch/arm/mach-tegra/include/mach/clk.h
new file mode 100644
index 000000000000..2896f25ebfb5
--- /dev/null
+++ b/arch/arm/mach-tegra/include/mach/clk.h
@@ -0,0 +1,26 @@
1/*
2 * arch/arm/mach-tegra/include/mach/clk.h
3 *
4 * Copyright (C) 2010 Google, Inc.
5 *
6 * Author:
7 * Erik Gilling <konkers@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#ifndef __MACH_CLK_H
21#define __MACH_CLK_H
22
23void tegra_periph_reset_deassert(struct clk *c);
24void tegra_periph_reset_assert(struct clk *c);
25
26#endif
diff --git a/arch/arm/mach-tegra/include/mach/clkdev.h b/arch/arm/mach-tegra/include/mach/clkdev.h
new file mode 100644
index 000000000000..412f5c63e65a
--- /dev/null
+++ b/arch/arm/mach-tegra/include/mach/clkdev.h
@@ -0,0 +1,32 @@
1/*
2 * arch/arm/mach-tegra/include/mach/clkdev.h
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#ifndef __MACH_CLKDEV_H
21#define __MACH_CLKDEV_H
22
23static inline int __clk_get(struct clk *clk)
24{
25 return 1;
26}
27
28static inline void __clk_put(struct clk *clk)
29{
30}
31
32#endif
diff --git a/arch/arm/mach-tegra/tegra2_clocks.c b/arch/arm/mach-tegra/tegra2_clocks.c
new file mode 100644
index 000000000000..426163231fff
--- /dev/null
+++ b/arch/arm/mach-tegra/tegra2_clocks.c
@@ -0,0 +1,1359 @@
1/*
2 * arch/arm/mach-tegra/tegra2_clocks.c
3 *
4 * Copyright (C) 2010 Google, Inc.
5 *
6 * Author:
7 * Colin Cross <ccross@google.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/list.h>
23#include <linux/spinlock.h>
24#include <linux/delay.h>
25#include <linux/io.h>
26#include <linux/hrtimer.h>
27
28#include <asm/clkdev.h>
29
30#include <mach/iomap.h>
31
32#include "clock.h"
33
34#define RST_DEVICES 0x004
35#define RST_DEVICES_SET 0x300
36#define RST_DEVICES_CLR 0x304
37
38#define CLK_OUT_ENB 0x010
39#define CLK_OUT_ENB_SET 0x320
40#define CLK_OUT_ENB_CLR 0x324
41
42#define OSC_CTRL 0x50
43#define OSC_CTRL_OSC_FREQ_MASK (3<<30)
44#define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
45#define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
46#define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
47#define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
48
49#define OSC_FREQ_DET 0x58
50#define OSC_FREQ_DET_TRIG (1<<31)
51
52#define OSC_FREQ_DET_STATUS 0x5C
53#define OSC_FREQ_DET_BUSY (1<<31)
54#define OSC_FREQ_DET_CNT_MASK 0xFFFF
55
56#define PERIPH_CLK_SOURCE_MASK (3<<30)
57#define PERIPH_CLK_SOURCE_SHIFT 30
58#define PERIPH_CLK_SOURCE_ENABLE (1<<28)
59#define PERIPH_CLK_SOURCE_DIV_MASK 0xFF
60#define PERIPH_CLK_SOURCE_DIV_SHIFT 0
61
62#define PLL_BASE 0x0
63#define PLL_BASE_BYPASS (1<<31)
64#define PLL_BASE_ENABLE (1<<30)
65#define PLL_BASE_REF_ENABLE (1<<29)
66#define PLL_BASE_OVERRIDE (1<<28)
67#define PLL_BASE_LOCK (1<<27)
68#define PLL_BASE_DIVP_MASK (0x7<<20)
69#define PLL_BASE_DIVP_SHIFT 20
70#define PLL_BASE_DIVN_MASK (0x3FF<<8)
71#define PLL_BASE_DIVN_SHIFT 8
72#define PLL_BASE_DIVM_MASK (0x1F)
73#define PLL_BASE_DIVM_SHIFT 0
74
75#define PLL_OUT_RATIO_MASK (0xFF<<8)
76#define PLL_OUT_RATIO_SHIFT 8
77#define PLL_OUT_OVERRIDE (1<<2)
78#define PLL_OUT_CLKEN (1<<1)
79#define PLL_OUT_RESET_DISABLE (1<<0)
80
81#define PLL_MISC(c) (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc)
82#define PLL_MISC_DCCON_SHIFT 20
83#define PLL_MISC_LOCK_ENABLE (1<<18)
84#define PLL_MISC_CPCON_SHIFT 8
85#define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT)
86#define PLL_MISC_LFCON_SHIFT 4
87#define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT)
88#define PLL_MISC_VCOCON_SHIFT 0
89#define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT)
90
91#define PLLD_MISC_CLKENABLE (1<<30)
92#define PLLD_MISC_DIV_RST (1<<23)
93#define PLLD_MISC_DCCON_SHIFT 12
94
95#define PERIPH_CLK_TO_ENB_REG(c) ((c->clk_num / 32) * 4)
96#define PERIPH_CLK_TO_ENB_SET_REG(c) ((c->clk_num / 32) * 8)
97#define PERIPH_CLK_TO_ENB_BIT(c) (1 << (c->clk_num % 32))
98
99#define SUPER_CLK_MUX 0x00
100#define SUPER_STATE_SHIFT 28
101#define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT)
102#define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT)
103#define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT)
104#define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT)
105#define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT)
106#define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT)
107#define SUPER_SOURCE_MASK 0xF
108#define SUPER_FIQ_SOURCE_SHIFT 12
109#define SUPER_IRQ_SOURCE_SHIFT 8
110#define SUPER_RUN_SOURCE_SHIFT 4
111#define SUPER_IDLE_SOURCE_SHIFT 0
112
113#define SUPER_CLK_DIVIDER 0x04
114
115#define BUS_CLK_DISABLE (1<<3)
116#define BUS_CLK_DIV_MASK 0x3
117
118static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE);
119
120#define clk_writel(value, reg) \
121 __raw_writel(value, (u32)reg_clk_base + (reg))
122#define clk_readl(reg) \
123 __raw_readl((u32)reg_clk_base + (reg))
124
125unsigned long clk_measure_input_freq(void)
126{
127 u32 clock_autodetect;
128 clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET);
129 do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY);
130 clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS);
131 if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) {
132 return 12000000;
133 } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) {
134 return 13000000;
135 } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) {
136 return 19200000;
137 } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) {
138 return 26000000;
139 } else {
140 pr_err("%s: Unexpected clock autodetect value %d", __func__, clock_autodetect);
141 BUG();
142 return 0;
143 }
144}
145
146static int clk_div71_get_divider(struct clk *c, unsigned long rate)
147{
148 unsigned long divider_u71;
149
150 divider_u71 = DIV_ROUND_UP(c->rate * 2, rate);
151
152 if (divider_u71 - 2 > 255 || divider_u71 - 2 < 0)
153 return -EINVAL;
154
155 return divider_u71 - 2;
156}
157
158static unsigned long tegra2_clk_recalculate_rate(struct clk *c)
159{
160 unsigned long rate;
161 rate = c->parent->rate;
162
163 if (c->mul != 0 && c->div != 0)
164 c->rate = rate * c->mul / c->div;
165 else
166 c->rate = rate;
167 return c->rate;
168}
169
170
171/* clk_m functions */
172static unsigned long tegra2_clk_m_autodetect_rate(struct clk *c)
173{
174 u32 auto_clock_control = clk_readl(OSC_CTRL) & ~OSC_CTRL_OSC_FREQ_MASK;
175
176 c->rate = clk_measure_input_freq();
177 switch (c->rate) {
178 case 12000000:
179 auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ;
180 break;
181 case 13000000:
182 auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ;
183 break;
184 case 19200000:
185 auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ;
186 break;
187 case 26000000:
188 auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ;
189 break;
190 default:
191 pr_err("%s: Unexpected clock rate %ld", __func__, c->rate);
192 BUG();
193 }
194 clk_writel(auto_clock_control, OSC_CTRL);
195 return c->rate;
196}
197
198static void tegra2_clk_m_init(struct clk *c)
199{
200 pr_debug("%s on clock %s\n", __func__, c->name);
201 tegra2_clk_m_autodetect_rate(c);
202}
203
204static int tegra2_clk_m_enable(struct clk *c)
205{
206 pr_debug("%s on clock %s\n", __func__, c->name);
207 return 0;
208}
209
210static void tegra2_clk_m_disable(struct clk *c)
211{
212 pr_debug("%s on clock %s\n", __func__, c->name);
213 BUG();
214}
215
216static struct clk_ops tegra_clk_m_ops = {
217 .init = tegra2_clk_m_init,
218 .enable = tegra2_clk_m_enable,
219 .disable = tegra2_clk_m_disable,
220};
221
222/* super clock functions */
223/* "super clocks" on tegra have two-stage muxes and a clock skipping
224 * super divider. We will ignore the clock skipping divider, since we
225 * can't lower the voltage when using the clock skip, but we can if we
226 * lower the PLL frequency.
227 */
228static void tegra2_super_clk_init(struct clk *c)
229{
230 u32 val;
231 int source;
232 int shift;
233 const struct clk_mux_sel *sel;
234 val = clk_readl(c->reg + SUPER_CLK_MUX);
235 c->state = ON;
236 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
237 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
238 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
239 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
240 source = (val >> shift) & SUPER_SOURCE_MASK;
241 for (sel = c->inputs; sel->input != NULL; sel++) {
242 if (sel->value == source)
243 break;
244 }
245 BUG_ON(sel->input == NULL);
246 c->parent = sel->input;
247 tegra2_clk_recalculate_rate(c);
248}
249
250static int tegra2_super_clk_enable(struct clk *c)
251{
252 clk_writel(0, c->reg + SUPER_CLK_DIVIDER);
253 return 0;
254}
255
256static void tegra2_super_clk_disable(struct clk *c)
257{
258 pr_debug("%s on clock %s\n", __func__, c->name);
259
260 /* oops - don't disable the CPU clock! */
261 BUG();
262}
263
264static int tegra2_super_clk_set_parent(struct clk *c, struct clk *p)
265{
266 u32 val;
267 const struct clk_mux_sel *sel;
268 int shift;
269 val = clk_readl(c->reg + SUPER_CLK_MUX);;
270 BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) &&
271 ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE));
272 shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ?
273 SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT;
274 for (sel = c->inputs; sel->input != NULL; sel++) {
275 if (sel->input == p) {
276 clk_reparent(c, p);
277 val &= ~(SUPER_SOURCE_MASK << shift);
278 val |= sel->value << shift;
279 clk_writel(val, c->reg);
280 c->rate = c->parent->rate;
281 return 0;
282 }
283 }
284 return -EINVAL;
285}
286
287static struct clk_ops tegra_super_ops = {
288 .init = tegra2_super_clk_init,
289 .enable = tegra2_super_clk_enable,
290 .disable = tegra2_super_clk_disable,
291 .set_parent = tegra2_super_clk_set_parent,
292 .recalculate_rate = tegra2_clk_recalculate_rate,
293};
294
295/* bus clock functions */
296static void tegra2_bus_clk_init(struct clk *c)
297{
298 u32 val = clk_readl(c->reg);
299 c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON;
300 c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1;
301 c->mul = 1;
302 tegra2_clk_recalculate_rate(c);
303}
304
305static int tegra2_bus_clk_enable(struct clk *c)
306{
307 u32 val = clk_readl(c->reg);
308 val &= ~(BUS_CLK_DISABLE << c->reg_shift);
309 clk_writel(val, c->reg);
310 return 0;
311}
312
313static void tegra2_bus_clk_disable(struct clk *c)
314{
315 u32 val = clk_readl(c->reg);
316 val |= BUS_CLK_DISABLE << c->reg_shift;
317 clk_writel(val, c->reg);
318}
319
320static int tegra2_bus_clk_set_rate(struct clk *c, unsigned long rate)
321{
322 u32 val = clk_readl(c->reg);
323 unsigned long parent_rate = c->parent->rate;
324 int i;
325 for (i = 1; i <= 4; i++) {
326 if (rate == parent_rate / i) {
327 val &= ~(BUS_CLK_DIV_MASK << c->reg_shift);
328 val |= (i - 1) << c->reg_shift;
329 clk_writel(val, c->reg);
330 c->div = i;
331 c->mul = 1;
332 return 0;
333 }
334 }
335 return -EINVAL;
336}
337
338static struct clk_ops tegra_bus_ops = {
339 .init = tegra2_bus_clk_init,
340 .enable = tegra2_bus_clk_enable,
341 .disable = tegra2_bus_clk_disable,
342 .set_rate = tegra2_bus_clk_set_rate,
343 .recalculate_rate = tegra2_clk_recalculate_rate,
344};
345
346/* PLL Functions */
347static unsigned long tegra2_pll_clk_recalculate_rate(struct clk *c)
348{
349 u64 rate;
350 rate = c->parent->rate;
351 rate *= c->n;
352 do_div(rate, c->m);
353 if (c->p == 2)
354 rate >>= 1;
355 c->rate = rate;
356 return c->rate;
357}
358
359static int tegra2_pll_clk_wait_for_lock(struct clk *c)
360{
361 ktime_t before;
362
363 before = ktime_get();
364 while (!(clk_readl(c->reg + PLL_BASE) & PLL_BASE_LOCK)) {
365 if (ktime_us_delta(ktime_get(), before) > 5000) {
366 pr_err("Timed out waiting for lock bit on pll %s",
367 c->name);
368 return -1;
369 }
370 }
371
372 return 0;
373}
374
375static void tegra2_pll_clk_init(struct clk *c)
376{
377 u32 val = clk_readl(c->reg + PLL_BASE);
378
379 c->state = (val & PLL_BASE_ENABLE) ? ON : OFF;
380
381 if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) {
382 pr_warning("Clock %s has unknown fixed frequency\n", c->name);
383 c->n = 1;
384 c->m = 0;
385 c->p = 1;
386 } else if (val & PLL_BASE_BYPASS) {
387 c->n = 1;
388 c->m = 1;
389 c->p = 1;
390 } else {
391 c->n = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT;
392 c->m = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT;
393 c->p = (val & PLL_BASE_DIVP_MASK) ? 2 : 1;
394 }
395
396 val = clk_readl(c->reg + PLL_MISC(c));
397 if (c->flags & PLL_HAS_CPCON)
398 c->cpcon = (val & PLL_MISC_CPCON_MASK) >> PLL_MISC_CPCON_SHIFT;
399
400 tegra2_pll_clk_recalculate_rate(c);
401}
402
403static int tegra2_pll_clk_enable(struct clk *c)
404{
405 u32 val;
406 pr_debug("%s on clock %s\n", __func__, c->name);
407
408 val = clk_readl(c->reg + PLL_BASE);
409 val &= ~PLL_BASE_BYPASS;
410 val |= PLL_BASE_ENABLE;
411 clk_writel(val, c->reg + PLL_BASE);
412
413 val = clk_readl(c->reg + PLL_MISC(c));
414 val |= PLL_MISC_LOCK_ENABLE;
415 clk_writel(val, c->reg + PLL_MISC(c));
416
417 tegra2_pll_clk_wait_for_lock(c);
418
419 return 0;
420}
421
422static void tegra2_pll_clk_disable(struct clk *c)
423{
424 u32 val;
425 pr_debug("%s on clock %s\n", __func__, c->name);
426
427 val = clk_readl(c->reg);
428 val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE);
429 clk_writel(val, c->reg);
430}
431
432static int tegra2_pll_clk_set_rate(struct clk *c, unsigned long rate)
433{
434 u32 val;
435 unsigned long input_rate;
436 const struct clk_pll_table *sel;
437
438 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
439 BUG_ON(c->refcnt != 0);
440
441 input_rate = c->parent->rate;
442 for (sel = c->pll_table; sel->input_rate != 0; sel++) {
443 if (sel->input_rate == input_rate && sel->output_rate == rate) {
444 c->n = sel->n;
445 c->m = sel->m;
446 c->p = sel->p;
447 c->cpcon = sel->cpcon;
448
449 val = clk_readl(c->reg + PLL_BASE);
450 if (c->flags & PLL_FIXED)
451 val |= PLL_BASE_OVERRIDE;
452 val &= ~(PLL_BASE_DIVP_MASK | PLL_BASE_DIVN_MASK |
453 PLL_BASE_DIVM_MASK);
454 val |= (c->m << PLL_BASE_DIVM_SHIFT) |
455 (c->n << PLL_BASE_DIVN_SHIFT);
456 BUG_ON(c->p > 2);
457 if (c->p == 2)
458 val |= 1 << PLL_BASE_DIVP_SHIFT;
459 clk_writel(val, c->reg + PLL_BASE);
460
461 if (c->flags & PLL_HAS_CPCON) {
462 val = c->cpcon << PLL_MISC_CPCON_SHIFT;
463 val |= PLL_MISC_LOCK_ENABLE;
464 clk_writel(val, c->reg + PLL_MISC(c));
465 }
466
467 if (c->state == ON)
468 tegra2_pll_clk_enable(c);
469
470 c->rate = rate;
471 return 0;
472 }
473 }
474 return -EINVAL;
475}
476
477static struct clk_ops tegra_pll_ops = {
478 .init = tegra2_pll_clk_init,
479 .enable = tegra2_pll_clk_enable,
480 .disable = tegra2_pll_clk_disable,
481 .set_rate = tegra2_pll_clk_set_rate,
482 .recalculate_rate = tegra2_pll_clk_recalculate_rate,
483};
484
485/* Clock divider ops */
486static void tegra2_pll_div_clk_init(struct clk *c)
487{
488 u32 val = clk_readl(c->reg);
489 u32 divu71;
490 val >>= c->reg_shift;
491 c->state = (val & PLL_OUT_CLKEN) ? ON : OFF;
492 if (!(val & PLL_OUT_RESET_DISABLE))
493 c->state = OFF;
494
495 if (c->flags & DIV_U71) {
496 divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT;
497 c->div = (divu71 + 2);
498 c->mul = 2;
499 } else if (c->flags & DIV_2) {
500 c->div = 2;
501 c->mul = 1;
502 } else {
503 c->div = 1;
504 c->mul = 1;
505 }
506
507 tegra2_clk_recalculate_rate(c);
508}
509
510static int tegra2_pll_div_clk_enable(struct clk *c)
511{
512 u32 val;
513 u32 new_val;
514
515 pr_debug("%s: %s\n", __func__, c->name);
516 if (c->flags & DIV_U71) {
517 val = clk_readl(c->reg);
518 new_val = val >> c->reg_shift;
519 new_val &= 0xFFFF;
520
521 new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE;
522
523 val &= ~(0xFFFF << c->reg_shift);
524 val |= new_val << c->reg_shift;
525 clk_writel(val, c->reg);
526 return 0;
527 } else if (c->flags & DIV_2) {
528 BUG_ON(!(c->flags & PLLD));
529 val = clk_readl(c->reg);
530 val &= ~PLLD_MISC_DIV_RST;
531 clk_writel(val, c->reg);
532 return 0;
533 }
534 return -EINVAL;
535}
536
537static void tegra2_pll_div_clk_disable(struct clk *c)
538{
539 u32 val;
540 u32 new_val;
541
542 pr_debug("%s: %s\n", __func__, c->name);
543 if (c->flags & DIV_U71) {
544 val = clk_readl(c->reg);
545 new_val = val >> c->reg_shift;
546 new_val &= 0xFFFF;
547
548 new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE);
549
550 val &= ~(0xFFFF << c->reg_shift);
551 val |= new_val << c->reg_shift;
552 clk_writel(val, c->reg);
553 } else if (c->flags & DIV_2) {
554 BUG_ON(!(c->flags & PLLD));
555 val = clk_readl(c->reg);
556 val |= PLLD_MISC_DIV_RST;
557 clk_writel(val, c->reg);
558 }
559}
560
561static int tegra2_pll_div_clk_set_rate(struct clk *c, unsigned long rate)
562{
563 u32 val;
564 u32 new_val;
565 int divider_u71;
566 pr_debug("%s: %s %lu\n", __func__, c->name, rate);
567 if (c->flags & DIV_U71) {
568 divider_u71 = clk_div71_get_divider(c->parent, rate);
569 if (divider_u71 >= 0) {
570 val = clk_readl(c->reg);
571 new_val = val >> c->reg_shift;
572 new_val &= 0xFFFF;
573 if (c->flags & DIV_U71_FIXED)
574 new_val |= PLL_OUT_OVERRIDE;
575 new_val &= ~PLL_OUT_RATIO_MASK;
576 new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT;
577
578 val &= ~(0xFFFF << c->reg_shift);
579 val |= new_val << c->reg_shift;
580 clk_writel(val, c->reg);
581 c->div = divider_u71 + 2;
582 c->mul = 2;
583 tegra2_clk_recalculate_rate(c);
584 return 0;
585 }
586 } else if (c->flags & DIV_2) {
587 if (c->parent->rate == rate * 2) {
588 c->rate = rate;
589 return 0;
590 }
591 }
592 return -EINVAL;
593}
594
595
596static struct clk_ops tegra_pll_div_ops = {
597 .init = tegra2_pll_div_clk_init,
598 .enable = tegra2_pll_div_clk_enable,
599 .disable = tegra2_pll_div_clk_disable,
600 .set_rate = tegra2_pll_div_clk_set_rate,
601 .recalculate_rate = tegra2_clk_recalculate_rate,
602};
603
604/* Periph clk ops */
605
606static void tegra2_periph_clk_init(struct clk *c)
607{
608 u32 val = clk_readl(c->reg);
609 const struct clk_mux_sel *mux = 0;
610 const struct clk_mux_sel *sel;
611 if (c->flags & MUX) {
612 for (sel = c->inputs; sel->input != NULL; sel++) {
613 if (val >> PERIPH_CLK_SOURCE_SHIFT == sel->value)
614 mux = sel;
615 }
616 BUG_ON(!mux);
617
618 c->parent = mux->input;
619 } else {
620 c->parent = c->inputs[0].input;
621 }
622
623 if (c->flags & DIV_U71) {
624 u32 divu71 = val & PERIPH_CLK_SOURCE_DIV_MASK;
625 c->div = divu71 + 2;
626 c->mul = 2;
627 } else {
628 c->div = 1;
629 c->mul = 1;
630 }
631
632 c->state = ON;
633 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
634 PERIPH_CLK_TO_ENB_BIT(c)))
635 c->state = OFF;
636 if (!(c->flags & PERIPH_NO_RESET))
637 if (clk_readl(RST_DEVICES + PERIPH_CLK_TO_ENB_REG(c)) &
638 PERIPH_CLK_TO_ENB_BIT(c))
639 c->state = OFF;
640 tegra2_clk_recalculate_rate(c);
641}
642
643static int tegra2_periph_clk_enable(struct clk *c)
644{
645 u32 val;
646 pr_debug("%s on clock %s\n", __func__, c->name);
647
648 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
649 CLK_OUT_ENB_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
650 if (!(c->flags & PERIPH_NO_RESET) && !(c->flags & PERIPH_MANUAL_RESET))
651 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
652 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
653 if (c->flags & PERIPH_EMC_ENB) {
654 /* The EMC peripheral clock has 2 extra enable bits */
655 /* FIXME: Do they need to be disabled? */
656 val = clk_readl(c->reg);
657 val |= 0x3 << 24;
658 clk_writel(val, c->reg);
659 }
660 return 0;
661}
662
663static void tegra2_periph_clk_disable(struct clk *c)
664{
665 pr_debug("%s on clock %s\n", __func__, c->name);
666
667 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
668 CLK_OUT_ENB_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
669}
670
671void tegra2_periph_reset_deassert(struct clk *c)
672{
673 pr_debug("%s on clock %s\n", __func__, c->name);
674 if (!(c->flags & PERIPH_NO_RESET))
675 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
676 RST_DEVICES_CLR + PERIPH_CLK_TO_ENB_SET_REG(c));
677}
678
679void tegra2_periph_reset_assert(struct clk *c)
680{
681 pr_debug("%s on clock %s\n", __func__, c->name);
682 if (!(c->flags & PERIPH_NO_RESET))
683 clk_writel(PERIPH_CLK_TO_ENB_BIT(c),
684 RST_DEVICES_SET + PERIPH_CLK_TO_ENB_SET_REG(c));
685}
686
687
688static int tegra2_periph_clk_set_parent(struct clk *c, struct clk *p)
689{
690 u32 val;
691 const struct clk_mux_sel *sel;
692 pr_debug("%s: %s %s\n", __func__, c->name, p->name);
693 for (sel = c->inputs; sel->input != NULL; sel++) {
694 if (sel->input == p) {
695 clk_reparent(c, p);
696 val = clk_readl(c->reg);
697 val &= ~PERIPH_CLK_SOURCE_MASK;
698 val |= (sel->value) << PERIPH_CLK_SOURCE_SHIFT;
699 clk_writel(val, c->reg);
700 c->rate = c->parent->rate;
701 return 0;
702 }
703 }
704
705 return -EINVAL;
706}
707
708static int tegra2_periph_clk_set_rate(struct clk *c, unsigned long rate)
709{
710 u32 val;
711 int divider_u71;
712 pr_debug("%s: %lu\n", __func__, rate);
713 if (c->flags & DIV_U71) {
714 divider_u71 = clk_div71_get_divider(c->parent, rate);
715 if (divider_u71 >= 0) {
716 val = clk_readl(c->reg);
717 val &= ~PERIPH_CLK_SOURCE_DIV_MASK;
718 val |= divider_u71;
719 clk_writel(val, c->reg);
720 c->div = divider_u71 + 2;
721 c->mul = 2;
722 tegra2_clk_recalculate_rate(c);
723 return 0;
724 }
725 }
726 return -EINVAL;
727}
728
729static struct clk_ops tegra_periph_clk_ops = {
730 .init = &tegra2_periph_clk_init,
731 .enable = &tegra2_periph_clk_enable,
732 .disable = &tegra2_periph_clk_disable,
733 .set_parent = &tegra2_periph_clk_set_parent,
734 .set_rate = &tegra2_periph_clk_set_rate,
735 .recalculate_rate = &tegra2_clk_recalculate_rate,
736};
737
738/* Clock doubler ops */
739static void tegra2_clk_double_init(struct clk *c)
740{
741 c->mul = 2;
742 c->div = 1;
743 c->state = ON;
744 if (!(clk_readl(CLK_OUT_ENB + PERIPH_CLK_TO_ENB_REG(c)) &
745 PERIPH_CLK_TO_ENB_BIT(c)))
746 c->state = OFF;
747 tegra2_clk_recalculate_rate(c);
748};
749
750static struct clk_ops tegra_clk_double_ops = {
751 .init = &tegra2_clk_double_init,
752 .enable = &tegra2_periph_clk_enable,
753 .disable = &tegra2_periph_clk_disable,
754 .recalculate_rate = &tegra2_clk_recalculate_rate,
755};
756
757/* Clock definitions */
758static struct clk tegra_clk_32k = {
759 .name = "clk_32k",
760 .rate = 32678,
761 .ops = NULL,
762};
763
764static struct clk_pll_table tegra_pll_s_table[] = {
765 {32768, 12000000, 366, 1, 1, 0},
766 {32768, 13000000, 397, 1, 1, 0},
767 {32768, 19200000, 586, 1, 1, 0},
768 {32768, 26000000, 793, 1, 1, 0},
769 {0, 0, 0, 0, 0, 0},
770};
771
772static struct clk tegra_pll_s = {
773 .name = "pll_s",
774 .flags = PLL_ALT_MISC_REG,
775 .ops = &tegra_pll_ops,
776 .reg = 0xf0,
777 .input_min = 32768,
778 .input_max = 32768,
779 .parent = &tegra_clk_32k,
780 .cf_min = 0, /* FIXME */
781 .cf_max = 0, /* FIXME */
782 .vco_min = 12000000,
783 .vco_max = 26000000,
784 .pll_table = tegra_pll_s_table,
785};
786
787static struct clk_mux_sel tegra_clk_m_sel[] = {
788 { .input = &tegra_clk_32k, .value = 0},
789 { .input = &tegra_pll_s, .value = 1},
790 { 0, 0},
791};
792static struct clk tegra_clk_m = {
793 .name = "clk_m",
794 .flags = ENABLE_ON_INIT,
795 .ops = &tegra_clk_m_ops,
796 .inputs = tegra_clk_m_sel,
797 .reg = 0x1fc,
798 .reg_mask = (1<<28),
799 .reg_shift = 28,
800};
801
802static struct clk_pll_table tegra_pll_c_table[] = {
803 { 0, 0, 0, 0, 0, 0 },
804};
805
806static struct clk tegra_pll_c = {
807 .name = "pll_c",
808 .flags = PLL_HAS_CPCON,
809 .ops = &tegra_pll_ops,
810 .reg = 0x80,
811 .input_min = 2000000,
812 .input_max = 31000000,
813 .parent = &tegra_clk_m,
814 .cf_min = 1000000,
815 .cf_max = 6000000,
816 .vco_min = 20000000,
817 .vco_max = 1400000000,
818 .pll_table = tegra_pll_c_table,
819};
820
821static struct clk tegra_pll_c_out1 = {
822 .name = "pll_c_out1",
823 .ops = &tegra_pll_div_ops,
824 .flags = DIV_U71,
825 .parent = &tegra_pll_c,
826 .reg = 0x84,
827 .reg_shift = 0,
828};
829
830static struct clk_pll_table tegra_pll_m_table[] = {
831 { 0, 0, 0, 0, 0, 0 },
832};
833
834static struct clk tegra_pll_m = {
835 .name = "pll_m",
836 .flags = PLL_HAS_CPCON,
837 .ops = &tegra_pll_ops,
838 .reg = 0x90,
839 .input_min = 2000000,
840 .input_max = 31000000,
841 .parent = &tegra_clk_m,
842 .cf_min = 1000000,
843 .cf_max = 6000000,
844 .vco_min = 20000000,
845 .vco_max = 1200000000,
846 .pll_table = tegra_pll_m_table,
847};
848
849static struct clk tegra_pll_m_out1 = {
850 .name = "pll_m_out1",
851 .ops = &tegra_pll_div_ops,
852 .flags = DIV_U71,
853 .parent = &tegra_pll_m,
854 .reg = 0x94,
855 .reg_shift = 0,
856};
857
858static struct clk_pll_table tegra_pll_p_table[] = {
859 { 12000000, 216000000, 432, 12, 2, 8},
860 { 13000000, 216000000, 432, 13, 2, 8},
861 { 19200000, 216000000, 90, 4, 2, 1},
862 { 26000000, 216000000, 432, 26, 2, 8},
863 { 12000000, 432000000, 432, 12, 1, 8},
864 { 13000000, 432000000, 432, 13, 1, 8},
865 { 19200000, 432000000, 90, 4, 1, 1},
866 { 26000000, 432000000, 432, 26, 1, 8},
867 { 0, 0, 0, 0, 0, 0 },
868};
869
870static struct clk tegra_pll_p = {
871 .name = "pll_p",
872 .flags = ENABLE_ON_INIT | PLL_FIXED | PLL_HAS_CPCON,
873 .ops = &tegra_pll_ops,
874 .reg = 0xa0,
875 .input_min = 2000000,
876 .input_max = 31000000,
877 .parent = &tegra_clk_m,
878 .cf_min = 1000000,
879 .cf_max = 6000000,
880 .vco_min = 20000000,
881 .vco_max = 1400000000,
882 .pll_table = tegra_pll_p_table,
883};
884
885static struct clk tegra_pll_p_out1 = {
886 .name = "pll_p_out1",
887 .ops = &tegra_pll_div_ops,
888 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
889 .parent = &tegra_pll_p,
890 .reg = 0xa4,
891 .reg_shift = 0,
892};
893
894static struct clk tegra_pll_p_out2 = {
895 .name = "pll_p_out2",
896 .ops = &tegra_pll_div_ops,
897 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
898 .parent = &tegra_pll_p,
899 .reg = 0xa4,
900 .reg_shift = 16,
901};
902
903static struct clk tegra_pll_p_out3 = {
904 .name = "pll_p_out3",
905 .ops = &tegra_pll_div_ops,
906 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
907 .parent = &tegra_pll_p,
908 .reg = 0xa8,
909 .reg_shift = 0,
910};
911
912static struct clk tegra_pll_p_out4 = {
913 .name = "pll_p_out4",
914 .ops = &tegra_pll_div_ops,
915 .flags = ENABLE_ON_INIT | DIV_U71 | DIV_U71_FIXED,
916 .parent = &tegra_pll_p,
917 .reg = 0xa8,
918 .reg_shift = 16,
919};
920
921static struct clk_pll_table tegra_pll_a_table[] = {
922 { 28800000, 56448000, 49, 25, 1, 1},
923 { 28800000, 73728000, 64, 25, 1, 1},
924 { 28800000, 11289600, 49, 25, 1, 1},
925 { 28800000, 12288000, 64, 25, 1, 1},
926 { 0, 0, 0, 0, 0, 0 },
927};
928
929static struct clk tegra_pll_a = {
930 .name = "pll_a",
931 .flags = PLL_HAS_CPCON,
932 .ops = &tegra_pll_ops,
933 .reg = 0xb0,
934 .input_min = 2000000,
935 .input_max = 31000000,
936 .parent = &tegra_pll_p_out1,
937 .cf_min = 1000000,
938 .cf_max = 6000000,
939 .vco_min = 20000000,
940 .vco_max = 1400000000,
941 .pll_table = tegra_pll_a_table,
942};
943
944static struct clk tegra_pll_a_out0 = {
945 .name = "pll_a_out0",
946 .ops = &tegra_pll_div_ops,
947 .flags = DIV_U71,
948 .parent = &tegra_pll_a,
949 .reg = 0xb4,
950 .reg_shift = 0,
951};
952
953static struct clk_pll_table tegra_pll_d_table[] = {
954 { 12000000, 1000000000, 1000, 12, 1, 12},
955 { 13000000, 1000000000, 1000, 13, 1, 12},
956 { 19200000, 1000000000, 625, 12, 1, 8},
957 { 26000000, 1000000000, 1000, 26, 1, 12},
958 { 0, 0, 0, 0, 0, 0 },
959};
960
961static struct clk tegra_pll_d = {
962 .name = "pll_d",
963 .flags = PLL_HAS_CPCON | PLLD,
964 .ops = &tegra_pll_ops,
965 .reg = 0xd0,
966 .input_min = 2000000,
967 .input_max = 40000000,
968 .parent = &tegra_clk_m,
969 .cf_min = 1000000,
970 .cf_max = 6000000,
971 .vco_min = 40000000,
972 .vco_max = 1000000000,
973 .pll_table = tegra_pll_d_table,
974};
975
976static struct clk tegra_pll_d_out0 = {
977 .name = "pll_d_out0",
978 .ops = &tegra_pll_div_ops,
979 .flags = DIV_2 | PLLD,
980 .parent = &tegra_pll_d,
981};
982
983static struct clk_pll_table tegra_pll_u_table[] = {
984 { 12000000, 480000000, 960, 12, 1, 0},
985 { 13000000, 480000000, 960, 13, 1, 0},
986 { 19200000, 480000000, 200, 4, 1, 0},
987 { 26000000, 480000000, 960, 26, 1, 0},
988 { 0, 0, 0, 0, 0, 0 },
989};
990
991static struct clk tegra_pll_u = {
992 .name = "pll_u",
993 .flags = 0,
994 .ops = &tegra_pll_ops,
995 .reg = 0xc0,
996 .input_min = 2000000,
997 .input_max = 40000000,
998 .parent = &tegra_clk_m,
999 .cf_min = 1000000,
1000 .cf_max = 6000000,
1001 .vco_min = 480000000,
1002 .vco_max = 960000000,
1003 .pll_table = tegra_pll_u_table,
1004};
1005
1006static struct clk_pll_table tegra_pll_x_table[] = {
1007 { 12000000, 1000000000, 1000, 12, 1, 12},
1008 { 13000000, 1000000000, 1000, 13, 1, 12},
1009 { 19200000, 1000000000, 625, 12, 1, 8},
1010 { 26000000, 1000000000, 1000, 26, 1, 12},
1011 { 12000000, 750000000, 750, 12, 1, 12},
1012 { 13000000, 750000000, 750, 13, 1, 12},
1013 { 19200000, 750000000, 625, 16, 1, 8},
1014 { 26000000, 750000000, 750, 26, 1, 12},
1015 { 0, 0, 0, 0, 0, 0 },
1016};
1017
1018static struct clk tegra_pll_x = {
1019 .name = "pll_x",
1020 .flags = PLL_HAS_CPCON | PLL_ALT_MISC_REG,
1021 .ops = &tegra_pll_ops,
1022 .reg = 0xe0,
1023 .input_min = 2000000,
1024 .input_max = 31000000,
1025 .parent = &tegra_clk_m,
1026 .cf_min = 1000000,
1027 .cf_max = 6000000,
1028 .vco_min = 20000000,
1029 .vco_max = 1200000000,
1030 .pll_table = tegra_pll_x_table,
1031};
1032
1033static struct clk tegra_clk_d = {
1034 .name = "clk_d",
1035 .flags = PERIPH_NO_RESET,
1036 .ops = &tegra_clk_double_ops,
1037 .clk_num = 90,
1038 .reg = 0x34,
1039 .reg_shift = 12,
1040 .parent = &tegra_clk_m,
1041};
1042
1043/* FIXME: need tegra_audio
1044static struct clk tegra_clk_audio_2x = {
1045 .name = "clk_d",
1046 .flags = PERIPH_NO_RESET,
1047 .ops = &tegra_clk_double_ops,
1048 .clk_num = 89,
1049 .reg = 0x34,
1050 .reg_shift = 8,
1051 .parent = &tegra_audio,
1052}
1053*/
1054
1055static struct clk_mux_sel mux_cclk[] = {
1056 { .input = &tegra_clk_m, .value = 0},
1057 { .input = &tegra_pll_c, .value = 1},
1058 { .input = &tegra_clk_32k, .value = 2},
1059 { .input = &tegra_pll_m, .value = 3},
1060 { .input = &tegra_pll_p, .value = 4},
1061 { .input = &tegra_pll_p_out4, .value = 5},
1062 { .input = &tegra_pll_p_out3, .value = 6},
1063 { .input = &tegra_clk_d, .value = 7},
1064 { .input = &tegra_pll_x, .value = 8},
1065 { 0, 0},
1066};
1067
1068static struct clk_mux_sel mux_sclk[] = {
1069 { .input = &tegra_clk_m, .value = 0},
1070 { .input = &tegra_pll_c_out1, .value = 1},
1071 { .input = &tegra_pll_p_out4, .value = 2},
1072 { .input = &tegra_pll_p_out3, .value = 3},
1073 { .input = &tegra_pll_p_out2, .value = 4},
1074 { .input = &tegra_clk_d, .value = 5},
1075 { .input = &tegra_clk_32k, .value = 6},
1076 { .input = &tegra_pll_m_out1, .value = 7},
1077 { 0, 0},
1078};
1079
1080static struct clk tegra_clk_cpu = {
1081 .name = "cpu",
1082 .inputs = mux_cclk,
1083 .reg = 0x20,
1084 .ops = &tegra_super_ops,
1085};
1086
1087static struct clk tegra_clk_sys = {
1088 .name = "sys",
1089 .inputs = mux_sclk,
1090 .reg = 0x28,
1091 .ops = &tegra_super_ops,
1092};
1093
1094static struct clk tegra_clk_hclk = {
1095 .name = "hclk",
1096 .flags = DIV_BUS,
1097 .parent = &tegra_clk_sys,
1098 .reg = 0x30,
1099 .reg_shift = 4,
1100 .ops = &tegra_bus_ops,
1101};
1102
1103static struct clk tegra_clk_pclk = {
1104 .name = "pclk",
1105 .flags = DIV_BUS,
1106 .parent = &tegra_clk_hclk,
1107 .reg = 0x30,
1108 .reg_shift = 0,
1109 .ops = &tegra_bus_ops,
1110};
1111
1112static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
1113 { .input = &tegra_pll_m, .value = 0},
1114 { .input = &tegra_pll_c, .value = 1},
1115 { .input = &tegra_pll_p, .value = 2},
1116 { .input = &tegra_pll_a_out0, .value = 3},
1117 { 0, 0},
1118};
1119
1120static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
1121 { .input = &tegra_pll_m, .value = 0},
1122 { .input = &tegra_pll_c, .value = 1},
1123 { .input = &tegra_pll_p, .value = 2},
1124 { .input = &tegra_clk_m, .value = 3},
1125 { 0, 0},
1126};
1127
1128static struct clk_mux_sel mux_pllp_pllc_pllm_clkm[] = {
1129 { .input = &tegra_pll_p, .value = 0},
1130 { .input = &tegra_pll_c, .value = 1},
1131 { .input = &tegra_pll_m, .value = 2},
1132 { .input = &tegra_clk_m, .value = 3},
1133 { 0, 0},
1134};
1135
1136static struct clk_mux_sel mux_plla_audio_pllp_clkm[] = {
1137 {.input = &tegra_pll_a, .value = 0},
1138 /* FIXME: no mux defined for tegra_audio
1139 {.input = &tegra_audio, .value = 1},*/
1140 {.input = &tegra_pll_p, .value = 2},
1141 {.input = &tegra_clk_m, .value = 3},
1142 { 0, 0},
1143};
1144
1145static struct clk_mux_sel mux_pllp_plld_pllc_clkm[] = {
1146 {.input = &tegra_pll_p, .value = 0},
1147 {.input = &tegra_pll_d_out0, .value = 1},
1148 {.input = &tegra_pll_c, .value = 2},
1149 {.input = &tegra_clk_m, .value = 3},
1150 { 0, 0},
1151};
1152
1153static struct clk_mux_sel mux_pllp_pllc_audio_clkm_clk32[] = {
1154 {.input = &tegra_pll_p, .value = 0},
1155 {.input = &tegra_pll_c, .value = 1},
1156 /* FIXME: no mux defined for tegra_audio
1157 {.input = &tegra_audio, .value = 2},*/
1158 {.input = &tegra_clk_m, .value = 3},
1159 {.input = &tegra_clk_32k, .value = 4},
1160 { 0, 0},
1161};
1162
1163static struct clk_mux_sel mux_pllp_pllc_pllm[] = {
1164 {.input = &tegra_pll_p, .value = 0},
1165 {.input = &tegra_pll_c, .value = 1},
1166 {.input = &tegra_pll_m, .value = 2},
1167 { 0, 0},
1168};
1169
1170static struct clk_mux_sel mux_clk_m[] = {
1171 { .input = &tegra_clk_m, .value = 0},
1172 { 0, 0},
1173};
1174
1175static struct clk_mux_sel mux_pllp_out3[] = {
1176 { .input = &tegra_pll_p_out3, .value = 0},
1177 { 0, 0},
1178};
1179
1180static struct clk_mux_sel mux_plld[] = {
1181 { .input = &tegra_pll_d, .value = 0},
1182 { 0, 0},
1183};
1184
1185static struct clk_mux_sel mux_clk_32k[] = {
1186 { .input = &tegra_clk_32k, .value = 0},
1187 { 0, 0},
1188};
1189
1190#define PERIPH_CLK(_name, _dev, _con, _clk_num, _reg, _inputs, _flags) \
1191 { \
1192 .name = _name, \
1193 .lookup = { \
1194 .dev_id = _dev, \
1195 .con_id = _con, \
1196 }, \
1197 .ops = &tegra_periph_clk_ops, \
1198 .clk_num = _clk_num, \
1199 .reg = _reg, \
1200 .inputs = _inputs, \
1201 .flags = _flags, \
1202 }
1203
1204struct clk tegra_periph_clks[] = {
1205 PERIPH_CLK("rtc", "rtc-tegra", NULL, 4, 0, mux_clk_32k, PERIPH_NO_RESET),
1206 PERIPH_CLK("timer", "timer", NULL, 5, 0, mux_clk_m, 0),
1207 PERIPH_CLK("i2s1", "i2s.0", NULL, 11, 0x100, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
1208 PERIPH_CLK("i2s2", "i2s.1", NULL, 18, 0x104, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
1209 /* FIXME: spdif has 2 clocks but 1 enable */
1210 PERIPH_CLK("spdif_out", "spdif_out", NULL, 10, 0x108, mux_plla_audio_pllp_clkm, MUX | DIV_U71),
1211 PERIPH_CLK("spdif_in", "spdif_in", NULL, 10, 0x10c, mux_pllp_pllc_pllm, MUX | DIV_U71),
1212 PERIPH_CLK("pwm", "pwm", NULL, 17, 0x110, mux_pllp_pllc_audio_clkm_clk32, MUX | DIV_U71),
1213 PERIPH_CLK("spi", "spi", NULL, 43, 0x114, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1214 PERIPH_CLK("xio", "xio", NULL, 45, 0x120, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1215 PERIPH_CLK("twc", "twc", NULL, 16, 0x12c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1216 PERIPH_CLK("sbc1", "spi_tegra.0", NULL, 41, 0x134, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1217 PERIPH_CLK("sbc2", "spi_tegra.1", NULL, 44, 0x118, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1218 PERIPH_CLK("sbc3", "spi_tegra.2", NULL, 46, 0x11c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1219 PERIPH_CLK("sbc4", "spi_tegra.3", NULL, 68, 0x1b4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1220 PERIPH_CLK("ide", "ide", NULL, 25, 0x144, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1221 PERIPH_CLK("ndflash", "tegra_nand", NULL, 13, 0x160, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1222 /* FIXME: vfir shares an enable with uartb */
1223 PERIPH_CLK("vfir", "vfir", NULL, 7, 0x168, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1224 PERIPH_CLK("sdmmc1", "sdhci-tegra.0", NULL, 14, 0x150, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1225 PERIPH_CLK("sdmmc2", "sdhci-tegra.1", NULL, 9, 0x154, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1226 PERIPH_CLK("sdmmc3", "sdhci-tegra.2", NULL, 69, 0x1bc, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1227 PERIPH_CLK("sdmmc4", "sdhci-tegra.3", NULL, 15, 0x160, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1228 PERIPH_CLK("vde", "vde", NULL, 61, 0x1c8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1229 PERIPH_CLK("csite", "csite", NULL, 73, 0x1d4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1230 /* FIXME: what is la? */
1231 PERIPH_CLK("la", "la", NULL, 76, 0x1f8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1232 PERIPH_CLK("owr", "owr", NULL, 71, 0x1cc, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1233 PERIPH_CLK("nor", "nor", NULL, 42, 0x1d0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1234 PERIPH_CLK("mipi", "mipi", NULL, 50, 0x174, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1235 PERIPH_CLK("i2c1", "tegra-i2c.0", NULL, 12, 0x124, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1236 PERIPH_CLK("i2c2", "tegra-i2c.1", NULL, 54, 0x198, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1237 PERIPH_CLK("i2c3", "tegra-i2c.2", NULL, 67, 0x1b8, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1238 PERIPH_CLK("dvc", "tegra-i2c.3", NULL, 47, 0x128, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1239 PERIPH_CLK("i2c1_i2c", "tegra-i2c.0", "i2c", 0, 0, mux_pllp_out3, 0),
1240 PERIPH_CLK("i2c2_i2c", "tegra-i2c.1", "i2c", 0, 0, mux_pllp_out3, 0),
1241 PERIPH_CLK("i2c3_i2c", "tegra-i2c.2", "i2c", 0, 0, mux_pllp_out3, 0),
1242 PERIPH_CLK("dvc_i2c", "tegra-i2c.3", "i2c", 0, 0, mux_pllp_out3, 0),
1243 PERIPH_CLK("uarta", "uart.0", NULL, 6, 0x178, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1244 PERIPH_CLK("uartb", "uart.1", NULL, 7, 0x17c, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1245 PERIPH_CLK("uartc", "uart.2", NULL, 55, 0x1a0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1246 PERIPH_CLK("uartd", "uart.3", NULL, 65, 0x1c0, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1247 PERIPH_CLK("uarte", "uart.4", NULL, 66, 0x1c4, mux_pllp_pllc_pllm_clkm, MUX | DIV_U71),
1248 PERIPH_CLK("3d", "3d", NULL, 24, 0x158, mux_pllm_pllc_pllp_plla, MUX | DIV_U71 | PERIPH_MANUAL_RESET),
1249 PERIPH_CLK("2d", "2d", NULL, 21, 0x15c, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1250 /* FIXME: vi and vi_sensor share an enable */
1251 PERIPH_CLK("vi", "vi", NULL, 20, 0x148, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1252 PERIPH_CLK("vi_sensor", "vi_sensor", NULL, 20, 0x1a8, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1253 PERIPH_CLK("epp", "epp", NULL, 19, 0x16c, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1254 PERIPH_CLK("mpe", "mpe", NULL, 60, 0x170, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1255 PERIPH_CLK("host1x", "host1x", NULL, 28, 0x180, mux_pllm_pllc_pllp_plla, MUX | DIV_U71),
1256 /* FIXME: cve and tvo share an enable */
1257 PERIPH_CLK("cve", "cve", NULL, 49, 0x140, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1258 PERIPH_CLK("tvo", "tvo", NULL, 49, 0x188, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1259 PERIPH_CLK("hdmi", "hdmi", NULL, 51, 0x18c, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1260 PERIPH_CLK("tvdac", "tvdac", NULL, 53, 0x194, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1261 PERIPH_CLK("disp1", "tegrafb.0", NULL, 27, 0x138, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1262 PERIPH_CLK("disp2", "tegrafb.1", NULL, 26, 0x13c, mux_pllp_plld_pllc_clkm, MUX | DIV_U71),
1263 PERIPH_CLK("usbd", "fsl-tegra-udc", NULL, 22, 0, mux_clk_m, 0),
1264 PERIPH_CLK("usb2", "usb.1", NULL, 58, 0, mux_clk_m, 0),
1265 PERIPH_CLK("usb3", "usb.2", NULL, 59, 0, mux_clk_m, 0),
1266 PERIPH_CLK("emc", "emc", NULL, 57, 0x19c, mux_pllm_pllc_pllp_clkm, MUX | DIV_U71 | PERIPH_EMC_ENB),
1267 PERIPH_CLK("dsi", "dsi", NULL, 48, 0, mux_plld, 0),
1268};
1269
1270#define CLK_DUPLICATE(_name, _dev, _con) \
1271 { \
1272 .name = _name, \
1273 .lookup = { \
1274 .dev_id = _dev, \
1275 .con_id = _con, \
1276 }, \
1277 }
1278
1279/* Some clocks may be used by different drivers depending on the board
1280 * configuration. List those here to register them twice in the clock lookup
1281 * table under two names.
1282 */
1283struct clk_duplicate tegra_clk_duplicates[] = {
1284 CLK_DUPLICATE("uarta", "tegra_uart.0", NULL),
1285 CLK_DUPLICATE("uartb", "tegra_uart.1", NULL),
1286 CLK_DUPLICATE("uartc", "tegra_uart.2", NULL),
1287 CLK_DUPLICATE("uartd", "tegra_uart.3", NULL),
1288 CLK_DUPLICATE("uarte", "tegra_uart.4", NULL),
1289};
1290
1291#define CLK(dev, con, ck) \
1292 { \
1293 .dev_id = dev, \
1294 .con_id = con, \
1295 .clk = ck, \
1296 }
1297
1298struct clk_lookup tegra_clk_lookups[] = {
1299 /* external root sources */
1300 CLK(NULL, "32k_clk", &tegra_clk_32k),
1301 CLK(NULL, "pll_s", &tegra_pll_s),
1302 CLK(NULL, "clk_m", &tegra_clk_m),
1303 CLK(NULL, "pll_m", &tegra_pll_m),
1304 CLK(NULL, "pll_m_out1", &tegra_pll_m_out1),
1305 CLK(NULL, "pll_c", &tegra_pll_c),
1306 CLK(NULL, "pll_c_out1", &tegra_pll_c_out1),
1307 CLK(NULL, "pll_p", &tegra_pll_p),
1308 CLK(NULL, "pll_p_out1", &tegra_pll_p_out1),
1309 CLK(NULL, "pll_p_out2", &tegra_pll_p_out2),
1310 CLK(NULL, "pll_p_out3", &tegra_pll_p_out3),
1311 CLK(NULL, "pll_p_out4", &tegra_pll_p_out4),
1312 CLK(NULL, "pll_a", &tegra_pll_a),
1313 CLK(NULL, "pll_a_out0", &tegra_pll_a_out0),
1314 CLK(NULL, "pll_d", &tegra_pll_d),
1315 CLK(NULL, "pll_d_out0", &tegra_pll_d_out0),
1316 CLK(NULL, "pll_u", &tegra_pll_u),
1317 CLK(NULL, "pll_x", &tegra_pll_x),
1318 CLK(NULL, "cpu", &tegra_clk_cpu),
1319 CLK(NULL, "sys", &tegra_clk_sys),
1320 CLK(NULL, "hclk", &tegra_clk_hclk),
1321 CLK(NULL, "pclk", &tegra_clk_pclk),
1322 CLK(NULL, "clk_d", &tegra_clk_d),
1323};
1324
1325void __init tegra2_init_clocks(void)
1326{
1327 int i;
1328 struct clk_lookup *cl;
1329 struct clk *c;
1330 struct clk_duplicate *cd;
1331
1332 for (i = 0; i < ARRAY_SIZE(tegra_clk_lookups); i++) {
1333 cl = &tegra_clk_lookups[i];
1334 clk_init(cl->clk);
1335 clkdev_add(cl);
1336 }
1337
1338 for (i = 0; i < ARRAY_SIZE(tegra_periph_clks); i++) {
1339 c = &tegra_periph_clks[i];
1340 cl = &c->lookup;
1341 cl->clk = c;
1342
1343 clk_init(cl->clk);
1344 clkdev_add(cl);
1345 }
1346
1347 for (i = 0; i < ARRAY_SIZE(tegra_clk_duplicates); i++) {
1348 cd = &tegra_clk_duplicates[i];
1349 c = tegra_get_clock_by_name(cd->name);
1350 if (c) {
1351 cl = &cd->lookup;
1352 cl->clk = c;
1353 clkdev_add(cl);
1354 } else {
1355 pr_err("%s: Unknown duplicate clock %s\n", __func__,
1356 cd->name);
1357 }
1358 }
1359}