20 #include <linux/kernel.h>
23 #include <linux/time.h>
26 #include <mach/generic.h>
39 #define CR(x) ((x) * 0x80 + 0x80)
40 #define IR(x) ((x) * 0x80 + 0x84)
41 #define LOAD(x) ((x) * 0x80 + 0x88)
42 #define COUNT(x) ((x) * 0x80 + 0x8C)
45 #define CTRL_INT_ENABLE 0x0100
46 #define CTRL_ENABLE 0x0020
47 #define CTRL_ONE_SHOT 0x0010
49 #define CTRL_PRESCALER1 0x0
50 #define CTRL_PRESCALER2 0x1
51 #define CTRL_PRESCALER4 0x2
52 #define CTRL_PRESCALER8 0x3
53 #define CTRL_PRESCALER16 0x4
54 #define CTRL_PRESCALER32 0x5
55 #define CTRL_PRESCALER64 0x6
56 #define CTRL_PRESCALER128 0x7
57 #define CTRL_PRESCALER256 0x8
59 #define INT_STATUS 0x1
64 #define SPEAR_MIN_RANGE 4
67 static struct clk *gpt_clk;
69 static void clockevent_set_mode(
enum clock_event_mode
mode,
70 struct clock_event_device *clk_event_dev);
71 static int clockevent_next_event(
unsigned long evt,
72 struct clock_event_device *clk_event_dev);
74 static void spear_clocksource_init(
void)
98 static struct clock_event_device clkevt = {
100 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
101 .set_mode = clockevent_set_mode,
102 .set_next_event = clockevent_next_event,
106 static void clockevent_set_mode(
enum clock_event_mode
mode,
107 struct clock_event_device *clk_event_dev)
118 case CLOCK_EVT_MODE_PERIODIC:
129 case CLOCK_EVT_MODE_ONESHOT:
135 case CLOCK_EVT_MODE_UNUSED:
136 case CLOCK_EVT_MODE_SHUTDOWN:
137 case CLOCK_EVT_MODE_RESUME:
141 pr_err(
"Invalid mode requested\n");
146 static int clockevent_next_event(
unsigned long cycles,
147 struct clock_event_device *clk_event_dev)
164 struct clock_event_device *
evt = &clkevt;
168 evt->event_handler(evt);
173 static struct irqaction spear_timer_irq = {
176 .handler = spear_timer_interrupt
179 static void __init spear_clockevent_init(
int irq)
203 { .compatible =
"st,spear-timer", },
214 pr_err(
"%s: No timer passed via DT\n", __func__);
220 pr_err(
"%s: No irq passed for timer via DT\n", __func__);
226 pr_err(
"%s: of iomap failed\n", __func__);
232 pr_err(
"%s:couldn't get clk for gpt\n", __func__);
236 ret = clk_prepare_enable(gpt_clk);
238 pr_err(
"%s:couldn't prepare-enable gpt clock\n", __func__);
239 goto err_prepare_enable_clk;
242 spear_clockevent_init(irq);
243 spear_clocksource_init();
247 err_prepare_enable_clk: