time.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* time.c: FRV arch-specific time handling
  2. *
  3. * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. * - Derived from arch/m68k/kernel/time.c
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h>
  15. #include <linux/kernel.h>
  16. #include <linux/param.h>
  17. #include <linux/string.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/profile.h>
  20. #include <linux/irq.h>
  21. #include <linux/mm.h>
  22. #include <asm/io.h>
  23. #include <asm/timer-regs.h>
  24. #include <asm/mb-regs.h>
  25. #include <asm/mb86943a.h>
  26. #include <linux/timex.h>
  27. #define TICK_SIZE (tick_nsec / 1000)
  28. unsigned long __nongprelbss __clkin_clock_speed_HZ;
  29. unsigned long __nongprelbss __ext_bus_clock_speed_HZ;
  30. unsigned long __nongprelbss __res_bus_clock_speed_HZ;
  31. unsigned long __nongprelbss __sdram_clock_speed_HZ;
  32. unsigned long __nongprelbss __core_bus_clock_speed_HZ;
  33. unsigned long __nongprelbss __core_clock_speed_HZ;
  34. unsigned long __nongprelbss __dsu_clock_speed_HZ;
  35. unsigned long __nongprelbss __serial_clock_speed_HZ;
  36. unsigned long __delay_loops_MHz;
  37. static irqreturn_t timer_interrupt(int irq, void *dummy);
  38. static struct irqaction timer_irq = {
  39. .handler = timer_interrupt,
  40. .name = "timer",
  41. };
  42. /*
  43. * timer_interrupt() needs to keep up the real-time clock,
  44. * as well as call the "xtime_update()" routine every clocktick
  45. */
  46. static irqreturn_t timer_interrupt(int irq, void *dummy)
  47. {
  48. profile_tick(CPU_PROFILING);
  49. xtime_update(1);
  50. #ifdef CONFIG_HEARTBEAT
  51. static unsigned short n;
  52. n++;
  53. __set_LEDS(n);
  54. #endif /* CONFIG_HEARTBEAT */
  55. update_process_times(user_mode(get_irq_regs()));
  56. return IRQ_HANDLED;
  57. }
  58. void time_divisor_init(void)
  59. {
  60. unsigned short base, pre, prediv;
  61. /* set the scheduling timer going */
  62. pre = 1;
  63. prediv = 4;
  64. base = __res_bus_clock_speed_HZ / pre / HZ / (1 << prediv);
  65. __set_TPRV(pre);
  66. __set_TxCKSL_DATA(0, prediv);
  67. __set_TCTR(TCTR_SC_CTR0 | TCTR_RL_RW_LH8 | TCTR_MODE_2);
  68. __set_TCSR_DATA(0, base & 0xff);
  69. __set_TCSR_DATA(0, base >> 8);
  70. }
  71. void read_persistent_clock(struct timespec *ts)
  72. {
  73. unsigned int year, mon, day, hour, min, sec;
  74. extern void arch_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec);
  75. /* FIX by dqg : Set to zero for platforms that don't have tod */
  76. /* without this time is undefined and can overflow time_t, causing */
  77. /* very strange errors */
  78. year = 1980;
  79. mon = day = 1;
  80. hour = min = sec = 0;
  81. arch_gettod (&year, &mon, &day, &hour, &min, &sec);
  82. if ((year += 1900) < 1970)
  83. year += 100;
  84. ts->tv_sec = mktime(year, mon, day, hour, min, sec);
  85. ts->tv_nsec = 0;
  86. }
  87. void time_init(void)
  88. {
  89. /* install scheduling interrupt handler */
  90. setup_irq(IRQ_CPU_TIMER0, &timer_irq);
  91. time_divisor_init();
  92. }
  93. /*
  94. * Scheduler clock - returns current time in nanosec units.
  95. */
  96. unsigned long long sched_clock(void)
  97. {
  98. return jiffies_64 * (1000000000 / HZ);
  99. }