[alsa-devel] [PATCH 1/2] ASoC: img-spdif-in: Add suspend / resume handling

Ed Blake ed.blake at sondrel.com
Mon Oct 2 12:01:17 CEST 2017


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

Signed-off-by: Ed Blake <ed.blake at sondrel.com>
---
 sound/soc/img/img-spdif-in.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/sound/soc/img/img-spdif-in.c b/sound/soc/img/img-spdif-in.c
index 8adfd65..d74bcc5 100644
--- a/sound/soc/img/img-spdif-in.c
+++ b/sound/soc/img/img-spdif-in.c
@@ -82,6 +82,8 @@ struct img_spdif_in {
 	unsigned int single_freq;
 	unsigned int multi_freqs[IMG_SPDIF_IN_NUM_ACLKGEN];
 	bool active;
+	u32 suspend_clkgen;
+	u32 suspend_ctl;
 
 	/* Write-only registers */
 	unsigned int aclkgen_regs[IMG_SPDIF_IN_NUM_ACLKGEN];
@@ -676,8 +678,38 @@ static int img_spdif_in_dai_probe(struct snd_soc_dai *dai)
 	return 0;
 }
 
+static int img_spdif_in_dai_suspend(struct snd_soc_dai *dai)
+{
+	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(dai);
+
+	spdif->suspend_clkgen = img_spdif_in_readl(spdif, IMG_SPDIF_IN_CLKGEN);
+	spdif->suspend_ctl = img_spdif_in_readl(spdif, IMG_SPDIF_IN_CTL);
+
+	clk_disable_unprepare(spdif->clk_sys);
+
+	return 0;
+}
+
+static int img_spdif_in_dai_resume(struct snd_soc_dai *dai)
+{
+	struct img_spdif_in *spdif = snd_soc_dai_get_drvdata(dai);
+	int i;
+
+	clk_prepare_enable(spdif->clk_sys);
+
+	for (i = 0; i < IMG_SPDIF_IN_NUM_ACLKGEN; i++)
+		img_spdif_in_aclkgen_writel(spdif, i);
+
+	img_spdif_in_writel(spdif, spdif->suspend_clkgen, IMG_SPDIF_IN_CLKGEN);
+	img_spdif_in_writel(spdif, spdif->suspend_ctl, IMG_SPDIF_IN_CTL);
+
+	return 0;
+}
+
 static struct snd_soc_dai_driver img_spdif_in_dai = {
 	.probe = img_spdif_in_dai_probe,
+	.suspend = img_spdif_in_dai_suspend,
+	.resume = img_spdif_in_dai_resume,
 	.capture = {
 		.channels_min = 2,
 		.channels_max = 2,
-- 
1.9.1



More information about the Alsa-devel mailing list