diff options
Diffstat (limited to 'arch/mips/au1000/common/time.c')
-rw-r--r-- | arch/mips/au1000/common/time.c | 78 |
1 files changed, 35 insertions, 43 deletions
diff --git a/arch/mips/au1000/common/time.c b/arch/mips/au1000/common/time.c index bdb6d73b26fb..563d9390a872 100644 --- a/arch/mips/au1000/common/time.c +++ b/arch/mips/au1000/common/time.c | |||
@@ -25,11 +25,9 @@ | |||
25 | * | 25 | * |
26 | * Setting up the clock on the MIPS boards. | 26 | * Setting up the clock on the MIPS boards. |
27 | * | 27 | * |
28 | * Update. Always configure the kernel with CONFIG_NEW_TIME_C. This | 28 | * We provide the clock interrupt processing and the timer offset compute |
29 | * will use the user interface gettimeofday() functions from the | 29 | * functions. If CONFIG_PM is selected, we also ensure the 32KHz timer is |
30 | * arch/mips/kernel/time.c, and we provide the clock interrupt processing | 30 | * available. -- Dan |
31 | * and the timer offset compute functions. If CONFIG_PM is selected, | ||
32 | * we also ensure the 32KHz timer is available. -- Dan | ||
33 | */ | 31 | */ |
34 | 32 | ||
35 | #include <linux/types.h> | 33 | #include <linux/types.h> |
@@ -47,8 +45,7 @@ extern int allow_au1k_wait; /* default off for CP0 Counter */ | |||
47 | #if HZ < 100 || HZ > 1000 | 45 | #if HZ < 100 || HZ > 1000 |
48 | #error "unsupported HZ value! Must be in [100,1000]" | 46 | #error "unsupported HZ value! Must be in [100,1000]" |
49 | #endif | 47 | #endif |
50 | #define MATCH20_INC (328*100/HZ) /* magic number 328 is for HZ=100... */ | 48 | #define MATCH20_INC (328 * 100 / HZ) /* magic number 328 is for HZ=100... */ |
51 | extern void startup_match20_interrupt(irq_handler_t handler); | ||
52 | static unsigned long last_pc0, last_match20; | 49 | static unsigned long last_pc0, last_match20; |
53 | #endif | 50 | #endif |
54 | 51 | ||
@@ -61,7 +58,7 @@ static irqreturn_t counter0_irq(int irq, void *dev_id) | |||
61 | { | 58 | { |
62 | unsigned long pc0; | 59 | unsigned long pc0; |
63 | int time_elapsed; | 60 | int time_elapsed; |
64 | static int jiffie_drift = 0; | 61 | static int jiffie_drift; |
65 | 62 | ||
66 | if (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20) { | 63 | if (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20) { |
67 | /* should never happen! */ | 64 | /* should never happen! */ |
@@ -70,13 +67,11 @@ static irqreturn_t counter0_irq(int irq, void *dev_id) | |||
70 | } | 67 | } |
71 | 68 | ||
72 | pc0 = au_readl(SYS_TOYREAD); | 69 | pc0 = au_readl(SYS_TOYREAD); |
73 | if (pc0 < last_match20) { | 70 | if (pc0 < last_match20) |
74 | /* counter overflowed */ | 71 | /* counter overflowed */ |
75 | time_elapsed = (0xffffffff - last_match20) + pc0; | 72 | time_elapsed = (0xffffffff - last_match20) + pc0; |
76 | } | 73 | else |
77 | else { | ||
78 | time_elapsed = pc0 - last_match20; | 74 | time_elapsed = pc0 - last_match20; |
79 | } | ||
80 | 75 | ||
81 | while (time_elapsed > 0) { | 76 | while (time_elapsed > 0) { |
82 | do_timer(1); | 77 | do_timer(1); |
@@ -92,8 +87,9 @@ static irqreturn_t counter0_irq(int irq, void *dev_id) | |||
92 | au_writel(last_match20 + MATCH20_INC, SYS_TOYMATCH2); | 87 | au_writel(last_match20 + MATCH20_INC, SYS_TOYMATCH2); |
93 | au_sync(); | 88 | au_sync(); |
94 | 89 | ||
95 | /* our counter ticks at 10.009765625 ms/tick, we we're running | 90 | /* |
96 | * almost 10uS too slow per tick. | 91 | * Our counter ticks at 10.009765625 ms/tick, we we're running |
92 | * almost 10 uS too slow per tick. | ||
97 | */ | 93 | */ |
98 | 94 | ||
99 | if (jiffie_drift >= 999) { | 95 | if (jiffie_drift >= 999) { |
@@ -117,20 +113,17 @@ struct irqaction counter0_action = { | |||
117 | /* When we wakeup from sleep, we have to "catch up" on all of the | 113 | /* When we wakeup from sleep, we have to "catch up" on all of the |
118 | * timer ticks we have missed. | 114 | * timer ticks we have missed. |
119 | */ | 115 | */ |
120 | void | 116 | void wakeup_counter0_adjust(void) |
121 | wakeup_counter0_adjust(void) | ||
122 | { | 117 | { |
123 | unsigned long pc0; | 118 | unsigned long pc0; |
124 | int time_elapsed; | 119 | int time_elapsed; |
125 | 120 | ||
126 | pc0 = au_readl(SYS_TOYREAD); | 121 | pc0 = au_readl(SYS_TOYREAD); |
127 | if (pc0 < last_match20) { | 122 | if (pc0 < last_match20) |
128 | /* counter overflowed */ | 123 | /* counter overflowed */ |
129 | time_elapsed = (0xffffffff - last_match20) + pc0; | 124 | time_elapsed = (0xffffffff - last_match20) + pc0; |
130 | } | 125 | else |
131 | else { | ||
132 | time_elapsed = pc0 - last_match20; | 126 | time_elapsed = pc0 - last_match20; |
133 | } | ||
134 | 127 | ||
135 | while (time_elapsed > 0) { | 128 | while (time_elapsed > 0) { |
136 | time_elapsed -= MATCH20_INC; | 129 | time_elapsed -= MATCH20_INC; |
@@ -143,10 +136,8 @@ wakeup_counter0_adjust(void) | |||
143 | 136 | ||
144 | } | 137 | } |
145 | 138 | ||
146 | /* This is just for debugging to set the timer for a sleep delay. | 139 | /* This is just for debugging to set the timer for a sleep delay. */ |
147 | */ | 140 | void wakeup_counter0_set(int ticks) |
148 | void | ||
149 | wakeup_counter0_set(int ticks) | ||
150 | { | 141 | { |
151 | unsigned long pc0; | 142 | unsigned long pc0; |
152 | 143 | ||
@@ -157,21 +148,22 @@ wakeup_counter0_set(int ticks) | |||
157 | } | 148 | } |
158 | #endif | 149 | #endif |
159 | 150 | ||
160 | /* I haven't found anyone that doesn't use a 12 MHz source clock, | 151 | /* |
152 | * I haven't found anyone that doesn't use a 12 MHz source clock, | ||
161 | * but just in case..... | 153 | * but just in case..... |
162 | */ | 154 | */ |
163 | #define AU1000_SRC_CLK 12000000 | 155 | #define AU1000_SRC_CLK 12000000 |
164 | 156 | ||
165 | /* | 157 | /* |
166 | * We read the real processor speed from the PLL. This is important | 158 | * We read the real processor speed from the PLL. This is important |
167 | * because it is more accurate than computing it from the 32KHz | 159 | * because it is more accurate than computing it from the 32 KHz |
168 | * counter, if it exists. If we don't have an accurate processor | 160 | * counter, if it exists. If we don't have an accurate processor |
169 | * speed, all of the peripherals that derive their clocks based on | 161 | * speed, all of the peripherals that derive their clocks based on |
170 | * this advertised speed will introduce error and sometimes not work | 162 | * this advertised speed will introduce error and sometimes not work |
171 | * properly. This function is futher convoluted to still allow configurations | 163 | * properly. This function is futher convoluted to still allow configurations |
172 | * to do that in case they have really, really old silicon with a | 164 | * to do that in case they have really, really old silicon with a |
173 | * write-only PLL register, that we need the 32KHz when power management | 165 | * write-only PLL register, that we need the 32 KHz when power management |
174 | * "wait" is enabled, and we need to detect if the 32KHz isn't present | 166 | * "wait" is enabled, and we need to detect if the 32 KHz isn't present |
175 | * but requested......got it? :-) -- Dan | 167 | * but requested......got it? :-) -- Dan |
176 | */ | 168 | */ |
177 | unsigned long calc_clock(void) | 169 | unsigned long calc_clock(void) |
@@ -182,8 +174,7 @@ unsigned long calc_clock(void) | |||
182 | 174 | ||
183 | spin_lock_irqsave(&time_lock, flags); | 175 | spin_lock_irqsave(&time_lock, flags); |
184 | 176 | ||
185 | /* Power management cares if we don't have a 32KHz counter. | 177 | /* Power management cares if we don't have a 32 KHz counter. */ |
186 | */ | ||
187 | no_au1xxx_32khz = 0; | 178 | no_au1xxx_32khz = 0; |
188 | counter = au_readl(SYS_COUNTER_CNTRL); | 179 | counter = au_readl(SYS_COUNTER_CNTRL); |
189 | if (counter & SYS_CNTRL_E0) { | 180 | if (counter & SYS_CNTRL_E0) { |
@@ -193,7 +184,7 @@ unsigned long calc_clock(void) | |||
193 | 184 | ||
194 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S); | 185 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S); |
195 | /* RTC now ticks at 32.768/16 kHz */ | 186 | /* RTC now ticks at 32.768/16 kHz */ |
196 | au_writel(trim_divide-1, SYS_RTCTRIM); | 187 | au_writel(trim_divide - 1, SYS_RTCTRIM); |
197 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S); | 188 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S); |
198 | 189 | ||
199 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S); | 190 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S); |
@@ -215,9 +206,11 @@ unsigned long calc_clock(void) | |||
215 | #endif | 206 | #endif |
216 | else | 207 | else |
217 | cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK; | 208 | cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK; |
209 | /* On Alchemy CPU:counter ratio is 1:1 */ | ||
218 | mips_hpt_frequency = cpu_speed; | 210 | mips_hpt_frequency = cpu_speed; |
219 | // Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) | 211 | /* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */ |
220 | set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL)&0x03) + 2) * 16)); | 212 | set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL) |
213 | & 0x03) + 2) * 16)); | ||
221 | spin_unlock_irqrestore(&time_lock, flags); | 214 | spin_unlock_irqrestore(&time_lock, flags); |
222 | return cpu_speed; | 215 | return cpu_speed; |
223 | } | 216 | } |
@@ -228,10 +221,10 @@ void __init plat_time_init(void) | |||
228 | 221 | ||
229 | est_freq += 5000; /* round */ | 222 | est_freq += 5000; /* round */ |
230 | est_freq -= est_freq%10000; | 223 | est_freq -= est_freq%10000; |
231 | printk("CPU frequency %d.%02d MHz\n", est_freq/1000000, | 224 | printk(KERN_INFO "CPU frequency %u.%02u MHz\n", |
232 | (est_freq%1000000)*100/1000000); | 225 | est_freq / 1000000, ((est_freq % 1000000) * 100) / 1000000); |
233 | set_au1x00_speed(est_freq); | 226 | set_au1x00_speed(est_freq); |
234 | set_au1x00_lcd_clock(); // program the LCD clock | 227 | set_au1x00_lcd_clock(); /* program the LCD clock */ |
235 | 228 | ||
236 | #ifdef CONFIG_PM | 229 | #ifdef CONFIG_PM |
237 | /* | 230 | /* |
@@ -243,30 +236,29 @@ void __init plat_time_init(void) | |||
243 | * counter 0 interrupt as a special irq and it doesn't show | 236 | * counter 0 interrupt as a special irq and it doesn't show |
244 | * up under /proc/interrupts. | 237 | * up under /proc/interrupts. |
245 | * | 238 | * |
246 | * Check to ensure we really have a 32KHz oscillator before | 239 | * Check to ensure we really have a 32 KHz oscillator before |
247 | * we do this. | 240 | * we do this. |
248 | */ | 241 | */ |
249 | if (no_au1xxx_32khz) | 242 | if (no_au1xxx_32khz) |
250 | printk("WARNING: no 32KHz clock found.\n"); | 243 | printk(KERN_WARNING "WARNING: no 32KHz clock found.\n"); |
251 | else { | 244 | else { |
252 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S); | 245 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S); |
253 | au_writel(0, SYS_TOYWRITE); | 246 | au_writel(0, SYS_TOYWRITE); |
254 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S); | 247 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S); |
255 | 248 | ||
256 | au_writel(au_readl(SYS_WAKEMSK) | (1<<8), SYS_WAKEMSK); | 249 | au_writel(au_readl(SYS_WAKEMSK) | (1 << 8), SYS_WAKEMSK); |
257 | au_writel(~0, SYS_WAKESRC); | 250 | au_writel(~0, SYS_WAKESRC); |
258 | au_sync(); | 251 | au_sync(); |
259 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20); | 252 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20); |
260 | 253 | ||
261 | /* setup match20 to interrupt once every HZ */ | 254 | /* Setup match20 to interrupt once every HZ */ |
262 | last_pc0 = last_match20 = au_readl(SYS_TOYREAD); | 255 | last_pc0 = last_match20 = au_readl(SYS_TOYREAD); |
263 | au_writel(last_match20 + MATCH20_INC, SYS_TOYMATCH2); | 256 | au_writel(last_match20 + MATCH20_INC, SYS_TOYMATCH2); |
264 | au_sync(); | 257 | au_sync(); |
265 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20); | 258 | while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20); |
266 | setup_irq(AU1000_TOY_MATCH2_INT, &counter0_action); | 259 | setup_irq(AU1000_TOY_MATCH2_INT, &counter0_action); |
267 | 260 | ||
268 | /* We can use the real 'wait' instruction. | 261 | /* We can use the real 'wait' instruction. */ |
269 | */ | ||
270 | allow_au1k_wait = 1; | 262 | allow_au1k_wait = 1; |
271 | } | 263 | } |
272 | 264 | ||