Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Roper <matthew.d.roper@intel.com>
To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Cc: matthew.d.roper@intel.com
Subject: [PATCH 1/4] drm/i915/display: Make refclk fetching logic reusable
Date: Thu, 20 Feb 2025 16:38:45 -0800	[thread overview]
Message-ID: <20250221003843.443559-7-matthew.d.roper@intel.com> (raw)
In-Reply-To: <20250221003843.443559-6-matthew.d.roper@intel.com>

There's cdclk-specific code to obtain the display reference clock,
either by reading a strap register, or by using a platform-specific
hardcoded value.  There's at least one other place in our drivers that
potentially needs this clock frequency, so refactor the logic to make it
more generally usable.

While we're at it, change the fallback frequency we assume if the strap
readout gives us something unrecognizable to 38.4MHz for platforms with
display version 14 and above.  38.4MHz seems to be the sole frequency
that's actually been used in recent history (since MTL), so this is
probably the safest guess to make going forward.

Signed-off-by: Matt Roper <matthew.d.roper@intel.com>
---
 drivers/gpu/drm/i915/display/intel_cdclk.c | 44 +++++++++++++---------
 drivers/gpu/drm/i915/display/intel_cdclk.h |  1 +
 2 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.c b/drivers/gpu/drm/i915/display/intel_cdclk.c
index c6cfc57a0346..57b01f8a7be8 100644
--- a/drivers/gpu/drm/i915/display/intel_cdclk.c
+++ b/drivers/gpu/drm/i915/display/intel_cdclk.c
@@ -1636,38 +1636,48 @@ static u8 xe3lpd_calc_voltage_level(int cdclk)
 	return 0;
 }
 
-static void icl_readout_refclk(struct intel_display *display,
-			       struct intel_cdclk_config *cdclk_config)
+static u32 icl_readout_refclk(struct intel_display *display)
 {
 	u32 dssm = intel_de_read(display, SKL_DSSM) & ICL_DSSM_CDCLK_PLL_REFCLK_MASK;
 
 	switch (dssm) {
-	default:
-		MISSING_CASE(dssm);
-		fallthrough;
 	case ICL_DSSM_CDCLK_PLL_REFCLK_24MHz:
-		cdclk_config->ref = 24000;
-		break;
+		return 24000;
 	case ICL_DSSM_CDCLK_PLL_REFCLK_19_2MHz:
-		cdclk_config->ref = 19200;
-		break;
+		return 19200;
 	case ICL_DSSM_CDCLK_PLL_REFCLK_38_4MHz:
-		cdclk_config->ref = 38400;
-		break;
+		return 38400;
+	default:
+		MISSING_CASE(dssm);
+		return DISPLAY_VER(display) >= 14 ? 38400 : 24000;
 	}
 }
 
+/**
+ * intel_display_get_refclk - Returns the display reference clock
+ * @display: display instance
+ *
+ * Returns the display reference clock in KHz.  The display reference clock
+ * is defined by the SoC; on some platforms the proper value should be read
+ * from a hardware strap register, while on others there's only a single
+ * possible value.
+ */
+u32 intel_display_get_refclk(struct intel_display *display)
+{
+	if (display->platform.dg2)
+		return 38400;
+	else if (DISPLAY_VER(display) >= 11)
+		return icl_readout_refclk(display);
+	else
+		return 19200;
+}
+
 static void bxt_de_pll_readout(struct intel_display *display,
 			       struct intel_cdclk_config *cdclk_config)
 {
 	u32 val, ratio;
 
-	if (display->platform.dg2)
-		cdclk_config->ref = 38400;
-	else if (DISPLAY_VER(display) >= 11)
-		icl_readout_refclk(display, cdclk_config);
-	else
-		cdclk_config->ref = 19200;
+	cdclk_config->ref = intel_display_get_refclk(display);
 
 	val = intel_de_read(display, BXT_DE_PLL_ENABLE);
 	if ((val & BXT_DE_PLL_PLL_ENABLE) == 0 ||
diff --git a/drivers/gpu/drm/i915/display/intel_cdclk.h b/drivers/gpu/drm/i915/display/intel_cdclk.h
index 6b0e7a41eba3..3cfbe1f2b6b5 100644
--- a/drivers/gpu/drm/i915/display/intel_cdclk.h
+++ b/drivers/gpu/drm/i915/display/intel_cdclk.h
@@ -65,6 +65,7 @@ void intel_init_cdclk_hooks(struct intel_display *display);
 void intel_update_max_cdclk(struct intel_display *display);
 void intel_update_cdclk(struct intel_display *display);
 u32 intel_read_rawclk(struct intel_display *display);
+u32 intel_display_get_refclk(struct intel_display *display);
 bool intel_cdclk_clock_changed(const struct intel_cdclk_config *a,
 			       const struct intel_cdclk_config *b);
 int intel_mdclk_cdclk_ratio(struct intel_display *display,
-- 
2.48.1


  reply	other threads:[~2025-02-21  0:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21  0:38 [PATCH 0/4] Stop accessing display TIMESTAMP_OVERRIDE in GT code Matt Roper
2025-02-21  0:38 ` Matt Roper [this message]
2025-02-24  9:13   ` [PATCH 1/4] drm/i915/display: Make refclk fetching logic reusable Jani Nikula
2025-02-24 13:31   ` Vivekanandan, Balasubramani
2025-02-21  0:38 ` [PATCH 2/4] drm/i915/gt: Replace TIMESTAMP_OVERRIDE readout Matt Roper
2025-02-24 13:55   ` Vivekanandan, Balasubramani
2025-02-21  0:38 ` [PATCH 3/4] drm/xe: Drop usage of TIMESTAMP_OVERRIDE Matt Roper
2025-02-21  3:35   ` Lucas De Marchi
2025-02-21  4:25   ` kernel test robot
2025-02-24 14:13   ` Vivekanandan, Balasubramani
2025-02-21  0:38 ` [PATCH 4/4] drm/xe/sriov: Drop TIMESTAMP_OVERRIDE from Xe2 runtime regs Matt Roper
2025-02-21  0:44 ` ✓ CI.Patch_applied: success for Stop accessing display TIMESTAMP_OVERRIDE in GT code Patchwork
2025-02-21  0:44 ` ✓ CI.checkpatch: " Patchwork
2025-02-21  0:46 ` ✓ CI.KUnit: " Patchwork
2025-02-21  1:02 ` ✓ CI.Build: " Patchwork
2025-02-21  1:05 ` ✓ CI.Hooks: " Patchwork
2025-02-21  1:06 ` ✗ CI.checksparse: warning " Patchwork
2025-02-21  1:26 ` ✓ Xe.CI.BAT: success " Patchwork
2025-02-21 17:01 ` ✗ Xe.CI.Full: failure " Patchwork

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=20250221003843.443559-7-matthew.d.roper@intel.com \
    --to=matthew.d.roper@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox