Skip to contentSkip to conversation

drm/ast: Untangle the chaos in mode setting

PATCH In review Thomas Zimmermann 2 participants 20 messages Jun 27, 2024 – Jun 28, 2024

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: Untangle the chaos in mode setting

The CRTC's mode-setting code contains quite a bit of code that belongs to the planes or various encoder chips. This patchset refactors these bits and moves things to the correct places.

With the patches applied, the remaining DPMS function will be gone and its content be moved. Several code duplications will be removed. There was also a bugfix wrt the VGA SCREEN_DISABLE bit, but it's unclear if the bug had any effect in practice.

Tested with AST2100 and AST2600 with VGA and DP outputs.

Thomas Zimmermann (8):
drm/ast: Implement atomic enable/disable for encoders drm/ast: Program mode for AST DP in atomic_mode_set drm/ast: Move mode-setting code into mode_set_nofb CRTC helper drm/ast: Handle primary-plane format setup in atomic_update drm/ast: Remove gamma LUT updates from DPMS code drm/ast: Only set VGA SCREEN_DISABLE bit in CRTC code drm/ast: Inline ast_crtc_dpms() into callers drm/ast: Use drm_atomic_helper_commit_tail() helper

 drivers/gpu/drm/ast/ast_mode.c | 204 ++++++++++++++++++---------------
 drivers/gpu/drm/ast/ast_reg.h  |  10 +-
 2 files changed, 112 insertions(+), 102 deletions(-)
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH 1/8 drm/ast: Implement atomic enable/disable for encoders

The CRTC helpers contain code to enable and disable DisplayPort connectors. Implement this functionality in the respective connector's atomic_enable/atomic_disable callbacks. DRM's atomic-modesetting helpers will call the functions as part of the atomic commit.

---
 drivers/gpu/drm/ast/ast_mode.c | 66 +++++++++++++++++++++++++---------
 1 file changed, 50 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +50 -16
index 2fd9c78eab73..7f9f77b7ee73 100644
@@ -1034,14 +1034,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	case DRM_MODE_DPMS_ON:
 		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-		if (ast->tx_chip_types & AST_TX_DP501_BIT)
-			ast_set_dp501_video_output(crtc->dev, 1);
-
-		if (ast->tx_chip_types & AST_TX_ASTDP_BIT) {
-			ast_dp_power_on_off(crtc->dev, AST_DP_POWER_ON);
-			ast_wait_for_vretrace(ast);
-			ast_dp_set_on_off(crtc->dev, 1);
-		}
 
 		ast_state = to_ast_crtc_state(crtc->state);
 		format = ast_state->format;
@@ -1061,14 +1053,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	case DRM_MODE_DPMS_SUSPEND:
 	case DRM_MODE_DPMS_OFF:
 		ch = mode;
-		if (ast->tx_chip_types & AST_TX_DP501_BIT)
-			ast_set_dp501_video_output(crtc->dev, 0);
-
-		if (ast->tx_chip_types & AST_TX_ASTDP_BIT) {
-			ast_dp_set_on_off(crtc->dev, 0);
-			ast_dp_power_on_off(crtc->dev, AST_DP_POWER_OFF);
-		}
-
 		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0x20);
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
 		break;
@@ -1521,6 +1505,27 @@ static const struct drm_encoder_funcs ast_dp501_encoder_funcs = {
 	.destroy = drm_encoder_cleanup,
 };
 
+static void ast_dp501_encoder_helper_atomic_enable(struct drm_encoder *encoder,
+						   struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_set_dp501_video_output(dev, 1);
+}
+
+static void ast_dp501_encoder_helper_atomic_disable(struct drm_encoder *encoder,
+						    struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_set_dp501_video_output(dev, 0);
+}
+
+static const struct drm_encoder_helper_funcs ast_dp501_encoder_helper_funcs = {
+	.atomic_enable = ast_dp501_encoder_helper_atomic_enable,
+	.atomic_disable = ast_dp501_encoder_helper_atomic_disable,
+};
+
 /*
  * DP501 Connector
  */
@@ -1607,6 +1612,8 @@ static int ast_dp501_output_init(struct ast_device *ast)
 			       DRM_MODE_ENCODER_TMDS, NULL);
 	if (ret)
 		return ret;
+	drm_encoder_helper_add(encoder, &ast_dp501_encoder_helper_funcs);
+
 	encoder->possible_crtcs = drm_crtc_mask(crtc);
 
 	ret = ast_dp501_connector_init(dev, connector);
@@ -1628,6 +1635,31 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
 	.destroy = drm_encoder_cleanup,
 };
 
+static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,
+						   struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+	struct ast_device *ast = to_ast_device(dev);
+
+	ast_dp_power_on_off(dev, AST_DP_POWER_ON);
+	ast_wait_for_vretrace(ast);
+	ast_dp_set_on_off(dev, 1);
+}
+
+static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
+						    struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_dp_set_on_off(dev, 0);
+	ast_dp_power_on_off(dev, AST_DP_POWER_OFF);
+}
+
+static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
+	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
+	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,
+};
+
 /*
  * ASPEED Display-Port Connector
  */
@@ -1726,6 +1758,8 @@ static int ast_astdp_output_init(struct ast_device *ast)
 			       DRM_MODE_ENCODER_TMDS, NULL);
 	if (ret)
 		return ret;
+	drm_encoder_helper_add(encoder, &ast_astdp_encoder_helper_funcs);
+
 	encoder->possible_crtcs = drm_crtc_mask(crtc);
 
 	ret = ast_astdp_connector_init(dev, connector);
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] drm/ast: Implement atomic enable/disable for encoders

Quoted 4 lines · Thomas Zimmermann

The CRTC helpers contain code to enable and disable DisplayPort connectors. Implement this functionality in the respective connector's atomic_enable/atomic_disable callbacks. DRM's atomic-modesetting helpers will call the functions as part of the atomic commit.

Thanks, it looks good te me.

Quoted 118 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 66 +++++++++++++++++++++++++---------
  1 file changed, 50 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +50 -16
