On 27.02.2023 17:47, Vijendar Mukunda wrote:
Add support for runtime pm ops for AMD SoundWire manager driver.
Signed-off-by: Vijendar Mukunda Vijendar.Mukunda@amd.com Signed-off-by: Mastan Katragadda Mastan.Katragadda@amd.com
drivers/soundwire/amd_manager.c | 161 ++++++++++++++++++++++++++++++ drivers/soundwire/amd_manager.h | 3 + include/linux/soundwire/sdw_amd.h | 17 ++++ 3 files changed, 181 insertions(+)
diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index 7bb2300f16b3..12345077c395 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -14,6 +14,7 @@ #include <linux/slab.h> #include <linux/soundwire/sdw.h> #include <linux/soundwire/sdw_registers.h> +#include <linux/pm_runtime.h> #include <linux/wait.h> #include <sound/pcm_params.h> #include <sound/soc.h> @@ -178,6 +179,12 @@ static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager) acp_reg_writel(0x00, amd_manager->mmio + ACP_SW_ERROR_INTR_MASK); }
+static int amd_deinit_sdw_manager(struct amd_sdw_manager *amd_manager) +{
amd_disable_sdw_interrupts(amd_manager);
return amd_disable_sdw_manager(amd_manager);
+}
static void amd_sdw_set_frameshape(struct amd_sdw_manager *amd_manager) { u32 frame_size; @@ -957,6 +964,12 @@ static void amd_sdw_probe_work(struct work_struct *work) return; amd_sdw_set_frameshape(amd_manager); }
/* Enable runtime PM */
pm_runtime_set_autosuspend_delay(amd_manager->dev, AMD_SDW_MASTER_SUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(amd_manager->dev);
pm_runtime_mark_last_busy(amd_manager->dev);
pm_runtime_set_active(amd_manager->dev);
pm_runtime_enable(amd_manager->dev);
}
static int amd_sdw_manager_probe(struct platform_device *pdev) @@ -1040,17 +1053,165 @@ static int amd_sdw_manager_remove(struct platform_device *pdev) { struct amd_sdw_manager *amd_manager = dev_get_drvdata(&pdev->dev);
pm_runtime_disable(&pdev->dev); cancel_work_sync(&amd_manager->probe_work); amd_disable_sdw_interrupts(amd_manager); sdw_bus_master_delete(&amd_manager->bus); return amd_disable_sdw_manager(amd_manager);
}
+static int amd_sdw_clock_stop(struct amd_sdw_manager *amd_manager) +{
u32 val;
u32 retry_count = 0;
int ret;
ret = sdw_bus_prep_clk_stop(&amd_manager->bus);
if (ret < 0 && ret != -ENODATA) {
dev_err(amd_manager->dev, "prepare clock stop failed %d", ret);
return 0;
}
ret = sdw_bus_clk_stop(&amd_manager->bus);
if (ret < 0 && ret != -ENODATA) {
dev_err(amd_manager->dev, "bus clock stop failed %d", ret);
return 0;
}
do {
val = acp_reg_readl(amd_manager->mmio + ACP_SW_CLK_RESUME_CTRL);
if (val & AMD_SDW_CLK_STOP_DONE) {
amd_manager->clk_stopped = true;
break;
}
usleep_range(10, 20);
} while (retry_count++ < AMD_SDW_CLK_STOP_MAX_RETRY_COUNT);
Could these do { } while () be replaced by read_poll_timeout() ?