linux-mediatek.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Enric Balletbo i Serra <enric.balletbo@collabora.com>
To: Eizan Miyamoto <eizan@chromium.org>, linux-kernel@vger.kernel.org
Cc: wenst@chromium.org, chunkuang.hu@kernel.org,
	yong.wu@mediatek.com, houlong.wei@mediatek.com,
	Andrew-CT Chen <andrew-ct.chen@mediatek.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Minghsiu Tsai <minghsiu.tsai@mediatek.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-media@vger.kernel.org, linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v5 6/8] media: mtk-mdp: propagate errors better in pm_suspend/resume
Date: Mon, 12 Jul 2021 12:12:49 +0200	[thread overview]
Message-ID: <fb0cef50-be3b-3657-fff1-65a957eba35d@collabora.com> (raw)
In-Reply-To: <20210709122040.v5.6.If7d6a147afd8880940c42d7998e47ed3869e8805@changeid>

Hi Eizan,

Thank you for your patch.

On 9/7/21 4:23, Eizan Miyamoto wrote:
> Up until this change, many errors were logged but ignored when powering
> on clocks and calling pm_runtime_get/put() inside mtk_mdp_core. This
> change tries to do a better job at propagating errors back to the power
> management framework.
> 

Yeah, that's nice. I commented that i dislike the error handling and seems that
you're fixing part of it here. It was a bit difficult to review the patches
because this back and forth, some problems introduced by previous patches where
fixed later. If possible I'd reorganize a bit the patches, even squash some of
the pm changes. Basically move this patch before, and do it together with the
other pm patches (even try to squash if possible).