index 2fd9c78eab73..7f9f77b7ee73 100644
@@ -1034,14 +1034,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  	case DRM_MODE_DPMS_ON:
  		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-		if (ast->tx_chip_types & AST_TX_DP501_BIT)
-			ast_set_dp501_video_output(crtc->dev, 1);
-
-		if (ast->tx_chip_types & AST_TX_ASTDP_BIT) {
-			ast_dp_power_on_off(crtc->dev, AST_DP_POWER_ON);
-			ast_wait_for_vretrace(ast);
-			ast_dp_set_on_off(crtc->dev, 1);
-		}
 
  		ast_state = to_ast_crtc_state(crtc->state);
  		format = ast_state->format;
@@ -1061,14 +1053,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  	case DRM_MODE_DPMS_SUSPEND:
  	case DRM_MODE_DPMS_OFF:
  		ch = mode;
-		if (ast->tx_chip_types & AST_TX_DP501_BIT)
-			ast_set_dp501_video_output(crtc->dev, 0);
-
-		if (ast->tx_chip_types & AST_TX_ASTDP_BIT) {
-			ast_dp_set_on_off(crtc->dev, 0);
-			ast_dp_power_on_off(crtc->dev, AST_DP_POWER_OFF);
-		}
-
  		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0x20);
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
  		break;
@@ -1521,6 +1505,27 @@ static const struct drm_encoder_funcs ast_dp501_encoder_funcs = {
  	.destroy = drm_encoder_cleanup,
  };
 
+static void ast_dp501_encoder_helper_atomic_enable(struct drm_encoder *encoder,
+						   struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_set_dp501_video_output(dev, 1);
+}
+
+static void ast_dp501_encoder_helper_atomic_disable(struct drm_encoder *encoder,
+						    struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_set_dp501_video_output(dev, 0);
+}
+
+static const struct drm_encoder_helper_funcs ast_dp501_encoder_helper_funcs = {
+	.atomic_enable = ast_dp501_encoder_helper_atomic_enable,
+	.atomic_disable = ast_dp501_encoder_helper_atomic_disable,
+};
+
  /*
   * DP501 Connector
   */
@@ -1607,6 +1612,8 @@ static int ast_dp501_output_init(struct ast_device *ast)
  			       DRM_MODE_ENCODER_TMDS, NULL);
  	if (ret)
  		return ret;
+	drm_encoder_helper_add(encoder, &ast_dp501_encoder_helper_funcs);
+
  	encoder->possible_crtcs = drm_crtc_mask(crtc);
 
  	ret = ast_dp501_connector_init(dev, connector);
@@ -1628,6 +1635,31 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
  	.destroy = drm_encoder_cleanup,
  };
 
+static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,
+						   struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+	struct ast_device *ast = to_ast_device(dev);
+
+	ast_dp_power_on_off(dev, AST_DP_POWER_ON);
+	ast_wait_for_vretrace(ast);
+	ast_dp_set_on_off(dev, 1);
+}
+
+static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
+						    struct drm_atomic_state *state)
+{
+	struct drm_device *dev = encoder->dev;
+
+	ast_dp_set_on_off(dev, 0);
+	ast_dp_power_on_off(dev, AST_DP_POWER_OFF);
+}
+
+static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
+	.atomic_enable = ast_astdp_encoder_helper_atomic_enable,
+	.atomic_disable = ast_astdp_encoder_helper_atomic_disable,
+};
+
  /*
   * ASPEED Display-Port Connector
   */
@@ -1726,6 +1758,8 @@ static int ast_astdp_output_init(struct ast_device *ast)
  			       DRM_MODE_ENCODER_TMDS, NULL);
  	if (ret)
  		return ret;
+	drm_encoder_helper_add(encoder, &ast_astdp_encoder_helper_funcs);
+
  	encoder->possible_crtcs = drm_crtc_mask(crtc);
 
  	ret = ast_astdp_connector_init(dev, connector);
author maintainer
#3 lore raw

PATCH 2/8 drm/ast: Program mode for AST DP in atomic_mode_set

In reply to Thomas Zimmermann

The CRTC's atomic flush function contains code to program the display mode ot the AST DP chip. Move the code to the connector's atomic_mode_set callback. The DRM atomic-modesetting code invoke this callback as part of the atomic commit.

---
 drivers/gpu/drm/ast/ast_mode.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +12 -5
index 7f9f77b7ee73..421fcdad40e4 100644
@@ -1190,7 +1190,6 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 	struct drm_device *dev = crtc->dev;
 	struct ast_device *ast = to_ast_device(dev);
 	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
