timers.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <asm/setup.h>
  18. #include <asm/system.h>
  19. #include <asm/pgtable.h>
  20. #include <asm/irq.h>
  21. #include <asm/machdep.h>
  22. #include <asm/MC68VZ328.h>
  23. /***************************************************************************/
  24. #if defined(CONFIG_DRAGEN2)
  25. /* with a 33.16 MHz clock, this will give usec resolution to the time functions */
  26. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  27. #define CLOCK_PRE 7
  28. #define TICKS_PER_JIFFY 41450
  29. #elif defined(CONFIG_XCOPILOT_BUGS)
  30. /*
  31. * The only thing I know is that CLK32 is not available on Xcopilot
  32. * I have little idea about what frequency SYSCLK has on Xcopilot.
  33. * The values for prescaler and compare registers were simply
  34. * taken from the original source
  35. */
  36. #define CLOCK_SOURCE TCTL_CLKSOURCE_SYSCLK
  37. #define CLOCK_PRE 2
  38. #define TICKS_PER_JIFFY 0xd7e4
  39. #else
  40. /* default to using the 32Khz clock */
  41. #define CLOCK_SOURCE TCTL_CLKSOURCE_32KHZ
  42. #define CLOCK_PRE 31
  43. #define TICKS_PER_JIFFY 10
  44. #endif
  45. /***************************************************************************/
  46. void m68328_timer_init(irqreturn_t (*timer_routine) (int, void *, struct pt_regs *))
  47. {
  48. /* disable timer 1 */
  49. TCTL = 0;
  50. /* set ISR */
  51. if (request_irq(TMR_IRQ_NUM, timer_routine, IRQ_FLG_LOCK, "timer", NULL))
  52. panic("Unable to attach timer interrupt\n");
  53. /* Restart mode, Enable int, Set clock source */
  54. TCTL = TCTL_OM | TCTL_IRQEN | CLOCK_SOURCE;
  55. TPRER = CLOCK_PRE;
  56. TCMP = TICKS_PER_JIFFY;
  57. /* Enable timer 1 */
  58. TCTL |= TCTL_TEN;
  59. }
  60. /***************************************************************************/
  61. void m68328_timer_tick(void)
  62. {
  63. /* Reset Timer1 */
  64. TSTAT &= 0;
  65. }
  66. /***************************************************************************/
  67. unsigned long m68328_timer_gettimeoffset(void)
  68. {
  69. unsigned long ticks = TCN, offset = 0;
  70. /* check for pending interrupt */
  71. if (ticks < (TICKS_PER_JIFFY >> 1) && (ISR & (1 << TMR_IRQ_NUM)))
  72. offset = 1000000 / HZ;
  73. ticks = (ticks * 1000000 / HZ) / TICKS_PER_JIFFY;
  74. return ticks + offset;
  75. }
  76. /***************************************************************************/
  77. void m68328_timer_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec)
  78. {
  79. long now = RTCTIME;
  80. *year = *mon = *day = 1;
  81. *hour = (now >> 24) % 24;
  82. *min = (now >> 16) % 60;
  83. *sec = now % 60;
  84. }
  85. /***************************************************************************/