All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] media: mali-c55: Keep IRQ requested during suspend
@ 2026-12-02 11:51 Linus Walleij
       [not found] ` <6b10143a.7e650fc9.5f16c.7076@mx.google.com>
  2026-12-02 14:31 ` [PATCH v4] " Jacopo Mondi
  0 siblings, 2 replies; 3+ messages in thread
From: Linus Walleij @ 2026-12-02 11:51 UTC (permalink / raw)
  To: Li Youhong, Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab,
	Hans Verkuil, Nayden Kanchev
  Cc: linux-media, stable, Linus Walleij

The interrupt is currently freed on every runtime suspend and requested
again on runtime resume. Apart from tying interrupt ownership to the
power state rather than to the driver lifetime, this leaves remove to
guess whether an action is installed for the IRQ.

Request the interrupt once during probe and free it during remove.

Disable and synchronize the IRQ before powering the ISP off, and enable
it only after a successful power-on.

Hold a runtime PM reference during probe until the IRQ is installed,
and stop runtime PM and drain the IRQ before unregistering the media
entities during remove.

Fixes: d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
Cc: stable@vger.kernel.org
Signed-off-by: Linus Walleij <linusw@kernel.org>
---
This is essentially my reply with the "proper fix" for:
https://lore.kernel.org/linux-media/20260903025526.2657105-1-dayou5941@163.com/

Keep the Mali-C55 interrupt requested for the driver's lifetime instead
of changing interrupt ownership along with the runtime power state.
Synchronize and disable the IRQ before power-off, and enable it after
power-on. Hold a PM reference until probe installs the IRQ, and stop
runtime PM and drain the IRQ before removing the media entities.

Tested on the Renesas RZ/V2H board with the other in-flight patches
(DTS changes and the TPG enablement) doing full suspend/resume cycles
with wakeup from RTC and NMI and capturing images before and after
the test.

This patch was authored with the assistance of an LLM.
---
Changes in v4:
- Clarify the probe PM reference and why power-off follows media teardown.
- Link to v3: https://patch.msgid.link/20261123-mali-c55-irq-supend-resume-v3-1-8a933864e7aa@kernel.org

Changes in v3:
- Explain the probe PM reference and drop the threaded IRQ comment.
- Link to v2: https://patch.msgid.link/20261027-mali-c55-irq-supend-resume-v2-1-759b3f5b2cfd@kernel.org

Changes in v2:
- Drop the wakeup-source binding patch and all ISP wakeup handling.
- Drop the patch retaining ISP power for wakeup; keep the IRQ lifetime fix.
- Link to v1: https://patch.msgid.link/20260929-mali-c55-irq-supend-resume-v1-0-e3af34afff12@kernel.org
---
 .../media/platform/arm/mali-c55/mali-c55-core.c    | 45 ++++++++++++----------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
index f28e9f4354ac..5e270d37fbe9 100644
--- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c
+++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
@@ -675,8 +675,7 @@ static int __maybe_unused mali_c55_runtime_suspend(struct device *dev)
 {
 	struct mali_c55 *mali_c55 = dev_get_drvdata(dev);
 
-	if (irq_has_action(mali_c55->irqnum))
-		free_irq(mali_c55->irqnum, dev);
+	disable_irq(mali_c55->irqnum);
 	__mali_c55_power_off(mali_c55);
 
 	return 0;
@@ -745,20 +744,9 @@ static int __maybe_unused mali_c55_runtime_resume(struct device *dev)
 	if (ret)
 		return ret;
 
-	/*
-	 * The driver needs to transfer large amounts of register settings to
-	 * the ISP each frame, using either a DMA transfer or memcpy. We use a
-	 * threaded IRQ to avoid disabling interrupts the entire time that's
-	 * happening.
-	 */
-	ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
-				   IRQF_ONESHOT, dev_driver_string(dev), dev);
-	if (ret) {
-		__mali_c55_power_off(mali_c55);
-		dev_err(dev, "failed to request irq\n");
-	}
+	enable_irq(mali_c55->irqnum);
 