> Signed-off-by: Eizan Miyamoto <eizan@chromium.org>
> ---
> 
> (no changes since v1)
> 
>  drivers/media/platform/mtk-mdp/mtk_mdp_comp.c | 62 ++++++++++++++++---
>  drivers/media/platform/mtk-mdp/mtk_mdp_comp.h |  6 +-
>  drivers/media/platform/mtk-mdp/mtk_mdp_core.c | 57 +++++++++++++----
>  3 files changed, 99 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> index 8a9267d0da1e..87e3f72ff02b 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.c
> @@ -53,9 +53,9 @@ static const struct of_device_id mtk_mdp_comp_driver_dt_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mtk_mdp_comp_driver_dt_match);
>  
> -void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp)
> +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp)
>  {
> -	int err;
> +	int status, err;
>  
>  	if (comp->larb_dev) {
>  		err = mtk_smi_larb_get(comp->larb_dev);
> @@ -65,34 +65,76 @@ void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp)
>  	}
>  
>  	err = pm_runtime_get_sync(comp->dev);
> -	if (err < 0)
> +	if (err < 0) {
>  		dev_err(comp->dev, "failed to runtime get, err %d.\n", err);
> +		return err;
> +	}
> +
> +	err = mtk_mdp_comp_clock_on(comp);
> +	if (err) {
> +		dev_err(comp->dev, "failed to turn on clock. err=%d", err);
> +		status = err;
> +		goto err_mtk_mdp_comp_clock_on;
> +	}
> +
> +	return err;
> +
> +err_mtk_mdp_comp_clock_on:
> +	err = pm_runtime_put_sync(comp->dev);
> +	if (err)
> +		dev_err(comp->dev, "failed to runtime put in cleanup. err=%d", err);
>  
> -	mtk_mdp_comp_clock_on(comp);
> +	return status;
>  }
>  
> -void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp)
> +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp)
>  {
> -	int err;
> +	int status, err;
>  
>  	mtk_mdp_comp_clock_off(comp);
>  
>  	err = pm_runtime_put_sync(comp->dev);
> -	if (err < 0)
> +	if (err < 0) {
>  		dev_err(comp->dev, "failed to runtime put, err %d.\n", err);
> +		status = err;
> +		goto err_pm_runtime_put_sync;
> +	}
> +
> +	return 0;
> +
> +err_pm_runtime_put_sync:
> +	err = mtk_mdp_comp_clock_on(comp);
> +	if (err)
> +		dev_err(comp->dev, "failed to turn on clock in cleanup. err=%d", err);
> +
> +	return status;
>  }
>  
> -void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
> +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp)
>  {
> -	int i, err;
> +	int i, err, status;
>  
>  	for (i = 0; i < ARRAY_SIZE(comp->clk); i++) {
>  		if (IS_ERR(comp->clk[i]))
>  			continue;
>  		err = clk_prepare_enable(comp->clk[i]);
> -		if (err)
> +		if (err) {
> +			status = err;
>  			dev_err(comp->dev, "failed to enable clock, err %d. i:%d\n", err, i);
> +			goto err_clk_prepare_enable;
> +		}
> +	}
> +
> +	return 0;
> +
> +err_clk_prepare_enable:
> +	for (--i; i >= 0; i--) {
> +		if (IS_ERR(comp->clk[i]))
> +			continue;
> +		clk_disable_unprepare(comp->clk[i]);
>  	}
> +
> +	return status;
>  }
>  
>  void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp)
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
> index 15ef9539a5a7..5201c47f7baa 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_comp.h
> @@ -23,10 +23,10 @@ struct mtk_mdp_comp {
>  
>  int mtk_mdp_comp_init(struct mtk_mdp_comp *comp, struct device *dev);
>  
> -void mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp);
> -void mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp);
> +int mtk_mdp_comp_power_on(struct mtk_mdp_comp *comp);
> +int mtk_mdp_comp_power_off(struct mtk_mdp_comp *comp);
>  
> -void mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp);
> +int mtk_mdp_comp_clock_on(struct mtk_mdp_comp *comp);
>  void mtk_mdp_comp_clock_off(struct mtk_mdp_comp *comp);
>  
>  extern struct platform_driver mtk_mdp_component_driver;
> diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
> index 74ef37eb50bd..b45d588d2659 100644
> --- a/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
> +++ b/drivers/media/platform/mtk-mdp/mtk_mdp_core.c
> @@ -50,8 +50,9 @@ static const struct of_device_id mtk_mdp_of_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mtk_mdp_of_ids);
>  
> -static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
> +static int mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
>  {
> +	int err, status;
>  	struct mtk_mdp_comp *comp_node;
>  
>  	/*
> @@ -59,18 +60,41 @@ static void mtk_mdp_clock_on(struct mtk_mdp_dev *mdp)
>  	 * on it through mtk_mdp_m2m_start_streaming, making it unnecessary to
>  	 * have mtk_mdp_comp_power_on called on it.
>  	 */
> -	mtk_mdp_comp_clock_on(&mdp->comp_self);
> +	err = mtk_mdp_comp_clock_on(&mdp->comp_self);
> +	if (err)
> +		return err;
> +
> +	list_for_each_entry(comp_node, &mdp->comp_list, node) {
> +		err = mtk_mdp_comp_power_on(comp_node);
> +		if (err) {
> +			status = err;
> +			goto err_mtk_mdp_comp_power_on;
> +		}
> +	}
>  
> -	list_for_each_entry(comp_node, &mdp->comp_list, node)
> -		mtk_mdp_comp_power_on(comp_node);
> +	return 0;
> +
> +err_mtk_mdp_comp_power_on:
> +	list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) {
> +		err = mtk_mdp_comp_power_off(comp_node);
> +		if (err)
> +			dev_err(&mdp->pdev->dev, "failed to power off after error. err=%d", err);
> +	}
> +	return status;
>  }
>  
> -static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
> +static int mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
>  {
> +	int status, err;
>  	struct mtk_mdp_comp *comp_node;
>  
> -	list_for_each_entry(comp_node, &mdp->comp_list, node)
> -		mtk_mdp_comp_power_off(comp_node);
> +	list_for_each_entry(comp_node, &mdp->comp_list, node) {
> +		err = mtk_mdp_comp_power_off(comp_node);
> +		if (err) {
> +			status = err;
> +			goto err_mtk_mdp_comp_power_off;
> +		}
> +	}
>  
>  	/*
>  	 * The master / rdma0 component will have pm_runtime_put called
> @@ -78,6 +102,17 @@ static void mtk_mdp_clock_off(struct mtk_mdp_dev *mdp)
>  	 * have mtk_mdp_comp_power_off called on it.
>  	 */
>  	mtk_mdp_comp_clock_off(&mdp->comp_self);
> +
> +	return 0;
> +
> +err_mtk_mdp_comp_power_off:
> +	list_for_each_entry_continue_reverse(comp_node, &mdp->comp_list, node) {
> +		err = mtk_mdp_comp_power_on(comp_node);
> +		if (err)
> +			dev_err(&mdp->pdev->dev, "failed to power on after error. err=%d", err);
> +	}
> +
> +	return status;
>  }
>  
>  static void mtk_mdp_wdt_worker(struct work_struct *work)
> @@ -318,18 +353,14 @@ static int __maybe_unused mtk_mdp_pm_suspend(struct device *dev)
>  {
>  	struct mtk_mdp_dev *mdp = dev_get_drvdata(dev);
>  
> -	mtk_mdp_clock_off(mdp);
> -
> -	return 0;
> +	return mtk_mdp_clock_off(mdp);
>  }
>  
>  static int __maybe_unused mtk_mdp_pm_resume(struct device *dev)
>  {
>  	struct mtk_mdp_dev *mdp = dev_get_drvdata(dev);
>  
> -	mtk_mdp_clock_on(mdp);
> -
> -	return 0;
> +	return mtk_mdp_clock_on(mdp);
>  }
>  
>  static int __maybe_unused mtk_mdp_suspend(struct device *dev)
> 

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

  reply	other threads:[~2021-07-12 10:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09  2:23 [PATCH v5 0/8] Refactor MTK MDP driver into core/components Eizan Miyamoto
2021-07-09  2:23 ` [PATCH v5 1/8] mtk-mdp: add driver to probe mdp components Eizan Miyamoto
2021-07-12 10:11   ` Enric Balletbo i Serra
2021-07-09  2:23 ` [PATCH v5 2/8] mtk-mdp: use pm_runtime in MDP component driver Eizan Miyamoto
2021-07-12 10:12   ` Enric Balletbo i Serra
2021-07-09  2:23 ` [PATCH v5 3/8] media: mtk-mdp: don't pm_run_time_get/put for master comp in clock_on Eizan Miyamoto
2021-07-12 10:12   ` Enric Balletbo i Serra
2021-07-09  2:23 ` [PATCH v5 4/8] mtk-mdp: soc: mediatek: register mdp from mmsys Eizan Miyamoto
2021-07-12 10:12   ` Enric Balletbo i Serra
2021-07-09  2:23 ` [PATCH v5 5/8] media: mtk-mdp: search for vpu node instead of linking it to a property Eizan Miyamoto
2021-07-09  2:23 ` [PATCH v5 6/8] media: mtk-mdp: propagate errors better in pm_suspend/resume Eizan Miyamoto
2021-07-12 10:12   ` Enric Balletbo i Serra [this message]
2021-07-09  2:23 ` [PATCH v5 7/8] media: mtk-mdp: use mdp-rdma0 alias to point to MDP master Eizan Miyamoto
2021-07-12 10:12   ` Enric Balletbo i Serra
2021-07-09  2:23 ` [PATCH v5 8/8] dts: mtk-mdp: remove mediatek, vpu property from primary MDP device Eizan Miyamoto
2021-07-12 10:13   ` [PATCH v5 8/8] dts: mtk-mdp: remove mediatek,vpu " Enric Balletbo i Serra

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=fb0cef50-be3b-3657-fff1-65a957eba35d@collabora.com \
    --to=enric.balletbo@collabora.com \
    --cc=andrew-ct.chen@mediatek.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=eizan@chromium.org \
    --cc=houlong.wei@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=matthias.bgg@gmail.com \
    --cc=mchehab@kernel.org \
    --cc=minghsiu.tsai@mediatek.com \
    --cc=wenst@chromium.org \
    --cc=yong.wu@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).