Prepare for smi cleaning up "mediatek,larb".
Display use the dispsys device to call pm_rumtime_get_sync before.
This patch add pm_runtime_xx with ovl and rdma device whose nodes has
"iommus" property, then display could help pm_runtime_get for smi via
ovl or rdma device.
(Yong: Use pm_runtime_resume_and_get instead of pm_runtime_get_sync)
CC: CK Hu <ck.hu@mediatek.com>
Signed-off-by: Yongqiang Niu <yongqiang.niu@mediatek.com>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
Acked-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Tested-by: Frank Wunderlich <frank-w@public-files.de> # BPI-R2/MT7623
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/soc/mediatek/mtk-cmdq.h>
 
 #include "mtk_disp_drv.h"
                return ret;
        }
 
+       pm_runtime_enable(dev);
+
        ret = component_add(dev, &mtk_disp_ovl_component_ops);
-       if (ret)
+       if (ret) {
+               pm_runtime_disable(dev);
                dev_err(dev, "Failed to add component: %d\n", ret);
+       }
 
        return ret;
 }
 static int mtk_disp_ovl_remove(struct platform_device *pdev)
 {
        component_del(&pdev->dev, &mtk_disp_ovl_component_ops);
+       pm_runtime_disable(&pdev->dev);
 
        return 0;
 }
 
 #include <linux/of_device.h>
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/soc/mediatek/mtk-cmdq.h>
 
 #include "mtk_disp_drv.h"
 
        platform_set_drvdata(pdev, priv);
 
+       pm_runtime_enable(dev);
+
        ret = component_add(dev, &mtk_disp_rdma_component_ops);
-       if (ret)
+       if (ret) {
+               pm_runtime_disable(dev);
                dev_err(dev, "Failed to add component: %d\n", ret);
+       }
 
        return ret;
 }
 {
        component_del(&pdev->dev, &mtk_disp_rdma_component_ops);
 
+       pm_runtime_disable(&pdev->dev);
+
        return 0;
 }
 
 
                return;
        }
 
+       ret = pm_runtime_resume_and_get(comp->dev);
+       if (ret < 0) {
+               mtk_smi_larb_put(comp->larb_dev);
+               DRM_DEV_ERROR(comp->dev, "Failed to enable power domain: %d\n", ret);
+               return;
+       }
+
        ret = mtk_crtc_ddp_hw_init(mtk_crtc);
        if (ret) {
                mtk_smi_larb_put(comp->larb_dev);
+               pm_runtime_put(comp->dev);
                return;
        }
 
 {
        struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
        struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
-       int i;
+       int i, ret;
 
        DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
        if (!mtk_crtc->enabled)
        drm_crtc_vblank_off(crtc);
        mtk_crtc_ddp_hw_fini(mtk_crtc);
        mtk_smi_larb_put(comp->larb_dev);
+       ret = pm_runtime_put(comp->dev);
+       if (ret < 0)
+               DRM_DEV_ERROR(comp->dev, "Failed to disable power domain: %d\n", ret);
 
        mtk_crtc->enabled = false;
 }