Commit | Line | Data |
---|---|---|
730c1fad MS |
1 | /* MN10300 clockevents |
2 | * | |
3 | * Copyright (C) 2010 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by Mark Salter (msalter@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public Licence | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the Licence, or (at your option) any later version. | |
10 | */ | |
11 | #include <linux/clockchips.h> | |
12 | #include <linux/interrupt.h> | |
13 | #include <linux/percpu.h> | |
14 | #include <linux/smp.h> | |
15 | #include <asm/timex.h> | |
16 | #include "internal.h" | |
17 | ||
18 | #ifdef CONFIG_SMP | |
19 | #if (CONFIG_NR_CPUS > 2) && !defined(CONFIG_GEENERIC_CLOCKEVENTS_BROADCAST) | |
20 | #error "This doesn't scale well! Need per-core local timers." | |
21 | #endif | |
22 | #else /* CONFIG_SMP */ | |
23 | #define stop_jiffies_counter1() | |
24 | #define reload_jiffies_counter1(x) | |
25 | #define TMJC1IRQ TMJCIRQ | |
26 | #endif | |
27 | ||
28 | ||
29 | static int next_event(unsigned long delta, | |
30 | struct clock_event_device *evt) | |
31 | { | |
32 | unsigned int cpu = smp_processor_id(); | |
33 | ||
34 | if (cpu == 0) { | |
35 | stop_jiffies_counter(); | |
36 | reload_jiffies_counter(delta - 1); | |
37 | } else { | |
38 | stop_jiffies_counter1(); | |
39 | reload_jiffies_counter1(delta - 1); | |
40 | } | |
41 | return 0; | |
42 | } | |
43 | ||
44 | static void set_clock_mode(enum clock_event_mode mode, | |
45 | struct clock_event_device *evt) | |
46 | { | |
47 | /* Nothing to do ... */ | |
48 | } | |
49 | ||
50 | static DEFINE_PER_CPU(struct clock_event_device, mn10300_clockevent_device); | |
51 | static DEFINE_PER_CPU(struct irqaction, timer_irq); | |
52 | ||
53 | static irqreturn_t timer_interrupt(int irq, void *dev_id) | |
54 | { | |
55 | struct clock_event_device *cd; | |
56 | unsigned int cpu = smp_processor_id(); | |
57 | ||
58 | if (cpu == 0) | |
59 | stop_jiffies_counter(); | |
60 | else | |
61 | stop_jiffies_counter1(); | |
62 | ||
63 | cd = &per_cpu(mn10300_clockevent_device, cpu); | |
64 | cd->event_handler(cd); | |
65 | ||
66 | return IRQ_HANDLED; | |
67 | } | |
68 | ||
69 | static void event_handler(struct clock_event_device *dev) | |
70 | { | |
71 | } | |
72 | ||
73 | int __init init_clockevents(void) | |
74 | { | |
75 | struct clock_event_device *cd; | |
76 | struct irqaction *iact; | |
77 | unsigned int cpu = smp_processor_id(); | |
78 | ||
79 | cd = &per_cpu(mn10300_clockevent_device, cpu); | |
80 | ||
81 | if (cpu == 0) { | |
82 | stop_jiffies_counter(); | |
83 | cd->irq = TMJCIRQ; | |
84 | } else { | |
85 | stop_jiffies_counter1(); | |
86 | cd->irq = TMJC1IRQ; | |
87 | } | |
88 | ||
89 | cd->name = "Timestamp"; | |
90 | cd->features = CLOCK_EVT_FEAT_ONESHOT; | |
91 | ||
92 | /* Calculate the min / max delta */ | |
93 | clockevent_set_clock(cd, MN10300_JCCLK); | |
94 | ||
95 | cd->max_delta_ns = clockevent_delta2ns(TMJCBR_MAX, cd); | |
96 | cd->min_delta_ns = clockevent_delta2ns(100, cd); | |
97 | ||
98 | cd->rating = 200; | |
99 | cd->cpumask = cpumask_of(smp_processor_id()); | |
100 | cd->set_mode = set_clock_mode; | |
101 | cd->event_handler = event_handler; | |
102 | cd->set_next_event = next_event; | |
103 | ||
104 | iact = &per_cpu(timer_irq, cpu); | |
105 | iact->flags = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER; | |
106 | iact->handler = timer_interrupt; | |
107 | ||
108 | clockevents_register_device(cd); | |
109 | ||
110 | #if defined(CONFIG_SMP) && !defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) | |
111 | /* setup timer irq affinity so it only runs on this cpu */ | |
112 | { | |
113 | struct irq_desc *desc; | |
114 | desc = irq_to_desc(cd->irq); | |
115 | cpumask_copy(desc->affinity, cpumask_of(cpu)); | |
116 | iact->flags |= IRQF_NOBALANCING; | |
117 | } | |
118 | #endif | |
119 | ||
120 | if (cpu == 0) { | |
121 | reload_jiffies_counter(MN10300_JC_PER_HZ - 1); | |
122 | iact->name = "CPU0 Timer"; | |
123 | } else { | |
124 | reload_jiffies_counter1(MN10300_JC_PER_HZ - 1); | |
125 | iact->name = "CPU1 Timer"; | |
126 | } | |
127 | ||
128 | setup_jiffies_interrupt(cd->irq, iact); | |
129 | ||
130 | return 0; | |
131 | } |