mdp5_irq.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  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.
  8. *
  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
  12. * more details.
  13. *
  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/>.
  16. */
  17. #include <linux/irqdomain.h>
  18. #include <linux/irq.h>
  19. #include "msm_drv.h"
  20. #include "mdp5_kms.h"
  21. void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
  22. uint32_t old_irqmask)
  23. {
  24. mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_MDP_INTR_CLEAR(0),
  25. irqmask ^ (irqmask & old_irqmask));
  26. mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_MDP_INTR_EN(0), irqmask);
  27. }
  28. static void mdp5_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus)
  29. {
  30. DRM_ERROR("errors: %08x\n", irqstatus);
  31. }
  32. void mdp5_irq_preinstall(struct msm_kms *kms)
  33. {
  34. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  35. mdp5_enable(mdp5_kms);
  36. mdp5_write(mdp5_kms, REG_MDP5_MDP_INTR_CLEAR(0), 0xffffffff);
  37. mdp5_write(mdp5_kms, REG_MDP5_MDP_INTR_EN(0), 0x00000000);
  38. mdp5_disable(mdp5_kms);
  39. }
  40. int mdp5_irq_postinstall(struct msm_kms *kms)
  41. {
  42. struct mdp_kms *mdp_kms = to_mdp_kms(kms);
  43. struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
  44. struct mdp_irq *error_handler = &mdp5_kms->error_handler;
  45. error_handler->irq = mdp5_irq_error_handler;
  46. error_handler->irqmask = MDP5_IRQ_INTF0_UNDER_RUN |
  47. MDP5_IRQ_INTF1_UNDER_RUN |
  48. MDP5_IRQ_INTF2_UNDER_RUN |
  49. MDP5_IRQ_INTF3_UNDER_RUN;
  50. mdp_irq_register(mdp_kms, error_handler);
  51. return 0;
  52. }
  53. void mdp5_irq_uninstall(struct msm_kms *kms)
  54. {
  55. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  56. mdp5_enable(mdp5_kms);
  57. mdp5_write(mdp5_kms, REG_MDP5_MDP_INTR_EN(0), 0x00000000);
  58. mdp5_disable(mdp5_kms);
  59. }
  60. static void mdp5_irq_mdp(struct mdp_kms *mdp_kms)
  61. {
  62. struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
  63. struct drm_device *dev = mdp5_kms->dev;
  64. struct msm_drm_private *priv = dev->dev_private;
  65. unsigned int id;
  66. uint32_t status, enable;
  67. enable = mdp5_read(mdp5_kms, REG_MDP5_MDP_INTR_EN(0));
  68. status = mdp5_read(mdp5_kms, REG_MDP5_MDP_INTR_STATUS(0)) & enable;
  69. mdp5_write(mdp5_kms, REG_MDP5_MDP_INTR_CLEAR(0), status);
  70. VERB("status=%08x", status);
  71. mdp_dispatch_irqs(mdp_kms, status);
  72. for (id = 0; id < priv->num_crtcs; id++)
  73. if (status & mdp5_crtc_vblank(priv->crtcs[id]))
  74. drm_handle_vblank(dev, id);
  75. }
  76. irqreturn_t mdp5_irq(struct msm_kms *kms)
  77. {
  78. struct mdp_kms *mdp_kms = to_mdp_kms(kms);
  79. struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
  80. uint32_t intr;
  81. intr = mdp5_read(mdp5_kms, REG_MDSS_HW_INTR_STATUS);
  82. VERB("intr=%08x", intr);
  83. if (intr & MDSS_HW_INTR_STATUS_INTR_MDP) {
  84. mdp5_irq_mdp(mdp_kms);
  85. intr &= ~MDSS_HW_INTR_STATUS_INTR_MDP;
  86. }
  87. while (intr) {
  88. irq_hw_number_t hwirq = fls(intr) - 1;
  89. generic_handle_irq(irq_find_mapping(
  90. mdp5_kms->irqcontroller.domain, hwirq));
  91. intr &= ~(1 << hwirq);
  92. }
  93. return IRQ_HANDLED;
  94. }
  95. int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
  96. {
  97. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  98. mdp5_enable(mdp5_kms);
  99. mdp_update_vblank_mask(to_mdp_kms(kms),
  100. mdp5_crtc_vblank(crtc), true);
  101. mdp5_disable(mdp5_kms);
  102. return 0;
  103. }
  104. void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
  105. {
  106. struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
  107. mdp5_enable(mdp5_kms);
  108. mdp_update_vblank_mask(to_mdp_kms(kms),
  109. mdp5_crtc_vblank(crtc), false);
  110. mdp5_disable(mdp5_kms);
  111. }
  112. /*
  113. * interrupt-controller implementation, so sub-blocks (hdmi/eDP/dsi/etc)
  114. * can register to get their irq's delivered
  115. */
  116. #define VALID_IRQS (MDSS_HW_INTR_STATUS_INTR_DSI0 | \
  117. MDSS_HW_INTR_STATUS_INTR_DSI1 | \
  118. MDSS_HW_INTR_STATUS_INTR_HDMI | \
  119. MDSS_HW_INTR_STATUS_INTR_EDP)
  120. static void mdp5_hw_mask_irq(struct irq_data *irqd)
  121. {
  122. struct mdp5_kms *mdp5_kms = irq_data_get_irq_chip_data(irqd);
  123. smp_mb__before_atomic();
  124. clear_bit(irqd->hwirq, &mdp5_kms->irqcontroller.enabled_mask);
  125. smp_mb__after_atomic();
  126. }
  127. static void mdp5_hw_unmask_irq(struct irq_data *irqd)
  128. {
  129. struct mdp5_kms *mdp5_kms = irq_data_get_irq_chip_data(irqd);
  130. smp_mb__before_atomic();
  131. set_bit(irqd->hwirq, &mdp5_kms->irqcontroller.enabled_mask);
  132. smp_mb__after_atomic();
  133. }
  134. static struct irq_chip mdp5_hw_irq_chip = {
  135. .name = "mdp5",
  136. .irq_mask = mdp5_hw_mask_irq,
  137. .irq_unmask = mdp5_hw_unmask_irq,
  138. };
  139. static int mdp5_hw_irqdomain_map(struct irq_domain *d,
  140. unsigned int irq, irq_hw_number_t hwirq)
  141. {
  142. struct mdp5_kms *mdp5_kms = d->host_data;
  143. if (!(VALID_IRQS & (1 << hwirq)))
  144. return -EPERM;
  145. irq_set_chip_and_handler(irq, &mdp5_hw_irq_chip, handle_level_irq);
  146. irq_set_chip_data(irq, mdp5_kms);
  147. return 0;
  148. }
  149. static struct irq_domain_ops mdp5_hw_irqdomain_ops = {
  150. .map = mdp5_hw_irqdomain_map,
  151. .xlate = irq_domain_xlate_onecell,
  152. };
  153. int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms)
  154. {
  155. struct device *dev = mdp5_kms->dev->dev;
  156. struct irq_domain *d;
  157. d = irq_domain_add_linear(dev->of_node, 32,
  158. &mdp5_hw_irqdomain_ops, mdp5_kms);
  159. if (!d) {
  160. dev_err(dev, "mdp5 irq domain add failed\n");
  161. return -ENXIO;
  162. }
  163. mdp5_kms->irqcontroller.enabled_mask = 0;
  164. mdp5_kms->irqcontroller.domain = d;
  165. return 0;
  166. }
  167. void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms)
  168. {
  169. if (mdp5_kms->irqcontroller.domain) {
  170. irq_domain_remove(mdp5_kms->irqcontroller.domain);
  171. mdp5_kms->irqcontroller.domain = NULL;
  172. }
  173. }