public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend
@ 2026-02-06  3:30 Tzung-Bi Shih
  2026-02-06  3:40 ` Tzung-Bi Shih
  2026-02-12 16:04 ` Mathieu Poirier
  0 siblings, 2 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2026-02-06  3:30 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Chen-Yu Tsai,
	tzungbi, linux-remoteproc, linux-arm-kernel, linux-mediatek

Prior to commit d935187cfb27 ("remoteproc: mediatek: Break lock
dependency to prepare_lock"), `scp->clk` was prepared and enabled only
when it needs to communicate with the SCP.  The commit d935187cfb27
moved the prepare operation to remoteproc's prepare(), keeping the clock
prepared as long as the SCP is running.

The power consumption due to the prolonged clock preparation can be
negligible when the system is running, as SCP is designed to be a very
power efficient processor.

However, the clock remains prepared even when the system enters system
suspend.  This prevents the underlying clock controller (and potentially
the parent PLLs) from shutting down, which increases power consumption
and may block the system from entering deep sleep states.

Add suspend and resume callbacks.  Unprepare the clock in suspend() if
it was active and re-prepare it in resume() to ensure the clock is
properly disabled during system suspend, while maintaining the "always
prepared" semantics while the system is active.  The driver doesn't
implement .attach() callback, hence it only checks for RPROC_RUNNING.

Fixes: d935187cfb27 ("remoteproc: mediatek: Break lock dependency to prepare_lock")
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
---
 drivers/remoteproc/mtk_scp.c | 39 ++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
index 4651311aeb07..bb6f6a16d895 100644
--- a/drivers/remoteproc/mtk_scp.c
+++ b/drivers/remoteproc/mtk_scp.c
@@ -1592,12 +1592,51 @@ static const struct of_device_id mtk_scp_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
 
+static int __maybe_unused scp_suspend(struct device *dev)
+{
+	struct mtk_scp *scp = dev_get_drvdata(dev);
+	struct rproc *rproc = scp->rproc;
+
+	/*
+	 * Only unprepare if the SCP is running and holding the clock.
+	 *
+	 * Note: `scp_ops` doesn't implement .attach() callback, hence
+	 * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
+	 * should also be checked here.
+	 */
+	if (rproc->state == RPROC_RUNNING)
+		clk_unprepare(scp->clk);
+	return 0;
+}
+
+static int __maybe_unused scp_resume(struct device *dev)
+{
+	struct mtk_scp *scp = dev_get_drvdata(dev);
+	struct rproc *rproc = scp->rproc;
+
+	/*
+	 * Only prepare if the SCP was running and holding the clock.
+	 *
+	 * Note: `scp_ops` doesn't implement .attach() callback, hence
+	 * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
+	 * should also be checked here.
+	 */
+	if (rproc->state == RPROC_RUNNING)
+		return clk_prepare(scp->clk);
+	return 0;
+}
+
+static const struct dev_pm_ops scp_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(scp_suspend, scp_resume)
+};
+
 static struct platform_driver mtk_scp_driver = {
 	.probe = scp_probe,
 	.remove = scp_remove,
 	.driver = {
 		.name = "mtk-scp",
 		.of_match_table = mtk_scp_of_match,
+		.pm = &scp_pm_ops,
 	},
 };
 
