timers.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /***************************************************************************/
  2. /*
  3. * timers.c -- generic ColdFire hardware timer support.
  4. *
  5. * Copyright (C) 1999-2003, Greg Ungerer (gerg@snapgear.com)
  6. */
  7. /***************************************************************************/
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/param.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <asm/io.h>
  14. #include <asm/irq.h>
  15. #include <asm/traps.h>
  16. #include <asm/machdep.h>
  17. #include <asm/coldfire.h>
  18. #include <asm/mcftimer.h>
  19. #include <asm/mcfsim.h>
  20. /***************************************************************************/
  21. /*
  22. * By default use timer1 as the system clock timer.
  23. */
  24. #define TA(a) (MCF_MBAR + MCFTIMER_BASE1 + (a))
  25. /*
  26. * Default the timer and vector to use for ColdFire. Some ColdFire
  27. * CPU's and some boards may want different. Their sub-architecture
  28. * startup code (in config.c) can change these if they want.
  29. */
  30. unsigned int mcf_timervector = 29;
  31. unsigned int mcf_profilevector = 31;
  32. unsigned int mcf_timerlevel = 5;
  33. /*
  34. * These provide the underlying interrupt vector support.
  35. * Unfortunately it is a little different on each ColdFire.
  36. */
  37. extern void mcf_settimericr(int timer, int level);
  38. extern int mcf_timerirqpending(int timer);
  39. /***************************************************************************/
  40. void coldfire_tick(void)
  41. {
  42. /* Reset the ColdFire timer */
  43. __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, TA(MCFTIMER_TER));
  44. }
  45. /***************************************************************************/
  46. void coldfire_timer_init(irqreturn_t (*handler)(int, void *, struct pt_regs *))
  47. {
  48. __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR));
  49. __raw_writew(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR));
  50. __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  51. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR));
  52. request_irq(mcf_timervector, handler, IRQF_DISABLED, "timer", NULL);
  53. mcf_settimericr(1, mcf_timerlevel);
  54. #ifdef CONFIG_HIGHPROFILE
  55. coldfire_profile_init();
  56. #endif
  57. }
  58. /***************************************************************************/
  59. unsigned long coldfire_timer_offset(void)
  60. {
  61. unsigned long trr, tcn, offset;
  62. tcn = __raw_readw(TA(MCFTIMER_TCN));
  63. trr = __raw_readw(TA(MCFTIMER_TRR));
  64. offset = (tcn * (1000000 / HZ)) / trr;
  65. /* Check if we just wrapped the counters and maybe missed a tick */
  66. if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1))
  67. offset += 1000000 / HZ;
  68. return offset;
  69. }
  70. /***************************************************************************/
  71. #ifdef CONFIG_HIGHPROFILE
  72. /***************************************************************************/
  73. /*
  74. * By default use timer2 as the profiler clock timer.
  75. */
  76. #define PA(a) (MCF_MBAR + MCFTIMER_BASE2 + (a))
  77. /*
  78. * Choose a reasonably fast profile timer. Make it an odd value to
  79. * try and get good coverage of kernal operations.
  80. */
  81. #define PROFILEHZ 1013
  82. /*
  83. * Use the other timer to provide high accuracy profiling info.
  84. */
  85. void coldfire_profile_tick(int irq, void *dummy, struct pt_regs *regs)
  86. {
  87. /* Reset ColdFire timer2 */
  88. __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, PA(MCFTIMER_TER));
  89. if (current->pid)
  90. profile_tick(CPU_PROFILING, regs);
  91. }
  92. /***************************************************************************/
  93. void coldfire_profile_init(void)
  94. {
  95. printk(KERN_INFO "PROFILE: lodging TIMER2 @ %dHz as profile timer\n", PROFILEHZ);
  96. /* Set up TIMER 2 as high speed profile clock */
  97. __raw_writew(MCFTIMER_TMR_DISABLE, PA(MCFTIMER_TMR));
  98. __raw_writew(((MCF_CLK / 16) / PROFILEHZ), PA(MCFTIMER_TRR));
  99. __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  100. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, PA(MCFTIMER_TMR));
  101. request_irq(mcf_profilevector, coldfire_profile_tick,
  102. (IRQF_DISABLED | IRQ_FLG_FAST), "profile timer", NULL);
  103. mcf_settimericr(2, 7);
  104. }
  105. /***************************************************************************/
  106. #endif /* CONFIG_HIGHPROFILE */
  107. /***************************************************************************/