2 * arch/sh/kernel/time.c
4 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
5 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 2002 - 2009 Paul Mundt
7 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/profile.h>
17 #include <linux/timex.h>
18 #include <linux/sched.h>
19 #include <linux/clockchips.h>
20 #include <linux/mc146818rtc.h> /* for rtc_lock */
21 #include <linux/platform_device.h>
22 #include <linux/smp.h>
23 #include <linux/rtc.h>
24 #include <asm/clock.h>
26 #include <asm/timer.h>
28 struct sys_timer *sys_timer;
30 /* Move this somewhere more sensible.. */
31 DEFINE_SPINLOCK(rtc_lock);
32 EXPORT_SYMBOL(rtc_lock);
35 static void null_rtc_get_time(struct timespec *tv)
37 tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
41 static int null_rtc_set_time(const time_t secs)
46 void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
47 int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
49 #ifdef CONFIG_GENERIC_CMOS_UPDATE
50 unsigned long read_persistent_clock(void)
57 int update_persistent_clock(struct timespec now)
59 return rtc_sh_set_time(now.tv_sec);
63 unsigned int get_rtc_time(struct rtc_time *tm)
65 if (rtc_sh_get_time != null_rtc_get_time) {
69 rtc_time_to_tm(tv.tv_sec, tm);
74 EXPORT_SYMBOL(get_rtc_time);
76 int set_rtc_time(struct rtc_time *tm)
80 rtc_tm_to_time(tm, &secs);
81 return rtc_sh_set_time(secs);
83 EXPORT_SYMBOL(set_rtc_time);
85 static int __init rtc_generic_init(void)
87 struct platform_device *pdev;
89 if (rtc_sh_get_time == null_rtc_get_time)
92 pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
98 module_init(rtc_generic_init);
100 void (*board_time_init)(void);
102 struct clocksource clocksource_sh = {
106 unsigned long long sched_clock(void)
108 unsigned long long cycles;
110 /* jiffies based sched_clock if no clocksource is installed */
111 if (!clocksource_sh.rating)
112 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
114 cycles = clocksource_sh.read(&clocksource_sh);
115 return cyc2ns(&clocksource_sh, cycles);
118 static void __init sh_late_time_init(void)
121 * Make sure all compiled-in early timers register themselves.
122 * Run probe() for one "earlytimer" device.
124 early_platform_driver_register_all("earlytimer");
125 if (early_platform_driver_probe("earlytimer", 1, 0))
129 * Find the timer to use as the system timer, it will be
130 * initialized for us.
132 sys_timer = get_sys_timer();
133 if (unlikely(!sys_timer))
134 panic("System timer missing.\n");
136 printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
139 void __init time_init(void)
146 rtc_sh_get_time(&xtime);
147 set_normalized_timespec(&wall_to_monotonic,
148 -xtime.tv_sec, -xtime.tv_nsec);
150 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
151 local_timer_setup(smp_processor_id());
154 late_time_init = sh_late_time_init;