timers.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /***************************************************************************/
  2. /*
  3. * timers.c -- generic ColdFire hardware timer support.
  4. *
  5. * Copyright (C) 1999-2006, 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. #if defined(CONFIG_M532x)
  40. #define __raw_readtrr __raw_readl
  41. #define __raw_writetrr __raw_writel
  42. #else
  43. #define __raw_readtrr __raw_readw
  44. #define __raw_writetrr __raw_writew
  45. #endif
  46. /***************************************************************************/
  47. void coldfire_tick(void)
  48. {
  49. /* Reset the ColdFire timer */
  50. __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, TA(MCFTIMER_TER));
  51. }
  52. /***************************************************************************/
  53. void coldfire_timer_init(irq_handler_t handler)
  54. {
  55. __raw_writew(MCFTIMER_TMR_DISABLE, TA(MCFTIMER_TMR));
  56. __raw_writetrr(((MCF_BUSCLK / 16) / HZ), TA(MCFTIMER_TRR));
  57. __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  58. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, TA(MCFTIMER_TMR));
  59. request_irq(mcf_timervector, handler, IRQF_DISABLED, "timer", NULL);
  60. mcf_settimericr(1, mcf_timerlevel);
  61. #ifdef CONFIG_HIGHPROFILE
  62. coldfire_profile_init();
  63. #endif
  64. }
  65. /***************************************************************************/
  66. unsigned long coldfire_timer_offset(void)
  67. {
  68. unsigned long trr, tcn, offset;
  69. tcn = __raw_readw(TA(MCFTIMER_TCN));
  70. trr = __raw_readtrr(TA(MCFTIMER_TRR));
  71. offset = (tcn * (1000000 / HZ)) / trr;
  72. /* Check if we just wrapped the counters and maybe missed a tick */
  73. if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1))
  74. offset += 1000000 / HZ;
  75. return offset;
  76. }
  77. /***************************************************************************/
  78. #ifdef CONFIG_HIGHPROFILE
  79. /***************************************************************************/
  80. /*
  81. * By default use timer2 as the profiler clock timer.
  82. */
  83. #define PA(a) (MCF_MBAR + MCFTIMER_BASE2 + (a))
  84. /*
  85. * Choose a reasonably fast profile timer. Make it an odd value to
  86. * try and get good coverage of kernel operations.
  87. */
  88. #define PROFILEHZ 1013
  89. /*
  90. * Use the other timer to provide high accuracy profiling info.
  91. */
  92. irqreturn_t coldfire_profile_tick(int irq, void *dummy)
  93. {
  94. /* Reset ColdFire timer2 */
  95. __raw_writeb(MCFTIMER_TER_CAP | MCFTIMER_TER_REF, PA(MCFTIMER_TER));
  96. if (current->pid)
  97. profile_tick(CPU_PROFILING, regs);
  98. return IRQ_HANDLED;
  99. }
  100. /***************************************************************************/
  101. void coldfire_profile_init(void)
  102. {
  103. printk(KERN_INFO "PROFILE: lodging TIMER2 @ %dHz as profile timer\n", PROFILEHZ);
  104. /* Set up TIMER 2 as high speed profile clock */
  105. __raw_writew(MCFTIMER_TMR_DISABLE, PA(MCFTIMER_TMR));
  106. __raw_writetrr(((MCF_CLK / 16) / PROFILEHZ), PA(MCFTIMER_TRR));
  107. __raw_writew(MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  108. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE, PA(MCFTIMER_TMR));
  109. request_irq(mcf_profilevector, coldfire_profile_tick,
  110. (IRQF_DISABLED | IRQ_FLG_FAST), "profile timer", NULL);
  111. mcf_settimericr(2, 7);
  112. }
  113. /***************************************************************************/
  114. #endif /* CONFIG_HIGHPROFILE */
  115. /***************************************************************************/