Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2001 MontaVista Software Inc. |
| 3 | * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net |
| 4 | * Copyright (c) 2003, 2004 Maciej W. Rozycki |
| 5 | * |
| 6 | * Common time service routines for MIPS machines. See |
| 7 | * Documentation/mips/time.README. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
| 13 | */ |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 14 | #include <linux/clockchips.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/types.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/param.h> |
Yoichi Yuasa | b1043cc | 2007-09-13 13:13:28 +0900 | [diff] [blame] | 20 | #include <linux/profile.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/time.h> |
| 22 | #include <linux/timex.h> |
| 23 | #include <linux/smp.h> |
| 24 | #include <linux/kernel_stat.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <linux/module.h> |
| 28 | |
| 29 | #include <asm/bootinfo.h> |
Ralf Baechle | ec74e36 | 2005-07-13 11:48:45 +0000 | [diff] [blame] | 30 | #include <asm/cache.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/compiler.h> |
| 32 | #include <asm/cpu.h> |
| 33 | #include <asm/cpu-features.h> |
| 34 | #include <asm/div64.h> |
| 35 | #include <asm/sections.h> |
| 36 | #include <asm/time.h> |
| 37 | |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 38 | #include <irq.h> |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* |
| 41 | * The integer part of the number of usecs per jiffy is taken from tick, |
| 42 | * but the fractional part is not recorded, so we calculate it using the |
| 43 | * initial value of HZ. This aids systems where tick isn't really an |
| 44 | * integer (e.g. for HZ = 128). |
| 45 | */ |
| 46 | #define USECS_PER_JIFFY TICK_SIZE |
| 47 | #define USECS_PER_JIFFY_FRAC ((unsigned long)(u32)((1000000ULL << 32) / HZ)) |
| 48 | |
| 49 | #define TICK_SIZE (tick_nsec / 1000) |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * forward reference |
| 53 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | DEFINE_SPINLOCK(rtc_lock); |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 55 | EXPORT_SYMBOL(rtc_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 57 | int __weak rtc_mips_set_time(unsigned long sec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
| 59 | return 0; |
| 60 | } |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 61 | EXPORT_SYMBOL(rtc_mips_set_time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 63 | int __weak rtc_mips_set_mmss(unsigned long nowtime) |
| 64 | { |
| 65 | return rtc_mips_set_time(nowtime); |
| 66 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Ralf Baechle | f5ff0a2 | 2007-08-13 15:26:12 +0100 | [diff] [blame] | 68 | int update_persistent_clock(struct timespec now) |
| 69 | { |
| 70 | return rtc_mips_set_mmss(now.tv_sec); |
| 71 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | /* how many counter cycles in a jiffy */ |
Ralf Baechle | ec74e36 | 2005-07-13 11:48:45 +0000 | [diff] [blame] | 74 | static unsigned long cycles_per_jiffy __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* |
| 77 | * Null timer ack for systems not needing one (e.g. i8254). |
| 78 | */ |
| 79 | static void null_timer_ack(void) { /* nothing */ } |
| 80 | |
| 81 | /* |
| 82 | * Null high precision timer functions for systems lacking one. |
| 83 | */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 84 | static cycle_t null_hpt_read(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
| 86 | return 0; |
| 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Timer ack for an R4k-compatible timer of a known frequency. |
| 91 | */ |
| 92 | static void c0_timer_ack(void) |
| 93 | { |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 94 | write_c0_compare(read_c0_compare()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* |
| 98 | * High precision timer functions for a R4k-compatible timer. |
| 99 | */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 100 | static cycle_t c0_hpt_read(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | return read_c0_count(); |
| 103 | } |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | int (*mips_timer_state)(void); |
| 106 | void (*mips_timer_ack)(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | /* |
| 109 | * local_timer_interrupt() does profiling and process accounting |
| 110 | * on a per-CPU basis. |
| 111 | * |
| 112 | * In UP mode, it is invoked from the (global) timer_interrupt. |
| 113 | * |
| 114 | * In SMP mode, it might invoked by per-CPU timer interrupt, or |
| 115 | * a broadcasted inter-processor interrupt which itself is triggered |
| 116 | * by the global timer interrupt. |
| 117 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 118 | void local_timer_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 120 | profile_tick(CPU_PROFILING); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 121 | update_process_times(user_mode(get_irq_regs())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 124 | int null_perf_irq(void) |
Ralf Baechle | ba339c0 | 2005-12-09 12:29:38 +0000 | [diff] [blame] | 125 | { |
| 126 | return 0; |
| 127 | } |
| 128 | |
Ralf Baechle | 91a2fcc | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 129 | EXPORT_SYMBOL(null_perf_irq); |
| 130 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 131 | int (*perf_irq)(void) = null_perf_irq; |
Ralf Baechle | ba339c0 | 2005-12-09 12:29:38 +0000 | [diff] [blame] | 132 | |
Ralf Baechle | ba339c0 | 2005-12-09 12:29:38 +0000 | [diff] [blame] | 133 | EXPORT_SYMBOL(perf_irq); |
| 134 | |
Chris Dearman | ffe9ee4 | 2007-05-24 22:24:20 +0100 | [diff] [blame] | 135 | /* |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 136 | * Timer interrupt |
| 137 | */ |
| 138 | int cp0_compare_irq; |
| 139 | |
| 140 | /* |
Chris Dearman | ffe9ee4 | 2007-05-24 22:24:20 +0100 | [diff] [blame] | 141 | * Performance counter IRQ or -1 if shared with timer |
| 142 | */ |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 143 | int cp0_perfcount_irq; |
| 144 | EXPORT_SYMBOL_GPL(cp0_perfcount_irq); |
Chris Dearman | ffe9ee4 | 2007-05-24 22:24:20 +0100 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * Possibly handle a performance counter interrupt. |
| 148 | * Return true if the timer interrupt should not be checked |
| 149 | */ |
| 150 | static inline int handle_perf_irq (int r2) |
| 151 | { |
| 152 | /* |
| 153 | * The performance counter overflow interrupt may be shared with the |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 154 | * timer interrupt (cp0_perfcount_irq < 0). If it is and a |
Chris Dearman | ffe9ee4 | 2007-05-24 22:24:20 +0100 | [diff] [blame] | 155 | * performance counter has overflowed (perf_irq() == IRQ_HANDLED) |
| 156 | * and we can't reliably determine if a counter interrupt has also |
| 157 | * happened (!r2) then don't check for a timer interrupt. |
| 158 | */ |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 159 | return (cp0_perfcount_irq < 0) && |
Chris Dearman | ffe9ee4 | 2007-05-24 22:24:20 +0100 | [diff] [blame] | 160 | perf_irq() == IRQ_HANDLED && |
| 161 | !r2; |
| 162 | } |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* |
| 165 | * time_init() - it does the following things. |
| 166 | * |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 167 | * 1) plat_time_init() - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | * a) (optional) set up RTC routines, |
| 169 | * b) (optional) calibrate and set the mips_hpt_frequency |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 170 | * (only needed if you intended to use cpu counter as timer interrupt |
| 171 | * source) |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 172 | * 2) calculate a couple of cached variables for later usage |
| 173 | * 3) plat_timer_setup() - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * a) (optional) over-write any choices made above by time_init(). |
| 175 | * b) machine specific code should setup the timer irqaction. |
| 176 | * c) enable the timer interrupt |
| 177 | */ |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | unsigned int mips_hpt_frequency; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | static unsigned int __init calibrate_hpt(void) |
| 182 | { |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 183 | cycle_t frequency, hpt_start, hpt_end, hpt_count, hz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | const int loops = HZ / 10; |
| 186 | int log_2_loops = 0; |
| 187 | int i; |
| 188 | |
| 189 | /* |
| 190 | * We want to calibrate for 0.1s, but to avoid a 64-bit |
| 191 | * division we round the number of loops up to the nearest |
| 192 | * power of 2. |
| 193 | */ |
| 194 | while (loops > 1 << log_2_loops) |
| 195 | log_2_loops++; |
| 196 | i = 1 << log_2_loops; |
| 197 | |
| 198 | /* |
| 199 | * Wait for a rising edge of the timer interrupt. |
| 200 | */ |
| 201 | while (mips_timer_state()); |
| 202 | while (!mips_timer_state()); |
| 203 | |
| 204 | /* |
| 205 | * Now see how many high precision timer ticks happen |
| 206 | * during the calculated number of periods between timer |
| 207 | * interrupts. |
| 208 | */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 209 | hpt_start = clocksource_mips.read(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | do { |
| 211 | while (mips_timer_state()); |
| 212 | while (!mips_timer_state()); |
| 213 | } while (--i); |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 214 | hpt_end = clocksource_mips.read(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 216 | hpt_count = (hpt_end - hpt_start) & clocksource_mips.mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | hz = HZ; |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 218 | frequency = hpt_count * hz; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | return frequency >> log_2_loops; |
| 221 | } |
| 222 | |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 223 | struct clocksource clocksource_mips = { |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 224 | .name = "MIPS", |
Franck Bui-Huu | 55d0b4e | 2007-05-04 17:36:44 +0200 | [diff] [blame] | 225 | .mask = CLOCKSOURCE_MASK(32), |
Thomas Gleixner | 877fe38 | 2007-02-16 01:27:40 -0800 | [diff] [blame] | 226 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 227 | }; |
| 228 | |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 229 | static int mips_next_event(unsigned long delta, |
| 230 | struct clock_event_device *evt) |
| 231 | { |
| 232 | unsigned int cnt; |
| 233 | |
| 234 | cnt = read_c0_count(); |
| 235 | cnt += delta; |
| 236 | write_c0_compare(cnt); |
| 237 | |
| 238 | return ((long)(read_c0_count() - cnt ) > 0) ? -ETIME : 0; |
| 239 | } |
| 240 | |
| 241 | static void mips_set_mode(enum clock_event_mode mode, |
| 242 | struct clock_event_device *evt) |
| 243 | { |
| 244 | /* Nothing to do ... */ |
| 245 | } |
| 246 | |
| 247 | struct clock_event_device mips_clockevent; |
| 248 | |
| 249 | static struct clock_event_device *global_cd[NR_CPUS]; |
| 250 | static int cp0_timer_irq_installed; |
| 251 | |
| 252 | static irqreturn_t timer_interrupt(int irq, void *dev_id) |
| 253 | { |
| 254 | const int r2 = cpu_has_mips_r2; |
| 255 | struct clock_event_device *cd; |
| 256 | int cpu = smp_processor_id(); |
| 257 | |
| 258 | /* |
| 259 | * Suckage alert: |
| 260 | * Before R2 of the architecture there was no way to see if a |
| 261 | * performance counter interrupt was pending, so we have to run |
| 262 | * the performance counter interrupt handler anyway. |
| 263 | */ |
| 264 | if (handle_perf_irq(r2)) |
| 265 | goto out; |
| 266 | |
| 267 | /* |
| 268 | * The same applies to performance counter interrupts. But with the |
| 269 | * above we now know that the reason we got here must be a timer |
| 270 | * interrupt. Being the paranoiacs we are we check anyway. |
| 271 | */ |
| 272 | if (!r2 || (read_c0_cause() & (1 << 30))) { |
| 273 | c0_timer_ack(); |
| 274 | cd = global_cd[cpu]; |
| 275 | cd->event_handler(cd); |
| 276 | } |
| 277 | |
| 278 | out: |
| 279 | return IRQ_HANDLED; |
| 280 | } |
| 281 | |
| 282 | static struct irqaction timer_irqaction = { |
| 283 | .handler = timer_interrupt, |
| 284 | .flags = IRQF_DISABLED | IRQF_PERCPU, |
| 285 | .name = "timer", |
| 286 | }; |
| 287 | |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 288 | static void __init init_mips_clocksource(void) |
| 289 | { |
| 290 | u64 temp; |
| 291 | u32 shift; |
| 292 | |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 293 | if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read) |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 294 | return; |
| 295 | |
| 296 | /* Calclate a somewhat reasonable rating value */ |
| 297 | clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; |
| 298 | /* Find a shift value */ |
| 299 | for (shift = 32; shift > 0; shift--) { |
| 300 | temp = (u64) NSEC_PER_SEC << shift; |
| 301 | do_div(temp, mips_hpt_frequency); |
| 302 | if ((temp >> 32) == 0) |
| 303 | break; |
| 304 | } |
| 305 | clocksource_mips.shift = shift; |
| 306 | clocksource_mips.mult = (u32)temp; |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 307 | |
| 308 | clocksource_register(&clocksource_mips); |
| 309 | } |
| 310 | |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 311 | void __init __weak plat_time_init(void) |
| 312 | { |
| 313 | } |
| 314 | |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 315 | void __init __weak plat_timer_setup(struct irqaction *irq) |
| 316 | { |
| 317 | } |
| 318 | |
| 319 | void __cpuinit mips_clockevent_init(void) |
| 320 | { |
| 321 | uint64_t mips_freq = mips_hpt_frequency; |
| 322 | unsigned int cpu = smp_processor_id(); |
| 323 | struct clock_event_device *cd; |
| 324 | unsigned int irq = MIPS_CPU_IRQ_BASE + 7; |
| 325 | |
| 326 | if (!cpu_has_counter) |
| 327 | return; |
| 328 | |
| 329 | if (cpu == 0) |
| 330 | cd = &mips_clockevent; |
| 331 | else |
| 332 | cd = kzalloc(sizeof(*cd), GFP_ATOMIC); |
| 333 | if (!cd) |
| 334 | return; /* We're probably roadkill ... */ |
| 335 | |
| 336 | cd->name = "MIPS"; |
| 337 | cd->features = CLOCK_EVT_FEAT_ONESHOT; |
| 338 | |
| 339 | /* Calculate the min / max delta */ |
| 340 | cd->mult = div_sc((unsigned long) mips_freq, NSEC_PER_SEC, 32); |
| 341 | cd->shift = 32; |
| 342 | cd->max_delta_ns = clockevent_delta2ns(0x7fffffff, cd); |
| 343 | cd->min_delta_ns = clockevent_delta2ns(0x30, cd); |
| 344 | |
| 345 | cd->rating = 300; |
| 346 | cd->irq = irq; |
| 347 | cd->cpumask = cpumask_of_cpu(cpu); |
| 348 | cd->set_next_event = mips_next_event; |
| 349 | cd->set_mode = mips_set_mode; |
| 350 | |
| 351 | global_cd[cpu] = cd; |
| 352 | clockevents_register_device(cd); |
| 353 | |
| 354 | if (!cp0_timer_irq_installed) { |
| 355 | #ifdef CONFIG_MIPS_MT_SMTC |
| 356 | #define CPUCTR_IMASKBIT (0x100 << cp0_compare_irq) |
| 357 | setup_irq_smtc(irq, &timer_irqaction, CPUCTR_IMASKBIT); |
| 358 | #else |
| 359 | setup_irq(irq, &timer_irqaction); |
| 360 | #endif /* CONFIG_MIPS_MT_SMTC */ |
| 361 | cp0_timer_irq_installed = 1; |
| 362 | } |
| 363 | } |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | void __init time_init(void) |
| 366 | { |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 367 | plat_time_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* Choose appropriate high precision timer routines. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 370 | if (!cpu_has_counter && !clocksource_mips.read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* No high precision timer -- sorry. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 372 | clocksource_mips.read = null_hpt_read; |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 373 | else if (!mips_hpt_frequency && !mips_timer_state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | /* A high precision timer of unknown frequency. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 375 | if (!clocksource_mips.read) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | /* No external high precision timer -- use R4k. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 377 | clocksource_mips.read = c0_hpt_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } else { |
| 379 | /* We know counter frequency. Or we can get it. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 380 | if (!clocksource_mips.read) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | /* No external high precision timer -- use R4k. */ |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 382 | clocksource_mips.read = c0_hpt_read; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 384 | if (!mips_timer_state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* No external timer interrupt -- use R4k. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | mips_timer_ack = c0_timer_ack; |
Atsushi Nemoto | c87b6eb | 2006-10-28 01:14:37 +0900 | [diff] [blame] | 387 | /* Calculate cache parameters. */ |
| 388 | cycles_per_jiffy = |
| 389 | (mips_hpt_frequency + HZ / 2) / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | if (!mips_hpt_frequency) |
| 393 | mips_hpt_frequency = calibrate_hpt(); |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | /* Report the high precision timer rate for a reference. */ |
| 396 | printk("Using %u.%03u MHz high precision timer.\n", |
| 397 | ((mips_hpt_frequency + 500) / 1000) / 1000, |
| 398 | ((mips_hpt_frequency + 500) / 1000) % 1000); |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 399 | |
| 400 | #ifdef CONFIG_IRQ_CPU |
| 401 | setup_irq(MIPS_CPU_IRQ_BASE + 7, &timer_irqaction); |
| 402 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | if (!mips_timer_ack) |
| 406 | /* No timer interrupt ack (e.g. i8254). */ |
| 407 | mips_timer_ack = null_timer_ack; |
| 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | /* |
| 410 | * Call board specific timer interrupt setup. |
| 411 | * |
| 412 | * this pointer must be setup in machine setup routine. |
| 413 | * |
| 414 | * Even if a machine chooses to use a low-level timer interrupt, |
| 415 | * it still needs to setup the timer_irqaction. |
| 416 | * In that case, it might be better to set timer_irqaction.handler |
| 417 | * to be NULL function so that we are sure the high-level code |
| 418 | * is not invoked accidentally. |
| 419 | */ |
Ralf Baechle | 54d0a21 | 2006-07-09 21:38:56 +0100 | [diff] [blame] | 420 | plat_timer_setup(&timer_irqaction); |
Atsushi Nemoto | 16b7b2a | 2006-10-24 00:21:27 +0900 | [diff] [blame] | 421 | |
| 422 | init_mips_clocksource(); |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame^] | 423 | mips_clockevent_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |