sh: Kill off dead timer sysclass pm hooks.
[safe/jmp/linux-2.6] / arch / sh / kernel / time.c
1 /*
2  *  arch/sh/kernel/time.c
3  *
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>
8  *
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
11  * for more details.
12  */
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>
25 #include <asm/rtc.h>
26 #include <asm/timer.h>
27
28 struct sys_timer *sys_timer;
29
30 /* Move this somewhere more sensible.. */
31 DEFINE_SPINLOCK(rtc_lock);
32 EXPORT_SYMBOL(rtc_lock);
33
34 /* Dummy RTC ops */
35 static void null_rtc_get_time(struct timespec *tv)
36 {
37         tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
38         tv->tv_nsec = 0;
39 }
40
41 static int null_rtc_set_time(const time_t secs)
42 {
43         return 0;
44 }
45
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;
48
49 #ifdef CONFIG_GENERIC_CMOS_UPDATE
50 unsigned long read_persistent_clock(void)
51 {
52         struct timespec tv;
53         rtc_sh_get_time(&tv);
54         return tv.tv_sec;
55 }
56
57 int update_persistent_clock(struct timespec now)
58 {
59         return rtc_sh_set_time(now.tv_sec);
60 }
61 #endif
62
63 unsigned int get_rtc_time(struct rtc_time *tm)
64 {
65         if (rtc_sh_get_time != null_rtc_get_time) {
66                 struct timespec tv;
67
68                 rtc_sh_get_time(&tv);
69                 rtc_time_to_tm(tv.tv_sec, tm);
70         }
71
72         return RTC_24H;
73 }
74 EXPORT_SYMBOL(get_rtc_time);
75
76 int set_rtc_time(struct rtc_time *tm)
77 {
78         unsigned long secs;
79
80         rtc_tm_to_time(tm, &secs);
81         return rtc_sh_set_time(secs);
82 }
83 EXPORT_SYMBOL(set_rtc_time);
84
85 static int __init rtc_generic_init(void)
86 {
87         struct platform_device *pdev;
88
89         if (rtc_sh_get_time == null_rtc_get_time)
90                 return -ENODEV;
91
92         pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
93         if (IS_ERR(pdev))
94                 return PTR_ERR(pdev);
95
96         return 0;
97 }
98 module_init(rtc_generic_init);
99
100 void (*board_time_init)(void);
101
102 struct clocksource clocksource_sh = {
103         .name           = "SuperH",
104 };
105
106 unsigned long long sched_clock(void)
107 {
108         unsigned long long cycles;
109
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);
113
114         cycles = clocksource_sh.read(&clocksource_sh);
115         return cyc2ns(&clocksource_sh, cycles);
116 }
117
118 static void __init sh_late_time_init(void)
119 {
120         /*
121          * Make sure all compiled-in early timers register themselves.
122          * Run probe() for one "earlytimer" device.
123          */
124         early_platform_driver_register_all("earlytimer");
125         if (early_platform_driver_probe("earlytimer", 1, 0))
126                 return;
127
128         /*
129          * Find the timer to use as the system timer, it will be
130          * initialized for us.
131          */
132         sys_timer = get_sys_timer();
133         if (unlikely(!sys_timer))
134                 panic("System timer missing.\n");
135
136         printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
137 }
138
139 void __init time_init(void)
140 {
141         if (board_time_init)
142                 board_time_init();
143
144         clk_init();
145
146         rtc_sh_get_time(&xtime);
147         set_normalized_timespec(&wall_to_monotonic,
148                                 -xtime.tv_sec, -xtime.tv_nsec);
149
150 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
151         local_timer_setup(smp_processor_id());
152 #endif
153
154         late_time_init = sh_late_time_init;
155 }