diff mbox series

[10/10] drm/ast: Avoid upcasting to struct ast_device

Message ID 20240911115347.899148-11-tzimmermann@suse.de (mailing list archive)
State New, archived
Headers show
Series drm/ast: Various cleanups | expand

Commit Message

Thomas Zimmermann Sept. 11, 2024, 11:51 a.m. UTC
Several 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.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 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(-)

Comments

Jocelyn Falempe Sept. 12, 2024, 1:49 p.m. UTC | #1
On 11/09/2024 13:51, Thomas Zimmermann wrote:
> Several 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.

Thanks, it looks good to me.

Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---
>   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(-)
> 
> diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
> index 225817087b4d..63b7ef02513d 100644
> --- a/drivers/gpu/drm/ast/ast_drv.c
> +++ b/drivers/gpu/drm/ast/ast_drv.c
> @@ -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);
>   }
> diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
> index e29db59bb7d8..21ce3769bf0d 100644
> --- a/drivers/gpu/drm/ast/ast_drv.h
> +++ b/drivers/gpu/drm/ast/ast_drv.h
> @@ -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);
> diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
> index 3aeb0f4b19d5..3d92d9e5208f 100644
> --- a/drivers/gpu/drm/ast/ast_main.c
> +++ b/drivers/gpu/drm/ast/ast_main.c
> @@ -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)
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index f90fade5d681..9d5321c81e68 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -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;
>   
> diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c
> index 324778c72d23..364030f97571 100644
> --- a/drivers/gpu/drm/ast/ast_post.c
> +++ b/drivers/gpu/drm/ast/ast_post.c
> @@ -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;
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
index 225817087b4d..63b7ef02513d 100644
--- a/drivers/gpu/drm/ast/ast_drv.c
+++ b/drivers/gpu/drm/ast/ast_drv.c
@@ -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);
 }
diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index e29db59bb7d8..21ce3769bf0d 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -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);
diff --git a/drivers/gpu/drm/ast/ast_main.c b/drivers/gpu/drm/ast/ast_main.c
index 3aeb0f4b19d5..3d92d9e5208f 100644
--- a/drivers/gpu/drm/ast/ast_main.c
+++ b/drivers/gpu/drm/ast/ast_main.c
@@ -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)
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index f90fade5d681..9d5321c81e68 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -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;
 
diff --git a/drivers/gpu/drm/ast/ast_post.c b/drivers/gpu/drm/ast/ast_post.c
index 324778c72d23..364030f97571 100644
--- a/drivers/gpu/drm/ast/ast_post.c
+++ b/drivers/gpu/drm/ast/ast_post.c
@@ -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;