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 v2 17/32] drm: rcar-du: Rework clock configuration based on hardware limits
Date: Tue, 17 Sep 2019 14:07:45 +0100	[thread overview]
Message-ID: <1568725680-32730-18-git-send-email-fabrizio.castro@bp.renesas.com> (raw)
In-Reply-To: <1568725680-32730-1-git-send-email-fabrizio.castro@bp.renesas.com>

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

commit 7281e6c6a5bdbde9cae6eb3c6d2bf2706b94807d upstream.

The DU channels that have a display PLL (DPLL) can only use external
clock sources, and don't have an internal clock divider (with the
exception of H3 ES1.x where the post-divider is present and needs to be
used as a workaround for a DPLL silicon issue).

Rework the clock configuration to take this into account, avoiding
selection of non-existing clock sources or usage of a missing
post-divider.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Signed-off-by: Fabrizio Castro <fabrizio.castro@bp.renesas.com>
---
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 134 ++++++++++++++++++---------------
 1 file changed, 73 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
index 5441d5a..342519c 100644
--- a/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
+++ b/drivers/gpu/drm/rcar-du/rcar_du_crtc.c
@@ -207,78 +207,90 @@ static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc)
 	const struct drm_display_mode *mode = &rcrtc->crtc.state->adjusted_mode;
 	struct rcar_du_device *rcdu = rcrtc->group->dev;
 	unsigned long mode_clock = mode->clock * 1000;
-	unsigned long clk;
-	u32 value;
+	u32 dsmr;
 	u32 escr;
-	u32 div;
 
