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 | |
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')
-rw-r--r-- | arch/mips/alchemy/common/clocks.c | 54 | ||||
-rw-r--r-- | arch/mips/alchemy/common/setup.c | 9 | ||||
-rw-r--r-- | arch/mips/alchemy/common/time.c | 54 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-au1x00/au1000.h | 1 |
4 files changed, 64 insertions, 54 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 | } | ||
diff --git a/arch/mips/alchemy/common/setup.c b/arch/mips/alchemy/common/setup.c index 8ad453af2c64..3f036b3d400e 100644 --- a/arch/mips/alchemy/common/setup.c +++ b/arch/mips/alchemy/common/setup.c | |||
@@ -44,6 +44,15 @@ extern void set_cpuspec(void); | |||
44 | 44 | ||
45 | void __init plat_mem_setup(void) | 45 | void __init plat_mem_setup(void) |
46 | { | 46 | { |
47 | unsigned long est_freq; | ||
48 | |||
49 | /* determine core clock */ | ||
50 | est_freq = au1xxx_calc_clock(); | ||
51 | est_freq += 5000; /* round */ | ||
52 | est_freq -= est_freq % 10000; | ||
53 | printk(KERN_INFO "(PRId %08x) @ %lu.%02lu MHz\n", read_c0_prid(), | ||
54 | est_freq / 1000000, ((est_freq % 1000000) * 100) / 1000000); | ||
55 | |||
47 | _machine_restart = au1000_restart; | 56 | _machine_restart = au1000_restart; |
48 | _machine_halt = au1000_halt; | 57 | _machine_halt = au1000_halt; |
49 | pm_power_off = au1000_power_off; | 58 | pm_power_off = au1000_power_off; |
diff --git a/arch/mips/alchemy/common/time.c b/arch/mips/alchemy/common/time.c index 57f0aec590b8..32880146cbc1 100644 --- a/arch/mips/alchemy/common/time.c +++ b/arch/mips/alchemy/common/time.c | |||
@@ -44,53 +44,6 @@ | |||
44 | 44 | ||
45 | extern int allow_au1k_wait; /* default off for CP0 Counter */ | 45 | extern int allow_au1k_wait; /* default off for CP0 Counter */ |
46 | 46 | ||
47 | static DEFINE_SPINLOCK(time_lock); | ||
48 | |||
49 | /* | ||
50 | * I haven't found anyone that doesn't use a 12 MHz source clock, | ||
51 | * but just in case..... | ||
52 | */ | ||
53 | #define AU1000_SRC_CLK 12000000 | ||
54 | |||
55 | /* | ||
56 | * We read the real processor speed from the PLL. This is important | ||
57 | * because it is more accurate than computing it from the 32 KHz | ||
58 | * counter, if it exists. If we don't have an accurate processor | ||
59 | * speed, all of the peripherals that derive their clocks based on | ||
60 | * this advertised speed will introduce error and sometimes not work | ||
61 | * properly. This function is futher convoluted to still allow configurations | ||
62 | * to do that in case they have really, really old silicon with a | ||
63 | * write-only PLL register. -- Dan | ||
64 | */ | ||
65 | unsigned long calc_clock(void) | ||
66 | { | ||
67 | unsigned long cpu_speed; | ||
68 | unsigned long flags; | ||
69 | |||
70 | spin_lock_irqsave(&time_lock, flags); | ||
71 | |||
72 | /* | ||
73 | * On early Au1000, sys_cpupll was write-only. Since these | ||
74 | * silicon versions of Au1000 are not sold by AMD, we don't bend | ||
75 | * over backwards trying to determine the frequency. | ||
76 | */ | ||
77 | if (au1xxx_cpu_has_pll_wo()) | ||
78 | #ifdef CONFIG_SOC_AU1000_FREQUENCY | ||
79 | cpu_speed = CONFIG_SOC_AU1000_FREQUENCY; | ||
80 | #else | ||
81 | cpu_speed = 396000000; | ||
82 | #endif | ||
83 | else | ||
84 | cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK; | ||
85 | /* On Alchemy CPU:counter ratio is 1:1 */ | ||
86 | mips_hpt_frequency = cpu_speed; | ||
87 | /* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */ | ||
88 | set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL) | ||
89 | & 0x03) + 2) * 16)); | ||
90 | spin_unlock_irqrestore(&time_lock, flags); | ||
91 | return cpu_speed; | ||
92 | } | ||
93 | |||
94 | static cycle_t au1x_counter1_read(void) | 47 | static cycle_t au1x_counter1_read(void) |
95 | { | 48 | { |
96 | return au_readl(SYS_RTCREAD); | 49 | return au_readl(SYS_RTCREAD); |
@@ -150,13 +103,6 @@ void __init plat_time_init(void) | |||
150 | { | 103 | { |
151 | struct clock_event_device *cd = &au1x_rtcmatch2_clockdev; | 104 | struct clock_event_device *cd = &au1x_rtcmatch2_clockdev; |
152 | unsigned long t; | 105 | unsigned long t; |
153 | unsigned int est_freq = calc_clock(); | ||
154 | |||
155 | est_freq += 5000; /* round */ | ||
156 | est_freq -= est_freq%10000; | ||
157 | printk(KERN_INFO "(PRId %08x) @ %u.%02u MHz\n", read_c0_prid(), | ||
158 | est_freq / 1000000, ((est_freq % 1000000) * 100) / 1000000); | ||
159 | set_au1x00_speed(est_freq); | ||
160 | 106 | ||
161 | /* Check if firmware (YAMON, ...) has enabled 32kHz and clock | 107 | /* Check if firmware (YAMON, ...) has enabled 32kHz and clock |
162 | * has been detected. If so install the rtcmatch2 clocksource, | 108 | * has been detected. If so install the rtcmatch2 clocksource, |
diff --git a/arch/mips/include/asm/mach-au1x00/au1000.h b/arch/mips/include/asm/mach-au1x00/au1000.h index 5db26e60a8c5..2b88c2982cb0 100644 --- a/arch/mips/include/asm/mach-au1x00/au1000.h +++ b/arch/mips/include/asm/mach-au1x00/au1000.h | |||
@@ -135,6 +135,7 @@ extern void set_au1x00_speed(unsigned int new_freq); | |||
135 | extern unsigned int get_au1x00_speed(void); | 135 | extern unsigned int get_au1x00_speed(void); |
136 | extern void set_au1x00_uart_baud_base(unsigned long new_baud_base); | 136 | extern void set_au1x00_uart_baud_base(unsigned long new_baud_base); |
137 | extern unsigned long get_au1x00_uart_baud_base(void); | 137 | extern unsigned long get_au1x00_uart_baud_base(void); |
138 | extern unsigned long au1xxx_calc_clock(void); | ||
138 | 139 | ||
139 | /* | 140 | /* |
140 | * Every board describes its IRQ mapping with this table. | 141 | * Every board describes its IRQ mapping with this table. |