timers.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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/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. * Default the timer and vector to use for ColdFire. Some ColdFire
  23. * CPU's and some boards may want different. Their sub-architecture
  24. * startup code (in config.c) can change these if they want.
  25. */
  26. unsigned int mcf_timervector = 29;
  27. unsigned int mcf_profilevector = 31;
  28. unsigned int mcf_timerlevel = 5;
  29. static volatile struct mcftimer *mcf_timerp;
  30. /*
  31. * These provide the underlying interrupt vector support.
  32. * Unfortunately it is a little different on each ColdFire.
  33. */
  34. extern void mcf_settimericr(int timer, int level);
  35. extern int mcf_timerirqpending(int timer);
  36. /***************************************************************************/
  37. void coldfire_tick(void)
  38. {
  39. /* Reset the ColdFire timer */
  40. mcf_timerp->ter = MCFTIMER_TER_CAP | MCFTIMER_TER_REF;
  41. }
  42. /***************************************************************************/
  43. void coldfire_timer_init(irqreturn_t (*handler)(int, void *, struct pt_regs *))
  44. {
  45. /* Set up an internal TIMER as poll clock */
  46. mcf_timerp = (volatile struct mcftimer *) (MCF_MBAR + MCFTIMER_BASE1);
  47. mcf_timerp->tmr = MCFTIMER_TMR_DISABLE;
  48. mcf_timerp->trr = (unsigned short) ((MCF_BUSCLK / 16) / HZ);
  49. mcf_timerp->tmr = MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  50. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE;
  51. request_irq(mcf_timervector, handler, SA_INTERRUPT, "timer", NULL);
  52. mcf_settimericr(1, mcf_timerlevel);
  53. #ifdef CONFIG_HIGHPROFILE
  54. coldfire_profile_init();
  55. #endif
  56. }
  57. /***************************************************************************/
  58. unsigned long coldfire_timer_offset(void)
  59. {
  60. unsigned long trr, tcn, offset;
  61. /*
  62. * The change to pointer and de-reference is to force the compiler
  63. * to read the registers with a single 16bit access. Otherwise it
  64. * does some crazy 8bit read combining.
  65. */
  66. tcn = *(&mcf_timerp->tcn);
  67. trr = *(&mcf_timerp->trr);
  68. offset = (tcn * (1000000 / HZ)) / trr;
  69. /* Check if we just wrapped the counters and maybe missed a tick */
  70. if ((offset < (1000000 / HZ / 2)) && mcf_timerirqpending(1))
  71. offset += 1000000 / HZ;
  72. return offset;
  73. }
  74. /***************************************************************************/
  75. #ifdef CONFIG_HIGHPROFILE
  76. /***************************************************************************/
  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. static volatile struct mcftimer *mcf_proftp;
  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. mcf_proftp->ter = MCFTIMER_TER_CAP | MCFTIMER_TER_REF;
  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. mcf_proftp = (volatile struct mcftimer *) (MCF_MBAR + MCFTIMER_BASE2);
  99. mcf_proftp->tmr = MCFTIMER_TMR_DISABLE;
  100. mcf_proftp->trr = (unsigned short) ((MCF_CLK / 16) / PROFILEHZ);
  101. mcf_proftp->tmr = MCFTIMER_TMR_ENORI | MCFTIMER_TMR_CLK16 |
  102. MCFTIMER_TMR_RESTART | MCFTIMER_TMR_ENABLE;
  103. request_irq(mcf_profilevector, coldfire_profile_tick,
  104. (SA_INTERRUPT | IRQ_FLG_FAST), "profile timer", NULL);
  105. mcf_settimericr(2, 7);
  106. }
  107. /***************************************************************************/
  108. #endif /* CONFIG_HIGHPROFILE */
  109. /***************************************************************************/