All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: linux-sh@vger.kernel.org
Subject: [PATCH 12/38] drm: rcar-du: Turn vblank on/off when enabling/disabling CRTC
Date: Wed, 25 Feb 2015 21:54:32 +0000	[thread overview]
Message-ID: <1424901298-6829-13-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

The DRM core vblank handling mechanism requires drivers to forcefully
turn vblank reporting off when disabling the CRTC, and to restore the
vblank reporting status when enabling the CRTC.

Implement this using the drm_crtc_vblank_on/off helpers. When disabling
vblank we must first wait for page flips to complete, so implement page
flip completion wait as well.

Finally, drm_crtc_vblank_off() must be called at startup to synchronize
the state of the vblank core code with the hardware, which is initially
disabled. This is performed at CRTC creation time, requiring vertical
blanking to be initialized before creating CRTCs.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 18 +++++++++++++-----
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  | 14 ++++++++------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 7f5ae0269a61..5cf2cac75146 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -279,7 +279,7 @@ void rcar_du_crtc_cancel_page_flip(struct rcar_du_crtc *rcrtc,
 	if (event && event->base.file_priv = file) {
 		rcrtc->event = NULL;
 		event->base.destroy(&event->base);
-		drm_vblank_put(dev, rcrtc->index);
+		drm_crtc_vblank_put(&rcrtc->crtc);
 	}
 	spin_unlock_irqrestore(&dev->event_lock, flags);
 }
@@ -303,7 +303,7 @@ static void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc)
 	wake_up(&rcrtc->flip_wait);
 	spin_unlock_irqrestore(&dev->event_lock, flags);
 
-	drm_vblank_put(dev, rcrtc->index);
+	drm_crtc_vblank_put(&rcrtc->crtc);
 }
 
 static bool rcar_du_crtc_page_flip_pending(struct rcar_du_crtc *rcrtc)
@@ -383,6 +383,9 @@ static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
 
 	rcar_du_group_start_stop(rcrtc->group, true);
 
+	/* Turn vertical blanking interrupt reporting back on. */
+	drm_crtc_vblank_on(crtc);
+
 	rcrtc->started = true;
 }
 
@@ -393,10 +396,12 @@ static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
 	if (!rcrtc->started)
 		return;
 
-	/* Wait for page flip completion before stopping the CRTC as userspace
-	 * excepts page flips to eventually complete.
+	/* Disable vertical blanking interrupt reporting. We first need to wait
+	 * for page flip completion before stopping the CRTC as userspace
+	 * expects page flips to eventually complete.
 	 */
 	rcar_du_crtc_wait_page_flip(rcrtc);
+	drm_crtc_vblank_off(crtc);
 
 	mutex_lock(&rcrtc->group->planes.lock);
 	rcrtc->plane->enabled = false;
@@ -596,7 +601,7 @@ static int rcar_du_crtc_page_flip(struct drm_crtc *crtc,
 
 	if (event) {
 		event->pipe = rcrtc->index;
-		drm_vblank_get(dev, rcrtc->index);
+		drm_crtc_vblank_get(crtc);
 		spin_lock_irqsave(&dev->event_lock, flags);
 		rcrtc->event = event;
 		spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -693,6 +698,9 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index)
 
 	drm_crtc_helper_add(crtc, &crtc_helper_funcs);
 
+	/* Start with vertical blanking interrupt reporting disabled. */
+	drm_crtc_vblank_off(crtc);
+
 	/* Register the interrupt handler. */
 	if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
 		irq = platform_get_irq(pdev, index);
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index e0d74f821416..8ab4c69c599b 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -175,17 +175,19 @@ static int rcar_du_load(struct drm_device *dev, unsigned long flags)
 	if (IS_ERR(rcdu->mmio))
 		return PTR_ERR(rcdu->mmio);
 
-	/* DRM/KMS objects */
-	ret = rcar_du_modeset_init(rcdu);
+	/* Initialize vertical blanking interrupts handling. Start with vblank
+	 * disabled for all CRTCs.
+	 */
+	ret = drm_vblank_init(dev, (1 << rcdu->info->num_crtcs) - 1);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to initialize DRM/KMS\n");
+		dev_err(&pdev->dev, "failed to initialize vblank\n");
 		goto done;
 	}
 
-	/* vblank handling */
-	ret = drm_vblank_init(dev, (1 << rcdu->num_crtcs) - 1);
+	/* DRM/KMS objects */
+	ret = rcar_du_modeset_init(rcdu);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to initialize vblank\n");
+		dev_err(&pdev->dev, "failed to initialize DRM/KMS\n");
 		goto done;
 	}
 
