timers.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/config.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <asm/setup.h>
  19. #include <asm/system.h>
  20. #include <asm/pgtable.h>
  21. #include <asm/irq.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. void m68328_timer_init(irqreturn_t (*timer_routine) (int, void *, struct pt_regs *))
  48. {
  49. /* disable timer 1 */
  50. TCTL = 0;
  51. /* set ISR */
  52. if (request_irq(TMR_IRQ_NUM, timer_routine, IRQ_FLG_LOCK, "timer", NULL))
  53. panic("Unable to attach timer interrupt\n");
  54. /* Restart mode, Enable int, Set clock source */
  55. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  56. TPRER = CLOCK_PRE;
  57. TCMP = TICKS_PER_JIFFY;
  58. /* Enable timer 1 */
  59. TCTL |= TCTL_TEN;
  60. }
  61. /***************************************************************************/
  62. void m68328_timer_tick(void)
  63. {
  64. /* Reset Timer1 */
  65. TSTAT &= 0;
  66. }
  67. /***************************************************************************/
  68. unsigned long m68328_timer_gettimeoffset(void)
  69. {
  70. unsigned long ticks = TCN, offset = 0;
  71. /* check for pending interrupt */
  72. if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM)))
  73. offset = 1000000 / HZ;
  74. ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY;
  75. return ticks + offset;
  76. }
  77. /***************************************************************************/
  78. void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
  79. {
  80. long now = RTCTIME;
  81. *year = *mon = *day = 1;
  82. *hour = (now >> 24) % 24;
  83. *min = (now >> 16) % 60;
  84. *sec = now % 60;
  85. }
  86. /***************************************************************************/