time.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * linux/arch/arm/kernel/time.c
  3. *
  4. * Copyright (C) 1991, 1992, 1995 Linus Torvalds
  5. * Modifications for ARM (C) 1994-2001 Russell King
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This file contains the ARM-specific time handling details:
  12. * reading the RTC at bootup, etc...
  13. */
  14. #include <linux/module.h>
  15. #include <linux/kernel.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/time.h>
  18. #include <linux/init.h>
  19. #include <linux/sched.h>
  20. #include <linux/smp.h>
  21. #include <linux/timex.h>
  22. #include <linux/errno.h>
  23. #include <linux/profile.h>
  24. #include <linux/syscore_ops.h>
  25. #include <linux/timer.h>
  26. #include <linux/irq.h>
  27. #include <linux/mc146818rtc.h>
  28. #include <asm/leds.h>
  29. #include <asm/thread_info.h>
  30. #include <asm/sched_clock.h>
  31. #include <asm/stacktrace.h>
  32. #include <asm/mach/arch.h>
  33. #include <asm/mach/time.h>
  34. /*
  35. * Our system timer.
  36. */
  37. static struct sys_timer *system_timer;
  38. #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
  39. /* this needs a better home */
  40. DEFINE_SPINLOCK(rtc_lock);
  41. #ifdef CONFIG_RTC_DRV_CMOS_MODULE
  42. EXPORT_SYMBOL(rtc_lock);
  43. #endif
  44. #endif /* pc-style 'CMOS' RTC support */
  45. /* change this if you have some constant time drift */
  46. #define USECS_PER_JIFFY (1000000/HZ)
  47. #ifdef CONFIG_SMP
  48. unsigned long profile_pc(struct pt_regs *regs)
  49. {
  50. struct stackframe frame;
  51. if (!in_lock_functions(regs->ARM_pc))
  52. return regs->ARM_pc;
  53. frame.fp = regs->ARM_fp;
  54. frame.sp = regs->ARM_sp;
  55. frame.lr = regs->ARM_lr;
  56. frame.pc = regs->ARM_pc;
  57. do {
  58. int ret = unwind_frame(&frame);
  59. if (ret < 0)
  60. return 0;
  61. } while (in_lock_functions(frame.pc));
  62. return frame.pc;
  63. }
  64. EXPORT_SYMBOL(profile_pc);
  65. #endif
  66. #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
  67. u32 arch_gettimeoffset(void)
  68. {
  69. if (system_timer->offset != NULL)
  70. return system_timer->offset() * 1000;
  71. return 0;
  72. }
  73. #endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
  74. #ifdef CONFIG_LEDS_TIMER
  75. static inline void do_leds(void)
  76. {
  77. static unsigned int count = HZ/2;
  78. if (--count == 0) {
  79. count = HZ/2;
  80. leds_event(led_timer);
  81. }
  82. }
  83. #else
  84. #define do_leds()
  85. #endif
  86. #ifndef CONFIG_GENERIC_CLOCKEVENTS
  87. /*
  88. * Kernel system timer support.
  89. */
  90. void timer_tick(void)
  91. {
  92. profile_tick(CPU_PROFILING);
  93. do_leds();
  94. xtime_update(1);
  95. #ifndef CONFIG_SMP
  96. update_process_times(user_mode(get_irq_regs()));
  97. #endif
  98. }
  99. #endif
  100. #if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
  101. static int timer_suspend(void)
  102. {
  103. if (system_timer->suspend)
  104. system_timer->suspend();
  105. return 0;
  106. }
  107. static void timer_resume(void)
  108. {
  109. if (system_timer->resume)
  110. system_timer->resume();
  111. }
  112. #else
  113. #define timer_suspend NULL
  114. #define timer_resume NULL
  115. #endif
  116. static struct syscore_ops timer_syscore_ops = {
  117. .suspend = timer_suspend,
  118. .resume = timer_resume,
  119. };
  120. static int __init timer_init_syscore_ops(void)
  121. {
  122. register_syscore_ops(&timer_syscore_ops);
  123. return 0;
  124. }
  125. device_initcall(timer_init_syscore_ops);
  126. void __init time_init(void)
  127. {
  128. system_timer = machine_desc->timer;
  129. system_timer->init();
  130. #ifdef CONFIG_HAVE_SCHED_CLOCK
  131. sched_clock_postinit();
  132. #endif
  133. }