[PATCH v3 08/22] soundwire: intel: reset pm_runtime status during system resume

From: Pierre-Louis Bossart
Date: Thu Nov 14 2019 - 13:21:09 EST


The system resume does the entire bus re-initialization and brings it
to full-power. If the device was pm_runtime suspended, there is no
need to run the pm_runtime resume sequence after the system runtime.

Follow the documentation from runtime_pm.rst, and conditionally
disable, set_active and re-enable the device on system resume.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@xxxxxxxxxxxxxxx>
---
drivers/soundwire/intel.c | 30 ++++++++++++++++++++++++++++++
include/linux/soundwire/sdw.h | 1 +
2 files changed, 31 insertions(+)

diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c
index 1ce2a3c5900c..b2bc99970245 100644
--- a/drivers/soundwire/intel.c
+++ b/drivers/soundwire/intel.c
@@ -1298,6 +1298,7 @@ static int intel_master_remove(struct sdw_master_device *md)

static int intel_suspend(struct device *dev)
{
+ struct sdw_master_device *md = to_sdw_master_device(dev);
struct sdw_cdns *cdns = dev_get_drvdata(dev);
struct sdw_intel *sdw = cdns_to_intel(cdns);
int ret;
@@ -1308,6 +1309,20 @@ static int intel_suspend(struct device *dev)
return 0;
}

+ if (pm_runtime_status_suspended(dev)) {
+ dev_dbg(dev,
+ "%s: pm_runtime status: suspended\n",
+ __func__);
+
+ /*
+ * keep track of the state for the system resume, where
+ * we will need to reset the pm_runtime status to active
+ */
+ md->pm_runtime_suspended = true;
+
+ return 0;
+ }
+
ret = sdw_cdns_enable_interrupt(cdns, false);
if (ret < 0) {
dev_err(dev, "cannot disable interrupts on suspend\n");
@@ -1356,6 +1371,7 @@ static int intel_suspend_runtime(struct device *dev)

static int intel_resume(struct device *dev)
{
+ struct sdw_master_device *md = to_sdw_master_device(dev);
struct sdw_cdns *cdns = dev_get_drvdata(dev);
struct sdw_intel *sdw = cdns_to_intel(cdns);
int ret;
@@ -1366,6 +1382,20 @@ static int intel_resume(struct device *dev)
return 0;
}

+ if (md->pm_runtime_suspended) {
+ dev_dbg(dev,
+ "%s: pm_runtime status was suspended, forcing active\n",
+ __func__);
+
+ /* follow required sequence from runtime_pm.rst */
+ pm_runtime_disable(dev);
+ pm_runtime_set_active(dev);
+ pm_runtime_mark_last_busy(dev);
+ pm_runtime_enable(dev);
+
+ md->pm_runtime_suspended = false;
+ }
+
ret = intel_init(sdw);
if (ret) {
dev_err(dev, "%s failed: %d", __func__, ret);
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index d22950b1a5d9..72b2e0438abb 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -589,6 +589,7 @@ struct sdw_master_device {
struct device dev;
int link_id;
struct sdw_md_driver *driver;
+ bool pm_runtime_suspended;
void *pdata; /* core does not touch */
};

--
2.20.1