2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
28 static DECLARE_WAIT_QUEUE_HEAD(wait_event);
30 static DEFINE_SPINLOCK(list_lock);
32 static void update_irq(struct mdp_kms *mdp_kms)
35 uint32_t irqmask = mdp_kms->vblank_mask;
37 assert_spin_locked(&list_lock);
39 list_for_each_entry(irq, &mdp_kms->irq_list, node)
40 irqmask |= irq->irqmask;
42 mdp_kms->funcs->set_irqmask(mdp_kms, irqmask, mdp_kms->cur_irq_mask);
43 mdp_kms->cur_irq_mask = irqmask;
46 /* if an mdp_irq's irqmask has changed, such as when mdp5 crtc<->encoder
47 * link changes, this must be called to figure out the new global irqmask
49 void mdp_irq_update(struct mdp_kms *mdp_kms)
52 spin_lock_irqsave(&list_lock, flags);
54 spin_unlock_irqrestore(&list_lock, flags);
57 void mdp_dispatch_irqs(struct mdp_kms *mdp_kms, uint32_t status)
59 struct mdp_irq *handler, *n;
62 spin_lock_irqsave(&list_lock, flags);
63 mdp_kms->in_irq = true;
64 list_for_each_entry_safe(handler, n, &mdp_kms->irq_list, node) {
65 if (handler->irqmask & status) {
66 spin_unlock_irqrestore(&list_lock, flags);
67 handler->irq(handler, handler->irqmask & status);
68 spin_lock_irqsave(&list_lock, flags);
71 mdp_kms->in_irq = false;
73 spin_unlock_irqrestore(&list_lock, flags);
77 void mdp_update_vblank_mask(struct mdp_kms *mdp_kms, uint32_t mask, bool enable)
81 spin_lock_irqsave(&list_lock, flags);
83 mdp_kms->vblank_mask |= mask;
85 mdp_kms->vblank_mask &= ~mask;
87 spin_unlock_irqrestore(&list_lock, flags);
90 static void wait_irq(struct mdp_irq *irq, uint32_t irqstatus)
92 struct mdp_irq_wait *wait =
93 container_of(irq, struct mdp_irq_wait, irq);
95 wake_up_all(&wait_event);
98 void mdp_irq_wait(struct mdp_kms *mdp_kms, uint32_t irqmask)
100 struct mdp_irq_wait wait = {
107 mdp_irq_register(mdp_kms, &wait.irq);
108 wait_event_timeout(wait_event, (wait.count <= 0),
109 msecs_to_jiffies(100));
110 mdp_irq_unregister(mdp_kms, &wait.irq);
113 void mdp_irq_register(struct mdp_kms *mdp_kms, struct mdp_irq *irq)
116 bool needs_update = false;
118 spin_lock_irqsave(&list_lock, flags);
120 if (!irq->registered) {
121 irq->registered = true;
122 list_add(&irq->node, &mdp_kms->irq_list);
123 needs_update = !mdp_kms->in_irq;
126 spin_unlock_irqrestore(&list_lock, flags);
129 mdp_irq_update(mdp_kms);
132 void mdp_irq_unregister(struct mdp_kms *mdp_kms, struct mdp_irq *irq)
135 bool needs_update = false;
137 spin_lock_irqsave(&list_lock, flags);
139 if (irq->registered) {
140 irq->registered = false;
141 list_del(&irq->node);
142 needs_update = !mdp_kms->in_irq;
145 spin_unlock_irqrestore(&list_lock, flags);
148 mdp_irq_update(mdp_kms);