From c6df0a92957f704fb9c0d5da556365bf2dcd9880 Mon Sep 17 00:00:00 2001 From: Gopi Chandra Sekhar Reddy Kanala Date: Thu, 26 Nov 2026 15:22:07 +0530 Subject: [PATCH] FROMLIST: soundwire: qcom: switch system sleep to the guarded v2 callbacks The system sleep callbacks were pm_runtime_force_suspend() and pm_runtime_force_resume(), which run the runtime suspend path on every controller that is runtime active when system suspend starts. That path is only safe in the state runtime PM itself suspends the controller in, with the peripherals suspended and no stream set up: - A set up stream stays prepared and enabled across system sleep, and nothing programs its ports again on resume. With the forced suspend, playback that was running when s2idle was entered stayed silent after resume on Glymur CRD. - Without clock stop, runtime resume resets the bus and only re-initializes the peripherals it saw detach, which peripherals that were never runtime suspended have not done. - A controller that was already runtime suspended had runtime PM disabled from the suspend phase on, instead of from suspend_late as the PM core does, which makes the window in which the wake IRQ handler cannot resume it longer. Replace them with swrm_suspend() and swrm_resume(). swrm_suspend() leaves the controller alone if it is already runtime suspended, if the bus does not support clock stop, or if a stream is set up. Otherwise it forces the controller into runtime suspend and records that in sleep_forced, and swrm_resume() only undoes a forced suspend. A controller that is left running keeps its bus clock and hclk on across system sleep, as before the forced suspend was added. A lane provider has no bus of its own: probe returns before sdw_bus_master_add(), so bus.bus_lock and bus.m_rt_list are not initialized. Its consumer is suspended before it through the device link, so only force the provider into runtime suspend if the consumer was. While at it, move to SYSTEM_SLEEP_PM_OPS(), RUNTIME_PM_OPS() and pm_ptr(), and drop the __maybe_unused annotations. Signed-off-by: Gopi Chandra Sekhar Reddy Kanala Link: https://lore.kernel.org/all/20261130-qcom-swr-system-sleep-v2-2-4f65a868813d@oss.qualcomm.com/ --- drivers/soundwire/qcom.c | 52 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index 3fee3f38a44e8..6b4617525bd40 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -295,6 +295,7 @@ struct qcom_swrm_ctrl { u32 slave_status; u32 wr_fifo_depth; bool clock_stop_not_supported; + bool sleep_forced; unsigned int reg_layout_local[SWRM_OFFSET_DP_SAMPLECTRL2_BANK + 1]; }; @@ -2253,7 +2254,7 @@ static void qcom_swrm_remove(struct platform_device *pdev) clk_disable_unprepare(ctrl->hclk); } -static int __maybe_unused swrm_runtime_resume(struct device *dev) +static int swrm_runtime_resume(struct device *dev) { struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); int ret; @@ -2330,7 +2331,7 @@ static int __maybe_unused swrm_runtime_resume(struct device *dev) return 0; } -static int __maybe_unused swrm_runtime_suspend(struct device *dev) +static int swrm_runtime_suspend(struct device *dev) { struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); int ret; @@ -2377,9 +2378,50 @@ static int __maybe_unused swrm_runtime_suspend(struct device *dev) return 0; } +static int swrm_suspend(struct device *dev) +{ + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); + bool stream_set_up; + int ret; + + if (pm_runtime_status_suspended(dev)) + return 0; + + if (ctrl->is_lane_provider) { + if (!ctrl->lane_consumer || !ctrl->lane_consumer->sleep_forced) + return 0; + } else { + scoped_guard(mutex, &ctrl->bus.bus_lock) + stream_set_up = !list_empty(&ctrl->bus.m_rt_list); + + if (ctrl->clock_stop_not_supported || stream_set_up) + return 0; + } + + ret = pm_runtime_force_suspend(dev); + if (ret) + return ret; + + ctrl->sleep_forced = true; + + return 0; +} + +static int swrm_resume(struct device *dev) +{ + struct qcom_swrm_ctrl *ctrl = dev_get_drvdata(dev); + + if (!ctrl->sleep_forced) + return 0; + + ctrl->sleep_forced = false; + + return pm_runtime_force_resume(dev); +} + static const struct dev_pm_ops swrm_dev_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) - SET_RUNTIME_PM_OPS(swrm_runtime_suspend, swrm_runtime_resume, NULL) + SYSTEM_SLEEP_PM_OPS(swrm_suspend, swrm_resume) + RUNTIME_PM_OPS(swrm_runtime_suspend, swrm_runtime_resume, NULL) }; static const struct of_device_id qcom_swrm_of_match[] = { @@ -2401,7 +2443,7 @@ static struct platform_driver qcom_swrm_driver = { .driver = { .name = "qcom-soundwire", .of_match_table = qcom_swrm_of_match, - .pm = &swrm_dev_pm_ops, + .pm = pm_ptr(&swrm_dev_pm_ops), } }; module_platform_driver(qcom_swrm_driver);