omap_irq.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. #include "omap_drv.h"
  20. static DEFINE_SPINLOCK(list_lock);
  21. static void omap_irq_error_handler(struct omap_drm_irq *irq,
  22. uint32_t irqstatus)
  23. {
  24. DRM_ERROR("errors: %08x\n", irqstatus);
  25. }
  26. /* call with list_lock and dispc runtime held */
  27. static void omap_irq_update(struct drm_device *dev)
  28. {
  29. struct omap_drm_private *priv = dev->dev_private;
  30. struct omap_drm_irq *irq;
  31. uint32_t irqmask = priv->vblank_mask;
  32. assert_spin_locked(&list_lock);
  33. list_for_each_entry(irq, &priv->irq_list, node)
  34. irqmask |= irq->irqmask;
  35. DBG("irqmask=%08x", irqmask);
  36. dispc_write_irqenable(irqmask);
  37. dispc_read_irqenable(); /* flush posted write */
  38. }
  39. void __omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq)
  40. {
  41. struct omap_drm_private *priv = dev->dev_private;
  42. unsigned long flags;
  43. spin_lock_irqsave(&list_lock, flags);
  44. if (!WARN_ON(irq->registered)) {
  45. irq->registered = true;
  46. list_add(&irq->node, &priv->irq_list);
  47. omap_irq_update(dev);
  48. }
  49. spin_unlock_irqrestore(&list_lock, flags);
  50. }
  51. void omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq)
  52. {
  53. dispc_runtime_get();
  54. __omap_irq_register(dev, irq);
  55. dispc_runtime_put();
  56. }
  57. void __omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq)
  58. {
  59. unsigned long flags;
  60. spin_lock_irqsave(&list_lock, flags);
  61. if (!WARN_ON(!irq->registered)) {
  62. irq->registered = false;
  63. list_del(&irq->node);
  64. omap_irq_update(dev);
  65. }
  66. spin_unlock_irqrestore(&list_lock, flags);
  67. }
  68. void omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq)
  69. {
  70. dispc_runtime_get();
  71. __omap_irq_unregister(dev, irq);
  72. dispc_runtime_put();
  73. }
  74. struct omap_irq_wait {
  75. struct omap_drm_irq irq;
  76. int count;
  77. };
  78. static DECLARE_WAIT_QUEUE_HEAD(wait_event);
  79. static void wait_irq(struct omap_drm_irq *irq, uint32_t irqstatus)
  80. {
  81. struct omap_irq_wait *wait =
  82. container_of(irq, struct omap_irq_wait, irq);
  83. wait->count--;
  84. wake_up_all(&wait_event);
  85. }
  86. struct omap_irq_wait * omap_irq_wait_init(struct drm_device *dev,
  87. uint32_t irqmask, int count)
  88. {
  89. struct omap_irq_wait *wait = kzalloc(sizeof(*wait), GFP_KERNEL);
  90. wait->irq.irq = wait_irq;
  91. wait->irq.irqmask = irqmask;
  92. wait->count = count;
  93. omap_irq_register(dev, &wait->irq);
  94. return wait;
  95. }
  96. int omap_irq_wait(struct drm_device *dev, struct omap_irq_wait *wait,
  97. unsigned long timeout)
  98. {
  99. int ret = wait_event_timeout(wait_event, (wait->count <= 0), timeout);
  100. omap_irq_unregister(dev, &wait->irq);
  101. kfree(wait);
  102. if (ret == 0)
  103. return -1;
  104. return 0;
  105. }
  106. /**
  107. * enable_vblank - enable vblank interrupt events
  108. * @dev: DRM device
  109. * @pipe: which irq to enable
  110. *
  111. * Enable vblank interrupts for @crtc. If the device doesn't have
  112. * a hardware vblank counter, this routine should be a no-op, since
  113. * interrupts will have to stay on to keep the count accurate.
  114. *
  115. * RETURNS
  116. * Zero on success, appropriate errno if the given @crtc's vblank
  117. * interrupt cannot be enabled.
  118. */
  119. int omap_irq_enable_vblank(struct drm_device *dev, unsigned int pipe)
  120. {
  121. struct omap_drm_private *priv = dev->dev_private;
  122. struct drm_crtc *crtc = priv->crtcs[pipe];
  123. unsigned long flags;
  124. DBG("dev=%p, crtc=%u", dev, pipe);
  125. spin_lock_irqsave(&list_lock, flags);
  126. priv->vblank_mask |= pipe2vbl(crtc);
  127. omap_irq_update(dev);
  128. spin_unlock_irqrestore(&list_lock, flags);
  129. return 0;
  130. }
  131. /**
  132. * disable_vblank - disable vblank interrupt events
  133. * @dev: DRM device
  134. * @pipe: which irq to enable
  135. *
  136. * Disable vblank interrupts for @crtc. If the device doesn't have
  137. * a hardware vblank counter, this routine should be a no-op, since
  138. * interrupts will have to stay on to keep the count accurate.
  139. */
  140. void omap_irq_disable_vblank(struct drm_device *dev, unsigned int pipe)
  141. {
  142. struct omap_drm_private *priv = dev->dev_private;
  143. struct drm_crtc *crtc = priv->crtcs[pipe];
  144. unsigned long flags;
  145. DBG("dev=%p, crtc=%u", dev, pipe);
  146. spin_lock_irqsave(&list_lock, flags);
  147. priv->vblank_mask &= ~pipe2vbl(crtc);
  148. omap_irq_update(dev);
  149. spin_unlock_irqrestore(&list_lock, flags);
  150. }
  151. static irqreturn_t omap_irq_handler(int irq, void *arg)
  152. {
  153. struct drm_device *dev = (struct drm_device *) arg;
  154. struct omap_drm_private *priv = dev->dev_private;
  155. struct omap_drm_irq *handler, *n;
  156. unsigned long flags;
  157. unsigned int id;
  158. u32 irqstatus;
  159. irqstatus = dispc_read_irqstatus();
  160. dispc_clear_irqstatus(irqstatus);
  161. dispc_read_irqstatus(); /* flush posted write */
  162. VERB("irqs: %08x", irqstatus);
  163. for (id = 0; id < priv->num_crtcs; id++) {
  164. struct drm_crtc *crtc = priv->crtcs[id];
  165. if (irqstatus & pipe2vbl(crtc))
  166. drm_handle_vblank(dev, id);
  167. }
  168. spin_lock_irqsave(&list_lock, flags);
  169. list_for_each_entry_safe(handler, n, &priv->irq_list, node) {
  170. if (handler->irqmask & irqstatus) {
  171. spin_unlock_irqrestore(&list_lock, flags);
  172. handler->irq(handler, handler->irqmask & irqstatus);
  173. spin_lock_irqsave(&list_lock, flags);
  174. }
  175. }
  176. spin_unlock_irqrestore(&list_lock, flags);
  177. return IRQ_HANDLED;
  178. }
  179. /*
  180. * We need a special version, instead of just using drm_irq_install(),
  181. * because we need to register the irq via omapdss. Once omapdss and
  182. * omapdrm are merged together we can assign the dispc hwmod data to
  183. * ourselves and drop these and just use drm_irq_{install,uninstall}()
  184. */
  185. int omap_drm_irq_install(struct drm_device *dev)
  186. {
  187. struct omap_drm_private *priv = dev->dev_private;
  188. struct omap_drm_irq *error_handler = &priv->error_handler;
  189. int ret;
  190. INIT_LIST_HEAD(&priv->irq_list);
  191. dispc_runtime_get();
  192. dispc_clear_irqstatus(0xffffffff);
  193. dispc_runtime_put();
  194. ret = dispc_request_irq(omap_irq_handler, dev);
  195. if (ret < 0)
  196. return ret;
  197. error_handler->irq = omap_irq_error_handler;
  198. error_handler->irqmask = DISPC_IRQ_OCP_ERR;
  199. /* for now ignore DISPC_IRQ_SYNC_LOST_DIGIT.. really I think
  200. * we just need to ignore it while enabling tv-out
  201. */
  202. error_handler->irqmask &= ~DISPC_IRQ_SYNC_LOST_DIGIT;
  203. omap_irq_register(dev, error_handler);
  204. dev->irq_enabled = true;
  205. return 0;
  206. }
  207. void omap_drm_irq_uninstall(struct drm_device *dev)
  208. {
  209. unsigned long irqflags;
  210. int i;
  211. if (!dev->irq_enabled)
  212. return;
  213. dev->irq_enabled = false;
  214. /* Wake up any waiters so they don't hang. */
  215. if (dev->num_crtcs) {
  216. spin_lock_irqsave(&dev->vbl_lock, irqflags);
  217. for (i = 0; i < dev->num_crtcs; i++) {
  218. wake_up(&dev->vblank[i].queue);
  219. dev->vblank[i].enabled = false;
  220. dev->vblank[i].last =
  221. dev->driver->get_vblank_counter(dev, i);
  222. }
  223. spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
  224. }
  225. dispc_free_irq(dev);
  226. }