drm/mediatek: Start/Stop components with function pointers
authorHsiao Chien Sung <shawn.sung@mediatek.com>
Thu, 14 Dec 2023 05:58:39 +0000 (13:58 +0800)
committerChun-Kuang Hu <chunkuang.hu@kernel.org>
Thu, 14 Dec 2023 14:36:17 +0000 (14:36 +0000)
By registering component related functions to the pointers,
we can easily manage them within a for-loop and simplify the
logic of component start/stop process.

Reviewed-by: CK Hu <ck.hu@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hsiao Chien Sung <shawn.sung@mediatek.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20231214055847.4936-16-shawn.sung@mediatek.com/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c

index e00d8a395ca0aab65ead2de9d9b7c2a016aa1efb..65c5153bdcd807d70f9781b3bbb603f855e91208 100644 (file)
@@ -72,6 +72,8 @@ static const char * const private_comp_stem[OVL_ADAPTOR_TYPE_NUM] = {
 static const struct mtk_ddp_comp_funcs ethdr = {
        .clk_enable = mtk_ethdr_clk_enable,
        .clk_disable = mtk_ethdr_clk_disable,
+       .start = mtk_ethdr_start,
+       .stop = mtk_ethdr_stop,
 };
 
 static const struct mtk_ddp_comp_funcs merge = {
@@ -191,16 +193,30 @@ void mtk_ovl_adaptor_config(struct device *dev, unsigned int w,
 
 void mtk_ovl_adaptor_start(struct device *dev)
 {
+       int i;
        struct mtk_disp_ovl_adaptor *ovl_adaptor = dev_get_drvdata(dev);
 
-       mtk_ethdr_start(ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0]);
+       for (i = 0; i < OVL_ADAPTOR_ID_MAX; i++) {
+               if (!ovl_adaptor->ovl_adaptor_comp[i] ||
+                   !comp_matches[i].funcs->start)
+                       continue;
+
+               comp_matches[i].funcs->start(ovl_adaptor->ovl_adaptor_comp[i]);
+       }
 }
 
 void mtk_ovl_adaptor_stop(struct device *dev)
 {
+       int i;
        struct mtk_disp_ovl_adaptor *ovl_adaptor = dev_get_drvdata(dev);
 
-       mtk_ethdr_stop(ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0]);
+       for (i = 0; i < OVL_ADAPTOR_ID_MAX; i++) {
+               if (!ovl_adaptor->ovl_adaptor_comp[i] ||
+                   !comp_matches[i].funcs->stop)
+                       continue;
+
+               comp_matches[i].funcs->stop(ovl_adaptor->ovl_adaptor_comp[i]);
+       }
 }
 
 /**