From: Mika Kahola <mika.kahola@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH v5 11/22] drm/i915/mtl: C20 port clock calculation
Date: Thu, 16 Mar 2023 13:13:24 +0200 [thread overview]
Message-ID: <20230316111335.66915-12-mika.kahola@intel.com> (raw)
In-Reply-To: <20230316111335.66915-1-mika.kahola@intel.com>
Calculate port clock with C20 phy.
v2: Initialize parameters
v3: Revised formula for port clock check
Signed-off-by: Mika Kahola <mika.kahola@intel.com>
---
drivers/gpu/drm/i915/display/intel_cx0_phy.c | 70 ++++++++++++++++++-
drivers/gpu/drm/i915/display/intel_cx0_phy.h | 2 +
.../gpu/drm/i915/display/intel_cx0_phy_regs.h | 12 ++--
drivers/gpu/drm/i915/display/intel_ddi.c | 4 +-
4 files changed, 78 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/i915/display/intel_cx0_phy.c b/drivers/gpu/drm/i915/display/intel_cx0_phy.c
index bc6913a7444a..23ebea25aaa9 100644
--- a/drivers/gpu/drm/i915/display/intel_cx0_phy.c
+++ b/drivers/gpu/drm/i915/display/intel_cx0_phy.c
@@ -1626,6 +1626,18 @@ intel_c10_mpllb_tables_get(struct intel_crtc_state *crtc_state,
return NULL;
}
+static const struct intel_c20pll_state * const *
+intel_c20_pll_tables_get(struct intel_crtc_state *crtc_state,
+ struct intel_encoder *encoder)
+{
+ if (intel_crtc_has_dp_encoder(crtc_state)) {
+ return mtl_c20_dp_tables;
+ }
+
+ MISSING_CASE(encoder->type);
+ return NULL;
+}
+
static int intel_c10mpllb_calc_state(struct intel_crtc_state *crtc_state,
struct intel_encoder *encoder)
{
@@ -1657,15 +1669,36 @@ static int intel_c10mpllb_calc_state(struct intel_crtc_state *crtc_state,
return -EINVAL;
}
+static int intel_c20pll_calc_state(struct intel_crtc_state *crtc_state,
+ struct intel_encoder *encoder)
+{
+ const struct intel_c20pll_state * const *tables;
+ int i;
+
+ tables = intel_c20_pll_tables_get(crtc_state, encoder);
+ if (!tables)
+ return -EINVAL;
+
+ for (i = 0; tables[i]; i++) {
+ if (crtc_state->port_clock <= tables[i]->clock) {
+ crtc_state->cx0pll_state.c20pll_state = *tables[i];
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
int intel_cx0mpllb_calc_state(struct intel_crtc_state *crtc_state,
struct intel_encoder *encoder)
{
struct drm_i915_private *i915 = to_i915(encoder->base.dev);
enum phy phy = intel_port_to_phy(i915, encoder->port);
- drm_WARN_ON(&i915->drm, !intel_is_c10phy(i915, phy));
-
- return intel_c10mpllb_calc_state(crtc_state, encoder);
+ if (intel_is_c10phy(i915, phy))
+ return intel_c10mpllb_calc_state(crtc_state, encoder);
+ else
+ return intel_c20pll_calc_state(crtc_state, encoder);
}
void intel_c10mpllb_readout_hw_state(struct intel_encoder *encoder,
@@ -2111,6 +2144,37 @@ int intel_c10mpllb_calc_port_clock(struct intel_encoder *encoder,
return tmpclk;
}
+int intel_c20pll_calc_port_clock(struct intel_encoder *encoder,
+ const struct intel_c20pll_state *pll_state)
+{
+ unsigned int frac_quot = 0, frac_rem = 0, frac_den = 1;
+ unsigned int multiplier, refclk = 38400;
+ unsigned ref_clk_mpllb_div = 0;
+ unsigned fb_clk_div4_en = 0;
+ unsigned long tmp1, tmp2;
+
+ if (pll_state->mpllb[6] & C20_MPLLB_FRACEN) {
+ multiplier = REG_FIELD_GET(C20_MULTIPLIER_MASK, pll_state->mpllb[0]);
+ ref_clk_mpllb_div = REG_FIELD_GET(C20_REF_CLK_MPLLB_DIV_MASK, pll_state->mpllb[6]);
+ fb_clk_div4_en = REG_FIELD_GET(C20_FB_CLK_DIV4_EN, pll_state->mpllb[6]);
+ frac_den = pll_state->mpllb[7];
+ frac_quot = pll_state->mpllb[8];
+ frac_rem = pll_state->mpllb[9];
+ } else if (pll_state->mplla[6] & C20_MPLLA_FRACEN) {
+ multiplier = REG_FIELD_GET(C20_MULTIPLIER_MASK, pll_state->mplla[0]);
+ ref_clk_mpllb_div = REG_FIELD_GET(C20_REF_CLK_MPLLB_DIV_MASK, pll_state->mpllb[6]);
+ fb_clk_div4_en = REG_FIELD_GET(C20_FB_CLK_DIV4_EN, pll_state->mpllb[6]);
+ frac_den = pll_state->mpllb[7];
+ frac_quot = pll_state->mplla[8];
+ frac_rem = pll_state->mplla[9];
+ }
+
+ tmp1 = DIV_ROUND_CLOSEST(refclk * (1 << (1 + fb_clk_div4_en)), 1 << ref_clk_mpllb_div);
+ tmp2 = (multiplier << 15) + frac_quot + DIV_ROUND_CLOSEST(frac_rem,frac_den);
+
+ return DIV_ROUND_CLOSEST((tmp1 * tmp2) >> 17, 10);
+}
+
static void intel_program_port_clock_ctl(struct intel_encoder *encoder,
const struct intel_crtc_state *crtc_state,
bool lane_reversal)
diff --git a/drivers/gpu/drm/i915/display/intel_cx0_phy.h b/drivers/gpu/drm/i915/display/intel_cx0_phy.h
index 0b46b2ad48a9..0a8e76fd101e 100644
--- a/drivers/gpu/drm/i915/display/intel_cx0_phy.h
+++ b/drivers/gpu/drm/i915/display/intel_cx0_phy.h
@@ -43,6 +43,8 @@ int intel_c10mpllb_calc_port_clock(struct intel_encoder *encoder,
const struct intel_c10mpllb_state *pll_state);
void intel_c10mpllb_state_verify(struct intel_atomic_state *state,
struct intel_crtc_state *new_crtc_state);
+int intel_c20pll_calc_port_clock(struct intel_encoder *encoder,
+ const struct intel_c20pll_state *pll_state);
int intel_cx0_phy_check_hdmi_link_rate(struct intel_hdmi *hdmi, int clock);
void intel_cx0_phy_set_signal_levels(struct intel_encoder *encoder,
const struct intel_crtc_state *crtc_state);
diff --git a/drivers/gpu/drm/i915/display/intel_cx0_phy_regs.h b/drivers/gpu/drm/i915/display/intel_cx0_phy_regs.h
index baadaaf3e39a..929a8aa243c3 100644
--- a/drivers/gpu/drm/i915/display/intel_cx0_phy_regs.h
+++ b/drivers/gpu/drm/i915/display/intel_cx0_phy_regs.h
@@ -208,11 +208,13 @@
#define PHY_C20_A_MPLLB_CNTX_CFG(idx) (0xCB5A - (idx))
#define PHY_C20_B_MPLLB_CNTX_CFG(idx) (0xCB4E - (idx))
-#define C20_MPLLB_FRACEN REG_BIT(13)
-#define C20_MPLLA_FRACEN REG_BIT(14)
-#define C20_MULTIPLIER_MASK REG_GENMASK(11, 0)
-#define C20_MPLLB_TX_CLK_DIV_MASK REG_GENMASK(15, 13)
-#define C20_MPLLA_TX_CLK_DIV_MASK REG_GENMASK(10, 8)
+#define C20_MPLLB_FRACEN REG_BIT(13)
+#define C20_MPLLA_FRACEN REG_BIT(14)
+#define C20_MPLLB_TX_CLK_DIV_MASK REG_GENMASK(15, 13)
+#define C20_REF_CLK_MPLLB_DIV_MASK REG_GENMASK(12, 10)
+#define C20_MULTIPLIER_MASK REG_GENMASK(11, 0)
+#define C20_MPLLA_TX_CLK_DIV_MASK REG_GENMASK(10, 8)
+#define C20_FB_CLK_DIV4_EN REG_BIT(13)
#define RAWLANEAONX_DIG_TX_MPLLB_CAL_DONE_BANK(idx) (0x303D + (idx))
diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
index d94add6e322d..30a1aa7d776a 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -3519,13 +3519,13 @@ static void mtl_ddi_get_config(struct intel_encoder *encoder,
if (intel_is_c10phy(i915, phy)) {
intel_c10mpllb_readout_hw_state(encoder, &crtc_state->cx0pll_state.c10mpllb_state);
intel_c10mpllb_dump_hw_state(i915, &crtc_state->cx0pll_state.c10mpllb_state);
+ crtc_state->port_clock = intel_c10mpllb_calc_port_clock(encoder, &crtc_state->cx0pll_state.c10mpllb_state);
} else {
intel_c20pll_readout_hw_state(encoder, &crtc_state->cx0pll_state.c20pll_state);
intel_c20pll_dump_hw_state(i915, &crtc_state->cx0pll_state.c20pll_state);
+ crtc_state->port_clock = intel_c20pll_calc_port_clock(encoder, &crtc_state->cx0pll_state.c20pll_state);
}
- crtc_state->port_clock = intel_c10mpllb_calc_port_clock(encoder, &crtc_state->cx0pll_state.c10mpllb_state);
-
intel_ddi_get_config(encoder, crtc_state);
}
--
2.34.1
next prev parent reply other threads:[~2023-03-16 11:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-16 11:13 [Intel-gfx] [PATCH v5 00/22] drm/i915/mtl: Add C10 and C20 phy support Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 01/22] drm/i915/mtl: Initial DDI port setup Mika Kahola
2023-03-20 18:25 ` Lucas De Marchi
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 02/22] drm/i915/mtl: Add DP rates Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 03/22] drm/i915/mtl: Create separate reg file for PICA registers Mika Kahola
2023-03-20 18:06 ` Lucas De Marchi
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 04/22] drm/i915/mtl: Add Support for C10 PHY message bus and pll programming Mika Kahola
2023-03-24 17:47 ` Gustavo Sousa
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 05/22] drm/i915/mtl: Add C10 phy programming for HDMI Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 06/22] drm/i915/mtl: Add vswing programming for C10 phys Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 07/22] drm/i915/mtl: Add support for PM DEMAND Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 08/22] drm/i915/mtl: C20 PLL programming Mika Kahola
2023-03-24 19:56 ` Gustavo Sousa
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 09/22] drm/i915/mtl: C20 HW readout Mika Kahola
2023-03-24 20:21 ` Gustavo Sousa
2023-03-27 9:25 ` Imre Deak
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 10/22] drm/i915/mtl: Dump C20 pll hw state Mika Kahola
2023-03-16 11:13 ` Mika Kahola [this message]
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 12/22] drm/i915/mtl: C20 HDMI state calculations Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 13/22] drm/i915/mtl: Add voltage swing sequence for C20 Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 14/22] drm/i915/mtl: For DP2.0 10G and 20G rates use MPLLA Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 15/22] drm/i915/mtl: Enabling/disabling sequence Thunderbolt pll Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 16/22] drm/i915/mtl: Readout Thunderbolt HW state Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 17/22] drm/i915/mtl: Enable TC ports Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 18/22] drm/i915/mtl: MTL PICA hotplug detection Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 19/22] drm/i915/mtl: Define mask for DDI AUX interrupts Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 20/22] drm/i915/mtl: Power up TCSS Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 21/22] drm/i915/mtl: TypeC HPD live status query Mika Kahola
2023-03-16 11:13 ` [Intel-gfx] [PATCH v5 22/22] drm/i915/mtl: Pin assignment for TypeC Mika Kahola
2023-04-11 14:32 ` Luca Coelho
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=20230316111335.66915-12-mika.kahola@intel.com \
--to=mika.kahola@intel.com \
--cc=intel-gfx@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