2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
8 #include <linux/init.h>
11 #include <asm/setup.h>
14 #include <asm/mips-boards/generic.h>
16 static int mips_cpu_timer_irq
;
17 static int mips_cpu_perf_irq
;
19 static void mips_timer_dispatch(void)
21 do_IRQ(mips_cpu_timer_irq
);
24 static void mips_perf_dispatch(void)
26 do_IRQ(mips_cpu_perf_irq
);
29 static void __iomem
*status_reg
= (void __iomem
*)0xbf000410;
32 * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect.
34 static unsigned int __init
estimate_cpu_frequency(void)
36 unsigned int prid
= read_c0_prid() & (PRID_COMP_MASK
| PRID_IMP_MASK
);
37 unsigned int tick
= 0;
42 local_irq_save(flags
);
44 orig
= readl(status_reg
) & 0x2; /* get original sample */
45 /* wait for transition */
46 while ((readl(status_reg
) & 0x2) == orig
)
48 orig
= orig
^ 0x2; /* flip the bit */
52 /* wait 1 second (the sampling clock transitions every 10ms) */
54 /* wait for transition */
55 while ((readl(status_reg
) & 0x2) == orig
)
57 orig
= orig
^ 0x2; /* flip the bit */
61 freq
= read_c0_count();
63 local_irq_restore(flags
);
65 mips_hpt_frequency
= freq
;
67 /* Adjust for processor */
68 if ((prid
!= (PRID_COMP_MIPS
| PRID_IMP_20KC
)) &&
69 (prid
!= (PRID_COMP_MIPS
| PRID_IMP_25KF
)))
72 freq
+= 5000; /* rounding */
78 void read_persistent_clock(struct timespec
*ts
)
84 static void __init
plat_perf_setup(void)
86 if (cp0_perfcount_irq
>= 0) {
88 set_vi_handler(cp0_perfcount_irq
, mips_perf_dispatch
);
89 mips_cpu_perf_irq
= MIPS_CPU_IRQ_BASE
+ cp0_perfcount_irq
;
93 unsigned int get_c0_compare_int(void)
96 set_vi_handler(cp0_compare_irq
, mips_timer_dispatch
);
97 mips_cpu_timer_irq
= MIPS_CPU_IRQ_BASE
+ cp0_compare_irq
;
98 return mips_cpu_timer_irq
;
101 void __init
plat_time_init(void)
103 unsigned int est_freq
;
105 est_freq
= estimate_cpu_frequency();
107 pr_debug("CPU frequency %d.%02d MHz\n", (est_freq
/ 1000000),
108 (est_freq
% 1000000) * 100 / 1000000);
110 mips_scroll_message();