-	/*
-	 * Compute the clock divisor and select the internal or external dot
-	 * clock based on the requested frequency.
-	 */
-	clk = clk_get_rate(rcrtc->clock);
-	div = DIV_ROUND_CLOSEST(clk, mode_clock);
-	div = clamp(div, 1U, 64U) - 1;
-	escr = div | ESCR_DCLKSEL_CLKS;
-
-	if (rcrtc->extclock) {
+	if (rcdu->info->dpll_ch & (1 << rcrtc->index)) {
+		unsigned long target = mode_clock;
 		struct dpll_info dpll = { 0 };
 		unsigned long extclk;
-		unsigned long extrate;
-		unsigned long rate;
-		u32 extdiv;
+		u32 dpllcr;
+		u32 div = 0;
 
-		extclk = clk_get_rate(rcrtc->extclock);
-		if (rcdu->info->dpll_ch & (1 << rcrtc->index)) {
-			unsigned long target = mode_clock;
+		/*
+		 * DU channels that have a display PLL can't use the internal
+		 * system clock, and have no internal clock divider.
+		 */
 
-			/*
-			 * The H3 ES1.x exhibits dot clock duty cycle stability
-			 * issues. We can work around them by configuring the
-			 * DPLL to twice the desired frequency, coupled with a
-			 * /2 post-divider. This isn't needed on other SoCs and
-			 * breaks HDMI output on M3-W for a currently unknown
-			 * reason, so restrict the workaround to H3 ES1.x.
-			 */
-			if (soc_device_match(rcar_du_r8a7795_es1))
-				target *= 2;
+		if (WARN_ON(!rcrtc->extclock))
+			return;
 
-			rcar_du_dpll_divider(rcrtc, &dpll, extclk, target);
-			extclk = dpll.output;
+		/*
+		 * The H3 ES1.x exhibits dot clock duty cycle stability issues.
+		 * We can work around them by configuring the DPLL to twice the
+		 * desired frequency, coupled with a /2 post-divider. Restrict
+		 * the workaround to H3 ES1.x as ES2.0 and all other SoCs have
+		 * no post-divider when a display PLL is present (as shown by
+		 * the workaround breaking HDMI output on M3-W during testing).
+		 */
+		if (soc_device_match(rcar_du_r8a7795_es1)) {
+			target *= 2;
+			div = 1;
 		}
 
-		extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock);
-		extdiv = clamp(extdiv, 1U, 64U) - 1;
+		extclk = clk_get_rate(rcrtc->extclock);
+		rcar_du_dpll_divider(rcrtc, &dpll, extclk, target);
 
-		rate = clk / (div + 1);
-		extrate = extclk / (extdiv + 1);
+		dpllcr = DPLLCR_CODE | DPLLCR_CLKE
+		       | DPLLCR_FDPLL(dpll.fdpll)
+		       | DPLLCR_N(dpll.n) | DPLLCR_M(dpll.m)
+		       | DPLLCR_STBY;
 
-		if (abs((long)extrate - (long)mode_clock) <
-		    abs((long)rate - (long)mode_clock)) {
+		if (rcrtc->index == 1)
+			dpllcr |= DPLLCR_PLCS1
+			       |  DPLLCR_INCS_DOTCLKIN1;
+		else
+			dpllcr |= DPLLCR_PLCS0
+			       |  DPLLCR_INCS_DOTCLKIN0;
 
-			if (rcdu->info->dpll_ch & (1 << rcrtc->index)) {
-				u32 dpllcr = DPLLCR_CODE | DPLLCR_CLKE
-					   | DPLLCR_FDPLL(dpll.fdpll)
-					   | DPLLCR_N(dpll.n) | DPLLCR_M(dpll.m)
-					   | DPLLCR_STBY;
+		rcar_du_group_write(rcrtc->group, DPLLCR, dpllcr);
 
-				if (rcrtc->index == 1)
-					dpllcr |= DPLLCR_PLCS1
-					       |  DPLLCR_INCS_DOTCLKIN1;
-				else
-					dpllcr |= DPLLCR_PLCS0
-					       |  DPLLCR_INCS_DOTCLKIN0;
+		escr = ESCR_DCLKSEL_DCLKIN | div;
+	} else {
+		unsigned long clk;
+		u32 div;
 
-				rcar_du_group_write(rcrtc->group, DPLLCR,
-						    dpllcr);
-			}
+		/*
+		 * Compute the clock divisor and select the internal or external
+		 * dot clock based on the requested frequency.
+		 */
+		clk = clk_get_rate(rcrtc->clock);
+		div = DIV_ROUND_CLOSEST(clk, mode_clock);
+		div = clamp(div, 1U, 64U) - 1;
 
-			escr = ESCR_DCLKSEL_DCLKIN | extdiv;
-		}
+		escr = ESCR_DCLKSEL_CLKS | div;
 
-		dev_dbg(rcrtc->group->dev->dev,
-			"mode clock %lu extrate %lu rate %lu ESCR 0x%08x\n",
-			mode_clock, extrate, rate, escr);
+		if (rcrtc->extclock) {
+			unsigned long extclk;
+			unsigned long extrate;
+			unsigned long rate;
+			u32 extdiv;
+
+			extclk = clk_get_rate(rcrtc->extclock);
+			extdiv = DIV_ROUND_CLOSEST(extclk, mode_clock);
+			extdiv = clamp(extdiv, 1U, 64U) - 1;
+
+			extrate = extclk / (extdiv + 1);
+			rate = clk / (div + 1);
+
+			if (abs((long)extrate - (long)mode_clock) <
+			    abs((long)rate - (long)mode_clock))
+				escr = ESCR_DCLKSEL_DCLKIN | extdiv;
+
+			dev_dbg(rcrtc->group->dev->dev,
+				"mode clock %lu extrate %lu rate %lu ESCR 0x%08x\n",
+				mode_clock, extrate, rate, escr);
+		}
 	}
 
 	rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? ESCR2 : ESCR,
@@ -286,11 +298,11 @@ static void rcar_du_crtc_set_display_timing(struct rcar_du_crtc *rcrtc)
 	rcar_du_group_write(rcrtc->group, rcrtc->index % 2 ? OTAR2 : OTAR, 0);
 
 	/* Signal polarities */
-	value = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? DSMR_VSL : 0)
-	      | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? DSMR_HSL : 0)
-	      | ((mode->flags & DRM_MODE_FLAG_INTERLACE) ? DSMR_ODEV : 0)
-	      | DSMR_DIPM_DISP | DSMR_CSPM;
-	rcar_du_crtc_write(rcrtc, DSMR, value);
+	dsmr = ((mode->flags & DRM_MODE_FLAG_PVSYNC) ? DSMR_VSL : 0)
+	     | ((mode->flags & DRM_MODE_FLAG_PHSYNC) ? DSMR_HSL : 0)
+	     | ((mode->flags & DRM_MODE_FLAG_INTERLACE) ? DSMR_ODEV : 0)
+	     | DSMR_DIPM_DISP | DSMR_CSPM;
+	rcar_du_crtc_write(rcrtc, DSMR, dsmr);
 
 	/* Display timings */
 	rcar_du_crtc_write(rcrtc, HDSR, mode->htotal - mode->hsync_start - 19);
-- 
2.7.4

  parent reply	other threads:[~2019-09-17 13:07 UTC|newest]

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