Skip to contentSkip to conversation

dma: img-spdif-out: Add power management

PATCH Superseded Ed Blake 2 participants 8 messages Oct 2, 2017 – Oct 9, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ed Blake

author
#0 lore raw

cover dma: img-spdif-out: Add power management

This patch set adds power managment to the img-spdif-out driver. The first patch renames existing 'suspend' and 'resume' functions to 'runtime_suspend' and 'runtime_resume', which is what they actually are, the second patch adds system PM suspend / resume handling and the third patch adds control of the sys clock to runtime PM.

Ed Blake (3):
ASoC: img-spdif-out: Rename suspend / resume funcs
ASoC: img-spdif-out: Add suspend / resume handling
ASoC: img-spdif-out: Add control of sys clock to runtime PM

 sound/soc/img/img-spdif-out.c | 89 +++++++++++++++++++++++++++++++++----------
 1 file changed, 68 insertions(+), 21 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH 1/3 ASoC: img-spdif-out: Rename suspend / resume funcs

Rename suspend and resume functions to runtime_suspend and runtime_resume, which is what they actually are. This will avoid confusion when adding suspend and resume functions in a subsequent patch.

---
 sound/soc/img/img-spdif-out.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
sound/soc/img/img-spdif-out.c +7 -7
index 383655d..416aa57 100644
@@ -49,7 +49,7 @@ struct img_spdif_out {
 	struct reset_control *rst;
 };
 
-static int img_spdif_out_suspend(struct device *dev)
+static int img_spdif_out_runtime_suspend(struct device *dev)
 {
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 
@@ -58,7 +58,7 @@ static int img_spdif_out_suspend(struct device *dev)
 	return 0;
 }
 
