Skip to contentSkip to conversation

drm/vc4: hdmi: Support the 4k @ 60Hz modes

PATCH Superseded Maxime Ripard 3 participants 24 messages Feb 25, 2021 – Mar 17, 2021

Subsystems (5)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover drm/vc4: hdmi: Support the 4k @ 60Hz modes

Hi,

Here is a series that enables the higher resolutions on the HDMI0 Controller found in the BCM2711 (RPi4).

In order to work it needs a few adjustments to config.txt, most notably to enable the enable_hdmi_4kp60 and force_turbo options.

The firmware also has a glitch at the moment and will not properly release the BSC controllers, which will make the EDID retrieval fail.

We can work around this using the following config.txt options:

disable_fw_kms_setup=1
hdmi_edid_file:0=1
hdmi_edid_filename:0=1366x768.bin
hdmi_ignore_edid:0=1
hdmi_edid_file:1=1
hdmi_edid_filename:1=1366x768.bin
hdmi_ignore_edid:1=1

A fix will come for the firmware eventually.

Let me know what you think,
Maxime

Maxime Ripard (8):
clk: Add range accessors
drm/vc4: hvs: Make the HVS bind first
drm/vc4: hdmi: Properly compute the BVB clock rate drm/vc4: hdmi: Check and warn if we can't reach 4kp60 frequencies drm/vc4: hdmi: Enable the scrambler
drm/vc4: hdmi: Raise the maximum clock rate
drm/vc4: plane: Fix typo in scaler width and height drm/vc4: plane: Remove redundant assignment

 drivers/clk/clk.c                   | 30 ++++++++++
 drivers/gpu/drm/vc4/vc4_drv.c       | 11 +++-
 drivers/gpu/drm/vc4/vc4_hdmi.c      | 88 ++++++++++++++++++++++++++---
 drivers/gpu/drm/vc4/vc4_hdmi.h      |  8 +++
 drivers/gpu/drm/vc4/vc4_hdmi_regs.h |  3 +
 drivers/gpu/drm/vc4/vc4_plane.c     |  5 +-
 include/linux/clk.h                 | 16 ++++++
 7 files changed, 148 insertions(+), 13 deletions(-)
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/8 clk: Add range accessors

Some devices might need to access the current available range of a clock to discover their capabilities. Let's add those accessors.

---
 drivers/clk/clk.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 46 insertions(+)
drivers/clk/clk.c +30 -0
index 8c1d04db990d..b7307d4f090d 100644
@@ -2407,6 +2407,36 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_set_max_rate);
 
+long clk_get_min_rate(struct clk *clk)
+{
+	unsigned long min_rate, max_rate;
+
+	if (!clk)
+		return 0;
+
+	clk_prepare_lock();
+	clk_core_get_boundaries(clk->core, &min_rate, &max_rate);
+	clk_prepare_unlock();
+
+	return min_rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_min_rate);
+
+long clk_get_max_rate(struct clk *clk)
+{
+	unsigned long min_rate, max_rate;
+
+	if (!clk)
+		return 0;
+
+	clk_prepare_lock();
+	clk_core_get_boundaries(clk->core, &min_rate, &max_rate);
+	clk_prepare_unlock();
+
+	return max_rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_max_rate);
+
 /**
  * clk_get_parent - return the parent of a clk
  * @clk: the clk whose parent gets returned
include/linux/clk.h +16 -0
index 31ff1bf1b79f..6f0c00ddf3ac 100644
@@ -709,6 +709,22 @@ int clk_set_min_rate(struct clk *clk, unsigned long rate);
  */
 int clk_set_max_rate(struct clk *clk, unsigned long rate);
 
+/**
+ * clk_get_min_rate - get the minimum clock rate for a clock source
+ * @clk: clock source
+  *
+ * Returns the minimum rate or negative errno.
+ */
+long clk_get_min_rate(struct clk *clk);
+
+/**
+ * clk_get_max_rate - get the maximum clock rate for a clock source
+ * @clk: clock source
+  *
+ * Returns the maximum rate or negative errno.
+ */
+long clk_get_max_rate(struct clk *clk);
+
 /**
  * clk_set_parent - set the parent clock source for this clock
  * @clk: clock source
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#2 lore raw

Re: [PATCH 1/8] clk: Add range accessors

Quoting Maxime Ripard (2021-02-25 07:59:02)

Quoted 2 lines

Some devices might need to access the current available range of a clock to discover their capabilities. Let's add those accessors.

This needs more than two sentences to describe what's required.

Quoted 12 lines
---
 drivers/clk/clk.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 46 insertions(+)
drivers/clk/clk.c +0 -0
index 8c1d04db990d..b7307d4f090d 100644

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2410

Quoted 4 lines
drivers/clk/clk.c +1 -0
@@ -2407,6 +2407,36 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_set_max_rate);
 
+long clk_get_min_rate(struct clk *clk)

I need to read the rest of the patches but I don't see the justification for this sort of API vs. having the consumer constrain the clk frequency that it wants. Is the code that's setting the min/max constraints not the same as the code that's calling this API? Would an OPP table better serve this so the device knows what frequencies are valid?s Please provide the use case/justification in the commit text.

Why two functions instead of one function to get both min and max?

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2417

Quoted 7 lines
drivers/clk/clk.c +7 -0
+{
+       unsigned long min_rate, max_rate;
+
+       if (!clk)
+               return 0;
+
+       clk_prepare_lock();

Please add a comment indicating why we grab the lock. Yes clk_core_get_boundaries() has a lock held assertion, but I don't know why we care about the lock here besides that we don't want the consumers to change while we calculate the boundaries as it may be some inaccurate number.

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2430

Quoted 13 lines
drivers/clk/clk.c +13 -0
+       clk_core_get_boundaries(clk->core, &min_rate, &max_rate);
+       clk_prepare_unlock();
+
+       return min_rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_min_rate);
+
+long clk_get_max_rate(struct clk *clk)
+{
+       unsigned long min_rate, max_rate;
+
+       if (!clk)
+               return 0;

ULONG_MAX?

Quoted 17 lines
drivers/clk/clk.c +9 -0
+
+       clk_prepare_lock();
+       clk_core_get_boundaries(clk->core, &min_rate, &max_rate);
+       clk_prepare_unlock();
+
+       return max_rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_max_rate);
+
 /**
  * clk_get_parent - return the parent of a clk
  * @clk: the clk whose parent gets returned
include/linux/clk.h +0 -0
index 31ff1bf1b79f..6f0c00ddf3ac 100644

include/linux/clk.h int clk_set_min_rate(struct clk *clk, unsigned long rate); · line 716

Quoted 8 lines
include/linux/clk.h +5 -0
@@ -709,6 +709,22 @@ int clk_set_min_rate(struct clk *clk, unsigned long rate);
  */
 int clk_set_max_rate(struct clk *clk, unsigned long rate);
 
