Skip to contentSkip to conversation

drm/ast: astdp: Improve mode handling

PATCH In review Thomas Zimmermann 2 participants 9 messages Feb 4, 2025 – Feb 10, 2025

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: astdp: Improve mode handling

The ASTDP transmitter chip requires a mode index for each supported mode. Currently, that is being handled internally whne programming the display mode. Rework the code to filter out unsupported modes and detect errors early.

Tested on AST2600 hardware.

Thomas Zimmermann (4):
drm/ast: astdp: Add connector state drm/ast: astdp: Inline mode-index calculation drm/ast: astdp: Store mode index in connector state drm/ast: astdp: Validate display modes

 drivers/gpu/drm/ast/ast_dp.c | 157 ++++++++++++++++++++++++++---------
 1 file changed, 118 insertions(+), 39 deletions(-)
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 1/4 drm/ast: astdp: Add connector state

Add dedicated connector state for ASTDP connectors. The state will store values for programming the transmitter chip.

---
 drivers/gpu/drm/ast/ast_dp.c | 62 ++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +56 -6
index db3eb9ce1498..9c49b507a0d2 100644
@@ -42,6 +42,16 @@ static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[
 	{ 0 }
 };
 
+struct ast_astdp_connector_state {
+	struct drm_connector_state base;
+};
+
+static struct ast_astdp_connector_state *
+to_ast_astdp_connector_state(const struct drm_connector_state *state)
+{
+	return container_of(state, struct ast_astdp_connector_state, base);
+}
+
 static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
 {
 	const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table;
@@ -442,18 +452,58 @@ static const struct drm_connector_helper_funcs ast_astdp_connector_helper_funcs
 	.detect_ctx = ast_astdp_connector_helper_detect_ctx,
 };
 
-/*
- * Output
- */
+static void ast_astdp_connector_reset(struct drm_connector *connector)
+{
+	struct ast_astdp_connector_state *astdp_state =
+		kzalloc(sizeof(*astdp_state), GFP_KERNEL);
+
+	if (connector->state)
+		connector->funcs->atomic_destroy_state(connector, connector->state);
+
+	if (astdp_state)
+		__drm_atomic_helper_connector_reset(connector, &astdp_state->base);
+	else
+		__drm_atomic_helper_connector_reset(connector, NULL);
+}
+
+static struct drm_connector_state *
+ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
+{
+	struct ast_astdp_connector_state *new_astdp_state;
+	struct drm_device *dev = connector->dev;
+
+	if (drm_WARN_ON(dev, !connector->state))
+		return NULL;
+
+	new_astdp_state = kmalloc(sizeof(*new_astdp_state), GFP_KERNEL);
+	if (!new_astdp_state)
+		return NULL;
+	__drm_atomic_helper_connector_duplicate_state(connector, &new_astdp_state->base);
+
+	return &new_astdp_state->base;
+}
+
+static void ast_astdp_connector_atomic_destroy_state(struct drm_connector *connector,
+						     struct drm_connector_state *state)
+{
+	struct ast_astdp_connector_state *astdp_state = to_ast_astdp_connector_state(state);
+
+	__drm_atomic_helper_connector_destroy_state(&astdp_state->base);
+	kfree(astdp_state);
+}
 
 static const struct drm_connector_funcs ast_astdp_connector_funcs = {
-	.reset = drm_atomic_helper_connector_reset,
+	.reset = ast_astdp_connector_reset,
 	.fill_modes = drm_helper_probe_single_connector_modes,
 	.destroy = drm_connector_cleanup,
-	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
-	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+	.atomic_duplicate_state = ast_astdp_connector_atomic_duplicate_state,
+	.atomic_destroy_state = ast_astdp_connector_atomic_destroy_state,
 };
 
+/*
+ * Output
+ */
+
 int ast_astdp_output_init(struct ast_device *ast)
 {
 	struct drm_device *dev = &ast->base;
Signature · 1 line
2.48.1
reviewer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] drm/ast: astdp: Add connector state

Quoted 2 lines · Thomas Zimmermann

Add dedicated connector state for ASTDP connectors. The state will store values for programming the transmitter chip.

Thanks, it looks good to me.

