Add linux-next specific files for 20110831
[linux-2.6/next.git] / arch / arm / mach-sa1100 / time.c
blobfa6602491d54749c6b06483b2fc33eebc68a6c43
1 /*
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@fluxnic.net>
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/sched.h> /* just for sched_clock() - funny that */
16 #include <linux/timex.h>
17 #include <linux/clockchips.h>
19 #include <asm/mach/time.h>
20 #include <asm/sched_clock.h>
21 #include <mach/hardware.h>
24 * This is the SA11x0 sched_clock implementation.
26 static DEFINE_CLOCK_DATA(cd);
29 * Constants generated by clocks_calc_mult_shift(m, s, 3.6864MHz,
30 * NSEC_PER_SEC, 60).
31 * This gives a resolution of about 271ns and a wrap period of about 19min.
33 #define SC_MULT 2275555556u
34 #define SC_SHIFT 23
36 unsigned long long notrace sched_clock(void)
38 u32 cyc = OSCR;
39 return cyc_to_fixed_sched_clock(&cd, cyc, (u32)~0, SC_MULT, SC_SHIFT);
42 static void notrace sa1100_update_sched_clock(void)
44 u32 cyc = OSCR;
45 update_sched_clock(&cd, cyc, (u32)~0);
48 #define MIN_OSCR_DELTA 2
50 static irqreturn_t sa1100_ost0_interrupt(int irq, void *dev_id)
52 struct clock_event_device *c = dev_id;
54 /* Disarm the compare/match, signal the event. */
55 OIER &= ~OIER_E0;
56 OSSR = OSSR_M0;
57 c->event_handler(c);
59 return IRQ_HANDLED;
62 static int
63 sa1100_osmr0_set_next_event(unsigned long delta, struct clock_event_device *c)
65 unsigned long next, oscr;
67 OIER |= OIER_E0;
68 next = OSCR + delta;
69 OSMR0 = next;
70 oscr = OSCR;
72 return (signed)(next - oscr) <= MIN_OSCR_DELTA ? -ETIME : 0;
75 static void
76 sa1100_osmr0_set_mode(enum clock_event_mode mode, struct clock_event_device *c)
78 switch (mode) {
79 case CLOCK_EVT_MODE_ONESHOT:
80 case CLOCK_EVT_MODE_UNUSED:
81 case CLOCK_EVT_MODE_SHUTDOWN:
82 OIER &= ~OIER_E0;
83 OSSR = OSSR_M0;
84 break;
86 case CLOCK_EVT_MODE_RESUME:
87 case CLOCK_EVT_MODE_PERIODIC:
88 break;
92 static struct clock_event_device ckevt_sa1100_osmr0 = {
93 .name = "osmr0",
94 .features = CLOCK_EVT_FEAT_ONESHOT,
95 .rating = 200,
96 .set_next_event = sa1100_osmr0_set_next_event,
97 .set_mode = sa1100_osmr0_set_mode,
100 static struct irqaction sa1100_timer_irq = {
101 .name = "ost0",
102 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
103 .handler = sa1100_ost0_interrupt,
104 .dev_id = &ckevt_sa1100_osmr0,
107 static void __init sa1100_timer_init(void)
109 OIER = 0;
110 OSSR = OSSR_M0 | OSSR_M1 | OSSR_M2 | OSSR_M3;
112 init_fixed_sched_clock(&cd, sa1100_update_sched_clock, 32,
113 3686400, SC_MULT, SC_SHIFT);
115 clockevents_calc_mult_shift(&ckevt_sa1100_osmr0, 3686400, 4);
116 ckevt_sa1100_osmr0.max_delta_ns =
117 clockevent_delta2ns(0x7fffffff, &ckevt_sa1100_osmr0);
118 ckevt_sa1100_osmr0.min_delta_ns =
119 clockevent_delta2ns(MIN_OSCR_DELTA * 2, &ckevt_sa1100_osmr0) + 1;
120 ckevt_sa1100_osmr0.cpumask = cpumask_of(0);
122 setup_irq(IRQ_OST0, &sa1100_timer_irq);
124 clocksource_mmio_init(&OSCR, "oscr", CLOCK_TICK_RATE, 200, 32,
125 clocksource_mmio_readl_up);
126 clockevents_register_device(&ckevt_sa1100_osmr0);
129 #ifdef CONFIG_PM
130 unsigned long osmr[4], oier;
132 static void sa1100_timer_suspend(void)
134 osmr[0] = OSMR0;
135 osmr[1] = OSMR1;
136 osmr[2] = OSMR2;
137 osmr[3] = OSMR3;
138 oier = OIER;
141 static void sa1100_timer_resume(void)
143 OSSR = 0x0f;
144 OSMR0 = osmr[0];
145 OSMR1 = osmr[1];
146 OSMR2 = osmr[2];
147 OSMR3 = osmr[3];
148 OIER = oier;
151 * OSMR0 is the system timer: make sure OSCR is sufficiently behind
153 OSCR = OSMR0 - LATCH;
155 #else
156 #define sa1100_timer_suspend NULL
157 #define sa1100_timer_resume NULL
158 #endif
160 struct sys_timer sa1100_timer = {
161 .init = sa1100_timer_init,
162 .suspend = sa1100_timer_suspend,
163 .resume = sa1100_timer_resume,