-	struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
 
 	/*
 	 * The gamma LUT has to be reloaded after changing the primary
@@ -1204,10 +1203,6 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 		else
 			ast_crtc_set_gamma_linear(ast, ast_crtc_state->format);
 	}
-
-	//Set Aspeed Display-Port
-	if (ast->tx_chip_types & AST_TX_ASTDP_BIT)
-		ast_dp_set_mode(crtc, vbios_mode_info);
 }
 
 static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
@@ -1635,6 +1630,17 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
 	.destroy = drm_encoder_cleanup,
 };
 
+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)
+{
+	struct drm_crtc *crtc = crtc_state->crtc;
+	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
+
+	ast_dp_set_mode(crtc, vbios_mode_info);
+}
+
 static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,
 						   struct drm_atomic_state *state)
 {
@@ -1656,6 +1662,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
 }
 
 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,
 };
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 2/8
#4 lore raw

Re: [PATCH 2/8] drm/ast: Program mode for AST DP in atomic_mode_set

Quoted 4 lines · Thomas Zimmermann

The CRTC's atomic flush function contains code to program the display mode ot the AST DP chip. Move the code to the connector's atomic_mode_set callback. The DRM atomic-modesetting code invoke this callback as part of the atomic commit.

Thanks, it looks good te me.

Quoted 55 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 17 ++++++++++++-----
  1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +12 -5
index 7f9f77b7ee73..421fcdad40e4 100644
@@ -1190,7 +1190,6 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
  	struct drm_device *dev = crtc->dev;
  	struct ast_device *ast = to_ast_device(dev);
  	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
-	struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
 
  	/*
  	 * The gamma LUT has to be reloaded after changing the primary
@@ -1204,10 +1203,6 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
  		else
  			ast_crtc_set_gamma_linear(ast, ast_crtc_state->format);
  	}
-
-	//Set Aspeed Display-Port
-	if (ast->tx_chip_types & AST_TX_ASTDP_BIT)
-		ast_dp_set_mode(crtc, vbios_mode_info);
  }
 
  static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
@@ -1635,6 +1630,17 @@ static const struct drm_encoder_funcs ast_astdp_encoder_funcs = {
  	.destroy = drm_encoder_cleanup,
  };
 
+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)
+{
+	struct drm_crtc *crtc = crtc_state->crtc;
+	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
+
+	ast_dp_set_mode(crtc, vbios_mode_info);
+}
+
  static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,
  						   struct drm_atomic_state *state)
  {
@@ -1656,6 +1662,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,
  }
 
  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,
  };
author maintainer
#5 lore raw

PATCH 3/8 drm/ast: Move mode-setting code into mode_set_nofb CRTC helper

In reply to Thomas Zimmermann

Do all mode setting in ast_crtc_helper_mode_set_nofb(), which always runs after disabling the CRTC and before programming the planes. Removes implicit synchronization between the CRTC's atomic disable, enable and the vertical retrace.

Display-mode updates require HW cursors to be disabled. The HW cursor only picks up changes at vertical retrace periods. So the CRTC's atomic_disable helper waited for the retrace to delay any following mode-setting operations, which then happened in atomic_enable. See [1] for a description of the problem.

With the CRTC helper callback mode_set_nofb, we can now synchronize and reprogram in the same place. As it always runs before the plane update, the plane code can be reordered with the CRTC's later atomic_enable et al.

---
 drivers/gpu/drm/ast/ast_mode.c | 52 ++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 24 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +28 -24
index 421fcdad40e4..e8312b3472ed 100644
@@ -1131,6 +1131,33 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode
 	return status;
 }
 
+static void ast_crtc_helper_mode_set_nofb(struct drm_crtc *crtc)
+{
+	struct drm_device *dev = crtc->dev;
+	struct ast_device *ast = to_ast_device(dev);
+	struct drm_crtc_state *crtc_state = crtc->state;
+	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	struct ast_vbios_mode_info *vbios_mode_info =
+		&ast_crtc_state->vbios_mode_info;
+	struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
+
+	/*
+	 * Ensure that no scanout takes place before reprogramming mode
+	 * and format registers.
+	 *
+	 * TODO: Get vblank interrupts working and remove this line.
+	 */
+	ast_wait_for_vretrace(ast);
+
+	ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa1, 0x06);
+	ast_set_std_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_crtthd_reg(ast);
+	ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info);
+}
+
 static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 					struct drm_atomic_state *state)
 {
@@ -1207,30 +1234,12 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 
 static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
 {
-	struct drm_device *dev = crtc->dev;
-	struct ast_device *ast = to_ast_device(dev);
-	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
-	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
-	struct ast_vbios_mode_info *vbios_mode_info =
-		&ast_crtc_state->vbios_mode_info;
-	struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
-
-	ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa1, 0x06);
-	ast_set_std_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_crtthd_reg(ast);
-	ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info);
-
 	ast_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
 }
 
 static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
 {
 	struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
-	struct drm_device *dev = crtc->dev;
-	struct ast_device *ast = to_ast_device(dev);
 
 	ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
 
@@ -1245,16 +1254,11 @@ static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_ato
 	 * simple pageflips on the planes.
 	 */
 	drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false);
-
-	/*
-	 * Ensure that no scanout takes place before reprogramming mode
-	 * and format registers.
-	 */
-	ast_wait_for_vretrace(ast);
 }
 
 static const struct drm_crtc_helper_funcs ast_crtc_helper_funcs = {
 	.mode_valid = ast_crtc_helper_mode_valid,
+	.mode_set_nofb = ast_crtc_helper_mode_set_nofb,
 	.atomic_check = ast_crtc_helper_atomic_check,
 	.atomic_flush = ast_crtc_helper_atomic_flush,
 	.atomic_enable = ast_crtc_helper_atomic_enable,
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 3/8
#6 lore raw

Re: [PATCH 3/8] drm/ast: Move mode-setting code into mode_set_nofb CRTC helper

Quoted 11 lines · Thomas Zimmermann

Do all mode setting in ast_crtc_helper_mode_set_nofb(), which always runs after disabling the CRTC and before programming the planes. Removes implicit synchronization between the CRTC's atomic disable, enable and the vertical retrace.

Display-mode updates require HW cursors to be disabled. The HW cursor only picks up changes at vertical retrace periods. So the CRTC's atomic_disable helper waited for the retrace to delay any following mode-setting operations, which then happened in atomic_enable. See [1] for a description of the problem.

Quoted 4 lines

With the CRTC helper callback mode_set_nofb, we can now synchronize and reprogram in the same place. As it always runs before the plane update, the plane code can be reordered with the CRTC's later atomic_enable et al.

Thanks, it looks good te me.

Quoted 94 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 52 ++++++++++++++++++----------------
  1 file changed, 28 insertions(+), 24 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +28 -24
index 421fcdad40e4..e8312b3472ed 100644
@@ -1131,6 +1131,33 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode
  	return status;
  }
 
