11 #include <linux/kernel.h>
13 #include <linux/types.h>
26 #include <mach/cputype.h>
27 #include <mach/hardware.h>
28 #include <mach/time.h>
32 static struct clock_event_device clockevent_davinci;
33 static unsigned int davinci_clock_tick_rate;
66 #define TCR_ENAMODE_DISABLE 0x0
67 #define TCR_ENAMODE_ONESHOT 0x1
68 #define TCR_ENAMODE_PERIODIC 0x2
69 #define TCR_ENAMODE_MASK 0x3
71 #define TGCR_TIMMODE_SHIFT 2
72 #define TGCR_TIMMODE_64BIT_GP 0x0
73 #define TGCR_TIMMODE_32BIT_UNCHAINED 0x1
74 #define TGCR_TIMMODE_64BIT_WDOG 0x2
75 #define TGCR_TIMMODE_32BIT_CHAINED 0x3
77 #define TGCR_TIM12RS_SHIFT 0
78 #define TGCR_TIM34RS_SHIFT 1
79 #define TGCR_RESET 0x0
80 #define TGCR_UNRESET 0x1
81 #define TGCR_RESET_MASK 0x3
83 #define WDTCR_WDEN_SHIFT 14
84 #define WDTCR_WDEN_DISABLE 0x0
85 #define WDTCR_WDEN_ENABLE 0x1
86 #define WDTCR_WDKEY_SHIFT 16
87 #define WDTCR_WDKEY_SEQ0 0xa5c6
88 #define WDTCR_WDKEY_SEQ1 0xda7e
102 static struct timer_s timers[];
105 #define TIMER_OPTS_DISABLED 0x01
106 #define TIMER_OPTS_ONESHOT 0x02
107 #define TIMER_OPTS_PERIODIC 0x04
108 #define TIMER_OPTS_STATE_MASK 0x07
110 #define TIMER_OPTS_USE_COMPARE 0x80000000
111 #define USING_COMPARE(t) ((t)->opts & TIMER_OPTS_USE_COMPARE)
113 static char *id_to_name[] = {
120 static int timer32_config(
struct timer_s *
t)
160 static inline u32 timer32_read(
struct timer_s *t)
167 struct clock_event_device *
evt = &clockevent_davinci;
169 evt->event_handler(evt);
174 static irqreturn_t freerun_interrupt(
int irq,
void *dev_id)
179 static struct timer_s timers[] = {
181 .name =
"clockevent",
189 .name =
"free-run counter",
194 .handler = freerun_interrupt,
199 static void __init timer_init(
void)
288 static u32 notrace davinci_read_sched_clock(
void)
296 static int davinci_set_next_event(
unsigned long cycles,
297 struct clock_event_device *evt)
306 static void davinci_set_mode(
enum clock_event_mode
mode,
307 struct clock_event_device *evt)
312 case CLOCK_EVT_MODE_PERIODIC:
313 t->
period = davinci_clock_tick_rate / (
HZ);
318 case CLOCK_EVT_MODE_ONESHOT:
322 case CLOCK_EVT_MODE_UNUSED:
323 case CLOCK_EVT_MODE_SHUTDOWN:
327 case CLOCK_EVT_MODE_RESUME:
332 static struct clock_event_device clockevent_davinci = {
333 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
335 .set_next_event = davinci_set_next_event,
336 .set_mode = davinci_set_mode,
340 static void __init davinci_timer_init(
void)
342 struct clk *timer_clk;
344 unsigned int clockevent_id;
345 unsigned int clocksource_id;
347 "%s: can't register clocksource!\n";
350 clockevent_id = soc_info->
timer_info->clockevent_id;
351 clocksource_id = soc_info->
timer_info->clocksource_id;
361 if (clockevent_id == clocksource_id) {
369 " of system timers. Results unpredictable.\n");
370 else if ((dtip[event_timer].
cmp_off == 0)
371 || (dtip[event_timer].
cmp_irq == 0))
372 pr_warning(
"davinci_timer_init: Invalid timer instance"
373 " setup. Results unpredictable.\n");
376 clockevent_davinci.features = CLOCK_EVT_FEAT_ONESHOT;
381 BUG_ON(IS_ERR(timer_clk));
390 clocksource_davinci.
name = id_to_name[clocksource_id];
391 if (clocksource_register_hz(&clocksource_davinci,
392 davinci_clock_tick_rate))
396 davinci_clock_tick_rate);
400 clockevent_davinci.mult = div_sc(davinci_clock_tick_rate,
NSEC_PER_SEC,
401 clockevent_davinci.shift);
402 clockevent_davinci.max_delta_ns =
404 clockevent_davinci.min_delta_ns = 50000;
410 timer32_config(&timers[i]);
414 .init = davinci_timer_init,