time.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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/sysdev.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/stacktrace.h>
  31. #include <asm/mach/time.h>
  32. /*
  33. * Our system timer.
  34. */
  35. struct sys_timer *system_timer;
  36. #if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
  37. /* this needs a better home */
  38. DEFINE_SPINLOCK(rtc_lock);
  39. #ifdef CONFIG_RTC_DRV_CMOS_MODULE
  40. EXPORT_SYMBOL(rtc_lock);
  41. #endif
  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. write_seqlock(&xtime_lock);
  93. do_timer(1);
  94. write_sequnlock(&xtime_lock);
  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(struct sys_device *dev, pm_message_t state)
  102. {
  103. struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
  104. if (timer->suspend != NULL)
  105. timer->suspend();
  106. return 0;
  107. }
  108. static int timer_resume(struct sys_device *dev)
  109. {
  110. struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
  111. if (timer->resume != NULL)
  112. timer->resume();
  113. return 0;
  114. }
  115. #else
  116. #define timer_suspend NULL
  117. #define timer_resume NULL
  118. #endif
  119. static struct sysdev_class timer_sysclass = {
  120. .name = "timer",
  121. .suspend = timer_suspend,
  122. .resume = timer_resume,
  123. };
  124. static int __init timer_init_sysfs(void)
  125. {
  126. int ret = sysdev_class_register(&timer_sysclass);
  127. if (ret == 0) {
  128. system_timer->dev.cls = &timer_sysclass;
  129. ret = sysdev_register(&system_timer->dev);
  130. }
  131. return ret;
  132. }
  133. device_initcall(timer_init_sysfs);
  134. void __init time_init(void)
  135. {
  136. system_timer->init();
  137. }