Jesper Nilsson | daa00b9 | 2008-01-28 16:40:21 +0100 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * linux/arch/cris/kernel/time.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992, 1995 Linus Torvalds |
| 5 | * Copyright (C) 1999, 2000, 2001 Axis Communications AB |
| 6 | * |
| 7 | * 1994-07-02 Alan Modra |
| 8 | * fixed set_rtc_mmss, fixed time.year for >= 2000, new mktime |
| 9 | * 1995-03-26 Markus Kuhn |
| 10 | * fixed 500 ms bug at call to set_rtc_mmss, fixed DS12887 |
| 11 | * precision CMOS clock update |
| 12 | * 1996-05-03 Ingo Molnar |
| 13 | * fixed time warps in do_[slow|fast]_gettimeoffset() |
| 14 | * 1997-09-10 Updated NTP code according to technical memorandum Jan '96 |
| 15 | * "A Kernel Model for Precision Timekeeping" by Dave Mills |
| 16 | * |
| 17 | * Linux/CRIS specific code: |
| 18 | * |
| 19 | * Authors: Bjorn Wesen |
Jesper Nilsson | daa00b9 | 2008-01-28 16:40:21 +0100 | [diff] [blame] | 20 | * Johan Adolfsson |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/errno.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/param.h> |
| 27 | #include <linux/jiffies.h> |
| 28 | #include <linux/bcd.h> |
| 29 | #include <linux/timex.h> |
| 30 | #include <linux/init.h> |
Mikael Starvik | 21783c9 | 2005-07-27 11:44:40 -0700 | [diff] [blame] | 31 | #include <linux/profile.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 32 | #include <linux/sched.h> /* just for sched_clock() - funny that */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Jesper Nilsson | 9c75fc8 | 2012-04-05 11:52:55 +0200 | [diff] [blame] | 34 | |
| 35 | #define D(x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #define TICK_SIZE tick |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | extern unsigned long loops_per_jiffy; /* init/main.c */ |
| 40 | unsigned long loops_per_usec; |
| 41 | |
Jesper Nilsson | 60dbd66 | 2010-07-30 17:33:07 +0200 | [diff] [blame] | 42 | |
| 43 | #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | extern unsigned long do_slow_gettimeoffset(void); |
| 45 | static unsigned long (*do_gettimeoffset)(void) = do_slow_gettimeoffset; |
| 46 | |
john stultz | ba875ba | 2010-03-05 13:42:31 -0800 | [diff] [blame] | 47 | u32 arch_gettimeoffset(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Stephen Warren | 547046f | 2012-11-08 10:50:55 -0700 | [diff] [blame^] | 49 | return do_gettimeoffset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
Jesper Nilsson | 60dbd66 | 2010-07-30 17:33:07 +0200 | [diff] [blame] | 51 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | int set_rtc_mmss(unsigned long nowtime) |
| 54 | { |
Jesper Nilsson | 9c75fc8 | 2012-04-05 11:52:55 +0200 | [diff] [blame] | 55 | D(printk(KERN_DEBUG "set_rtc_mmss(%lu)\n", nowtime)); |
| 56 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* grab the time from the RTC chip */ |
Jesper Nilsson | 9c75fc8 | 2012-04-05 11:52:55 +0200 | [diff] [blame] | 60 | unsigned long get_cmos_time(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
Jesper Nilsson | 9c75fc8 | 2012-04-05 11:52:55 +0200 | [diff] [blame] | 62 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
John Stultz | 8eff8a5 | 2010-03-03 19:57:28 -0800 | [diff] [blame] | 66 | int update_persistent_clock(struct timespec now) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
John Stultz | 8eff8a5 | 2010-03-03 19:57:28 -0800 | [diff] [blame] | 68 | return set_rtc_mmss(now.tv_sec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
John Stultz | 8eff8a5 | 2010-03-03 19:57:28 -0800 | [diff] [blame] | 71 | void read_persistent_clock(struct timespec *ts) |
| 72 | { |
Jesper Nilsson | 9c75fc8 | 2012-04-05 11:52:55 +0200 | [diff] [blame] | 73 | ts->tv_sec = 0; |
John Stultz | 8eff8a5 | 2010-03-03 19:57:28 -0800 | [diff] [blame] | 74 | ts->tv_nsec = 0; |
| 75 | } |
| 76 | |
| 77 | |
Mikael Starvik | 21783c9 | 2005-07-27 11:44:40 -0700 | [diff] [blame] | 78 | extern void cris_profile_sample(struct pt_regs* regs); |
| 79 | |
| 80 | void |
| 81 | cris_do_profile(struct pt_regs* regs) |
| 82 | { |
| 83 | |
Jesper Nilsson | 0188e60 | 2007-11-14 17:01:00 -0800 | [diff] [blame] | 84 | #ifdef CONFIG_SYSTEM_PROFILER |
Mikael Starvik | 21783c9 | 2005-07-27 11:44:40 -0700 | [diff] [blame] | 85 | cris_profile_sample(regs); |
| 86 | #endif |
| 87 | |
Jesper Nilsson | 0188e60 | 2007-11-14 17:01:00 -0800 | [diff] [blame] | 88 | #ifdef CONFIG_PROFILING |
Jesper Nilsson | c261038 | 2008-01-31 17:56:24 +0100 | [diff] [blame] | 89 | profile_tick(CPU_PROFILING); |
Mikael Starvik | 21783c9 | 2005-07-27 11:44:40 -0700 | [diff] [blame] | 90 | #endif |
| 91 | } |
| 92 | |
Jesper Nilsson | daa00b9 | 2008-01-28 16:40:21 +0100 | [diff] [blame] | 93 | unsigned long long sched_clock(void) |
| 94 | { |
Jesper Nilsson | 60dbd66 | 2010-07-30 17:33:07 +0200 | [diff] [blame] | 95 | return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ) + |
Jesper Nilsson | daa00b9 | 2008-01-28 16:40:21 +0100 | [diff] [blame] | 96 | get_ns_in_jiffie(); |
| 97 | } |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static int |
| 100 | __init init_udelay(void) |
| 101 | { |
| 102 | loops_per_usec = (loops_per_jiffy * HZ) / 1000000; |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | __initcall(init_udelay); |