mdp5_irq.c 3.8 KB
Newer Older
R
Rob Clark 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

R
Rob Clark 已提交
18
#include <linux/irq.h>
R
Rob Clark 已提交
19

20 21
#include <drm/drm_print.h>

R
Rob Clark 已提交
22 23 24
#include "msm_drv.h"
#include "mdp5_kms.h"

25 26
void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
		uint32_t old_irqmask)
R
Rob Clark 已提交
27
{
28 29 30
	mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_CLEAR,
		   irqmask ^ (irqmask & old_irqmask));
	mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_EN, irqmask);
R
Rob Clark 已提交
31 32 33 34
}

static void mdp5_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus)
{
35 36 37 38
	struct mdp5_kms *mdp5_kms = container_of(irq, struct mdp5_kms, error_handler);
	static DEFINE_RATELIMIT_STATE(rs, 5*HZ, 1);
	extern bool dumpstate;

R
Rob Clark 已提交
39
	DRM_ERROR_RATELIMITED("errors: %08x\n", irqstatus);
40 41 42 43

	if (dumpstate && __ratelimit(&rs)) {
		struct drm_printer p = drm_info_printer(mdp5_kms->dev->dev);
		drm_state_dump(mdp5_kms->dev, &p);
44 45
		if (mdp5_kms->smp)
			mdp5_smp_dump(mdp5_kms->smp, &p);
46
	}
R
Rob Clark 已提交
47 48 49 50 51
}

void mdp5_irq_preinstall(struct msm_kms *kms)
{
	struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
52 53 54
	struct device *dev = &mdp5_kms->pdev->dev;

	pm_runtime_get_sync(dev);
55 56
	mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, 0xffffffff);
	mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000);
57
	pm_runtime_put_autosuspend(dev);
R
Rob Clark 已提交
58 59 60 61 62 63
}

int mdp5_irq_postinstall(struct msm_kms *kms)
{
	struct mdp_kms *mdp_kms = to_mdp_kms(kms);
	struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
64
	struct device *dev = &mdp5_kms->pdev->dev;
R
Rob Clark 已提交
65 66 67 68 69 70 71 72
	struct mdp_irq *error_handler = &mdp5_kms->error_handler;

	error_handler->irq = mdp5_irq_error_handler;
	error_handler->irqmask = MDP5_IRQ_INTF0_UNDER_RUN |
			MDP5_IRQ_INTF1_UNDER_RUN |
			MDP5_IRQ_INTF2_UNDER_RUN |
			MDP5_IRQ_INTF3_UNDER_RUN;

73
	pm_runtime_get_sync(dev);
R
Rob Clark 已提交
74
	mdp_irq_register(mdp_kms, error_handler);
75
	pm_runtime_put_autosuspend(dev);
R
Rob Clark 已提交
76 77 78 79 80 81 82

	return 0;
}

void mdp5_irq_uninstall(struct msm_kms *kms)
{
	struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
83 84 85
	struct device *dev = &mdp5_kms->pdev->dev;

	pm_runtime_get_sync(dev);
86
	mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000);
87
	pm_runtime_put_autosuspend(dev);
R
Rob Clark 已提交
88 89
}

90
irqreturn_t mdp5_irq(struct msm_kms *kms)
R
Rob Clark 已提交
91
{
92
	struct mdp_kms *mdp_kms = to_mdp_kms(kms);
R
Rob Clark 已提交
93 94 95 96
	struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
	struct drm_device *dev = mdp5_kms->dev;
	struct msm_drm_private *priv = dev->dev_private;
	unsigned int id;
97
	uint32_t status, enable;
R
Rob Clark 已提交
98

99 100 101
	enable = mdp5_read(mdp5_kms, REG_MDP5_INTR_EN);
	status = mdp5_read(mdp5_kms, REG_MDP5_INTR_STATUS) & enable;
	mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, status);
R
Rob Clark 已提交
102 103 104

	VERB("status=%08x", status);

105 106
	mdp_dispatch_irqs(mdp_kms, status);

R
Rob Clark 已提交
107 108 109 110 111 112 113 114 115
	for (id = 0; id < priv->num_crtcs; id++)
		if (status & mdp5_crtc_vblank(priv->crtcs[id]))
			drm_handle_vblank(dev, id);

	return IRQ_HANDLED;
}

int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
{
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);
R
Rob Clark 已提交
120 121
	mdp_update_vblank_mask(to_mdp_kms(kms),
			mdp5_crtc_vblank(crtc), true);
122
	pm_runtime_put_autosuspend(dev);
123

R
Rob Clark 已提交
124 125 126 127 128
	return 0;
}

void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
{
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);
R
Rob Clark 已提交
133 134
	mdp_update_vblank_mask(to_mdp_kms(kms),
			mdp5_crtc_vblank(crtc), false);
135
	pm_runtime_put_autosuspend(dev);
R
Rob Clark 已提交
136
}