devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: "Shawn Sung (宋孝謙)" <Shawn.Sung@mediatek.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"angelogioacchino.delregno@collabora.com"
	<angelogioacchino.delregno@collabora.com>,
	"robh+dt@kernel.org" <robh+dt@kernel.org>,
	"krzysztof.kozlowski+dt@linaro.org"
	<krzysztof.kozlowski+dt@linaro.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>,
	"Jason-JH Lin (林睿祥)" <Jason-JH.Lin@mediatek.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"Nancy Lin (林欣螢)" <Nancy.Lin@mediatek.com>,
	"Moudy Ho (何宗原)" <Moudy.Ho@mediatek.com>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Nathan Lu (呂東霖)" <Nathan.Lu@mediatek.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"sean@poorly.run" <sean@poorly.run>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"fshao@chromium.org" <fshao@chromium.org>,
	"johnson.wang@mediatek.corp-partner.google.com"
	<johnson.wang@mediatek.corp-partner.google.com>
Subject: Re: [PATCH v10 14/24] drm/mediatek: Power on/off devices with function pointers
Date: Tue, 24 Oct 2023 08:12:40 +0000	[thread overview]
Message-ID: <d01f4e1753d3880b8c096c2f69adf19c1f136c8b.camel@mediatek.com> (raw)
In-Reply-To: <20231019055619.19358-15-shawn.sung@mediatek.com>

Hi, Hsiao-chien:

