diff options
Diffstat (limited to 'drivers/gpu/drm/omapdrm/omap_irq.c')
| -rw-r--r-- | drivers/gpu/drm/omapdrm/omap_irq.c | 322 | 
1 files changed, 322 insertions, 0 deletions
| diff --git a/drivers/gpu/drm/omapdrm/omap_irq.c b/drivers/gpu/drm/omapdrm/omap_irq.c new file mode 100644 index 000000000000..e01303ee00c3 --- /dev/null +++ b/drivers/gpu/drm/omapdrm/omap_irq.c | |||
| @@ -0,0 +1,322 @@ | |||
| 1 | /* | ||
| 2 | * drivers/gpu/drm/omapdrm/omap_irq.c | ||
| 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 | |||
| 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(); /* flush posted write */ | ||
| 46 | } | ||
| 47 | |||
| 48 | void 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 | |||
| 66 | void 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 | |||
| 83 | struct omap_irq_wait { | ||
| 84 | struct omap_drm_irq irq; | ||
| 85 | int count; | ||
| 86 | }; | ||
| 87 | |||
| 88 | static DECLARE_WAIT_QUEUE_HEAD(wait_event); | ||
| 89 | |||
| 90 | static 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 | |||
| 98 | struct 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 | |||
| 109 | int 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 | * enable_vblank - enable vblank interrupt events | ||
| 122 | * @dev: DRM device | ||
| 123 | * @crtc: which irq to enable | ||
| 124 | * | ||
| 125 | * Enable vblank interrupts for @crtc. If the device doesn't have | ||
| 126 | * a hardware vblank counter, this routine should be a no-op, since | ||
| 127 | * interrupts will have to stay on to keep the count accurate. | ||
| 128 | * | ||
| 129 | * RETURNS | ||
| 130 | * Zero on success, appropriate errno if the given @crtc's vblank | ||
| 131 | * interrupt cannot be enabled. | ||
| 132 | */ | ||
| 133 | int omap_irq_enable_vblank(struct drm_device *dev, int crtc) | ||
| 134 | { | ||
| 135 | struct omap_drm_private *priv = dev->dev_private; | ||
| 136 | unsigned long flags; | ||
| 137 | |||
| 138 | DBG("dev=%p, crtc=%d", dev, crtc); | ||
| 139 | |||
| 140 | dispc_runtime_get(); | ||
| 141 | spin_lock_irqsave(&list_lock, flags); | ||
| 142 | priv->vblank_mask |= pipe2vbl(crtc); | ||
| 143 | omap_irq_update(dev); | ||
| 144 | spin_unlock_irqrestore(&list_lock, flags); | ||
| 145 | dispc_runtime_put(); | ||
| 146 | |||
| 147 | return 0; | ||
| 148 | } | ||
| 149 | |||
| 150 | /** | ||
| 151 | * disable_vblank - disable vblank interrupt events | ||
| 152 | * @dev: DRM device | ||
| 153 | * @crtc: which irq to enable | ||
| 154 | * | ||
| 155 | * Disable vblank interrupts for @crtc. If the device doesn't have | ||
| 156 | * a hardware vblank counter, this routine should be a no-op, since | ||
| 157 | * interrupts will have to stay on to keep the count accurate. | ||
| 158 | */ | ||
| 159 | void omap_irq_disable_vblank(struct drm_device *dev, int crtc) | ||
| 160 | { | ||
| 161 | struct omap_drm_private *priv = dev->dev_private; | ||
| 162 | unsigned long flags; | ||
| 163 | |||
| 164 | DBG("dev=%p, crtc=%d", dev, crtc); | ||
| 165 | |||
| 166 | dispc_runtime_get(); | ||
| 167 | spin_lock_irqsave(&list_lock, flags); | ||
| 168 | priv->vblank_mask &= ~pipe2vbl(crtc); | ||
| 169 | omap_irq_update(dev); | ||
| 170 | spin_unlock_irqrestore(&list_lock, flags); | ||
| 171 | dispc_runtime_put(); | ||
| 172 | } | ||
| 173 | |||
| 174 | irqreturn_t omap_irq_handler(DRM_IRQ_ARGS) | ||
| 175 | { | ||
| 176 | struct drm_device *dev = (struct drm_device *) arg; | ||
| 177 | struct omap_drm_private *priv = dev->dev_private; | ||
| 178 | struct omap_drm_irq *handler, *n; | ||
| 179 | unsigned long flags; | ||
| 180 | unsigned int id; | ||
| 181 | u32 irqstatus; | ||
| 182 | |||
| 183 | irqstatus = dispc_read_irqstatus(); | ||
| 184 | dispc_clear_irqstatus(irqstatus); | ||
| 185 | dispc_read_irqstatus(); /* flush posted write */ | ||
| 186 | |||
| 187 | VERB("irqs: %08x", irqstatus); | ||
| 188 | |||
| 189 | for (id = 0; id < priv->num_crtcs; id++) | ||
| 190 | if (irqstatus & pipe2vbl(id)) | ||
| 191 | drm_handle_vblank(dev, id); | ||
| 192 | |||
| 193 | spin_lock_irqsave(&list_lock, flags); | ||
| 194 | list_for_each_entry_safe(handler, n, &priv->irq_list, node) { | ||
| 195 | if (handler->irqmask & irqstatus) { | ||
| 196 | spin_unlock_irqrestore(&list_lock, flags); | ||
| 197 | handler->irq(handler, handler->irqmask & irqstatus); | ||
| 198 | spin_lock_irqsave(&list_lock, flags); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | spin_unlock_irqrestore(&list_lock, flags); | ||
| 202 | |||
| 203 | return IRQ_HANDLED; | ||
| 204 | } | ||
| 205 | |||
| 206 | void omap_irq_preinstall(struct drm_device *dev) | ||
| 207 | { | ||
| 208 | DBG("dev=%p", dev); | ||
| 209 | dispc_runtime_get(); | ||
| 210 | dispc_clear_irqstatus(0xffffffff); | ||
| 211 | dispc_runtime_put(); | ||
| 212 | } | ||
| 213 | |||
| 214 | int omap_irq_postinstall(struct drm_device *dev) | ||
| 215 | { | ||
| 216 | struct omap_drm_private *priv = dev->dev_private; | ||
| 217 | struct omap_drm_irq *error_handler = &priv->error_handler; | ||
| 218 | |||
| 219 | DBG("dev=%p", dev); | ||
| 220 | |||
| 221 | INIT_LIST_HEAD(&priv->irq_list); | ||
| 222 | |||
| 223 | error_handler->irq = omap_irq_error_handler; | ||
| 224 | error_handler->irqmask = DISPC_IRQ_OCP_ERR; | ||
| 225 | |||
| 226 | /* for now ignore DISPC_IRQ_SYNC_LOST_DIGIT.. really I think | ||
| 227 | * we just need to ignore it while enabling tv-out | ||
| 228 | */ | ||
| 229 | error_handler->irqmask &= ~DISPC_IRQ_SYNC_LOST_DIGIT; | ||
| 230 | |||
| 231 | omap_irq_register(dev, error_handler); | ||
| 232 | |||
| 233 | return 0; | ||
| 234 | } | ||
| 235 | |||
| 236 | void omap_irq_uninstall(struct drm_device *dev) | ||
| 237 | { | ||
| 238 | DBG("dev=%p", dev); | ||
| 239 | // TODO prolly need to call drm_irq_uninstall() somewhere too | ||
| 240 | } | ||
| 241 | |||
| 242 | /* | ||
| 243 | * We need a special version, instead of just using drm_irq_install(), | ||
| 244 | * because we need to register the irq via omapdss. Once omapdss and | ||
| 245 | * omapdrm are merged together we can assign the dispc hwmod data to | ||
| 246 | * ourselves and drop these and just use drm_irq_{install,uninstall}() | ||
| 247 | */ | ||
| 248 | |||
| 249 | int omap_drm_irq_install(struct drm_device *dev) | ||
| 250 | { | ||
| 251 | int ret; | ||
| 252 | |||
| 253 | mutex_lock(&dev->struct_mutex); | ||
| 254 | |||
| 255 | if (dev->irq_enabled) { | ||
| 256 | mutex_unlock(&dev->struct_mutex); | ||
| 257 | return -EBUSY; | ||
| 258 | } | ||
| 259 | dev->irq_enabled = 1; | ||
| 260 | mutex_unlock(&dev->struct_mutex); | ||
| 261 | |||
| 262 | /* Before installing handler */ | ||
| 263 | if (dev->driver->irq_preinstall) | ||
| 264 | dev->driver->irq_preinstall(dev); | ||
| 265 | |||
| 266 | ret = dispc_request_irq(dev->driver->irq_handler, dev); | ||
| 267 | |||
| 268 | if (ret < 0) { | ||
| 269 | mutex_lock(&dev->struct_mutex); | ||
| 270 | dev->irq_enabled = 0; | ||
| 271 | mutex_unlock(&dev->struct_mutex); | ||
| 272 | return ret; | ||
| 273 | } | ||
| 274 | |||
| 275 | /* After installing handler */ | ||
| 276 | if (dev->driver->irq_postinstall) | ||
| 277 | ret = dev->driver->irq_postinstall(dev); | ||
| 278 | |||
| 279 | if (ret < 0) { | ||
| 280 | mutex_lock(&dev->struct_mutex); | ||
| 281 | dev->irq_enabled = 0; | ||
| 282 | mutex_unlock(&dev->struct_mutex); | ||
| 283 | dispc_free_irq(dev); | ||
| 284 | } | ||
| 285 | |||
| 286 | return ret; | ||
| 287 | } | ||
| 288 | |||
| 289 | int omap_drm_irq_uninstall(struct drm_device *dev) | ||
| 290 | { | ||
| 291 | unsigned long irqflags; | ||
| 292 | int irq_enabled, i; | ||
| 293 | |||
| 294 | mutex_lock(&dev->struct_mutex); | ||
| 295 | irq_enabled = dev->irq_enabled; | ||
| 296 | dev->irq_enabled = 0; | ||
| 297 | mutex_unlock(&dev->struct_mutex); | ||
| 298 | |||
| 299 | /* | ||
| 300 | * Wake up any waiters so they don't hang. | ||
| 301 | */ | ||
| 302 | if (dev->num_crtcs) { | ||
| 303 | spin_lock_irqsave(&dev->vbl_lock, irqflags); | ||
| 304 | for (i = 0; i < dev->num_crtcs; i++) { | ||
| 305 | DRM_WAKEUP(&dev->vbl_queue[i]); | ||
| 306 | dev->vblank_enabled[i] = 0; | ||
| 307 | dev->last_vblank[i] = | ||
| 308 | dev->driver->get_vblank_counter(dev, i); | ||
| 309 | } | ||
| 310 | spin_unlock_irqrestore(&dev->vbl_lock, irqflags); | ||
| 311 | } | ||
| 312 | |||
| 313 | if (!irq_enabled) | ||
| 314 | return -EINVAL; | ||
| 315 | |||
| 316 | if (dev->driver->irq_uninstall) | ||
| 317 | dev->driver->irq_uninstall(dev); | ||
| 318 | |||
| 319 | dispc_free_irq(dev); | ||
| 320 | |||
| 321 | return 0; | ||
| 322 | } | ||
