1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "omap_drv.h"
21
22static DEFINE_SPINLOCK(list_lock);
23
24static void omap_irq_error_handler(struct omap_drm_irq *irq,
25 uint32_t irqstatus)
26{
27 DRM_ERROR("errors: %08x\n", irqstatus);
28}
29
30
31static void omap_irq_update(struct drm_device *dev)
32{
33 struct omap_drm_private *priv = dev->dev_private;
34 struct omap_drm_irq *irq;
35 uint32_t irqmask = priv->vblank_mask;
36
37 BUG_ON(!spin_is_locked(&list_lock));
38
39 list_for_each_entry(irq, &priv->irq_list, node)
40 irqmask |= irq->irqmask;
41
42 DBG("irqmask=%08x", irqmask);
43
44 dispc_write_irqenable(irqmask);
45 dispc_read_irqenable();
46}
47
48void omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq)
49{
50 struct omap_drm_private *priv = dev->dev_private;
51 unsigned long flags;
52
53 dispc_runtime_get();
54 spin_lock_irqsave(&list_lock, flags);
55
56 if (!WARN_ON(irq->registered)) {
57 irq->registered = true;
58 list_add(&irq->node, &priv->irq_list);
59 omap_irq_update(dev);
60 }
61
62 spin_unlock_irqrestore(&list_lock, flags);
63 dispc_runtime_put();
64}
65
66void omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq)
67{
68 unsigned long flags;
69
70 dispc_runtime_get();
71 spin_lock_irqsave(&list_lock, flags);
72
73 if (!WARN_ON(!irq->registered)) {
74 irq->registered = false;
75 list_del(&irq->node);
76 omap_irq_update(dev);
77 }
78
79 spin_unlock_irqrestore(&list_lock, flags);
80 dispc_runtime_put();
81}
82
83struct omap_irq_wait {
84 struct omap_drm_irq irq;
85 int count;
86};
87
88static DECLARE_WAIT_QUEUE_HEAD(wait_event);
89
90static void wait_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
91{
92 struct omap_irq_wait *wait =
93 container_of(irq, struct omap_irq_wait, irq);
94 wait->count--;
95 wake_up_all(&wait_event);
96}
97
98struct omap_irq_wait * omap_irq_wait_init(struct drm_device *dev,
99 uint32_t irqmask, int count)
100{
101 struct omap_irq_wait *wait = kzalloc(sizeof(*wait), GFP_KERNEL);
102 wait->irq.irq = wait_irq;
103 wait->irq.irqmask = irqmask;
104 wait->count = count;
105 omap_irq_register(dev, &wait->irq);
106 return wait;
107}
108
109int omap_irq_wait(struct drm_device *dev, struct omap_irq_wait *wait,
110 unsigned long timeout)
111{
112 int ret = wait_event_timeout(wait_event, (wait->count <= 0), timeout);
113 omap_irq_unregister(dev, &wait->irq);
114 kfree(wait);
115 if (ret == 0)
116 return -1;
117 return 0;
118}
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133int omap_irq_enable_vblank(struct drm_device *dev, int crtc_id)
134{
135 struct omap_drm_private *priv = dev->dev_private;
136 struct drm_crtc *crtc = priv->crtcs[crtc_id];
137 unsigned long flags;
138
139 DBG("dev=%p, crtc=%d", dev, crtc_id);
140
141 dispc_runtime_get();
142 spin_lock_irqsave(&list_lock, flags);
143 priv->vblank_mask |= pipe2vbl(crtc);
144 omap_irq_update(dev);
145 spin_unlock_irqrestore(&list_lock, flags);
146 dispc_runtime_put();
147
148 return 0;
149}
150
151
152
153
154
155
156
157
158
159
160void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id)
161{
162 struct omap_drm_private *priv = dev->dev_private;
163 struct drm_crtc *crtc = priv->crtcs[crtc_id];
164 unsigned long flags;
165
166 DBG("dev=%p, crtc=%d", dev, crtc_id);
167
168 dispc_runtime_get();
169 spin_lock_irqsave(&list_lock, flags);
170 priv->vblank_mask &= ~pipe2vbl(crtc);
171 omap_irq_update(dev);
172 spin_unlock_irqrestore(&list_lock, flags);
173 dispc_runtime_put();
174}
175
176irqreturn_t omap_irq_handler(DRM_IRQ_ARGS)
177{
178 struct drm_device *dev = (struct drm_device *) arg;
179 struct omap_drm_private *priv = dev->dev_private;
180 struct omap_drm_irq *handler, *n;
181 unsigned long flags;
182 unsigned int id;
183 u32 irqstatus;
184
185 irqstatus = dispc_read_irqstatus();
186 dispc_clear_irqstatus(irqstatus);
187 dispc_read_irqstatus();
188
189 VERB("irqs: %08x", irqstatus);
190
191 for (id = 0; id < priv->num_crtcs; id++) {
192 struct drm_crtc *crtc = priv->crtcs[id];
193
194 if (irqstatus & pipe2vbl(crtc))
195 drm_handle_vblank(dev, id);
196 }
197
198 spin_lock_irqsave(&list_lock, flags);
199 list_for_each_entry_safe(handler, n, &priv->irq_list, node) {
200 if (handler->irqmask & irqstatus) {
201 spin_unlock_irqrestore(&list_lock, flags);
202 handler->irq(handler, handler->irqmask & irqstatus);
203 spin_lock_irqsave(&list_lock, flags);
204 }
205 }
206 spin_unlock_irqrestore(&list_lock, flags);
207
208 return IRQ_HANDLED;
209}
210
211void omap_irq_preinstall(struct drm_device *dev)
212{
213 DBG("dev=%p", dev);
214 dispc_runtime_get();
215 dispc_clear_irqstatus(0xffffffff);
216 dispc_runtime_put();
217}
218
219int omap_irq_postinstall(struct drm_device *dev)
220{
221 struct omap_drm_private *priv = dev->dev_private;
222 struct omap_drm_irq *error_handler = &priv->error_handler;
223
224 DBG("dev=%p", dev);
225
226 INIT_LIST_HEAD(&priv->irq_list);
227
228 error_handler->irq = omap_irq_error_handler;
229 error_handler->irqmask = DISPC_IRQ_OCP_ERR;
230
231
232
233
234 error_handler->irqmask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
235
236 omap_irq_register(dev, error_handler);
237
238 return 0;
239}
240
241void omap_irq_uninstall(struct drm_device *dev)
242{
243 DBG("dev=%p", dev);
244
245}
246
247
248
249
250
251
252
253
254int omap_drm_irq_install(struct drm_device *dev)
255{
256 int ret;
257
258 mutex_lock(&dev->struct_mutex);
259
260 if (dev->irq_enabled) {
261 mutex_unlock(&dev->struct_mutex);
262 return -EBUSY;
263 }
264 dev->irq_enabled = 1;
265 mutex_unlock(&dev->struct_mutex);
266
267
268 if (dev->driver->irq_preinstall)
269 dev->driver->irq_preinstall(dev);
270
271 ret = dispc_request_irq(dev->driver->irq_handler, dev);
272
273 if (ret < 0) {
274 mutex_lock(&dev->struct_mutex);
275 dev->irq_enabled = 0;
276 mutex_unlock(&dev->struct_mutex);
277 return ret;
278 }
279
280
281 if (dev->driver->irq_postinstall)
282 ret = dev->driver->irq_postinstall(dev);
283
284 if (ret < 0) {
285 mutex_lock(&dev->struct_mutex);
286 dev->irq_enabled = 0;
287 mutex_unlock(&dev->struct_mutex);
288 dispc_free_irq(dev);
289 }
290
291 return ret;
292}
293
294int omap_drm_irq_uninstall(struct drm_device *dev)
295{
296 unsigned long irqflags;
297 int irq_enabled, i;
298
299 mutex_lock(&dev->struct_mutex);
300 irq_enabled = dev->irq_enabled;
301 dev->irq_enabled = 0;
302 mutex_unlock(&dev->struct_mutex);
303
304
305
306
307 if (dev->num_crtcs) {
308 spin_lock_irqsave(&dev->vbl_lock, irqflags);
309 for (i = 0; i < dev->num_crtcs; i++) {
310 DRM_WAKEUP(&dev->vbl_queue[i]);
311 dev->vblank_enabled[i] = 0;
312 dev->last_vblank[i] =
313 dev->driver->get_vblank_counter(dev, i);
314 }
315 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
316 }
317
318 if (!irq_enabled)
319 return -EINVAL;
320
321 if (dev->driver->irq_uninstall)
322 dev->driver->irq_uninstall(dev);
323
324 dispc_free_irq(dev);
325
326 return 0;
327}
328