+/**
+ * clk_get_min_rate - get the minimum clock rate for a clock source
+ * @clk: clock source
+  *
+ * Returns the minimum rate or negative errno.

Hmm?

include/linux/clk.h int clk_set_min_rate(struct clk *clk, unsigned long rate); · line 718

Quoted 2 lines
include/linux/clk.h +2 -0
+ */
+long clk_get_min_rate(struct clk *clk);

Why long instead of unsigned long? Error values don't seem to be returned.

include/linux/clk.h int clk_set_min_rate(struct clk *clk, unsigned long rate);

Quoted 13 lines
include/linux/clk.h +9 -1
+
+/**
+ * clk_get_max_rate - get the maximum clock rate for a clock source
+ * @clk: clock source
+  *
+ * Returns the maximum rate or negative errno.
+ */
+long clk_get_max_rate(struct clk *clk);
+
 /**
  * clk_set_parent - set the parent clock source for this clock
  * @clk: clock source
--

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 1/8] clk: Add range accessors

Hi Stephen,

Quoted 21 lines · Stephen Boyd

Quoting Maxime Ripard (2021-02-25 07:59:02)

Quoted 2 lines

Some devices might need to access the current available range of a clock to discover their capabilities. Let's add those accessors.

This needs more than two sentences to describe what's required.

Quoted 15 lines
---
 drivers/clk/clk.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 46 insertions(+)
drivers/clk/clk.c +0 -0
index 8c1d04db990d..b7307d4f090d 100644
@@ -2407,6 +2407,36 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_set_max_rate);
 
Quoted 8 lines

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2410

Quoted 1 line
drivers/clk/clk.c +1 -0
+long clk_get_min_rate(struct clk *clk)

I need to read the rest of the patches but I don't see the justification for this sort of API vs. having the consumer constrain the clk frequency that it wants. Is the code that's setting the min/max constraints not the same as the code that's calling this API? Would an OPP table better serve this so the device knows what frequencies are valid?s Please provide the use case/justification in the commit text.

The patch that uses it is the patch 4

The issue I'm trying to solve is that all the RaspberryPi have a configuration file for the firmware, and the firmware is in charge of the clocks communicating through a mailbox interface.

By default, one of the main clocks in the system can only reach 500MHz, and that's the range reported by the firmware when queried. However, in order to support display modes with a fairly high bandwidth such as 4k at 60Hz, that clock needs to be raised to at least 550MHz, and the firmware configuration has a special parameter for that one. Setting that parameter will increase the range of the clock to have proper boundaries for that display mode.

If a user doesn't enable it and tries to use those display modes, the display will be completely blank.

There's no way to query the firmware configuration directly, so we can instead query the range of the clock and see if the firmware enables us to use those modes, warn the user and ignore the modes that wouldn't work. That's what those accessors are here for

Quoted 1 line

Why two functions instead of one function to get both min and max?

Since we have clk_set_min_rate and clk_set_max_rate, it made sense to me to mirror that, but I'd be happy to change if you think otherwise

I'll address your other commenst

Maxime

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#4 lore raw

Re: [PATCH 1/8] clk: Add range accessors

Quoting Maxime Ripard (2021-03-03 00:45:27)

Quoted 47 lines

Hi Stephen,

Quoted 21 lines · Stephen Boyd

Quoting Maxime Ripard (2021-02-25 07:59:02)

Quoted 2 lines

Some devices might need to access the current available range of a clock to discover their capabilities. Let's add those accessors.

This needs more than two sentences to describe what's required.

Quoted 15 lines
---
 drivers/clk/clk.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 46 insertions(+)
drivers/clk/clk.c +0 -0
index 8c1d04db990d..b7307d4f090d 100644
@@ -2407,6 +2407,36 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_set_max_rate);
 
Quoted 8 lines

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2410

Quoted 1 line
drivers/clk/clk.c +1 -0
+long clk_get_min_rate(struct clk *clk)

I need to read the rest of the patches but I don't see the justification for this sort of API vs. having the consumer constrain the clk frequency that it wants. Is the code that's setting the min/max constraints not the same as the code that's calling this API? Would an OPP table better serve this so the device knows what frequencies are valid?s Please provide the use case/justification in the commit text.

The patch that uses it is the patch 4

The issue I'm trying to solve is that all the RaspberryPi have a configuration file for the firmware, and the firmware is in charge of the clocks communicating through a mailbox interface.

By default, one of the main clocks in the system can only reach 500MHz, and that's the range reported by the firmware when queried. However, in order to support display modes with a fairly high bandwidth such as 4k at 60Hz, that clock needs to be raised to at least 550MHz, and the firmware configuration has a special parameter for that one. Setting that parameter will increase the range of the clock to have proper boundaries for that display mode.

Quoted 7 lines

If a user doesn't enable it and tries to use those display modes, the display will be completely blank.

There's no way to query the firmware configuration directly, so we can instead query the range of the clock and see if the firmware enables us to use those modes, warn the user and ignore the modes that wouldn't work. That's what those accessors are here for

How does the clk driver query the firmware but it can't be done directly by the drm driver?

Quoted 6 lines
Quoted 2 lines

Why two functions instead of one function to get both min and max?

Since we have clk_set_min_rate and clk_set_max_rate, it made sense to me to mirror that, but I'd be happy to change if you think otherwise

Does using clk_round_rate() work just as well?
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH 1/8] clk: Add range accessors

Quoted 51 lines · Stephen Boyd

Quoting Maxime Ripard (2021-03-03 00:45:27)

Quoted 50 lines

Hi Stephen,

Quoted 21 lines · Stephen Boyd

Quoting Maxime Ripard (2021-02-25 07:59:02)

Quoted 2 lines

Some devices might need to access the current available range of a clock to discover their capabilities. Let's add those accessors.

This needs more than two sentences to describe what's required.

Quoted 15 lines
---
 drivers/clk/clk.c   | 30 ++++++++++++++++++++++++++++++
 include/linux/clk.h | 16 ++++++++++++++++
 2 files changed, 46 insertions(+)
drivers/clk/clk.c +0 -0
index 8c1d04db990d..b7307d4f090d 100644
@@ -2407,6 +2407,36 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL_GPL(clk_set_max_rate);
 
Quoted 8 lines

drivers/clk/clk.c int clk_set_max_rate(struct clk *clk, unsigned long rate) · line 2410

Quoted 1 line
drivers/clk/clk.c +1 -0
+long clk_get_min_rate(struct clk *clk)

I need to read the rest of the patches but I don't see the justification for this sort of API vs. having the consumer constrain the clk frequency that it wants. Is the code that's setting the min/max constraints not the same as the code that's calling this API? Would an OPP table better serve this so the device knows what frequencies are valid?s Please provide the use case/justification in the commit text.

The patch that uses it is the patch 4

The issue I'm trying to solve is that all the RaspberryPi have a configuration file for the firmware, and the firmware is in charge of the clocks communicating through a mailbox interface.

By default, one of the main clocks in the system can only reach 500MHz, and that's the range reported by the firmware when queried. However, in order to support display modes with a fairly high bandwidth such as 4k at 60Hz, that clock needs to be raised to at least 550MHz, and the firmware configuration has a special parameter for that one. Setting that parameter will increase the range of the clock to have proper boundaries for that display mode.

If a user doesn't enable it and tries to use those display modes, the display will be completely blank.

Quoted 7 lines
Quoted 4 lines

There's no way to query the firmware configuration directly, so we can instead query the range of the clock and see if the firmware enables us to use those modes, warn the user and ignore the modes that wouldn't work. That's what those accessors are here for

How does the clk driver query the firmware but it can't be done directly by the drm driver?

The configuration is done through a text file accessed by the firmware. What I meant was that the kernel cannot access the content of that file to make sure the right options have been enabled.

However, it can indeed communicate with the firmware through the extent of the API it provides, but it's fairly limited. In our case, the only way to tell is to look for side effects of the configuration option, ie the maximum rate of the clock that has been increased.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Why two functions instead of one function to get both min and max?

Since we have clk_set_min_rate and clk_set_max_rate, it made sense to me to mirror that, but I'd be happy to change if you think otherwise

Does using clk_round_rate() work just as well?

I guess it could work too, I'll try it out

Maxime

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

PATCH 2/8 drm/vc4: hvs: Make the HVS bind first

In reply to Maxime Ripard

We'll need to have the HVS binding before the HDMI controllers so that we can check whether the firmware allows to run in 4kp60. Reorder a bit the component list, and document the current constraints we're aware of.

---
 drivers/gpu/drm/vc4/vc4_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_drv.c +10 -1
index 556ad0f02a0d..0310590ee66e 100644
@@ -303,12 +303,21 @@ static const struct component_master_ops vc4_drm_ops = {
 	.unbind = vc4_drm_unbind,
 };
 
+/*
+ * This list determines the binding order of our components, and we have
+ * a few constraints:
+ *   - The TXP driver needs to be bound before the PixelValves (CRTC)
+ *     but after the HVS to set the possible_crtc field properly
+ *   - The HDMI driver needs to be bound after the HVS so that we can
+ *     lookup the HVS maximum core clock rate and figure out if we
+ *     support 4kp60 or not.
+ */
 static struct platform_driver *const component_drivers[] = {
+	&vc4_hvs_driver,
 	&vc4_hdmi_driver,
 	&vc4_vec_driver,
 	&vc4_dpi_driver,
 	&vc4_dsi_driver,
-	&vc4_hvs_driver,
 	&vc4_txp_driver,
 	&vc4_crtc_driver,
 	&vc4_v3d_driver,
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by on v1 2/8
#7 lore raw

Re: [PATCH 2/8] drm/vc4: hvs: Make the HVS bind first

Quoted 6 lines · Maxime Ripard

We'll need to have the HVS binding before the HDMI controllers so that we can check whether the firmware allows to run in 4kp60. Reorder a bit the component list, and document the current constraints we're aware of.

Based on my understanding of bind ordering this makes sense, but I don't consider myself an expert there.

Quoted 32 lines
---
 drivers/gpu/drm/vc4/vc4_drv.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_drv.c +10 -2
index 556ad0f02a0d..0310590ee66e 100644
@@ -303,12 +303,21 @@ static const struct component_master_ops vc4_drm_ops = {
        .unbind = vc4_drm_unbind,
 };
 
+/*
+ * This list determines the binding order of our components, and we have
+ * a few constraints:
+ *   - The TXP driver needs to be bound before the PixelValves (CRTC)
+ *     but after the HVS to set the possible_crtc field properly
+ *   - The HDMI driver needs to be bound after the HVS so that we can
+ *     lookup the HVS maximum core clock rate and figure out if we
+ *     support 4kp60 or not.
+ */
 static struct platform_driver *const component_drivers[] = {
+       &vc4_hvs_driver,
        &vc4_hdmi_driver,
        &vc4_vec_driver,
        &vc4_dpi_driver,
        &vc4_dsi_driver,
-       &vc4_hvs_driver,
        &vc4_txp_driver,
        &vc4_crtc_driver,
        &vc4_v3d_driver,
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

PATCH 3/8 drm/vc4: hdmi: Properly compute the BVB clock rate

In reply to Maxime Ripard

The BVB clock rate computation doesn't take into account a mode clock of 594MHz that we're going to need to support 4k60.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +3 -8
index eee9751009c2..b5bc742993a4 100644
@@ -91,7 +91,6 @@
 # define VC4_HD_M_ENABLE			BIT(0)
 
 #define CEC_CLOCK_FREQ 40000
-#define VC4_HSM_MID_CLOCK 149985000
 
 #define HDMI_14_MAX_TMDS_CLK   (340 * 1000 * 1000)
 
@@ -739,7 +738,7 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
 		conn_state_to_vc4_hdmi_conn_state(conn_state);
 	struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
 	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-	unsigned long pixel_rate, hsm_rate;
+	unsigned long bvb_rate, pixel_rate, hsm_rate;
 	int ret;
 
 	ret = pm_runtime_get_sync(&vc4_hdmi->pdev->dev);
@@ -793,12 +792,8 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
 
 	vc4_hdmi_cec_update_clk_div(vc4_hdmi);
 
-	/*
-	 * FIXME: When the pixel freq is 594MHz (4k60), this needs to be setup
-	 * at 300MHz.
-	 */
-	ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock,
-			       (hsm_rate > VC4_HSM_MID_CLOCK ? 150000000 : 75000000));
+	bvb_rate = roundup(mode->clock * 1000 / 2, 75000000);
+	ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock, bvb_rate);
 	if (ret) {
 		DRM_ERROR("Failed to set pixel bvb clock rate: %d\n", ret);
 		clk_disable_unprepare(vc4_hdmi->hsm_clock);
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#9 lore raw

Re: [PATCH 3/8] drm/vc4: hdmi: Properly compute the BVB clock rate

Hi Maxime

Quoted 31 lines · Maxime Ripard

The BVB clock rate computation doesn't take into account a mode clock of 594MHz that we're going to need to support 4k60.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -2
index eee9751009c2..b5bc742993a4 100644
@@ -91,7 +91,6 @@
 # define VC4_HD_M_ENABLE                       BIT(0)
 
 #define CEC_CLOCK_FREQ 40000
-#define VC4_HSM_MID_CLOCK 149985000
 
 #define HDMI_14_MAX_TMDS_CLK   (340 * 1000 * 1000)
 
@@ -739,7 +738,7 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
                conn_state_to_vc4_hdmi_conn_state(conn_state);
        struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
        struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-       unsigned long pixel_rate, hsm_rate;
+       unsigned long bvb_rate, pixel_rate, hsm_rate;
        int ret;
 
        ret = pm_runtime_get_sync(&vc4_hdmi->pdev->dev);

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, · line 795

Quoted 10 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -6
@@ -793,12 +792,8 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
 
        vc4_hdmi_cec_update_clk_div(vc4_hdmi);
 
-       /*
-        * FIXME: When the pixel freq is 594MHz (4k60), this needs to be setup
-        * at 300MHz.
-        */
-       ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock,
-                              (hsm_rate > VC4_HSM_MID_CLOCK ? 150000000 : 75000000));
+       bvb_rate = roundup(mode->clock * 1000 / 2, 75000000);

