Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / msm / disp / mdp5 / mdp5_irq.c
blob9b4c8d92ff32060f6715fd8bcdb96e3725b154fd
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
5 */
7 #include <linux/irq.h>
9 #include <drm/drm_print.h>
10 #include <drm/drm_vblank.h>
12 #include "msm_drv.h"
13 #include "mdp5_kms.h"
15 void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
16 uint32_t old_irqmask)
18 mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_CLEAR,
19 irqmask ^ (irqmask & old_irqmask));
20 mdp5_write(to_mdp5_kms(mdp_kms), REG_MDP5_INTR_EN, irqmask);
23 static void mdp5_irq_error_handler(struct mdp_irq *irq, uint32_t irqstatus)
25 struct mdp5_kms *mdp5_kms = container_of(irq, struct mdp5_kms, error_handler);
26 static DEFINE_RATELIMIT_STATE(rs, 5*HZ, 1);
27 extern bool dumpstate;
29 DRM_ERROR_RATELIMITED("errors: %08x\n", irqstatus);
31 if (dumpstate && __ratelimit(&rs)) {
32 struct drm_printer p = drm_info_printer(mdp5_kms->dev->dev);
33 drm_state_dump(mdp5_kms->dev, &p);
34 if (mdp5_kms->smp)
35 mdp5_smp_dump(mdp5_kms->smp, &p);
39 void mdp5_irq_preinstall(struct msm_kms *kms)
41 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
42 struct device *dev = &mdp5_kms->pdev->dev;
44 pm_runtime_get_sync(dev);
45 mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, 0xffffffff);
46 mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000);
47 pm_runtime_put_sync(dev);
50 int mdp5_irq_postinstall(struct msm_kms *kms)
52 struct mdp_kms *mdp_kms = to_mdp_kms(kms);
53 struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
54 struct device *dev = &mdp5_kms->pdev->dev;
55 struct mdp_irq *error_handler = &mdp5_kms->error_handler;
57 error_handler->irq = mdp5_irq_error_handler;
58 error_handler->irqmask = MDP5_IRQ_INTF0_UNDER_RUN |
59 MDP5_IRQ_INTF1_UNDER_RUN |
60 MDP5_IRQ_INTF2_UNDER_RUN |
61 MDP5_IRQ_INTF3_UNDER_RUN;
63 pm_runtime_get_sync(dev);
64 mdp_irq_register(mdp_kms, error_handler);
65 pm_runtime_put_sync(dev);
67 return 0;
70 void mdp5_irq_uninstall(struct msm_kms *kms)
72 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
73 struct device *dev = &mdp5_kms->pdev->dev;
75 pm_runtime_get_sync(dev);
76 mdp5_write(mdp5_kms, REG_MDP5_INTR_EN, 0x00000000);
77 pm_runtime_put_sync(dev);
80 irqreturn_t mdp5_irq(struct msm_kms *kms)
82 struct mdp_kms *mdp_kms = to_mdp_kms(kms);
83 struct mdp5_kms *mdp5_kms = to_mdp5_kms(mdp_kms);
84 struct drm_device *dev = mdp5_kms->dev;
85 struct msm_drm_private *priv = dev->dev_private;
86 unsigned int id;
87 uint32_t status, enable;
89 enable = mdp5_read(mdp5_kms, REG_MDP5_INTR_EN);
90 status = mdp5_read(mdp5_kms, REG_MDP5_INTR_STATUS) & enable;
91 mdp5_write(mdp5_kms, REG_MDP5_INTR_CLEAR, status);
93 VERB("status=%08x", status);
95 mdp_dispatch_irqs(mdp_kms, status);
97 for (id = 0; id < priv->num_crtcs; id++)
98 if (status & mdp5_crtc_vblank(priv->crtcs[id]))
99 drm_handle_vblank(dev, id);
101 return IRQ_HANDLED;
104 int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
106 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
107 struct device *dev = &mdp5_kms->pdev->dev;
109 pm_runtime_get_sync(dev);
110 mdp_update_vblank_mask(to_mdp_kms(kms),
111 mdp5_crtc_vblank(crtc), true);
112 pm_runtime_put_sync(dev);
114 return 0;
117 void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc)
119 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
120 struct device *dev = &mdp5_kms->pdev->dev;
122 pm_runtime_get_sync(dev);
123 mdp_update_vblank_mask(to_mdp_kms(kms),
124 mdp5_crtc_vblank(crtc), false);
125 pm_runtime_put_sync(dev);