-- 
2.0.5


WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: linux-sh@vger.kernel.org
Subject: [PATCH 12/38] drm: rcar-du: Turn vblank on/off when enabling/disabling CRTC
Date: Wed, 25 Feb 2015 23:54:32 +0200	[thread overview]
Message-ID: <1424901298-6829-13-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1424901298-6829-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

The DRM core vblank handling mechanism requires drivers to forcefully
turn vblank reporting off when disabling the CRTC, and to restore the
vblank reporting status when enabling the CRTC.

Implement this using the drm_crtc_vblank_on/off helpers. When disabling
vblank we must first wait for page flips to complete, so implement page
flip completion wait as well.

Finally, drm_crtc_vblank_off() must be called at startup to synchronize
the state of the vblank core code with the hardware, which is initially
disabled. This is performed at CRTC creation time, requiring vertical
blanking to be initialized before creating CRTCs.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 18 +++++++++++++-----
 drivers/gpu/drm/rcar-du/rcar_du_drv.c  | 14 ++++++++------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 7f5ae0269a61..5cf2cac75146 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -279,7 +279,7 @@ void rcar_du_crtc_cancel_page_flip(struct rcar_du_crtc *rcrtc,
 	if (event && event->base.file_priv == file) {
 		rcrtc->event = NULL;
 		event->base.destroy(&event->base);
-		drm_vblank_put(dev, rcrtc->index);
+		drm_crtc_vblank_put(&rcrtc->crtc);
 	}
 	spin_unlock_irqrestore(&dev->event_lock, flags);
 }
@@ -303,7 +303,7 @@ static void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc)
 	wake_up(&rcrtc->flip_wait);
 	spin_unlock_irqrestore(&dev->event_lock, flags);
 
-	drm_vblank_put(dev, rcrtc->index);
+	drm_crtc_vblank_put(&rcrtc->crtc);
 }
 
 static bool rcar_du_crtc_page_flip_pending(struct rcar_du_crtc *rcrtc)
@@ -383,6 +383,9 @@ static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
 
 	rcar_du_group_start_stop(rcrtc->group, true);
 
+	/* Turn vertical blanking interrupt reporting back on. */
+	drm_crtc_vblank_on(crtc);
+
 	rcrtc->started = true;
 }
 
@@ -393,10 +396,12 @@ static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
 	if (!rcrtc->started)
 		return;
 
-	/* Wait for page flip completion before stopping the CRTC as userspace
-	 * excepts page flips to eventually complete.
+	/* Disable vertical blanking interrupt reporting. We first need to wait
+	 * for page flip completion before stopping the CRTC as userspace
+	 * expects page flips to eventually complete.
 	 */
 	rcar_du_crtc_wait_page_flip(rcrtc);
+	drm_crtc_vblank_off(crtc);
 
 	mutex_lock(&rcrtc->group->planes.lock);
 	rcrtc->plane->enabled = false;
@@ -596,7 +601,7 @@ static int rcar_du_crtc_page_flip(struct drm_crtc *crtc,
 
 	if (event) {
 		event->pipe = rcrtc->index;
-		drm_vblank_get(dev, rcrtc->index);
+		drm_crtc_vblank_get(crtc);
 		spin_lock_irqsave(&dev->event_lock, flags);
 		rcrtc->event = event;
 		spin_unlock_irqrestore(&dev->event_lock, flags);
@@ -693,6 +698,9 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index)
 
 	drm_crtc_helper_add(crtc, &crtc_helper_funcs);
 
+	/* Start with vertical blanking interrupt reporting disabled. */
+	drm_crtc_vblank_off(crtc);
+
 	/* Register the interrupt handler. */
 	if (rcar_du_has(rcdu, RCAR_DU_FEATURE_CRTC_IRQ_CLOCK)) {
 		irq = platform_get_irq(pdev, index);
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
index e0d74f821416..8ab4c69c599b 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
@@ -175,17 +175,19 @@ static int rcar_du_load(struct drm_device *dev, unsigned long flags)
 	if (IS_ERR(rcdu->mmio))
 		return PTR_ERR(rcdu->mmio);
 
-	/* DRM/KMS objects */
-	ret = rcar_du_modeset_init(rcdu);
+	/* Initialize vertical blanking interrupts handling. Start with vblank
+	 * disabled for all CRTCs.
+	 */
+	ret = drm_vblank_init(dev, (1 << rcdu->info->num_crtcs) - 1);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to initialize DRM/KMS\n");
+		dev_err(&pdev->dev, "failed to initialize vblank\n");
 		goto done;
 	}
 
-	/* vblank handling */
-	ret = drm_vblank_init(dev, (1 << rcdu->num_crtcs) - 1);
+	/* DRM/KMS objects */
+	ret = rcar_du_modeset_init(rcdu);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to initialize vblank\n");
+		dev_err(&pdev->dev, "failed to initialize DRM/KMS\n");
 		goto done;
 	}
 