+static void ast_crtc_helper_mode_set_nofb(struct drm_crtc *crtc)
+{
+	struct drm_device *dev = crtc->dev;
+	struct ast_device *ast = to_ast_device(dev);
+	struct drm_crtc_state *crtc_state = crtc->state;
+	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
+	struct ast_vbios_mode_info *vbios_mode_info =
+		&ast_crtc_state->vbios_mode_info;
+	struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
+
+	/*
+	 * Ensure that no scanout takes place before reprogramming mode
+	 * and format registers.
+	 *
+	 * TODO: Get vblank interrupts working and remove this line.
+	 */
+	ast_wait_for_vretrace(ast);
+
+	ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa1, 0x06);
+	ast_set_std_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info);
+	ast_set_crtthd_reg(ast);
+	ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info);
+}
+
  static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
  					struct drm_atomic_state *state)
  {
@@ -1207,30 +1234,12 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 
  static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
  {
-	struct drm_device *dev = crtc->dev;
-	struct ast_device *ast = to_ast_device(dev);
-	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
-	struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
-	struct ast_vbios_mode_info *vbios_mode_info =
-		&ast_crtc_state->vbios_mode_info;
-	struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
-
-	ast_set_vbios_mode_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_index_reg(ast, AST_IO_VGACRI, 0xa1, 0x06);
-	ast_set_std_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_crtc_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_dclk_reg(ast, adjusted_mode, vbios_mode_info);
-	ast_set_crtthd_reg(ast);
-	ast_set_sync_reg(ast, adjusted_mode, vbios_mode_info);
-
  	ast_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
  }
 
  static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
  {
  	struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
-	struct drm_device *dev = crtc->dev;
-	struct ast_device *ast = to_ast_device(dev);
 
  	ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
 
@@ -1245,16 +1254,11 @@ static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_ato
  	 * simple pageflips on the planes.
  	 */
  	drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false);
-
-	/*
-	 * Ensure that no scanout takes place before reprogramming mode
-	 * and format registers.
-	 */
-	ast_wait_for_vretrace(ast);
  }
 
  static const struct drm_crtc_helper_funcs ast_crtc_helper_funcs = {
  	.mode_valid = ast_crtc_helper_mode_valid,
+	.mode_set_nofb = ast_crtc_helper_mode_set_nofb,
  	.atomic_check = ast_crtc_helper_atomic_check,
  	.atomic_flush = ast_crtc_helper_atomic_flush,
  	.atomic_enable = ast_crtc_helper_atomic_enable,
author maintainer
#7 lore raw

PATCH 4/8 drm/ast: Handle primary-plane format setup in atomic_update

In reply to Thomas Zimmermann

Several color registers are programmed in the DPMS code of the CRTC's atomic_enable helper. This code will not be executed if the color format changes without a full mode switch. The same code already exists in the atomic_update helper of the primary plane. There, the code will not run if only the display mode changes.

The color format is a property of the primary plane, so consolidate all code in the plane's atomic_update.

---
 drivers/gpu/drm/ast/ast_mode.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +3 -8
index e8312b3472ed..6a81d657175d 100644
@@ -649,12 +649,12 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
 	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, plane);
 	struct drm_framebuffer *old_fb = old_plane_state->fb;
 	struct ast_plane *ast_plane = to_ast_plane(plane);
+	struct drm_crtc *crtc = plane_state->crtc;
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 	struct drm_rect damage;
 	struct drm_atomic_helper_damage_iter iter;
 