-- 
2.53.0.rc2.204.g2597b5adb4-goog



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend
  2026-02-06  3:30 [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend Tzung-Bi Shih
@ 2026-02-06  3:40 ` Tzung-Bi Shih
  2026-02-12 16:04 ` Mathieu Poirier
  1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2026-02-06  3:40 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: Matthias Brugger, AngeloGioacchino Del Regno, Chen-Yu Tsai,
	linux-remoteproc, linux-arm-kernel, linux-mediatek

On Fri, Feb 06, 2026 at 03:30:33AM +0000, Tzung-Bi Shih wrote:
> Prior to commit d935187cfb27 ("remoteproc: mediatek: Break lock
> dependency to prepare_lock"), `scp->clk` was prepared and enabled only
> when it needs to communicate with the SCP.  The commit d935187cfb27
> moved the prepare operation to remoteproc's prepare(), keeping the clock
> prepared as long as the SCP is running.
> 
> The power consumption due to the prolonged clock preparation can be
> negligible when the system is running, as SCP is designed to be a very
> power efficient processor.
> 
> However, the clock remains prepared even when the system enters system
> suspend.  This prevents the underlying clock controller (and potentially
> the parent PLLs) from shutting down, which increases power consumption
> and may block the system from entering deep sleep states.
> 
> Add suspend and resume callbacks.  Unprepare the clock in suspend() if
> it was active and re-prepare it in resume() to ensure the clock is
> properly disabled during system suspend, while maintaining the "always
> prepared" semantics while the system is active.  The driver doesn't
> implement .attach() callback, hence it only checks for RPROC_RUNNING.
> 
> Fixes: d935187cfb27 ("remoteproc: mediatek: Break lock dependency to prepare_lock")
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> ---

Pardon me for forgetting to attach changelog before sending the patch.  Here
is the changelog:

v2:
- Add note and code comment for RPROC_ATTACHED.
- Use __maybe_unused instead of '#ifdef CONFIG_PM_SLEEP'.
- Add R-b tag.

v1: https://lore.kernel.org/all/20260204085442.1822123-1-tzungbi@kernel.org

>  drivers/remoteproc/mtk_scp.c | 39 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
> 
> diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> index 4651311aeb07..bb6f6a16d895 100644
> --- a/drivers/remoteproc/mtk_scp.c
> +++ b/drivers/remoteproc/mtk_scp.c
> @@ -1592,12 +1592,51 @@ static const struct of_device_id mtk_scp_of_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
>  
> +static int __maybe_unused scp_suspend(struct device *dev)
> +{
> +	struct mtk_scp *scp = dev_get_drvdata(dev);
> +	struct rproc *rproc = scp->rproc;
> +
> +	/*
> +	 * Only unprepare if the SCP is running and holding the clock.
> +	 *
> +	 * Note: `scp_ops` doesn't implement .attach() callback, hence
> +	 * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
> +	 * should also be checked here.
> +	 */
> +	if (rproc->state == RPROC_RUNNING)
> +		clk_unprepare(scp->clk);
> +	return 0;
> +}
> +
> +static int __maybe_unused scp_resume(struct device *dev)
> +{
> +	struct mtk_scp *scp = dev_get_drvdata(dev);
> +	struct rproc *rproc = scp->rproc;
> +
> +	/*
> +	 * Only prepare if the SCP was running and holding the clock.
> +	 *
> +	 * Note: `scp_ops` doesn't implement .attach() callback, hence
> +	 * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
> +	 * should also be checked here.
> +	 */
> +	if (rproc->state == RPROC_RUNNING)
> +		return clk_prepare(scp->clk);
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops scp_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(scp_suspend, scp_resume)
> +};
> +
>  static struct platform_driver mtk_scp_driver = {
>  	.probe = scp_probe,
>  	.remove = scp_remove,
>  	.driver = {
>  		.name = "mtk-scp",
>  		.of_match_table = mtk_scp_of_match,
> +		.pm = &scp_pm_ops,
>  	},
>  };
>  
> -- 
> 2.53.0.rc2.204.g2597b5adb4-goog
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend
  2026-02-06  3:30 [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend Tzung-Bi Shih
  2026-02-06  3:40 ` Tzung-Bi Shih
@ 2026-02-12 16:04 ` Mathieu Poirier
  1 sibling, 0 replies; 3+ messages in thread
From: Mathieu Poirier @ 2026-02-12 16:04 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Bjorn Andersson, Matthias Brugger, AngeloGioacchino Del Regno,
	Chen-Yu Tsai, linux-remoteproc, linux-arm-kernel, linux-mediatek

On Thu, 5 Feb 2026 at 20:31, Tzung-Bi Shih <tzungbi@kernel.org> wrote:
>
> Prior to commit d935187cfb27 ("remoteproc: mediatek: Break lock
> dependency to prepare_lock"), `scp->clk` was prepared and enabled only
> when it needs to communicate with the SCP.  The commit d935187cfb27
> moved the prepare operation to remoteproc's prepare(), keeping the clock
> prepared as long as the SCP is running.
>
> The power consumption due to the prolonged clock preparation can be
> negligible when the system is running, as SCP is designed to be a very
> power efficient processor.
>
> However, the clock remains prepared even when the system enters system
> suspend.  This prevents the underlying clock controller (and potentially
> the parent PLLs) from shutting down, which increases power consumption
> and may block the system from entering deep sleep states.
>
> Add suspend and resume callbacks.  Unprepare the clock in suspend() if
> it was active and re-prepare it in resume() to ensure the clock is
> properly disabled during system suspend, while maintaining the "always
> prepared" semantics while the system is active.  The driver doesn't
> implement .attach() callback, hence it only checks for RPROC_RUNNING.
>
> Fixes: d935187cfb27 ("remoteproc: mediatek: Break lock dependency to prepare_lock")
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
> ---
>  drivers/remoteproc/mtk_scp.c | 39 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 39 insertions(+)
>

I will pick this up when rc1 comes out.

Thanks,
Mathieu

> diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> index 4651311aeb07..bb6f6a16d895 100644
> --- a/drivers/remoteproc/mtk_scp.c
> +++ b/drivers/remoteproc/mtk_scp.c
> @@ -1592,12 +1592,51 @@ static const struct of_device_id mtk_scp_of_match[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mtk_scp_of_match);
>
> +static int __maybe_unused scp_suspend(struct device *dev)
> +{
> +       struct mtk_scp *scp = dev_get_drvdata(dev);
> +       struct rproc *rproc = scp->rproc;
> +
> +       /*
> +        * Only unprepare if the SCP is running and holding the clock.
> +        *
> +        * Note: `scp_ops` doesn't implement .attach() callback, hence
> +        * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
> +        * should also be checked here.
> +        */
> +       if (rproc->state == RPROC_RUNNING)
> +               clk_unprepare(scp->clk);
> +       return 0;
> +}
> +
> +static int __maybe_unused scp_resume(struct device *dev)
> +{
> +       struct mtk_scp *scp = dev_get_drvdata(dev);
> +       struct rproc *rproc = scp->rproc;
> +
> +       /*
> +        * Only prepare if the SCP was running and holding the clock.
> +        *
> +        * Note: `scp_ops` doesn't implement .attach() callback, hence
> +        * `rproc->state` can never be RPROC_ATTACHED.  Otherwise, it
> +        * should also be checked here.
> +        */
> +       if (rproc->state == RPROC_RUNNING)
> +               return clk_prepare(scp->clk);
> +       return 0;
> +}
> +
> +static const struct dev_pm_ops scp_pm_ops = {
> +       SET_SYSTEM_SLEEP_PM_OPS(scp_suspend, scp_resume)
> +};
> +
>  static struct platform_driver mtk_scp_driver = {
>         .probe = scp_probe,
>         .remove = scp_remove,
>         .driver = {
>                 .name = "mtk-scp",
>                 .of_match_table = mtk_scp_of_match,
> +               .pm = &scp_pm_ops,
>         },
>  };
>
> --
> 2.53.0.rc2.204.g2597b5adb4-goog
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-12 16:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-06  3:30 [PATCH v2] remoteproc: mediatek: Unprepare SCP clock during system suspend Tzung-Bi Shih
2026-02-06  3:40 ` Tzung-Bi Shih
2026-02-12 16:04 ` Mathieu Poirier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox