mdp5_mdss.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright (c) 2016, The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published by
  6. * the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/irqdomain.h>
  17. #include <linux/irq.h>
  18. #include "msm_drv.h"
  19. #include "mdp5_kms.h"
  20. /*
  21. * If needed, this can become more specific: something like struct mdp5_mdss,
  22. * which contains a 'struct msm_mdss base' member.
  23. */
  24. struct msm_mdss {
  25. struct drm_device *dev;
  26. void __iomem *mmio, *vbif;
  27. struct regulator *vdd;
  28. struct {
  29. volatile unsigned long enabled_mask;
  30. struct irq_domain *domain;
  31. } irqcontroller;
  32. };
  33. static inline void mdss_write(struct msm_mdss *mdss, u32 reg, u32 data)
  34. {
  35. msm_writel(data, mdss->mmio + reg);
  36. }
  37. static inline u32 mdss_read(struct msm_mdss *mdss, u32 reg)
  38. {
  39. return msm_readl(mdss->mmio + reg);
  40. }
  41. static irqreturn_t mdss_irq(int irq, void *arg)
  42. {
  43. struct msm_mdss *mdss = arg;
  44. u32 intr;
  45. intr = mdss_read(mdss, REG_MDSS_HW_INTR_STATUS);
  46. VERB("intr=%08x", intr);
  47. while (intr) {
  48. irq_hw_number_t hwirq = fls(intr) - 1;
  49. generic_handle_irq(irq_find_mapping(
  50. mdss->irqcontroller.domain, hwirq));
  51. intr &= ~(1 << hwirq);
  52. }
  53. return IRQ_HANDLED;
  54. }
  55. /*
  56. * interrupt-controller implementation, so sub-blocks (MDP/HDMI/eDP/DSI/etc)
  57. * can register to get their irq's delivered
  58. */
  59. #define VALID_IRQS (MDSS_HW_INTR_STATUS_INTR_MDP | \
  60. MDSS_HW_INTR_STATUS_INTR_DSI0 | \
  61. MDSS_HW_INTR_STATUS_INTR_DSI1 | \
  62. MDSS_HW_INTR_STATUS_INTR_HDMI | \
  63. MDSS_HW_INTR_STATUS_INTR_EDP)
  64. static void mdss_hw_mask_irq(struct irq_data *irqd)
  65. {
  66. struct msm_mdss *mdss = irq_data_get_irq_chip_data(irqd);
  67. smp_mb__before_atomic();
  68. clear_bit(irqd->hwirq, &mdss->irqcontroller.enabled_mask);
  69. smp_mb__after_atomic();
  70. }
  71. static void mdss_hw_unmask_irq(struct irq_data *irqd)
  72. {
  73. struct msm_mdss *mdss = irq_data_get_irq_chip_data(irqd);
  74. smp_mb__before_atomic();
  75. set_bit(irqd->hwirq, &mdss->irqcontroller.enabled_mask);
  76. smp_mb__after_atomic();
  77. }
  78. static struct irq_chip mdss_hw_irq_chip = {
  79. .name = "mdss",
  80. .irq_mask = mdss_hw_mask_irq,
  81. .irq_unmask = mdss_hw_unmask_irq,
  82. };
  83. static int mdss_hw_irqdomain_map(struct irq_domain *d, unsigned int irq,
  84. irq_hw_number_t hwirq)
  85. {
  86. struct msm_mdss *mdss = d->host_data;
  87. if (!(VALID_IRQS & (1 << hwirq)))
  88. return -EPERM;
  89. irq_set_chip_and_handler(irq, &mdss_hw_irq_chip, handle_level_irq);
  90. irq_set_chip_data(irq, mdss);
  91. return 0;
  92. }
  93. static struct irq_domain_ops mdss_hw_irqdomain_ops = {
  94. .map = mdss_hw_irqdomain_map,
  95. .xlate = irq_domain_xlate_onecell,
  96. };
  97. static int mdss_irq_domain_init(struct msm_mdss *mdss)
  98. {
  99. struct device *dev = mdss->dev->dev;
  100. struct irq_domain *d;
  101. d = irq_domain_add_linear(dev->of_node, 32, &mdss_hw_irqdomain_ops,
  102. mdss);
  103. if (!d) {
  104. dev_err(dev, "mdss irq domain add failed\n");
  105. return -ENXIO;
  106. }
  107. mdss->irqcontroller.enabled_mask = 0;
  108. mdss->irqcontroller.domain = d;
  109. return 0;
  110. }
  111. void msm_mdss_destroy(struct drm_device *dev)
  112. {
  113. struct msm_drm_private *priv = dev->dev_private;
  114. struct msm_mdss *mdss = priv->mdss;
  115. if (!mdss)
  116. return;
  117. irq_domain_remove(mdss->irqcontroller.domain);
  118. mdss->irqcontroller.domain = NULL;
  119. regulator_disable(mdss->vdd);
  120. pm_runtime_put_sync(dev->dev);
  121. pm_runtime_disable(dev->dev);
  122. }
  123. int msm_mdss_init(struct drm_device *dev)
  124. {
  125. struct platform_device *pdev = dev->platformdev;
  126. struct msm_drm_private *priv = dev->dev_private;
  127. struct msm_mdss *mdss;
  128. int ret;
  129. DBG("");
  130. if (!of_device_is_compatible(dev->dev->of_node, "qcom,mdss"))
  131. return 0;
  132. mdss = devm_kzalloc(dev->dev, sizeof(*mdss), GFP_KERNEL);
  133. if (!mdss) {
  134. ret = -ENOMEM;
  135. goto fail;
  136. }
  137. mdss->dev = dev;
  138. mdss->mmio = msm_ioremap(pdev, "mdss_phys", "MDSS");
  139. if (IS_ERR(mdss->mmio)) {
  140. ret = PTR_ERR(mdss->mmio);
  141. goto fail;
  142. }
  143. mdss->vbif = msm_ioremap(pdev, "vbif_phys", "VBIF");
  144. if (IS_ERR(mdss->vbif)) {
  145. ret = PTR_ERR(mdss->vbif);
  146. goto fail;
  147. }
  148. /* Regulator to enable GDSCs in downstream kernels */
  149. mdss->vdd = devm_regulator_get(dev->dev, "vdd");
  150. if (IS_ERR(mdss->vdd)) {
  151. ret = PTR_ERR(mdss->vdd);
  152. goto fail;
  153. }
  154. ret = regulator_enable(mdss->vdd);
  155. if (ret) {
  156. dev_err(dev->dev, "failed to enable regulator vdd: %d\n",
  157. ret);
  158. goto fail;
  159. }
  160. ret = devm_request_irq(dev->dev, platform_get_irq(pdev, 0),
  161. mdss_irq, 0, "mdss_isr", mdss);
  162. if (ret) {
  163. dev_err(dev->dev, "failed to init irq: %d\n", ret);
  164. goto fail_irq;
  165. }
  166. ret = mdss_irq_domain_init(mdss);
  167. if (ret) {
  168. dev_err(dev->dev, "failed to init sub-block irqs: %d\n", ret);
  169. goto fail_irq;
  170. }
  171. priv->mdss = mdss;
  172. pm_runtime_enable(dev->dev);
  173. /*
  174. * TODO: This is needed as the MDSS GDSC is only tied to MDSS's power
  175. * domain. Remove this once runtime PM is adapted for all the devices.
  176. */
  177. pm_runtime_get_sync(dev->dev);
  178. return 0;
  179. fail_irq:
  180. regulator_disable(mdss->vdd);
  181. fail:
  182. return ret;
  183. }