Skip to contentSkip to conversation

SII902X HDMI Bridge fixups

PATCH Applied Jayesh Choudhary 4 participants 10 messages Jun 13, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover SII902X HDMI Bridge fixups

- Move the mode_valid hook to drm_bridge_funcs structure to take care of the case when the encoder attaches the bridge chain with the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag in which case, the connector is not initialized in the bridge's attach call and mode_valid is not called.

- Also add this check to the atomic_check call as suggested by Maxime in v1 patch.

- Move from deprecated enable()/disable() hooks to atomic hooks as suggested in v4 by Sam

Testing has been done on AM62X platform which have SII902X HDMI bridge. From the logs we can see the propagated modes and flip test for 1080p resolution.

Testlog:
<https://gist.github.com/Jayesh2000/9bea6840672869337039296bc1145df4>

Changelog v4->v5:
- Add followup patch to replace deprecated bridge hooks
- Fix atomic check to return negative value
- Made commit message for [1/2] in v4 more clear while keeping the R-by and Acked-by tags.
- Fix commit header for [2/2] in v4

v4 patch:
<https://lore.kernel.org/all/[email protected]/>

Changelog v3->v4:
- Remove mode_valid hook from connector_helper_funcs as it is not needed.

v3 patch:
<https://lore.kernel.org/all/[email protected]/>

Changelog v2->v3:
- Remove newline that was introduced in [1/2] and later deleted in [2/2] in v2

v2 patch:
<https://lore.kernel.org/all/[email protected]/>

Changelog v1->v2:
- Add KHZ suffix in the macros to be more clear
- Add the hook for drm_bridge_funcs as well
- Add check in atomic_check dunction call (in a separate patch)

v1 patch:
<https://lore.kernel.org/all/[email protected]/>

Jayesh Choudhary (3):
drm/bridge: sii902x: Fix mode_valid hook drm/bridge: sii902x: Support atomic bridge APIs drm/bridge: sii902x: Add pixel clock check in atomic_check

 drivers/gpu/drm/bridge/sii902x.c | 46 +++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 13 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/3 drm/bridge: sii902x: Fix mode_valid hook

Currently, mode_valid is defined only in drm_connector_helper_funcs. When the bridge is attached with the 'DRM_BRIDGE_ATTACH_NO_CONNECTOR' flag, the connector is not initialized, and so is the mode_valid hook under connector helper funcs.
It also returns MODE_OK for all modes without actually checking the modes.
So move the mode_valid hook to drm_bridge_funcs with proper clock checks for maximum and minimum pixel clock supported by the bridge.

---
 drivers/gpu/drm/bridge/sii902x.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +23 -9
index 2fbeda9025bf..6a6055a4ccf9 100644
@@ -163,6 +163,14 @@
 
 #define SII902X_AUDIO_PORT_INDEX		3
 
+/*
+ * The maximum resolution supported by the HDMI bridge is 1080p@60Hz
+ * and 1920x1200 requiring a pixel clock of 165MHz and the minimum
+ * resolution supported is 480p@60Hz requiring a pixel clock of 25MHz
+ */
+#define SII902X_MIN_PIXEL_CLOCK_KHZ		25000
+#define SII902X_MAX_PIXEL_CLOCK_KHZ		165000
+
 struct sii902x {
 	struct i2c_client *i2c;
 	struct regmap *regmap;
@@ -310,17 +318,8 @@ static int sii902x_get_modes(struct drm_connector *connector)
 	return num;
 }
 
-static enum drm_mode_status sii902x_mode_valid(struct drm_connector *connector,
-					       struct drm_display_mode *mode)
-{
-	/* TODO: check mode */
-
-	return MODE_OK;
-}
-
 static const struct drm_connector_helper_funcs sii902x_connector_helper_funcs = {
 	.get_modes = sii902x_get_modes,
-	.mode_valid = sii902x_mode_valid,
 };
 
 static void sii902x_bridge_disable(struct drm_bridge *bridge)
@@ -504,6 +503,20 @@ static int sii902x_bridge_atomic_check(struct drm_bridge *bridge,
 	return 0;
 }
 
