timers.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /***************************************************************************/
  2. /*
  3. * timers.c - Generic hardware timer support.
  4. *
  5. * Copyright (C) 1993 Hamish Macdonald
  6. * Copyright (C) 1999 D. Jeff Dionne
  7. * Copyright (C) 2001 Georges Menie, Ken Desmet
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive
  11. * for more details.
  12. */
  13. /***************************************************************************/
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/clocksource.h>
  20. #include <linux/rtc.h>
  21. #include <asm/setup.h>
  22. #include <asm/pgtable.h>
  23. #include <asm/machdep.h>
  24. #include <asm/MC68VZ328.h>
  25. /***************************************************************************/
  26. #if defined(CONFIG_DRAGEN2)
  27. /* with a 33.16 MHz clock, this will give usec resolution to the time functions */
  28. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  29. #define CLOCK_PRE 7
  30. #define TICKS_PER_JIFFY 41450
  31. #elif defined(CONFIG_XCOPILOT_BUGS)
  32. /*
  33. * The only thing I know is that CLK32 is not available on Xcopilot
  34. * I have little idea about what frequency SYSCLK has on Xcopilot.
  35. * The values for prescaler and compare registers were simply
  36. * taken from the original source
  37. */
  38. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  39. #define CLOCK_PRE 2
  40. #define TICKS_PER_JIFFY 0xd7e4
  41. #else
  42. /* default to using the 32Khz clock */
  43. #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
  44. #define CLOCK_PRE 31
  45. #define TICKS_PER_JIFFY 10
  46. #endif
  47. static u32 m68328_tick_cnt;
  48. static irq_handler_t timer_interrupt;
  49. /***************************************************************************/
  50. static irqreturn_t hw_tick(int irq, void *dummy)
  51. {
  52. /* Reset Timer1 */
  53. TSTAT &= 0;
  54. m68328_tick_cnt += TICKS_PER_JIFFY;
  55. return timer_interrupt(irq, dummy);
  56. }
  57. /***************************************************************************/
  58. static struct irqaction m68328_timer_irq = {
  59. .name = "timer",
  60. .flags = IRQF_TIMER,
  61. .handler = hw_tick,
  62. };
  63. /***************************************************************************/
  64. static cycle_t m68328_read_clk(struct clocksource *cs)
  65. {
  66. unsigned long flags;
  67. u32 cycles;
  68. local_irq_save(flags);
  69. cycles = m68328_tick_cnt + TCN;
  70. local_irq_restore(flags);
  71. return cycles;
  72. }
  73. /***************************************************************************/
  74. static struct clocksource m68328_clk = {
  75. .name = "timer",
  76. .rating = 250,
  77. .read = m68328_read_clk,
  78. .mask = CLOCKSOURCE_MASK(32),
  79. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  80. };
  81. /***************************************************************************/
  82. void hw_timer_init(irq_handler_t handler)
  83. {
  84. /* disable timer 1 */
  85. TCTL = 0;
  86. /* set ISR */
  87. setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
  88. /* Restart mode, Enable int, Set clock source */
  89. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  90. TPRER = CLOCK_PRE;
  91. TCMP = TICKS_PER_JIFFY;
  92. /* Enable timer 1 */
  93. TCTL |= TCTL_TEN;
  94. clocksource_register_hz(&m68328_clk, TICKS_PER_JIFFY*HZ);
  95. timer_interrupt = handler;
  96. }
  97. /***************************************************************************/
  98. int m68328_hwclk(int set, struct rtc_time *t)
  99. {
  100. if (!set) {
  101. long now = RTCTIME;
  102. t->tm_year = t->tm_mon = t->tm_mday = 1;
  103. t->tm_hour = (now >> 24) % 24;
  104. t->tm_min = (now >> 16) % 60;
  105. t->tm_sec = now % 60;
  106. }
  107. return 0;
  108. }
  109. /***************************************************************************/