2 * linux/arch/arm/mach-footbridge/dc21285-timer.c
4 * Copyright (C) 1998 Russell King.
5 * Copyright (C) 1998 Phil Blundell
7 #include <linux/clockchips.h>
8 #include <linux/clocksource.h>
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/irq.h>
12 #include <linux/sched_clock.h>
16 #include <asm/hardware/dec21285.h>
17 #include <asm/mach/time.h>
18 #include <asm/system_info.h>
22 static cycle_t
cksrc_dc21285_read(struct clocksource
*cs
)
24 return cs
->mask
- *CSR_TIMER2_VALUE
;
27 static int cksrc_dc21285_enable(struct clocksource
*cs
)
29 *CSR_TIMER2_LOAD
= cs
->mask
;
31 *CSR_TIMER2_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
35 static void cksrc_dc21285_disable(struct clocksource
*cs
)
40 static struct clocksource cksrc_dc21285
= {
41 .name
= "dc21285_timer2",
43 .read
= cksrc_dc21285_read
,
44 .enable
= cksrc_dc21285_enable
,
45 .disable
= cksrc_dc21285_disable
,
46 .mask
= CLOCKSOURCE_MASK(24),
47 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
50 static int ckevt_dc21285_set_next_event(unsigned long delta
,
51 struct clock_event_device
*c
)
54 *CSR_TIMER1_LOAD
= delta
;
55 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
60 static int ckevt_dc21285_shutdown(struct clock_event_device
*c
)
66 static int ckevt_dc21285_set_periodic(struct clock_event_device
*c
)
69 *CSR_TIMER1_LOAD
= (mem_fclk_21285
+ 8 * HZ
) / (16 * HZ
);
70 *CSR_TIMER1_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_AUTORELOAD
|
75 static struct clock_event_device ckevt_dc21285
= {
76 .name
= "dc21285_timer1",
77 .features
= CLOCK_EVT_FEAT_PERIODIC
|
78 CLOCK_EVT_FEAT_ONESHOT
,
81 .set_next_event
= ckevt_dc21285_set_next_event
,
82 .set_state_shutdown
= ckevt_dc21285_shutdown
,
83 .set_state_periodic
= ckevt_dc21285_set_periodic
,
84 .set_state_oneshot
= ckevt_dc21285_shutdown
,
85 .tick_resume
= ckevt_dc21285_set_periodic
,
88 static irqreturn_t
timer1_interrupt(int irq
, void *dev_id
)
90 struct clock_event_device
*ce
= dev_id
;
94 /* Stop the timer if in one-shot mode */
95 if (clockevent_state_oneshot(ce
))
98 ce
->event_handler(ce
);
103 static struct irqaction footbridge_timer_irq
= {
104 .name
= "dc21285_timer1",
105 .handler
= timer1_interrupt
,
106 .flags
= IRQF_TIMER
| IRQF_IRQPOLL
,
107 .dev_id
= &ckevt_dc21285
,
111 * Set up timer interrupt.
113 void __init
footbridge_timer_init(void)
115 struct clock_event_device
*ce
= &ckevt_dc21285
;
116 unsigned rate
= DIV_ROUND_CLOSEST(mem_fclk_21285
, 16);
118 clocksource_register_hz(&cksrc_dc21285
, rate
);
120 setup_irq(ce
->irq
, &footbridge_timer_irq
);
122 ce
->cpumask
= cpumask_of(smp_processor_id());
123 clockevents_config_and_register(ce
, rate
, 0x4, 0xffffff);
126 static u64 notrace
footbridge_read_sched_clock(void)
128 return ~*CSR_TIMER3_VALUE
;
131 void __init
footbridge_sched_clock(void)
133 unsigned rate
= DIV_ROUND_CLOSEST(mem_fclk_21285
, 16);
135 *CSR_TIMER3_LOAD
= 0;
137 *CSR_TIMER3_CNTL
= TIMER_CNTL_ENABLE
| TIMER_CNTL_DIV16
;
139 sched_clock_register(footbridge_read_sched_clock
, 24, rate
);