Skip to contentSkip to conversation

ASoC: Add helper function for changing the DAI link format

PATCH Applied Lars-Peter Clausen 3 participants 5 messages Jan 6, 2015 – Jan 7, 2015

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

PATCH 1/3 ASoC: Add helper function for changing the DAI link format

For some setups it is necessary to change the DAI link format at runtime. This patch factors out the code that does the initial static DAI link format configuration into a separate helper function which can be used board drivers as well.

This allows board drivers that have to change the DAI link format at runtime to reuse it instead of having to manually change the format on all DAIs.

---
 include/sound/soc.h  |   3 ++
 sound/soc/soc-core.c | 125 ++++++++++++++++++++++++++++-----------------------
 2 files changed, 72 insertions(+), 56 deletions(-)
include/sound/soc.h +3 -0
index b4fca9a..edd4a0a 100644
@@ -429,6 +429,9 @@ bool snd_soc_runtime_ignore_pmdown_time(struct snd_soc_pcm_runtime *rtd);
 void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream);
 void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream);
 
+int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
+	unsigned int dai_fmt);
+
 /* Utility functions to get clock rates from various things */
 int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
 int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
sound/soc/soc-core.c +69 -56

140 lines not on this page · raw message

Signature · 1 line
1.8.0
#1 lore raw

PATCH 2/3 ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt()

Use snd_soc_runtime_set_dai_fmt() to configure the format for the DAI link rather than configuring each DAI individually.

---
 sound/soc/omap/omap-twl4030.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
sound/soc/omap/omap-twl4030.c +1 -19
index 5e551c7..fb1f6bb 100644
@@ -53,11 +53,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_card *card = rtd->card;
 	unsigned int fmt;
-	int ret;
 
 	switch (params_channels(params)) {
 	case 2: /* Stereo I2S mode */
@@ -74,21 +70,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
-	/* Set codec DAI configuration */
-	ret = snd_soc_dai_set_fmt(codec_dai, fmt);
-	if (ret < 0) {
-		dev_err(card->dev, "can't set codec DAI configuration\n");
-		return ret;
-	}
-
-	/* Set cpu DAI configuration */
-	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
-	if (ret < 0) {
-		dev_err(card->dev, "can't set cpu DAI configuration\n");
-		return ret;
-	}
-
-	return 0;
+	return snd_soc_runtime_set_dai_fmt(rtd, fmt);
 }
 
 static struct snd_soc_ops omap_twl4030_ops = {
Signature · 1 line
1.8.0
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt()

Quoted 2 lines · Lars-Peter Clausen

Use snd_soc_runtime_set_dai_fmt() to configure the format for the DAI link rather than configuring each DAI individually.

Quoted 46 lines
---
 sound/soc/omap/omap-twl4030.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
sound/soc/omap/omap-twl4030.c +1 -19
index 5e551c7..fb1f6bb 100644
@@ -53,11 +53,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *codec_dai = rtd->codec_dai;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_card *card = rtd->card;
 	unsigned int fmt;
-	int ret;
 
 	switch (params_channels(params)) {
 	case 2: /* Stereo I2S mode */
@@ -74,21 +70,7 @@ static int omap_twl4030_hw_params(struct snd_pcm_substream *substream,
 		return -EINVAL;
 	}
 
-	/* Set codec DAI configuration */
-	ret = snd_soc_dai_set_fmt(codec_dai, fmt);
-	if (ret < 0) {
-		dev_err(card->dev, "can't set codec DAI configuration\n");
-		return ret;
-	}
-
-	/* Set cpu DAI configuration */
-	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
-	if (ret < 0) {
-		dev_err(card->dev, "can't set cpu DAI configuration\n");
-		return ret;
-	}
-
-	return 0;
+	return snd_soc_runtime_set_dai_fmt(rtd, fmt);
 }
 
 static struct snd_soc_ops omap_twl4030_ops = {
Signature · 1 line
Péter
#3 lore raw

PATCH 3/3 ASoC: mop500_ab8500: Use snd_soc_runtime_set_dai_fmt()

In reply to Lars-Peter Clausen

Use snd_soc_runtime_set_dai_fmt() to configure the format for the DAI link rather than configuring each DAI individually.

---
 sound/soc/ux500/mop500_ab8500.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
sound/soc/ux500/mop500_ab8500.c +2 -14
index be4f1ac7..aa65370 100644
@@ -290,21 +290,9 @@ static int mop500_ab8500_hw_params(struct snd_pcm_substream *substream,
 			SND_SOC_DAIFMT_GATED;
 	}
 
-	ret = snd_soc_dai_set_fmt(codec_dai, fmt);
-	if (ret < 0) {
-		dev_err(dev,
-			"%s: ERROR: snd_soc_dai_set_fmt failed for codec_dai (ret = %d)!\n",
-			__func__, ret);
-		return ret;
-	}
-
-	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
-	if (ret < 0) {
-		dev_err(dev,
-			"%s: ERROR: snd_soc_dai_set_fmt failed for cpu_dai (ret = %d)!\n",
-			__func__, ret);
+	ret = snd_soc_runtime_set_dai_fmt(rtd, fmt);
+	if (ret)
 		return ret;
-	}
 
 	/* Setup TDM-slots */
 
Signature · 1 line
1.8.0
maintainer Applied
#4 lore raw
In reply to Lars-Peter Clausen
Quoted 4 lines · Lars-Peter Clausen

For some setups it is necessary to change the DAI link format at runtime. This patch factors out the code that does the initial static DAI link format configuration into a separate helper function which can be used board drivers as well.

Applied all, thanks.