-	return ret;
+	return 0;
 }
 
 static const struct dev_pm_ops mali_c55_pm_ops = {
@@ -825,27 +813,41 @@ static int mali_c55_probe(struct platform_device *pdev)
 	pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
 	pm_runtime_use_autosuspend(&pdev->dev);
 	pm_runtime_set_active(&pdev->dev);
+
+	/*
+	 * Media registration exposes video nodes before the IRQ is installed.
+	 * Keep the ISP active so runtime PM cannot touch the IRQ yet.
+	 */
+	pm_runtime_get_noresume(dev);
 	pm_runtime_enable(&pdev->dev);
 
 	ret = mali_c55_media_frameworks_init(mali_c55);
 	if (ret)
 		goto err_pm_runtime_disable;
 
-	pm_runtime_idle(&pdev->dev);
-
 	mali_c55->irqnum = platform_get_irq(pdev, 0);
 	if (mali_c55->irqnum < 0) {
 		ret = mali_c55->irqnum;
 		goto err_deinit_media_frameworks;
 	}
 
+	ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
+				   IRQF_ONESHOT, dev_driver_string(dev), dev);
+	if (ret) {
+		dev_err(dev, "failed to request irq\n");
+		goto err_deinit_media_frameworks;
+	}
+
+	pm_runtime_put_autosuspend(dev);
+
 	return 0;
 
 err_deinit_media_frameworks:
 	mali_c55_media_frameworks_deinit(mali_c55);
 err_pm_runtime_disable:
