All of lore.kernel.org
 help / color / mirror / Atom feed
From: fabrizio.castro@bp.renesas.com (Fabrizio Castro)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 4.19.y-cip 14/32] drm: rcar-du: Cache DSYSR value to ensure known initial value
Date: Mon, 16 Sep 2019 16:50:28 +0100	[thread overview]
Message-ID: <1568649046-17420-15-git-send-email-fabrizio.castro@bp.renesas.com> (raw)
In-Reply-To: <1568649046-17420-1-git-send-email-fabrizio.castro@bp.renesas.com>

From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

commit 9144adc5e5a99577bce0d4ee2ca3615f53b9d296 upstream.

DSYSR is a DU channel register that also contains group fields. It is
thus written to by both the group and CRTC code, using read-update-write
sequences. As the register isn't initialized explicitly at startup time,
this can lead to invalid or otherwise unexpected values being written to
some of the fields if they have been modified by the firmware or just
not reset properly.

To fix this we can write a fully known value to the DSYSR register when
turning a channel's functional clock on. However, the mix of group and
channel fields complicate this. A simpler solution is to cache the
register and initialize the cached value to the desired hardware
defaults.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tested-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c  | 16 ++++++++--------
 drivers/gpu/drm/rcar-du/rcar_du_crtc.h  |  5 +++++
 drivers/gpu/drm/rcar-du/rcar_du_group.c |  7 ++++---
 3 files changed, 17 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 4b43d83..f2f6322 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -61,13 +61,12 @@ static void rcar_du_crtc_set(struct rcar_du_crtc *rcrtc, u32 reg, u32 set)
 		      rcar_du_read(rcdu, rcrtc->mmio_offset + reg) | set);
 }
 
-static void rcar_du_crtc_clr_set(struct rcar_du_crtc *rcrtc, u32 reg,
-				 u32 clr, u32 set)
+void rcar_du_crtc_dsysr_clr_set(struct rcar_du_crtc *rcrtc, u32 clr, u32 set)
 {
 	struct rcar_du_device *rcdu = rcrtc->group->dev;
-	u32 value = rcar_du_read(rcdu, rcrtc->mmio_offset + reg);
 
-	rcar_du_write(rcdu, rcrtc->mmio_offset + reg, (value & ~clr) | set);
+	rcrtc->dsysr = (rcrtc->dsysr & ~clr) | set;
+	rcar_du_write(rcdu, rcrtc->mmio_offset + DSYSR, rcrtc->dsysr);
 }
 
 static int rcar_du_crtc_get(struct rcar_du_crtc *rcrtc)
@@ -525,9 +524,9 @@ static void rcar_du_crtc_start(struct rcar_du_crtc *rcrtc)
 	 * actively driven).
 	 */
 	interlaced = rcrtc->crtc.mode.flags & DRM_MODE_FLAG_INTERLACE;
-	rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK | DSYSR_SCM_MASK,
-			     (interlaced ? DSYSR_SCM_INT_VIDEO : 0) |
-			     DSYSR_TVM_MASTER);
+	rcar_du_crtc_dsysr_clr_set(rcrtc, DSYSR_TVM_MASK | DSYSR_SCM_MASK,
+				   (interlaced ? DSYSR_SCM_INT_VIDEO : 0) |
+				   DSYSR_TVM_MASTER);
 
 	rcar_du_group_start_stop(rcrtc->group, true);
 }
@@ -594,7 +593,7 @@ static void rcar_du_crtc_stop(struct rcar_du_crtc *rcrtc)
 	 * Select switch sync mode. This stops display operation and configures
 	 * the HSYNC and VSYNC signals as inputs.
 	 */
-	rcar_du_crtc_clr_set(rcrtc, DSYSR, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH);
+	rcar_du_crtc_dsysr_clr_set(rcrtc, DSYSR_TVM_MASK, DSYSR_TVM_SWITCH);
 
 	rcar_du_group_start_stop(rcrtc->group, false);
 }
@@ -972,6 +971,7 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int swindex,
 	rcrtc->group = rgrp;
 	rcrtc->mmio_offset = mmio_offsets[hwindex];
 	rcrtc->index = hwindex;
+	rcrtc->dsysr = (rcrtc->index % 2 ? 0 : DSYSR_DRES) | DSYSR_TVM_TVSYNC;
 
 	if (rcar_du_has(rcdu, RCAR_DU_FEATURE_VSP1_SOURCE))
 		primary = &rcrtc->vsp->planes[rcrtc->vsp_pipe].plane;
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.h b/drivers/gpu/drm/rcar-du/rcar_du_crtc.h
index 7680cb2..2c1eaa3 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.h
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.h
@@ -34,6 +34,7 @@ struct rcar_du_vsp;
  * @mmio_offset: offset of the CRTC registers in the DU MMIO block
  * @index: CRTC software and hardware index
  * @initialized: whether the CRTC has been initialized and clocks enabled
+ * @dsysr: cached value of the DSYSR register
  * @vblank_enable: whether vblank events are enabled on this CRTC
  * @event: event to post when the pending page flip completes
  * @flip_wait: wait queue used to signal page flip completion