-	if (!old_fb || (fb->format != old_fb->format)) {
-		struct drm_crtc *crtc = plane_state->crtc;
-		struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	if (!old_fb || (fb->format != old_fb->format) || crtc_state->mode_changed) {
 		struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
 		struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
 
@@ -1025,7 +1025,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
 	struct ast_crtc_state *ast_state;
 	const struct drm_format_info *format;
-	struct ast_vbios_mode_info *vbios_mode_info;
 
 	/* TODO: Maybe control display signal generation with
 	 *       Sync Enable (bit CR17.7).
@@ -1039,10 +1038,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 		format = ast_state->format;
 
 		if (format) {
-			vbios_mode_info = &ast_state->vbios_mode_info;
-
-			ast_set_color_reg(ast, format);
-			ast_set_vbios_color_reg(ast, format, vbios_mode_info);
 			if (crtc->state->gamma_lut)
 				ast_crtc_set_gamma(ast, format, crtc->state->gamma_lut->data);
 			else
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 4/8
#8 lore raw

Re: [PATCH 4/8] drm/ast: Handle primary-plane format setup in atomic_update

Quoted 5 lines · Thomas Zimmermann

Several color registers are programmed in the DPMS code of the CRTC's atomic_enable helper. This code will not be executed if the color format changes without a full mode switch. The same code already exists in the atomic_update helper of the primary plane. There, the code will not run if only the display mode changes.

This last sentence is unclear to me.

Quoted 3 lines

The color format is a property of the primary plane, so consolidate all code in the plane's atomic_update.

With the comment clarified,

Quoted 45 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 11 +++--------
  1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +3 -8
index e8312b3472ed..6a81d657175d 100644
@@ -649,12 +649,12 @@ static void ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
  	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, plane);
  	struct drm_framebuffer *old_fb = old_plane_state->fb;
  	struct ast_plane *ast_plane = to_ast_plane(plane);
+	struct drm_crtc *crtc = plane_state->crtc;
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
  	struct drm_rect damage;
  	struct drm_atomic_helper_damage_iter iter;
 
-	if (!old_fb || (fb->format != old_fb->format)) {
-		struct drm_crtc *crtc = plane_state->crtc;
-		struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	if (!old_fb || (fb->format != old_fb->format) || crtc_state->mode_changed) {
  		struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state);
  		struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info;
 
@@ -1025,7 +1025,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
  	struct ast_crtc_state *ast_state;
  	const struct drm_format_info *format;
-	struct ast_vbios_mode_info *vbios_mode_info;
 
  	/* TODO: Maybe control display signal generation with
  	 *       Sync Enable (bit CR17.7).
@@ -1039,10 +1038,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  		format = ast_state->format;
 
  		if (format) {
-			vbios_mode_info = &ast_state->vbios_mode_info;
-
-			ast_set_color_reg(ast, format);
-			ast_set_vbios_color_reg(ast, format, vbios_mode_info);
  			if (crtc->state->gamma_lut)
  				ast_crtc_set_gamma(ast, format, crtc->state->gamma_lut->data);
  			else
author maintainer
#9 lore raw

Re: [PATCH 4/8] drm/ast: Handle primary-plane format setup in atomic_update

Hi

Am 28.06.24 um 11:54 schrieb Jocelyn Falempe:

Quoted 10 lines · Thomas Zimmermann
Quoted 5 lines

Several color registers are programmed in the DPMS code of the CRTC's atomic_enable helper. This code will not be executed if the color format changes without a full mode switch. The same code already exists in the atomic_update helper of the primary plane. There, the code will not run if only the display mode changes.

This last sentence is unclear to me.

OK, sure. It means that the plane's code might not run if the color format stays the same when the display mode changes. I'll try to reword.

Best regards
Thomas

Quoted 56 lines
Quoted 4 lines

The color format is a property of the primary plane, so consolidate all code in the plane's atomic_update.

With the comment clarified,

Quoted 46 lines

---
  drivers/gpu/drm/ast/ast_mode.c | 11 +++--------

  1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +3 -2
index e8312b3472ed..6a81d657175d 100644
@@ -649,12 +649,12 @@ static void 
 ast_primary_plane_helper_atomic_update(struct drm_plane *plane,
       struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, plane);
       struct drm_framebuffer *old_fb = old_plane_state->fb;
       struct ast_plane *ast_plane = to_ast_plane(plane);
+    struct drm_crtc *crtc = plane_state->crtc;
+    struct drm_crtc_state *crtc_state = 
 drm_atomic_get_new_crtc_state(state, crtc);
       struct drm_rect damage;
       struct drm_atomic_helper_damage_iter iter;
   -    if (!old_fb || (fb->format != old_fb->format)) {
-        struct drm_crtc *crtc = plane_state->crtc;
-        struct drm_crtc_state *crtc_state = 
 drm_atomic_get_new_crtc_state(state, crtc);
+    if (!old_fb || (fb->format != old_fb->format) || 

crtc_state->mode_changed) {
          struct ast_crtc_state *ast_crtc_state = to_ast_crtc_state(crtc_state); struct ast_vbios_mode_info *vbios_mode_info = &ast_crtc_state->vbios_mode_info; @@ -1025,7 +1025,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode) u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
      struct ast_crtc_state *ast_state;
      const struct drm_format_info *format;
-    struct ast_vbios_mode_info *vbios_mode_info;
        /* TODO: Maybe control display signal generation with
       *       Sync Enable (bit CR17.7).

drivers/gpu/drm/ast/ast_mode.c +0 -4
@@ -1039,10 +1038,6 @@ static void ast_crtc_dpms(struct drm_crtc 
 *crtc, int mode)
           format = ast_state->format;
             if (format) {
-            vbios_mode_info = &ast_state->vbios_mode_info;
-
-            ast_set_color_reg(ast, format);
-            ast_set_vbios_color_reg(ast, format, vbios_mode_info);
               if (crtc->state->gamma_lut)
                   ast_crtc_set_gamma(ast, format, crtc->state->gamma_lut->data);

              else

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
author maintainer
#10 lore raw

PATCH 5/8 drm/ast: Remove gamma LUT updates from DPMS code

In reply to Thomas Zimmermann

The DPMS code, called from the CRTC's atomic_enable, rewrites the gamma LUT. This is already done in the CRTC's atomic_flush. Remove the duplication.

---
 drivers/gpu/drm/ast/ast_mode.c | 12 ------------
 1 file changed, 12 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +0 -12
index 6a81d657175d..e90179bc0842 100644
@@ -1023,8 +1023,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 {
 	struct ast_device *ast = to_ast_device(crtc->dev);
 	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
-	struct ast_crtc_state *ast_state;
-	const struct drm_format_info *format;
 
 	/* TODO: Maybe control display signal generation with
 	 *       Sync Enable (bit CR17.7).
@@ -1033,16 +1031,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	case DRM_MODE_DPMS_ON:
 		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-
-		ast_state = to_ast_crtc_state(crtc->state);
-		format = ast_state->format;
-
-		if (format) {
-			if (crtc->state->gamma_lut)
-				ast_crtc_set_gamma(ast, format, crtc->state->gamma_lut->data);
-			else
-				ast_crtc_set_gamma_linear(ast, format);
-		}
 		break;
 	case DRM_MODE_DPMS_STANDBY:
 	case DRM_MODE_DPMS_SUSPEND:
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 5/8
#11 lore raw

Re: [PATCH 5/8] drm/ast: Remove gamma LUT updates from DPMS code

Quoted 3 lines · Thomas Zimmermann

The DPMS code, called from the CRTC's atomic_enable, rewrites the gamma LUT. This is already done in the CRTC's atomic_flush. Remove the duplication.

Thanks, it looks good te me.

Quoted 36 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 12 ------------
  1 file changed, 12 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +0 -12
index 6a81d657175d..e90179bc0842 100644
@@ -1023,8 +1023,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  {
  	struct ast_device *ast = to_ast_device(crtc->dev);
  	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
-	struct ast_crtc_state *ast_state;
-	const struct drm_format_info *format;
 
  	/* TODO: Maybe control display signal generation with
  	 *       Sync Enable (bit CR17.7).
@@ -1033,16 +1031,6 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  	case DRM_MODE_DPMS_ON:
  		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-
-		ast_state = to_ast_crtc_state(crtc->state);
-		format = ast_state->format;
-
-		if (format) {
-			if (crtc->state->gamma_lut)
-				ast_crtc_set_gamma(ast, format, crtc->state->gamma_lut->data);
-			else
-				ast_crtc_set_gamma_linear(ast, format);
-		}
  		break;
  	case DRM_MODE_DPMS_STANDBY:
  	case DRM_MODE_DPMS_SUSPEND:
author maintainer
#12 lore raw

PATCH 6/8 drm/ast: Only set VGA SCREEN_DISABLE bit in CRTC code

In reply to Thomas Zimmermann

The SCREEN_DISABLE bit controls scanout from display memory. The bit affects all planes, so set it only in the CRTC's atomic enable and disable functions.

A number of bugs affect this fix. First of all, ast_set_std_regs() tries to set VGASR1 except for the SD bit. Bit the read bitmask is invert, so it preserves anything exceptt the SD bit. Fix this by inverting the read mask.

The second issue is that primary-plane and CRTC helpers modify the SD bit. The bit controls scanout for all planes, primary and HW cursor, so set it only in the CRTC code.

Further add a constant to represent the SD bit in VGASR1. Keep the plane's atomic_disable around to make the DRM framework happy.

---
 drivers/gpu/drm/ast/ast_mode.c | 14 +++++++-------
 drivers/gpu/drm/ast/ast_reg.h  |  1 +
 2 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +7 -7
index e90179bc0842..77358b587098 100644
@@ -303,7 +303,7 @@ static void ast_set_std_reg(struct ast_device *ast,
 
 	/* Set SEQ; except Screen Disable field */
 	ast_set_index_reg(ast, AST_IO_VGASRI, 0x00, 0x03);
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, stdtable->seq[0]);
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0x20, stdtable->seq[0]);
 	for (i = 1; i < 4; i++) {
 		jreg = stdtable->seq[i];
 		ast_set_index_reg(ast, AST_IO_VGASRI, (i + 1), jreg);
@@ -690,15 +690,15 @@ static void ast_primary_plane_helper_atomic_enable(struct drm_plane *plane,
 	 * Therefore only reprogram the address after enabling the plane.
 	 */
 	ast_set_start_address_crt1(ast, (u32)ast_plane->offset);
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x1, 0xdf, 0x00);
 }
 
 static void ast_primary_plane_helper_atomic_disable(struct drm_plane *plane,
 						    struct drm_atomic_state *state)
 {
-	struct ast_device *ast = to_ast_device(plane->dev);
-
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x1, 0xdf, 0x20);
+	/*
+	 * Keep this empty function to avoid calling
+	 * atomic_update when disabling the plane.
+	 */
 }
 
 static int ast_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