-static int img_spdif_out_resume(struct device *dev)
+static int img_spdif_out_runtime_resume(struct device *dev)
 {
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 	int ret;
@@ -366,7 +366,7 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 
 	pm_runtime_enable(&pdev->dev);
 	if (!pm_runtime_enabled(&pdev->dev)) {
-		ret = img_spdif_out_resume(&pdev->dev);
+		ret = img_spdif_out_runtime_resume(&pdev->dev);
 		if (ret)
 			goto err_pm_disable;
 	}
@@ -393,7 +393,7 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 
 err_suspend:
 	if (!pm_runtime_status_suspended(&pdev->dev))
-		img_spdif_out_suspend(&pdev->dev);
+		img_spdif_out_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	clk_disable_unprepare(spdif->clk_sys);
@@ -407,7 +407,7 @@ static int img_spdif_out_dev_remove(struct platform_device *pdev)
 
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
-		img_spdif_out_suspend(&pdev->dev);
+		img_spdif_out_runtime_suspend(&pdev->dev);
 
 	clk_disable_unprepare(spdif->clk_sys);
 
@@ -421,8 +421,8 @@ static int img_spdif_out_dev_remove(struct platform_device *pdev)
 MODULE_DEVICE_TABLE(of, img_spdif_out_of_match);
 
 static const struct dev_pm_ops img_spdif_out_pm_ops = {
-	SET_RUNTIME_PM_OPS(img_spdif_out_suspend,
-			   img_spdif_out_resume, NULL)
+	SET_RUNTIME_PM_OPS(img_spdif_out_runtime_suspend,
+			   img_spdif_out_runtime_resume, NULL)
 };
 
 static struct platform_driver img_spdif_out_driver = {
Signature · 1 line
1.9.1
author
#5 lore raw

PATCH 2/3 ASoC: img-spdif-out: Add suspend / resume handling

In reply to Ed Blake

Implement ASoC suspend and resume callbacks to save and restore register state, to support platforms where the power is disabled during suspend.

---
 sound/soc/img/img-spdif-out.c | 44 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
sound/soc/img/img-spdif-out.c +44 -0
index 416aa57..8123e2a 100644
@@ -47,6 +47,9 @@ struct img_spdif_out {
 	struct snd_dmaengine_dai_dma_data dma_data;
 	struct device *dev;
 	struct reset_control *rst;
+	u32 suspend_ctl;
+	u32 suspend_csl;
+	u32 suspend_csh;
 };
 
 static int img_spdif_out_runtime_suspend(struct device *dev)
@@ -296,8 +299,49 @@ static int img_spdif_out_dai_probe(struct snd_soc_dai *dai)
 	return 0;
 }
 
+static int img_spdif_out_dai_suspend(struct snd_soc_dai *dai)
+{
+	struct img_spdif_out *spdif = snd_soc_dai_get_drvdata(dai);
+	int ret;
+
+	if (pm_runtime_status_suspended(spdif->dev)) {
+		ret = img_spdif_out_runtime_resume(spdif->dev);
+		if (ret)
+			return ret;
+	}
+
+	spdif->suspend_ctl = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CTL);
+	spdif->suspend_csl = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CSL);
+	spdif->suspend_csh = img_spdif_out_readl(spdif, IMG_SPDIF_OUT_CSH_UV);
+
+	img_spdif_out_runtime_suspend(spdif->dev);
+
+	return 0;
+}
+
+static int img_spdif_out_dai_resume(struct snd_soc_dai *dai)
+{
+	struct img_spdif_out *spdif = snd_soc_dai_get_drvdata(dai);
+	int ret;
+
+	ret = img_spdif_out_runtime_resume(spdif->dev);
+	if (ret)
+		return ret;
+
+	img_spdif_out_writel(spdif, spdif->suspend_ctl, IMG_SPDIF_OUT_CTL);
+	img_spdif_out_writel(spdif, spdif->suspend_csl, IMG_SPDIF_OUT_CSL);
+	img_spdif_out_writel(spdif, spdif->suspend_csh, IMG_SPDIF_OUT_CSH_UV);
+
+	if (pm_runtime_status_suspended(spdif->dev))
+		img_spdif_out_runtime_suspend(spdif->dev);
+
+	return 0;
+}
+
 static struct snd_soc_dai_driver img_spdif_out_dai = {
 	.probe = img_spdif_out_dai_probe,
+	.suspend = img_spdif_out_dai_suspend,
+	.resume = img_spdif_out_dai_resume,
 	.playback = {
 		.channels_min = 2,
 		.channels_max = 2,
Signature · 1 line
1.9.1
author
#6 lore raw

PATCH 3/3 ASoC: img-spdif-out: Add control of sys clock to runtime PM

In reply to Ed Blake

Disable sys clock as well as ref clock when runtime suspended.

---
 sound/soc/img/img-spdif-out.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
sound/soc/img/img-spdif-out.c +17 -14
index 8123e2a..9b93182 100644
@@ -57,6 +57,7 @@ static int img_spdif_out_runtime_suspend(struct device *dev)
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 
 	clk_disable_unprepare(spdif->clk_ref);
+	clk_disable_unprepare(spdif->clk_sys);
 
 	return 0;
 }
@@ -66,9 +67,16 @@ static int img_spdif_out_runtime_resume(struct device *dev)
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(spdif->clk_sys);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		return ret;
+	}
+
 	ret = clk_prepare_enable(spdif->clk_ref);
 	if (ret) {
 		dev_err(dev, "clk_enable failed: %d\n", ret);
+		clk_disable_unprepare(spdif->clk_sys);
 		return ret;
 	}
 
@@ -399,21 +407,21 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 		return PTR_ERR(spdif->clk_ref);
 	}
 
-	ret = clk_prepare_enable(spdif->clk_sys);
-	if (ret)
-		return ret;
-
-	img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
-				IMG_SPDIF_OUT_CTL);
-
-	img_spdif_out_reset(spdif);
-
 	pm_runtime_enable(&pdev->dev);
 	if (!pm_runtime_enabled(&pdev->dev)) {
 		ret = img_spdif_out_runtime_resume(&pdev->dev);
 		if (ret)
 			goto err_pm_disable;
 	}
