timers.c 4.0 KB

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