timers.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/machdep.h>
  23. #include <asm/MC68VZ328.h>
  24. /***************************************************************************/
  25. #if defined(CONFIG_DRAGEN2)
  26. /* with a 33.16 MHz clock, this will give usec resolution to the time functions */
  27. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  28. #define CLOCK_PRE 7
  29. #define TICKS_PER_JIFFY 41450
  30. #elif defined(CONFIG_XCOPILOT_BUGS)
  31. /*
  32. * The only thing I know is that CLK32 is not available on Xcopilot
  33. * I have little idea about what frequency SYSCLK has on Xcopilot.
  34. * The values for prescaler and compare registers were simply
  35. * taken from the original source
  36. */
  37. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  38. #define CLOCK_PRE 2
  39. #define TICKS_PER_JIFFY 0xd7e4
  40. #else
  41. /* default to using the 32Khz clock */
  42. #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
  43. #define CLOCK_PRE 31
  44. #define TICKS_PER_JIFFY 10
  45. #endif
  46. static u32 m68328_tick_cnt;
  47. /***************************************************************************/
  48. static irqreturn_t hw_tick(int irq, void *dummy)
  49. {
  50. /* Reset Timer1 */
  51. TSTAT &= 0;
  52. m68328_tick_cnt += TICKS_PER_JIFFY;
  53. legacy_timer_tick(1);
  54. return IRQ_HANDLED;
  55. }
  56. /***************************************************************************/
  57. static u64 m68328_read_clk(struct clocksource *cs)
  58. {
  59. unsigned long flags;
  60. u32 cycles;
  61. local_irq_save(flags);
  62. cycles = m68328_tick_cnt + TCN;
  63. local_irq_restore(flags);
  64. return cycles;
  65. }
  66. /***************************************************************************/
  67. static struct clocksource m68328_clk = {
  68. .name = "timer",
  69. .rating = 250,
  70. .read = m68328_read_clk,
  71. .mask = CLOCKSOURCE_MASK(32),
  72. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  73. };
  74. /***************************************************************************/
  75. void hw_timer_init(void)
  76. {
  77. int ret;
  78. /* disable timer 1 */
  79. TCTL = 0;
  80. /* set ISR */
  81. ret = request_irq(TMR_IRQ_NUM, hw_tick, IRQF_TIMER, "timer", NULL);
  82. if (ret) {
  83. pr_err("Failed to request irq %d (timer): %pe\n", TMR_IRQ_NUM,
  84. ERR_PTR(ret));
  85. }
  86. /* Restart mode, Enable int, Set clock source */
  87. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  88. TPRER = CLOCK_PRE;
  89. TCMP = TICKS_PER_JIFFY;
  90. /* Enable timer 1 */
  91. TCTL |= TCTL_TEN;
  92. clocksource_register_hz(&m68328_clk, TICKS_PER_JIFFY*HZ);
  93. }
  94. /***************************************************************************/
  95. int m68328_hwclk(int set, struct rtc_time *t)
  96. {
  97. if (!set) {
  98. long now = RTCTIME;
  99. t->tm_year = 1;
  100. t->tm_mon = 0;
  101. t->tm_mday = 1;
  102. t->tm_hour = (now >> 24) % 24;
  103. t->tm_min = (now >> 16) % 60;
  104. t->tm_sec = now % 60;
  105. }
  106. return 0;
  107. }
  108. /***************************************************************************/