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
);
45 /* if an mdp_irq's irqmask has changed, such as when mdp5 crtc<->encoder
46 * link changes, this must be called to figure out the new global irqmask
48 void mdp_irq_update(struct mdp_kms
*mdp_kms
)
51 spin_lock_irqsave(&list_lock
, flags
);
53 spin_unlock_irqrestore(&list_lock
, flags
);
56 void mdp_dispatch_irqs(struct mdp_kms
*mdp_kms
, uint32_t status
)
58 struct mdp_irq
*handler
, *n
;
61 spin_lock_irqsave(&list_lock
, flags
);
62 mdp_kms
->in_irq
= true;
63 list_for_each_entry_safe(handler
, n
, &mdp_kms
->irq_list
, node
) {
64 if (handler
->irqmask
& status
) {
65 spin_unlock_irqrestore(&list_lock
, flags
);
66 handler
->irq(handler
, handler
->irqmask
& status
);
67 spin_lock_irqsave(&list_lock
, flags
);
70 mdp_kms
->in_irq
= false;
72 spin_unlock_irqrestore(&list_lock
, flags
);
76 void mdp_update_vblank_mask(struct mdp_kms
*mdp_kms
, uint32_t mask
, bool enable
)
80 spin_lock_irqsave(&list_lock
, flags
);
82 mdp_kms
->vblank_mask
|= mask
;
84 mdp_kms
->vblank_mask
&= ~mask
;
86 spin_unlock_irqrestore(&list_lock
, flags
);
89 static void wait_irq(struct mdp_irq
*irq
, uint32_t irqstatus
)
91 struct mdp_irq_wait
*wait
=
92 container_of(irq
, struct mdp_irq_wait
, irq
);
94 wake_up_all(&wait_event
);
97 void mdp_irq_wait(struct mdp_kms
*mdp_kms
, uint32_t irqmask
)
99 struct mdp_irq_wait wait
= {
106 mdp_irq_register(mdp_kms
, &wait
.irq
);
107 wait_event_timeout(wait_event
, (wait
.count
<= 0),
108 msecs_to_jiffies(100));
109 mdp_irq_unregister(mdp_kms
, &wait
.irq
);
112 void mdp_irq_register(struct mdp_kms
*mdp_kms
, struct mdp_irq
*irq
)
115 bool needs_update
= false;
117 spin_lock_irqsave(&list_lock
, flags
);
119 if (!irq
->registered
) {
120 irq
->registered
= true;
121 list_add(&irq
->node
, &mdp_kms
->irq_list
);
122 needs_update
= !mdp_kms
->in_irq
;
125 spin_unlock_irqrestore(&list_lock
, flags
);
128 mdp_irq_update(mdp_kms
);
131 void mdp_irq_unregister(struct mdp_kms
*mdp_kms
, struct mdp_irq
*irq
)
134 bool needs_update
= false;
136 spin_lock_irqsave(&list_lock
, flags
);
138 if (irq
->registered
) {
139 irq
->registered
= false;
140 list_del(&irq
->node
);
141 needs_update
= !mdp_kms
->in_irq
;
144 spin_unlock_irqrestore(&list_lock
, flags
);
147 mdp_irq_update(mdp_kms
);