drm/ast: Various cleanups
Subsystems (3)
Thomas Zimmermann
maintainercover drm/ast: Various cleanups
Here are various cleanups for the ast driver. Most of the patches inline functions or avoid upcasting. Some internal helpers of the astdp support are now easier to understand.
Tested on AST2600 HW.
Thomas Zimmermann (10):
drm/ast: astdp: Inline ast_astdp_connector_init() drm/ast: astdp: Avoid upcasting to struct ast_device drm/ast: astdp: Replace power_on helpers drm/ast: astdp: Replace ast_dp_set_on_off() drm/ast: dp501: Inline ast_dp501_connector_init() drm/ast: dp501: Avoid upcasting to struct ast_device drm/ast: sil164: Inline ast_sil164_connector_init() drm/ast: vga: Inline ast_vga_connector_init() drm/ast: Respect return value from CRTC init drm/ast: Avoid upcasting to struct ast_device
drivers/gpu/drm/ast/ast_dp.c | 141 ++++++++++++++++--------------- drivers/gpu/drm/ast/ast_dp501.c | 96 ++++++++++----------- drivers/gpu/drm/ast/ast_drv.c | 2 +- drivers/gpu/drm/ast/ast_drv.h | 9 +- drivers/gpu/drm/ast/ast_main.c | 10 +-- drivers/gpu/drm/ast/ast_mode.c | 8 +- drivers/gpu/drm/ast/ast_post.c | 32 +++---- drivers/gpu/drm/ast/ast_reg.h | 15 +--- drivers/gpu/drm/ast/ast_sil164.c | 55 ++++++------ drivers/gpu/drm/ast/ast_vga.c | 55 ++++++------ 10 files changed, 200 insertions(+), 223 deletions(-)
Signature · 1 line
2.46.0
Thomas Zimmermann
maintainerPATCH 1/10 drm/ast: astdp: Inline ast_astdp_connector_init()
Inline ast_astdp_connector_init() into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined.
Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
--- drivers/gpu/drm/ast/ast_dp.c | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +22 -23
@@ -414,6 +414,10 @@ static const struct drm_connector_helper_funcs ast_astdp_connector_helper_funcs .detect_ctx = ast_astdp_connector_helper_detect_ctx, }; +/* +* Output +*/ +static const struct drm_connector_funcs ast_astdp_connector_funcs = { .reset = drm_atomic_helper_connector_reset, .fill_modes = drm_helper_probe_single_connector_modes,
@@ -422,34 +426,18 @@ static const struct drm_connector_funcs ast_astdp_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_astdp_connector_init (struct drm_device *dev,struct drm_connector *connector) -{ -int ret; - - ret =drm_connector_init (dev, connector, &ast_astdp_connector_funcs, - DRM_MODE_CONNECTOR_DisplayPort); -if (ret) -return ret; - -drm_connector_helper_add (connector, &ast_astdp_connector_helper_funcs); - - connector->interlace_allowed =0 ; - connector->doublescan_allowed =0 ; - - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; - -return 0 ; -} -int ast_astdp_output_init (struct ast_device *ast) {struct drm_device *dev = &ast->base;struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.astdp.encoder; -struct ast_connector *ast_connector = &ast->output.astdp.connector; -struct drm_connector *connector = &ast_connector->base; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* encoder */ + + encoder = &ast->output.astdp.encoder; ret =drm_encoder_init (dev, encoder, &ast_astdp_encoder_funcs,DRM_MODE_ENCODER_TMDS ,NULL );if (ret)
@@ -458,9 +446,20 @@ int ast_astdp_output_init(struct ast_device *ast) encoder->possible_crtcs =drm_crtc_mask (crtc); - ret =ast_astdp_connector_init (dev, connector); +/* connector */ + + ast_connector = &ast->output.astdp.connector; + connector = &ast_connector->base; + ret =drm_connector_init (dev, connector, &ast_astdp_connector_funcs, + DRM_MODE_CONNECTOR_DisplayPort);if (ret)return ret; +drm_connector_helper_add (connector, &ast_astdp_connector_helper_funcs); + + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; + ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Signature · 1 line
2.46.0
Re: [PATCH 01/10] drm/ast: astdp: Inline ast_astdp_connector_init()
Quoted 7 lines · Thomas Zimmermann
Inline
ast_astdp_connector_init()into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined.Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
Thanks, it looks good to me.
Quoted 6 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp.c | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-)
Thomas Zimmermann
maintainerPATCH 2/10 drm/ast: astdp: Avoid upcasting to struct ast_device
In reply to Thomas ZimmermannSeveral functions receive an instance of struct drm_device only to upcast it to struct ast_device. Improve type safety by passing the AST device directly.
--- drivers/gpu/drm/ast/ast_dp.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +10 -14
@@ -158,9 +158,8 @@ static bool ast_dp_power_is_on(struct ast_device *ast)return !(vgacre3 &AST_DP_PHY_SLEEP ); } -static void ast_dp_power_on_off (struct drm_device *dev,bool on) +static void ast_dp_power_on_off (struct ast_device *ast,bool on) { -struct ast_device *ast =to_ast_device (dev);// Read and Turn off DP PHY sleep u8 bE3 =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 ,AST_DP_VIDEO_ENABLE );
@@ -192,9 +191,8 @@ static void ast_dp_link_training(struct ast_device *ast)drm_err (dev,"Link training failed\n" ); } -static void ast_dp_set_on_off (struct drm_device *dev,bool on) +static void ast_dp_set_on_off (struct ast_device *ast,bool on) { -struct ast_device *ast =to_ast_device (dev);u8 video_on_off = on;u32 i =0 ;
@@ -317,26 +315,25 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoderstatic 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); +struct ast_device *ast =to_ast_device (encoder->dev);struct ast_connector *ast_connector = &ast->output.astdp.connector;if (ast_connector->physical_status == connector_status_connected) { -ast_dp_power_on_off (dev,AST_DP_POWER_ON ); +ast_dp_power_on_off (ast,AST_DP_POWER_ON );ast_dp_link_training (ast);ast_wait_for_vretrace (ast); -ast_dp_set_on_off (dev,1 ); +ast_dp_set_on_off (ast,1 ); } }static void ast_astdp_encoder_helper_atomic_disable (struct drm_encoder *encoder,struct drm_atomic_state *state) { -struct drm_device *dev = encoder->dev; +struct ast_device *ast =to_ast_device (encoder->dev); -ast_dp_set_on_off (dev,0 ); -ast_dp_power_on_off (dev,AST_DP_POWER_OFF ); +ast_dp_set_on_off (ast,0 ); +ast_dp_power_on_off (ast,AST_DP_POWER_OFF ); }static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
@@ -383,7 +380,6 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connector bool force) {struct ast_connector *ast_connector =to_ast_connector (connector); -struct drm_device *dev = connector->dev;struct ast_device *ast =to_ast_device (connector->dev);enum drm_connector_status status = connector_status_disconnected;bool power_is_on;
@@ -392,13 +388,13 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connector power_is_on =ast_dp_power_is_on (ast);if (!power_is_on) -ast_dp_power_on_off (dev, true); +ast_dp_power_on_off (ast, true);if (ast_astdp_is_connected (ast)) status = connector_status_connected;if (!power_is_on && status == connector_status_disconnected) -ast_dp_power_on_off (dev, false); +ast_dp_power_on_off (ast, false);mutex_unlock (&ast->modeset_lock);
Signature · 1 line
2.46.0
Re: [PATCH 02/10] drm/ast: astdp: Avoid upcasting to struct ast_device
Quoted 3 lines · Thomas Zimmermann
Several functions receive an instance of struct
drm_deviceonly to upcast it to structast_device. Improve type safety by passing the AST device directly.
Thanks, it looks good to me.
Quoted 89 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-)drivers/gpu/drm/ast/ast_dp.c +10
-14@@ -158,9 +158,8 @@ static bool ast_dp_power_is_on(struct ast_device *ast)return !(vgacre3 &AST_DP_PHY_SLEEP ); } -static void ast_dp_power_on_off (struct drm_device *dev,bool on) +static void ast_dp_power_on_off (struct ast_device *ast,bool on) { -struct ast_device *ast =to_ast_device (dev);// Read and Turn off DP PHY sleep u8 bE3 =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 ,AST_DP_VIDEO_ENABLE );@@ -192,9 +191,8 @@ static void ast_dp_link_training(struct ast_device *ast)drm_err (dev,"Link training failed\n" ); } -static void ast_dp_set_on_off (struct drm_device *dev,bool on) +static void ast_dp_set_on_off (struct ast_device *ast,bool on) { -struct ast_device *ast =to_ast_device (dev);u8 video_on_off = on;u32 i =0 ;@@ -317,26 +315,25 @@ static void ast_astdp_encoder_helper_atomic_mode_set(struct drm_encoder *encoderstatic 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); +struct ast_device *ast =to_ast_device (encoder->dev);struct ast_connector *ast_connector = &ast->output.astdp.connector;if (ast_connector->physical_status == connector_status_connected) { -ast_dp_power_on_off (dev,AST_DP_POWER_ON ); +ast_dp_power_on_off (ast,AST_DP_POWER_ON );ast_dp_link_training (ast);ast_wait_for_vretrace (ast); -ast_dp_set_on_off (dev,1 ); +ast_dp_set_on_off (ast,1 ); } }static void ast_astdp_encoder_helper_atomic_disable (struct drm_encoder *encoder,struct drm_atomic_state *state) { -struct drm_device *dev = encoder->dev; +struct ast_device *ast =to_ast_device (encoder->dev); -ast_dp_set_on_off (dev,0 ); -ast_dp_power_on_off (dev,AST_DP_POWER_OFF ); +ast_dp_set_on_off (ast,0 ); +ast_dp_power_on_off (ast,AST_DP_POWER_OFF ); }static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {@@ -383,7 +380,6 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connector bool force) {struct ast_connector *ast_connector =to_ast_connector (connector); -struct drm_device *dev = connector->dev;struct ast_device *ast =to_ast_device (connector->dev);enum drm_connector_status status = connector_status_disconnected;bool power_is_on;@@ -392,13 +388,13 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connector power_is_on =ast_dp_power_is_on (ast);if (!power_is_on) -ast_dp_power_on_off (dev, true); +ast_dp_power_on_off (ast, true);if (ast_astdp_is_connected (ast)) status = connector_status_connected;if (!power_is_on && status == connector_status_disconnected) -ast_dp_power_on_off (dev, false); +ast_dp_power_on_off (ast, false);mutex_unlock (&ast->modeset_lock);
Thomas Zimmermann
maintainerPATCH 3/10 drm/ast: astdp: Replace power_on helpers
In reply to Thomas ZimmermannReplace the helper for controlling power on the physical connector, ast_dp_power_on_off(), with ast_dp_set_phy_sleep(). The new name reflects the effect of the operation. Simplify the implementation. The call now controls sleeping, hence semantics are inversed. Each 'on' becomes an 'off' operation and vice versa.
Do the same for ast_dp_power_is_on() and also align naming of the register constant with the rest of the code.
--- drivers/gpu/drm/ast/ast_dp.c | 39 +++++++++++++++-------------------- drivers/gpu/drm/ast/ast_drv.h | 3 --- drivers/gpu/drm/ast/ast_reg.h | 2 +- 3 files changed, 18 insertions(+), 26 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +17 -22
@@ -149,27 +149,22 @@ int ast_dp_launch(struct ast_device *ast)return 0 ; } -static bool ast_dp_power_is_on (struct ast_device *ast) +static bool ast_dp_get_phy_sleep (struct ast_device *ast) { -u8 vgacre3; +u8 vgacre3 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xe3 ); - vgacre3 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xe3 ); - -return !(vgacre3 &AST_DP_PHY_SLEEP ); +return (vgacre3 &AST_IO_VGACRE3_DP_PHY_SLEEP ); } -static void ast_dp_power_on_off (struct ast_device *ast,bool on) +static void ast_dp_set_phy_sleep (struct ast_device *ast,bool sleep) { -// Read and Turn off DP PHY sleep -u8 bE3 =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 ,AST_DP_VIDEO_ENABLE ); - -// Turn on DP PHY sleep -if (!on) - bE3 |=AST_DP_PHY_SLEEP ; +u8 vgacre3 =0x00 ; -// DP Power on/off -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 , (u8 ) ~AST_DP_PHY_SLEEP , bE3); +if (sleep) + vgacre3 |=AST_IO_VGACRE3_DP_PHY_SLEEP ; +ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xe3 , (u8 )~AST_IO_VGACRE3_DP_PHY_SLEEP , + vgacre3);msleep (50 ); }
@@ -319,7 +314,7 @@ static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,struct ast_connector *ast_connector = &ast->output.astdp.connector;if (ast_connector->physical_status == connector_status_connected) { -ast_dp_power_on_off (ast,AST_DP_POWER_ON ); +ast_dp_set_phy_sleep (ast, false);ast_dp_link_training (ast);ast_wait_for_vretrace (ast);
@@ -333,7 +328,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,struct ast_device *ast =to_ast_device (encoder->dev);ast_dp_set_on_off (ast,0 ); -ast_dp_power_on_off (ast,AST_DP_POWER_OFF ); +ast_dp_set_phy_sleep (ast, true); }static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {
@@ -382,19 +377,19 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connectorstruct ast_connector *ast_connector =to_ast_connector (connector);struct ast_device *ast =to_ast_device (connector->dev);enum drm_connector_status status = connector_status_disconnected; -bool power_is_on; +bool phy_sleep;mutex_lock (&ast->modeset_lock); - power_is_on =ast_dp_power_is_on (ast); -if (!power_is_on) -ast_dp_power_on_off (ast, true); + phy_sleep =ast_dp_get_phy_sleep (ast); +if (phy_sleep) +ast_dp_set_phy_sleep (ast, false);if (ast_astdp_is_connected (ast)) status = connector_status_connected; -if (!power_is_on && status == connector_status_disconnected) -ast_dp_power_on_off (ast, false); +if (phy_sleep && status == connector_status_disconnected) +ast_dp_set_phy_sleep (ast, true);mutex_unlock (&ast->modeset_lock);
drivers/gpu/drm/ast/ast_drv.h +0 -3
@@ -403,9 +403,6 @@ int ast_mode_config_init(struct ast_device *ast);#define AST_DP501_LINKRATE 0xf014#define AST_DP501_EDID_DATA 0xf020 -#define AST_DP_POWER_ON true -#define AST_DP_POWER_OFF false -/* * ASTDP resoultion table: * EX: ASTDP_A_B_C:
drivers/gpu/drm/ast/ast_reg.h +1 -1
@@ -41,6 +41,7 @@#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)#define AST_IO_VGACRDF_HPD BIT(0) +#define AST_IO_VGACRE3_DP_PHY_SLEEP BIT(4)#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)#define AST_IO_VGAIR1_R (0x5A)
@@ -69,7 +70,6 @@*/ /* Define for Soc scratched reg used on ASTDP */ -#define AST_DP_PHY_SLEEP BIT(4)#define AST_DP_VIDEO_ENABLE BIT(0)/*
Signature · 1 line
2.46.0
Re: [PATCH 03/10] drm/ast: astdp: Replace power_on helpers
Quoted 8 lines · Thomas Zimmermann
Replace the helper for controlling power on the physical connector,
ast_dp_power_on_off(), withast_dp_set_phy_sleep(). The new name reflects the effect of the operation. Simplify the implementation. The call now controls sleeping, hence semantics are inversed. Each 'on' becomes an 'off' operation and vice versa.Do the same for
ast_dp_power_is_on()and also align naming of the register constant with the rest of the code.
Thanks, it looks good to me.
Quoted 127 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp.c | 39 +++++++++++++++-------------------- drivers/gpu/drm/ast/ast_drv.h | 3 --- drivers/gpu/drm/ast/ast_reg.h | 2 +- 3 files changed, 18 insertions(+), 26 deletions(-)drivers/gpu/drm/ast/ast_dp.c +17
-22@@ -149,27 +149,22 @@ int ast_dp_launch(struct ast_device *ast)return 0 ; } -static bool ast_dp_power_is_on (struct ast_device *ast) +static bool ast_dp_get_phy_sleep (struct ast_device *ast) { -u8 vgacre3; +u8 vgacre3 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xe3 ); - vgacre3 =ast_get_index_reg (ast,AST_IO_VGACRI ,0xe3 ); - -return !(vgacre3 &AST_DP_PHY_SLEEP ); +return (vgacre3 &AST_IO_VGACRE3_DP_PHY_SLEEP ); } -static void ast_dp_power_on_off (struct ast_device *ast,bool on) +static void ast_dp_set_phy_sleep (struct ast_device *ast,bool sleep) { -// Read and Turn off DP PHY sleep -u8 bE3 =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 ,AST_DP_VIDEO_ENABLE ); - -// Turn on DP PHY sleep -if (!on) - bE3 |=AST_DP_PHY_SLEEP ; +u8 vgacre3 =0x00 ; -// DP Power on/off -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 , (u8 ) ~AST_DP_PHY_SLEEP , bE3); +if (sleep) + vgacre3 |=AST_IO_VGACRE3_DP_PHY_SLEEP ; +ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xe3 , (u8 )~AST_IO_VGACRE3_DP_PHY_SLEEP , + vgacre3);msleep (50 ); }@@ -319,7 +314,7 @@ static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,struct ast_connector *ast_connector = &ast->output.astdp.connector;if (ast_connector->physical_status == connector_status_connected) { -ast_dp_power_on_off (ast,AST_DP_POWER_ON ); +ast_dp_set_phy_sleep (ast, false);ast_dp_link_training (ast);ast_wait_for_vretrace (ast);@@ -333,7 +328,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder,struct ast_device *ast =to_ast_device (encoder->dev);ast_dp_set_on_off (ast,0 ); -ast_dp_power_on_off (ast,AST_DP_POWER_OFF ); +ast_dp_set_phy_sleep (ast, true); }static const struct drm_encoder_helper_funcs ast_astdp_encoder_helper_funcs = {@@ -382,19 +377,19 @@ static int ast_astdp_connector_helper_detect_ctx(struct drm_connector *connectorstruct ast_connector *ast_connector =to_ast_connector (connector);struct ast_device *ast =to_ast_device (connector->dev);enum drm_connector_status status = connector_status_disconnected; -bool power_is_on; +bool phy_sleep;mutex_lock (&ast->modeset_lock); - power_is_on =ast_dp_power_is_on (ast); -if (!power_is_on) -ast_dp_power_on_off (ast, true); + phy_sleep =ast_dp_get_phy_sleep (ast); +if (phy_sleep) +ast_dp_set_phy_sleep (ast, false);if (ast_astdp_is_connected (ast)) status = connector_status_connected; -if (!power_is_on && status == connector_status_disconnected) -ast_dp_power_on_off (ast, false); +if (phy_sleep && status == connector_status_disconnected) +ast_dp_set_phy_sleep (ast, true);mutex_unlock (&ast->modeset_lock);drivers/gpu/drm/ast/ast_drv.h +0
-3@@ -403,9 +403,6 @@ int ast_mode_config_init(struct ast_device *ast);#define AST_DP501_LINKRATE 0xf014#define AST_DP501_EDID_DATA 0xf020 -#define AST_DP_POWER_ON true -#define AST_DP_POWER_OFF false -/* * ASTDP resoultion table: * EX: ASTDP_A_B_C: drivers/gpu/drm/ast/ast_reg.h +1
-1@@ -41,6 +41,7 @@#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)#define AST_IO_VGACRDF_HPD BIT(0) +#define AST_IO_VGACRE3_DP_PHY_SLEEP BIT(4)#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)#define AST_IO_VGAIR1_R (0x5A)@@ -69,7 +70,6 @@*/ /* Define for Soc scratched reg used on ASTDP */ -#define AST_DP_PHY_SLEEP BIT(4)#define AST_DP_VIDEO_ENABLE BIT(0)/*
Thomas Zimmermann
maintainerPATCH 4/10 drm/ast: astdp: Replace ast_dp_set_on_off()
In reply to Thomas ZimmermannReplace ast_dp_set_on_off() with ast_dp_set_enable(). The helper's new name reflects the performed operation. If enabling fails, the new helper prints a warning. The code that waits for the programmed effect to take place is now located in __ast_dp_wait_enable().
Also align the register constants with the rest of the code.
--- drivers/gpu/drm/ast/ast_dp.c | 49 +++++++++++++++++++++++------------ drivers/gpu/drm/ast/ast_reg.h | 13 ++-------- 2 files changed, 35 insertions(+), 27 deletions(-)
drivers/gpu/drm/ast/ast_dp.c +33 -16
@@ -186,22 +186,39 @@ static void ast_dp_link_training(struct ast_device *ast)drm_err (dev,"Link training failed\n" ); } -static void ast_dp_set_on_off (struct ast_device *ast,bool on) +static bool __ast_dp_wait_enable (struct ast_device *ast,bool enabled) { -u8 video_on_off = on; -u32 i =0 ; - -// Video On/Off -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 , (u8 ) ~AST_DP_VIDEO_ENABLE , on); - - video_on_off <<=4 ; -while (ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xDF , -ASTDP_MIRROR_VIDEO_ENABLE ) != video_on_off) { -// wait 1 ms -mdelay (1 ); -if (++i >200 ) -break ; +u8 vgacrdf_test =0x00 ; +u8 vgacrdf; +unsigned int i; + +if (enabled) + vgacrdf_test |=AST_IO_VGACRDF_DP_VIDEO_ENABLE ; + +for (i =0 ; i <200 ; ++i) { +if (i) +mdelay (1 ); + vgacrdf =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xdf , +AST_IO_VGACRDF_DP_VIDEO_ENABLE ); +if (vgacrdf == vgacrdf_test) +return true; } + +return false; +} + +static void ast_dp_set_enable (struct ast_device *ast,bool enabled) +{ +struct drm_device *dev = &ast->base; +u8 vgacre3 =0x00 ; + +if (enabled) + vgacre3 |=AST_IO_VGACRE3_DP_VIDEO_ENABLE ; + +ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xe3 , (u8 )~AST_IO_VGACRE3_DP_VIDEO_ENABLE , + vgacre3); + +drm_WARN_ON (dev, !__ast_dp_wait_enable (ast, enabled)); }static void ast_dp_set_mode (struct drm_crtc *crtc,struct ast_vbios_mode_info *vbios_mode)
@@ -318,7 +335,7 @@ static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,ast_dp_link_training (ast);ast_wait_for_vretrace (ast); -ast_dp_set_on_off (ast,1 ); +ast_dp_set_enable (ast, true); } }
@@ -327,7 +344,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder, {struct ast_device *ast =to_ast_device (encoder->dev); -ast_dp_set_on_off (ast,0 ); +ast_dp_set_enable (ast, false);ast_dp_set_phy_sleep (ast, true); }
drivers/gpu/drm/ast/ast_reg.h +2 -11
@@ -41,6 +41,8 @@#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)#define AST_IO_VGACRDF_HPD BIT(0) +#define AST_IO_VGACRDF_DP_VIDEO_ENABLE BIT(4)/* mirrors AST_IO_VGACRE3_DP_VIDEO_ENABLE */ +#define AST_IO_VGACRE3_DP_VIDEO_ENABLE BIT(0)#define AST_IO_VGACRE3_DP_PHY_SLEEP BIT(4)#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)
@@ -69,17 +71,6 @@* AST DisplayPort */ -/* Define for Soc scratched reg used on ASTDP */ -#define AST_DP_VIDEO_ENABLE BIT(0) - -/* -* CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE -* Precondition: A. ~AST_DP_PHY_SLEEP && -* B. DP_HPD && -* C. DP_LINK_SUCCESS -*/ -#define ASTDP_MIRROR_VIDEO_ENABLE BIT(4) -/* * ASTDP setmode registers: * CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
Signature · 1 line
2.46.0
Re: [PATCH 04/10] drm/ast: astdp: Replace ast_dp_set_on_off()
Quoted 7 lines · Thomas Zimmermann
Replace
ast_dp_set_on_off()withast_dp_set_enable(). The helper's new name reflects the performed operation. If enabling fails, the new helper prints a warning. The code that waits for the programmed effect to take place is now located in__ast_dp_wait_enable().Also align the register constants with the rest of the code.
Thanks, it looks good to me.
Quoted 113 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp.c | 49 +++++++++++++++++++++++------------ drivers/gpu/drm/ast/ast_reg.h | 13 ++-------- 2 files changed, 35 insertions(+), 27 deletions(-)drivers/gpu/drm/ast/ast_dp.c +33
-16@@ -186,22 +186,39 @@ static void ast_dp_link_training(struct ast_device *ast)drm_err (dev,"Link training failed\n" ); } -static void ast_dp_set_on_off (struct ast_device *ast,bool on) +static bool __ast_dp_wait_enable (struct ast_device *ast,bool enabled) { -u8 video_on_off = on; -u32 i =0 ; - -// Video On/Off -ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xE3 , (u8 ) ~AST_DP_VIDEO_ENABLE , on); - - video_on_off <<=4 ; -while (ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xDF , -ASTDP_MIRROR_VIDEO_ENABLE ) != video_on_off) { -// wait 1 ms -mdelay (1 ); -if (++i >200 ) -break ; +u8 vgacrdf_test =0x00 ; +u8 vgacrdf; +unsigned int i; + +if (enabled) + vgacrdf_test |=AST_IO_VGACRDF_DP_VIDEO_ENABLE ; + +for (i =0 ; i <200 ; ++i) { +if (i) +mdelay (1 ); + vgacrdf =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xdf , +AST_IO_VGACRDF_DP_VIDEO_ENABLE ); +if (vgacrdf == vgacrdf_test) +return true; } + +return false; +} + +static void ast_dp_set_enable (struct ast_device *ast,bool enabled) +{ +struct drm_device *dev = &ast->base; +u8 vgacre3 =0x00 ; + +if (enabled) + vgacre3 |=AST_IO_VGACRE3_DP_VIDEO_ENABLE ; + +ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xe3 , (u8 )~AST_IO_VGACRE3_DP_VIDEO_ENABLE , + vgacre3); + +drm_WARN_ON (dev, !__ast_dp_wait_enable (ast, enabled)); }static void ast_dp_set_mode (struct drm_crtc *crtc,struct ast_vbios_mode_info *vbios_mode)@@ -318,7 +335,7 @@ static void ast_astdp_encoder_helper_atomic_enable(struct drm_encoder *encoder,ast_dp_link_training (ast);ast_wait_for_vretrace (ast); -ast_dp_set_on_off (ast,1 ); +ast_dp_set_enable (ast, true); } }@@ -327,7 +344,7 @@ static void ast_astdp_encoder_helper_atomic_disable(struct drm_encoder *encoder, {struct ast_device *ast =to_ast_device (encoder->dev); -ast_dp_set_on_off (ast,0 ); +ast_dp_set_enable (ast, false);ast_dp_set_phy_sleep (ast, true); }drivers/gpu/drm/ast/ast_reg.h +2
-11@@ -41,6 +41,8 @@#define AST_IO_VGACRD7_EDID_VALID_FLAG BIT(0)#define AST_IO_VGACRDC_LINK_SUCCESS BIT(0)#define AST_IO_VGACRDF_HPD BIT(0) +#define AST_IO_VGACRDF_DP_VIDEO_ENABLE BIT(4)/* mirrors AST_IO_VGACRE3_DP_VIDEO_ENABLE */ +#define AST_IO_VGACRE3_DP_VIDEO_ENABLE BIT(0)#define AST_IO_VGACRE3_DP_PHY_SLEEP BIT(4)#define AST_IO_VGACRE5_EDID_READ_DONE BIT(0)@@ -69,17 +71,6 @@* AST DisplayPort */ -/* Define for Soc scratched reg used on ASTDP */ -#define AST_DP_VIDEO_ENABLE BIT(0) - -/* -* CRDF[b4]: Mirror of AST_DP_VIDEO_ENABLE -* Precondition: A. ~AST_DP_PHY_SLEEP && -* B. DP_HPD && -* C. DP_LINK_SUCCESS -*/ -#define ASTDP_MIRROR_VIDEO_ENABLE BIT(4) -/* * ASTDP setmode registers: * CRE0[7:0]: MISC0 ((0x00: 18-bpp) or (0x20: 24-bpp)
Thomas Zimmermann
maintainerPATCH 5/10 drm/ast: dp501: Inline ast_dp501_connector_init()
In reply to Thomas ZimmermannInline ast_dp501_connector_init() into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined.
Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
--- drivers/gpu/drm/ast/ast_dp501.c | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/gpu/drm/ast/ast_dp501.c +21 -22
@@ -567,34 +567,22 @@ static const struct drm_connector_funcs ast_dp501_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_dp501_connector_init (struct drm_device *dev,struct drm_connector *connector) -{ -int ret; - - ret =drm_connector_init (dev, connector, &ast_dp501_connector_funcs, - DRM_MODE_CONNECTOR_DisplayPort); -if (ret) -return ret; - -drm_connector_helper_add (connector, &ast_dp501_connector_helper_funcs); - - connector->interlace_allowed =0 ; - connector->doublescan_allowed =0 ; - - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; - -return 0 ; -} +/* +* Output +*/ int ast_dp501_output_init (struct ast_device *ast) {struct drm_device *dev = &ast->base;struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.dp501.encoder; -struct ast_connector *ast_connector = &ast->output.dp501.connector; -struct drm_connector *connector = &ast_connector->base; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* encoder */ + + encoder = &ast->output.dp501.encoder; ret =drm_encoder_init (dev, encoder, &ast_dp501_encoder_funcs,DRM_MODE_ENCODER_TMDS ,NULL );if (ret)
@@ -603,9 +591,20 @@ int ast_dp501_output_init(struct ast_device *ast) encoder->possible_crtcs =drm_crtc_mask (crtc); - ret =ast_dp501_connector_init (dev, connector); +/* connector */ + + ast_connector = &ast->output.dp501.connector; + connector = &ast_connector->base; + ret =drm_connector_init (dev, connector, &ast_dp501_connector_funcs, + DRM_MODE_CONNECTOR_DisplayPort);if (ret)return ret; +drm_connector_helper_add (connector, &ast_dp501_connector_helper_funcs); + + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; + ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Signature · 1 line
2.46.0
Re: [PATCH 05/10] drm/ast: dp501: Inline ast_dp501_connector_init()
Quoted 7 lines · Thomas Zimmermann
Inline
ast_dp501_connector_init()into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined.Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
Thanks, it looks good to me.
Quoted 76 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp501.c | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-)drivers/gpu/drm/ast/ast_dp501.c +21
-22@@ -567,34 +567,22 @@ static const struct drm_connector_funcs ast_dp501_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_dp501_connector_init (struct drm_device *dev,struct drm_connector *connector) -{ -int ret; - - ret =drm_connector_init (dev, connector, &ast_dp501_connector_funcs, - DRM_MODE_CONNECTOR_DisplayPort); -if (ret) -return ret; - -drm_connector_helper_add (connector, &ast_dp501_connector_helper_funcs); - - connector->interlace_allowed =0 ; - connector->doublescan_allowed =0 ; - - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; - -return 0 ; -} +/* +* Output +*/ int ast_dp501_output_init (struct ast_device *ast) {struct drm_device *dev = &ast->base;struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.dp501.encoder; -struct ast_connector *ast_connector = &ast->output.dp501.connector; -struct drm_connector *connector = &ast_connector->base; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* encoder */ + + encoder = &ast->output.dp501.encoder; ret =drm_encoder_init (dev, encoder, &ast_dp501_encoder_funcs,DRM_MODE_ENCODER_TMDS ,NULL );if (ret)@@ -603,9 +591,20 @@ int ast_dp501_output_init(struct ast_device *ast) encoder->possible_crtcs =drm_crtc_mask (crtc); - ret =ast_dp501_connector_init (dev, connector); +/* connector */ + + ast_connector = &ast->output.dp501.connector; + connector = &ast_connector->base; + ret =drm_connector_init (dev, connector, &ast_dp501_connector_funcs, + DRM_MODE_CONNECTOR_DisplayPort);if (ret)return ret; +drm_connector_helper_add (connector, &ast_dp501_connector_helper_funcs); + + connector->interlace_allowed =0 ; + connector->doublescan_allowed =0 ; + connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; + ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Thomas Zimmermann
maintainerPATCH 6/10 drm/ast: dp501: Avoid upcasting to struct ast_device
In reply to Thomas ZimmermannSeveral functions receive an instance of struct drm_device only to upcast it to struct ast_device. Improve type safety by passing the AST device directly.
--- drivers/gpu/drm/ast/ast_dp501.c | 53 ++++++++++++++------------------- drivers/gpu/drm/ast/ast_drv.h | 4 +-- drivers/gpu/drm/ast/ast_main.c | 2 +- drivers/gpu/drm/ast/ast_post.c | 2 +- 4 files changed, 27 insertions(+), 34 deletions(-)
drivers/gpu/drm/ast/ast_dp501.c +23 -30
@@ -21,9 +21,9 @@ static void ast_release_firmware(void *data) ast->dp501_fw =NULL ; } -static int ast_load_dp501_microcode (struct drm_device *dev) +static int ast_load_dp501_microcode (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;int ret; ret =request_firmware (&ast->dp501_fw,"ast_dp501_fw.bin" , dev->dev);
@@ -109,10 +109,10 @@ static bool wait_fw_ready(struct ast_device *ast) }#endif -static bool ast_write_cmd (struct drm_device *dev,u8 data) +static bool ast_write_cmd (struct ast_device *ast,u8 data) { -struct ast_device *ast =to_ast_device (dev);int retry =0 ; +if (wait_nack (ast)) {send_nack (ast);ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0x9a ,0x00 , data);
@@ -131,10 +131,8 @@ static bool ast_write_cmd(struct drm_device *dev, u8 data)return false; } -static bool ast_write_data (struct drm_device *dev,u8 data) +static bool ast_write_data (struct ast_device *ast,u8 data) { -struct ast_device *ast =to_ast_device (dev); -if (wait_nack (ast)) {send_nack (ast);ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0x9a ,0x00 , data);
@@ -175,10 +173,10 @@ static void clear_cmd(struct ast_device *ast) }#endif -static void ast_set_dp501_video_output (struct drm_device *dev,u8 mode) +static void ast_set_dp501_video_output (struct ast_device *ast,u8 mode) { -ast_write_cmd (dev,0x40 ); -ast_write_data (dev, mode); +ast_write_cmd (ast,0x40 ); +ast_write_data (ast, mode);msleep (10 ); }
@@ -188,9 +186,8 @@ static u32 get_fw_base(struct ast_device *ast)return ast_mindwm (ast,0x1e6e2104 ) &0x7fffffff ; } -bool ast_backup_fw (struct drm_device *dev,u8 *addr,u32 size) +bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size) { -struct ast_device *ast =to_ast_device (dev);u32 i, data;u32 boot_address;
@@ -207,9 +204,8 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)return false; } -static bool ast_launch_m68k (struct drm_device *dev) +static bool ast_launch_m68k (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u32 i, data, len =0 ;u32 boot_address;u8 *fw_addr =NULL ;
@@ -226,7 +222,7 @@ static bool ast_launch_m68k(struct drm_device *dev) len =32 *1024 ; }else {if (!ast->dp501_fw && -ast_load_dp501_microcode (dev) <0 ) +ast_load_dp501_microcode (ast) <0 )return false; fw_addr = (u8 *)ast->dp501_fw->data;
@@ -348,9 +344,8 @@ static int ast_dp512_read_edid_block(void *data, u8 *buf, unsigned int block, sireturn true; } -static bool ast_init_dvo (struct drm_device *dev) +static bool ast_init_dvo (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 jreg;u32 data;ast_write32 (ast,0xf004 ,0x1e6e0000 );
@@ -421,9 +416,8 @@ static bool ast_init_dvo(struct drm_device *dev) } -static void ast_init_analog (struct drm_device *dev) +static void ast_init_analog (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u32 data;/*
@@ -448,28 +442,27 @@ static void ast_init_analog(struct drm_device *dev)ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xa3 ,0xcf ,0x00 ); } -void ast_init_3rdtx (struct drm_device *dev) +void ast_init_3rdtx (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 jreg;if (IS_AST_GEN4 (ast) ||IS_AST_GEN5 (ast)) { jreg =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd1 ,0xff );switch (jreg &0x0e ) {case 0x04 : -ast_init_dvo (dev); +ast_init_dvo (ast);break ;case 0x08 : -ast_launch_m68k (dev); +ast_launch_m68k (ast);break ;case 0x0c : -ast_init_dvo (dev); +ast_init_dvo (ast);break ;default :if (ast->tx_chip ==AST_TX_SIL164 ) -ast_init_dvo (dev); +ast_init_dvo (ast);else -ast_init_analog (dev); +ast_init_analog (ast); } } }
@@ -485,17 +478,17 @@ static const struct drm_encoder_funcs ast_dp501_encoder_funcs = {static void ast_dp501_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 (encoder->dev); -ast_set_dp501_video_output (dev,1 ); +ast_set_dp501_video_output (ast,1 ); }static void ast_dp501_encoder_helper_atomic_disable (struct drm_encoder *encoder,struct drm_atomic_state *state) { -struct drm_device *dev = encoder->dev; +struct ast_device *ast =to_ast_device (encoder->dev); -ast_set_dp501_video_output (dev,0 ); +ast_set_dp501_video_output (ast,0 ); }static const struct drm_encoder_helper_funcs ast_dp501_encoder_helper_funcs = {
drivers/gpu/drm/ast/ast_drv.h +2 -2
@@ -455,8 +455,8 @@ int ast_vga_output_init(struct ast_device *ast);int ast_sil164_output_init (struct ast_device *ast);/* ast dp501 */ -bool ast_backup_fw (struct drm_device *dev,u8 *addr,u32 size); -void ast_init_3rdtx (struct drm_device *dev); +bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size); +void ast_init_3rdtx (struct ast_device *ast);int ast_dp501_output_init (struct ast_device *ast);/* aspeed DP */
drivers/gpu/drm/ast/ast_main.c +1 -1
@@ -110,7 +110,7 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post) ast->dp501_fw_addr =drmm_kzalloc (dev,32 *1024 ,GFP_KERNEL );if (ast->dp501_fw_addr) {/* backup firmware */ -if (ast_backup_fw (dev, ast->dp501_fw_addr,32 *1024 )) { +if (ast_backup_fw (ast, ast->dp501_fw_addr,32 *1024 )) {drmm_kfree (dev, ast->dp501_fw_addr); ast->dp501_fw_addr =NULL ; }
drivers/gpu/drm/ast/ast_post.c +1 -1
@@ -360,7 +360,7 @@ void ast_post_gpu(struct drm_device *dev)else ast_init_dram_reg (dev); -ast_init_3rdtx (dev); +ast_init_3rdtx (ast); }else {if (ast->tx_chip ==AST_TX_SIL164 )ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xa3 ,0xcf ,0x80 );/* Enable DVO */
Signature · 1 line
2.46.0
Re: [PATCH 06/10] drm/ast: dp501: Avoid upcasting to struct ast_device
Quoted 4 lines · Thomas Zimmermann
Several functions receive an instance of struct
drm_deviceonly to upcast it to structast_device. Improve type safety by passing the AST device directly.
Thanks, it looks good to me. One small comment below
Quoted 193 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_dp501.c | 53 ++++++++++++++------------------- drivers/gpu/drm/ast/ast_drv.h | 4 +-- drivers/gpu/drm/ast/ast_main.c | 2 +- drivers/gpu/drm/ast/ast_post.c | 2 +- 4 files changed, 27 insertions(+), 34 deletions(-)drivers/gpu/drm/ast/ast_dp501.c +23
-30@@ -21,9 +21,9 @@ static void ast_release_firmware(void *data) ast->dp501_fw =NULL ; } -static int ast_load_dp501_microcode (struct drm_device *dev) +static int ast_load_dp501_microcode (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;int ret; ret =request_firmware (&ast->dp501_fw,"ast_dp501_fw.bin" , dev->dev);@@ -109,10 +109,10 @@ static bool wait_fw_ready(struct ast_device *ast) }#endif -static bool ast_write_cmd (struct drm_device *dev,u8 data) +static bool ast_write_cmd (struct ast_device *ast,u8 data) { -struct ast_device *ast =to_ast_device (dev);int retry =0 ; +if (wait_nack (ast)) {send_nack (ast);ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0x9a ,0x00 , data);@@ -131,10 +131,8 @@ static bool ast_write_cmd(struct drm_device *dev, u8 data)return false; } -static bool ast_write_data (struct drm_device *dev,u8 data) +static bool ast_write_data (struct ast_device *ast,u8 data) { -struct ast_device *ast =to_ast_device (dev); -if (wait_nack (ast)) {send_nack (ast);ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0x9a ,0x00 , data);@@ -175,10 +173,10 @@ static void clear_cmd(struct ast_device *ast) }#endif -static void ast_set_dp501_video_output (struct drm_device *dev,u8 mode) +static void ast_set_dp501_video_output (struct ast_device *ast,u8 mode) { -ast_write_cmd (dev,0x40 ); -ast_write_data (dev, mode); +ast_write_cmd (ast,0x40 ); +ast_write_data (ast, mode);msleep (10 ); }@@ -188,9 +186,8 @@ static u32 get_fw_base(struct ast_device *ast)return ast_mindwm (ast,0x1e6e2104 ) &0x7fffffff ; } -bool ast_backup_fw (struct drm_device *dev,u8 *addr,u32 size) +bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size) { -struct ast_device *ast =to_ast_device (dev);u32 i, data;u32 boot_address;@@ -207,9 +204,8 @@ bool ast_backup_fw(struct drm_device *dev, u8 *addr, u32 size)return false; } -static bool ast_launch_m68k (struct drm_device *dev) +static bool ast_launch_m68k (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u32 i, data, len =0 ;u32 boot_address;u8 *fw_addr =NULL ;@@ -226,7 +222,7 @@ static bool ast_launch_m68k(struct drm_device *dev) len =32 *1024 ; }else {if (!ast->dp501_fw && -ast_load_dp501_microcode (dev) <0 ) +ast_load_dp501_microcode (ast) <0 )return false; fw_addr = (u8 *)ast->dp501_fw->data;@@ -348,9 +344,8 @@ static int ast_dp512_read_edid_block(void *data, u8 *buf, unsigned int block, sireturn true; } -static bool ast_init_dvo (struct drm_device *dev) +static bool ast_init_dvo (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 jreg;u32 data;ast_write32 (ast,0xf004 ,0x1e6e0000 );@@ -421,9 +416,8 @@ static bool ast_init_dvo(struct drm_device *dev) } -static void ast_init_analog (struct drm_device *dev) +static void ast_init_analog (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u32 data;/* @@ -448,28 +442,27 @@ static void ast_init_analog(struct drm_device *dev)ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xa3 ,0xcf ,0x00 ); } -void ast_init_3rdtx (struct drm_device *dev) +void ast_init_3rdtx (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 jreg;if (IS_AST_GEN4 (ast) ||IS_AST_GEN5 (ast)) { jreg =ast_get_index_reg_mask (ast,AST_IO_VGACRI ,0xd1 ,0xff );switch (jreg &0x0e ) {case 0x04 : -ast_init_dvo (dev); +ast_init_dvo (ast);break ;case 0x08 : -ast_launch_m68k (dev); +ast_launch_m68k (ast);break ;case 0x0c : -ast_init_dvo (dev); +ast_init_dvo (ast);break ;default :if (ast->tx_chip ==AST_TX_SIL164 ) -ast_init_dvo (dev); +ast_init_dvo (ast);else -ast_init_analog (dev); +ast_init_analog (ast); } } }@@ -485,17 +478,17 @@ static const struct drm_encoder_funcs ast_dp501_encoder_funcs = {static void ast_dp501_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 (encoder->dev); -ast_set_dp501_video_output (dev,1 ); +ast_set_dp501_video_output (ast,1 ); }static void ast_dp501_encoder_helper_atomic_disable (struct drm_encoder *encoder,struct drm_atomic_state *state) { -struct drm_device *dev = encoder->dev; +struct ast_device *ast =to_ast_device (encoder->dev); -ast_set_dp501_video_output (dev,0 ); +ast_set_dp501_video_output (ast,0 ); }static const struct drm_encoder_helper_funcs ast_dp501_encoder_helper_funcs = {drivers/gpu/drm/ast/ast_drv.h +2
-2@@ -455,8 +455,8 @@ int ast_vga_output_init(struct ast_device *ast);int ast_sil164_output_init (struct ast_device *ast);/* ast dp501 */ -bool ast_backup_fw (struct drm_device *dev,u8 *addr,u32 size); -void ast_init_3rdtx (struct drm_device *dev); +bool ast_backup_fw (struct ast_device *ast,u8 *addr,u32 size); +void ast_init_3rdtx (struct ast_device *ast);int ast_dp501_output_init (struct ast_device *ast);/* aspeed DP */ drivers/gpu/drm/ast/ast_main.c +0
-0
drivers/gpu/drm/ast/ast_main.c static void ast_detect_tx_chip(struct ast_device *ast, bool need_post) · line 113
Quoted 5 lines
drivers/gpu/drm/ast/ast_main.c +1
-1@@ -110,7 +110,7 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post) ast->dp501_fw_addr =drmm_kzalloc (dev,32 *1024 ,GFP_KERNEL );if (ast->dp501_fw_addr) {/* backup firmware */ -if (ast_backup_fw (dev, ast->dp501_fw_addr,32 *1024 )) { +if (ast_backup_fw (ast, ast->dp501_fw_addr,32 *1024 )) {
Maybe we can remove the fw_addr parameter of ast_backup_fw(), it's the only call to this function.
Quoted 16 lines
drivers/gpu/drm/ast/ast_main.c +0
-0drmm_kfree (dev, ast->dp501_fw_addr); ast->dp501_fw_addr =NULL ; }drivers/gpu/drm/ast/ast_post.c +1
-1@@ -360,7 +360,7 @@ void ast_post_gpu(struct drm_device *dev)else ast_init_dram_reg (dev); -ast_init_3rdtx (dev); +ast_init_3rdtx (ast); }else {if (ast->tx_chip ==AST_TX_SIL164 )ast_set_index_reg_mask (ast,AST_IO_VGACRI ,0xa3 ,0xcf ,0x80 );/* Enable DVO */
Thomas Zimmermann
maintainerRe: [PATCH 06/10] drm/ast: dp501: Avoid upcasting to struct ast_device
Hi
Am 12.09.24 um 15:48 schrieb Jocelyn Falempe:
[...]
Quoted 11 lines
drivers/gpu/drm/ast/ast_main.c static void ast_detect_tx_chip(struct ast_device · line 114
Quoted 9 lines
drivers/gpu/drm/ast/ast_main.c +1
-1@@ -110,7 +110,7 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post) ast->dp501_fw_addr = drmm_kzalloc(dev, 32*1024, GFP_KERNEL); if (ast->dp501_fw_addr) { /* backup firmware */ - if (ast_backup_fw(dev, ast->dp501_fw_addr, 32*1024)) { + if (ast_backup_fw(ast, ast->dp501_fw_addr, 32*1024)) {Maybe we can remove the
fw_addrparameter ofast_backup_fw(), it's the only call to this function.
I don't mind, but it belongs in a separate patchset. After doing something about the odd TX chips that we talked about, I intent to rework the TX- and GPU-POST code.
Best regards
Thomas
Quoted 17 lines
Quoted 16 lines
drivers/gpu/drm/ast/ast_main.c +0
-0drmm_kfree(dev, ast->dp501_fw_addr); ast->dp501_fw_addr = NULL;}
drivers/gpu/drm/ast/ast_post.c +0
-0@@ -360,7 +360,7 @@ void ast_post_gpu(struct drm_device *dev)else
ast_init_dram_reg(dev);
-ast_init_3rdtx(dev);
+ast_init_3rdtx(ast);
} else {
if (ast->tx_chip==AST_TX_SIL164)
ast_set_index_reg_mask(ast, AST_IO_VGACRI, 0xa3, 0xcf, 0x80); /* Enable DVO */
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)
Thomas Zimmermann
maintainerPATCH 7/10 drm/ast: sil164: Inline ast_sil164_connector_init()
In reply to Thomas ZimmermannInline ast_sil164_connector_init() into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined. While at it, remove the error message from the call to ast_ddc_create(). The function already warns on errors.
Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
--- drivers/gpu/drm/ast/ast_sil164.c | 55 +++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-)
drivers/gpu/drm/ast/ast_sil164.c +26 -29
@@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_sil164_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_sil164_connector_init (struct drm_device *dev,struct drm_connector *connector) +/* +* Output +*/ + +int ast_sil164_output_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base; +struct drm_crtc *crtc = &ast->crtc;struct i2c_adapter *ddc; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* DDC */ + ddc =ast_ddc_create (ast); -if (IS_ERR (ddc)) { - ret =PTR_ERR (ddc); -drm_err (dev,"failed to add DDC bus for connector; ret=%d\n" , ret); +if (IS_ERR (ddc)) +return PTR_ERR (ddc); + +/* encoder */ + + encoder = &ast->output.sil164.encoder; + ret =drm_encoder_init (dev, encoder, &ast_sil164_encoder_funcs, +DRM_MODE_ENCODER_TMDS ,NULL ); +if (ret)return ret; - } + encoder->possible_crtcs =drm_crtc_mask (crtc); + +/* connector */ + ast_connector = &ast->output.sil164.connector; + connector = &ast_connector->base; ret =drm_connector_init_with_ddc (dev, connector, &ast_sil164_connector_funcs,DRM_MODE_CONNECTOR_DVII , ddc);if (ret)return ret; -drm_connector_helper_add (connector, &ast_sil164_connector_helper_funcs); connector->interlace_allowed =0 ; connector->doublescan_allowed =0 ; - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; -return 0 ; -} - -int ast_sil164_output_init (struct ast_device *ast) -{ -struct drm_device *dev = &ast->base; -struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.sil164.encoder; -struct ast_connector *ast_connector = &ast->output.sil164.connector; -struct drm_connector *connector = &ast_connector->base; -int ret; - - ret =drm_encoder_init (dev, encoder, &ast_sil164_encoder_funcs, -DRM_MODE_ENCODER_TMDS ,NULL ); -if (ret) -return ret; - encoder->possible_crtcs =drm_crtc_mask (crtc); - - ret =ast_sil164_connector_init (dev, connector); -if (ret) -return ret; ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Signature · 1 line
2.46.0
Re: [PATCH 07/10] drm/ast: sil164: Inline ast_sil164_connector_init()
Quoted 8 lines · Thomas Zimmermann
Inline
ast_sil164_connector_init()into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined. While at it, remove the error message from the call toast_ddc_create(). The function already warns on errors.Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
Thanks, it looks good to me.
Quoted 89 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_sil164.c | 55 +++++++++++++++----------------- 1 file changed, 26 insertions(+), 29 deletions(-)drivers/gpu/drm/ast/ast_sil164.c +26
-29@@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_sil164_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_sil164_connector_init (struct drm_device *dev,struct drm_connector *connector) +/* +* Output +*/ + +int ast_sil164_output_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base; +struct drm_crtc *crtc = &ast->crtc;struct i2c_adapter *ddc; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* DDC */ + ddc =ast_ddc_create (ast); -if (IS_ERR (ddc)) { - ret =PTR_ERR (ddc); -drm_err (dev,"failed to add DDC bus for connector; ret=%d\n" , ret); +if (IS_ERR (ddc)) +return PTR_ERR (ddc); + +/* encoder */ + + encoder = &ast->output.sil164.encoder; + ret =drm_encoder_init (dev, encoder, &ast_sil164_encoder_funcs, +DRM_MODE_ENCODER_TMDS ,NULL ); +if (ret)return ret; - } + encoder->possible_crtcs =drm_crtc_mask (crtc); + +/* connector */ + ast_connector = &ast->output.sil164.connector; + connector = &ast_connector->base; ret =drm_connector_init_with_ddc (dev, connector, &ast_sil164_connector_funcs,DRM_MODE_CONNECTOR_DVII , ddc);if (ret)return ret; -drm_connector_helper_add (connector, &ast_sil164_connector_helper_funcs); connector->interlace_allowed =0 ; connector->doublescan_allowed =0 ; - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; -return 0 ; -} - -int ast_sil164_output_init (struct ast_device *ast) -{ -struct drm_device *dev = &ast->base; -struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.sil164.encoder; -struct ast_connector *ast_connector = &ast->output.sil164.connector; -struct drm_connector *connector = &ast_connector->base; -int ret; - - ret =drm_encoder_init (dev, encoder, &ast_sil164_encoder_funcs, -DRM_MODE_ENCODER_TMDS ,NULL ); -if (ret) -return ret; - encoder->possible_crtcs =drm_crtc_mask (crtc); - - ret =ast_sil164_connector_init (dev, connector); -if (ret) -return ret; ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Thomas Zimmermann
maintainerPATCH 8/10 drm/ast: vga: Inline ast_vga_connector_init()
In reply to Thomas ZimmermannInline ast_vga_connector_init() into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined. While at it, remove the error message from the call to ast_ddc_create(). The function already warns on errors.
Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
--- drivers/gpu/drm/ast/ast_vga.c | 55 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)
drivers/gpu/drm/ast/ast_vga.c +26 -29
@@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_vga_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_vga_connector_init (struct drm_device *dev,struct drm_connector *connector) +/* +* Output +*/ + +int ast_vga_output_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base; +struct drm_crtc *crtc = &ast->crtc;struct i2c_adapter *ddc; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* DDC */ + ddc =ast_ddc_create (ast); -if (IS_ERR (ddc)) { - ret =PTR_ERR (ddc); -drm_err (dev,"failed to add DDC bus for connector; ret=%d\n" , ret); +if (IS_ERR (ddc)) +return PTR_ERR (ddc); + +/* encoder */ + + encoder = &ast->output.vga.encoder; + ret =drm_encoder_init (dev, encoder, &ast_vga_encoder_funcs, +DRM_MODE_ENCODER_DAC ,NULL ); +if (ret)return ret; - } + encoder->possible_crtcs =drm_crtc_mask (crtc); + +/* connector */ + ast_connector = &ast->output.vga.connector; + connector = &ast_connector->base; ret =drm_connector_init_with_ddc (dev, connector, &ast_vga_connector_funcs,DRM_MODE_CONNECTOR_VGA , ddc);if (ret)return ret; -drm_connector_helper_add (connector, &ast_vga_connector_helper_funcs); connector->interlace_allowed =0 ; connector->doublescan_allowed =0 ; - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; -return 0 ; -} - -int ast_vga_output_init (struct ast_device *ast) -{ -struct drm_device *dev = &ast->base; -struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.vga.encoder; -struct ast_connector *ast_connector = &ast->output.vga.connector; -struct drm_connector *connector = &ast_connector->base; -int ret; - - ret =drm_encoder_init (dev, encoder, &ast_vga_encoder_funcs, -DRM_MODE_ENCODER_DAC ,NULL ); -if (ret) -return ret; - encoder->possible_crtcs =drm_crtc_mask (crtc); - - ret =ast_vga_connector_init (dev, connector); -if (ret) -return ret; ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Signature · 1 line
2.46.0
Re: [PATCH 08/10] drm/ast: vga: Inline ast_vga_connector_init()
Quoted 8 lines · Thomas Zimmermann
Inline
ast_vga_connector_init()into its only caller. The helper currently only does half of the connector-init work and is trivial enough to be inlined. While at it, remove the error message from the call toast_ddc_create(). The function already warns on errors.Also set the local variables for encoder and connector as late as possible, so that the compiler warns if we use them before having initialized the instance.
Thanks, it looks good to me.
Quoted 89 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_vga.c | 55 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)drivers/gpu/drm/ast/ast_vga.c +26
-29@@ -71,52 +71,49 @@ static const struct drm_connector_funcs ast_vga_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; -static int ast_vga_connector_init (struct drm_device *dev,struct drm_connector *connector) +/* +* Output +*/ + +int ast_vga_output_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base; +struct drm_crtc *crtc = &ast->crtc;struct i2c_adapter *ddc; +struct drm_encoder *encoder; +struct ast_connector *ast_connector; +struct drm_connector *connector;int ret; +/* DDC */ + ddc =ast_ddc_create (ast); -if (IS_ERR (ddc)) { - ret =PTR_ERR (ddc); -drm_err (dev,"failed to add DDC bus for connector; ret=%d\n" , ret); +if (IS_ERR (ddc)) +return PTR_ERR (ddc); + +/* encoder */ + + encoder = &ast->output.vga.encoder; + ret =drm_encoder_init (dev, encoder, &ast_vga_encoder_funcs, +DRM_MODE_ENCODER_DAC ,NULL ); +if (ret)return ret; - } + encoder->possible_crtcs =drm_crtc_mask (crtc); + +/* connector */ + ast_connector = &ast->output.vga.connector; + connector = &ast_connector->base; ret =drm_connector_init_with_ddc (dev, connector, &ast_vga_connector_funcs,DRM_MODE_CONNECTOR_VGA , ddc);if (ret)return ret; -drm_connector_helper_add (connector, &ast_vga_connector_helper_funcs); connector->interlace_allowed =0 ; connector->doublescan_allowed =0 ; - connector->polled =DRM_CONNECTOR_POLL_CONNECT |DRM_CONNECTOR_POLL_DISCONNECT ; -return 0 ; -} - -int ast_vga_output_init (struct ast_device *ast) -{ -struct drm_device *dev = &ast->base; -struct drm_crtc *crtc = &ast->crtc; -struct drm_encoder *encoder = &ast->output.vga.encoder; -struct ast_connector *ast_connector = &ast->output.vga.connector; -struct drm_connector *connector = &ast_connector->base; -int ret; - - ret =drm_encoder_init (dev, encoder, &ast_vga_encoder_funcs, -DRM_MODE_ENCODER_DAC ,NULL ); -if (ret) -return ret; - encoder->possible_crtcs =drm_crtc_mask (crtc); - - ret =ast_vga_connector_init (dev, connector); -if (ret) -return ret; ast_connector->physical_status = connector->status; ret =drm_connector_attach_encoder (connector, encoder);
Thomas Zimmermann
maintainerPATCH 9/10 drm/ast: Respect return value from CRTC init
In reply to Thomas ZimmermannReturn an error if CRTC initialization fails.
--- drivers/gpu/drm/ast/ast_mode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_mode.c +3 -1
@@ -1396,7 +1396,9 @@ int ast_mode_config_init(struct ast_device *ast)if (ret)return ret; -ast_crtc_init (dev); + ret =ast_crtc_init (dev); +if (ret) +return ret;switch (ast->tx_chip) {case AST_TX_NONE :
Signature · 1 line
2.46.0
Re: [PATCH 09/10] drm/ast: Respect return value from CRTC init
Quoted 1 line · Thomas Zimmermann
Return an error if CRTC initialization fails.
Thanks, it looks good to me.
Quoted 21 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_mode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/ast/ast_mode.c +3
-1@@ -1396,7 +1396,9 @@ int ast_mode_config_init(struct ast_device *ast)if (ret)return ret; -ast_crtc_init (dev); + ret =ast_crtc_init (dev); +if (ret) +return ret;switch (ast->tx_chip) {case AST_TX_NONE :
Thomas Zimmermann
maintainerPATCH 10/10 drm/ast: Avoid upcasting to struct ast_device
In reply to Thomas ZimmermannSeveral functions receive an instance of struct drm_device only to upcast it to struct ast_device. Improve type safety by passing the AST device directly.
--- drivers/gpu/drm/ast/ast_drv.c | 2 +- drivers/gpu/drm/ast/ast_drv.h | 2 +- drivers/gpu/drm/ast/ast_main.c | 8 ++++---- drivers/gpu/drm/ast/ast_mode.c | 6 +++--- drivers/gpu/drm/ast/ast_post.c | 30 ++++++++++++------------------ 5 files changed, 21 insertions(+), 27 deletions(-)
drivers/gpu/drm/ast/ast_drv.c +1 -1
@@ -396,7 +396,7 @@ static int ast_drm_thaw(struct drm_device *dev)ast_enable_vga (ast->ioregs);ast_open_key (ast->ioregs);ast_enable_mmio (dev->dev, ast->ioregs); -ast_post_gpu (dev); +ast_post_gpu (ast);return drm_mode_config_helper_resume (dev); }
drivers/gpu/drm/ast/ast_drv.h +1 -1
@@ -446,7 +446,7 @@ int ast_mode_config_init(struct ast_device *ast);int ast_mm_init (struct ast_device *ast);/* ast post */ -void ast_post_gpu (struct drm_device *dev); +void ast_post_gpu (struct ast_device *ast);u32 ast_mindwm (struct ast_device *ast,u32 r);void ast_moutdwm (struct ast_device *ast,u32 r,u32 v);void ast_patch_ahb_2500 (void __iomem *regs);
drivers/gpu/drm/ast/ast_main.c +4 -4
@@ -132,10 +132,10 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)drm_info (dev,"Using %s\n" , info_str[ast->tx_chip]); } -static int ast_get_dram_info (struct drm_device *dev) +static int ast_get_dram_info (struct ast_device *ast) { +struct drm_device *dev = &ast->base;struct device_node *np = dev->dev->of_node; -struct ast_device *ast =to_ast_device (dev);uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;uint32_t denum, num, div, ref_pll, dsel;
@@ -277,7 +277,7 @@ struct drm_device *ast_device_create(struct pci_dev *pdev,ast_detect_widescreen (ast);ast_detect_tx_chip (ast, need_post); - ret =ast_get_dram_info (dev); + ret =ast_get_dram_info (ast);if (ret)return ERR_PTR (ret);
@@ -285,7 +285,7 @@ struct drm_device *ast_device_create(struct pci_dev *pdev, ast->mclk, ast->dram_type, ast->dram_bus_width);if (need_post) -ast_post_gpu (dev); +ast_post_gpu (ast); ret =ast_mm_init (ast);if (ret)
drivers/gpu/drm/ast/ast_mode.c +3 -3
@@ -1287,9 +1287,9 @@ static const struct drm_crtc_funcs ast_crtc_funcs = { .atomic_destroy_state = ast_crtc_atomic_destroy_state, }; -static int ast_crtc_init (struct drm_device *dev) +static int ast_crtc_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;struct drm_crtc *crtc = &ast->crtc;int ret;
@@ -1396,7 +1396,7 @@ int ast_mode_config_init(struct ast_device *ast)if (ret)return ret; - ret =ast_crtc_init (dev); + ret =ast_crtc_init (ast);if (ret)return ret;
drivers/gpu/drm/ast/ast_post.c +12 -18
@@ -34,16 +34,14 @@#include "ast_dram_tables.h" #include "ast_drv.h" -static void ast_post_chip_2300 (struct drm_device *dev); -static void ast_post_chip_2500 (struct drm_device *dev); +static void ast_post_chip_2300 (struct ast_device *ast); +static void ast_post_chip_2500 (struct ast_device *ast);static const u8 extreginfo[] = {0x0f ,0x04 ,0x1c ,0xff };static const u8 extreginfo_ast2300[] = {0x0f ,0x04 ,0x1f ,0xff }; -static void -ast_set_def_ext_reg (struct drm_device *dev) +static void ast_set_def_ext_reg (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 i, index, reg;const u8 *ext_reg_info;
@@ -252,9 +250,8 @@ static void cbrdlli_ast2150(struct ast_device *ast, int busw) -static void ast_init_dram_reg (struct drm_device *dev) +static void ast_init_dram_reg (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 j;u32 data, temp, i;const struct ast_dramstruct *dram_reg_info;
@@ -343,22 +340,20 @@ static void ast_init_dram_reg(struct drm_device *dev) }while ((j &0x40 ) ==0 ); } -void ast_post_gpu (struct drm_device *dev) +void ast_post_gpu (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); - -ast_set_def_ext_reg (dev); +ast_set_def_ext_reg (ast);if (IS_AST_GEN7 (ast)) {if (ast->tx_chip ==AST_TX_ASTDP )ast_dp_launch (ast); }else if (ast->config_mode == ast_use_p2a) {if (IS_AST_GEN6 (ast)) -ast_post_chip_2500 (dev); +ast_post_chip_2500 (ast);else if (IS_AST_GEN5 (ast) ||IS_AST_GEN4 (ast)) -ast_post_chip_2300 (dev); +ast_post_chip_2300 (ast);else -ast_init_dram_reg (dev); +ast_init_dram_reg (ast);ast_init_3rdtx (ast); }else {
@@ -1569,9 +1564,8 @@ static void ddr2_init(struct ast_device *ast, struct ast2300_dram_param *param) } -static void ast_post_chip_2300 (struct drm_device *dev) +static void ast_post_chip_2300 (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);struct ast2300_dram_param param;u32 temp;u8 reg;
@@ -2038,9 +2032,9 @@ void ast_patch_ahb_2500(void __iomem *regs)__ast_moutdwm (regs,0x1e6e207c ,0x08000000 );/* clear fast reset */ } -void ast_post_chip_2500 (struct drm_device *dev) +void ast_post_chip_2500 (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;u32 temp;u8 reg;
Signature · 1 line
2.46.0
Re: [PATCH 10/10] drm/ast: Avoid upcasting to struct ast_device
Quoted 3 lines · Thomas Zimmermann
Several functions receive an instance of struct
drm_deviceonly to upcast it to structast_device. Improve type safety by passing the AST device directly.
Thanks, it looks good to me.
Quoted 182 lines
Signed-off-by Thomas Zimmermann <[email protected]>--- drivers/gpu/drm/ast/ast_drv.c | 2 +- drivers/gpu/drm/ast/ast_drv.h | 2 +- drivers/gpu/drm/ast/ast_main.c | 8 ++++---- drivers/gpu/drm/ast/ast_mode.c | 6 +++--- drivers/gpu/drm/ast/ast_post.c | 30 ++++++++++++------------------ 5 files changed, 21 insertions(+), 27 deletions(-)drivers/gpu/drm/ast/ast_drv.c +1
-1@@ -396,7 +396,7 @@ static int ast_drm_thaw(struct drm_device *dev)ast_enable_vga (ast->ioregs);ast_open_key (ast->ioregs);ast_enable_mmio (dev->dev, ast->ioregs); -ast_post_gpu (dev); +ast_post_gpu (ast);return drm_mode_config_helper_resume (dev); }drivers/gpu/drm/ast/ast_drv.h +1
-1@@ -446,7 +446,7 @@ int ast_mode_config_init(struct ast_device *ast);int ast_mm_init (struct ast_device *ast);/* ast post */ -void ast_post_gpu (struct drm_device *dev); +void ast_post_gpu (struct ast_device *ast);u32 ast_mindwm (struct ast_device *ast,u32 r);void ast_moutdwm (struct ast_device *ast,u32 r,u32 v);void ast_patch_ahb_2500 (void __iomem *regs);drivers/gpu/drm/ast/ast_main.c +4
-4@@ -132,10 +132,10 @@ static void ast_detect_tx_chip(struct ast_device *ast, bool need_post)drm_info (dev,"Using %s\n" , info_str[ast->tx_chip]); } -static int ast_get_dram_info (struct drm_device *dev) +static int ast_get_dram_info (struct ast_device *ast) { +struct drm_device *dev = &ast->base;struct device_node *np = dev->dev->of_node; -struct ast_device *ast =to_ast_device (dev);uint32_t mcr_cfg, mcr_scu_mpll, mcr_scu_strap;uint32_t denum, num, div, ref_pll, dsel;@@ -277,7 +277,7 @@ struct drm_device *ast_device_create(struct pci_dev *pdev,ast_detect_widescreen (ast);ast_detect_tx_chip (ast, need_post); - ret =ast_get_dram_info (dev); + ret =ast_get_dram_info (ast);if (ret)return ERR_PTR (ret);@@ -285,7 +285,7 @@ struct drm_device *ast_device_create(struct pci_dev *pdev, ast->mclk, ast->dram_type, ast->dram_bus_width);if (need_post) -ast_post_gpu (dev); +ast_post_gpu (ast); ret =ast_mm_init (ast);if (ret)drivers/gpu/drm/ast/ast_mode.c +3
-3@@ -1287,9 +1287,9 @@ static const struct drm_crtc_funcs ast_crtc_funcs = { .atomic_destroy_state = ast_crtc_atomic_destroy_state, }; -static int ast_crtc_init (struct drm_device *dev) +static int ast_crtc_init (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;struct drm_crtc *crtc = &ast->crtc;int ret;@@ -1396,7 +1396,7 @@ int ast_mode_config_init(struct ast_device *ast)if (ret)return ret; - ret =ast_crtc_init (dev); + ret =ast_crtc_init (ast);if (ret)return ret;drivers/gpu/drm/ast/ast_post.c +12
-18@@ -34,16 +34,14 @@#include "ast_dram_tables.h" #include "ast_drv.h" -static void ast_post_chip_2300 (struct drm_device *dev); -static void ast_post_chip_2500 (struct drm_device *dev); +static void ast_post_chip_2300 (struct ast_device *ast); +static void ast_post_chip_2500 (struct ast_device *ast);static const u8 extreginfo[] = {0x0f ,0x04 ,0x1c ,0xff };static const u8 extreginfo_ast2300[] = {0x0f ,0x04 ,0x1f ,0xff }; -static void -ast_set_def_ext_reg (struct drm_device *dev) +static void ast_set_def_ext_reg (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 i, index, reg;const u8 *ext_reg_info;@@ -252,9 +250,8 @@ static void cbrdlli_ast2150(struct ast_device *ast, int busw) -static void ast_init_dram_reg (struct drm_device *dev) +static void ast_init_dram_reg (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);u8 j;u32 data, temp, i;const struct ast_dramstruct *dram_reg_info;@@ -343,22 +340,20 @@ static void ast_init_dram_reg(struct drm_device *dev) }while ((j &0x40 ) ==0 ); } -void ast_post_gpu (struct drm_device *dev) +void ast_post_gpu (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); - -ast_set_def_ext_reg (dev); +ast_set_def_ext_reg (ast);if (IS_AST_GEN7 (ast)) {if (ast->tx_chip ==AST_TX_ASTDP )ast_dp_launch (ast); }else if (ast->config_mode == ast_use_p2a) {if (IS_AST_GEN6 (ast)) -ast_post_chip_2500 (dev); +ast_post_chip_2500 (ast);else if (IS_AST_GEN5 (ast) ||IS_AST_GEN4 (ast)) -ast_post_chip_2300 (dev); +ast_post_chip_2300 (ast);else -ast_init_dram_reg (dev); +ast_init_dram_reg (ast);ast_init_3rdtx (ast); }else {@@ -1569,9 +1564,8 @@ static void ddr2_init(struct ast_device *ast, struct ast2300_dram_param *param) } -static void ast_post_chip_2300 (struct drm_device *dev) +static void ast_post_chip_2300 (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev);struct ast2300_dram_param param;u32 temp;u8 reg;@@ -2038,9 +2032,9 @@ void ast_patch_ahb_2500(void __iomem *regs)__ast_moutdwm (regs,0x1e6e207c ,0x08000000 );/* clear fast reset */ } -void ast_post_chip_2500 (struct drm_device *dev) +void ast_post_chip_2500 (struct ast_device *ast) { -struct ast_device *ast =to_ast_device (dev); +struct drm_device *dev = &ast->base;u32 temp;u8 reg;