-- 
2.0.5


  parent reply	other threads:[~2015-02-25 21:54 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 21:54 [PATCH 00/38] Renesas R-Car DU atomic updates support Laurent Pinchart
2015-02-25 21:54 ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 01/38] drm/atomic: Rename drm_atomic_helper_commit_pre_planes() state argument Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 02/38] drm/atomic-helper: Rename commmit_post/pre_planes Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 03/38] drm/atomic-helpers: make mode_set hooks optional Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 04/38] drm/atomic-helpers: Fix documentation typos and wrong copy&paste Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 05/38] drm: adv7511: Fix DDC error interrupt handling Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 06/38] drm: adv7511: Fix nested sleep when reading EDID Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 07/38] drm: rcar-du: Don't disable unused functions at init time Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 08/38] drm: rcar-du: Remove drm_fbdev_cma_restore_mode() call " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 09/38] drm: rcar-du: Don't set connector->encoder " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 10/38] drm: rcar-du: Reorder CRTC functions Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 11/38] drm: rcar-du: Wait for page flip completion when turning the CRTC off Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` Laurent Pinchart [this message]
2015-02-25 21:54   ` [PATCH 12/38] drm: rcar-du: Turn vblank on/off when enabling/disabling CRTC Laurent Pinchart
2015-02-25 21:54 ` [PATCH 13/38] drm: rcar-du: Disable fbdev emulation when no connector is present Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 14/38] drm: rcar-du: Define macros for the max number of groups, CRTCs and LVDS Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 15/38] drm: rcar-du: Implement universal plane support Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 16/38] drm: rcar-du: Fix hardware plane allocation Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 17/38] drm: rcar-du: Implement planes atomic operations Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 18/38] drm: rcar-du: Handle primary plane config through atomic plane ops Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 19/38] drm: rcar-du: Wire up atomic state object scaffolding Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 20/38] drm: rcar-du: Remove private copy of plane size and position Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 21/38] drm: rcar-du: Replace LVDS encoder DPMS by enable/disable Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 22/38] drm: rcar-du: Rework encoder enable/disable for atomic updates Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 23/38] drm: rcar-du: Rework HDMI " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 24/38] drm: rcar-du: Rework CRTC " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 25/38] drm: rcar-du: Switch plane update to atomic helpers Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 26/38] drm: rcar-du: Switch mode config " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 27/38] drm: rcar-du: Switch connector DPMS " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 28/38] drm: rcar-du: Replace encoder mode_fixup with atomic_check Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 29/38] drm: rcar-du: Implement asynchronous commit support Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 30/38] drm: rcar-du: Switch page flip to atomic helpers Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 31/38] drm: rcar-du: Switch plane set_property " Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 32/38] drm: rcar-du: Rework plane setup code Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 33/38] drm: rcar-du: Replace plane crtc and enabled fields by plane state Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 34/38] drm: rcar-du: Remove unneeded rcar_du_crtc plane field Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 35/38] drm: rcar-du: Move plane format to plane state Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 36/38] drm: rcar-du: Move plane commit code from CRTC start to CRTC resume Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 37/38] drm: rcar-du: Move group locking inside rcar_du_crtc_update_planes() Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-25 21:54 ` [PATCH 38/38] drm: rcar-du: Fix race condition in hardware plane allocator Laurent Pinchart
2015-02-25 21:54   ` Laurent Pinchart
2015-02-26  0:43 ` [PATCH 00/38] Renesas R-Car DU atomic updates support Magnus Damm
2015-02-26  0:43   ` Magnus Damm
2015-02-26  9:23   ` Laurent Pinchart
2015-02-26  9:23     ` Laurent Pinchart
2015-02-27  0:14     ` Magnus Damm
2015-02-27  0:14       ` Magnus Damm
2015-02-27 10:43       ` Laurent Pinchart
2015-02-27 10:43         ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424901298-6829-13-git-send-email-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-sh@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.