Quoted 92 lines
---
  drivers/gpu/drm/ast/ast_dp.c | 62 ++++++++++++++++++++++++++++++++----
  1 file changed, 56 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +56 -6
index db3eb9ce1498..9c49b507a0d2 100644
@@ -42,6 +42,16 @@ static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[
  	{ 0 }
  };
 
+struct ast_astdp_connector_state {
+	struct drm_connector_state base;
+};
+
+static struct ast_astdp_connector_state *
+to_ast_astdp_connector_state(const struct drm_connector_state *state)
+{
+	return container_of(state, struct ast_astdp_connector_state, base);
+}
+
  static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
  {
  	const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table;
@@ -442,18 +452,58 @@ static const struct drm_connector_helper_funcs ast_astdp_connector_helper_funcs
  	.detect_ctx = ast_astdp_connector_helper_detect_ctx,
  };
 
-/*
- * Output
- */
+static void ast_astdp_connector_reset(struct drm_connector *connector)
+{
+	struct ast_astdp_connector_state *astdp_state =
+		kzalloc(sizeof(*astdp_state), GFP_KERNEL);
+
+	if (connector->state)
+		connector->funcs->atomic_destroy_state(connector, connector->state);
+
+	if (astdp_state)
+		__drm_atomic_helper_connector_reset(connector, &astdp_state->base);
+	else
+		__drm_atomic_helper_connector_reset(connector, NULL);
+}
+
+static struct drm_connector_state *
+ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
+{
+	struct ast_astdp_connector_state *new_astdp_state;
+	struct drm_device *dev = connector->dev;
+
+	if (drm_WARN_ON(dev, !connector->state))
+		return NULL;
+
+	new_astdp_state = kmalloc(sizeof(*new_astdp_state), GFP_KERNEL);
+	if (!new_astdp_state)
+		return NULL;
+	__drm_atomic_helper_connector_duplicate_state(connector, &new_astdp_state->base);
+
+	return &new_astdp_state->base;
+}
+
+static void ast_astdp_connector_atomic_destroy_state(struct drm_connector *connector,
+						     struct drm_connector_state *state)
+{
+	struct ast_astdp_connector_state *astdp_state = to_ast_astdp_connector_state(state);
+
+	__drm_atomic_helper_connector_destroy_state(&astdp_state->base);
+	kfree(astdp_state);
+}
 
  static const struct drm_connector_funcs ast_astdp_connector_funcs = {
-	.reset = drm_atomic_helper_connector_reset,
+	.reset = ast_astdp_connector_reset,
  	.fill_modes = drm_helper_probe_single_connector_modes,
  	.destroy = drm_connector_cleanup,
-	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
-	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+	.atomic_duplicate_state = ast_astdp_connector_atomic_duplicate_state,
+	.atomic_destroy_state = ast_astdp_connector_atomic_destroy_state,
  };
 
+/*
+ * Output
+ */
+
  int ast_astdp_output_init(struct ast_device *ast)
  {
  	struct drm_device *dev = &ast->base;
author maintainer
#3 lore raw

PATCH 2/4 drm/ast: astdp: Inline mode-index calculation

In reply to Thomas Zimmermann

Programming the astdp transmitter chip requires a magic value for individual modes. Inline the helper for calculating the value into its only caller (i.e., the encoder's atomic_mode_set).

With further refactoring, the atomic check will be able to detect invalid modes before attempting to program them.

---
 drivers/gpu/drm/ast/ast_dp.c | 52 +++++++++++++++---------------------
 1 file changed, 21 insertions(+), 31 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +21 -31
index 9c49b507a0d2..e7b00153c37e 100644
@@ -52,7 +52,7 @@ to_ast_astdp_connector_state(const struct drm_connector_state *state)
 	return container_of(state, struct ast_astdp_connector_state, base);
 }
 
-static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
+static int ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
 {
 	const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table;
 
@@ -65,35 +65,6 @@ static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdispl
 	return -EINVAL;
 }
 
-static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode)
-{
-	int mode_index;
-	u8 refresh_rate_index;
-
-	mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde);
-	if (mode_index < 0)
-		return mode_index;
-
-	if (vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255)
-		return -EINVAL;
-	refresh_rate_index = vmode->refresh_rate_index - 1;
-
-	/* FIXME: Why are we doing this? */
-	switch (mode_index) {
-	case ASTDP_1280x800_60_RB:
-	case ASTDP_1440x900_60_RB:
-	case ASTDP_1600x900_60_RB:
-	case ASTDP_1680x1050_60_RB:
-		mode_index = (u8)(mode_index - (u8)refresh_rate_index);
-		break;
-	default:
-		mode_index = (u8)(mode_index + (u8)refresh_rate_index);
-		break;
-	}
-
-	return mode_index;
-}
-
 static bool ast_astdp_is_connected(struct ast_device *ast)
 {
 	if (!ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xDF, AST_IO_VGACRDF_HPD))
