mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno  <angelogioacchino.delregno@collabora.com>
To: Irui Wang <irui.wang@mediatek.com>,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Yunfei Dong <yunfei.dong@mediatek.com>
Cc: Project_Global_Chrome_Upstream_Group@mediatek.com,
	linux-media@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Maoguang Meng <maoguang.meng@mediatek.com>
Subject: Re: [PATCH] media: mediatek: vcodec: add encoder power management helper functions
Date: Mon, 25 Sep 2023 11:13:43 +0200	[thread overview]
Message-ID: <6df2b962-fa21-d58f-7f39-fe46d049f97e@collabora.com> (raw)
In-Reply-To: <20230925040200.18220-1-irui.wang@mediatek.com>

Il 25/09/23 06:02, Irui Wang ha scritto:
> Remove PM functions at start/stop streaming, add PM helper functions
> to get PM before encoding frame start and put PM after encoding frame
> done. Meanwhile, remove unnecessary clock operations.
> 
> Signed-off-by: Irui Wang <irui.wang@mediatek.com>
> ---
>   .../mediatek/vcodec/encoder/mtk_vcodec_enc.c  | 21 +++----------------
>   .../vcodec/encoder/mtk_vcodec_enc_pm.c        | 18 ++++++++++++++++
>   .../vcodec/encoder/mtk_vcodec_enc_pm.h        |  3 ++-
>   .../mediatek/vcodec/encoder/venc_drv_if.c     |  8 ++-----
>   4 files changed, 25 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> index 04948d3eb011..eb381fa6e7d1 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c
> @@ -866,7 +866,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
>   {
>   	struct mtk_vcodec_enc_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
> @@ -886,18 +886,12 @@ 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_venc_err(ctx, "pm_runtime_resume_and_get fail %d", ret);
> -		goto err_start_stream;
> -	}
> -
>   	mtk_venc_set_param(ctx, &param);
>   	ret = venc_if_set_param(ctx, VENC_SET_PARAM_ENC, &param);
>   	if (ret) {
>   		mtk_v4l2_venc_err(ctx, "venc_if_set_param failed=%d", ret);
>   		ctx->state = MTK_STATE_ABORT;
> -		goto err_set_param;
> +		goto err_start_stream;
>   	}
>   	ctx->param_change = MTK_ENCODE_PARAM_NONE;
>   
> @@ -910,18 +904,13 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count)
>   		if (ret) {
>   			mtk_v4l2_venc_err(ctx, "venc_if_set_param failed=%d", ret);
>   			ctx->state = MTK_STATE_ABORT;
> -			goto err_set_param;
> +			goto err_start_stream;
>   		}
>   		ctx->state = MTK_STATE_HEADER;
>   	}
>   
>   	return 0;
>   
> -err_set_param:
> -	pm_ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> -	if (pm_ret < 0)
> -		mtk_v4l2_venc_err(ctx, "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);
> @@ -1004,10 +993,6 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q)
>   	if (ret)
>   		mtk_v4l2_venc_err(ctx, "venc_if_deinit failed=%d", ret);
>   
> -	ret = pm_runtime_put(&ctx->dev->plat_dev->dev);
> -	if (ret < 0)
> -		mtk_v4l2_venc_err(ctx, "pm_runtime_put fail %d", ret);
> -
>   	ctx->state = MTK_STATE_FREE;
>   }
>   
> diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
> index 3fce936e61b9..a22b7dfc656e 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.c
> @@ -58,6 +58,24 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *mtkdev)
>   	return 0;
>   }
>   
> +void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm)
> +{
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(pm->dev);
> +	if (ret)
> +		dev_err(pm->dev, "pm_runtime_resume_and_get fail: %d", ret);
> +}

Those are exactly the same functions as the DECODER counterpart... instead
of duplicating them, can you please simply commonize the functions in
mtk_vcodec_dec_pm.c ?

Regards,
Angelo

> +
> +void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm)
> +{
> +	int ret;
> +
> +	ret = pm_runtime_put(pm->dev);
> +	if (ret && ret != -EAGAIN)
> +		dev_err(pm->dev, "pm_runtime_put fail %d", ret);
> +}
> +
>   void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm)
>   {
>   	struct mtk_vcodec_clk *enc_clk = &pm->venc_clk;
> diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
> index e50be0575190..157ea08ba9e3 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_pm.h
> @@ -10,7 +10,8 @@
>   #include "mtk_vcodec_enc_drv.h"
>   
>   int mtk_vcodec_init_enc_clk(struct mtk_vcodec_enc_dev *dev);
> -
> +void mtk_vcodec_enc_pw_on(struct mtk_vcodec_pm *pm);
> +void mtk_vcodec_enc_pw_off(struct mtk_vcodec_pm *pm);
>   void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm);
>   void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm);
>   
> diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
> index 1bdaecdd64a7..c402a686f3cb 100644
> --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
> +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c
> @@ -32,9 +32,7 @@ int venc_if_init(struct mtk_vcodec_enc_ctx *ctx, unsigned int fourcc)
>   	}
>   
>   	mtk_venc_lock(ctx);
> -	mtk_vcodec_enc_clock_on(&ctx->dev->pm);
>   	ret = ctx->enc_if->init(ctx);
> -	mtk_vcodec_enc_clock_off(&ctx->dev->pm);
>   	mtk_venc_unlock(ctx);
>   
>   	return ret;
> @@ -46,9 +44,7 @@ int venc_if_set_param(struct mtk_vcodec_enc_ctx *ctx,
>   	int ret = 0;
>   
>   	mtk_venc_lock(ctx);
> -	mtk_vcodec_enc_clock_on(&ctx->dev->pm);
>   	ret = ctx->enc_if->set_param(ctx->drv_handle, type, in);
> -	mtk_vcodec_enc_clock_off(&ctx->dev->pm);
>   	mtk_venc_unlock(ctx);
>   
>   	return ret;
> @@ -68,10 +64,12 @@ int venc_if_encode(struct mtk_vcodec_enc_ctx *ctx,
>   	ctx->dev->curr_ctx = ctx;
>   	spin_unlock_irqrestore(&ctx->dev->irqlock, flags);
>   
> +	mtk_vcodec_enc_pw_on(&ctx->dev->pm);
>   	mtk_vcodec_enc_clock_on(&ctx->dev->pm);
>   	ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf,
>   				  bs_buf, result);
>   	mtk_vcodec_enc_clock_off(&ctx->dev->pm);
> +	mtk_vcodec_enc_pw_off(&ctx->dev->pm);
>   
>   	spin_lock_irqsave(&ctx->dev->irqlock, flags);
>   	ctx->dev->curr_ctx = NULL;
> @@ -89,9 +87,7 @@ int venc_if_deinit(struct mtk_vcodec_enc_ctx *ctx)
>   		return 0;
>   
>   	mtk_venc_lock(ctx);
> -	mtk_vcodec_enc_clock_on(&ctx->dev->pm);
>   	ret = ctx->enc_if->deinit(ctx->drv_handle);
> -	mtk_vcodec_enc_clock_off(&ctx->dev->pm);
>   	mtk_venc_unlock(ctx);
>   
>   	ctx->drv_handle = NULL;


  reply	other threads:[~2023-09-25  9:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-25  4:02 Irui Wang
2023-09-25  9:13 ` AngeloGioacchino Del Regno [this message]
2023-09-27  1:51   ` Irui Wang (王瑞)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6df2b962-fa21-d58f-7f39-fe46d049f97e@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=irui.wang@mediatek.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maoguang.meng@mediatek.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=yunfei.dong@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®