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>
14 #include <linux/interrupt.h>
15 #include <linux/mc146818rtc.h>
16 #include <linux/timex.h>
17 #include <asm/mipsregs.h>
18 #include <asm/ptrace.h>
19 #include <asm/hardirq.h>
21 #include <asm/div64.h>
24 #include <asm/mc146818-time.h>
25 #include <asm/msc01_ic.h>
27 #include <asm/mips-boards/generic.h>
28 #include <asm/mips-boards/prom.h>
29 #include <asm/mips-boards/simint.h>
30 #include <asm/mc146818-time.h>
34 unsigned long cpu_khz;
36 irqreturn_t sim_timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
39 int cpu = smp_processor_id();
42 * CPU 0 handles the global timer interrupt job
43 * resets count/compare registers to trigger next timer int.
45 #ifndef CONFIG_MIPS_MT_SMTC
47 timer_interrupt(irq, dev_id, regs);
50 /* Everyone else needs to reset the timer int here as
51 ll_local_timer_interrupt doesn't */
53 * FIXME: need to cope with counter underflow.
54 * More support needs to be added to kernel/time for
55 * counter/timer interrupts on multiple CPU's
57 write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
61 * In SMTC system, one Count/Compare set exists per VPE.
62 * Which TC within a VPE gets the interrupt is essentially
63 * random - we only know that it shouldn't be one with
64 * IXMT set. Whichever TC gets the interrupt needs to
65 * send special interprocessor interrupts to the other
66 * TCs to make sure that they schedule, etc.
68 * That code is specific to the SMTC kernel, not to
69 * the simulation platform, so it's invoked from
70 * the general MIPS timer_interrupt routine.
72 * We have a problem in that the interrupt vector code
73 * had to turn off the timer IM bit to avoid redundant
74 * entries, but we may never get to mips_cpu_irq_end
75 * to turn it back on again if the scheduler gets
76 * involved. So we clear the pending timer here,
77 * and re-enable the mask...
81 write_c0_compare (read_c0_count() - 1);
82 clear_c0_cause(0x100 << MIPSCPU_INT_CPUCTR);
83 set_c0_status(0x100 << MIPSCPU_INT_CPUCTR);
87 if(cpu_data[cpu].vpe_id == 0) timer_interrupt(irq, dev_id, regs);
88 else write_c0_compare (read_c0_count() + ( mips_hpt_frequency/HZ));
89 smtc_timer_broadcast(cpu_data[cpu].vpe_id);
91 #endif /* CONFIG_MIPS_MT_SMTC */
94 * every CPU should do profiling and process accounting
96 local_timer_interrupt (irq, dev_id, regs);
99 return timer_interrupt (irq, dev_id, regs);
106 * Estimate CPU frequency. Sets mips_counter_frequency as a side-effect
108 static unsigned int __init estimate_cpu_frequency(void)
110 unsigned int prid = read_c0_prid() & 0xffff00;
115 * hardwire the board frequency to 12MHz.
118 if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
119 (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
126 local_irq_save(flags);
128 /* Start counter exactly on falling edge of update flag */
129 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
130 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
132 /* Start r4k counter. */
135 /* Read counter exactly on falling edge of update flag */
136 while (CMOS_READ(RTC_REG_A) & RTC_UIP);
137 while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
139 count = read_c0_count();
141 /* restore interrupts */
142 local_irq_restore(flags);
145 mips_hpt_frequency = count;
147 if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
148 (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
151 count += 5000; /* round */
152 count -= count%10000;
157 void __init sim_time_init(void)
159 unsigned int est_freq, flags;
161 local_irq_save(flags);
164 /* Set Data mode - binary. */
165 CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
168 est_freq = estimate_cpu_frequency ();
170 printk("CPU frequency %d.%02d MHz\n", est_freq/1000000,
171 (est_freq%1000000)*100/1000000);
173 cpu_khz = est_freq / 1000;
175 local_irq_restore(flags);
178 static int mips_cpu_timer_irq;
180 static void mips_timer_dispatch (struct pt_regs *regs)
182 do_IRQ (mips_cpu_timer_irq, regs);
186 void __init plat_timer_setup(struct irqaction *irq)
189 set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
190 mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
194 set_vi_handler(MIPSCPU_INT_CPUCTR, mips_timer_dispatch);
195 mips_cpu_timer_irq = MIPSCPU_INT_BASE + MIPSCPU_INT_CPUCTR;
198 /* we are using the cpu counter for timer interrupts */
199 irq->handler = sim_timer_interrupt;
200 setup_irq(mips_cpu_timer_irq, irq);
203 /* irq_desc(riptor) is a global resource, when the interrupt overlaps
204 on seperate cpu's the first one tries to handle the second interrupt.
205 The effect is that the int remains disabled on the second cpu.
206 Mark the interrupt with IRQ_PER_CPU to avoid any confusion */
207 irq_desc[mips_cpu_timer_irq].status |= IRQ_PER_CPU;
210 /* to generate the first timer interrupt */
211 write_c0_compare(read_c0_count() + (mips_hpt_frequency/HZ));