Minor hesitation here that I would need to check the hardware over. As I read your code, if the clock falls 300MHz and 450MHz then you'd ask for a bvb_rate of 225MHz. Depending on what the source clock is that may not be valid.
The firmware goes for 75, 150, or 300MHz only.

Dave

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
+       ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock, bvb_rate);
        if (ret) {
                DRM_ERROR("Failed to set pixel bvb clock rate: %d\n", ret);
                clk_disable_unprepare(vc4_hdmi->hsm_clock);
--

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#10 lore raw

Re: [PATCH 3/8] drm/vc4: hdmi: Properly compute the BVB clock rate

Quoted 38 lines · Dave Stevenson

Hi Maxime

Quoted 34 lines · Maxime Ripard

The BVB clock rate computation doesn't take into account a mode clock of 594MHz that we're going to need to support 4k60.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -2
index eee9751009c2..b5bc742993a4 100644
@@ -91,7 +91,6 @@
 # define VC4_HD_M_ENABLE                       BIT(0)
 
 #define CEC_CLOCK_FREQ 40000
-#define VC4_HSM_MID_CLOCK 149985000
 
 #define HDMI_14_MAX_TMDS_CLK   (340 * 1000 * 1000)
 
@@ -739,7 +738,7 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
                conn_state_to_vc4_hdmi_conn_state(conn_state);
        struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
        struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
-       unsigned long pixel_rate, hsm_rate;
+       unsigned long bvb_rate, pixel_rate, hsm_rate;
        int ret;
 
        ret = pm_runtime_get_sync(&vc4_hdmi->pdev->dev);
@@ -793,12 +792,8 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder,
 
        vc4_hdmi_cec_update_clk_div(vc4_hdmi);
 
Quoted 13 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, · line 795

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -6
-       /*
-        * FIXME: When the pixel freq is 594MHz (4k60), this needs to be setup
-        * at 300MHz.
-        */
-       ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock,
-                              (hsm_rate > VC4_HSM_MID_CLOCK ? 150000000 : 75000000));
+       bvb_rate = roundup(mode->clock * 1000 / 2, 75000000);

