diff mbox series

[3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper

Message ID 20240201125304.218467-4-angelogioacchino.delregno@collabora.com (mailing list archive)
State New, archived
Headers show
Series drm/mediatek: Fixes for DDP component search/destroy | expand

Commit Message

AngeloGioacchino Del Regno Feb. 1, 2024, 12:53 p.m. UTC
Move the simple component check to a new mtk_ddp_is_simple_comp()
internal helper to reduce code duplication.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 57 +++++++++++----------
 1 file changed, 31 insertions(+), 26 deletions(-)

Comments

CK Hu (胡俊光) March 22, 2024, 8:57 a.m. UTC | #1
Hi, Angelo:

On Thu, 2024-02-01 at 13:53 +0100, AngeloGioacchino Del Regno wrote:
> Move the simple component check to a new mtk_ddp_is_simple_comp()
> internal helper to reduce code duplication.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Signed-off-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 57 +++++++++++------
> ----
>  1 file changed, 31 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 539b526a6b0a..4ca2a02ada3c 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -575,6 +575,29 @@ unsigned int
> mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
>  	return ret;
>  }
>  
> +static bool mtk_ddp_is_simple_comp(enum mtk_ddp_comp_type type)
> +{
> +	switch (type) {
> +	case MTK_DISP_AAL:
> +	case MTK_DISP_BLS:
> +	case MTK_DISP_CCORR:
> +	case MTK_DISP_COLOR:
> +	case MTK_DISP_GAMMA:
> +	case MTK_DISP_MERGE:
> +	case MTK_DISP_OVL:
> +	case MTK_DISP_OVL_2L:
> +	case MTK_DISP_OVL_ADAPTOR:
> +	case MTK_DISP_PWM:
> +	case MTK_DISP_RDMA:
> +	case MTK_DP_INTF:
> +	case MTK_DPI:
> +	case MTK_DSI:
> +		return false;
> +	default:
> +		return true;
> +	}
> +}
> +
>  int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp
> *comp,
>  		      unsigned int comp_id)
>  {
> @@ -605,19 +628,13 @@ int mtk_ddp_comp_init(struct device_node *node,
> struct mtk_ddp_comp *comp,
>  	}
>  	comp->dev = &comp_pdev->dev;
>  
> -	if (type == MTK_DISP_AAL ||
> -	    type == MTK_DISP_BLS ||
> -	    type == MTK_DISP_CCORR ||
> -	    type == MTK_DISP_COLOR ||
> -	    type == MTK_DISP_GAMMA ||
> -	    type == MTK_DISP_MERGE ||
> -	    type == MTK_DISP_OVL ||
> -	    type == MTK_DISP_OVL_2L ||
> -	    type == MTK_DISP_PWM ||
> -	    type == MTK_DISP_RDMA ||
> -	    type == MTK_DPI ||
> -	    type == MTK_DP_INTF ||
> -	    type == MTK_DSI)
> +	/*
> +	 * Resources for simple components are retrieved here as those
> are
> +	 * managed in here without the need of more complex drivers;
> for
> +	 * the latter, their respective probe function will do the job,
> so
> +	 * we must avoid getting their resources here.
> +	 */
> +	if (!mtk_ddp_is_simple_comp(type))
>  		return 0;
>  
>  	priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
> @@ -651,19 +668,7 @@ void mtk_ddp_comp_destroy(struct mtk_ddp_comp
> *comp)
>  		return;
>  
>  	/* Complex components are destroyed with their own remove
> callback */
> -	if (type == MTK_DISP_AAL ||
> -	    type == MTK_DISP_BLS ||
> -	    type == MTK_DISP_CCORR ||
> -	    type == MTK_DISP_COLOR ||
> -	    type == MTK_DISP_GAMMA ||
> -	    type == MTK_DISP_MERGE ||
> -	    type == MTK_DISP_OVL ||
> -	    type == MTK_DISP_OVL_2L ||
> -	    type == MTK_DISP_PWM ||
> -	    type == MTK_DISP_RDMA ||
> -	    type == MTK_DPI ||
> -	    type == MTK_DP_INTF ||
> -	    type == MTK_DSI)
> +	if (!mtk_ddp_is_simple_comp(mtk_ddp_matches[comp->id].type))
>  		return;
>  
>  	priv = dev_get_drvdata(comp->dev);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 539b526a6b0a..4ca2a02ada3c 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -575,6 +575,29 @@  unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 	return ret;
 }
 
+static bool mtk_ddp_is_simple_comp(enum mtk_ddp_comp_type type)
+{
+	switch (type) {
+	case MTK_DISP_AAL:
+	case MTK_DISP_BLS:
+	case MTK_DISP_CCORR:
+	case MTK_DISP_COLOR:
+	case MTK_DISP_GAMMA:
+	case MTK_DISP_MERGE:
+	case MTK_DISP_OVL:
+	case MTK_DISP_OVL_2L:
+	case MTK_DISP_OVL_ADAPTOR:
+	case MTK_DISP_PWM:
+	case MTK_DISP_RDMA:
+	case MTK_DP_INTF:
+	case MTK_DPI:
+	case MTK_DSI:
+		return false;
+	default:
+		return true;
+	}
+}
+
 int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 		      unsigned int comp_id)
 {
@@ -605,19 +628,13 @@  int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 	}
 	comp->dev = &comp_pdev->dev;
 
-	if (type == MTK_DISP_AAL ||
-	    type == MTK_DISP_BLS ||
-	    type == MTK_DISP_CCORR ||
-	    type == MTK_DISP_COLOR ||
-	    type == MTK_DISP_GAMMA ||
-	    type == MTK_DISP_MERGE ||
-	    type == MTK_DISP_OVL ||
-	    type == MTK_DISP_OVL_2L ||
-	    type == MTK_DISP_PWM ||
-	    type == MTK_DISP_RDMA ||
-	    type == MTK_DPI ||
-	    type == MTK_DP_INTF ||
-	    type == MTK_DSI)
+	/*
+	 * Resources for simple components are retrieved here as those are
+	 * managed in here without the need of more complex drivers; for
+	 * the latter, their respective probe function will do the job, so
+	 * we must avoid getting their resources here.
+	 */
+	if (!mtk_ddp_is_simple_comp(type))
 		return 0;
 
 	priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
@@ -651,19 +668,7 @@  void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp)
 		return;
 
 	/* Complex components are destroyed with their own remove callback */
-	if (type == MTK_DISP_AAL ||
-	    type == MTK_DISP_BLS ||
-	    type == MTK_DISP_CCORR ||
-	    type == MTK_DISP_COLOR ||
-	    type == MTK_DISP_GAMMA ||
-	    type == MTK_DISP_MERGE ||
-	    type == MTK_DISP_OVL ||
-	    type == MTK_DISP_OVL_2L ||
-	    type == MTK_DISP_PWM ||
-	    type == MTK_DISP_RDMA ||
-	    type == MTK_DPI ||
-	    type == MTK_DP_INTF ||
-	    type == MTK_DSI)
+	if (!mtk_ddp_is_simple_comp(mtk_ddp_matches[comp->id].type))
 		return;
 
 	priv = dev_get_drvdata(comp->dev);