+static enum drm_mode_status
+sii902x_bridge_mode_valid(struct drm_bridge *bridge,
+			  const struct drm_display_info *info,
+			  const struct drm_display_mode *mode)
+{
+	if (mode->clock < SII902X_MIN_PIXEL_CLOCK_KHZ)
+		return MODE_CLOCK_LOW;
+
+	if (mode->clock > SII902X_MAX_PIXEL_CLOCK_KHZ)
+		return MODE_CLOCK_HIGH;
+
+	return MODE_OK;
+}
+
 static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.attach = sii902x_bridge_attach,
 	.mode_set = sii902x_bridge_mode_set,
@@ -516,6 +529,7 @@ static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
 	.atomic_get_input_bus_fmts = sii902x_bridge_atomic_get_input_bus_fmts,
 	.atomic_check = sii902x_bridge_atomic_check,
+	.mode_valid = sii902x_bridge_mode_valid,
 };
 
 static int sii902x_mute(struct sii902x *sii902x, bool mute)
Signature · 1 line
2.25.1
Reviewed-by on v5 1/3
#2 lore raw

Re: [PATCH v5 1/3] drm/bridge: sii902x: Fix mode_valid hook

Hi Jayesh,

Thanks for the patches!

Quoted 75 lines · Jayesh Choudhary

Currently, mode_valid is defined only in drm_connector_helper_funcs. When the bridge is attached with the 'DRM_BRIDGE_ATTACH_NO_CONNECTOR' flag, the connector is not initialized, and so is the mode_valid hook under connector helper funcs.
It also returns MODE_OK for all modes without actually checking the modes.
So move the mode_valid hook to drm_bridge_funcs with proper clock checks for maximum and minimum pixel clock supported by the bridge.

---
 drivers/gpu/drm/bridge/sii902x.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +22 -9
index 2fbeda9025bf..6a6055a4ccf9 100644
@@ -163,6 +163,14 @@
 
 #define SII902X_AUDIO_PORT_INDEX		3
 
+/*
+ * The maximum resolution supported by the HDMI bridge is 1080p@60Hz
+ * and 1920x1200 requiring a pixel clock of 165MHz and the minimum
+ * resolution supported is 480p@60Hz requiring a pixel clock of 25MHz
+ */
+#define SII902X_MIN_PIXEL_CLOCK_KHZ		25000
+#define SII902X_MAX_PIXEL_CLOCK_KHZ		165000
+
 struct sii902x {
 	struct i2c_client *i2c;
 	struct regmap *regmap;
@@ -310,17 +318,8 @@ static int sii902x_get_modes(struct drm_connector *connector)
 	return num;
 }
 
-static enum drm_mode_status sii902x_mode_valid(struct drm_connector *connector,
-					       struct drm_display_mode *mode)
-{
-	/* TODO: check mode */
-
-	return MODE_OK;
-}
-
 static const struct drm_connector_helper_funcs sii902x_connector_helper_funcs = {
 	.get_modes = sii902x_get_modes,
-	.mode_valid = sii902x_mode_valid,
 };
 
 static void sii902x_bridge_disable(struct drm_bridge *bridge)
@@ -504,6 +503,20 @@ static int sii902x_bridge_atomic_check(struct drm_bridge *bridge,
 	return 0;
 }
 
+static enum drm_mode_status
+sii902x_bridge_mode_valid(struct drm_bridge *bridge,
+			  const struct drm_display_info *info,
+			  const struct drm_display_mode *mode)
+{
+	if (mode->clock < SII902X_MIN_PIXEL_CLOCK_KHZ)
+		return MODE_CLOCK_LOW;
+
+	if (mode->clock > SII902X_MAX_PIXEL_CLOCK_KHZ)
+		return MODE_CLOCK_HIGH;
+
+	return MODE_OK;
+}
+
 static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.attach = sii902x_bridge_attach,
 	.mode_set = sii902x_bridge_mode_set,

drivers/gpu/drm/bridge/sii902x.c static const struct drm_bridge_funcs sii902x_bridge_funcs = { · line 535

Quoted 7 lines
drivers/gpu/drm/bridge/sii902x.c +1 -0
@@ -516,6 +529,7 @@ static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
 	.atomic_get_input_bus_fmts = sii902x_bridge_atomic_get_input_bus_fmts,
 	.atomic_check = sii902x_bridge_atomic_check,
+	.mode_valid = sii902x_bridge_mode_valid,
 };
 
 static int sii902x_mute(struct sii902x *sii902x, bool mute)
