timers.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 <asm/setup.h>
  20. #include <asm/system.h>
  21. #include <asm/pgtable.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. /***************************************************************************/
  47. static struct irqaction m68328_timer_irq = {
  48. .name = "timer",
  49. .flags = IRQF_DISABLED | IRQF_TIMER,
  50. };
  51. void m68328_timer_init(irq_handler_t timer_routine)
  52. {
  53. /* disable timer 1 */
  54. TCTL = 0;
  55. /* set ISR */
  56. m68328_timer_irq.handler = timer_routine;
  57. setup_irq(TMR_IRQ_NUM, &m68328_timer_irq);
  58. /* Restart mode, Enable int, Set clock source */
  59. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  60. TPRER = CLOCK_PRE;
  61. TCMP = TICKS_PER_JIFFY;
  62. /* Enable timer 1 */
  63. TCTL |= TCTL_TEN;
  64. }
  65. /***************************************************************************/
  66. void m68328_timer_tick(void)
  67. {
  68. /* Reset Timer1 */
  69. TSTAT &= 0;
  70. }
  71. /***************************************************************************/
  72. unsigned long m68328_timer_gettimeoffset(void)
  73. {
  74. unsigned long ticks = TCN, offset = 0;
  75. /* check for pending interrupt */
  76. if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM)))
  77. offset = 1000000 / HZ;
  78. ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY;
  79. return ticks + offset;
  80. }
  81. /***************************************************************************/
  82. void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
  83. {
  84. long now = RTCTIME;
  85. *year = *mon = *day = 1;
  86. *hour = (now >> 24) % 24;
  87. *min = (now >> 16) % 60;
  88. *sec = now % 60;
  89. }
  90. /***************************************************************************/