diff options
Diffstat (limited to 'arch/mips/kernel/time.c')
-rw-r--r-- | arch/mips/kernel/time.c | 64 |
1 files changed, 24 insertions, 40 deletions
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c index e535f86efa2f..11aab6d6bfe5 100644 --- a/arch/mips/kernel/time.c +++ b/arch/mips/kernel/time.c | |||
@@ -11,7 +11,6 @@ | |||
11 | * Free Software Foundation; either version 2 of the License, or (at your | 11 | * Free Software Foundation; either version 2 of the License, or (at your |
12 | * option) any later version. | 12 | * option) any later version. |
13 | */ | 13 | */ |
14 | #include <linux/clocksource.h> | ||
15 | #include <linux/types.h> | 14 | #include <linux/types.h> |
16 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
17 | #include <linux/init.h> | 16 | #include <linux/init.h> |
@@ -83,17 +82,11 @@ static void null_timer_ack(void) { /* nothing */ } | |||
83 | /* | 82 | /* |
84 | * Null high precision timer functions for systems lacking one. | 83 | * Null high precision timer functions for systems lacking one. |
85 | */ | 84 | */ |
86 | static unsigned int null_hpt_read(void) | 85 | static cycle_t null_hpt_read(void) |
87 | { | 86 | { |
88 | return 0; | 87 | return 0; |
89 | } | 88 | } |
90 | 89 | ||
91 | static void __init null_hpt_init(void) | ||
92 | { | ||
93 | /* nothing */ | ||
94 | } | ||
95 | |||
96 | |||
97 | /* | 90 | /* |
98 | * Timer ack for an R4k-compatible timer of a known frequency. | 91 | * Timer ack for an R4k-compatible timer of a known frequency. |
99 | */ | 92 | */ |
@@ -118,7 +111,7 @@ static void c0_timer_ack(void) | |||
118 | /* | 111 | /* |
119 | * High precision timer functions for a R4k-compatible timer. | 112 | * High precision timer functions for a R4k-compatible timer. |
120 | */ | 113 | */ |
121 | static unsigned int c0_hpt_read(void) | 114 | static cycle_t c0_hpt_read(void) |
122 | { | 115 | { |
123 | return read_c0_count(); | 116 | return read_c0_count(); |
124 | } | 117 | } |
@@ -132,9 +125,6 @@ static void __init c0_hpt_timer_init(void) | |||
132 | 125 | ||
133 | int (*mips_timer_state)(void); | 126 | int (*mips_timer_state)(void); |
134 | void (*mips_timer_ack)(void); | 127 | void (*mips_timer_ack)(void); |
135 | unsigned int (*mips_hpt_read)(void); | ||
136 | void (*mips_hpt_init)(void) __initdata = null_hpt_init; | ||
137 | unsigned int mips_hpt_mask = 0xffffffff; | ||
138 | 128 | ||
139 | /* last time when xtime and rtc are sync'ed up */ | 129 | /* last time when xtime and rtc are sync'ed up */ |
140 | static long last_rtc_update; | 130 | static long last_rtc_update; |
@@ -276,8 +266,7 @@ static struct irqaction timer_irqaction = { | |||
276 | 266 | ||
277 | static unsigned int __init calibrate_hpt(void) | 267 | static unsigned int __init calibrate_hpt(void) |
278 | { | 268 | { |
279 | u64 frequency; | 269 | cycle_t frequency, hpt_start, hpt_end, hpt_count, hz; |
280 | u32 hpt_start, hpt_end, hpt_count, hz; | ||
281 | 270 | ||
282 | const int loops = HZ / 10; | 271 | const int loops = HZ / 10; |
283 | int log_2_loops = 0; | 272 | int log_2_loops = 0; |
@@ -303,28 +292,23 @@ static unsigned int __init calibrate_hpt(void) | |||
303 | * during the calculated number of periods between timer | 292 | * during the calculated number of periods between timer |
304 | * interrupts. | 293 | * interrupts. |
305 | */ | 294 | */ |
306 | hpt_start = mips_hpt_read(); | 295 | hpt_start = clocksource_mips.read(); |
307 | do { | 296 | do { |
308 | while (mips_timer_state()); | 297 | while (mips_timer_state()); |
309 | while (!mips_timer_state()); | 298 | while (!mips_timer_state()); |
310 | } while (--i); | 299 | } while (--i); |
311 | hpt_end = mips_hpt_read(); | 300 | hpt_end = clocksource_mips.read(); |
312 | 301 | ||
313 | hpt_count = (hpt_end - hpt_start) & mips_hpt_mask; | 302 | hpt_count = (hpt_end - hpt_start) & clocksource_mips.mask; |
314 | hz = HZ; | 303 | hz = HZ; |
315 | frequency = (u64)hpt_count * (u64)hz; | 304 | frequency = hpt_count * hz; |
316 | 305 | ||
317 | return frequency >> log_2_loops; | 306 | return frequency >> log_2_loops; |
318 | } | 307 | } |
319 | 308 | ||
320 | static cycle_t read_mips_hpt(void) | 309 | struct clocksource clocksource_mips = { |
321 | { | ||
322 | return (cycle_t)mips_hpt_read(); | ||
323 | } | ||
324 | |||
325 | static struct clocksource clocksource_mips = { | ||
326 | .name = "MIPS", | 310 | .name = "MIPS", |
327 | .read = read_mips_hpt, | 311 | .mask = 0xffffffff, |
328 | .is_continuous = 1, | 312 | .is_continuous = 1, |
329 | }; | 313 | }; |
330 | 314 | ||
@@ -333,7 +317,7 @@ static void __init init_mips_clocksource(void) | |||
333 | u64 temp; | 317 | u64 temp; |
334 | u32 shift; | 318 | u32 shift; |
335 | 319 | ||
336 | if (!mips_hpt_frequency || mips_hpt_read == null_hpt_read) | 320 | if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read) |
337 | return; | 321 | return; |
338 | 322 | ||
339 | /* Calclate a somewhat reasonable rating value */ | 323 | /* Calclate a somewhat reasonable rating value */ |
@@ -347,7 +331,6 @@ static void __init init_mips_clocksource(void) | |||
347 | } | 331 | } |
348 | clocksource_mips.shift = shift; | 332 | clocksource_mips.shift = shift; |
349 | clocksource_mips.mult = (u32)temp; | 333 | clocksource_mips.mult = (u32)temp; |
350 | clocksource_mips.mask = mips_hpt_mask; | ||
351 | 334 | ||
352 | clocksource_register(&clocksource_mips); | 335 | clocksource_register(&clocksource_mips); |
353 | } | 336 | } |
@@ -367,32 +350,36 @@ void __init time_init(void) | |||
367 | -xtime.tv_sec, -xtime.tv_nsec); | 350 | -xtime.tv_sec, -xtime.tv_nsec); |
368 | 351 | ||
369 | /* Choose appropriate high precision timer routines. */ | 352 | /* Choose appropriate high precision timer routines. */ |
370 | if (!cpu_has_counter && !mips_hpt_read) | 353 | if (!cpu_has_counter && !clocksource_mips.read) |
371 | /* No high precision timer -- sorry. */ | 354 | /* No high precision timer -- sorry. */ |
372 | mips_hpt_read = null_hpt_read; | 355 | clocksource_mips.read = null_hpt_read; |
373 | else if (!mips_hpt_frequency && !mips_timer_state) { | 356 | else if (!mips_hpt_frequency && !mips_timer_state) { |
374 | /* A high precision timer of unknown frequency. */ | 357 | /* A high precision timer of unknown frequency. */ |
375 | if (!mips_hpt_read) | 358 | if (!clocksource_mips.read) |
376 | /* No external high precision timer -- use R4k. */ | 359 | /* No external high precision timer -- use R4k. */ |
377 | mips_hpt_read = c0_hpt_read; | 360 | clocksource_mips.read = c0_hpt_read; |
378 | } else { | 361 | } else { |
379 | /* We know counter frequency. Or we can get it. */ | 362 | /* We know counter frequency. Or we can get it. */ |
380 | if (!mips_hpt_read) { | 363 | if (!clocksource_mips.read) { |
381 | /* No external high precision timer -- use R4k. */ | 364 | /* No external high precision timer -- use R4k. */ |
382 | mips_hpt_read = c0_hpt_read; | 365 | clocksource_mips.read = c0_hpt_read; |
383 | 366 | ||
384 | if (!mips_timer_state) { | 367 | if (!mips_timer_state) { |
385 | /* No external timer interrupt -- use R4k. */ | 368 | /* No external timer interrupt -- use R4k. */ |
386 | mips_hpt_init = c0_hpt_timer_init; | ||
387 | mips_timer_ack = c0_timer_ack; | 369 | mips_timer_ack = c0_timer_ack; |
370 | /* Calculate cache parameters. */ | ||
371 | cycles_per_jiffy = | ||
372 | (mips_hpt_frequency + HZ / 2) / HZ; | ||
373 | /* | ||
374 | * This sets up the high precision | ||
375 | * timer for the first interrupt. | ||
376 | */ | ||
377 | c0_hpt_timer_init(); | ||
388 | } | 378 | } |
389 | } | 379 | } |
390 | if (!mips_hpt_frequency) | 380 | if (!mips_hpt_frequency) |
391 | mips_hpt_frequency = calibrate_hpt(); | 381 | mips_hpt_frequency = calibrate_hpt(); |
392 | 382 | ||
393 | /* Calculate cache parameters. */ | ||
394 | cycles_per_jiffy = (mips_hpt_frequency + HZ / 2) / HZ; | ||
395 | |||
396 | /* Report the high precision timer rate for a reference. */ | 383 | /* Report the high precision timer rate for a reference. */ |
397 | printk("Using %u.%03u MHz high precision timer.\n", | 384 | printk("Using %u.%03u MHz high precision timer.\n", |
398 | ((mips_hpt_frequency + 500) / 1000) / 1000, | 385 | ((mips_hpt_frequency + 500) / 1000) / 1000, |
@@ -403,9 +390,6 @@ void __init time_init(void) | |||
403 | /* No timer interrupt ack (e.g. i8254). */ | 390 | /* No timer interrupt ack (e.g. i8254). */ |
404 | mips_timer_ack = null_timer_ack; | 391 | mips_timer_ack = null_timer_ack; |
405 | 392 | ||
406 | /* This sets up the high precision timer for the first interrupt. */ | ||
407 | mips_hpt_init(); | ||
408 | |||
409 | /* | 393 | /* |
410 | * Call board specific timer interrupt setup. | 394 | * Call board specific timer interrupt setup. |
411 | * | 395 | * |