@@ -333,13 +304,32 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder
 	struct drm_device *dev = encoder->dev;
 	struct ast_device *ast = to_ast_device(dev);
 	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	const struct ast_vbios_enhtable *vmode = ast_crtc_state->vmode;
 	int mode_index;
+	u8 refresh_rate_index;
 	u8 vgacre0, vgacre1, vgacre2;
 
-	mode_index = ast_astdp_get_mode_index(ast_crtc_state->vmode);
+	mode_index = ast_astdp_get_mode_index(vmode->hde, vmode->vde);
 	if (drm_WARN_ON(dev, mode_index < 0))
 		return;
 
+	if (drm_WARN_ON(dev, vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255))
+		return;
+	refresh_rate_index = vmode->refresh_rate_index - 1;
+
+	/* FIXME: Why are we doing this? */
+	switch (mode_index) {
+	case ASTDP_1280x800_60_RB:
+	case ASTDP_1440x900_60_RB:
+	case ASTDP_1600x900_60_RB:
+	case ASTDP_1680x1050_60_RB:
+		mode_index = (u8)(mode_index - (u8)refresh_rate_index);
+		break;
+	default:
+		mode_index = (u8)(mode_index + (u8)refresh_rate_index);
+		break;
+	}
+
 	/*
 	 * CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
 	 * CRE1[7:0]: MISC1 (default: 0x00)
Signature · 1 line
2.48.1
reviewer Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] drm/ast: astdp: Inline mode-index calculation

Quoted 6 lines · Thomas Zimmermann

Programming the astdp transmitter chip requires a magic value for individual modes. Inline the helper for calculating the value into its only caller (i.e., the encoder's atomic_mode_set).

With further refactoring, the atomic check will be able to detect invalid modes before attempting to program them.

Thanks, it looks good to me.

Quoted 89 lines
---
  drivers/gpu/drm/ast/ast_dp.c | 52 +++++++++++++++---------------------
  1 file changed, 21 insertions(+), 31 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +21 -31
index 9c49b507a0d2..e7b00153c37e 100644
@@ -52,7 +52,7 @@ to_ast_astdp_connector_state(const struct drm_connector_state *state)
  	return container_of(state, struct ast_astdp_connector_state, base);
  }
 
-static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
+static int ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdisplay)
  {
  	const struct ast_astdp_mode_index_table_entry *entry = ast_astdp_mode_index_table;
 
@@ -65,35 +65,6 @@ static int __ast_astdp_get_mode_index(unsigned int hdisplay, unsigned int vdispl
  	return -EINVAL;
  }
 
-static int ast_astdp_get_mode_index(const struct ast_vbios_enhtable *vmode)
-{
-	int mode_index;
-	u8 refresh_rate_index;
-
-	mode_index = __ast_astdp_get_mode_index(vmode->hde, vmode->vde);
-	if (mode_index < 0)
-		return mode_index;
-
-	if (vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255)
-		return -EINVAL;
-	refresh_rate_index = vmode->refresh_rate_index - 1;
-
-	/* FIXME: Why are we doing this? */
-	switch (mode_index) {
-	case ASTDP_1280x800_60_RB:
-	case ASTDP_1440x900_60_RB:
-	case ASTDP_1600x900_60_RB:
-	case ASTDP_1680x1050_60_RB:
-		mode_index = (u8)(mode_index - (u8)refresh_rate_index);
-		break;
-	default:
-		mode_index = (u8)(mode_index + (u8)refresh_rate_index);
-		break;
-	}
-
-	return mode_index;
-}
-
  static bool ast_astdp_is_connected(struct ast_device *ast)
  {
  	if (!ast_get_index_reg_mask(ast, AST_IO_VGACRI, 0xDF, AST_IO_VGACRDF_HPD))
@@ -333,13 +304,32 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder
  	struct drm_device *dev = encoder->dev;
  	struct ast_device *ast = to_ast_device(dev);
  	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	const struct ast_vbios_enhtable *vmode = ast_crtc_state->vmode;
  	int mode_index;
+	u8 refresh_rate_index;
  	u8 vgacre0, vgacre1, vgacre2;
 
-	mode_index = ast_astdp_get_mode_index(ast_crtc_state->vmode);
+	mode_index = ast_astdp_get_mode_index(vmode->hde, vmode->vde);
  	if (drm_WARN_ON(dev, mode_index < 0))
  		return;
 
+	if (drm_WARN_ON(dev, vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255))
+		return;
+	refresh_rate_index = vmode->refresh_rate_index - 1;
+
+	/* FIXME: Why are we doing this? */
+	switch (mode_index) {
+	case ASTDP_1280x800_60_RB:
+	case ASTDP_1440x900_60_RB:
+	case ASTDP_1600x900_60_RB:
+	case ASTDP_1680x1050_60_RB:
+		mode_index = (u8)(mode_index - (u8)refresh_rate_index);
+		break;
+	default:
+		mode_index = (u8)(mode_index + (u8)refresh_rate_index);
+		break;
+	}
+
  	/*
  	 * CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
  	 * CRE1[7:0]: MISC1 (default: 0x00)
author maintainer
#5 lore raw

PATCH 3/4 drm/ast: astdp: Store mode index in connector state

In reply to Thomas Zimmermann

Look up the mode index for the astdp transmitter ship in the encoder's atomic check and report an error if the display mode is not supported.

The lookup uses the DRM display mode instead of the driver's internal VBIOS mode. Both are be equivalent. The modesetting code later reads the calculated index from the connector state to avoid recalculating it.

---
 drivers/gpu/drm/ast/ast_dp.c | 37 ++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +31 -6
index e7b00153c37e..056991afde7f 100644
@@ -5,6 +5,7 @@
 #include <linux/firmware.h>
 #include <linux/delay.h>
 
+#include <drm/drm_atomic.h>
 #include <drm/drm_atomic_state_helper.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_modeset_helper_vtables.h>
@@ -44,6 +45,8 @@ static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[
 
 struct ast_astdp_connector_state {
 	struct drm_connector_state base;
+
+	int mode_index;
 };
 
 static struct ast_astdp_connector_state *
@@ -305,14 +308,12 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder
 	struct ast_device *ast = to_ast_device(dev);
 	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
 	const struct ast_vbios_enhtable *vmode = ast_crtc_state->vmode;
-	int mode_index;
+	struct ast_astdp_connector_state *astdp_conn_state =
+		to_ast_astdp_connector_state(conn_state);
+	int mode_index = astdp_conn_state->mode_index;
 	u8 refresh_rate_index;
 	u8 vgacre0, vgacre1, vgacre2;
 
-	mode_index = ast_astdp_get_mode_index(vmode->hde, vmode->vde);
-	if (drm_WARN_ON(dev, mode_index < 0))
-		return;
-
 	if (drm_WARN_ON(dev, vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255))
 		return;
 	refresh_rate_index = vmode->refresh_rate_index - 1;
@@ -368,10 +369,30 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
 	ast_dp_set_phy_sleep(ast, true);
 }
 
+static int ast_astdp_encoder_helper_atomic_check(struct drm_encoder *encoder,
+						 struct drm_crtc_state *crtc_state,
+						 struct drm_connector_state *conn_state)
+{
+	const struct drm_display_mode *mode = &crtc_state->mode;
+	struct ast_astdp_connector_state *astdp_conn_state =
+		to_ast_astdp_connector_state(conn_state);
+	int res;
+
+	if (drm_atomic_crtc_needs_modeset(crtc_state)) {
+		res = ast_astdp_get_mode_index(mode->hdisplay, mode->vdisplay);
+		if (res < 0)
+			return res;
+		astdp_conn_state->mode_index = res;
+	}
+
+	return 0;
+}
+
 static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
 	.atomic_mode_set = ast_astdp_encoder_helper_atomic_mode_set,
 	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
 	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,
+	.atomic_check = ast_astdp_encoder_helper_atomic_check,
 };
 
 /*
@@ -459,7 +480,7 @@ static void ast_astdp_connector_reset(struct drm_connector *connector)
 static struct drm_connector_state *
 ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
 {
-	struct ast_astdp_connector_state *new_astdp_state;
+	struct ast_astdp_connector_state *new_astdp_state, *astdp_state;
 	struct drm_device *dev = connector->dev;
 
 	if (drm_WARN_ON(dev, !connector->state))
@@ -470,6 +491,10 @@ ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
 		return NULL;
 	__drm_atomic_helper_connector_duplicate_state(connector, &new_astdp_state->base);
 
+	astdp_state = to_ast_astdp_connector_state(connector->state);
+
+	new_astdp_state->mode_index = astdp_state->mode_index;
+
 	return &new_astdp_state->base;
 }
 
Signature · 1 line
2.48.1
reviewer Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] drm/ast: astdp: Store mode index in connector state

Quoted 5 lines · Thomas Zimmermann

Look up the mode index for the astdp transmitter ship in the encoder's atomic check and report an error if the display mode is not supported.

The lookup uses the DRM display mode instead of the driver's internal VBIOS mode. Both are be equivalent. The modesetting code later reads

Typo: Both are equivalent

Quoted 1 line

the calculated index from the connector state to avoid recalculating it.

Thanks, it looks good to me.

Quoted 96 lines
---
  drivers/gpu/drm/ast/ast_dp.c | 37 ++++++++++++++++++++++++++++++------
  1 file changed, 31 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +31 -6
index e7b00153c37e..056991afde7f 100644
@@ -5,6 +5,7 @@
  #include <linux/firmware.h>
  #include <linux/delay.h>
 
+#include <drm/drm_atomic.h>
  #include <drm/drm_atomic_state_helper.h>
  #include <drm/drm_edid.h>
  #include <drm/drm_modeset_helper_vtables.h>
@@ -44,6 +45,8 @@ static const struct ast_astdp_mode_index_table_entry ast_astdp_mode_index_table[
 
  struct ast_astdp_connector_state {
  	struct drm_connector_state base;
+
+	int mode_index;
  };
 
  static struct ast_astdp_connector_state *
@@ -305,14 +308,12 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder
  	struct ast_device *ast = to_ast_device(dev);
  	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
  	const struct ast_vbios_enhtable *vmode = ast_crtc_state->vmode;
-	int mode_index;
+	struct ast_astdp_connector_state *astdp_conn_state =
+		to_ast_astdp_connector_state(conn_state);
+	int mode_index = astdp_conn_state->mode_index;
  	u8 refresh_rate_index;
  	u8 vgacre0, vgacre1, vgacre2;
 
-	mode_index = ast_astdp_get_mode_index(vmode->hde, vmode->vde);
-	if (drm_WARN_ON(dev, mode_index < 0))
-		return;
-
  	if (drm_WARN_ON(dev, vmode->refresh_rate_index < 1 || vmode->refresh_rate_index > 255))
  		return;
  	refresh_rate_index = vmode->refresh_rate_index - 1;
@@ -368,10 +369,30 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
  	ast_dp_set_phy_sleep(ast, true);
  }
 
+static int ast_astdp_encoder_helper_atomic_check(struct drm_encoder *encoder,
+						 struct drm_crtc_state *crtc_state,
+						 struct drm_connector_state *conn_state)
+{
+	const struct drm_display_mode *mode = &crtc_state->mode;
+	struct ast_astdp_connector_state *astdp_conn_state =
+		to_ast_astdp_connector_state(conn_state);
+	int res;
+
+	if (drm_atomic_crtc_needs_modeset(crtc_state)) {
+		res = ast_astdp_get_mode_index(mode->hdisplay, mode->vdisplay);
+		if (res < 0)
+			return res;
+		astdp_conn_state->mode_index = res;
+	}
+
+	return 0;
+}
+
  static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
  	.atomic_mode_set = ast_astdp_encoder_helper_atomic_mode_set,
  	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
  	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,
+	.atomic_check = ast_astdp_encoder_helper_atomic_check,
  };
 
  /*
@@ -459,7 +480,7 @@ static void ast_astdp_connector_reset(struct drm_connector *connector)
  static struct drm_connector_state *
  ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
  {
-	struct ast_astdp_connector_state *new_astdp_state;
+	struct ast_astdp_connector_state *new_astdp_state, *astdp_state;
  	struct drm_device *dev = connector->dev;
 
  	if (drm_WARN_ON(dev, !connector->state))
@@ -470,6 +491,10 @@ ast_astdp_connector_atomic_duplicate_state(struct drm_connector *connector)
  		return NULL;
  	__drm_atomic_helper_connector_duplicate_state(connector, &new_astdp_state->base);
 
+	astdp_state = to_ast_astdp_connector_state(connector->state);
+
+	new_astdp_state->mode_index = astdp_state->mode_index;
+
  	return &new_astdp_state->base;
  }
 
author maintainer
#7 lore raw

PATCH 4/4 drm/ast: astdp: Validate display modes

In reply to Thomas Zimmermann

Validate each display mode against the astdp transmitter chips. Filters out modes that the chip does not support.

---
 drivers/gpu/drm/ast/ast_dp.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/gpu/drm/ast/ast_dp.c +14 -0
index 056991afde7f..19c04687b0fe 100644
@@ -300,6 +300,19 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
 	.destroy = drm_encoder_cleanup,
 };
 
+static enum drm_mode_status
+ast_astdp_encoder_helper_mode_valid(struct drm_encoder *encoder,
+				    const struct drm_display_mode *mode)
+{
+	int res;
+
+	res = ast_astdp_get_mode_index(mode->hdisplay, mode->vdisplay);
+	if (res < 0)
+		return MODE_NOMODE;
+
+	return MODE_OK;
+}
+
 static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder,
 						     struct drm_crtc_state *crtc_state,
 						     struct drm_connector_state *conn_state)
@@ -389,6 +402,7 @@ static int ast_astdp_encoder_helper_atomic_check(struct drm_encoder *encoder,
 }
 
 static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
+	.mode_valid = ast_astdp_encoder_helper_mode_valid,
 	.atomic_mode_set = ast_astdp_encoder_helper_atomic_mode_set,
 	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
 	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,
Signature · 1 line
2.48.1
reviewer Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] drm/ast: astdp: Validate display modes

Quoted 2 lines · Thomas Zimmermann

Validate each display mode against the astdp transmitter chips. Filters out modes that the chip does not support.

Thanks, it looks good to me.

Quoted 38 lines
---
  drivers/gpu/drm/ast/ast_dp.c | 14 ++++++++++++++
  1 file changed, 14 insertions(+)
drivers/gpu/drm/ast/ast_dp.c +14 -0
index 056991afde7f..19c04687b0fe 100644
@@ -300,6 +300,19 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
  	.destroy = drm_encoder_cleanup,
  };
 
+static enum drm_mode_status
+ast_astdp_encoder_helper_mode_valid(struct drm_encoder *encoder,
+				    const struct drm_display_mode *mode)
+{
+	int res;
+
+	res = ast_astdp_get_mode_index(mode->hdisplay, mode->vdisplay);
+	if (res < 0)
+		return MODE_NOMODE;
+
+	return MODE_OK;
+}
+
  static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoder,
  						     struct drm_crtc_state *crtc_state,
  						     struct drm_connector_state *conn_state)
@@ -389,6 +402,7 @@ static int ast_astdp_encoder_helper_atomic_check(struct drm_encoder *encoder,
  }
 
  static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
+	.mode_valid = ast_astdp_encoder_helper_mode_valid,
  	.atomic_mode_set = ast_astdp_encoder_helper_atomic_mode_set,
  	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
  	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,