@@ -54,6 +55,8 @@ struct rcar_du_crtc {
 	unsigned int index;
 	bool initialized;
 
+	u32 dsysr;
+
 	bool vblank_enable;
 	struct drm_pending_vblank_event *event;
 	wait_queue_head_t flip_wait;
@@ -104,4 +107,6 @@ void rcar_du_crtc_route_output(struct drm_crtc *crtc,
 			       enum rcar_du_output output);
 void rcar_du_crtc_finish_page_flip(struct rcar_du_crtc *rcrtc);
 
+void rcar_du_crtc_dsysr_clr_set(struct rcar_du_crtc *rcrtc, u32 clr, u32 set);
+
 #endif /* __RCAR_DU_CRTC_H__ */
diff --git a/drivers/gpu/drm/rcar-du/rcar_du_group.c b/drivers/gpu/drm/rcar-du/rcar_du_group.c
index d539cb2..5966d94 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_group.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_group.c
@@ -177,9 +177,10 @@ void rcar_du_group_put(struct rcar_du_group *rgrp)
 
 static void __rcar_du_group_start_stop(struct rcar_du_group *rgrp, bool start)
 {
-	rcar_du_group_write(rgrp, DSYSR,
-		(rcar_du_group_read(rgrp, DSYSR) & ~(DSYSR_DRES | DSYSR_DEN)) |
-		(start ? DSYSR_DEN : DSYSR_DRES));
+	struct rcar_du_crtc *rcrtc = &rgrp->dev->crtcs[rgrp->index * 2];
+
+	rcar_du_crtc_dsysr_clr_set(rcrtc, DSYSR_DRES | DSYSR_DEN,
+				   start ? DSYSR_DEN : DSYSR_DRES);
 }
 
 void rcar_du_group_start_stop(struct rcar_du_group *rgrp, bool start)
-- 
2.7.4

  parent reply	other threads:[~2019-09-16 15:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-16 15:50 [cip-dev] [PATCH 4.19.y-cip 00/32] Add PCIe and HDMI support to HiHope RZ/G2M Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 01/32] dt-bindings: PCI: rcar: Add device tree support for r8a774a1 Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 02/32] dt-bindings: display: renesas: du: Document the r8a774a1 bindings Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 03/32] dt-bindings: display: renesas: lvds: Document " Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 04/32] dt-bindings: display: renesas: Add r8a774a1 support Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 05/32] PCI: rcar: Replace unsigned long with u32/unsigned int in register accessors Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 06/32] PCI: rcar: Replace various variable types with unsigned ones for register values Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 07/32] PCI: rcar: Clean up debug messages Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 08/32] PCI: rcar: Do not shadow the 'irq' variable Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 09/32] drm: rcar-du: Add R8A774A1 support Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 10/32] drm: rcar-du: lvds: Add r8a774a1 support Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 11/32] drm: rcar-du: dw-hdmi: Reject modes with a too high clock frequency Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 12/32] drm: rcar-du: Refactor Feature and Quirk definitions Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 13/32] drm: rcar-du: Add interlaced feature flag Fabrizio Castro
2019-09-16 15:50 ` Fabrizio Castro [this message]
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 15/32] drm: rcar-du: Don't use TV sync mode when not supported by the hardware Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 16/32] drm: rcar-du: Support interlaced video output through vsp1 Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 17/32] drm: rcar-du: Rework clock configuration based on hardware limits Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 18/32] drm: rcar-du: Rename and document dpll_ch field Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 19/32] drm: rcar-du: Add support for missing pixel formats Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 20/32] drm: rcar-du: Store V4L2 fourcc in rcar_du_format_info structure Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 21/32] drm: rcar-du: Update framebuffer pitch and alignment limits for Gen3 Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 22/32] arm64: dts: renesas: r8a774a1: Add PCIe device nodes Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 23/32] arm64: dts: renesas: hihope-common: Declare pcie bus clock Fabrizio Castro
2019-09-17 12:36   ` nobuhiro1.iwamatsu at toshiba.co.jp
2019-09-17 13:06     ` Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 24/32] arm64: dts: renesas: hihope-rzg2-ex: Enable PCIe support Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 25/32] arm64: dts: renesas: r8a774a1: Add VSP instances Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 26/32] arm64: dts: renesas: r8a774a1: Add DU device to DT Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 27/32] arm64: dts: renesas: r8a774a1: Add FDP1 instance Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 28/32] arm64: dts: renesas: r8a774a1: Tie SYS-DMAC to IPMMU-DS0/1 Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 29/32] arm64: dts: renesas: r8a774a1: Tie Audio-DMAC to IPMMU-MP Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 30/32] arm64: dts: renesas: r8a774a1: Connect Ethernet-AVB to IPMMU-DS0 Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 31/32] arm64: dts: renesas: r8a774a1: Add HDMI encoder instance Fabrizio Castro
2019-09-16 15:50 ` [cip-dev] [PATCH 4.19.y-cip 32/32] arm64: dts: renesas: hihope-common: Add HDMI support Fabrizio Castro
2019-09-17  1:06 ` [cip-dev] [PATCH 4.19.y-cip 00/32] Add PCIe and HDMI support to HiHope RZ/G2M nobuhiro1.iwamatsu at toshiba.co.jp
2019-09-17  9:38   ` Pavel Machek
2019-09-18  5:25     ` nobuhiro1.iwamatsu at toshiba.co.jp

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=1568649046-17420-15-git-send-email-fabrizio.castro@bp.renesas.com \
    --to=fabrizio.castro@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.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.