Signature · 2 lines
Regards
Aradhya
#3 lore raw

PATCH v5 2/3 drm/bridge: sii902x: Support atomic bridge APIs

In reply to Jayesh Choudhary

Change exisitig enable() and disable() bridge hooks to their atomic counterparts as the former hooks are deprecated.

---
 drivers/gpu/drm/bridge/sii902x.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +6 -4
index 6a6055a4ccf9..00a8c469f553 100644
@@ -322,7 +322,8 @@ static const struct drm_connector_helper_funcs sii902x_connector_helper_funcs =
 	.get_modes = sii902x_get_modes,
 };
 
-static void sii902x_bridge_disable(struct drm_bridge *bridge)
+static void sii902x_bridge_atomic_disable(struct drm_bridge *bridge,
+					  struct drm_bridge_state *old_bridge_state)
 {
 	struct sii902x *sii902x = bridge_to_sii902x(bridge);
 
@@ -335,7 +336,8 @@ static void sii902x_bridge_disable(struct drm_bridge *bridge)
 	mutex_unlock(&sii902x->mutex);
 }
 
-static void sii902x_bridge_enable(struct drm_bridge *bridge)
+static void sii902x_bridge_atomic_enable(struct drm_bridge *bridge,
+					 struct drm_bridge_state *old_bridge_state)
 {
 	struct sii902x *sii902x = bridge_to_sii902x(bridge);
 
@@ -520,8 +522,8 @@ sii902x_bridge_mode_valid(struct drm_bridge *bridge,
 static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.attach = sii902x_bridge_attach,
 	.mode_set = sii902x_bridge_mode_set,
-	.disable = sii902x_bridge_disable,
-	.enable = sii902x_bridge_enable,
+	.atomic_disable = sii902x_bridge_atomic_disable,
+	.atomic_enable = sii902x_bridge_atomic_enable,
 	.detect = sii902x_bridge_detect,
 	.edid_read = sii902x_bridge_edid_read,
 	.atomic_reset = drm_atomic_helper_bridge_reset,
Signature · 1 line
2.25.1
Reviewed-by on v5 2/3
#4 lore raw

Re: [PATCH v5 2/3] drm/bridge: sii902x: Support atomic bridge APIs

Quoted 33 lines · Jayesh Choudhary

Change exisitig enable() and disable() bridge hooks to their atomic counterparts as the former hooks are deprecated.

---
 drivers/gpu/drm/bridge/sii902x.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/sii902x.c +4 -2
index 6a6055a4ccf9..00a8c469f553 100644
@@ -322,7 +322,8 @@ static const struct drm_connector_helper_funcs sii902x_connector_helper_funcs =
 	.get_modes = sii902x_get_modes,
 };
 
-static void sii902x_bridge_disable(struct drm_bridge *bridge)
+static void sii902x_bridge_atomic_disable(struct drm_bridge *bridge,
+					  struct drm_bridge_state *old_bridge_state)
 {
 	struct sii902x *sii902x = bridge_to_sii902x(bridge);
 
@@ -335,7 +336,8 @@ static void sii902x_bridge_disable(struct drm_bridge *bridge)
 	mutex_unlock(&sii902x->mutex);
 }
 
-static void sii902x_bridge_enable(struct drm_bridge *bridge)
+static void sii902x_bridge_atomic_enable(struct drm_bridge *bridge,
+					 struct drm_bridge_state *old_bridge_state)
 {
 	struct sii902x *sii902x = bridge_to_sii902x(bridge);
 

drivers/gpu/drm/bridge/sii902x.c sii902x_bridge_mode_valid(struct drm_bridge *bridge, · line 529

Quoted 10 lines
drivers/gpu/drm/bridge/sii902x.c +2 -2
@@ -520,8 +522,8 @@ sii902x_bridge_mode_valid(struct drm_bridge *bridge,
 static const struct drm_bridge_funcs sii902x_bridge_funcs = {
 	.attach = sii902x_bridge_attach,
 	.mode_set = sii902x_bridge_mode_set,
-	.disable = sii902x_bridge_disable,
-	.enable = sii902x_bridge_enable,
+	.atomic_disable = sii902x_bridge_atomic_disable,
+	.atomic_enable = sii902x_bridge_atomic_enable,
 	.detect = sii902x_bridge_detect,
 	.edid_read = sii902x_bridge_edid_read,
 	.atomic_reset = drm_atomic_helper_bridge_reset,
Signature · 2 lines
Regards
Aradhya
Reviewed-by on v5 2/3
#5 lore raw

Re: [PATCH v5 2/3] drm/bridge: sii902x: Support atomic bridge APIs

In reply to Jayesh Choudhary
Quoted 8 lines · Jayesh Choudhary

Change exisitig enable() and disable() bridge hooks to their atomic counterparts as the former hooks are deprecated.

---
 drivers/gpu/drm/bridge/sii902x.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 2 lines
With best wishes
Dmitry
#6 lore raw

PATCH v5 3/3 drm/bridge: sii902x: Add pixel clock check in atomic_check

In reply to Jayesh Choudhary

Check the pixel clock for the mode in atomic_check and ensure that it is within the range supported by the bridge.

---
 drivers/gpu/drm/bridge/sii902x.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/sii902x.c +4 -0
index 00a8c469f553..7f91b0db161e 100644
@@ -496,6 +496,10 @@ static int sii902x_bridge_atomic_check(struct drm_bridge *bridge,
 				       struct drm_crtc_state *crtc_state,
 				       struct drm_connector_state *conn_state)
 {
+	if (crtc_state->mode.clock < SII902X_MIN_PIXEL_CLOCK_KHZ ||
+	    crtc_state->mode.clock > SII902X_MAX_PIXEL_CLOCK_KHZ)
+		return -EINVAL;
+
 	/*
 	 * There might be flags negotiation supported in future but
 	 * set the bus flags in atomic_check statically for now.
Signature · 1 line
2.25.1
Reviewed-by on v5 3/3
#7 lore raw

Re: [PATCH v5 3/3] drm/bridge: sii902x: Add pixel clock check in atomic_check

Quoted 13 lines · Jayesh Choudhary

Check the pixel clock for the mode in atomic_check and ensure that it is within the range supported by the bridge.

---
 drivers/gpu/drm/bridge/sii902x.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/bridge/sii902x.c +0 -0
index 00a8c469f553..7f91b0db161e 100644

drivers/gpu/drm/bridge/sii902x.c static int sii902x_bridge_atomic_check(struct drm_bridge *bridge, · line 505

Quoted 10 lines
drivers/gpu/drm/bridge/sii902x.c +4 -0
@@ -496,6 +496,10 @@ static int sii902x_bridge_atomic_check(struct drm_bridge *bridge,
 				       struct drm_crtc_state *crtc_state,
 				       struct drm_connector_state *conn_state)
 {
+	if (crtc_state->mode.clock < SII902X_MIN_PIXEL_CLOCK_KHZ ||
+	    crtc_state->mode.clock > SII902X_MAX_PIXEL_CLOCK_KHZ)
+		return -EINVAL;
+
 	/*
 	 * There might be flags negotiation supported in future but
 	 * set the bus flags in atomic_check statically for now.
Signature · 2 lines
Regards
Aradhya
Reviewed-by on v5 3/3
#8 lore raw

Re: [PATCH v5 3/3] drm/bridge: sii902x: Add pixel clock check in atomic_check

In reply to Jayesh Choudhary
Quoted 8 lines · Jayesh Choudhary

Check the pixel clock for the mode in atomic_check and ensure that it is within the range supported by the bridge.

---
 drivers/gpu/drm/bridge/sii902x.c | 4 ++++
 1 file changed, 4 insertions(+)
Signature · 2 lines
With best wishes
Dmitry
maintainer Applied
#9 lore raw
In reply to Jayesh Choudhary
Quoted 10 lines · Jayesh Choudhary

- Move the mode_valid hook to drm_bridge_funcs structure to take care of the case when the encoder attaches the bridge chain with the DRM_BRIDGE_ATTACH_NO_CONNECTOR flag in which case, the connector is not initialized in the bridge's attach call and mode_valid is not called.

- Also add this check to the atomic_check call as suggested by Maxime in v1 patch.

[...]

Applied to misc/kernel.git (drm-misc-next).

Thanks!
Maxime