-	pm_runtime_set_suspended(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
+	pm_runtime_put_noidle(dev);
+	pm_runtime_set_suspended(&pdev->dev);
 	kfree(mali_c55->context.registers);
 err_power_off:
 	__mali_c55_power_off(mali_c55);
@@ -859,12 +861,15 @@ static void mali_c55_remove(struct platform_device *pdev)
 {
 	struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
 
+	pm_runtime_disable(&pdev->dev);
+	free_irq(mali_c55->irqnum, &pdev->dev);
+
+	/* Unregistering an active capture queue can still access the ISP. */
 	mali_c55_media_frameworks_deinit(mali_c55);
-	if (!pm_runtime_suspended(&pdev->dev)) {
+	if (!pm_runtime_status_suspended(&pdev->dev)) {
 		__mali_c55_power_off(mali_c55);
 		pm_runtime_set_suspended(&pdev->dev);
 	}
-	pm_runtime_disable(&pdev->dev);
 	kfree(mali_c55->context.registers);
 	of_reserved_mem_device_release(&pdev->dev);
 }

---
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
change-id: 20260918-mali-c55-irq-supend-resume-30b507a20011

Best regards,
--  
Linus Walleij <linusw@kernel.org>


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

* Re: [v4] media: mali-c55: Keep IRQ requested during suspend
       [not found] ` <6b10143a.7e650fc9.5f16c.7076@mx.google.com>
@ 2026-12-02 12:59   ` Linus Walleij
  0 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2026-12-02 12:59 UTC (permalink / raw)
  To: linux-media; +Cc: Linux Media CI

On Wed, Dec 2, 2026 at 1:51 PM Patchwork Integration
<patchwork@media-ci.org> wrote:

> # Test build-basic:x86_64
> drivers/platform/x86/intel/int3472/discrete.c: In function ‘skl_int3472_handle_gpio_resources’:
> drivers/platform/x86/intel/int3472/discrete.c:440:24: warning: ‘err_msg’ may be used uninitialized [-Wmaybe-uninitialized]
>   440 |                 return dev_err_probe(int3472->dev, ret, err_msg);
>       |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> drivers/platform/x86/intel/int3472/discrete.c:332:21: note: ‘err_msg’ was declared here
>   332 |         const char *err_msg;
>       |                     ^~~~~~~
> drivers/platform/x86/intel/int3472/discrete.c:440:24: warning: ‘err_msg’ may be used uninitialized [-Wmaybe-uninitialized]

This again?

Ignoring this for the same reasons as the last time.

Yours,
Linus Walleij

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

* Re: [PATCH v4] media: mali-c55: Keep IRQ requested during suspend
  2026-12-02 11:51 [PATCH v4] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
       [not found] ` <6b10143a.7e650fc9.5f16c.7076@mx.google.com>
@ 2026-12-02 14:31 ` Jacopo Mondi
  1 sibling, 0 replies; 3+ messages in thread
From: Jacopo Mondi @ 2026-12-02 14:31 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Li Youhong, Daniel Scally, Jacopo Mondi, Mauro Carvalho Chehab,
	Hans Verkuil, Nayden Kanchev, linux-media, stable

Hi Linus

On Wed, Dec 02, 2026 at 12:51:59PM +0100, Linus Walleij wrote:
> The interrupt is currently freed on every runtime suspend and requested
> again on runtime resume. Apart from tying interrupt ownership to the
> power state rather than to the driver lifetime, this leaves remove to
> guess whether an action is installed for the IRQ.
>
> Request the interrupt once during probe and free it during remove.
>
> Disable and synchronize the IRQ before powering the ISP off, and enable
> it only after a successful power-on.
>
> Hold a runtime PM reference during probe until the IRQ is installed,
> and stop runtime PM and drain the IRQ before unregistering the media
> entities during remove.
>
> Fixes: d5f281f3dd29 ("media: mali-c55: Add Mali-C55 ISP driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linus Walleij <linusw@kernel.org>
> ---
> This is essentially my reply with the "proper fix" for:
> https://lore.kernel.org/linux-media/20260903025526.2657105-1-dayou5941@163.com/
>
> Keep the Mali-C55 interrupt requested for the driver's lifetime instead
> of changing interrupt ownership along with the runtime power state.
> Synchronize and disable the IRQ before power-off, and enable it after
> power-on. Hold a PM reference until probe installs the IRQ, and stop
> runtime PM and drain the IRQ before removing the media entities.
>
> Tested on the Renesas RZ/V2H board with the other in-flight patches
> (DTS changes and the TPG enablement) doing full suspend/resume cycles
> with wakeup from RTC and NMI and capturing images before and after
> the test.
>
> This patch was authored with the assistance of an LLM.
> ---
> Changes in v4:
> - Clarify the probe PM reference and why power-off follows media teardown.
> - Link to v3: https://patch.msgid.link/20261123-mali-c55-irq-supend-resume-v3-1-8a933864e7aa@kernel.org
>
> Changes in v3:
> - Explain the probe PM reference and drop the threaded IRQ comment.
> - Link to v2: https://patch.msgid.link/20261027-mali-c55-irq-supend-resume-v2-1-759b3f5b2cfd@kernel.org
>
> Changes in v2:
> - Drop the wakeup-source binding patch and all ISP wakeup handling.
> - Drop the patch retaining ISP power for wakeup; keep the IRQ lifetime fix.
> - Link to v1: https://patch.msgid.link/20260929-mali-c55-irq-supend-resume-v1-0-e3af34afff12@kernel.org
> ---
>  .../media/platform/arm/mali-c55/mali-c55-core.c    | 45 ++++++++++++----------
>  1 file changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/media/platform/arm/mali-c55/mali-c55-core.c b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> index f28e9f4354ac..5e270d37fbe9 100644
> --- a/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> +++ b/drivers/media/platform/arm/mali-c55/mali-c55-core.c
> @@ -675,8 +675,7 @@ static int __maybe_unused mali_c55_runtime_suspend(struct device *dev)
>  {
>  	struct mali_c55 *mali_c55 = dev_get_drvdata(dev);
>
> -	if (irq_has_action(mali_c55->irqnum))
> -		free_irq(mali_c55->irqnum, dev);
> +	disable_irq(mali_c55->irqnum);
>  	__mali_c55_power_off(mali_c55);
>
>  	return 0;
> @@ -745,20 +744,9 @@ static int __maybe_unused mali_c55_runtime_resume(struct device *dev)
>  	if (ret)
>  		return ret;
>
> -	/*
> -	 * The driver needs to transfer large amounts of register settings to
> -	 * the ISP each frame, using either a DMA transfer or memcpy. We use a
> -	 * threaded IRQ to avoid disabling interrupts the entire time that's
> -	 * happening.
> -	 */
> -	ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
> -				   IRQF_ONESHOT, dev_driver_string(dev), dev);
> -	if (ret) {
> -		__mali_c55_power_off(mali_c55);
> -		dev_err(dev, "failed to request irq\n");
> -	}
> +	enable_irq(mali_c55->irqnum);
>
> -	return ret;
> +	return 0;
>  }
>
>  static const struct dev_pm_ops mali_c55_pm_ops = {
> @@ -825,27 +813,41 @@ static int mali_c55_probe(struct platform_device *pdev)
>  	pm_runtime_set_autosuspend_delay(&pdev->dev, 2000);
>  	pm_runtime_use_autosuspend(&pdev->dev);
>  	pm_runtime_set_active(&pdev->dev);
> +
> +	/*
> +	 * Media registration exposes video nodes before the IRQ is installed.
> +	 * Keep the ISP active so runtime PM cannot touch the IRQ yet.
> +	 */
> +	pm_runtime_get_noresume(dev);
>  	pm_runtime_enable(&pdev->dev);
>
>  	ret = mali_c55_media_frameworks_init(mali_c55);
>  	if (ret)
>  		goto err_pm_runtime_disable;
>
> -	pm_runtime_idle(&pdev->dev);
> -
>  	mali_c55->irqnum = platform_get_irq(pdev, 0);
>  	if (mali_c55->irqnum < 0) {
>  		ret = mali_c55->irqnum;
>  		goto err_deinit_media_frameworks;
>  	}
>
> +	ret = request_threaded_irq(mali_c55->irqnum, NULL, mali_c55_isr,
> +				   IRQF_ONESHOT, dev_driver_string(dev), dev);
> +	if (ret) {
> +		dev_err(dev, "failed to request irq\n");
> +		goto err_deinit_media_frameworks;
> +	}
> +
> +	pm_runtime_put_autosuspend(dev);
> +
>  	return 0;
>
>  err_deinit_media_frameworks:
>  	mali_c55_media_frameworks_deinit(mali_c55);
>  err_pm_runtime_disable:
> -	pm_runtime_set_suspended(&pdev->dev);
>  	pm_runtime_disable(&pdev->dev);
> +	pm_runtime_put_noidle(dev);
> +	pm_runtime_set_suspended(&pdev->dev);
>  	kfree(mali_c55->context.registers);
>  err_power_off:
>  	__mali_c55_power_off(mali_c55);
> @@ -859,12 +861,15 @@ static void mali_c55_remove(struct platform_device *pdev)
>  {
>  	struct mali_c55 *mali_c55 = platform_get_drvdata(pdev);
>
> +	pm_runtime_disable(&pdev->dev);
> +	free_irq(mali_c55->irqnum, &pdev->dev);
> +
> +	/* Unregistering an active capture queue can still access the ISP. */
>  	mali_c55_media_frameworks_deinit(mali_c55);
> -	if (!pm_runtime_suspended(&pdev->dev)) {
> +	if (!pm_runtime_status_suspended(&pdev->dev)) {
>  		__mali_c55_power_off(mali_c55);
>  		pm_runtime_set_suspended(&pdev->dev);
>  	}
> -	pm_runtime_disable(&pdev->dev);

Ack, I feel this version is easier to grasp, thanks!

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

I already sent the PR for v7.5 but maybe there still is a little time
to sneak this one in ?

>  	kfree(mali_c55->context.registers);
>  	of_reserved_mem_device_release(&pdev->dev);
>  }
>
> ---
> base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
> change-id: 20260918-mali-c55-irq-supend-resume-30b507a20011
>
> Best regards,
> --
> Linus Walleij <linusw@kernel.org>
>

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:51 [PATCH v4] media: mali-c55: Keep IRQ requested during suspend Linus Walleij
     [not found] ` <6b10143a.7e650fc9.5f16c.7076@mx.google.com>
2026-12-02 12:59   ` [v4] " Linus Walleij
2026-12-02 14:31 ` [PATCH v4] " Jacopo Mondi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.