@@ -1029,14 +1029,14 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
 	 */
 	switch (mode) {
 	case DRM_MODE_DPMS_ON:
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
+		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0);
 		break;
 	case DRM_MODE_DPMS_STANDBY:
 	case DRM_MODE_DPMS_SUSPEND:
 	case DRM_MODE_DPMS_OFF:
 		ch = mode;
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0x20);
+		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
 		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
 		break;
 	}
drivers/gpu/drm/ast/ast_reg.h +1 -0
index 62dddbf3fe56..6326cbdadc82 100644
@@ -22,6 +22,7 @@
 #define AST_IO_VGAER_VGA_ENABLE		BIT(0)
 
 #define AST_IO_VGASRI			(0x44)
+#define AST_IO_VGASR1_SD		BIT(5)
 #define AST_IO_VGADRR			(0x47)
 #define AST_IO_VGADWR			(0x48)
 #define AST_IO_VGAPDR		        (0x49)
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 6/8
#13 lore raw

Re: [PATCH 6/8] drm/ast: Only set VGA SCREEN_DISABLE bit in CRTC code

Quoted 9 lines · Thomas Zimmermann

The SCREEN_DISABLE bit controls scanout from display memory. The bit affects all planes, so set it only in the CRTC's atomic enable and disable functions.

A number of bugs affect this fix. First of all, ast_set_std_regs() tries to set VGASR1 except for the SD bit. Bit the read bitmask is invert, so it preserves anything exceptt the SD bit. Fix this by inverting the read mask.

Quoted 6 lines

The second issue is that primary-plane and CRTC helpers modify the SD bit. The bit controls scanout for all planes, primary and HW cursor, so set it only in the CRTC code.

Further add a constant to represent the SD bit in VGASR1. Keep the plane's atomic_disable around to make the DRM framework happy.

Thanks, it looks good te me.

Quoted 69 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 14 +++++++-------
  drivers/gpu/drm/ast/ast_reg.h  |  1 +
  2 files changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +7 -7
index e90179bc0842..77358b587098 100644
@@ -303,7 +303,7 @@ static void ast_set_std_reg(struct ast_device *ast,
 
  	/* Set SEQ; except Screen Disable field */
  	ast_set_index_reg(ast, AST_IO_VGASRI, 0x00, 0x03);
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, stdtable->seq[0]);
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0x20, stdtable->seq[0]);
  	for (i = 1; i < 4; i++) {
  		jreg = stdtable->seq[i];
  		ast_set_index_reg(ast, AST_IO_VGASRI, (i + 1), jreg);
@@ -690,15 +690,15 @@ static void ast_primary_plane_helper_atomic_enable(struct drm_plane *plane,
  	 * Therefore only reprogram the address after enabling the plane.
  	 */
  	ast_set_start_address_crt1(ast, (u32)ast_plane->offset);
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x1, 0xdf, 0x00);
  }
 
  static void ast_primary_plane_helper_atomic_disable(struct drm_plane *plane,
  						    struct drm_atomic_state *state)
  {
-	struct ast_device *ast = to_ast_device(plane->dev);
-
-	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x1, 0xdf, 0x20);
+	/*
+	 * Keep this empty function to avoid calling
+	 * atomic_update when disabling the plane.
+	 */
  }
 
  static int ast_primary_plane_helper_get_scanout_buffer(struct drm_plane *plane,
@@ -1029,14 +1029,14 @@ static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
  	 */
  	switch (mode) {
  	case DRM_MODE_DPMS_ON:
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0);
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
+		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0);
  		break;
  	case DRM_MODE_DPMS_STANDBY:
  	case DRM_MODE_DPMS_SUSPEND:
  	case DRM_MODE_DPMS_OFF:
  		ch = mode;
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI,  0x01, 0xdf, 0x20);
+		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
  		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
  		break;
  	}
drivers/gpu/drm/ast/ast_reg.h +1 -0
index 62dddbf3fe56..6326cbdadc82 100644
@@ -22,6 +22,7 @@
  #define AST_IO_VGAER_VGA_ENABLE		BIT(0)
 
  #define AST_IO_VGASRI			(0x44)
+#define AST_IO_VGASR1_SD		BIT(5)
  #define AST_IO_VGADRR			(0x47)
  #define AST_IO_VGADWR			(0x48)
  #define AST_IO_VGAPDR		        (0x49)
author maintainer
#14 lore raw

