diff options
Diffstat (limited to 'arch/mips/alchemy/common/clocks.c')
-rw-r--r-- | arch/mips/alchemy/common/clocks.c | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/arch/mips/alchemy/common/clocks.c b/arch/mips/alchemy/common/clocks.c index 043429d17c5f..d8991854530e 100644 --- a/arch/mips/alchemy/common/clocks.c +++ b/arch/mips/alchemy/common/clocks.c | |||
@@ -27,12 +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 int lcd_clock; /* KHz */ | ||
34 | static unsigned long uart_baud_base; | 41 | static unsigned long uart_baud_base; |
35 | 42 | ||
43 | static DEFINE_SPINLOCK(time_lock); | ||
44 | |||
36 | /* | 45 | /* |
37 | * Set the au1000_clock | 46 | * Set the au1000_clock |
38 | */ | 47 | */ |
@@ -63,31 +72,45 @@ void set_au1x00_uart_baud_base(unsigned long new_baud_base) | |||
63 | } | 72 | } |
64 | 73 | ||
65 | /* | 74 | /* |
66 | * Calculate the Au1x00's LCD clock based on the current | 75 | * We read the real processor speed from the PLL. This is important |
67 | * cpu clock and the system bus clock, and try to keep it | 76 | * because it is more accurate than computing it from the 32 KHz |
68 | * below 40 MHz (the Pb1000 board can lock-up if the LCD | 77 | * counter, if it exists. If we don't have an accurate processor |
69 | * clock is over 40 MHz). | 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 | ||
70 | */ | 83 | */ |
71 | void set_au1x00_lcd_clock(void) | 84 | unsigned long au1xxx_calc_clock(void) |
72 | { | 85 | { |
73 | unsigned int static_cfg0; | 86 | unsigned long cpu_speed; |
74 | unsigned int sys_busclk = (get_au1x00_speed() / 1000) / | 87 | unsigned long flags; |
75 | ((int)(au_readl(SYS_POWERCTRL) & 0x03) + 2); | ||
76 | 88 | ||
77 | static_cfg0 = au_readl(MEM_STCFG0); | 89 | spin_lock_irqsave(&time_lock, flags); |
78 | 90 | ||
79 | if (static_cfg0 & (1 << 11)) | 91 | /* |
80 | lcd_clock = sys_busclk / 5; /* note: BCLK switching fails with D5 */ | 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 | ||
81 | else | 102 | else |
82 | lcd_clock = sys_busclk / 4; | 103 | cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK; |
83 | 104 | ||
84 | if (lcd_clock > 50000) /* Epson MAX */ | 105 | /* On Alchemy CPU:counter ratio is 1:1 */ |
85 | printk(KERN_WARNING "warning: LCD clock too high (%u KHz)\n", | 106 | mips_hpt_frequency = cpu_speed; |
86 | lcd_clock); | 107 | /* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */ |
87 | } | 108 | set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL) |
109 | & 0x03) + 2) * 16)); | ||
88 | 110 | ||
89 | unsigned int get_au1x00_lcd_clock(void) | 111 | spin_unlock_irqrestore(&time_lock, flags); |
90 | { | 112 | |
91 | return lcd_clock; | 113 | set_au1x00_speed(cpu_speed); |
114 | |||
115 | return cpu_speed; | ||
92 | } | 116 | } |
93 | EXPORT_SYMBOL(get_au1x00_lcd_clock); | ||