time.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/export.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/sched_clock.h>
  28. #include <asm/leds.h>
  29. #include <asm/thread_info.h>
  30. #include <asm/stacktrace.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/time.h>
  33. /*
  34. * Our system timer.
  35. */
  36. static struct sys_timer *system_timer;
  37. #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) || \
  38. defined(CONFIG_NVRAM) || defined(CONFIG_NVRAM_MODULE)
  39. /* this needs a better home */
  40. DEFINE_SPINLOCK(rtc_lock);
  41. EXPORT_SYMBOL(rtc_lock);
  42. #endif /* pc-style 'CMOS' RTC support */
  43. /* change this if you have some constant time drift */
  44. #define USECS_PER_JIFFY (1000000/HZ)
  45. #ifdef CONFIG_SMP
  46. unsigned long profile_pc(struct pt_regs *regs)
  47. {
  48. struct stackframe frame;
  49. if (!in_lock_functions(regs->ARM_pc))
  50. return regs->ARM_pc;
  51. frame.fp = regs->ARM_fp;
  52. frame.sp = regs->ARM_sp;
  53. frame.lr = regs->ARM_lr;
  54. frame.pc = regs->ARM_pc;
  55. do {
  56. int ret = unwind_frame(&frame);
  57. if (ret < 0)
  58. return 0;
  59. } while (in_lock_functions(frame.pc));
  60. return frame.pc;
  61. }
  62. EXPORT_SYMBOL(profile_pc);
  63. #endif
  64. #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
  65. u32 arch_gettimeoffset(void)
  66. {
  67. if (system_timer->offset != NULL)
  68. return system_timer->offset() * 1000;
  69. return 0;
  70. }
  71. #endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
  72. #ifdef CONFIG_LEDS_TIMER
  73. static inline void do_leds(void)
  74. {
  75. static unsigned int count = HZ/2;
  76. if (--count == 0) {
  77. count = HZ/2;
  78. leds_event(led_timer);
  79. }
  80. }
  81. #else
  82. #define do_leds()
  83. #endif
  84. #ifndef CONFIG_GENERIC_CLOCKEVENTS
  85. /*
  86. * Kernel system timer support.
  87. */
  88. void timer_tick(void)
  89. {
  90. profile_tick(CPU_PROFILING);
  91. do_leds();
  92. xtime_update(1);
  93. #ifndef CONFIG_SMP
  94. update_process_times(user_mode(get_irq_regs()));
  95. #endif
  96. }
  97. #endif
  98. #if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
  99. static int timer_suspend(void)
  100. {
  101. if (system_timer->suspend)
  102. system_timer->suspend();
  103. return 0;
  104. }
  105. static void timer_resume(void)
  106. {
  107. if (system_timer->resume)
  108. system_timer->resume();
  109. }
  110. #else
  111. #define timer_suspend NULL
  112. #define timer_resume NULL
  113. #endif
  114. static struct syscore_ops timer_syscore_ops = {
  115. .suspend = timer_suspend,
  116. .resume = timer_resume,
  117. };
  118. static int __init timer_init_syscore_ops(void)
  119. {
  120. register_syscore_ops(&timer_syscore_ops);
  121. return 0;
  122. }
  123. device_initcall(timer_init_syscore_ops);
  124. void __init time_init(void)
  125. {
  126. system_timer = machine_desc->timer;
  127. system_timer->init();
  128. }