public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Kinn Coelho Juliao <kinncj@gmail.com>
To: linux-media@vger.kernel.org
Cc: Bin.Du@amd.com, pratap.nirujogi@amd.com,
	mario.limonciello@amd.com, sultan@kerneltoast.com,
	linux-kernel@vger.kernel.org,
	Kinn Coelho Juliao <kinncj@gmail.com>
Subject: [PATCH] media: amd: isp4: add system suspend/resume support
Date: Tue,  3 Mar 2026 17:44:33 -0500	[thread overview]
Message-ID: <20260303224433.87242-1-kinncj@gmail.com> (raw)
In-Reply-To: <20260302073020.148277-1-Bin.Du@amd.com>

The ISP4 capture platform driver currently has no dev_pm_ops. When the
driver is loaded during a session, the ISP hardware is left in an active
state on s2idle suspend, causing the system to hang and requiring a hard
power-off.

Add suspend and resume callbacks that properly tear down the ISP firmware
and hardware state before sleep via isp4sd_pwroff_and_deinit(). On
resume, the device is marked so that userspace re-opens the camera,
which triggers isp4sd_pwron_and_init() to reinitialize the hardware.

Tested on HP ZBook Ultra G1a (AMD Ryzen AI MAX+ PRO 395, Strix Halo)
with CachyOS kernel 6.19.5 — multiple suspend/resume cycles with the
camera active before suspend complete successfully.

Signed-off-by: Kinn Coelho Juliao <kinncj@gmail.com>
---
 drivers/media/platform/amd/isp4/isp4.c | 48 ++++++++++++++++++++++++++
 drivers/media/platform/amd/isp4/isp4.h |  1 +
 2 files changed, 49 insertions(+)

diff --git a/drivers/media/platform/amd/isp4/isp4.c b/drivers/media/platform/amd/isp4/isp4.c
index bf6b8e2..3e2c3bc 100644
--- a/drivers/media/platform/amd/isp4/isp4.c
+++ b/drivers/media/platform/amd/isp4/isp4.c
@@ -4,6 +4,7 @@
  */
 
 #include <linux/irq.h>
+#include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/vmalloc.h>
 #include <media/v4l2-ioctl.h>
@@ -221,11 +222,58 @@ static void isp4_capture_remove(struct platform_device *pdev)
 	media_device_cleanup(&isp_dev->mdev);
 }
 
+static int isp4_capture_suspend(struct device *dev)
+{
+	struct isp4_device *isp_dev = dev_get_drvdata(dev);
+	struct isp4_subdev *isp_subdev;
+	struct isp4_interface *ispif;
+	int ret;
+
+	if (!isp_dev)
+		return 0;
+
+	isp_subdev = &isp_dev->isp_subdev;
+	ispif = &isp_subdev->ispif;
+
+	if (ispif->status == ISP4IF_STATUS_PWR_OFF)
+		return 0;
+
+	dev_info(dev, "tearing down fw and hw state for suspend\n");
+
+	ret = isp4sd_pwroff_and_deinit(&isp_subdev->sdev);
+	if (ret)
+		dev_err(dev, "suspend teardown failed: %d\n", ret);
+
+	isp_dev->was_powered_before_suspend = true;
+
+	return 0;
+}
+
+static int isp4_capture_resume(struct device *dev)
+{
+	struct isp4_device *isp_dev = dev_get_drvdata(dev);
+
+	if (!isp_dev)
+		return 0;
+
+	if (isp_dev->was_powered_before_suspend) {
+		dev_info(dev, "ISP was active before suspend, camera must be reopened\n");
+		isp_dev->was_powered_before_suspend = false;
+	}
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(isp4_capture_pm_ops,
+				isp4_capture_suspend,
+				isp4_capture_resume);
+
 static struct platform_driver isp4_capture_drv = {
 	.probe = isp4_capture_probe,
 	.remove = isp4_capture_remove,
 	.driver = {
 		.name = ISP4_DRV_NAME,
+		.pm = pm_sleep_ptr(&isp4_capture_pm_ops),
 	}
 };
 
diff --git a/drivers/media/platform/amd/isp4/isp4.h b/drivers/media/platform/amd/isp4/isp4.h
index 2db6683..f39be96 100644
--- a/drivers/media/platform/amd/isp4/isp4.h
+++ b/drivers/media/platform/amd/isp4/isp4.h
@@ -13,6 +13,7 @@ struct isp4_device {
 	struct v4l2_device v4l2_dev;
 	struct isp4_subdev isp_subdev;
 	struct media_device mdev;
+	bool was_powered_before_suspend;
 };
 
 void isp4_intr_enable(struct isp4_subdev *isp_subdev, u32 index, bool enable);
-- 
2.53.0


  parent reply	other threads:[~2026-03-03 22:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02  7:30 [PATCH v9 0/7] Add AMD ISP4 driver Bin Du
2026-03-02  7:30 ` [PATCH v9 1/7] media: platform: amd: Introduce amd isp4 capture driver Bin Du
2026-03-02  7:30 ` [PATCH v9 2/7] media: platform: amd: low level support for isp4 firmware Bin Du
2026-03-02  7:30 ` [PATCH v9 3/7] media: platform: amd: Add isp4 fw and hw interface Bin Du
2026-03-02  7:30 ` [PATCH v9 4/7] media: platform: amd: isp4 subdev and firmware loading handling added Bin Du
2026-03-02  7:30 ` [PATCH v9 5/7] media: platform: amd: isp4 video node and buffers " Bin Du
2026-03-02  7:30 ` [PATCH v9 6/7] media: platform: amd: isp4 debug fs logging and more descriptive errors Bin Du
2026-03-02  7:30 ` [PATCH v9 7/7] Documentation: add documentation of AMD isp 4 driver Bin Du
2026-03-03 22:44 ` Kinn Coelho Juliao [this message]
2026-03-03 22:49   ` [PATCH] media: amd: isp4: add system suspend/resume support Mario Limonciello
2026-03-03 23:23     ` Nirujogi, Pratap
2026-03-04  0:28       ` Kinn Coelho Juliao
     [not found]         ` <bb32d3a9-51c1-4c56-9452-753c993c5316@amd.com>
2026-03-06  2:20           ` Kinn Julião
2026-03-06  3:58             ` Nirujogi, Pratap
     [not found]               ` <CAF+u_Bza2FStVhZEVzuVJjexteRkcK7OCAgTmEmyKDhrMCbBPg@mail.gmail.com>
2026-03-13 20:55                 ` Mario Limonciello
2026-03-11 22:18 ` [PATCH v9 0/7] Add AMD ISP4 driver Sakari Ailus
2026-03-13  6:27   ` Du, Bin

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=20260303224433.87242-1-kinncj@gmail.com \
    --to=kinncj@gmail.com \
    --cc=Bin.Du@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=pratap.nirujogi@amd.com \
    --cc=sultan@kerneltoast.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