aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/alchemy/common/clocks.c54
-rw-r--r--arch/mips/alchemy/common/setup.c9
-rw-r--r--arch/mips/alchemy/common/time.c54
-rw-r--r--arch/mips/include/asm/mach-au1x00/au1000.h1
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
32static unsigned int au1x00_clock; /* Hz */ 40static unsigned int au1x00_clock; /* Hz */
33static unsigned long uart_baud_base; 41static unsigned long uart_baud_base;
34 42
43static 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 */
84unsigned 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
45void __init plat_mem_setup(void) 45void __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
45extern int allow_au1k_wait; /* default off for CP0 Counter */ 45extern int allow_au1k_wait; /* default off for CP0 Counter */
46 46
47static 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 */
65unsigned 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
94static cycle_t au1x_counter1_read(void) 47static 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);
135extern unsigned int get_au1x00_speed(void); 135extern unsigned int get_au1x00_speed(void);
136extern void set_au1x00_uart_baud_base(unsigned long new_baud_base); 136extern void set_au1x00_uart_baud_base(unsigned long new_baud_base);
137extern unsigned long get_au1x00_uart_baud_base(void); 137extern unsigned long get_au1x00_uart_baud_base(void);
138extern 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.