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.
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>
18 struct icst525_params
;
21 struct list_head node
;
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
);
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
;
54 * (MAINDIV1(clkset
) + 2)
55 / (PREDIV(clkset
) + 2)
56 * (MAINDIV2(clkset
) + 2)
61 unsigned int hclkfreq_get (void)
63 unsigned int clkset
= CSC_CLKSET
;
64 unsigned int hclk
= fclkfreq_get () / (HCLKDIV(clkset
) + 1);
69 unsigned int pclkfreq_get (void)
71 unsigned int clkset
= CSC_CLKSET
;
72 int pclkdiv
= PCLKDIV(clkset
);
76 pclk
= hclkfreq_get () / (1 << pclkdiv
);
83 static LIST_HEAD(clocks
);
84 static DECLARE_MUTEX(clocks_sem
);
86 struct clk
*clk_get (struct device
*dev
, const char *id
)
89 struct clk
*clk
= ERR_PTR(-ENOENT
);
92 list_for_each_entry (p
, &clocks
, node
) {
93 if (strcmp (id
, p
->name
) == 0
94 && try_module_get(p
->owner
)) {
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
)
115 EXPORT_SYMBOL(clk_enable
);
117 void clk_disable (struct clk
*clk
)
120 EXPORT_SYMBOL(clk_disable
);
122 int clk_use (struct clk
*clk
)
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
)
137 EXPORT_SYMBOL(clk_get_rate
);
139 long clk_round_rate (struct clk
*clk
, unsigned long rate
)
143 EXPORT_SYMBOL(clk_round_rate
);
145 int clk_set_rate (struct clk
*clk
, unsigned long rate
)
150 EXPORT_SYMBOL(clk_set_rate
);
154 * These are fixed clocks.
156 static struct clk kmi_clk
= {
161 static struct clk uart_clk
= {
166 static struct clk mmci_clk
= {
172 static struct clk clcd_clk
= {
177 int clk_register (struct clk
*clk
)
180 list_add (&clk
->node
, &clocks
);
184 EXPORT_SYMBOL(clk_register
);
186 void clk_unregister (struct clk
*clk
)
189 list_del (&clk
->node
);
192 EXPORT_SYMBOL(clk_unregister
);
194 static int __init
clk_init (void)
196 clk_register(&clcd_clk
);
199 arch_initcall(clk_init
);