On Thu, 2023-10-19 at 13:56 +0800, Hsiao Chien Sung wrote:
> Different from OVL, OVL adaptor is a pseudo device so we didn't
> define it in the device tree, consequently,
> pm_runtime_resume_and_get()
> called by .atomic_enable() powers on no device. For this reason, we
> implement a function to power on the RDMAs in OVL adaptor, and the
> system will make sure the IOMMUs are powered on as well because of
> the
> device link (iommus) in the RDMA nodes in DTS.
> 
> This patch separates power and clock management process, it would be
> easier to maintain and extensions.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Signed-off-by: Hsiao Chien Sung <shawn.sung@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_drv.h       |  4 +
>  .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c   | 75 +++++++++++++++
> ----
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c       | 10 +--
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c   |  2 +
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h   | 20 +++++
>  drivers/gpu/drm/mediatek/mtk_mdp_rdma.c       | 16 ++++
>  6 files changed, 107 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> index bf06ccb65652..8465beeab435 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_drv.h
> @@ -109,6 +109,8 @@ void mtk_ovl_adaptor_connect(struct device *dev,
> struct device *mmsys_dev,
>  			     unsigned int next);
>  void mtk_ovl_adaptor_disconnect(struct device *dev, struct device
> *mmsys_dev,
>  				unsigned int next);
> +int mtk_ovl_adaptor_power_on(struct device *dev);
> +void mtk_ovl_adaptor_power_off(struct device *dev);
>  int mtk_ovl_adaptor_clk_enable(struct device *dev);
>  void mtk_ovl_adaptor_clk_disable(struct device *dev);
>  void mtk_ovl_adaptor_config(struct device *dev, unsigned int w,
> @@ -150,6 +152,8 @@ void mtk_rdma_disable_vblank(struct device *dev);
>  const u32 *mtk_rdma_get_formats(struct device *dev);
>  size_t mtk_rdma_get_num_formats(struct device *dev);
>  
> +int mtk_mdp_rdma_power_on(struct device *dev);
> +void mtk_mdp_rdma_power_off(struct device *dev);
>  int mtk_mdp_rdma_clk_enable(struct device *dev);
>  void mtk_mdp_rdma_clk_disable(struct device *dev);
>  void mtk_mdp_rdma_start(struct device *dev, struct cmdq_pkt
> *cmdq_pkt);
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
> b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
> index 81067f49ea69..aab98adcd9a4 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
> @@ -79,6 +79,8 @@ static const struct mtk_ddp_comp_funcs merge = {
>  };
>  
>  static const struct mtk_ddp_comp_funcs rdma = {
> +	.power_on = mtk_mdp_rdma_power_on,
> +	.power_off = mtk_mdp_rdma_power_off,
>  	.clk_enable = mtk_mdp_rdma_clk_enable,
>  	.clk_disable = mtk_mdp_rdma_clk_disable,
>  };
> @@ -200,21 +202,72 @@ void mtk_ovl_adaptor_stop(struct device *dev)
>  	mtk_ethdr_stop(ovl_adaptor-
> >ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0]);
>  }
>  
> -int mtk_ovl_adaptor_clk_enable(struct device *dev)
> +/**
> + * power_off - Power off the devices in OVL adaptor
> + * @dev: Device to be powered off
> + * @num: Number of the devices to be powered off
> + *
> + * Calls the .power_off() ovl_adaptor component callback if it is
> present.
> + */
> +static inline void power_off(struct device *dev, unsigned int num)
>  {
>  	struct mtk_disp_ovl_adaptor *ovl_adaptor =
> dev_get_drvdata(dev);
> -	struct device *comp;
> -	int ret;
>  	int i;
>  
> -	for (i = 0; i < OVL_ADAPTOR_MERGE0; i++) {
> -		comp = ovl_adaptor->ovl_adaptor_comp[i];
> -		ret = pm_runtime_get_sync(comp);
> +	if (num > OVL_ADAPTOR_ID_MAX)
> +		num = OVL_ADAPTOR_ID_MAX;
> +
> +	for (i = num - 1; i >= 0; i--) {
> +		if (!ovl_adaptor->ovl_adaptor_comp[i] ||
> +		    !comp_matches[i].funcs->power_off)
> +			continue;
> +
> +		comp_matches[i].funcs->power_off(ovl_adaptor-
> >ovl_adaptor_comp[i]);
> +	}
> +}
> +
> +/**
> + * mtk_ovl_adaptor_power_on - Power on the devices in OVL adaptor
> + * @dev: Device to be powered on
> + *
> + * Different from OVL, OVL adaptor is a pseudo device so
> + * we didn't define it in the device tree,
> pm_runtime_resume_and_get()
> + * called by .atomic_enable() power on no device in OVL adaptor,
> + * we have to implement a function to do the job instead.
> + *
> + * Return: Zero for success or negative number for failure.
> + */
> +int mtk_ovl_adaptor_power_on(struct device *dev)
> +{
> +	struct mtk_disp_ovl_adaptor *ovl_adaptor =
> dev_get_drvdata(dev);
> +	int i, ret;
> +
> +	for (i = 0; i < OVL_ADAPTOR_ID_MAX; i++) {
> +		if (!ovl_adaptor->ovl_adaptor_comp[i] ||
> +		    !comp_matches[i].funcs->power_on)
> +			continue;
> +
> +		ret = comp_matches[i].funcs->power_on(ovl_adaptor-
> >ovl_adaptor_comp[i]);
>  		if (ret < 0) {
>  			dev_err(dev, "Failed to enable power domain %d,
> err %d\n", i, ret);
> -			goto error;
> +			power_off(dev, i);
> +			return ret;
>  		}
>  	}
> +	return 0;
> +}
> +
> +void mtk_ovl_adaptor_power_off(struct device *dev)
> +{
> +	power_off(dev, OVL_ADAPTOR_ID_MAX);
> +}
> +
> +int mtk_ovl_adaptor_clk_enable(struct device *dev)
> +{
> +	struct mtk_disp_ovl_adaptor *ovl_adaptor =
> dev_get_drvdata(dev);
> +	struct device *comp;
> +	int ret;
> +	int i;
>  
>  	for (i = 0; i < OVL_ADAPTOR_ID_MAX; i++) {
>  		comp = ovl_adaptor->ovl_adaptor_comp[i];
> @@ -225,16 +278,10 @@ int mtk_ovl_adaptor_clk_enable(struct device
> *dev)
>  			dev_err(dev, "Failed to enable clock %d, err
> %d\n", i, ret);
>  			while (--i >= 0)
>  				comp_matches[i].funcs-
> >clk_disable(comp);
> -			i = OVL_ADAPTOR_MERGE0;
> -			goto error;
> +			return ret;
>  		}
>  	}
>  	return 0;
> -error:
> -	while (--i >= 0)
> -		pm_runtime_put(ovl_adaptor->ovl_adaptor_comp[i]);
> -
> -	return ret;
>  }
>  
>  void mtk_ovl_adaptor_clk_disable(struct device *dev)
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index a0b2ba3cbcdb..bc4cc75cca18 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -774,7 +774,7 @@ static void mtk_drm_crtc_atomic_enable(struct
> drm_crtc *crtc,
>  		return;
>  	}
>  
> -	ret = pm_runtime_resume_and_get(comp->dev);
> +	ret = mtk_ddp_comp_power_on(comp);
>  	if (ret < 0) {
>  		DRM_DEV_ERROR(comp->dev, "Failed to enable power
> domain: %d\n", ret);
>  		return;
> @@ -782,7 +782,7 @@ static void mtk_drm_crtc_atomic_enable(struct
> drm_crtc *crtc,
>  
>  	ret = mtk_crtc_ddp_hw_init(mtk_crtc, state);
>  	if (ret) {
> -		pm_runtime_put(comp->dev);
> +		mtk_ddp_comp_power_off(comp);
>  		return;
>  	}
>  
> @@ -795,7 +795,7 @@ static void mtk_drm_crtc_atomic_disable(struct
> drm_crtc *crtc,
>  {
>  	struct mtk_drm_crtc *mtk_crtc = to_mtk_crtc(crtc);
>  	struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[0];
> -	int i, ret;
> +	int i;
>  
>  	DRM_DEBUG_DRIVER("%s %d\n", __func__, crtc->base.id);
>  	if (!mtk_crtc->enabled)
> @@ -825,9 +825,7 @@ static void mtk_drm_crtc_atomic_disable(struct
> drm_crtc *crtc,
>  
>  	drm_crtc_vblank_off(crtc);
>  	mtk_crtc_ddp_hw_fini(mtk_crtc);
> -	ret = pm_runtime_put(comp->dev);
> -	if (ret < 0)
> -		DRM_DEV_ERROR(comp->dev, "Failed to disable power
> domain: %d\n", ret);
> +	mtk_ddp_comp_power_off(comp);
>  
>  	mtk_crtc->enabled = false;
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 10402e07a4a7..9940909c7435 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -396,6 +396,8 @@ static const struct mtk_ddp_comp_funcs ddp_ufoe =
> {
>  };
>  
>  static const struct mtk_ddp_comp_funcs ddp_ovl_adaptor = {
> +	.power_on = mtk_ovl_adaptor_power_on,
> +	.power_off = mtk_ovl_adaptor_power_off,
>  	.clk_enable = mtk_ovl_adaptor_clk_enable,
>  	.clk_disable = mtk_ovl_adaptor_clk_disable,
>  	.config = mtk_ovl_adaptor_config,
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> index 1c1d670cfe41..2597dd7ac0d2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> @@ -7,6 +7,7 @@
>  #define MTK_DRM_DDP_COMP_H
>  
>  #include <linux/io.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/soc/mediatek/mtk-cmdq.h>
>  #include <linux/soc/mediatek/mtk-mmsys.h>
>  #include <linux/soc/mediatek/mtk-mutex.h>
> @@ -46,6 +47,8 @@ enum mtk_ddp_comp_type {
>  struct mtk_ddp_comp;
>  struct cmdq_pkt;
>  struct mtk_ddp_comp_funcs {
> +	int (*power_on)(struct device *dev);
> +	void (*power_off)(struct device *dev);
>  	int (*clk_enable)(struct device *dev);
>  	void (*clk_disable)(struct device *dev);
>  	void (*config)(struct device *dev, unsigned int w,
> @@ -91,6 +94,23 @@ struct mtk_ddp_comp {
>  	int encoder_index;
>  };
>  
> +static inline int mtk_ddp_comp_power_on(struct mtk_ddp_comp *comp)
> +{
> +	if (comp->funcs && comp->funcs->power_on)
> +		return comp->funcs->power_on(comp->dev);
> +	else
> +		return pm_runtime_resume_and_get(comp->dev);
> +	return 0;
> +}
> +
> +static inline void mtk_ddp_comp_power_off(struct mtk_ddp_comp *comp)
> +{
> +	if (comp->funcs && comp->funcs->power_off)
> +		comp->funcs->power_off(comp->dev);
> +	else
> +		pm_runtime_put(comp->dev);
> +}
> +
>  static inline int mtk_ddp_comp_clk_enable(struct mtk_ddp_comp *comp)
>  {
>  	if (comp->funcs && comp->funcs->clk_enable)
> diff --git a/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c
> b/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c
> index 5746f06220c1..769ae7564da2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_mdp_rdma.c
> @@ -243,6 +243,22 @@ size_t mtk_mdp_rdma_get_num_formats(struct
> device *dev)
>  	return ARRAY_SIZE(formats);
>  }
>  
> +int mtk_mdp_rdma_power_on(struct device *dev)
> +{
> +	int ret = pm_runtime_resume_and_get(dev);
> +
> +	if (ret < 0) {
> +		dev_err(dev, "Failed to power on: %d\n", ret);
> +		return ret;
> +	}
> +	return 0;
> +}
> +
> +void mtk_mdp_rdma_power_off(struct device *dev)
> +{
> +	pm_runtime_put(dev);
> +}
> +
>  int mtk_mdp_rdma_clk_enable(struct device *dev)
>  {
>  	struct mtk_mdp_rdma *rdma = dev_get_drvdata(dev);

  parent reply	other threads:[~2023-10-24  8:12 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19  5:55 [PATCH v10 00/24] Add display driver for MT8188 VDOSYS1 Hsiao Chien Sung
2023-10-19  5:55 ` [PATCH v10 01/24] dt-bindings: display: mediatek: ethdr: Add compatible for MT8188 Hsiao Chien Sung
2023-10-19  5:55 ` [PATCH v10 02/24] dt-bindings: display: mediatek: mdp-rdma: " Hsiao Chien Sung
2023-10-19  5:55 ` [PATCH v10 03/24] dt-bindings: display: mediatek: merge: " Hsiao Chien Sung
2023-10-19  5:55 ` [PATCH v10 04/24] dt-bindings: display: mediatek: padding: Add MT8188 Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 05/24] dt-bindings: arm: mediatek: Add compatible for MT8188 Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 06/24] dt-bindings: reset: mt8188: Add VDOSYS reset control bits Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 07/24] soc: mediatek: Support MT8188 VDOSYS1 in mtk-mmsys Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 08/24] soc: mediatek: Support MT8188 VDOSYS1 Padding " Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 09/24] soc: mediatek: Support reset bit mapping in mmsys driver Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 10/24] soc: mediatek: Add MT8188 VDOSYS reset bit map Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 11/24] drm/mediatek: Rename OVL_ADAPTOR_TYPE_RDMA Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 12/24] drm/mediatek: Add component ID to component match structure Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 13/24] drm/mediatek: Manage component's clock with function pointers Hsiao Chien Sung
2023-10-19  9:10   ` AngeloGioacchino Del Regno
2023-10-24  7:55   ` CK Hu (胡俊光)
2023-10-19  5:56 ` [PATCH v10 14/24] drm/mediatek: Power on/off devices " Hsiao Chien Sung
2023-10-19  9:07   ` AngeloGioacchino Del Regno
2023-10-24  8:12   ` CK Hu (胡俊光) [this message]
2023-10-19  5:56 ` [PATCH v10 15/24] drm/mediatek: Remove ineffectual power management codes Hsiao Chien Sung
2023-10-19  9:07   ` AngeloGioacchino Del Regno
2023-10-19  9:52     ` Shawn Sung (宋孝謙)
2023-10-19 10:17       ` AngeloGioacchino Del Regno
2023-10-24  9:25   ` CK Hu (胡俊光)
2023-10-24  9:39     ` Shawn Sung (宋孝謙)
2023-10-19  5:56 ` [PATCH v10 16/24] drm/mediatek: Start/Stop components with function pointers Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 17/24] drm/mediatek: Sort OVL adaptor components Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 18/24] drm/mediatek: Refine device table of OVL adaptor Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 19/24] drm/mediatek: Support MT8188 Padding in display driver Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 20/24] drm/mediatek: Add Padding to OVL adaptor Hsiao Chien Sung
2023-10-19  9:10   ` AngeloGioacchino Del Regno
2023-10-19  9:20     ` Shawn Sung (宋孝謙)
2023-10-19  9:55       ` AngeloGioacchino Del Regno
2023-10-19 11:50         ` Shawn Sung (宋孝謙)
2023-10-19  5:56 ` [PATCH v10 21/24] drm/mediatek: Return error if MDP RDMA failed to enable the clock Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 22/24] drm/mediatek: Remove the redundant driver data for DPI Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 23/24] drm/mediatek: Fix underrun in VDO1 when switches off the layer Hsiao Chien Sung
2023-10-19  5:56 ` [PATCH v10 24/24] drm/mediatek: Support MT8188 VDOSYS1 in display driver Hsiao Chien Sung

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=d01f4e1753d3880b8c096c2f69adf19c1f136c8b.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=Jason-JH.Lin@mediatek.com \
    --cc=Moudy.Ho@mediatek.com \
    --cc=Nancy.Lin@mediatek.com \
    --cc=Nathan.Lu@mediatek.com \
    --cc=Shawn.Sung@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=fshao@chromium.org \
    --cc=johnson.wang@mediatek.corp-partner.google.com \
    --cc=krzysztof.kozlowski+dt@linaro.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=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=sean@poorly.run \
    /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).