diff options
author | Manuel Lauss <mano@roarinelk.homelinux.net> | 2008-12-21 03:26:24 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2009-01-11 04:57:27 -0500 |
commit | 2699cdfb765c3b7d77d28ea3bc7d84e486697177 (patch) | |
tree | 690eb6e847c7acfc0a5693a385907da480f33fd8 /arch/mips/alchemy/common/clocks.c | |
parent | 0c694de12b54fa96b9555e07603f567906ce21c8 (diff) |
MIPS: Alchemy: move calc_clock function.
Now that nothing in time.c depends on calc_clock, it can
be moved to clocks.c where it belongs.
While at it, give it a better non-generic name and call it
as soon as possible in plat_mem_init.
Signed-off-by: Manuel Lauss <mano@roarinelk.homelinux.net>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/alchemy/common/clocks.c')
-rw-r--r-- | arch/mips/alchemy/common/clocks.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/arch/mips/alchemy/common/clocks.c b/arch/mips/alchemy/common/clocks.c index a8170fda4932..d8991854530e 100644 --- a/arch/mips/alchemy/common/clocks.c +++ b/arch/mips/alchemy/common/clocks.c | |||
@@ -27,11 +27,21 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <linux/module.h> | 29 | #include <linux/module.h> |
30 | #include <linux/spinlock.h> | ||
31 | #include <asm/time.h> | ||
30 | #include <asm/mach-au1x00/au1000.h> | 32 | #include <asm/mach-au1x00/au1000.h> |
31 | 33 | ||
34 | /* | ||
35 | * I haven't found anyone that doesn't use a 12 MHz source clock, | ||
36 | * but just in case..... | ||
37 | */ | ||
38 | #define AU1000_SRC_CLK 12000000 | ||
39 | |||
32 | static unsigned int au1x00_clock; /* Hz */ | 40 | static unsigned int au1x00_clock; /* Hz */ |
33 | static unsigned long uart_baud_base; | 41 | static unsigned long uart_baud_base; |
34 | 42 | ||
43 | static DEFINE_SPINLOCK(time_lock); | ||
44 | |||
35 | /* | 45 | /* |
36 | * Set the au1000_clock | 46 | * Set the au1000_clock |
37 | */ | 47 | */ |
@@ -60,3 +70,47 @@ void set_au1x00_uart_baud_base(unsigned long new_baud_base) | |||
60 | { | 70 | { |
61 | uart_baud_base = new_baud_base; | 71 | uart_baud_base = new_baud_base; |
62 | } | 72 | } |
73 | |||
74 | /* | ||
75 | * We read the real processor speed from the PLL. This is important | ||
76 | * because it is more accurate than computing it from the 32 KHz | ||
77 | * counter, if it exists. If we don't have an accurate processor | ||
78 | * speed, all of the peripherals that derive their clocks based on | ||
79 | * this advertised speed will introduce error and sometimes not work | ||
80 | * properly. This function is futher convoluted to still allow configurations | ||
81 | * to do that in case they have really, really old silicon with a | ||
82 | * write-only PLL register. -- Dan | ||
83 | */ | ||
84 | unsigned long au1xxx_calc_clock(void) | ||
85 | { | ||
86 | unsigned long cpu_speed; | ||
87 | unsigned long flags; | ||
88 | |||
89 | spin_lock_irqsave(&time_lock, flags); | ||
90 | |||
91 | /* | ||
92 | * On early Au1000, sys_cpupll was write-only. Since these | ||
93 | * silicon versions of Au1000 are not sold by AMD, we don't bend | ||
94 | * over backwards trying to determine the frequency. | ||
95 | */ | ||
96 | if (au1xxx_cpu_has_pll_wo()) | ||
97 | #ifdef CONFIG_SOC_AU1000_FREQUENCY | ||
98 | cpu_speed = CONFIG_SOC_AU1000_FREQUENCY; | ||
99 | #else | ||
100 | cpu_speed = 396000000; | ||
101 | #endif | ||
102 | else | ||
103 | cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK; | ||
104 | |||
105 | /* On Alchemy CPU:counter ratio is 1:1 */ | ||
106 | mips_hpt_frequency = cpu_speed; | ||
107 | /* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */ | ||
108 | set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL) | ||
109 | & 0x03) + 2) * 16)); | ||
110 | |||
111 | spin_unlock_irqrestore(&time_lock, flags); | ||
112 | |||
113 | set_au1x00_speed(cpu_speed); | ||
114 | |||
115 | return cpu_speed; | ||
116 | } | ||