9 #include <linux/kernel.h>
13 #include <linux/bitops.h>
17 #include <linux/slab.h>
26 #define SIRFSOC_TIMER_COUNTER_LO 0x0000
27 #define SIRFSOC_TIMER_COUNTER_HI 0x0004
28 #define SIRFSOC_TIMER_MATCH_0 0x0008
29 #define SIRFSOC_TIMER_MATCH_1 0x000C
30 #define SIRFSOC_TIMER_MATCH_2 0x0010
31 #define SIRFSOC_TIMER_MATCH_3 0x0014
32 #define SIRFSOC_TIMER_MATCH_4 0x0018
33 #define SIRFSOC_TIMER_MATCH_5 0x001C
34 #define SIRFSOC_TIMER_STATUS 0x0020
35 #define SIRFSOC_TIMER_INT_EN 0x0024
36 #define SIRFSOC_TIMER_WATCHDOG_EN 0x0028
37 #define SIRFSOC_TIMER_DIV 0x002C
38 #define SIRFSOC_TIMER_LATCH 0x0030
39 #define SIRFSOC_TIMER_LATCHED_LO 0x0034
40 #define SIRFSOC_TIMER_LATCHED_HI 0x0038
42 #define SIRFSOC_TIMER_WDT_INDEX 5
44 #define SIRFSOC_TIMER_LATCH_BIT BIT(0)
46 #define SIRFSOC_TIMER_REG_CNT 11
57 static void __iomem *sirfsoc_timer_base;
58 static void __init sirfsoc_of_timer_map(
void);
63 struct clock_event_device *
ce =
dev_id;
70 ce->event_handler(ce);
88 static int sirfsoc_timer_set_next_event(
unsigned long delta,
89 struct clock_event_device *ce)
91 unsigned long now,
next;
100 return next - now > delta ? -
ETIME : 0;
103 static void sirfsoc_timer_set_mode(
enum clock_event_mode
mode,
104 struct clock_event_device *ce)
108 case CLOCK_EVT_MODE_PERIODIC:
111 case CLOCK_EVT_MODE_ONESHOT:
114 case CLOCK_EVT_MODE_SHUTDOWN:
117 case CLOCK_EVT_MODE_UNUSED:
118 case CLOCK_EVT_MODE_RESUME:
123 static void sirfsoc_clocksource_suspend(
struct clocksource *cs)
130 sirfsoc_timer_reg_val[i] =
readl_relaxed(sirfsoc_timer_base + sirfsoc_timer_reg_list[i]);
133 static void sirfsoc_clocksource_resume(
struct clocksource *cs)
137 for (i = 0; i < SIRFSOC_TIMER_REG_CNT - 2; i++)
138 writel_relaxed(sirfsoc_timer_reg_val[i], sirfsoc_timer_base + sirfsoc_timer_reg_list[i]);
144 static struct clock_event_device sirfsoc_clockevent = {
145 .name =
"sirfsoc_clockevent",
147 .features = CLOCK_EVT_FEAT_ONESHOT,
148 .set_mode = sirfsoc_timer_set_mode,
149 .set_next_event = sirfsoc_timer_set_next_event,
153 .name =
"sirfsoc_clocksource",
157 .read = sirfsoc_timer_read,
158 .suspend = sirfsoc_clocksource_suspend,
159 .resume = sirfsoc_clocksource_resume,
162 static struct irqaction sirfsoc_timer_irq = {
163 .name =
"sirfsoc_timer0",
166 .handler = sirfsoc_timer_interrupt,
167 .dev_id = &sirfsoc_clockevent,
171 static u32 notrace sirfsoc_read_sched_clock(
void)
173 return (
u32)(sirfsoc_timer_read(
NULL) & 0xffffffff);
176 static void __init sirfsoc_clockevent_init(
void)
180 sirfsoc_clockevent.max_delta_ns =
182 sirfsoc_clockevent.min_delta_ns =
190 static void __init sirfsoc_timer_init(
void)
208 sirfsoc_of_timer_map();
221 sirfsoc_clockevent_init();
225 { .compatible =
"sirf,prima2-tick" },
229 static void __init sirfsoc_of_timer_map(
void)
232 const unsigned int *intspec;
236 panic(
"unable to find compatible timer node in dtb\n");
237 sirfsoc_timer_base =
of_iomap(np, 0);
238 if (!sirfsoc_timer_base)
239 panic(
"unable to map timer cpu registers\n");
250 .init = sirfsoc_timer_init,