2 * linux/arch/arm/mach-sa1100/time.c
4 * Copyright (C) 1998 Deborah Wallach.
5 * Twiddles (C) 1999 Hugo Fiennes <hugo@empeg.com>
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>
17 #include <linux/clocksource.h>
19 #include <asm/mach/time.h>
20 #include <asm/hardware.h>
22 #define RTC_DEF_DIVIDER (32768 - 1)
23 #define RTC_DEF_TRIM 0
25 static int sa1100_set_rtc(void)
27 unsigned long current_time
= xtime
.tv_sec
;
29 if (RTSR
& RTSR_ALE
) {
30 /* make sure not to forward the clock over an alarm */
31 unsigned long alarm
= RTAR
;
32 if (current_time
>= alarm
&& alarm
>= RCNR
)
39 #ifdef CONFIG_NO_IDLE_HZ
40 static unsigned long initial_match
;
41 static int match_posponed
;
45 sa1100_timer_interrupt(int irq
, void *dev_id
)
47 unsigned int next_match
;
49 #ifdef CONFIG_NO_IDLE_HZ
52 OSMR0
= initial_match
;
57 * Loop until we get ahead of the free running timer.
58 * This ensures an exact clock tick count and time accuracy.
59 * Since IRQs are disabled at this point, coherence between
60 * lost_ticks(updated in do_timer()) and the match reg value is
61 * ensured, hence we can use do_gettimeofday() from interrupt
66 OSSR
= OSSR_M0
; /* Clear match on timer 0 */
67 next_match
= (OSMR0
+= LATCH
);
68 } while ((signed long)(next_match
- OSCR
) <= 0);
73 static struct irqaction sa1100_timer_irq
= {
74 .name
= "SA11xx Timer Tick",
75 .flags
= IRQF_DISABLED
| IRQF_TIMER
| IRQF_IRQPOLL
,
76 .handler
= sa1100_timer_interrupt
,
79 static cycle_t
sa1100_read_oscr(void)
84 static struct clocksource cksrc_sa1100_oscr
= {
87 .read
= sa1100_read_oscr
,
88 .mask
= CLOCKSOURCE_MASK(32),
90 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
93 static void __init
sa1100_timer_init(void)
97 set_rtc
= sa1100_set_rtc
;
99 OIER
= 0; /* disable any timer interrupts */
100 OSSR
= 0xf; /* clear status on all timers */
101 setup_irq(IRQ_OST0
, &sa1100_timer_irq
);
102 local_irq_save(flags
);
103 OIER
= OIER_E0
; /* enable match on timer 0 to cause interrupts */
104 OSMR0
= OSCR
+ LATCH
; /* set initial match */
105 local_irq_restore(flags
);
107 cksrc_sa1100_oscr
.mult
=
108 clocksource_hz2mult(CLOCK_TICK_RATE
, cksrc_sa1100_oscr
.shift
);
110 clocksource_register(&cksrc_sa1100_oscr
);
113 #ifdef CONFIG_NO_IDLE_HZ
114 static int sa1100_dyn_tick_enable_disable(void)
120 static void sa1100_dyn_tick_reprogram(unsigned long ticks
)
123 initial_match
= OSMR0
;
124 OSMR0
= initial_match
+ ticks
* LATCH
;
130 sa1100_dyn_tick_handler(int irq
, void *dev_id
)
132 if (match_posponed
) {
134 OSMR0
= initial_match
;
135 if ((signed long)(initial_match
- OSCR
) <= 0)
136 return sa1100_timer_interrupt(irq
, dev_id
);
141 static struct dyn_tick_timer sa1100_dyn_tick
= {
142 .enable
= sa1100_dyn_tick_enable_disable
,
143 .disable
= sa1100_dyn_tick_enable_disable
,
144 .reprogram
= sa1100_dyn_tick_reprogram
,
145 .handler
= sa1100_dyn_tick_handler
,
150 unsigned long osmr
[4], oier
;
152 static void sa1100_timer_suspend(void)
161 static void sa1100_timer_resume(void)
171 * OSMR0 is the system timer: make sure OSCR is sufficiently behind
173 OSCR
= OSMR0
- LATCH
;
176 #define sa1100_timer_suspend NULL
177 #define sa1100_timer_resume NULL
180 struct sys_timer sa1100_timer
= {
181 .init
= sa1100_timer_init
,
182 .suspend
= sa1100_timer_suspend
,
183 .resume
= sa1100_timer_resume
,
184 #ifdef CONFIG_NO_IDLE_HZ
185 .dyn_tick
= &sa1100_dyn_tick
,