Minor hesitation here that I would need to check the hardware over. As I read your code, if the clock falls 300MHz and 450MHz then you'd ask for a bvb_rate of 225MHz. Depending on what the source clock is that may not be valid.
The firmware goes for 75, 150, or 300MHz only.

The information I have says it has to be an integer divide of 600MHz (PLLC @ 3GHz / 5), so 225MHz is not valid.

(Minor contradictory information though as PLLC is bumped to 3.3GHz with enable_4kp60, but we still appear to get 300MHz for BVB after the /5. A little more checking warranted around here).

Quoted 9 lines

Dave

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
+       ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock, bvb_rate);
        if (ret) {
                DRM_ERROR("Failed to set pixel bvb clock rate: %d\n", ret);
                clk_disable_unprepare(vc4_hdmi->hsm_clock);
--

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

PATCH 4/8 drm/vc4: hdmi: Check and warn if we can't reach 4kp60 frequencies

In reply to Maxime Ripard

In order to reach the frequencies needed to output at 594MHz, the firmware needs to be configured with the appropriate parameters in the config.txt file (enable_hdmi_4kp60 and force_turbo).

Let's detect it at bind time, warn the user if we can't, and filter out the relevant modes.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 17 +++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi.h |  8 ++++++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +17 -0
index b5bc742993a4..f05f6da286f7 100644
@@ -953,6 +953,9 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
 	if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
 		return -EINVAL;
 
+	if (vc4_hdmi->disable_4kp60 && (pixel_rate > HDMI_14_MAX_TMDS_CLK))
+		return -EINVAL;
+
 	vc4_state->pixel_rate = pixel_rate;
 
 	return 0;
@@ -972,6 +975,9 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
 	if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
 		return MODE_CLOCK_HIGH;
 
+	if (vc4_hdmi->disable_4kp60 && ((mode->clock * 1000) > HDMI_14_MAX_TMDS_CLK))
+		return MODE_CLOCK_HIGH;
+
 	return MODE_OK;
 }
 
@@ -1986,6 +1992,17 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	vc4_hdmi->disable_wifi_frequencies =
 		of_property_read_bool(dev->of_node, "wifi-2.4ghz-coexistence");
 
+	if (variant->max_pixel_clock == 600000000) {
+		struct vc4_dev *vc4 = to_vc4_dev(drm);
+		long max_rate = clk_get_max_rate(vc4->hvs->core_clk);
+
+		if (max_rate < 550000000) {
+			drm_warn(drm, "The core clock cannot reach frequencies high enough to support 4k @ 60Hz.");
+			drm_warn(drm, "Please change your config.txt file to add hdmi_enable_4kp60 and force_turbo");
+			vc4_hdmi->disable_4kp60 = true;
+		}
+	}
+
 	if (vc4_hdmi->variant->reset)
 		vc4_hdmi->variant->reset(vc4_hdmi);
 
