[d-kernel] [PATCH 37/39] drm: baikal-m: add vblank events, fix mode switching

Daniil Gnusarev gnusarevda на basealt.ru
Пн Окт 14 17:02:18 MSK 2024


Added support for vblank events, which eliminated the slowness of
the graphical environment. In addition, for the case of several monitors,
the pitch parameter is taken into account, which solves the problem of
only vertical arrangement of screens.

Signed-off-by: Daniil Gnusarev <gnusarevda на basealt.ru>
---
 drivers/gpu/drm/baikal/baikal_vdu_crtc.c  | 58 ++++++++++++++++++-----
 drivers/gpu/drm/baikal/baikal_vdu_drm.h   | 18 +++++++
 drivers/gpu/drm/baikal/baikal_vdu_drv.c   | 16 +++++--
 drivers/gpu/drm/baikal/baikal_vdu_plane.c |  5 ++
 4 files changed, 83 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/baikal/baikal_vdu_crtc.c b/drivers/gpu/drm/baikal/baikal_vdu_crtc.c
index 50327813c04b3..b51231719fc9c 100644
--- a/drivers/gpu/drm/baikal/baikal_vdu_crtc.c
+++ b/drivers/gpu/drm/baikal/baikal_vdu_crtc.c
@@ -36,6 +36,13 @@ irqreturn_t baikal_vdu_irq(int irq, void *data)
 	irq_stat = readl(priv->regs + IVR);
 	raw_stat = readl(priv->regs + ISR);
 
