sim_time.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #include <asm/hardirq.h>
  11. #include <asm/div64.h>
  12. #include <asm/cpu.h>
  13. #include <asm/setup.h>
  14. #include <asm/time.h>
  15. #include <asm/irq.h>
  16. #include <asm/mc146818-time.h>
  17. #include <asm/msc01_ic.h>
  18. #include <asm/mips-boards/generic.h>
  19. #include <asm/mips-boards/prom.h>
  20. #include <asm/mips-boards/simint.h>
  21. unsigned long cpu_khz;
  22. /*
  23. * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect
  24. */
  25. static unsigned int __init estimate_cpu_frequency(void)
  26. {
  27. unsigned int prid = read_c0_prid() & 0xffff00;
  28. unsigned int count;
  29. #if 1
  30. /*
  31. * hardwire the board frequency to 12MHz.
  32. */
  33. if ((prid == (PRID_COMP_MIPS | PRID_IMP_20KC)) ||
  34. (prid == (PRID_COMP_MIPS | PRID_IMP_25KF)))
  35. count = 12000000;
  36. else
  37. count = 6000000;
  38. #else
  39. unsigned int flags;
  40. local_irq_save(flags);
  41. /* Start counter exactly on falling edge of update flag */
  42. while (CMOS_READ(RTC_REG_A) & RTC_UIP);
  43. while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
  44. /* Start r4k counter. */
  45. write_c0_count(0);
  46. /* Read counter exactly on falling edge of update flag */
  47. while (CMOS_READ(RTC_REG_A) & RTC_UIP);
  48. while (!(CMOS_READ(RTC_REG_A) & RTC_UIP));
  49. count = read_c0_count();
  50. /* restore interrupts */
  51. local_irq_restore(flags);
  52. #endif
  53. mips_hpt_frequency = count;
  54. if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
  55. (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
  56. count *= 2;
  57. count += 5000; /* round */
  58. count -= count%10000;
  59. return count;
  60. }
  61. static int mips_cpu_timer_irq;
  62. static void mips_timer_dispatch(void)
  63. {
  64. do_IRQ(mips_cpu_timer_irq);
  65. }
  66. unsigned __cpuinit get_c0_compare_int(void)
  67. {
  68. #ifdef MSC01E_INT_BASE
  69. if (cpu_has_veic) {
  70. set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
  71. mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
  72. return mips_cpu_timer_irq;
  73. }
  74. #endif
  75. if (cpu_has_vint)
  76. set_vi_handler(cp0_compare_irq, mips_timer_dispatch);
  77. mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
  78. return mips_cpu_timer_irq;
  79. }
  80. void __init plat_time_init(void)
  81. {
  82. unsigned int est_freq;
  83. /* Set Data mode - binary. */
  84. CMOS_WRITE(CMOS_READ(RTC_CONTROL) | RTC_DM_BINARY, RTC_CONTROL);
  85. est_freq = estimate_cpu_frequency();
  86. printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
  87. (est_freq % 1000000) * 100 / 1000000);
  88. cpu_khz = est_freq / 1000;
  89. }