• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/arch/mips/mipssim/
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>
6#include <linux/interrupt.h>
7#include <linux/mc146818rtc.h>
8#include <linux/smp.h>
9#include <linux/timex.h>
10
11#include <asm/hardirq.h>
12#include <asm/div64.h>
13#include <asm/cpu.h>
14#include <asm/time.h>
15#include <asm/irq.h>
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>
22
23
24unsigned long cpu_khz;
25
26/*
27 * Estimate CPU frequency.  Sets mips_hpt_frequency as a side-effect
28 */
29static unsigned int __init estimate_cpu_frequency(void)
30{
31	unsigned int prid = read_c0_prid() & 0xffff00;
32	unsigned int count;
33
34	/*
35	 * hardwire the board frequency to 12MHz.
36	 */
37
38	if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
39	    (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
40		count = 12000000;
41	else
42		count =  6000000;
43
44	mips_hpt_frequency = count;
45
46	if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
47	    (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
48		count *= 2;
49
50	count += 5000;    /* round */
51	count -= count%10000;
52
53	return count;
54}
55
56static int mips_cpu_timer_irq;
57
58static void mips_timer_dispatch(void)
59{
60	do_IRQ(mips_cpu_timer_irq);
61}
62
63
64unsigned __cpuinit get_c0_compare_int(void)
65{
66#ifdef MSC01E_INT_BASE
67	if (cpu_has_veic) {
68		set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
69		mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
70
71		return mips_cpu_timer_irq;
72	}
73#endif
74	if (cpu_has_vint)
75		set_vi_handler(cp0_compare_irq, mips_timer_dispatch);
76	mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
77
78	return mips_cpu_timer_irq;
79}
80
81void __init plat_time_init(void)
82{
83	unsigned int est_freq;
84
85	/* Set Data mode - binary. */
86	CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
87
88	est_freq = estimate_cpu_frequency();
89
90	printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
91	       (est_freq % 1000000) * 100 / 1000000);
92
93	cpu_khz = est_freq / 1000;
94}
95