Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 1 | #include <linux/types.h> |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 2 | #include <linux/init.h> |
| 3 | #include <linux/kernel_stat.h> |
| 4 | #include <linux/sched.h> |
| 5 | #include <linux/spinlock.h> |
Nicolas Kaiser | dd6bfd6 | 2006-11-07 09:56:24 +0100 | [diff] [blame] | 6 | #include <linux/interrupt.h> |
| 7 | #include <linux/mc146818rtc.h> |
Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 8 | #include <linux/smp.h> |
Nicolas Kaiser | dd6bfd6 | 2006-11-07 09:56:24 +0100 | [diff] [blame] | 9 | #include <linux/timex.h> |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 10 | |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 11 | #include <asm/hardirq.h> |
| 12 | #include <asm/div64.h> |
| 13 | #include <asm/cpu.h> |
| 14 | #include <asm/time.h> |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 15 | #include <asm/irq.h> |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 16 | #include <asm/mc146818-time.h> |
| 17 | #include <asm/msc01_ic.h> |
| 18 | |
| 19 | #include <asm/mips-boards/generic.h> |
| 20 | #include <asm/mips-boards/prom.h> |
| 21 | #include <asm/mips-boards/simint.h> |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 22 | |
| 23 | |
| 24 | unsigned long cpu_khz; |
| 25 | |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 26 | /* |
Ralf Baechle | 224dc50 | 2006-10-21 02:05:20 +0100 | [diff] [blame] | 27 | * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 28 | */ |
| 29 | static unsigned int __init estimate_cpu_frequency(void) |
| 30 | { |
| 31 | unsigned int prid = read_c0_prid() & 0xffff00; |
| 32 | unsigned int count; |
| 33 | |
| 34 | #if 1 |
| 35 | /* |
| 36 | * hardwire the board frequency to 12MHz. |
| 37 | */ |
| 38 | |
| 39 | if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) || |
| 40 | (prid == (PRID_COMP_MIPS | PRID_IMP_25KF))) |
| 41 | count = 12000000; |
| 42 | else |
| 43 | count = 6000000; |
| 44 | #else |
| 45 | unsigned int flags; |
| 46 | |
| 47 | local_irq_save(flags); |
| 48 | |
| 49 | /* Start counter exactly on falling edge of update flag */ |
| 50 | while (CMOS_READ(RTC_REG_A) & RTC_UIP); |
| 51 | while (!(CMOS_READ(RTC_REG_A) & RTC_UIP)); |
| 52 | |
| 53 | /* Start r4k counter. */ |
| 54 | write_c0_count(0); |
| 55 | |
| 56 | /* Read counter exactly on falling edge of update flag */ |
| 57 | while (CMOS_READ(RTC_REG_A) & RTC_UIP); |
| 58 | while (!(CMOS_READ(RTC_REG_A) & RTC_UIP)); |
| 59 | |
| 60 | count = read_c0_count(); |
| 61 | |
| 62 | /* restore interrupts */ |
| 63 | local_irq_restore(flags); |
| 64 | #endif |
| 65 | |
| 66 | mips_hpt_frequency = count; |
| 67 | |
| 68 | if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) && |
| 69 | (prid != (PRID_COMP_MIPS | PRID_IMP_25KF))) |
| 70 | count *= 2; |
| 71 | |
| 72 | count += 5000; /* round */ |
| 73 | count -= count%10000; |
| 74 | |
| 75 | return count; |
| 76 | } |
| 77 | |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 78 | void __init plat_time_init(void) |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 79 | { |
| 80 | unsigned int est_freq, flags; |
| 81 | |
| 82 | local_irq_save(flags); |
| 83 | |
Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 84 | /* Set Data mode - binary. */ |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 85 | CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL); |
| 86 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 87 | est_freq = estimate_cpu_frequency(); |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 88 | |
Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 89 | printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000, |
| 90 | (est_freq % 1000000) * 100 / 1000000); |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 91 | |
Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 92 | cpu_khz = est_freq / 1000; |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 93 | |
| 94 | local_irq_restore(flags); |
| 95 | } |
| 96 | |
| 97 | static int mips_cpu_timer_irq; |
| 98 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 99 | static void mips_timer_dispatch(void) |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 100 | { |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 101 | do_IRQ(mips_cpu_timer_irq); |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | |
Ralf Baechle | 5fd3265 | 2006-07-10 02:37:21 +0100 | [diff] [blame] | 105 | void __init plat_timer_setup(struct irqaction *irq) |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 106 | { |
| 107 | if (cpu_has_veic) { |
| 108 | set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch); |
| 109 | mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR; |
Ralf Baechle | f6e2373 | 2007-07-10 17:32:56 +0100 | [diff] [blame] | 110 | } else { |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 111 | if (cpu_has_vint) |
Ralf Baechle | 3b1d4ed | 2007-06-20 22:27:10 +0100 | [diff] [blame] | 112 | set_vi_handler(cp0_compare_irq, mips_timer_dispatch); |
| 113 | mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq; |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* we are using the cpu counter for timer interrupts */ |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 117 | setup_irq(mips_cpu_timer_irq, irq); |
| 118 | |
| 119 | #ifdef CONFIG_SMP |
| 120 | /* irq_desc(riptor) is a global resource, when the interrupt overlaps |
| 121 | on seperate cpu's the first one tries to handle the second interrupt. |
| 122 | The effect is that the int remains disabled on the second cpu. |
| 123 | Mark the interrupt with IRQ_PER_CPU to avoid any confusion */ |
Atsushi Nemoto | 1417836 | 2006-11-14 01:13:18 +0900 | [diff] [blame] | 124 | irq_desc[mips_cpu_timer_irq].flags |= IRQ_PER_CPU; |
| 125 | set_irq_handler(mips_cpu_timer_irq, handle_percpu_irq); |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 126 | #endif |
Ralf Baechle | c78cbf4 | 2005-09-30 13:59:37 +0100 | [diff] [blame] | 127 | } |