time.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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/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. /* this needs a better home */
  39. DEFINE_SPINLOCK(rtc_lock);
  40. #ifdef CONFIG_RTC_DRV_CMOS_MODULE
  41. EXPORT_SYMBOL(rtc_lock);
  42. #endif
  43. #endif /* pc-style 'CMOS' RTC support */
  44. /* change this if you have some constant time drift */
  45. #define USECS_PER_JIFFY (1000000/HZ)
  46. #ifdef CONFIG_SMP
  47. unsigned long profile_pc(struct pt_regs *regs)
  48. {
  49. struct stackframe frame;
  50. if (!in_lock_functions(regs->ARM_pc))
  51. return regs->ARM_pc;
  52. frame.fp = regs->ARM_fp;
  53. frame.sp = regs->ARM_sp;
  54. frame.lr = regs->ARM_lr;
  55. frame.pc = regs->ARM_pc;
  56. do {
  57. int ret = unwind_frame(&frame);
  58. if (ret < 0)
  59. return 0;
  60. } while (in_lock_functions(frame.pc));
  61. return frame.pc;
  62. }
  63. EXPORT_SYMBOL(profile_pc);
  64. #endif
  65. #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
  66. u32 arch_gettimeoffset(void)
  67. {
  68. if (system_timer->offset != NULL)
  69. return system_timer->offset() * 1000;
  70. return 0;
  71. }
  72. #endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
  73. #ifdef CONFIG_LEDS_TIMER
  74. static inline void do_leds(void)
  75. {
  76. static unsigned int count = HZ/2;
  77. if (--count == 0) {
  78. count = HZ/2;
  79. leds_event(led_timer);
  80. }
  81. }
  82. #else
  83. #define do_leds()
  84. #endif
  85. #ifndef CONFIG_GENERIC_CLOCKEVENTS
  86. /*
  87. * Kernel system timer support.
  88. */
  89. void timer_tick(void)
  90. {
  91. profile_tick(CPU_PROFILING);
  92. do_leds();
  93. write_seqlock(&xtime_lock);
  94. do_timer(1);
  95. write_sequnlock(&xtime_lock);
  96. #ifndef CONFIG_SMP
  97. update_process_times(user_mode(get_irq_regs()));
  98. #endif
  99. }
  100. #endif
  101. #if defined(CONFIG_PM) && !defined(CONFIG_GENERIC_CLOCKEVENTS)
  102. static int timer_suspend(struct sys_device *dev, pm_message_t state)
  103. {
  104. struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
  105. if (timer->suspend != NULL)
  106. timer->suspend();
  107. return 0;
  108. }
  109. static int timer_resume(struct sys_device *dev)
  110. {
  111. struct sys_timer *timer = container_of(dev, struct sys_timer, dev);
  112. if (timer->resume != NULL)
  113. timer->resume();
  114. return 0;
  115. }
  116. #else
  117. #define timer_suspend NULL
  118. #define timer_resume NULL
  119. #endif
  120. static struct sysdev_class timer_sysclass = {
  121. .name = "timer",
  122. .suspend = timer_suspend,
  123. .resume = timer_resume,
  124. };
  125. static int __init timer_init_sysfs(void)
  126. {
  127. int ret = sysdev_class_register(&timer_sysclass);
  128. if (ret == 0) {
  129. system_timer->dev.cls = &timer_sysclass;
  130. ret = sysdev_register(&system_timer->dev);
  131. }
  132. return ret;
  133. }
  134. device_initcall(timer_init_sysfs);
  135. void __init time_init(void)
  136. {
  137. system_timer = machine_desc->timer;
  138. system_timer->init();
  139. }