PATCH 7/8 drm/ast: Inline ast_crtc_dpms() into callers

In reply to Thomas Zimmermann

The function ast_crtc_dpms() is left over from when the ast driver did not implement atomic modesetting. But DPMS is not supported by atomic modesetting and the helper is only called to enable or disable the CRTC sync pulses. Inline the function into its callers.

To disable the CRTC, ast sets (AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF) in VGACRB6. Replace the constants with the correct register constants for VGACRB6.

---
 drivers/gpu/drm/ast/ast_mode.c | 36 +++++++++++-----------------------
 drivers/gpu/drm/ast/ast_reg.h  |  9 ++-------
 2 files changed, 13 insertions(+), 32 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +11 -25
index 77358b587098..d130c96edf35 100644
@@ -1019,29 +1019,6 @@ static int ast_cursor_plane_init(struct ast_device *ast)
  * CRTC
  */
 
-static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
-{
-	struct ast_device *ast = to_ast_device(crtc->dev);
-	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
-
-	/* TODO: Maybe control display signal generation with
-	 *       Sync Enable (bit CR17.7).
-	 */
-	switch (mode) {
-	case DRM_MODE_DPMS_ON:
-		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0);
-		break;
-	case DRM_MODE_DPMS_STANDBY:
-	case DRM_MODE_DPMS_SUSPEND:
-	case DRM_MODE_DPMS_OFF:
-		ch = mode;
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
-		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
-		break;
-	}
-}
-
 static enum drm_mode_status
 ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
 {
@@ -1217,14 +1194,23 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 
 static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
 {
-	ast_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
+	struct ast_device *ast = to_ast_device(crtc->dev);
+
+	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0x00);
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0x00);
 }
 
 static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
 {
 	struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
+	struct ast_device *ast = to_ast_device(crtc->dev);
+	u8 vgacrb6;
+
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
 
-	ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
+	vgacrb6 = AST_IO_VGACRB6_VSYNC_OFF |
+		  AST_IO_VGACRB6_HSYNC_OFF;
+	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, vgacrb6);
 
 	/*
 	 * HW cursors require the underlying primary plane and CRTC to
drivers/gpu/drm/ast/ast_reg.h +2 -7
index 6326cbdadc82..75671d345057 100644
@@ -32,6 +32,8 @@
 #define AST_IO_VGACR80_PASSWORD		(0xa8)
 #define AST_IO_VGACRA1_VGAIO_DISABLED	BIT(1)
 #define AST_IO_VGACRA1_MMIO_ENABLED	BIT(2)
+#define AST_IO_VGACRB6_HSYNC_OFF	BIT(0)
+#define AST_IO_VGACRB6_VSYNC_OFF	BIT(1)
 #define AST_IO_VGACRCB_HWC_16BPP	BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
 #define AST_IO_VGACRCB_HWC_ENABLED	BIT(1)
 
@@ -76,13 +78,6 @@
 #define ASTDP_HOST_EDID_READ_DONE	BIT(0)
 #define ASTDP_HOST_EDID_READ_DONE_MASK	GENMASK(0, 0)
 
-/*
- * CRB8[b1]: Enable VSYNC off
- * CRB8[b0]: Enable HSYNC off
- */
-#define AST_DPMS_VSYNC_OFF		BIT(1)
-#define AST_DPMS_HSYNC_OFF		BIT(0)
-
 /*
  * CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE
  * Precondition:	A. ~AST_DP_PHY_SLEEP  &&
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 7/8
#15 lore raw

Re: [PATCH 7/8] drm/ast: Inline ast_crtc_dpms() into callers

Quoted 8 lines · Thomas Zimmermann

The function ast_crtc_dpms() is left over from when the ast driver did not implement atomic modesetting. But DPMS is not supported by atomic modesetting and the helper is only called to enable or disable the CRTC sync pulses. Inline the function into its callers.

To disable the CRTC, ast sets (AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF) in VGACRB6. Replace the constants with the correct register constants for VGACRB6.

Thanks, it looks good te me.

Quoted 94 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 36 +++++++++++-----------------------
  drivers/gpu/drm/ast/ast_reg.h  |  9 ++-------
  2 files changed, 13 insertions(+), 32 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +11 -25
index 77358b587098..d130c96edf35 100644
@@ -1019,29 +1019,6 @@ static int ast_cursor_plane_init(struct ast_device *ast)
   * CRTC
   */
 
