Merge branch 'upstream' of git://electric-eye.fr.zoreil.com/home/romieu/linux-2.6...
[pandora-kernel.git] / arch / arm / mach-lh7a40x / clocks.c
1 /* arch/arm/mach-lh7a40x/clocks.c
2  *
3  *  Copyright (C) 2004 Marc Singer
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  version 2 as published by the Free Software Foundation.
8  *
9  */
10
11 #include <linux/config.h>
12 #include <linux/cpufreq.h>
13 #include <asm/hardware.h>
14 #include <asm/arch/clocks.h>
15 #include <linux/err.h>
16
17 struct module;
18 struct icst525_params;
19
20 struct clk {
21         struct list_head node;
22         unsigned long rate;
23         struct module *owner;
24         const char *name;
25 //      void *data;
26 //      const struct icst525_params *params;
27 //      void (*setvco)(struct clk *, struct icst525_vco vco);
28 };
29
30 int clk_register(struct clk *clk);
31 void clk_unregister(struct clk *clk);
32
33 /* ----- */
34
35 #define MAINDIV1(c)     (((c) >>  7) & 0x0f)
36 #define MAINDIV2(c)     (((c) >> 11) & 0x1f)
37 #define PS(c)           (((c) >> 18) & 0x03)
38 #define PREDIV(c)       (((c) >>  2) & 0x1f)
39 #define HCLKDIV(c)      (((c) >>  0) & 0x02)
40 #define PCLKDIV(c)      (((c) >> 16) & 0x03)
41
42 unsigned int cpufreq_get (unsigned int cpu) /* in kHz */
43 {
44         return fclkfreq_get ()/1000;
45 }
46 EXPORT_SYMBOL(cpufreq_get);
47
48 unsigned int fclkfreq_get (void)
49 {
50         unsigned int clkset = CSC_CLKSET;
51         unsigned int gclk
52                 = XTAL_IN
53                 / (1 << PS(clkset))
54                 * (MAINDIV1(clkset) + 2)
55                 / (PREDIV(clkset)   + 2)
56                 * (MAINDIV2(clkset) + 2)
57                 ;
58         return gclk;
59 }
60
61 unsigned int hclkfreq_get (void)
62 {
63         unsigned int clkset = CSC_CLKSET;
64         unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1);
65
66         return hclk;
67 }
68
69 unsigned int pclkfreq_get (void)
70 {
71         unsigned int clkset = CSC_CLKSET;
72         int pclkdiv = PCLKDIV(clkset);
73         unsigned int pclk;
74         if (pclkdiv == 0x3)
75                 pclkdiv = 0x2;
76         pclk = hclkfreq_get () / (1 << pclkdiv);
77
78         return pclk;
79 }
80
81 /* ----- */
82
83 static LIST_HEAD(clocks);
84 static DECLARE_MUTEX(clocks_sem);
85
86 struct clk *clk_get (struct device *dev, const char *id)
87 {
88         struct clk *p;
89         struct clk *clk = ERR_PTR(-ENOENT);
90
91         down (&clocks_sem);
92         list_for_each_entry (p, &clocks, node) {
93                 if (strcmp (id, p->name) == 0
94                     && try_module_get(p->owner)) {
95                         clk = p;
96                         break;
97                 }
98         }
99         up (&clocks_sem);
100
101         return clk;
102 }
103 EXPORT_SYMBOL(clk_get);
104
105 void clk_put (struct clk *clk)
106 {
107         module_put(clk->owner);
108 }
109 EXPORT_SYMBOL(clk_put);
110
111 int clk_enable (struct clk *clk)
112 {
113         return 0;
114 }
115 EXPORT_SYMBOL(clk_enable);
116
117 void clk_disable (struct clk *clk)
118 {
119 }
120 EXPORT_SYMBOL(clk_disable);
121
122 int clk_use (struct clk *clk)
123 {
124         return 0;
125 }
126 EXPORT_SYMBOL(clk_use);
127
128 void clk_unuse (struct clk *clk)
129 {
130 }
131 EXPORT_SYMBOL(clk_unuse);
132
133 unsigned long clk_get_rate (struct clk *clk)
134 {
135         return clk->rate;
136 }
137 EXPORT_SYMBOL(clk_get_rate);
138
139 long clk_round_rate (struct clk *clk, unsigned long rate)
140 {
141         return rate;
142 }
143 EXPORT_SYMBOL(clk_round_rate);
144
145 int clk_set_rate (struct clk *clk, unsigned long rate)
146 {
147         int ret = -EIO;
148         return ret;
149 }
150 EXPORT_SYMBOL(clk_set_rate);
151
152 #if 0
153 /*
154  * These are fixed clocks.
155  */
156 static struct clk kmi_clk = {
157         .name   = "KMIREFCLK",
158         .rate   = 24000000,
159 };
160
161 static struct clk uart_clk = {
162         .name   = "UARTCLK",
163         .rate   = 24000000,
164 };
165
166 static struct clk mmci_clk = {
167         .name   = "MCLK",
168         .rate   = 33000000,
169 };
170 #endif
171
172 static struct clk clcd_clk = {
173         .name   = "CLCDCLK",
174         .rate   = 0,
175 };
176
177 int clk_register (struct clk *clk)
178 {
179         down (&clocks_sem);
180         list_add (&clk->node, &clocks);
181         up (&clocks_sem);
182         return 0;
183 }
184 EXPORT_SYMBOL(clk_register);
185
186 void clk_unregister (struct clk *clk)
187 {
188         down (&clocks_sem);
189         list_del (&clk->node);
190         up (&clocks_sem);
191 }
192 EXPORT_SYMBOL(clk_unregister);
193
194 static int __init clk_init (void)
195 {
196         clk_register(&clcd_clk);
197         return 0;
198 }
199 arch_initcall(clk_init);