Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 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 | |
| 19 | #include "msm_drv.h" |
| 20 | #include "mdp4_kms.h" |
| 21 | |
jilai wang | 29f034d | 2015-08-05 15:33:29 -0400 | [diff] [blame] | 22 | void mdp4_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask, |
| 23 | uint32_t old_irqmask) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 24 | { |
jilai wang | 29f034d | 2015-08-05 15:33:29 -0400 | [diff] [blame] | 25 | mdp4_write(to_mdp4_kms(mdp_kms), REG_MDP4_INTR_CLEAR, |
| 26 | irqmask ^ (irqmask & old_irqmask)); |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 27 | mdp4_write(to_mdp4_kms(mdp_kms), REG_MDP4_INTR_ENABLE, irqmask); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 28 | } |
| 29 | |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 30 | static void mdp4_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus) |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 31 | { |
| 32 | DRM_ERROR("errors: %08x\n", irqstatus); |
| 33 | } |
| 34 | |
| 35 | void mdp4_irq_preinstall(struct msm_kms *kms) |
| 36 | { |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 37 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms)); |
Rob Clark | aa80a4a | 2015-03-02 16:19:06 -0500 | [diff] [blame] | 38 | mdp4_enable(mdp4_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 39 | mdp4_write(mdp4_kms, REG_MDP4_INTR_CLEAR, 0xffffffff); |
Rob Clark | aa80a4a | 2015-03-02 16:19:06 -0500 | [diff] [blame] | 40 | mdp4_write(mdp4_kms, REG_MDP4_INTR_ENABLE, 0x00000000); |
| 41 | mdp4_disable(mdp4_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | int mdp4_irq_postinstall(struct msm_kms *kms) |
| 45 | { |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 46 | struct mdp_kms *mdp_kms = to_mdp_kms(kms); |
| 47 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(mdp_kms); |
| 48 | struct mdp_irq *error_handler = &mdp4_kms->error_handler; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 49 | |
| 50 | error_handler->irq = mdp4_irq_error_handler; |
| 51 | error_handler->irqmask = MDP4_IRQ_PRIMARY_INTF_UDERRUN | |
| 52 | MDP4_IRQ_EXTERNAL_INTF_UDERRUN; |
| 53 | |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 54 | mdp_irq_register(mdp_kms, error_handler); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | void mdp4_irq_uninstall(struct msm_kms *kms) |
| 60 | { |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 61 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms)); |
Rob Clark | aa80a4a | 2015-03-02 16:19:06 -0500 | [diff] [blame] | 62 | mdp4_enable(mdp4_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 63 | mdp4_write(mdp4_kms, REG_MDP4_INTR_ENABLE, 0x00000000); |
Rob Clark | aa80a4a | 2015-03-02 16:19:06 -0500 | [diff] [blame] | 64 | mdp4_disable(mdp4_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | irqreturn_t mdp4_irq(struct msm_kms *kms) |
| 68 | { |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 69 | struct mdp_kms *mdp_kms = to_mdp_kms(kms); |
| 70 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(mdp_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 71 | struct drm_device *dev = mdp4_kms->dev; |
| 72 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 73 | unsigned int id; |
jilai wang | 29f034d | 2015-08-05 15:33:29 -0400 | [diff] [blame] | 74 | uint32_t status, enable; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 75 | |
jilai wang | 29f034d | 2015-08-05 15:33:29 -0400 | [diff] [blame] | 76 | enable = mdp4_read(mdp4_kms, REG_MDP4_INTR_ENABLE); |
| 77 | status = mdp4_read(mdp4_kms, REG_MDP4_INTR_STATUS) & enable; |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 78 | mdp4_write(mdp4_kms, REG_MDP4_INTR_CLEAR, status); |
| 79 | |
| 80 | VERB("status=%08x", status); |
| 81 | |
Rob Clark | 7d8d9f6 | 2014-04-22 12:27:28 -0400 | [diff] [blame] | 82 | mdp_dispatch_irqs(mdp_kms, status); |
| 83 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 84 | for (id = 0; id < priv->num_crtcs; id++) |
| 85 | if (status & mdp4_crtc_vblank(priv->crtcs[id])) |
| 86 | drm_handle_vblank(dev, id); |
| 87 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 88 | return IRQ_HANDLED; |
| 89 | } |
| 90 | |
| 91 | int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) |
| 92 | { |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 93 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms)); |
| 94 | |
| 95 | mdp4_enable(mdp4_kms); |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 96 | mdp_update_vblank_mask(to_mdp_kms(kms), |
| 97 | mdp4_crtc_vblank(crtc), true); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 98 | mdp4_disable(mdp4_kms); |
| 99 | |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc) |
| 104 | { |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 105 | struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms)); |
| 106 | |
| 107 | mdp4_enable(mdp4_kms); |
Rob Clark | 9e0efa6 | 2013-11-30 17:24:22 -0500 | [diff] [blame] | 108 | mdp_update_vblank_mask(to_mdp_kms(kms), |
| 109 | mdp4_crtc_vblank(crtc), false); |
Hai Li | 78b1d47 | 2015-07-27 13:49:45 -0400 | [diff] [blame] | 110 | mdp4_disable(mdp4_kms); |
Rob Clark | c8afe68 | 2013-06-26 12:44:06 -0400 | [diff] [blame] | 111 | } |