linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
To: "paul-pl.chen" <paul-pl.chen@mediatek.com>,
	robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org,
	chunkuang.hu@kernel.org
Cc: matthias.bgg@gmail.com, p.zabel@pengutronix.de,
	jason-jh.lin@mediatek.com, nancy.lin@mediatek.com,
	singo.chang@mediatek.com, xiandong.wang@mediatek.com,
	sirius.wang@mediatek.com, sunny.shen@mediatek.com,
	fshao@chromium.org, treapking@chromium.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	Project_Global_Chrome_Upstream_Group@mediatek.com
Subject: Re: [PATCH v2 07/15] soc: mediatek: mutex: refactor SOF settings for output components
Date: Mon, 24 Mar 2025 18:12:56 +0100	[thread overview]
Message-ID: <754df305-9767-47be-8f98-4e287c56808e@collabora.com> (raw)
In-Reply-To: <20250321093435.94835-8-paul-pl.chen@mediatek.com>

Il 21/03/25 10:33, paul-pl.chen ha scritto:
> From: Nancy Lin <nancy.lin@mediatek.com>
> 
> Refactor SOF settings by adding mtk_mutex_get_output_comp_sof()
> and extracting SOF logic from mtk_mutex_add_comp()
> and mtk_mutex_remove_comp().
> 
> - Added mtk_mutex_add_comp_sof() and mtk_mutex_remove_comp_sof()
>    for SOF settings.
> - Reused the switch case for SOF IDs.
> - Separated MOD and SOF logic.
> 

This also needs more than one commit.

The cleanups go in a commit doing only cleanups.

> Signed-off-by: Nancy Lin <nancy.lin@mediatek.com>
> Signed-off-by: Paul-pl Chen <paul-pl.chen@mediatek.com>
> ---
>   drivers/soc/mediatek/mtk-mutex.c       | 121 +++++++++++++++----------
>   include/linux/soc/mediatek/mtk-mutex.h |   4 +
>   2 files changed, 79 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/soc/mediatek/mtk-mutex.c b/drivers/soc/mediatek/mtk-mutex.c
> index aaa965d4b050..c026ac0e6969 100644
> --- a/drivers/soc/mediatek/mtk-mutex.c
> +++ b/drivers/soc/mediatek/mtk-mutex.c
> @@ -853,43 +853,84 @@ void mtk_mutex_unprepare(struct mtk_mutex *mutex)
>   }
>   EXPORT_SYMBOL_GPL(mtk_mutex_unprepare);
>   
> -void mtk_mutex_add_comp(struct mtk_mutex *mutex,
> -			enum mtk_ddp_comp_id id)
> +static int mtk_mutex_get_output_comp_sof(enum mtk_ddp_comp_id id)
>   {
> -	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
> -						 mutex[mutex->id]);
> -	unsigned int reg;
> -	unsigned int sof_id;
> -	unsigned int offset;
> -
> -	WARN_ON(&mtx->mutex[mutex->id] != mutex);
> -
>   	switch (id) {
>   	case DDP_COMPONENT_DSI0:
> -		sof_id = MUTEX_SOF_DSI0;
> -		break;
> +		return MUTEX_SOF_DSI0;
>   	case DDP_COMPONENT_DSI1:
> -		sof_id = MUTEX_SOF_DSI0;
> -		break;
> +		return MUTEX_SOF_DSI1;
>   	case DDP_COMPONENT_DSI2:
> -		sof_id = MUTEX_SOF_DSI2;
> -		break;
> +		return MUTEX_SOF_DSI2;
>   	case DDP_COMPONENT_DSI3:
> -		sof_id = MUTEX_SOF_DSI3;
> -		break;
> +		return MUTEX_SOF_DSI3;
>   	case DDP_COMPONENT_DPI0:
> -		sof_id = MUTEX_SOF_DPI0;
> -		break;
> +		return MUTEX_SOF_DPI0;
>   	case DDP_COMPONENT_DPI1:
> -		sof_id = MUTEX_SOF_DPI1;
> -		break;
> +		return MUTEX_SOF_DPI1;
>   	case DDP_COMPONENT_DP_INTF0:
> -		sof_id = MUTEX_SOF_DP_INTF0;
> -		break;
> +		return MUTEX_SOF_DP_INTF0;
>   	case DDP_COMPONENT_DP_INTF1:
> -		sof_id = MUTEX_SOF_DP_INTF1;
> -		break;
> +		return MUTEX_SOF_DP_INTF1;
>   	default:
> +		break;
> +	}
> +
> +	return -EINVAL;
> +}
> +
> +void mtk_mutex_add_comp_sof(struct mtk_mutex *mutex, enum mtk_ddp_comp_id id)
> +{
> +	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
> +						 mutex[mutex->id]);
> +	int sof_id = mtk_mutex_get_output_comp_sof(id);
> +	unsigned int offset;
> +
> +	if (sof_id < 0 || sof_id >= DDP_MUTEX_SOF_MAX)
> +		return;
> +
> +	WARN_ON(&mtx->mutex[mutex->id] != mutex);
> +
> +	offset = DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg, mutex->id);
> +
> +	writel_relaxed(mtx->data->mutex_sof[sof_id],
> +		       mtx->regs + offset);

