sltimers.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /***************************************************************************/
  2. /*
  3. * sltimers.c -- generic ColdFire slice timer support.
  4. *
  5. * Copyright (C) 2009-2010, Philippe De Muyter <phdm@macqel.be>
  6. * based on
  7. * timers.c -- generic ColdFire hardware timer support.
  8. * Copyright (C) 1999-2008, Greg Ungerer <gerg@snapgear.com>
  9. */
  10. /***************************************************************************/
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/profile.h>
  17. #include <linux/clocksource.h>
  18. #include <asm/io.h>
  19. #include <asm/traps.h>
  20. #include <asm/machdep.h>
  21. #include <asm/coldfire.h>
  22. #include <asm/mcfslt.h>
  23. #include <asm/mcfsim.h>
  24. /***************************************************************************/
  25. #ifdef CONFIG_HIGHPROFILE
  26. /*
  27. * By default use Slice Timer 1 as the profiler clock timer.
  28. */
  29. #define PA(a) (MCF_MBAR + MCFSLT_TIMER1 + (a))
  30. /*
  31. * Choose a reasonably fast profile timer. Make it an odd value to
  32. * try and get good coverage of kernel operations.
  33. */
  34. #define PROFILEHZ 1013
  35. irqreturn_t mcfslt_profile_tick(int irq, void *dummy)
  36. {
  37. /* Reset Slice Timer 1 */
  38. __raw_writel(MCFSLT_SSR_BE | MCFSLT_SSR_TE, PA(MCFSLT_SSR));
  39. if (current->pid)
  40. profile_tick(CPU_PROFILING);
  41. return IRQ_HANDLED;
  42. }
  43. static struct irqaction mcfslt_profile_irq = {
  44. .name = "profile timer",
  45. .flags = IRQF_DISABLED | IRQF_TIMER,
  46. .handler = mcfslt_profile_tick,
  47. };
  48. void mcfslt_profile_init(void)
  49. {
  50. printk(KERN_INFO "PROFILE: lodging TIMER 1 @ %dHz as profile timer\n",
  51. PROFILEHZ);
  52. setup_irq(MCF_IRQ_PROFILER, &mcfslt_profile_irq);
  53. /* Set up TIMER 2 as high speed profile clock */
  54. __raw_writel(MCF_BUSCLK / PROFILEHZ - 1, PA(MCFSLT_STCNT));
  55. __raw_writel(MCFSLT_SCR_RUN | MCFSLT_SCR_IEN | MCFSLT_SCR_TEN,
  56. PA(MCFSLT_SCR));
  57. }
  58. #endif /* CONFIG_HIGHPROFILE */
  59. /***************************************************************************/
  60. /*
  61. * By default use Slice Timer 0 as the system clock timer.
  62. */
  63. #define TA(a) (MCF_MBAR + MCFSLT_TIMER0 + (a))
  64. static u32 mcfslt_cycles_per_jiffy;
  65. static u32 mcfslt_cnt;
  66. static irqreturn_t mcfslt_tick(int irq, void *dummy)
  67. {
  68. /* Reset Slice Timer 0 */
  69. __raw_writel(MCFSLT_SSR_BE | MCFSLT_SSR_TE, TA(MCFSLT_SSR));
  70. mcfslt_cnt += mcfslt_cycles_per_jiffy;
  71. return arch_timer_interrupt(irq, dummy);
  72. }
  73. static struct irqaction mcfslt_timer_irq = {
  74. .name = "timer",
  75. .flags = IRQF_DISABLED | IRQF_TIMER,
  76. .handler = mcfslt_tick,
  77. };
  78. static cycle_t mcfslt_read_clk(struct clocksource *cs)
  79. {
  80. unsigned long flags;
  81. u32 cycles;
  82. u16 scnt;
  83. local_irq_save(flags);
  84. scnt = __raw_readl(TA(MCFSLT_SCNT));
  85. cycles = mcfslt_cnt;
  86. local_irq_restore(flags);
  87. /* subtract because slice timers count down */
  88. return cycles - scnt;
  89. }
  90. static struct clocksource mcfslt_clk = {
  91. .name = "slt",
  92. .rating = 250,
  93. .read = mcfslt_read_clk,
  94. .shift = 20,
  95. .mask = CLOCKSOURCE_MASK(32),
  96. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  97. };
  98. void hw_timer_init(void)
  99. {
  100. mcfslt_cycles_per_jiffy = MCF_BUSCLK / HZ;
  101. /*
  102. * The coldfire slice timer (SLT) runs from STCNT to 0 included,
  103. * then STCNT again and so on. It counts thus actually
  104. * STCNT + 1 steps for 1 tick, not STCNT. So if you want
  105. * n cycles, initialize STCNT with n - 1.
  106. */
  107. __raw_writel(mcfslt_cycles_per_jiffy - 1, TA(MCFSLT_STCNT));
  108. __raw_writel(MCFSLT_SCR_RUN | MCFSLT_SCR_IEN | MCFSLT_SCR_TEN,
  109. TA(MCFSLT_SCR));
  110. /* initialize mcfslt_cnt knowing that slice timers count down */
  111. mcfslt_cnt = mcfslt_cycles_per_jiffy;
  112. setup_irq(MCF_IRQ_TIMER, &mcfslt_timer_irq);
  113. mcfslt_clk.mult = clocksource_hz2mult(MCF_BUSCLK, mcfslt_clk.shift);
  114. clocksource_register(&mcfslt_clk);
  115. #ifdef CONFIG_HIGHPROFILE
  116. mcfslt_profile_init();
  117. #endif
  118. }