[ARM] sa1100: remove boot time RTC initialisation
[linux-2.6/x86.git] / arch / arm / mach-sa1100 / time.c
blobfdf7b016e7adeadfa5652ae9779803209eba3d91
1 /*
2 * linux/arch/arm/mach-sa1100/time.c
4 * Copyright (C) 1998 Deborah Wallach.
5 * Twiddles (C) 1999 Hugo Fiennes <hugo@empeg.com>
6 *
7 * 2000/03/29 (C) Nicolas Pitre <nico@cam.org>
8 * Rewritten: big cleanup, much simpler, better HZ accuracy.
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
15 #include <linux/timex.h>
16 #include <linux/signal.h>
18 #include <asm/mach/time.h>
19 #include <asm/hardware.h>
21 #define RTC_DEF_DIVIDER (32768 - 1)
22 #define RTC_DEF_TRIM 0
24 static int sa1100_set_rtc(void)
26 unsigned long current_time = xtime.tv_sec;
28 if (RTSR & RTSR_ALE) {
29 /* make sure not to forward the clock over an alarm */
30 unsigned long alarm = RTAR;
31 if (current_time >= alarm && alarm >= RCNR)
32 return -ERESTARTSYS;
34 RCNR = current_time;
35 return 0;
38 /* IRQs are disabled before entering here from do_gettimeofday() */
39 static unsigned long sa1100_gettimeoffset (void)
41 unsigned long ticks_to_match, elapsed, usec;
43 /* Get ticks before next timer match */
44 ticks_to_match = OSMR0 - OSCR;
46 /* We need elapsed ticks since last match */
47 elapsed = LATCH - ticks_to_match;
49 /* Now convert them to usec */
50 usec = (unsigned long)(elapsed * (tick_nsec / 1000))/LATCH;
52 return usec;
55 #ifdef CONFIG_NO_IDLE_HZ
56 static unsigned long initial_match;
57 static int match_posponed;
58 #endif
60 static irqreturn_t
61 sa1100_timer_interrupt(int irq, void *dev_id)
63 unsigned int next_match;
65 write_seqlock(&xtime_lock);
67 #ifdef CONFIG_NO_IDLE_HZ
68 if (match_posponed) {
69 match_posponed = 0;
70 OSMR0 = initial_match;
72 #endif
75 * Loop until we get ahead of the free running timer.
76 * This ensures an exact clock tick count and time accuracy.
77 * Since IRQs are disabled at this point, coherence between
78 * lost_ticks(updated in do_timer()) and the match reg value is
79 * ensured, hence we can use do_gettimeofday() from interrupt
80 * handlers.
82 do {
83 timer_tick();
84 OSSR = OSSR_M0; /* Clear match on timer 0 */
85 next_match = (OSMR0 += LATCH);
86 } while ((signed long)(next_match - OSCR) <= 0);
88 write_sequnlock(&xtime_lock);
90 return IRQ_HANDLED;
93 static struct irqaction sa1100_timer_irq = {
94 .name = "SA11xx Timer Tick",
95 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
96 .handler = sa1100_timer_interrupt,
99 static void __init sa1100_timer_init(void)
101 unsigned long flags;
103 set_rtc = sa1100_set_rtc;
105 OIER = 0; /* disable any timer interrupts */
106 OSSR = 0xf; /* clear status on all timers */
107 setup_irq(IRQ_OST0, &sa1100_timer_irq);
108 local_irq_save(flags);
109 OIER = OIER_E0; /* enable match on timer 0 to cause interrupts */
110 OSMR0 = OSCR + LATCH; /* set initial match */
111 local_irq_restore(flags);
114 #ifdef CONFIG_NO_IDLE_HZ
115 static int sa1100_dyn_tick_enable_disable(void)
117 /* nothing to do */
118 return 0;
121 static void sa1100_dyn_tick_reprogram(unsigned long ticks)
123 if (ticks > 1) {
124 initial_match = OSMR0;
125 OSMR0 = initial_match + ticks * LATCH;
126 match_posponed = 1;
130 static irqreturn_t
131 sa1100_dyn_tick_handler(int irq, void *dev_id)
133 if (match_posponed) {
134 match_posponed = 0;
135 OSMR0 = initial_match;
136 if ((signed long)(initial_match - OSCR) <= 0)
137 return sa1100_timer_interrupt(irq, dev_id);
139 return IRQ_NONE;
142 static struct dyn_tick_timer sa1100_dyn_tick = {
143 .enable = sa1100_dyn_tick_enable_disable,
144 .disable = sa1100_dyn_tick_enable_disable,
145 .reprogram = sa1100_dyn_tick_reprogram,
146 .handler = sa1100_dyn_tick_handler,
148 #endif
150 #ifdef CONFIG_PM
151 unsigned long osmr[4], oier;
153 static void sa1100_timer_suspend(void)
155 osmr[0] = OSMR0;
156 osmr[1] = OSMR1;
157 osmr[2] = OSMR2;
158 osmr[3] = OSMR3;
159 oier = OIER;
162 static void sa1100_timer_resume(void)
164 OSSR = 0x0f;
165 OSMR0 = osmr[0];
166 OSMR1 = osmr[1];
167 OSMR2 = osmr[2];
168 OSMR3 = osmr[3];
169 OIER = oier;
172 * OSMR0 is the system timer: make sure OSCR is sufficiently behind
174 OSCR = OSMR0 - LATCH;
176 #else
177 #define sa1100_timer_suspend NULL
178 #define sa1100_timer_resume NULL
179 #endif
181 struct sys_timer sa1100_timer = {
182 .init = sa1100_timer_init,
183 .suspend = sa1100_timer_suspend,
184 .resume = sa1100_timer_resume,
185 .offset = sa1100_gettimeoffset,
186 #ifdef CONFIG_NO_IDLE_HZ
187 .dyn_tick = &sa1100_dyn_tick,
188 #endif