11 #include <linux/module.h>
14 #include <linux/time.h>
15 #include <linux/timex.h>
27 #if defined(CONFIG_CYCLES_CLOCKSOURCE)
31 #ifdef CONFIG_CPU_FREQ
32 return __bfin_cycles_off + (
get_cycles() << __bfin_cycles_mod);
39 .
name =
"bfin_cs_cycles",
41 .read = bfin_read_cycles,
46 static inline unsigned long long bfin_cs_cycles_sched_clock(
void)
48 return clocksource_cyc2ns(bfin_read_cycles(&bfin_cs_cycles),
49 bfin_cs_cycles.
mult, bfin_cs_cycles.
shift);
54 if (clocksource_register_hz(&bfin_cs_cycles,
get_cclk()))
55 panic(
"failed to register clocksource");
60 # define bfin_cs_cycles_init()
63 #ifdef CONFIG_GPTMR0_CLOCKSOURCE
65 void __init setup_gptimer0(
void)
89 .
name =
"bfin_cs_gptimer0",
91 .read = bfin_read_gptimer0,
96 static inline unsigned long long bfin_cs_gptimer0_sched_clock(
void)
99 bfin_cs_gptimer0.
mult, bfin_cs_gptimer0.
shift);
106 if (clocksource_register_hz(&bfin_cs_gptimer0,
get_sclk()))
107 panic(
"failed to register clocksource");
112 # define bfin_cs_gptimer0_init()
115 #if defined(CONFIG_GPTMR0_CLOCKSOURCE) || defined(CONFIG_CYCLES_CLOCKSOURCE)
119 #if defined(CONFIG_CYCLES_CLOCKSOURCE)
120 return bfin_cs_cycles_sched_clock();
122 return bfin_cs_gptimer0_sched_clock();
127 #if defined(CONFIG_TICKSOURCE_GPTMR0)
128 static int bfin_gptmr0_set_next_event(
unsigned long cycles,
129 struct clock_event_device *
evt)
139 static void bfin_gptmr0_set_mode(
enum clock_event_mode
mode,
140 struct clock_event_device *
evt)
143 case CLOCK_EVT_MODE_PERIODIC: {
158 case CLOCK_EVT_MODE_ONESHOT:
170 case CLOCK_EVT_MODE_UNUSED:
171 case CLOCK_EVT_MODE_SHUTDOWN:
174 case CLOCK_EVT_MODE_RESUME:
179 static void bfin_gptmr0_ack(
void)
184 static void __init bfin_gptmr0_init(
void)
189 #ifdef CONFIG_CORE_TIMER_IRQ_L1
194 struct clock_event_device *evt =
dev_id;
203 evt->event_handler(evt);
208 .
name =
"Blackfin GPTimer0",
210 .handler = bfin_gptmr0_interrupt,
213 static struct clock_event_device clockevent_gptmr0 = {
214 .name =
"bfin_gptimer0",
218 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
219 .set_next_event = bfin_gptmr0_set_next_event,
220 .set_mode = bfin_gptmr0_set_mode,
223 static void __init bfin_gptmr0_clockevent_init(
struct clock_event_device *evt)
225 unsigned long clock_tick;
228 evt->mult = div_sc(clock_tick,
NSEC_PER_SEC, evt->shift);
238 #if defined(CONFIG_TICKSOURCE_CORETMR)
242 static int bfin_coretmr_set_next_event(
unsigned long cycles,
243 struct clock_event_device *evt)
253 static void bfin_coretmr_set_mode(
enum clock_event_mode mode,
254 struct clock_event_device *evt)
257 case CLOCK_EVT_MODE_PERIODIC: {
268 case CLOCK_EVT_MODE_ONESHOT:
275 case CLOCK_EVT_MODE_UNUSED:
276 case CLOCK_EVT_MODE_SHUTDOWN:
280 case CLOCK_EVT_MODE_RESUME:
285 void bfin_coretmr_init(
void)
299 #ifdef CONFIG_CORE_TIMER_IRQ_L1
303 irqreturn_t bfin_coretmr_interrupt(
int irq,
void *dev_id)
306 struct clock_event_device *evt = &
per_cpu(coretmr_events, cpu);
309 evt->event_handler(evt);
317 .
name =
"Blackfin CoreTimer",
319 .handler = bfin_coretmr_interrupt,
322 void bfin_coretmr_clockevent_init(
void)
324 unsigned long clock_tick;
326 struct clock_event_device *evt = &
per_cpu(coretmr_events, cpu);
338 evt->name =
"bfin_core_timer";
342 evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
343 evt->set_next_event = bfin_coretmr_set_next_event;
344 evt->set_mode = bfin_coretmr_set_mode;
347 evt->mult = div_sc(clock_tick,
NSEC_PER_SEC, evt->shift);
360 time_t secs_since_1970 = (365 * 37 + 9) * 24 * 60 * 60;
361 ts->
tv_sec = secs_since_1970;
368 #ifdef CONFIG_RTC_DRV_BFIN
382 #if defined(CONFIG_TICKSOURCE_CORETMR)
385 bfin_coretmr_clockevent_init();
388 #if defined(CONFIG_TICKSOURCE_GPTMR0)
391 gptmr0_irq.
dev_id = &clockevent_gptmr0;
392 bfin_gptmr0_clockevent_init(&clockevent_gptmr0);
395 #if !defined(CONFIG_TICKSOURCE_CORETMR) && !defined(CONFIG_TICKSOURCE_GPTMR0)
396 # error at least one clock event device is required