-static void ast_crtc_dpms(struct drm_crtc *crtc, int mode)
-{
-	struct ast_device *ast = to_ast_device(crtc->dev);
-	u8 ch = AST_DPMS_VSYNC_OFF | AST_DPMS_HSYNC_OFF;
-
-	/* TODO: Maybe control display signal generation with
-	 *       Sync Enable (bit CR17.7).
-	 */
-	switch (mode) {
-	case DRM_MODE_DPMS_ON:
-		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0);
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0);
-		break;
-	case DRM_MODE_DPMS_STANDBY:
-	case DRM_MODE_DPMS_SUSPEND:
-	case DRM_MODE_DPMS_OFF:
-		ch = mode;
-		ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
-		ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, ch);
-		break;
-	}
-}
-
  static enum drm_mode_status
  ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
  {
@@ -1217,14 +1194,23 @@ ast_crtc_helper_atomic_flush(struct drm_crtc *crtc,
 
  static void ast_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
  {
-	ast_crtc_dpms(crtc, DRM_MODE_DPMS_ON);
+	struct ast_device *ast = to_ast_device(crtc->dev);
+
+	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, 0x00);
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, 0x00);
  }
 
  static void ast_crtc_helper_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
  {
  	struct drm_crtc_state *old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
+	struct ast_device *ast = to_ast_device(crtc->dev);
+	u8 vgacrb6;
+
+	ast_set_index_reg_mask(ast, AST_IO_VGASRI, 0x01, 0xdf, AST_IO_VGASR1_SD);
 
-	ast_crtc_dpms(crtc, DRM_MODE_DPMS_OFF);
+	vgacrb6 = AST_IO_VGACRB6_VSYNC_OFF |
+		  AST_IO_VGACRB6_HSYNC_OFF;
+	ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xb6, 0xfc, vgacrb6);
 
  	/*
  	 * HW cursors require the underlying primary plane and CRTC to
drivers/gpu/drm/ast/ast_reg.h +2 -7
index 6326cbdadc82..75671d345057 100644
@@ -32,6 +32,8 @@
  #define AST_IO_VGACR80_PASSWORD		(0xa8)
  #define AST_IO_VGACRA1_VGAIO_DISABLED	BIT(1)
  #define AST_IO_VGACRA1_MMIO_ENABLED	BIT(2)
+#define AST_IO_VGACRB6_HSYNC_OFF	BIT(0)
+#define AST_IO_VGACRB6_VSYNC_OFF	BIT(1)
  #define AST_IO_VGACRCB_HWC_16BPP	BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
  #define AST_IO_VGACRCB_HWC_ENABLED	BIT(1)
 
@@ -76,13 +78,6 @@
  #define ASTDP_HOST_EDID_READ_DONE	BIT(0)
  #define ASTDP_HOST_EDID_READ_DONE_MASK	GENMASK(0, 0)
 
-/*
- * CRB8[b1]: Enable VSYNC off
- * CRB8[b0]: Enable HSYNC off
- */
-#define AST_DPMS_VSYNC_OFF		BIT(1)
-#define AST_DPMS_HSYNC_OFF		BIT(0)
-
  /*
   * CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE
   * Precondition:	A. ~AST_DP_PHY_SLEEP  &&
author maintainer
#16 lore raw

PATCH 8/8 drm/ast: Use drm_atomic_helper_commit_tail() helper

In reply to Thomas Zimmermann

Ast has no special requirements for runtime power management. So replace drm_atomic_helper_commit_tail_rpm() with the regular helper drm_atomic_helper_commit_tail().

---
 drivers/gpu/drm/ast/ast_mode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_mode.c +1 -1
index d130c96edf35..dc8f639e82fd 100644
@@ -1865,7 +1865,7 @@ static void ast_mode_config_helper_atomic_commit_tail(struct drm_atomic_state *s
 	 * the I/O-register lock. Released in atomic_flush().
 	 */
 	mutex_lock(&ast->modeset_lock);
-	drm_atomic_helper_commit_tail_rpm(state);
+	drm_atomic_helper_commit_tail(state);
 	mutex_unlock(&ast->modeset_lock);
 }
 
Signature · 1 line
2.45.2
reviewer Reviewed-by on v1 8/8
#17 lore raw

Re: [PATCH 8/8] drm/ast: Use drm_atomic_helper_commit_tail() helper

Quoted 3 lines · Thomas Zimmermann

Ast has no special requirements for runtime power management. So replace drm_atomic_helper_commit_tail_rpm() with the regular helper drm_atomic_helper_commit_tail().

Thanks, it looks good te me.

Quoted 19 lines
---
  drivers/gpu/drm/ast/ast_mode.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_mode.c +1 -1
index d130c96edf35..dc8f639e82fd 100644
@@ -1865,7 +1865,7 @@ static void ast_mode_config_helper_atomic_commit_tail(struct drm_atomic_state *s
  	 * the I/O-register lock. Released in atomic_flush().
  	 */
  	mutex_lock(&ast->modeset_lock);
-	drm_atomic_helper_commit_tail_rpm(state);
+	drm_atomic_helper_commit_tail(state);
  	mutex_unlock(&ast->modeset_lock);
  }
 
#18 lore raw
In reply to Thomas Zimmermann
Quoted 10 lines · Thomas Zimmermann

The CRTC's mode-setting code contains quite a bit of code that belongs to the planes or various encoder chips. This patchset refactors these bits and moves things to the correct places.

With the patches applied, the remaining DPMS function will be gone and its content be moved. Several code duplications will be removed. There was also a bugfix wrt the VGA SCREEN_DISABLE bit, but it's unclear if the bug had any effect in practice.

Tested with AST2100 and AST2600 with VGA and DP outputs.

Thanks,

I've tested the patch series, on a remote ampere (aarch64) system with AST 2500, and it works. I wasn't able to test with a real monitor attached.

Signature · 1 line
Jocelyn
Quoted 15 lines

Thomas Zimmermann (8):
drm/ast: Implement atomic enable/disable for encoders drm/ast: Program mode for AST DP in atomic_mode_set drm/ast: Move mode-setting code into mode_set_nofb CRTC helper drm/ast: Handle primary-plane format setup in atomic_update drm/ast: Remove gamma LUT updates from DPMS code drm/ast: Only set VGA SCREEN_DISABLE bit in CRTC code drm/ast: Inline ast_crtc_dpms() into callers drm/ast: Use drm_atomic_helper_commit_tail() helper

  drivers/gpu/drm/ast/ast_mode.c | 204 ++++++++++++++++++---------------
  drivers/gpu/drm/ast/ast_reg.h  |  10 +-
  2 files changed, 112 insertions(+), 102 deletions(-)
author maintainer
#19 lore raw

Hi

Am 28.06.24 um 12:09 schrieb Jocelyn Falempe:

Quoted 12 lines · Thomas Zimmermann
Quoted 9 lines

The CRTC's mode-setting code contains quite a bit of code that belongs to the planes or various encoder chips. This patchset refactors these bits and moves things to the correct places.

With the patches applied, the remaining DPMS function will be gone and its content be moved. Several code duplications will be removed. There was also a bugfix wrt the VGA SCREEN_DISABLE bit, but it's unclear if the bug had any effect in practice.

Quoted 5 lines
Quoted 1 line

Tested with AST2100 and AST2600 with VGA and DP outputs.

Thanks,

I've tested the patch series, on a remote ampere (aarch64) system with AST 2500, and it works. I wasn't able to test with a real monitor attached.

Ok, so the BMC also still works. Thanks for reviewing and testing.

I've long wanted to clean up this code. Earlier his week I got a monitor working on the AST2600's DP port. So I could finally test these refactorings. With this in place, there's more to come to improve the driver's output code.

Best regards
Thomas

Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)