mdp4_irq.c 2.9 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2 3 4 5 6
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 */

7
#include <drm/drm_print.h>
S
Sam Ravnborg 已提交
8
#include <drm/drm_vblank.h>
9 10 11 12

#include "msm_drv.h"
#include "mdp4_kms.h"

13 14
void mdp4_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
		uint32_t old_irqmask)
15
{
16 17
	mdp4_write(to_mdp4_kms(mdp_kms), REG_MDP4_INTR_CLEAR,
		irqmask ^ (irqmask & old_irqmask));
R
Rob Clark 已提交
18
	mdp4_write(to_mdp4_kms(mdp_kms), REG_MDP4_INTR_ENABLE, irqmask);
19 20
}

R
Rob Clark 已提交
21
static void mdp4_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus)
22
{
23 24 25 26
	struct mdp4_kms *mdp4_kms = container_of(irq, struct mdp4_kms, error_handler);
	static DEFINE_RATELIMIT_STATE(rs, 5*HZ, 1);
	extern bool dumpstate;

R
Rob Clark 已提交
27
	DRM_ERROR_RATELIMITED("errors: %08x\n", irqstatus);
28 29 30 31 32

	if (dumpstate && __ratelimit(&rs)) {
		struct drm_printer p = drm_info_printer(mdp4_kms->dev->dev);
		drm_state_dump(mdp4_kms->dev, &p);
	}
33 34 35 36
}

void mdp4_irq_preinstall(struct msm_kms *kms)
{
R
Rob Clark 已提交
37
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
R
Rob Clark 已提交
38
	mdp4_enable(mdp4_kms);
39
	mdp4_write(mdp4_kms, REG_MDP4_INTR_CLEAR, 0xffffffff);
R
Rob Clark 已提交
40 41
	mdp4_write(mdp4_kms, REG_MDP4_INTR_ENABLE, 0x00000000);
	mdp4_disable(mdp4_kms);
42 43 44 45
}

int mdp4_irq_postinstall(struct msm_kms *kms)
{
R
Rob Clark 已提交
46 47 48
	struct mdp_kms *mdp_kms = to_mdp_kms(kms);
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(mdp_kms);
	struct mdp_irq *error_handler = &mdp4_kms->error_handler;
49 50 51 52 53

	error_handler->irq = mdp4_irq_error_handler;
	error_handler->irqmask = MDP4_IRQ_PRIMARY_INTF_UDERRUN |
			MDP4_IRQ_EXTERNAL_INTF_UDERRUN;

R
Rob Clark 已提交
54
	mdp_irq_register(mdp_kms, error_handler);
55 56 57 58 59 60

	return 0;
}

void mdp4_irq_uninstall(struct msm_kms *kms)
{
R
Rob Clark 已提交
61
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));
R
Rob Clark 已提交
62
	mdp4_enable(mdp4_kms);
63
	mdp4_write(mdp4_kms, REG_MDP4_INTR_ENABLE, 0x00000000);
R
Rob Clark 已提交
64
	mdp4_disable(mdp4_kms);
65 66 67 68
}

irqreturn_t mdp4_irq(struct msm_kms *kms)
{
R
Rob Clark 已提交
69 70
	struct mdp_kms *mdp_kms = to_mdp_kms(kms);
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(mdp_kms);
71 72 73
	struct drm_device *dev = mdp4_kms->dev;
	struct msm_drm_private *priv = dev->dev_private;
	unsigned int id;
74
	uint32_t status, enable;
75

76 77
	enable = mdp4_read(mdp4_kms, REG_MDP4_INTR_ENABLE);
	status = mdp4_read(mdp4_kms, REG_MDP4_INTR_STATUS) & enable;
78 79 80 81
	mdp4_write(mdp4_kms, REG_MDP4_INTR_CLEAR, status);

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

82 83
	mdp_dispatch_irqs(mdp_kms, status);

84 85 86 87 88 89 90 91 92
	for (id = 0; id < priv->num_crtcs; id++)
		if (status & mdp4_crtc_vblank(priv->crtcs[id]))
			drm_handle_vblank(dev, id);

	return IRQ_HANDLED;
}

int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
{
93 94 95
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));

	mdp4_enable(mdp4_kms);
R
Rob Clark 已提交
96 97
	mdp_update_vblank_mask(to_mdp_kms(kms),
			mdp4_crtc_vblank(crtc), true);
98 99
	mdp4_disable(mdp4_kms);

100 101 102 103 104
	return 0;
}

void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
{
105 106 107
	struct mdp4_kms *mdp4_kms = to_mdp4_kms(to_mdp_kms(kms));

	mdp4_enable(mdp4_kms);
R
Rob Clark 已提交
108 109
	mdp_update_vblank_mask(to_mdp_kms(kms),
			mdp4_crtc_vblank(crtc), false);
110
	mdp4_disable(mdp4_kms);
111
}