IB/ipath: merge ipath_core and ib_ipath drivers
[linux-2.6/verdex.git] / arch / arm / mach-lh7a40x / clocks.c
blob2291afe9f23e9d6fa80c15d821ab1370033f9d29
1 /* arch/arm/mach-lh7a40x/clocks.c
3 * Copyright (C) 2004 Marc Singer
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.
9 */
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>
17 struct module;
18 struct icst525_params;
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);
30 int clk_register(struct clk *clk);
31 void clk_unregister(struct clk *clk);
33 /* ----- */
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)
42 unsigned int cpufreq_get (unsigned int cpu) /* in kHz */
44 return fclkfreq_get ()/1000;
46 EXPORT_SYMBOL(cpufreq_get);
48 unsigned int fclkfreq_get (void)
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)
58 return gclk;
61 unsigned int hclkfreq_get (void)
63 unsigned int clkset = CSC_CLKSET;
64 unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1);
66 return hclk;
69 unsigned int pclkfreq_get (void)
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);
78 return pclk;
81 /* ----- */
83 static LIST_HEAD(clocks);
84 static DECLARE_MUTEX(clocks_sem);
86 struct clk *clk_get (struct device *dev, const char *id)
88 struct clk *p;
89 struct clk *clk = ERR_PTR(-ENOENT);
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;
99 up (&clocks_sem);
101 return clk;
103 EXPORT_SYMBOL(clk_get);
105 void clk_put (struct clk *clk)
107 module_put(clk->owner);
109 EXPORT_SYMBOL(clk_put);
111 int clk_enable (struct clk *clk)
113 return 0;
115 EXPORT_SYMBOL(clk_enable);
117 void clk_disable (struct clk *clk)
120 EXPORT_SYMBOL(clk_disable);
122 int clk_use (struct clk *clk)
124 return 0;
126 EXPORT_SYMBOL(clk_use);
128 void clk_unuse (struct clk *clk)
131 EXPORT_SYMBOL(clk_unuse);
133 unsigned long clk_get_rate (struct clk *clk)
135 return clk->rate;
137 EXPORT_SYMBOL(clk_get_rate);
139 long clk_round_rate (struct clk *clk, unsigned long rate)
141 return rate;
143 EXPORT_SYMBOL(clk_round_rate);
145 int clk_set_rate (struct clk *clk, unsigned long rate)
147 int ret = -EIO;
148 return ret;
150 EXPORT_SYMBOL(clk_set_rate);
152 #if 0
154 * These are fixed clocks.
156 static struct clk kmi_clk = {
157 .name = "KMIREFCLK",
158 .rate = 24000000,
161 static struct clk uart_clk = {
162 .name = "UARTCLK",
163 .rate = 24000000,
166 static struct clk mmci_clk = {
167 .name = "MCLK",
168 .rate = 33000000,
170 #endif
172 static struct clk clcd_clk = {
173 .name = "CLCDCLK",
174 .rate = 0,
177 int clk_register (struct clk *clk)
179 down (&clocks_sem);
180 list_add (&clk->node, &clocks);
181 up (&clocks_sem);
182 return 0;
184 EXPORT_SYMBOL(clk_register);
186 void clk_unregister (struct clk *clk)
188 down (&clocks_sem);
189 list_del (&clk->node);
190 up (&clocks_sem);
192 EXPORT_SYMBOL(clk_unregister);
194 static int __init clk_init (void)
196 clk_register(&clcd_clk);
197 return 0;
199 arch_initcall(clk_init);