drivers/gpu/drm/vc4/vc4_hdmi.h +8 -0
index 3cebd1fd00fc..3cd021136402 100644
@@ -154,6 +154,14 @@ struct vc4_hdmi {
 	 */
 	bool disable_wifi_frequencies;
 
+	/*
+	 * Even if HDMI0 on the RPi4 can output modes requiring a pixel
+	 * rate higher than 297MHz, it needs some adjustments in the
+	 * config.txt file to be able to do so and thus won't always be
+	 * available.
+	 */
+	bool disable_4kp60;
+
 	struct cec_adapter *cec_adap;
 	struct cec_msg cec_rx_msg;
 	bool cec_tx_ok;
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#12 lore raw

Re: [PATCH 4/8] drm/vc4: hdmi: Check and warn if we can't reach 4kp60 frequencies

Hi Maxime

Quoted 4 lines · Maxime Ripard

In order to reach the frequencies needed to output at 594MHz, the firmware needs to be configured with the appropriate parameters in the config.txt file (enable_hdmi_4kp60 and force_turbo).

force_turbo isn't the right way to go about this as it permanently bumps all the clocks up, even if running the display at VGA.

Quoted 34 lines

Let's detect it at bind time, warn the user if we can't, and filter out the relevant modes.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 17 +++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi.h |  8 ++++++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +6 -0
index b5bc742993a4..f05f6da286f7 100644
@@ -953,6 +953,9 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
        if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
                return -EINVAL;
 
+       if (vc4_hdmi->disable_4kp60 && (pixel_rate > HDMI_14_MAX_TMDS_CLK))
+               return -EINVAL;
+
        vc4_state->pixel_rate = pixel_rate;
 
        return 0;
@@ -972,6 +975,9 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
        if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
                return MODE_CLOCK_HIGH;
 
+       if (vc4_hdmi->disable_4kp60 && ((mode->clock * 1000) > HDMI_14_MAX_TMDS_CLK))
+               return MODE_CLOCK_HIGH;
+
        return MODE_OK;
 }
 

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) · line 2001

Quoted 10 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +7 -0
@@ -1986,6 +1992,17 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
        vc4_hdmi->disable_wifi_frequencies =
                of_property_read_bool(dev->of_node, "wifi-2.4ghz-coexistence");
 
+       if (variant->max_pixel_clock == 600000000) {
+               struct vc4_dev *vc4 = to_vc4_dev(drm);
+               long max_rate = clk_get_max_rate(vc4->hvs->core_clk);
+
+               if (max_rate < 550000000) {
+                       drm_warn(drm, "The core clock cannot reach frequencies high enough to support 4k @ 60Hz.");
+                       drm_warn(drm, "Please change your config.txt file to add hdmi_enable_4kp60 and force_turbo");

Do we really want to warn in bind? Again you could have a VGA resolution monitor attached but that would trigger this warning. Can we warn (once) on processing the mode list and filtering out a clk

Quoted 1 line

HDMI_14_MAX_TMDS_CLK mode instead?

And mentioning force_turbo is again wrong.

Dave

Quoted 27 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +4 -0
+                       vc4_hdmi->disable_4kp60 = true;
+               }
+       }
+
        if (vc4_hdmi->variant->reset)
                vc4_hdmi->variant->reset(vc4_hdmi);
drivers/gpu/drm/vc4/vc4_hdmi.h +8 -1
index 3cebd1fd00fc..3cd021136402 100644
@@ -154,6 +154,14 @@ struct vc4_hdmi {
         */
        bool disable_wifi_frequencies;
 
+       /*
+        * Even if HDMI0 on the RPi4 can output modes requiring a pixel
+        * rate higher than 297MHz, it needs some adjustments in the
+        * config.txt file to be able to do so and thus won't always be
+        * available.
+        */
+       bool disable_4kp60;
+
        struct cec_adapter *cec_adap;
        struct cec_msg cec_rx_msg;
        bool cec_tx_ok;
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw

Re: [PATCH 4/8] drm/vc4: hdmi: Check and warn if we can't reach 4kp60 frequencies

Hi Dave,

Thanks for your review

Quoted 8 lines · Dave Stevenson
Quoted 4 lines · Maxime Ripard

In order to reach the frequencies needed to output at 594MHz, the firmware needs to be configured with the appropriate parameters in the config.txt file (enable_hdmi_4kp60 and force_turbo).

force_turbo isn't the right way to go about this as it permanently bumps all the clocks up, even if running the display at VGA.

so enable_hdmi_4kp60 is enough?

Quoted 37 lines
Quoted 37 lines

Let's detect it at bind time, warn the user if we can't, and filter out the relevant modes.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 17 +++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi.h |  8 ++++++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +6 -0
index b5bc742993a4..f05f6da286f7 100644
@@ -953,6 +953,9 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
        if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
                return -EINVAL;
 
+       if (vc4_hdmi->disable_4kp60 && (pixel_rate > HDMI_14_MAX_TMDS_CLK))
+               return -EINVAL;
+
        vc4_state->pixel_rate = pixel_rate;
 
        return 0;
@@ -972,6 +975,9 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
        if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
                return MODE_CLOCK_HIGH;
 
+       if (vc4_hdmi->disable_4kp60 && ((mode->clock * 1000) > HDMI_14_MAX_TMDS_CLK))
+               return MODE_CLOCK_HIGH;
+
        return MODE_OK;
 }
 
@@ -1986,6 +1992,17 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
        vc4_hdmi->disable_wifi_frequencies =
                of_property_read_bool(dev->of_node, "wifi-2.4ghz-coexistence");
 
Quoted 12 lines

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) · line 2001

Quoted 7 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +7 -0
+       if (variant->max_pixel_clock == 600000000) {
+               struct vc4_dev *vc4 = to_vc4_dev(drm);
+               long max_rate = clk_get_max_rate(vc4->hvs->core_clk);
+
+               if (max_rate < 550000000) {
+                       drm_warn(drm, "The core clock cannot reach frequencies high enough to support 4k @ 60Hz.");
+                       drm_warn(drm, "Please change your config.txt file to add hdmi_enable_4kp60 and force_turbo");

Do we really want to warn in bind? Again you could have a VGA resolution monitor attached but that would trigger this warning. Can we warn (once) on processing the mode list and filtering out a clk

Quoted 1 line

HDMI_14_MAX_TMDS_CLK mode instead?

That's a good idea indeed, I'll rework the patch to do that

Thanks!
Maxime

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#14 lore raw

Re: [PATCH 4/8] drm/vc4: hdmi: Check and warn if we can't reach 4kp60 frequencies

Quoted 8 lines · Maxime Ripard

Hi Dave,

Thanks for your review

Quoted 2 lines · Dave Stevenson
Quoted 1 line · Maxime Ripard
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

In order to reach the frequencies needed to output at 594MHz, the firmware needs to be configured with the appropriate parameters in the config.txt file (enable_hdmi_4kp60 and force_turbo).

force_turbo isn't the right way to go about this as it permanently bumps all the clocks up, even if running the display at VGA.

so enable_hdmi_4kp60 is enough?

No, but force_turbo=1 is the wrong way to go about fixing that.

I'll start a thread with Dom & Tim to discuss the best way of doing this. Immediate thoughts are that either vc4_hdmi needs to request the core clock be increased, or potentially the firmware could note the boosted BVB rate and increase core accordingly.

Dave

Quoted 48 lines
Quoted 48 lines
Quoted 34 lines

Let's detect it at bind time, warn the user if we can't, and filter out the relevant modes.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 17 +++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi.h |  8 ++++++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +6 -0
index b5bc742993a4..f05f6da286f7 100644
@@ -953,6 +953,9 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder,
        if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
                return -EINVAL;
 
+       if (vc4_hdmi->disable_4kp60 && (pixel_rate > HDMI_14_MAX_TMDS_CLK))
+               return -EINVAL;
+
        vc4_state->pixel_rate = pixel_rate;
 
        return 0;
@@ -972,6 +975,9 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
        if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
                return MODE_CLOCK_HIGH;
 
+       if (vc4_hdmi->disable_4kp60 && ((mode->clock * 1000) > HDMI_14_MAX_TMDS_CLK))
+               return MODE_CLOCK_HIGH;
+
        return MODE_OK;
 }
 

drivers/gpu/drm/vc4/vc4_hdmi.c static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) · line 2001

