soundwire: amd: add pm_prepare callback and pm ops support
authorVijendar Mukunda <Vijendar.Mukunda@amd.com>
Tue, 21 Mar 2023 05:09:01 +0000 (10:39 +0530)
committerVinod Koul <vkoul@kernel.org>
Wed, 12 Apr 2023 10:00:36 +0000 (15:30 +0530)
Add pm_prepare callback and System level pm ops support for
AMD SoundWire manager driver.

Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
Signed-off-by: Mastan Katragadda <Mastan.Katragadda@amd.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/lkml/20230310162554.699766-9-Vijendar.Mukunda@amd.com
Link: https://lore.kernel.org/r/20230321050901.115439-9-Vijendar.Mukunda@amd.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/soundwire/amd_manager.c

index d55706e87d83c45931a8c9338f7890754d155e0f..9fb7f91ca182790ccb096e662d2a3292793a8bdc 100644 (file)
@@ -1043,6 +1043,88 @@ static int amd_sdw_clock_stop_exit(struct amd_sdw_manager *amd_manager)
        return 0;
 }
 
+static int amd_resume_child_device(struct device *dev, void *data)
+{
+       struct sdw_slave *slave = dev_to_sdw_dev(dev);
+       int ret;
+
+       if (!slave->probed) {
+               dev_dbg(dev, "skipping device, no probed driver\n");
+               return 0;
+       }
+       if (!slave->dev_num_sticky) {
+               dev_dbg(dev, "skipping device, never detected on bus\n");
+               return 0;
+       }
+       ret = pm_request_resume(dev);
+       if (ret < 0) {
+               dev_err(dev, "pm_request_resume failed: %d\n", ret);
+               return ret;
+       }
+       return 0;
+}
+
+static int __maybe_unused amd_pm_prepare(struct device *dev)
+{
+       struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
+       struct sdw_bus *bus = &amd_manager->bus;
+       int ret;
+
+       if (bus->prop.hw_disabled) {
+               dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
+                       bus->link_id);
+               return 0;
+       }
+       /*
+        * When multiple peripheral devices connected over the same link, if SoundWire manager
+        * device is not in runtime suspend state, observed that device alerts are missing
+        * without pm_prepare on AMD platforms in clockstop mode0.
+        */
+       if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+               ret = pm_request_resume(dev);
+               if (ret < 0) {
+                       dev_err(bus->dev, "pm_request_resume failed: %d\n", ret);
+                       return 0;
+               }
+       }
+       /* To force peripheral devices to system level suspend state, resume the devices
+        * from runtime suspend state first. Without that unable to dispatch the alert
+        * status to peripheral driver during system level resume as they are in runtime
+        * suspend state.
+        */
+       ret = device_for_each_child(bus->dev, NULL, amd_resume_child_device);
+       if (ret < 0)
+               dev_err(dev, "amd_resume_child_device failed: %d\n", ret);
+       return 0;
+}
+
+static int __maybe_unused amd_suspend(struct device *dev)
+{
+       struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
+       struct sdw_bus *bus = &amd_manager->bus;
+       int ret;
+
+       if (bus->prop.hw_disabled) {
+               dev_dbg(bus->dev, "SoundWire manager %d is disabled, ignoring\n",
+                       bus->link_id);
+               return 0;
+       }
+
+       if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+               return amd_sdw_clock_stop(amd_manager);
+       } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
+               /*
+                * As per hardware programming sequence on AMD platforms,
+                * clock stop should be invoked first before powering-off
+                */
+               ret = amd_sdw_clock_stop(amd_manager);
+               if (ret)
+                       return ret;
+               return amd_deinit_sdw_manager(amd_manager);
+       }
+       return 0;
+}
+
 static int __maybe_unused amd_suspend_runtime(struct device *dev)
 {
        struct amd_sdw_manager *amd_manager = dev_get_drvdata(dev);
@@ -1105,6 +1187,8 @@ static int __maybe_unused amd_resume_runtime(struct device *dev)
 }
 
 static const struct dev_pm_ops amd_pm = {
+       .prepare = amd_pm_prepare,
+       SET_SYSTEM_SLEEP_PM_OPS(amd_suspend, amd_resume_runtime)
        SET_RUNTIME_PM_OPS(amd_suspend_runtime, amd_resume_runtime, NULL)
 };