Skip to contentSkip to conversation

ASoC: dwc: rework pm functions

PATCH New Vladimir Yakovlev 1 participant 1 message Mar 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: dwc: rework pm functions

When using a power domain, we must completely disconnect the module and turn off external signals when it is not in use and turn everything back on at the right time.

When entering system_sleep, pm_runtime_force_suspend() is called, which turns off the device if it was running. When exiting system_sleep, the opposite occurs: pm_runtime_force_resume() is called.

---
 sound/soc/dwc/dwc-i2s.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)
sound/soc/dwc/dwc-i2s.c +27 -11
index 28001e9857d9..1d99d42400c3 100644
@@ -481,8 +481,11 @@ static int dw_i2s_runtime_suspend(struct device *dev)
 {
 	struct dw_i2s_dev *dw_dev = dev_get_drvdata(dev);
 
+	reset_control_assert(dw_dev->reset);
+
 	if (dw_dev->capability & DW_I2S_MASTER)
-		clk_disable(dw_dev->clk);
+		clk_disable_unprepare(dw_dev->clk);
+
 	return 0;
 }
 
@@ -492,10 +495,18 @@ static int dw_i2s_runtime_resume(struct device *dev)
 	int ret;
 
 	if (dw_dev->capability & DW_I2S_MASTER) {
-		ret = clk_enable(dw_dev->clk);
+		ret = clk_prepare_enable(dw_dev->clk);
 		if (ret)
 			return ret;
 	}
+
+	ret = reset_control_deassert(dw_dev->reset);
+	if (ret) {
+		if (dw_dev->capability & DW_I2S_MASTER)
+			clk_disable_unprepare(dw_dev->clk);
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -504,22 +515,16 @@ static int dw_i2s_suspend(struct snd_soc_component *component)
 {
 	struct dw_i2s_dev *dev = snd_soc_component_get_drvdata(component);
 
-	if (dev->capability & DW_I2S_MASTER)
-		clk_disable(dev->clk);
-	return 0;
+	return pm_runtime_force_suspend(dev->dev);
 }
 
 static int dw_i2s_resume(struct snd_soc_component *component)
 {
 	struct dw_i2s_dev *dev = snd_soc_component_get_drvdata(component);
 	struct snd_soc_dai *dai;
-	int stream, ret;
+	int stream;
 
-	if (dev->capability & DW_I2S_MASTER) {
-		ret = clk_enable(dev->clk);
-		if (ret)
-			return ret;
-	}
+	pm_runtime_force_resume(dev->dev);
 
 	for_each_component_dais(component, dai) {
 		for_each_pcm_streams(stream)
@@ -1030,6 +1035,17 @@ static int dw_i2s_probe(struct platform_device *pdev)
 	}
 
 	pm_runtime_enable(&pdev->dev);
+	if (pm_runtime_enabled(&pdev->dev)) {
+		/*
+		 * runtime_pm will control clocks and resets,
+		 * but if RPM is off - turn on clocks and resets permanently
+		 */
+		if (dev->capability & DW_I2S_MASTER)
+			clk_disable_unprepare(dev->clk);
+		if (!dev->is_jh7110)
+			reset_control_assert(dev->reset);
+	}
+
 	return 0;
 
 err_assert_reset:
Signature · 1 line
2.34.1