+	ret = pm_runtime_get_sync(&pdev->dev);
+	if (ret < 0)
+		goto err_suspend;
+
+	img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
+			     IMG_SPDIF_OUT_CTL);
+
+	img_spdif_out_reset(spdif);
+	pm_runtime_put(&pdev->dev);
 
 	spin_lock_init(&spdif->lock);
 
@@ -440,21 +448,16 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 		img_spdif_out_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(spdif->clk_sys);
 
 	return ret;
 }
 
 static int img_spdif_out_dev_remove(struct platform_device *pdev)
 {
-	struct img_spdif_out *spdif = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
 		img_spdif_out_runtime_suspend(&pdev->dev);
 
-	clk_disable_unprepare(spdif->clk_sys);
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Applied "ASoC: img-spdif-out: Rename suspend / resume funcs" to the asoc tree

In reply to Ed Blake

The patch

ASoC: img-spdif-out: Rename suspend / resume funcs

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 2ab18dfe87596e207f17ff0567660cd7356c715a Mon Sep 17 00:00:00 2001

From: Ed Blake <[email protected]>
Date: Mon, 2 Oct 2017 11:01:55 +0100
Subject: [PATCH] ASoC: img-spdif-out: Rename suspend / resume funcs

Rename suspend and resume functions to runtime_suspend and runtime_resume, which is what they actually are. This will avoid confusion when adding suspend and resume functions in a subsequent patch.

---
 sound/soc/img/img-spdif-out.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
sound/soc/img/img-spdif-out.c +7 -7
index 383655da2e60..416aa5786b93 100644
@@ -49,7 +49,7 @@ struct img_spdif_out {
 	struct reset_control *rst;
 };
 
-static int img_spdif_out_suspend(struct device *dev)
+static int img_spdif_out_runtime_suspend(struct device *dev)
 {
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 
@@ -58,7 +58,7 @@ static int img_spdif_out_suspend(struct device *dev)
 	return 0;
 }
 
-static int img_spdif_out_resume(struct device *dev)
+static int img_spdif_out_runtime_resume(struct device *dev)
 {
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 	int ret;
@@ -366,7 +366,7 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 
 	pm_runtime_enable(&pdev->dev);
 	if (!pm_runtime_enabled(&pdev->dev)) {
-		ret = img_spdif_out_resume(&pdev->dev);
+		ret = img_spdif_out_runtime_resume(&pdev->dev);
 		if (ret)
 			goto err_pm_disable;
 	}
@@ -393,7 +393,7 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 
 err_suspend:
 	if (!pm_runtime_status_suspended(&pdev->dev))
-		img_spdif_out_suspend(&pdev->dev);
+		img_spdif_out_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	clk_disable_unprepare(spdif->clk_sys);
@@ -407,7 +407,7 @@ static int img_spdif_out_dev_remove(struct platform_device *pdev)
 
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
-		img_spdif_out_suspend(&pdev->dev);
+		img_spdif_out_runtime_suspend(&pdev->dev);
 
 	clk_disable_unprepare(spdif->clk_sys);
 
@@ -421,8 +421,8 @@ static const struct of_device_id img_spdif_out_of_match[] = {
 MODULE_DEVICE_TABLE(of, img_spdif_out_of_match);
 
 static const struct dev_pm_ops img_spdif_out_pm_ops = {
-	SET_RUNTIME_PM_OPS(img_spdif_out_suspend,
-			   img_spdif_out_resume, NULL)
+	SET_RUNTIME_PM_OPS(img_spdif_out_runtime_suspend,
+			   img_spdif_out_runtime_resume, NULL)
 };
 
 static struct platform_driver img_spdif_out_driver = {
Signature · 1 line
2.14.1
author
#3 lore raw

Re: Applied "ASoC: img-spdif-out: Rename suspend / resume funcs" to the asoc tree

Quoted 8 lines · Mark Brown

The patch

ASoC: img-spdif-out: Rename suspend / resume funcs

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

As you've taken this first patch of the set and not the subsequent two, I assume I should only include patches 2 and 3 in the v2 patch set?

Ed.

maintainer
#4 lore raw

Re: Applied "ASoC: img-spdif-out: Rename suspend / resume funcs" to the asoc tree

Quoted 2 lines · Ed Blake

As you've taken this first patch of the set and not the subsequent two, I assume I should only include patches 2 and 3 in the v2 patch set?

Of course:

| If any updates are required or you are submitting further changes they
| should be sent as incremental updates against current git, existing
| patches will not be replaced.
maintainer
#7 lore raw

Applied "ASoC: img-spdif-out: Add control of sys clock to runtime PM" to the asoc tree

In reply to Ed Blake

The patch

ASoC: img-spdif-out: Add control of sys clock to runtime PM

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From e8639d0c65ba4036b51d63e222080e56384b0573 Mon Sep 17 00:00:00 2001

From: Ed Blake <[email protected]>
Date: Fri, 6 Oct 2017 15:56:07 +0100
Subject: [PATCH] ASoC: img-spdif-out: Add control of sys clock to runtime PM

Disable sys clock as well as ref clock when runtime suspended.

---
 sound/soc/img/img-spdif-out.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)
sound/soc/img/img-spdif-out.c +17 -14
index 1808a5542fd1..934ed3df2ebf 100644
@@ -57,6 +57,7 @@ static int img_spdif_out_runtime_suspend(struct device *dev)
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 
 	clk_disable_unprepare(spdif->clk_ref);
+	clk_disable_unprepare(spdif->clk_sys);
 
 	return 0;
 }
@@ -66,9 +67,16 @@ static int img_spdif_out_runtime_resume(struct device *dev)
 	struct img_spdif_out *spdif = dev_get_drvdata(dev);
 	int ret;
 
+	ret = clk_prepare_enable(spdif->clk_sys);
+	if (ret) {
+		dev_err(dev, "clk_enable failed: %d\n", ret);
+		return ret;
+	}
+
 	ret = clk_prepare_enable(spdif->clk_ref);
 	if (ret) {
 		dev_err(dev, "clk_enable failed: %d\n", ret);
+		clk_disable_unprepare(spdif->clk_sys);
 		return ret;
 	}
 
@@ -358,21 +366,21 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 		return PTR_ERR(spdif->clk_ref);
 	}
 
-	ret = clk_prepare_enable(spdif->clk_sys);
-	if (ret)
-		return ret;
-
-	img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
-				IMG_SPDIF_OUT_CTL);
-
-	img_spdif_out_reset(spdif);
-
 	pm_runtime_enable(&pdev->dev);
 	if (!pm_runtime_enabled(&pdev->dev)) {
 		ret = img_spdif_out_runtime_resume(&pdev->dev);
 		if (ret)
 			goto err_pm_disable;
 	}
+	ret = pm_runtime_get_sync(&pdev->dev);
+	if (ret < 0)
+		goto err_suspend;
+
+	img_spdif_out_writel(spdif, IMG_SPDIF_OUT_CTL_FS_MASK,
+			     IMG_SPDIF_OUT_CTL);
+
+	img_spdif_out_reset(spdif);
+	pm_runtime_put(&pdev->dev);
 
 	spin_lock_init(&spdif->lock);
 
@@ -399,21 +407,16 @@ static int img_spdif_out_probe(struct platform_device *pdev)
 		img_spdif_out_runtime_suspend(&pdev->dev);
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
-	clk_disable_unprepare(spdif->clk_sys);
 
 	return ret;
 }
 
 static int img_spdif_out_dev_remove(struct platform_device *pdev)
 {
-	struct img_spdif_out *spdif = platform_get_drvdata(pdev);
-
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
 		img_spdif_out_runtime_suspend(&pdev->dev);
 
-	clk_disable_unprepare(spdif->clk_sys);
-
 	return 0;
 }
 
Signature · 1 line
2.14.1