timers.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /***************************************************************************/
  2. /*
  3. * linux/arch/m68knommu/platform/68328/timers.c
  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. /***************************************************************************/
  49. static irqreturn_t hw_tick(int irq, void *dummy)
  50. {
  51. /* Reset Timer1 */
  52. TSTAT &= 0;
  53. m68328_tick_cnt += TICKS_PER_JIFFY;
  54. return arch_timer_interrupt(irq, dummy);
  55. }
  56. /***************************************************************************/
  57. static struct irqaction m68328_timer_irq = {
  58. .name = "timer",
  59. .flags = IRQF_DISABLED | IRQF_TIMER,
  60. .handler = hw_tick,
  61. };
  62. /***************************************************************************/
  63. static cycle_t m68328_read_clk(struct clocksource *cs)
  64. {
  65. unsigned long flags;
  66. u32 cycles;
  67. local_irq_save(flags);
  68. cycles = m68328_tick_cnt + TCN;
  69. local_irq_restore(flags);
  70. return cycles;
  71. }
  72. /***************************************************************************/
  73. static struct clocksource m68328_clk = {
  74. .name = "timer",
  75. .rating = 250,
  76. .read = m68328_read_clk,
  77. .mask = CLOCKSOURCE_MASK(32),
  78. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  79. };
  80. /***************************************************************************/
  81. void hw_timer_init(void)
  82. {
  83. /* disable timer 1 */
  84. TCTL = 0;
  85. /* set ISR */
  86. setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
  87. /* Restart mode, Enable int, Set clock source */
  88. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  89. TPRER = CLOCK_PRE;
  90. TCMP = TICKS_PER_JIFFY;
  91. /* Enable timer 1 */
  92. TCTL |= TCTL_TEN;
  93. clocksource_register_hz(&m68328_clk, TICKS_PER_JIFFY*HZ);
  94. }
  95. /***************************************************************************/
  96. int m68328_hwclk(int set, struct rtc_time *t)
  97. {
  98. if (!set) {
  99. long now = RTCTIME;
  100. t->tm_year = t->tm_mon = t->tm_mday = 1;
  101. t->tm_hour = (now >> 24) % 24;
  102. t->tm_min = (now >> 16) % 60;
  103. t->tm_sec = now % 60;
  104. }
  105. return 0;
  106. }
  107. /***************************************************************************/