blob: 2291afe9f23e9d6fa80c15d821ab1370033f9d29 [file] [log] [blame]
Marc Singer638b2662006-05-16 11:41:28 +01001/* 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
17struct module;
18struct icst525_params;
19
20struct 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
30int clk_register(struct clk *clk);
31void 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
42unsigned int cpufreq_get (unsigned int cpu) /* in kHz */
43{
44 return fclkfreq_get ()/1000;
45}
46EXPORT_SYMBOL(cpufreq_get);
47
48unsigned 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
61unsigned 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
69unsigned 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
83static LIST_HEAD(clocks);
84static DECLARE_MUTEX(clocks_sem);
85
86struct 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}
103EXPORT_SYMBOL(clk_get);
104
105void clk_put (struct clk *clk)
106{
107 module_put(clk->owner);
108}
109EXPORT_SYMBOL(clk_put);
110
111int clk_enable (struct clk *clk)
112{
113 return 0;
114}
115EXPORT_SYMBOL(clk_enable);
116
117void clk_disable (struct clk *clk)
118{
119}
120EXPORT_SYMBOL(clk_disable);
121
122int clk_use (struct clk *clk)
123{
124 return 0;
125}
126EXPORT_SYMBOL(clk_use);
127
128void clk_unuse (struct clk *clk)
129{
130}
131EXPORT_SYMBOL(clk_unuse);
132
133unsigned long clk_get_rate (struct clk *clk)
134{
135 return clk->rate;
136}
137EXPORT_SYMBOL(clk_get_rate);
138
139long clk_round_rate (struct clk *clk, unsigned long rate)
140{
141 return rate;
142}
143EXPORT_SYMBOL(clk_round_rate);
144
145int clk_set_rate (struct clk *clk, unsigned long rate)
146{
147 int ret = -EIO;
148 return ret;
149}
150EXPORT_SYMBOL(clk_set_rate);
151
152#if 0
153/*
154 * These are fixed clocks.
155 */
156static struct clk kmi_clk = {
157 .name = "KMIREFCLK",
158 .rate = 24000000,
159};
160
161static struct clk uart_clk = {
162 .name = "UARTCLK",
163 .rate = 24000000,
164};
165
166static struct clk mmci_clk = {
167 .name = "MCLK",
168 .rate = 33000000,
169};
170#endif
171
172static struct clk clcd_clk = {
173 .name = "CLCDCLK",
174 .rate = 0,
175};
176
177int clk_register (struct clk *clk)
178{
179 down (&clocks_sem);
180 list_add (&clk->node, &clocks);
181 up (&clocks_sem);
182 return 0;
183}
184EXPORT_SYMBOL(clk_register);
185
186void clk_unregister (struct clk *clk)
187{
188 down (&clocks_sem);
189 list_del (&clk->node);
190 up (&clocks_sem);
191}
192EXPORT_SYMBOL(clk_unregister);
193
194static int __init clk_init (void)
195{
196 clk_register(&clcd_clk);
197 return 0;
198}
199arch_initcall(clk_init);