+	if (irq_stat & INTR_VCT) {
+		priv->counters[10]++;
+		if (priv->vblank)
+			drm_crtc_handle_vblank(&priv->crtc);
+		status = IRQ_HANDLED;
+	}
+
 	if (raw_stat & INTR_UFU) {
 		priv->counters[4]++;
 		status = IRQ_HANDLED;
@@ -228,6 +235,7 @@ static void baikal_vdu_crtc_helper_mode_set_nofb(struct drm_crtc *crtc)
 	unsigned int ppl, hsw, hfp, hbp;
 	unsigned int lpp, vsw, vfp, vbp;
 	unsigned int reg;
+	unsigned long flags;
 	int ret = 0;
 
 	drm_mode_debug_printmodeline(mode);
@@ -260,29 +268,31 @@ static void baikal_vdu_crtc_helper_mode_set_nofb(struct drm_crtc *crtc)
 		DRM_ERROR("Cannot set desired pixel clock (%lu Hz)\n", rate);
 
 	ppl = mode->hdisplay / 16;
-	if (priv->index == CRTC_LVDS && priv-> num_lanes == 2) {
+	if (priv->index == CRTC_LVDS && priv->num_lanes == 2) {
 		hsw = mode->hsync_end - mode->hsync_start;
 		hfp = mode->hsync_start - mode->hdisplay - 1;
+		hbp = mode->htotal - mode->hsync_end;
 	} else {
 		hsw = mode->hsync_end - mode->hsync_start - 1;
-		hfp = mode->hsync_start - mode->hdisplay;
+		hfp = mode->hsync_start - mode->hdisplay - 1;
+		hbp = mode->htotal - mode->hsync_end - 1;
 	}
-	hbp = mode->htotal - mode->hsync_end;
 
 	lpp = mode->vdisplay;
 	vsw = mode->vsync_end - mode->vsync_start;
 	vfp = mode->vsync_start - mode->vdisplay;
 	vbp = mode->vtotal - mode->vsync_end;
 
+	spin_lock_irqsave(&priv->lock, flags);
 	writel((HTR_HFP(hfp) & HTR_HFP_MASK) |
 			(HTR_PPL(ppl) & HTR_PPL_MASK) |
 			(HTR_HBP(hbp) & HTR_HBP_MASK) |
 			(HTR_HSW(hsw) & HTR_HSW_MASK),
 			priv->regs + HTR);
-
 	if (mode->hdisplay > 4080 || ppl * 16 != mode->hdisplay)
 		writel((HPPLOR_HPPLO(mode->hdisplay) & HPPLOR_HPPLO_MASK) | HPPLOR_HPOE,
-				priv->regs + HPPLOR);
+			priv->regs + HPPLOR);
+	spin_unlock_irqrestore(&priv->lock, flags);
 
 	writel((VTR1_VSW(vsw) & VTR1_VSW_MASK) |
 			(VTR1_VFP(vfp) & VTR1_VFP_MASK) |
@@ -314,8 +324,8 @@ static enum drm_mode_status baikal_vdu_mode_valid(struct drm_crtc *crtc,
 	                const struct drm_display_mode *mode)
 {
 	struct baikal_vdu_private *priv = crtc_to_baikal_vdu(crtc);
-	if (!priv->mode_override && (mode->hdisplay > 2560 ||
-			mode->vdisplay > 1440))
+	if (!priv->mode_override && (mode->hdisplay > 4096 ||
+			mode->vdisplay > 4096))
 		return MODE_BAD;
 	else
 		return MODE_OK;
@@ -329,8 +339,19 @@ static void baikal_vdu_crtc_helper_enable(struct drm_crtc *crtc,
 	u32 cntl, gpio;
 
 	DRM_DEV_DEBUG_DRIVER(crtc->dev->dev, "enabling pixel clock\n");
+
+	writel(ISCR_VSC_VFP, priv->regs + ISCR);
+
+	/* hold clock domain reset; disable clocking */
+	writel(0, priv->regs + PCTR);
+
 	baikal_vdu_crtc_clk_enable(priv);
 
+	/* release clock reset; enable clocking */
+	cntl = readl(priv->regs + PCTR);
+	cntl |= PCTR_PCR + PCTR_PCI;
+	writel(cntl, priv->regs + PCTR);
+
 	/* Set 16-word input FIFO watermark */
 	/* Enable and Power Up */
 	cntl = readl(priv->regs + CR1);
@@ -373,16 +394,14 @@ static void baikal_vdu_crtc_helper_enable(struct drm_crtc *crtc,
 		cntl |= CR1_OPS_LCD24;
 	writel(cntl, priv->regs + CR1);
 
-	writel(0x3ffff, priv->regs + ISR);
-	writel(INTR_FER, priv->regs + IMR);
+	drm_crtc_vblank_on(crtc);
 }
 
 void baikal_vdu_crtc_helper_disable(struct drm_crtc *crtc)
 {
 	struct baikal_vdu_private *priv = crtc_to_baikal_vdu(crtc);
 
-	writel(0x3ffff, priv->regs + ISR);
-	writel(0, priv->regs + IMR);
+	drm_crtc_vblank_off(crtc);
 
 	/* Disable clock */
 	DRM_DEV_DEBUG_DRIVER(crtc->dev->dev, "disabling pixel clock\n");
@@ -406,6 +425,21 @@ static void baikal_vdu_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 	}
 }
 
+static int baikal_vdu_enable_vblank(struct drm_crtc *crtc)
+{
+	struct baikal_vdu_private *priv = crtc_to_baikal_vdu(crtc);
+
+	baikal_vdu_set_irq(priv, true, true);
+	return 0;
+}
+
+static void baikal_vdu_disable_vblank(struct drm_crtc *crtc)
+{
+	struct baikal_vdu_private *priv = crtc_to_baikal_vdu(crtc);
+
+	baikal_vdu_set_irq(priv, true, false);
+}
+
 const struct drm_crtc_funcs crtc_funcs = {
 	.set_config = drm_atomic_helper_set_config,
 	.page_flip = drm_atomic_helper_page_flip,
@@ -413,6 +447,8 @@ const struct drm_crtc_funcs crtc_funcs = {
 	.destroy = drm_crtc_cleanup,
 	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+	.enable_vblank = baikal_vdu_enable_vblank,
+	.disable_vblank = baikal_vdu_disable_vblank,
 };
 
 const struct drm_crtc_helper_funcs crtc_helper_funcs = {
diff --git a/drivers/gpu/drm/baikal/baikal_vdu_drm.h b/drivers/gpu/drm/baikal/baikal_vdu_drm.h
index 90dc57bac7ae2..d5dfde4b6750c 100644
--- a/drivers/gpu/drm/baikal/baikal_vdu_drm.h
+++ b/drivers/gpu/drm/baikal/baikal_vdu_drm.h
@@ -19,6 +19,8 @@
 #include <linux/gpio.h>
 #include <linux/backlight.h>
 
+#include "baikal_vdu_regs.h"
+
 #define CRTC_HDMI	0
 #define CRTC_LVDS	1
 
@@ -54,6 +56,7 @@ struct baikal_vdu_private {
 	int data_mapping;
 	int off;
 	int ready;
+	bool vblank;
 
 	/* backlight */
 	struct gpio_desc *enable_gpio;
@@ -84,6 +87,21 @@ struct baikal_hdmi_bridge {
 };
 
 /* Generic functions */
+
+static inline void baikal_vdu_set_irq(struct baikal_vdu_private *priv, bool irq, bool vblank)
+{
+	u32 val;
+
+	priv->vblank = vblank && irq;
+
+	val = priv->vblank ? INTR_VCT + INTR_FER : INTR_FER;
+	val = irq ? val : 0;
+
+	/* clear interrupt status */
+	writel(0x3ffff, priv->regs + ISR);
+	writel(val, priv->regs + IMR);
+}
+
 inline void baikal_vdu_switch_on(struct baikal_vdu_private *priv);
 
 inline void baikal_vdu_switch_off(struct baikal_vdu_private *priv);
diff --git a/drivers/gpu/drm/baikal/baikal_vdu_drv.c b/drivers/gpu/drm/baikal/baikal_vdu_drv.c
index a951c6661ffa6..63a4916b33e93 100644
--- a/drivers/gpu/drm/baikal/baikal_vdu_drv.c
+++ b/drivers/gpu/drm/baikal/baikal_vdu_drv.c
@@ -33,6 +33,7 @@
 #include <drm/drm_of.h>
 #include <drm/drm_panel.h>
 #include <drm/drm_probe_helper.h>
+#include <drm/drm_vblank.h>
 
 #include "baikal_vdu_drm.h"
 #include "baikal_vdu_regs.h"
@@ -286,7 +287,7 @@ static int baikal_vdu_allocate_irq(struct platform_device *pdev,
 	}
 
 	/* turn off interrupts before requesting the irq */
-	writel(0, priv->regs + IMR);
+	baikal_vdu_set_irq(priv, false, false);
 	ret = request_irq(priv->irq, baikal_vdu_irq, IRQF_SHARED, dev->driver->name, priv);
 	if (ret != 0)
 		dev_err(dev, "%s %s: IRQ %d allocation failed\n", __func__, priv->name, priv->irq);
@@ -295,8 +296,7 @@ static int baikal_vdu_allocate_irq(struct platform_device *pdev,
 
 static void baikal_vdu_free_irq(struct baikal_vdu_private *priv)
 {
-	writel(0, priv->regs + IMR);
-	writel(0x3ffff, priv->regs + ISR);
+	baikal_vdu_set_irq(priv, false, false);
 	free_irq(priv->irq, priv->drm->dev);
 }
 
@@ -476,6 +476,14 @@ static int baikal_vdu_drm_probe(struct platform_device *pdev)
 	lvds->ready = lvds->ready & !lvds->off;
 	dev_info(dev, "%s output %s\n", hdmi->name, hdmi->ready ? "enabled" : "disabled");
 	dev_info(dev, "%s output %s\n", lvds->name, lvds->ready ? "enabled" : "disabled");
+
+	ret = drm_vblank_init(drm, (hdmi->ready ? 1 : 0) +
+				   (lvds->ready ? 1 : 0));
+	if (ret) {
+		dev_err(dev, "failed to init vblank\n");
+		goto out_config;
+	}
+
 	baikal_vdu_remove_efifb(drm);
 
 	if (hdmi->ready || lvds->ready) {
@@ -489,7 +497,9 @@ static int baikal_vdu_drm_probe(struct platform_device *pdev)
 			dev_err(dev, "failed to register DRM device\n");
 			goto out_config;
 		}
+
 		drm_fbdev_dma_setup(drm, 32);
+
 #if defined(CONFIG_DEBUG_FS)
 		if (hdmi->ready)
 			baikal_vdu_hdmi_debugfs_init(drm->primary);
diff --git a/drivers/gpu/drm/baikal/baikal_vdu_plane.c b/drivers/gpu/drm/baikal/baikal_vdu_plane.c
index d9bdb95a8d962..490110f7e50ce 100644
--- a/drivers/gpu/drm/baikal/baikal_vdu_plane.c
+++ b/drivers/gpu/drm/baikal/baikal_vdu_plane.c
@@ -87,6 +87,11 @@ static void baikal_vdu_primary_plane_atomic_update(struct drm_plane *plane,
 	}
 
 	writel(cntl, priv->regs + CR1);
+
+	spin_lock_irqsave(&priv->lock, flags);
+	writel((fb->pitches[0] / DIV_ROUND_UP(drm_format_info_bpp(fb->format, 0), 8)) |
+		HPPLOR_HPOE, priv->regs + HPPLOR);
+	spin_unlock_irqrestore(&priv->lock, flags);
 }
 
 static const struct drm_plane_helper_funcs baikal_vdu_primary_plane_helper_funcs = {
-- 
2.42.2



Подробная информация о списке рассылки devel-kernel