Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 1 | /* |
Rob Clark | 8bb0daf | 2013-02-11 12:43:09 -0500 | [diff] [blame] | 2 | * drivers/gpu/drm/omapdrm/omap_irq.c |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2012 Texas Instruments |
| 5 | * Author: Rob Clark <rob.clark@linaro.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License version 2 as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "omap_drv.h" |
| 21 | |
| 22 | static DEFINE_SPINLOCK(list_lock); |
| 23 | |
| 24 | static 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 | /* call with list_lock and dispc runtime held */ |
| 31 | static 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 | |
Tomi Valkeinen | 8519c62 | 2014-11-28 14:34:16 +0200 | [diff] [blame] | 37 | assert_spin_locked(&list_lock); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 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(); /* flush posted write */ |
| 46 | } |
| 47 | |
Tomi Valkeinen | 6da9f89 | 2013-10-24 09:50:50 +0300 | [diff] [blame] | 48 | void __omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 49 | { |
| 50 | struct omap_drm_private *priv = dev->dev_private; |
| 51 | unsigned long flags; |
| 52 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 53 | spin_lock_irqsave(&list_lock, flags); |
| 54 | |
| 55 | if (!WARN_ON(irq->registered)) { |
| 56 | irq->registered = true; |
| 57 | list_add(&irq->node, &priv->irq_list); |
| 58 | omap_irq_update(dev); |
| 59 | } |
| 60 | |
| 61 | spin_unlock_irqrestore(&list_lock, flags); |
Tomi Valkeinen | 6da9f89 | 2013-10-24 09:50:50 +0300 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq) |
| 65 | { |
| 66 | dispc_runtime_get(); |
| 67 | |
| 68 | __omap_irq_register(dev, irq); |
| 69 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 70 | dispc_runtime_put(); |
| 71 | } |
| 72 | |
Tomi Valkeinen | 6da9f89 | 2013-10-24 09:50:50 +0300 | [diff] [blame] | 73 | void __omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 74 | { |
| 75 | unsigned long flags; |
| 76 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 77 | spin_lock_irqsave(&list_lock, flags); |
| 78 | |
| 79 | if (!WARN_ON(!irq->registered)) { |
| 80 | irq->registered = false; |
| 81 | list_del(&irq->node); |
| 82 | omap_irq_update(dev); |
| 83 | } |
| 84 | |
| 85 | spin_unlock_irqrestore(&list_lock, flags); |
Tomi Valkeinen | 6da9f89 | 2013-10-24 09:50:50 +0300 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq) |
| 89 | { |
| 90 | dispc_runtime_get(); |
| 91 | |
| 92 | __omap_irq_unregister(dev, irq); |
| 93 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 94 | dispc_runtime_put(); |
| 95 | } |
| 96 | |
| 97 | struct omap_irq_wait { |
| 98 | struct omap_drm_irq irq; |
| 99 | int count; |
| 100 | }; |
| 101 | |
| 102 | static DECLARE_WAIT_QUEUE_HEAD(wait_event); |
| 103 | |
| 104 | static void wait_irq(struct omap_drm_irq *irq, uint32_t irqstatus) |
| 105 | { |
| 106 | struct omap_irq_wait *wait = |
| 107 | container_of(irq, struct omap_irq_wait, irq); |
| 108 | wait->count--; |
| 109 | wake_up_all(&wait_event); |
| 110 | } |
| 111 | |
| 112 | struct omap_irq_wait * omap_irq_wait_init(struct drm_device *dev, |
| 113 | uint32_t irqmask, int count) |
| 114 | { |
| 115 | struct omap_irq_wait *wait = kzalloc(sizeof(*wait), GFP_KERNEL); |
| 116 | wait->irq.irq = wait_irq; |
| 117 | wait->irq.irqmask = irqmask; |
| 118 | wait->count = count; |
| 119 | omap_irq_register(dev, &wait->irq); |
| 120 | return wait; |
| 121 | } |
| 122 | |
| 123 | int omap_irq_wait(struct drm_device *dev, struct omap_irq_wait *wait, |
| 124 | unsigned long timeout) |
| 125 | { |
| 126 | int ret = wait_event_timeout(wait_event, (wait->count <= 0), timeout); |
| 127 | omap_irq_unregister(dev, &wait->irq); |
| 128 | kfree(wait); |
| 129 | if (ret == 0) |
| 130 | return -1; |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * enable_vblank - enable vblank interrupt events |
| 136 | * @dev: DRM device |
| 137 | * @crtc: which irq to enable |
| 138 | * |
| 139 | * Enable vblank interrupts for @crtc. If the device doesn't have |
| 140 | * a hardware vblank counter, this routine should be a no-op, since |
| 141 | * interrupts will have to stay on to keep the count accurate. |
| 142 | * |
| 143 | * RETURNS |
| 144 | * Zero on success, appropriate errno if the given @crtc's vblank |
| 145 | * interrupt cannot be enabled. |
| 146 | */ |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 147 | int omap_irq_enable_vblank(struct drm_device *dev, int crtc_id) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 148 | { |
| 149 | struct omap_drm_private *priv = dev->dev_private; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 150 | struct drm_crtc *crtc = priv->crtcs[crtc_id]; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 151 | unsigned long flags; |
| 152 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 153 | DBG("dev=%p, crtc=%d", dev, crtc_id); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 154 | |
| 155 | dispc_runtime_get(); |
| 156 | spin_lock_irqsave(&list_lock, flags); |
| 157 | priv->vblank_mask |= pipe2vbl(crtc); |
| 158 | omap_irq_update(dev); |
| 159 | spin_unlock_irqrestore(&list_lock, flags); |
| 160 | dispc_runtime_put(); |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * disable_vblank - disable vblank interrupt events |
| 167 | * @dev: DRM device |
| 168 | * @crtc: which irq to enable |
| 169 | * |
| 170 | * Disable vblank interrupts for @crtc. If the device doesn't have |
| 171 | * a hardware vblank counter, this routine should be a no-op, since |
| 172 | * interrupts will have to stay on to keep the count accurate. |
| 173 | */ |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 174 | void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 175 | { |
| 176 | struct omap_drm_private *priv = dev->dev_private; |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 177 | struct drm_crtc *crtc = priv->crtcs[crtc_id]; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 178 | unsigned long flags; |
| 179 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 180 | DBG("dev=%p, crtc=%d", dev, crtc_id); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 181 | |
| 182 | dispc_runtime_get(); |
| 183 | spin_lock_irqsave(&list_lock, flags); |
| 184 | priv->vblank_mask &= ~pipe2vbl(crtc); |
| 185 | omap_irq_update(dev); |
| 186 | spin_unlock_irqrestore(&list_lock, flags); |
| 187 | dispc_runtime_put(); |
| 188 | } |
| 189 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 190 | static irqreturn_t omap_irq_handler(int irq, void *arg) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 191 | { |
| 192 | struct drm_device *dev = (struct drm_device *) arg; |
| 193 | struct omap_drm_private *priv = dev->dev_private; |
| 194 | struct omap_drm_irq *handler, *n; |
| 195 | unsigned long flags; |
| 196 | unsigned int id; |
| 197 | u32 irqstatus; |
| 198 | |
| 199 | irqstatus = dispc_read_irqstatus(); |
| 200 | dispc_clear_irqstatus(irqstatus); |
| 201 | dispc_read_irqstatus(); /* flush posted write */ |
| 202 | |
| 203 | VERB("irqs: %08x", irqstatus); |
| 204 | |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 205 | for (id = 0; id < priv->num_crtcs; id++) { |
| 206 | struct drm_crtc *crtc = priv->crtcs[id]; |
| 207 | |
| 208 | if (irqstatus & pipe2vbl(crtc)) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 209 | drm_handle_vblank(dev, id); |
Archit Taneja | 0d8f371 | 2013-03-26 19:15:19 +0530 | [diff] [blame] | 210 | } |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 211 | |
| 212 | spin_lock_irqsave(&list_lock, flags); |
| 213 | list_for_each_entry_safe(handler, n, &priv->irq_list, node) { |
| 214 | if (handler->irqmask & irqstatus) { |
| 215 | spin_unlock_irqrestore(&list_lock, flags); |
| 216 | handler->irq(handler, handler->irqmask & irqstatus); |
| 217 | spin_lock_irqsave(&list_lock, flags); |
| 218 | } |
| 219 | } |
| 220 | spin_unlock_irqrestore(&list_lock, flags); |
| 221 | |
| 222 | return IRQ_HANDLED; |
| 223 | } |
| 224 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 225 | /* |
| 226 | * We need a special version, instead of just using drm_irq_install(), |
| 227 | * because we need to register the irq via omapdss. Once omapdss and |
| 228 | * omapdrm are merged together we can assign the dispc hwmod data to |
| 229 | * ourselves and drop these and just use drm_irq_{install,uninstall}() |
| 230 | */ |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 231 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 232 | int omap_drm_irq_install(struct drm_device *dev) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 233 | { |
| 234 | struct omap_drm_private *priv = dev->dev_private; |
| 235 | struct omap_drm_irq *error_handler = &priv->error_handler; |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 236 | int ret; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 237 | |
| 238 | INIT_LIST_HEAD(&priv->irq_list); |
| 239 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 240 | dispc_runtime_get(); |
| 241 | dispc_clear_irqstatus(0xffffffff); |
| 242 | dispc_runtime_put(); |
| 243 | |
| 244 | ret = dispc_request_irq(omap_irq_handler, dev); |
| 245 | if (ret < 0) |
| 246 | return ret; |
| 247 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 248 | error_handler->irq = omap_irq_error_handler; |
| 249 | error_handler->irqmask = DISPC_IRQ_OCP_ERR; |
| 250 | |
| 251 | /* for now ignore DISPC_IRQ_SYNC_LOST_DIGIT.. really I think |
| 252 | * we just need to ignore it while enabling tv-out |
| 253 | */ |
| 254 | error_handler->irqmask &= ~DISPC_IRQ_SYNC_LOST_DIGIT; |
| 255 | |
| 256 | omap_irq_register(dev, error_handler); |
| 257 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 258 | dev->irq_enabled = true; |
| 259 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 263 | void omap_drm_irq_uninstall(struct drm_device *dev) |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 264 | { |
| 265 | unsigned long irqflags; |
Ville Syrjälä | 4423843 | 2013-10-04 14:53:37 +0300 | [diff] [blame] | 266 | int i; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 267 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 268 | if (!dev->irq_enabled) |
| 269 | return; |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 270 | |
Laurent Pinchart | f13ab00 | 2015-01-25 22:06:45 +0200 | [diff] [blame^] | 271 | dev->irq_enabled = false; |
| 272 | |
| 273 | /* Wake up any waiters so they don't hang. */ |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 274 | if (dev->num_crtcs) { |
| 275 | spin_lock_irqsave(&dev->vbl_lock, irqflags); |
| 276 | for (i = 0; i < dev->num_crtcs; i++) { |
Daniel Vetter | 57ed0f7 | 2013-12-11 11:34:43 +0100 | [diff] [blame] | 277 | wake_up(&dev->vblank[i].queue); |
Ville Syrjälä | 5380e92 | 2013-10-04 14:53:36 +0300 | [diff] [blame] | 278 | dev->vblank[i].enabled = false; |
| 279 | dev->vblank[i].last = |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 280 | dev->driver->get_vblank_counter(dev, i); |
| 281 | } |
| 282 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); |
| 283 | } |
| 284 | |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 285 | dispc_free_irq(dev); |
Rob Clark | f5f9454 | 2012-12-04 13:59:12 -0600 | [diff] [blame] | 286 | } |