[PATCH v3, 06/10] media: mtk-vcodec: Add venc power on/off interface
Irui Wang
irui.wang at mediatek.com
Thu Mar 17 01:22:26 PDT 2022
venc_multi_core mode power on/off all venc available power, pm_runtime_xx
helper is not appropriate called directly, add new power on/off
interface for it.
Signed-off-by: Irui Wang <irui.wang at mediatek.com>
---
.../platform/mtk-vcodec/mtk_vcodec_enc.c | 20 +----
.../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 7 ++
.../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 83 +++++++++++++++++++
.../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 5 ++
4 files changed, 98 insertions(+), 17 deletions(-)
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
index 0d1b065048a9..b0bc71f00930 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c
@@ -12,6 +12,7 @@
#include "mtk_vcodec_drv.h"
#include "mtk_vcodec_enc.h"
+#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_intr.h"
#include "mtk_vcodec_util.h"
#include "venc_drv_if.h"
@@ -849,7 +850,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
{
struct mtk_vcodec_ctx *ctx = vb2_get_drv_priv(q);
struct venc_enc_param param;
- int ret, pm_ret;
+ int ret;
int i;
/* Once state turn into MTK_STATE_ABORT, we need stop_streaming
@@ -857,7 +858,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
*/
if ((ctx->state == MTK_STATE_ABORT) || (ctx->state == MTK_STATE_FREE)) {
ret = -EIO;
- goto err_start_stream;
+ goto err_set_param;
}
/* Do the initialization when both start_streaming have been called */
@@ -869,12 +870,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
return 0;
}
- ret = pm_runtime_resume_and_get(&ctx->dev->plat_dev->dev);
- if (ret < 0) {
- mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
- goto err_start_stream;
- }
-
mtk_venc_set_param(ctx, ¶m);
ret = venc_if_set_param(ctx, VENC_SET_PARAM_ENC, ¶m);
if (ret) {
@@ -901,11 +896,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
return 0;
err_set_param:
- pm_ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
- if (pm_ret < 0)
- mtk_v4l2_err("pm_runtime_put fail %d", pm_ret);
-
-err_start_stream:
for (i = 0; i < q->num_buffers; ++i) {
struct vb2_buffer *buf = vb2_get_buffer(q, i);
@@ -988,10 +978,6 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
if (ret)
mtk_v4l2_err("venc_if_deinit failed=%d", ret);
- ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
- if (ret < 0)
- mtk_v4l2_err("pm_runtime_put fail %d", ret);
-
ctx->state = MTK_STATE_FREE;
}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
index 1b1c17b03ef5..d2937e62df29 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c
@@ -173,6 +173,12 @@ static int fops_vcodec_open(struct file *file)
mtk_v4l2_debug(0, "encoder capability %x", dev->enc_capability);
}
+ ret = mtk_vcodec_enc_pw_on(dev);
+ if (ret < 0) {
+ mtk_v4l2_err("encoder power on failed %d", ret);
+ goto err_load_fw;
+ }
+
mtk_v4l2_debug(2, "Create instance [%d]@%p m2m_ctx=%p ",
ctx->id, ctx, ctx->m2m_ctx);
@@ -207,6 +213,7 @@ static int fops_vcodec_release(struct file *file)
v4l2_m2m_ctx_release(ctx->m2m_ctx);
mtk_vcodec_enc_release(ctx);
+ mtk_vcodec_enc_pw_off(dev);
v4l2_fh_del(&ctx->fh);
v4l2_fh_exit(&ctx->fh);
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
index 1e814fc3172f..22b2eb867998 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c
@@ -9,6 +9,7 @@
#include <linux/of_platform.h>
#include <linux/pm_runtime.h>
+#include "mtk_vcodec_enc_core.h"
#include "mtk_vcodec_enc_pm.h"
#include "mtk_vcodec_util.h"
@@ -87,3 +88,85 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm)
clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk);
}
EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_off);
+
+int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev)
+{
+ int i, ret;
+ struct mtk_venc_core_dev *core;
+
+ /* power on all available venc cores */
+ for (i = 0; i < MTK_VENC_CORE_MAX; i++) {
+ core = (struct mtk_venc_core_dev *)dev->enc_core_dev[i];
+ if (!core)
+ return 0;
+
+ ret = pm_runtime_resume_and_get(&core->plat_dev->dev);
+ if (ret < 0) {
+ mtk_v4l2_err("power on core[%d] fail %d", i, ret);
+ goto pw_on_fail;
+ }
+ }
+ return 0;
+
+pw_on_fail:
+ for (i -= 1; i >= 0; i--) {
+ core = (struct mtk_venc_core_dev *)dev->enc_core_dev[i];
+ pm_runtime_put_sync(&core->plat_dev->dev);
+ }
+ return ret;
+}
+
+int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev)
+{
+ int i, ret;
+ struct mtk_venc_core_dev *core;
+
+ /* power off all available venc cores */
+ for (i = 0; i < MTK_VENC_CORE_MAX; i++) {
+ core = (struct mtk_venc_core_dev *)dev->enc_core_dev[i];
+ if (!core)
+ return 0;
+
+ ret = pm_runtime_put_sync(&core->plat_dev->dev);
+ if (ret < 0)
+ mtk_v4l2_err("power off core[%d] fail %d", i, ret);
+ }
+ return ret;
+}
+
+int mtk_vcodec_enc_pw_on(struct mtk_vcodec_dev *dev)
+{
+ int ret;
+
+ if (dev->venc_multi_core) {
+ ret = mtk_venc_core_pw_on(dev);
+ if (ret < 0) {
+ mtk_v4l2_err("venc core power on fail: %d", ret);
+ return ret;
+ }
+ } else {
+ ret = pm_runtime_resume_and_get(&dev->plat_dev->dev);
+ if (ret < 0) {
+ mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
+ return ret;
+ }
+ }
+ return 0;
+}
+
+int mtk_vcodec_enc_pw_off(struct mtk_vcodec_dev *dev)
+{
+ int ret;
+
+ if (dev->venc_multi_core) {
+ ret = mtk_venc_core_pw_off(dev);
+ if (ret < 0)
+ mtk_v4l2_err("venc core power off fail: %d", ret);
+
+ } else {
+ ret = pm_runtime_put_sync(&dev->plat_dev->dev);
+ if (ret < 0)
+ mtk_v4l2_err("pm_runtime_put_sync fail %d", ret);
+ }
+ return ret;
+}
diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
index 97a394c68f4e..99b6b6e29e35 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h
@@ -14,4 +14,9 @@ int mtk_vcodec_init_enc_clk(struct platform_device *pdev,
void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
+int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev);
+int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev);
+int mtk_vcodec_enc_pw_on(struct mtk_vcodec_dev *dev);
+int mtk_vcodec_enc_pw_off(struct mtk_vcodec_dev *dev);
+
#endif /* _MTK_VCODEC_ENC_PM_H_ */
--
2.18.0
More information about the Linux-mediatek
mailing list