Quoted 10 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +7 -0
@@ -1986,6 +1992,17 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
        vc4_hdmi->disable_wifi_frequencies =
                of_property_read_bool(dev->of_node, "wifi-2.4ghz-coexistence");
 
+       if (variant->max_pixel_clock == 600000000) {
+               struct vc4_dev *vc4 = to_vc4_dev(drm);
+               long max_rate = clk_get_max_rate(vc4->hvs->core_clk);
+
+               if (max_rate < 550000000) {
+                       drm_warn(drm, "The core clock cannot reach frequencies high enough to support 4k @ 60Hz.");
+                       drm_warn(drm, "Please change your config.txt file to add hdmi_enable_4kp60 and force_turbo");

Do we really want to warn in bind? Again you could have a VGA resolution monitor attached but that would trigger this warning. Can we warn (once) on processing the mode list and filtering out a clk

Quoted 6 lines
Quoted 1 line
Quoted 1 line

HDMI_14_MAX_TMDS_CLK mode instead?

That's a good idea indeed, I'll rework the patch to do that

Thanks!
Maxime

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#15 lore raw

PATCH 5/8 drm/vc4: hdmi: Enable the scrambler

In reply to Maxime Ripard

The HDMI controller on the BCM2711 includes a scrambler in order to reach the modes that require it. Let's add the support for it.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c      | 58 +++++++++++++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi_regs.h |  3 ++
 2 files changed, 61 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +58 -0
index f05f6da286f7..1a6babb53cf4 100644
@@ -35,6 +35,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_scdc_helper.h>
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/i2c.h>
@@ -76,6 +77,8 @@
 #define VC5_HDMI_VERTB_VSPO_SHIFT		16
 #define VC5_HDMI_VERTB_VSPO_MASK		VC4_MASK(29, 16)
 
+#define VC5_HDMI_SCRAMBLER_CTL_ENABLE		BIT(0)
+
 #define VC5_HDMI_DEEP_COLOR_CONFIG_1_INIT_PACK_PHASE_SHIFT	8
 #define VC5_HDMI_DEEP_COLOR_CONFIG_1_INIT_PACK_PHASE_MASK	VC4_MASK(10, 8)
 
@@ -445,6 +448,58 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder)
 		vc4_hdmi_set_audio_infoframe(encoder);
 }
 
+#define HDMI_14_MAX_TMDS_CLK	(340 * 1000 * 1000)
+
+static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder,
+					 struct drm_display_mode *mode)
+{
+	struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
+	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+	struct drm_display_info *display = &vc4_hdmi->connector.display_info;
+
+	if (!vc4_encoder->hdmi_monitor)
+		return false;
+
+	if (!display->hdmi.scdc.supported ||
+	    !display->hdmi.scdc.scrambling.supported)
+		return false;
+
+	if ((mode->clock * 1000) < HDMI_14_MAX_TMDS_CLK)
+		return false;
+
+	return true;
+}
+
+static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
+{
+	struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
+	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+
+	if (!vc4_hdmi_supports_scrambling(encoder, mode))
+		return;
+
+	drm_scdc_set_high_tmds_clock_ratio(vc4_hdmi->ddc, true);
+	drm_scdc_set_scrambling(vc4_hdmi->ddc, true);
+
+	HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) |
+		   VC5_HDMI_SCRAMBLER_CTL_ENABLE);
+}
+
+static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
+{
+	struct drm_display_mode *mode = &encoder->crtc->mode;
+	struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+
+	if (!vc4_hdmi_supports_scrambling(encoder, mode))
+		return;
+
+	HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) &
+		   ~VC5_HDMI_SCRAMBLER_CTL_ENABLE);
+
+	drm_scdc_set_scrambling(vc4_hdmi->ddc, false);
+	drm_scdc_set_high_tmds_clock_ratio(vc4_hdmi->ddc, false);
+}
+
 static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
 					       struct drm_atomic_state *state)
 {
@@ -457,6 +512,8 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
 
 	HDMI_WRITE(HDMI_VID_CTL,
 		   HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_BLANKPIX);
+
+	vc4_hdmi_disable_scrambling(encoder);
 }
 
 static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder,
@@ -901,6 +958,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
 	}
 
 	vc4_hdmi_recenter_fifo(vc4_hdmi);
+	vc4_hdmi_enable_scrambling(encoder);
 }
 
 static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
