This source file includes following definitions.
- disable_mfgpt0_counter
- enable_mfgpt0_counter
- mfgpt_timer_set_periodic
- mfgpt_timer_shutdown
- timer_interrupt
- setup_mfgpt0_timer
- mfgpt_read
- init_mfgpt_clocksource
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <linux/io.h>
15 #include <linux/init.h>
16 #include <linux/export.h>
17 #include <linux/jiffies.h>
18 #include <linux/spinlock.h>
19 #include <linux/interrupt.h>
20 #include <linux/clockchips.h>
21
22 #include <asm/time.h>
23
24 #include <cs5536/cs5536_mfgpt.h>
25
26 static DEFINE_RAW_SPINLOCK(mfgpt_lock);
27
28 static u32 mfgpt_base;
29
30
31
32
33
34
35
36
37 void disable_mfgpt0_counter(void)
38 {
39 outw(inw(MFGPT0_SETUP) & 0x7fff, MFGPT0_SETUP);
40 }
41 EXPORT_SYMBOL(disable_mfgpt0_counter);
42
43
44 void enable_mfgpt0_counter(void)
45 {
46 outw(0xe310, MFGPT0_SETUP);
47 }
48 EXPORT_SYMBOL(enable_mfgpt0_counter);
49
50 static int mfgpt_timer_set_periodic(struct clock_event_device *evt)
51 {
52 raw_spin_lock(&mfgpt_lock);
53
54 outw(COMPARE, MFGPT0_CMP2);
55 outw(0, MFGPT0_CNT);
56 enable_mfgpt0_counter();
57
58 raw_spin_unlock(&mfgpt_lock);
59 return 0;
60 }
61
62 static int mfgpt_timer_shutdown(struct clock_event_device *evt)
63 {
64 if (clockevent_state_periodic(evt) || clockevent_state_oneshot(evt)) {
65 raw_spin_lock(&mfgpt_lock);
66 disable_mfgpt0_counter();
67 raw_spin_unlock(&mfgpt_lock);
68 }
69
70 return 0;
71 }
72
73 static struct clock_event_device mfgpt_clockevent = {
74 .name = "mfgpt",
75 .features = CLOCK_EVT_FEAT_PERIODIC,
76
77
78 .set_state_shutdown = mfgpt_timer_shutdown,
79 .set_state_periodic = mfgpt_timer_set_periodic,
80 .irq = CS5536_MFGPT_INTR,
81 };
82
83 static irqreturn_t timer_interrupt(int irq, void *dev_id)
84 {
85 u32 basehi;
86
87
88
89
90
91
92
93 _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_MFGPT), &basehi, &mfgpt_base);
94
95
96 outw(inw(MFGPT0_SETUP) | 0x4000, MFGPT0_SETUP);
97
98 mfgpt_clockevent.event_handler(&mfgpt_clockevent);
99
100 return IRQ_HANDLED;
101 }
102
103 static struct irqaction irq5 = {
104 .handler = timer_interrupt,
105 .flags = IRQF_NOBALANCING | IRQF_TIMER,
106 .name = "timer"
107 };
108
109
110
111
112
113 void __init setup_mfgpt0_timer(void)
114 {
115 u32 basehi;
116 struct clock_event_device *cd = &mfgpt_clockevent;
117 unsigned int cpu = smp_processor_id();
118
119 cd->cpumask = cpumask_of(cpu);
120 clockevent_set_clock(cd, MFGPT_TICK_RATE);
121 cd->max_delta_ns = clockevent_delta2ns(0xffff, cd);
122 cd->max_delta_ticks = 0xffff;
123 cd->min_delta_ns = clockevent_delta2ns(0xf, cd);
124 cd->min_delta_ticks = 0xf;
125
126
127 _wrmsr(DIVIL_MSR_REG(MFGPT_IRQ), 0, 0x100);
128
129
130 _wrmsr(DIVIL_MSR_REG(PIC_ZSEL_LOW), 0, 0x50000);
131
132
133 _rdmsr(DIVIL_MSR_REG(DIVIL_LBAR_MFGPT), &basehi, &mfgpt_base);
134
135 clockevents_register_device(cd);
136
137 setup_irq(CS5536_MFGPT_INTR, &irq5);
138 }
139
140
141
142
143
144
145 static u64 mfgpt_read(struct clocksource *cs)
146 {
147 unsigned long flags;
148 int count;
149 u32 jifs;
150 static int old_count;
151 static u32 old_jifs;
152
153 raw_spin_lock_irqsave(&mfgpt_lock, flags);
154
155
156
157
158
159
160
161
162
163
164
165
166
167 jifs = jiffies;
168
169 count = inw(MFGPT0_CNT);
170
171
172
173
174
175
176
177
178
179
180
181 if (count < old_count && jifs == old_jifs)
182 count = old_count;
183
184 old_count = count;
185 old_jifs = jifs;
186
187 raw_spin_unlock_irqrestore(&mfgpt_lock, flags);
188
189 return (u64) (jifs * COMPARE) + count;
190 }
191
192 static struct clocksource clocksource_mfgpt = {
193 .name = "mfgpt",
194 .rating = 120,
195 .read = mfgpt_read,
196 .mask = CLOCKSOURCE_MASK(32),
197 };
198
199 int __init init_mfgpt_clocksource(void)
200 {
201 if (num_possible_cpus() > 1)
202 return 0;
203
204 return clocksource_register_hz(&clocksource_mfgpt, MFGPT_TICK_RATE);
205 }
206
207 arch_initcall(init_mfgpt_clocksource);