fits in one line

> +}
> +EXPORT_SYMBOL_GPL(mtk_mutex_add_comp_sof);
> +
> +void mtk_mutex_remove_comp_sof(struct mtk_mutex *mutex, enum mtk_ddp_comp_id id)
> +{
> +	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
> +						 mutex[mutex->id]);
> +	unsigned int reg;
> +	int sof_id = mtk_mutex_get_output_comp_sof(id);
> +	unsigned int offset;
> +
> +	if (sof_id < 0 || sof_id >= DDP_MUTEX_SOF_MAX)
> +		return;
> +
> +	WARN_ON(&mtx->mutex[mutex->id] != mutex);
> +
> +	offset = DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg, mutex->id);
> +	reg = readl_relaxed(mtx->regs + offset);
> +	reg &= ~(1 << mtx->data->mutex_sof[id]);
> +
> +	writel_relaxed(reg, mtx->regs + offset);
> +}
> +EXPORT_SYMBOL_GPL(mtk_mutex_remove_comp_sof);
> +
> +void mtk_mutex_add_comp(struct mtk_mutex *mutex,
> +			enum mtk_ddp_comp_id id)
> +{
> +	struct mtk_mutex_ctx *mtx = container_of(mutex, struct mtk_mutex_ctx,
> +						 mutex[mutex->id]);
> +	unsigned int reg;
> +	unsigned int offset;
> +	bool is_output_comp = !!mtk_mutex_get_output_comp_sof(id);
> +
> +	WARN_ON(&mtx->mutex[mutex->id] != mutex);
> +

Looks like you can just do

	if (is_output_comp) {
		mtk_mutex_add_comp_sof(mutex, id);
		return;
	}

	if (mtx->data->mutex_mod[id] < 32) { .....etc

> +	if (!is_output_comp) {
>   		if (mtx->data->mutex_mod[id] < 32) {
>   			offset = DISP_REG_MUTEX_MOD(mtx->data->mutex_mod_reg,
>   						    mutex->id);
> @@ -902,12 +943,10 @@ void mtk_mutex_add_comp(struct mtk_mutex *mutex,
>   			reg |= 1 << (mtx->data->mutex_mod[id] - 32);
>   			writel_relaxed(reg, mtx->regs + offset);
>   		}
> -		return;
>   	}
>   
> -	writel_relaxed(mtx->data->mutex_sof[sof_id],
> -		       mtx->regs +
> -		       DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg, mutex->id));
> +	if (is_output_comp)
> +		mtk_mutex_add_comp_sof(mutex, id);
>   }
>   EXPORT_SYMBOL_GPL(mtk_mutex_add_comp);
>   
> @@ -918,24 +957,11 @@ void mtk_mutex_remove_comp(struct mtk_mutex *mutex,
>   						 mutex[mutex->id]);
>   	unsigned int reg;
>   	unsigned int offset;
> +	bool is_output_comp = !!mtk_mutex_get_output_comp_sof(id);
>   
>   	WARN_ON(&mtx->mutex[mutex->id] != mutex);
>   
> -	switch (id) {
> -	case DDP_COMPONENT_DSI0:
> -	case DDP_COMPONENT_DSI1:
> -	case DDP_COMPONENT_DSI2:
> -	case DDP_COMPONENT_DSI3:
> -	case DDP_COMPONENT_DPI0:
> -	case DDP_COMPONENT_DPI1:
> -	case DDP_COMPONENT_DP_INTF0:
> -	case DDP_COMPONENT_DP_INTF1:
> -		writel_relaxed(MUTEX_SOF_SINGLE_MODE,
> -			       mtx->regs +
> -			       DISP_REG_MUTEX_SOF(mtx->data->mutex_sof_reg,
> -						  mutex->id));
> -		break;
> -	default:
> +	if (!is_output_comp) {

same comment as before.

>   		if (mtx->data->mutex_mod[id] < 32) {
>   			offset = DISP_REG_MUTEX_MOD(mtx->data->mutex_mod_reg,
>   						    mutex->id);
> @@ -948,8 +974,11 @@ void mtk_mutex_remove_comp(struct mtk_mutex *mutex,
>   			reg &= ~(1 << (mtx->data->mutex_mod[id] - 32));
>   			writel_relaxed(reg, mtx->regs + offset);
>   		}
> -		break;
>   	}
> +
> +	if (is_output_comp)
> +		mtk_mutex_remove_comp_sof(mutex, id);
> +

Regards,
Angelo




  reply	other threads:[~2025-03-24 17:18 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-21  9:33 [PATCH v2 00/15] Add MediaTek SoC DRM support for MT8196 paul-pl.chen
2025-03-21  9:33 ` [PATCH v2 01/15] dt-bindings: arm: mediatek: mmsys: add compatible " paul-pl.chen
2025-03-24  9:33   ` Krzysztof Kozlowski
2025-03-21  9:33 ` [PATCH v2 02/15] dt-bindings: soc: mediatek: add mutex yaml " paul-pl.chen
2025-03-24  9:34   ` Krzysztof Kozlowski
2025-03-21  9:33 ` [PATCH v2 03/15] dt-bindings: display: mediatek: add EXDMA " paul-pl.chen
2025-03-24  2:45   ` CK Hu (胡俊光)
2025-05-14 16:25     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 04/15] dt-bindings: display: mediatek: add BLENDER " paul-pl.chen
2025-03-24  9:36   ` Krzysztof Kozlowski
2025-03-28  2:27     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 05/15] dt-bindings: display: mediatek: add OUTPROC " paul-pl.chen
2025-03-24 16:02   ` Rob Herring
2025-04-01 15:44     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 06/15] soc: mediatek: add mmsys support " paul-pl.chen
2025-03-24 17:09   ` AngeloGioacchino Del Regno
2025-04-02  4:06     ` Paul-pl Chen (陳柏霖)
2025-04-02  9:33       ` AngeloGioacchino Del Regno
2025-04-11  9:26         ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 07/15] soc: mediatek: mutex: refactor SOF settings for output components paul-pl.chen
2025-03-24 17:12   ` AngeloGioacchino Del Regno [this message]
2025-04-02  3:30     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 08/15] soc: mediatek: mutex: add mutex support for MT8196 paul-pl.chen
2025-03-21  9:33 ` [PATCH v2 09/15] drm/mediatek: Refine OVL format convert API and export to public paul-pl.chen
2025-03-25  2:57   ` CK Hu (胡俊光)
2025-05-13 16:22     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 10/15] drm/mediatek: add EXDMA support for MT8196 paul-pl.chen
2025-03-24  3:00   ` CK Hu (胡俊光)
2025-05-14 10:00     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 11/15] drm/mediatek: add BLENDER " paul-pl.chen
2025-03-24  8:33   ` CK Hu (胡俊光)
2025-05-13 17:12     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 12/15] drm/mediatek: add OUTPROC " paul-pl.chen
2025-03-24  9:00   ` CK Hu (胡俊光)
2025-03-28  2:57     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 13/15] drm/mediatek: add ovlsys_adaptor " paul-pl.chen
2025-04-11  3:07   ` CK Hu (胡俊光)
2025-05-14 16:18     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 14/15] drm/mediatek: Add support for multiple mmsys in the one mediatek-drm driver paul-pl.chen
2025-03-25  3:44   ` CK Hu (胡俊光)
2025-05-13 16:11     ` Paul-pl Chen (陳柏霖)
2025-03-21  9:33 ` [PATCH v2 15/15] drm/mediatek: Add support for MT8196 multiple mmsys paul-pl.chen

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=754df305-9767-47be-8f98-4e287c56808e@collabora.com \
    --to=angelogioacchino.delregno@collabora.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fshao@chromium.org \
    --cc=jason-jh.lin@mediatek.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nancy.lin@mediatek.com \
    --cc=p.zabel@pengutronix.de \
    --cc=paul-pl.chen@mediatek.com \
    --cc=robh@kernel.org \
    --cc=singo.chang@mediatek.com \
    --cc=sirius.wang@mediatek.com \
    --cc=sunny.shen@mediatek.com \
    --cc=treapking@chromium.org \
    --cc=xiandong.wang@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;
as well as URLs for NNTP newsgroup(s).