drivers/gpu/drm/vc4/vc4_hdmi_regs.h +3 -0
index e1b58eac766f..6897586228ad 100644
@@ -100,6 +100,7 @@ enum vc4_hdmi_field {
 	HDMI_RM_FORMAT,
 	HDMI_RM_OFFSET,
 	HDMI_SCHEDULER_CONTROL,
+	HDMI_SCRAMBLER_CTL,
 	HDMI_SW_RESET_CONTROL,
 	HDMI_TX_PHY_CHANNEL_SWAP,
 	HDMI_TX_PHY_CLK_DIV,
@@ -234,6 +235,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi0_fields[] = {
 	VC4_HDMI_REG(HDMI_VERTB1, 0x0f8),
 	VC4_HDMI_REG(HDMI_MAI_CHANNEL_MAP, 0x09c),
 	VC4_HDMI_REG(HDMI_MAI_CONFIG, 0x0a0),
+	VC4_HDMI_REG(HDMI_SCRAMBLER_CTL, 0x1c4),
 	VC4_HDMI_REG(HDMI_DEEP_COLOR_CONFIG_1, 0x170),
 	VC4_HDMI_REG(HDMI_GCP_CONFIG, 0x178),
 	VC4_HDMI_REG(HDMI_GCP_WORD_1, 0x17c),
@@ -313,6 +315,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi1_fields[] = {
 	VC4_HDMI_REG(HDMI_VERTB1, 0x0f8),
 	VC4_HDMI_REG(HDMI_MAI_CHANNEL_MAP, 0x09c),
 	VC4_HDMI_REG(HDMI_MAI_CONFIG, 0x0a0),
+	VC4_HDMI_REG(HDMI_SCRAMBLER_CTL, 0x1c4),
 	VC4_HDMI_REG(HDMI_DEEP_COLOR_CONFIG_1, 0x170),
 	VC4_HDMI_REG(HDMI_GCP_CONFIG, 0x178),
 	VC4_HDMI_REG(HDMI_GCP_WORD_1, 0x17c),
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#16 lore raw

Re: [PATCH 5/8] drm/vc4: hdmi: Enable the scrambler

Hi Maxime

Quoted 32 lines · Maxime Ripard

The HDMI controller on the BCM2711 includes a scrambler in order to reach the modes that require it. Let's add the support for it.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c      | 58 +++++++++++++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi_regs.h |  3 ++
 2 files changed, 61 insertions(+)
drivers/gpu/drm/vc4/vc4_hdmi.c +3 -0
index f05f6da286f7..1a6babb53cf4 100644
@@ -35,6 +35,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
+#include <drm/drm_scdc_helper.h>
 #include <linux/clk.h>
 #include <linux/component.h>
 #include <linux/i2c.h>
@@ -76,6 +77,8 @@
 #define VC5_HDMI_VERTB_VSPO_SHIFT              16
 #define VC5_HDMI_VERTB_VSPO_MASK               VC4_MASK(29, 16)
 
+#define VC5_HDMI_SCRAMBLER_CTL_ENABLE          BIT(0)
+
 #define VC5_HDMI_DEEP_COLOR_CONFIG_1_INIT_PACK_PHASE_SHIFT     8
 #define VC5_HDMI_DEEP_COLOR_CONFIG_1_INIT_PACK_PHASE_MASK      VC4_MASK(10, 8)
 

drivers/gpu/drm/vc4/vc4_hdmi.c static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder) · line 451

Quoted 4 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -0
@@ -445,6 +448,58 @@ static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder)
                vc4_hdmi_set_audio_infoframe(encoder);
 }
 
+#define HDMI_14_MAX_TMDS_CLK   (340 * 1000 * 1000)

Something feels a bit funny here.
drm-misc-next already has a commit [1] that adds a define HDMI_14_MAX_TMDS_CLK. Part of it is in the diff for 3/8. So is there a need to redefine it in this patch?

[1] https://cgit.freedesktop.org/drm/drm-misc/commit/drivers/gpu/drm/vc4/vc4_hdmi.c?id=24169a2b0533a6c4030c91a7a074039e7c98fde6

Quoted 84 lines
drivers/gpu/drm/vc4/vc4_hdmi.c +54 -0
+
+static bool vc4_hdmi_supports_scrambling(struct drm_encoder *encoder,
+                                        struct drm_display_mode *mode)
+{
+       struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
+       struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+       struct drm_display_info *display = &vc4_hdmi->connector.display_info;
+
+       if (!vc4_encoder->hdmi_monitor)
+               return false;
+
+       if (!display->hdmi.scdc.supported ||
+           !display->hdmi.scdc.scrambling.supported)
+               return false;
+
+       if ((mode->clock * 1000) < HDMI_14_MAX_TMDS_CLK)
+               return false;
+
+       return true;
+}
+
+static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder)
+{
+       struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
+       struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+
+       if (!vc4_hdmi_supports_scrambling(encoder, mode))
+               return;
+
+       drm_scdc_set_high_tmds_clock_ratio(vc4_hdmi->ddc, true);
+       drm_scdc_set_scrambling(vc4_hdmi->ddc, true);
+
+       HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) |
+                  VC5_HDMI_SCRAMBLER_CTL_ENABLE);
+}
+
+static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
+{
+       struct drm_display_mode *mode = &encoder->crtc->mode;
+       struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
+
+       if (!vc4_hdmi_supports_scrambling(encoder, mode))
+               return;
+
+       HDMI_WRITE(HDMI_SCRAMBLER_CTL, HDMI_READ(HDMI_SCRAMBLER_CTL) &
+                  ~VC5_HDMI_SCRAMBLER_CTL_ENABLE);
+
+       drm_scdc_set_scrambling(vc4_hdmi->ddc, false);
+       drm_scdc_set_high_tmds_clock_ratio(vc4_hdmi->ddc, false);
+}
+
 static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
                                               struct drm_atomic_state *state)
 {
@@ -457,6 +512,8 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
 
        HDMI_WRITE(HDMI_VID_CTL,
                   HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_BLANKPIX);
+
+       vc4_hdmi_disable_scrambling(encoder);
 }
 
 static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder,
@@ -901,6 +958,7 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
        }
 
        vc4_hdmi_recenter_fifo(vc4_hdmi);
+       vc4_hdmi_enable_scrambling(encoder);
 }
 
 static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
