[MIPS] Cleanup remaining references to mips_counter_frequency.
[linux-2.6/x86.git] / arch / mips / mips-boards / sim / sim_time.c
blob24a4ed00cc0a0f39786a5e6749dadff0aee6296d
1 #include <linux/types.h>
2 #include <linux/init.h>
3 #include <linux/kernel_stat.h>
4 #include <linux/sched.h>
5 #include <linux/spinlock.h>
7 #include <asm/mipsregs.h>
8 #include <asm/ptrace.h>
9 #include <asm/hardirq.h>
10 #include <asm/div64.h>
11 #include <asm/cpu.h>
12 #include <asm/time.h>
14 #include <linux/interrupt.h>
15 #include <linux/mc146818rtc.h>
16 #include <linux/timex.h>
17 #include <asm/mipsregs.h>
18 #include <asm/hardirq.h>
19 #include <asm/irq.h>
20 #include <asm/div64.h>
21 #include <asm/cpu.h>
22 #include <asm/time.h>
23 #include <asm/mc146818-time.h>
24 #include <asm/msc01_ic.h>
26 #include <asm/mips-boards/generic.h>
27 #include <asm/mips-boards/prom.h>
28 #include <asm/mips-boards/simint.h>
29 #include <asm/mc146818-time.h>
30 #include <asm/smp.h>
33 unsigned long cpu_khz;
35 irqreturn_t sim_timer_interrupt(int irq, void *dev_id)
37 #ifdef CONFIG_SMP
38 int cpu = smp_processor_id();
41 * CPU 0 handles the global timer interrupt job
42 * resets count/compare registers to trigger next timer int.
44 #ifndef CONFIG_MIPS_MT_SMTC
45 if (cpu == 0) {
46 timer_interrupt(irq, dev_id);
48 else {
49 /* Everyone else needs to reset the timer int here as
50 ll_local_timer_interrupt doesn't */
52 * FIXME: need to cope with counter underflow.
53 * More support needs to be added to kernel/time for
54 * counter/timer interrupts on multiple CPU's
56 write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
58 #else /* SMTC */
60 * In SMTC system, one Count/Compare set exists per VPE.
61 * Which TC within a VPE gets the interrupt is essentially
62 * random - we only know that it shouldn't be one with
63 * IXMT set. Whichever TC gets the interrupt needs to
64 * send special interprocessor interrupts to the other
65 * TCs to make sure that they schedule, etc.
67 * That code is specific to the SMTC kernel, not to
68 * the simulation platform, so it's invoked from
69 * the general MIPS timer_interrupt routine.
71 * We have a problem in that the interrupt vector code
72 * had to turn off the timer IM bit to avoid redundant
73 * entries, but we may never get to mips_cpu_irq_end
74 * to turn it back on again if the scheduler gets
75 * involved. So we clear the pending timer here,
76 * and re-enable the mask...
79 int vpflags = dvpe();
80 write_c0_compare (read_c0_count() - 1);
81 clear_c0_cause(0x100 << MIPSCPU_INT_CPUCTR);
82 set_c0_status(0x100 << MIPSCPU_INT_CPUCTR);
83 irq_enable_hazard();
84 evpe(vpflags);
86 if(cpu_data[cpu].vpe_id == 0) timer_interrupt(irq, dev_id);
87 else write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
88 smtc_timer_broadcast(cpu_data[cpu].vpe_id);
90 #endif /* CONFIG_MIPS_MT_SMTC */
93 * every CPU should do profiling and process accounting
95 local_timer_interrupt (irq, dev_id);
96 return IRQ_HANDLED;
97 #else
98 return timer_interrupt (irq, dev_id);
99 #endif
105 * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect
107 static unsigned int __init estimate_cpu_frequency(void)
109 unsigned int prid = read_c0_prid() & 0xffff00;
110 unsigned int count;
112 #if 1
114 * hardwire the board frequency to 12MHz.
117 if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
118 (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
119 count = 12000000;
120 else
121 count = 6000000;
122 #else
123 unsigned int flags;
125 local_irq_save(flags);
127 /* Start counter exactly on falling edge of update flag */
128 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
129 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
131 /* Start r4k counter. */
132 write_c0_count(0);
134 /* Read counter exactly on falling edge of update flag */
135 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
136 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
138 count = read_c0_count();
140 /* restore interrupts */
141 local_irq_restore(flags);
142 #endif
144 mips_hpt_frequency = count;
146 if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
147 (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
148 count *= 2;
150 count += 5000; /* round */
151 count -= count%10000;
153 return count;
156 void __init sim_time_init(void)
158 unsigned int est_freq, flags;
160 local_irq_save(flags);
163 /* Set Data mode - binary. */
164 CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
167 est_freq = estimate_cpu_frequency ();
169 printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
170 (est_freq%1000000)*100/1000000);
172 cpu_khz = est_freq / 1000;
174 local_irq_restore(flags);
177 static int mips_cpu_timer_irq;
179 static void mips_timer_dispatch(void)
181 do_IRQ(mips_cpu_timer_irq);
185 void __init plat_timer_setup(struct irqaction *irq)
187 if (cpu_has_veic) {
188 set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
189 mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
191 else {
192 if (cpu_has_vint)
193 set_vi_handler(MIPSCPU_INT_CPUCTR, mips_timer_dispatch);
194 mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR;
197 /* we are using the cpu counter for timer interrupts */
198 irq->handler = sim_timer_interrupt;
199 setup_irq(mips_cpu_timer_irq, irq);
201 #ifdef CONFIG_SMP
202 /* irq_desc(riptor) is a global resource, when the interrupt overlaps
203 on seperate cpu's the first one tries to handle the second interrupt.
204 The effect is that the int remains disabled on the second cpu.
205 Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
206 irq_desc[mips_cpu_timer_irq].status |= IRQ_PER_CPU;
207 #endif
209 /* to generate the first timer interrupt */
210 write_c0_compare(read_c0_count() + (mips_hpt_frequency/HZ));