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 18 #include <linux/irq.h> 19 20 #include <drm/drm_print.h> 21 22 #include "msm_drv.h" 23 #include "mdp5_kms.h" 24 25 void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask, 26 uint32_t old_irqmask) 27 { 28 mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_CLEAR, 29 irqmask ^ (irqmask & old_irqmask)); 30 mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_EN, irqmask); 31 } 32 33 static void mdp5_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus) 34 { 35 struct mdp5_kms *mdp5_kms = container_of(irq, struct mdp5_kms, error_handler); 36 static DEFINE_RATELIMIT_STATE(rs, 5*HZ, 1); 37 extern bool dumpstate; 38 39 DRM_ERROR_RATELIMITED("errors: %08x\n", irqstatus); 40 41 if (dumpstate && __ratelimit(&rs)) { 42 struct drm_printer p = drm_info_printer(mdp5_kms->dev->dev); 43 drm_state_dump(mdp5_kms->dev, &p); 44 if (mdp5_kms->smp) 45 mdp5_smp_dump(mdp5_kms->smp, &p); 46 } 47 } 48 49 void mdp5_irq_preinstall(struct msm_kms *kms) 50 { 51 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms)); 52 struct device *dev = &mdp5_kms->pdev->dev; 53 54 pm_runtime_get_sync(dev); 55 mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, 0xffffffff); 56 mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000); 57 pm_runtime_put_sync(dev); 58 } 59 60 int mdp5_irq_postinstall(struct msm_kms *kms) 61 { 62 struct mdp_kms *mdp_kms = to_mdp_kms(kms); 63 struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms); 64 struct device *dev = &mdp5_kms->pdev->dev; 65 struct mdp_irq *error_handler = &mdp5_kms->error_handler; 66 67 error_handler->irq = mdp5_irq_error_handler; 68 error_handler->irqmask = MDP5_IRQ_INTF0_UNDER_RUN | 69 MDP5_IRQ_INTF1_UNDER_RUN | 70 MDP5_IRQ_INTF2_UNDER_RUN | 71 MDP5_IRQ_INTF3_UNDER_RUN; 72 73 pm_runtime_get_sync(dev); 74 mdp_irq_register(mdp_kms, error_handler); 75 pm_runtime_put_sync(dev); 76 77 return 0; 78 } 79 80 void mdp5_irq_uninstall(struct msm_kms *kms) 81 { 82 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms)); 83 struct device *dev = &mdp5_kms->pdev->dev; 84 85 pm_runtime_get_sync(dev); 86 mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000); 87 pm_runtime_put_sync(dev); 88 } 89 90 irqreturn_t mdp5_irq(struct msm_kms *kms) 91 { 92 struct mdp_kms *mdp_kms = to_mdp_kms(kms); 93 struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms); 94 struct drm_device *dev = mdp5_kms->dev; 95 struct msm_drm_private *priv = dev->dev_private; 96 unsigned int id; 97 uint32_t status, enable; 98 99 enable = mdp5_read(mdp5_kms, REG_MDP5_INTR_EN); 100 status = mdp5_read(mdp5_kms, REG_MDP5_INTR_STATUS) & enable; 101 mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, status); 102 103 VERB("status=%08x", status); 104 105 mdp_dispatch_irqs(mdp_kms, status); 106 107 for (id = 0; id < priv->num_crtcs; id++) 108 if (status & mdp5_crtc_vblank(priv->crtcs[id])) 109 drm_handle_vblank(dev, id); 110 111 return IRQ_HANDLED; 112 } 113 114 int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) 115 { 116 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms)); 117 struct device *dev = &mdp5_kms->pdev->dev; 118 119 pm_runtime_get_sync(dev); 120 mdp_update_vblank_mask(to_mdp_kms(kms), 121 mdp5_crtc_vblank(crtc), true); 122 pm_runtime_put_sync(dev); 123 124 return 0; 125 } 126 127 void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) 128 { 129 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms)); 130 struct device *dev = &mdp5_kms->pdev->dev; 131 132 pm_runtime_get_sync(dev); 133 mdp_update_vblank_mask(to_mdp_kms(kms), 134 mdp5_crtc_vblank(crtc), false); 135 pm_runtime_put_sync(dev); 136 } 137