drivers/gpu/drm/vc4/vc4_hdmi_regs.h +1 -0
index e1b58eac766f..6897586228ad 100644
@@ -100,6 +100,7 @@ enum vc4_hdmi_field {
        HDMI_RM_FORMAT,
        HDMI_RM_OFFSET,
        HDMI_SCHEDULER_CONTROL,
+       HDMI_SCRAMBLER_CTL,
        HDMI_SW_RESET_CONTROL,
        HDMI_TX_PHY_CHANNEL_SWAP,
        HDMI_TX_PHY_CLK_DIV,

drivers/gpu/drm/vc4/vc4_hdmi_regs.h static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi0_fields[] = { · line 238

Quoted 4 lines
drivers/gpu/drm/vc4/vc4_hdmi_regs.h +1 -0
@@ -234,6 +235,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi0_fields[] = {
        VC4_HDMI_REG(HDMI_VERTB1, 0x0f8),
        VC4_HDMI_REG(HDMI_MAI_CHANNEL_MAP, 0x09c),
        VC4_HDMI_REG(HDMI_MAI_CONFIG, 0x0a0),
+       VC4_HDMI_REG(HDMI_SCRAMBLER_CTL, 0x1c4),

Nit pick: the rest of these registers are in numerical order, but these new additions aren't.

Dave

Quoted 12 lines
drivers/gpu/drm/vc4/vc4_hdmi_regs.h +1 -1
        VC4_HDMI_REG(HDMI_DEEP_COLOR_CONFIG_1, 0x170),
        VC4_HDMI_REG(HDMI_GCP_CONFIG, 0x178),
        VC4_HDMI_REG(HDMI_GCP_WORD_1, 0x17c),
@@ -313,6 +315,7 @@ static const struct vc4_hdmi_register __maybe_unused vc5_hdmi_hdmi1_fields[] = {
        VC4_HDMI_REG(HDMI_VERTB1, 0x0f8),
        VC4_HDMI_REG(HDMI_MAI_CHANNEL_MAP, 0x09c),
        VC4_HDMI_REG(HDMI_MAI_CONFIG, 0x0a0),
+       VC4_HDMI_REG(HDMI_SCRAMBLER_CTL, 0x1c4),
        VC4_HDMI_REG(HDMI_DEEP_COLOR_CONFIG_1, 0x170),
        VC4_HDMI_REG(HDMI_GCP_CONFIG, 0x178),
        VC4_HDMI_REG(HDMI_GCP_WORD_1, 0x17c),
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#17 lore raw

PATCH 6/8 drm/vc4: hdmi: Raise the maximum clock rate

In reply to Maxime Ripard

Now that we have the infrastructure in place, we can raise the maximum pixel rate we can reach for HDMI0 on the BCM2711.

HDMI1 is left untouched since its pixelvalve has a smaller FIFO and would need a clock faster than what we can provide to support the same modes.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -1
index 1a6babb53cf4..27464add6468 100644
@@ -2177,7 +2177,7 @@ static const struct vc4_hdmi_variant bcm2711_hdmi0_variant = {
 	.encoder_type		= VC4_ENCODER_TYPE_HDMI0,
 	.debugfs_name		= "hdmi0_regs",
 	.card_name		= "vc4-hdmi-0",
-	.max_pixel_clock	= HDMI_14_MAX_TMDS_CLK,
+	.max_pixel_clock	= 600000000,
 	.registers		= vc5_hdmi_hdmi0_fields,
 	.num_registers		= ARRAY_SIZE(vc5_hdmi_hdmi0_fields),
 	.phy_lane_mapping	= {
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 6/8
#18 lore raw

Re: [PATCH 6/8] drm/vc4: hdmi: Raise the maximum clock rate

Quoted 9 lines · Maxime Ripard

Now that we have the infrastructure in place, we can raise the maximum pixel rate we can reach for HDMI0 on the BCM2711.

HDMI1 is left untouched since its pixelvalve has a smaller FIFO and would need a clock faster than what we can provide to support the same modes.

Quoted 18 lines
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +1 -2
index 1a6babb53cf4..27464add6468 100644
@@ -2177,7 +2177,7 @@ static const struct vc4_hdmi_variant bcm2711_hdmi0_variant = {
        .encoder_type           = VC4_ENCODER_TYPE_HDMI0,
        .debugfs_name           = "hdmi0_regs",
        .card_name              = "vc4-hdmi-0",
-       .max_pixel_clock        = HDMI_14_MAX_TMDS_CLK,
+       .max_pixel_clock        = 600000000,
        .registers              = vc5_hdmi_hdmi0_fields,
        .num_registers          = ARRAY_SIZE(vc5_hdmi_hdmi0_fields),
        .phy_lane_mapping       = {
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#19 lore raw

PATCH 7/8 drm/vc4: plane: Fix typo in scaler width and height

In reply to Maxime Ripard
---
 drivers/gpu/drm/vc4/vc4_plane.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_plane.c +2 -2
index 4a075294ff4c..5e8b7f72dc05 100644
@@ -912,9 +912,9 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
 		if (!vc4_state->is_unity) {
 			vc4_dlist_write(vc4_state,
 					VC4_SET_FIELD(vc4_state->crtc_w,
-						      SCALER_POS1_SCL_WIDTH) |
+						      SCALER5_POS1_SCL_WIDTH) |
 					VC4_SET_FIELD(vc4_state->crtc_h,
-						      SCALER_POS1_SCL_HEIGHT));
+						      SCALER5_POS1_SCL_HEIGHT));
 		}
 
 		/* Position Word 2: Source Image Size */
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 7/8
#20 lore raw

Re: [PATCH 7/8] drm/vc4: plane: Fix typo in scaler width and height

Quoted 2 lines · Maxime Ripard

Again no commit text body, but possibly not warranted

Quoted 21 lines
---
 drivers/gpu/drm/vc4/vc4_plane.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_plane.c +2 -3
index 4a075294ff4c..5e8b7f72dc05 100644
@@ -912,9 +912,9 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
                if (!vc4_state->is_unity) {
                        vc4_dlist_write(vc4_state,
                                        VC4_SET_FIELD(vc4_state->crtc_w,
-                                                     SCALER_POS1_SCL_WIDTH) |
+                                                     SCALER5_POS1_SCL_WIDTH) |
                                        VC4_SET_FIELD(vc4_state->crtc_h,
-                                                     SCALER_POS1_SCL_HEIGHT));
+                                                     SCALER5_POS1_SCL_HEIGHT));
                }
 
                /* Position Word 2: Source Image Size */
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

PATCH 8/8 drm/vc4: plane: Remove redundant assignment

In reply to Maxime Ripard
---
 drivers/gpu/drm/vc4/vc4_plane.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/vc4/vc4_plane.c +0 -1
index 5e8b7f72dc05..201831e924d9 100644
@@ -1131,7 +1131,6 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane,
 	plane->state->src_y = state->src_y;
 	plane->state->src_w = state->src_w;
 	plane->state->src_h = state->src_h;
-	plane->state->src_h = state->src_h;
 	plane->state->alpha = state->alpha;
 	plane->state->pixel_blend_mode = state->pixel_blend_mode;
 	plane->state->rotation = state->rotation;
Signature · 6 lines
2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v1 8/8
#22 lore raw

Re: [PATCH 8/8] drm/vc4: plane: Remove redundant assignment

Quoted 2 lines · Maxime Ripard

Other than no commit text body (which is hardly needed in this case)

Quoted 17 lines
---
 drivers/gpu/drm/vc4/vc4_plane.c | 1 -
 1 file changed, 1 deletion(-)
drivers/gpu/drm/vc4/vc4_plane.c +0 -2
index 5e8b7f72dc05..201831e924d9 100644
@@ -1131,7 +1131,6 @@ static void vc4_plane_atomic_async_update(struct drm_plane *plane,
        plane->state->src_y = state->src_y;
        plane->state->src_w = state->src_w;
        plane->state->src_h = state->src_h;
-       plane->state->src_h = state->src_h;
        plane->state->alpha = state->alpha;
        plane->state->pixel_blend_mode = state->pixel_blend_mode;
        plane->state->rotation = state->rotation;
--
Quoted 2 lines

2.29.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCH 8/8] drm/vc4: plane: Remove redundant assignment

Hi Dave,

Quoted 7 lines · Dave Stevenson
Quoted 2 lines · Maxime Ripard

Other than no commit text body (which is hardly needed in this case)

Yeah the last two patches weren't meant to be part of this series, I'll add a commit log and resend them.

Thanks!
Maxime

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel