All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] ASoC: Add helper function for changing the DAI link format
@ 2015-01-06 14:17 Lars-Peter Clausen
  2015-01-06 14:17 ` [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt() Lars-Peter Clausen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2015-01-06 14:17 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Peter Ujfalusi, alsa-devel, Lars-Peter Clausen, Jarkko Nikula

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.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 include/sound/soc.h  |   3 ++
 sound/soc/soc-core.c | 125 ++++++++++++++++++++++++++++-----------------------
 2 files changed, 72 insertions(+), 56 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index b4fca9a..edd4a0a 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -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);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c024962..4b8dc5f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1427,11 +1427,75 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec)
 	return 0;
 }
 
+/**
+ * snd_soc_runtime_set_dai_fmt() - Change DAI link format for a ASoC runtime
+ * @rtd: The runtime for which the DAI link format should be changed
+ * @dai_fmt: The new DAI link format
+ *
+ * This function updates the DAI link format for all DAIs connected to the DAI
+ * link for the specified runtime.
+ *
+ * Note: For setups with a static format set the dai_fmt field in the
+ * corresponding snd_dai_link struct instead of using this function.
+ *
+ * Returns 0 on success, otherwise a negative error code.
+ */
+int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
+	unsigned int dai_fmt)
+{
+	struct snd_soc_dai **codec_dais = rtd->codec_dais;
+	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < rtd->num_codecs; i++) {
+		struct snd_soc_dai *codec_dai = codec_dais[i];
+
+		ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+		if (ret != 0 && ret != -ENOTSUPP) {
+			dev_warn(codec_dai->dev,
+				 "ASoC: Failed to set DAI format: %d\n", ret);
+			return ret;
+		}
+	}
+
+	/* Flip the polarity for the "CPU" end of a CODEC<->CODEC link */
+	if (cpu_dai->codec) {
+		unsigned int inv_dai_fmt;
+
+		inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
+		switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+		case SND_SOC_DAIFMT_CBM_CFM:
+			inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
+			break;
+		case SND_SOC_DAIFMT_CBM_CFS:
+			inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+			break;
+		case SND_SOC_DAIFMT_CBS_CFM:
+			inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
+			break;
+		case SND_SOC_DAIFMT_CBS_CFS:
+			inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
+			break;
+		}
+
+		dai_fmt = inv_dai_fmt;
+	}
+
+	ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
+	if (ret != 0 && ret != -ENOTSUPP) {
+		dev_warn(cpu_dai->dev,
+			 "ASoC: Failed to set DAI format: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int snd_soc_instantiate_card(struct snd_soc_card *card)
 {
 	struct snd_soc_codec *codec;
-	struct snd_soc_dai_link *dai_link;
-	int ret, i, order, dai_fmt;
+	int ret, i, order;
 
 	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
 
@@ -1542,60 +1606,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 					card->num_dapm_routes);
 
 	for (i = 0; i < card->num_links; i++) {
-		struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
-		dai_link = &card->dai_link[i];
-		dai_fmt = dai_link->dai_fmt;
-
-		if (dai_fmt) {
-			struct snd_soc_dai **codec_dais = rtd->codec_dais;
-			int j;
-
-			for (j = 0; j < rtd->num_codecs; j++) {
-				struct snd_soc_dai *codec_dai = codec_dais[j];
-
-				ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
-				if (ret != 0 && ret != -ENOTSUPP)
-					dev_warn(codec_dai->dev,
-						 "ASoC: Failed to set DAI format: %d\n",
-						 ret);
-			}
-		}
-
-		/* If this is a regular CPU link there will be a platform */
-		if (dai_fmt &&
-		    (dai_link->platform_name || dai_link->platform_of_node)) {
-			ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
-						  dai_fmt);
-			if (ret != 0 && ret != -ENOTSUPP)
-				dev_warn(card->rtd[i].cpu_dai->dev,
-					 "ASoC: Failed to set DAI format: %d\n",
-					 ret);
-		} else if (dai_fmt) {
-			/* Flip the polarity for the "CPU" end */
-			dai_fmt &= ~SND_SOC_DAIFMT_MASTER_MASK;
-			switch (dai_link->dai_fmt &
-				SND_SOC_DAIFMT_MASTER_MASK) {
-			case SND_SOC_DAIFMT_CBM_CFM:
-				dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
-				break;
-			case SND_SOC_DAIFMT_CBM_CFS:
-				dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
-				break;
-			case SND_SOC_DAIFMT_CBS_CFM:
-				dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
-				break;
-			case SND_SOC_DAIFMT_CBS_CFS:
-				dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-				break;
-			}
-
-			ret = snd_soc_dai_set_fmt(card->rtd[i].cpu_dai,
-						  dai_fmt);
-			if (ret != 0 && ret != -ENOTSUPP)
-				dev_warn(card->rtd[i].cpu_dai->dev,
-					 "ASoC: Failed to set DAI format: %d\n",
-					 ret);
-		}
+		if (card->dai_link[i].dai_fmt)
+			snd_soc_runtime_set_dai_fmt(&card->rtd[i],
+				card->dai_link[i].dai_fmt);
 	}
 
 	snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt()
  2015-01-06 14:17 [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Lars-Peter Clausen
@ 2015-01-06 14:17 ` Lars-Peter Clausen
  2015-01-07 12:23   ` Peter Ujfalusi
  2015-01-06 14:17 ` [PATCH 3/3] ASoC: mop500_ab8500: " Lars-Peter Clausen
  2015-01-07 18:04 ` [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Mark Brown
  2 siblings, 1 reply; 5+ messages in thread
From: Lars-Peter Clausen @ 2015-01-06 14:17 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Peter Ujfalusi, alsa-devel, Lars-Peter Clausen, Jarkko Nikula

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/soc/omap/omap-twl4030.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
index 5e551c7..fb1f6bb 100644
--- a/sound/soc/omap/omap-twl4030.c
+++ b/sound/soc/omap/omap-twl4030.c
@@ -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 = {
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] ASoC: mop500_ab8500: Use snd_soc_runtime_set_dai_fmt()
  2015-01-06 14:17 [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Lars-Peter Clausen
  2015-01-06 14:17 ` [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt() Lars-Peter Clausen
@ 2015-01-06 14:17 ` Lars-Peter Clausen
  2015-01-07 18:04 ` [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Lars-Peter Clausen @ 2015-01-06 14:17 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood
  Cc: Peter Ujfalusi, alsa-devel, Lars-Peter Clausen, Jarkko Nikula

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/soc/ux500/mop500_ab8500.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/sound/soc/ux500/mop500_ab8500.c b/sound/soc/ux500/mop500_ab8500.c
index be4f1ac7..aa65370 100644
--- a/sound/soc/ux500/mop500_ab8500.c
+++ b/sound/soc/ux500/mop500_ab8500.c
@@ -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 */
 
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt()
  2015-01-06 14:17 ` [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt() Lars-Peter Clausen
@ 2015-01-07 12:23   ` Peter Ujfalusi
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Ujfalusi @ 2015-01-07 12:23 UTC (permalink / raw)
  To: Lars-Peter Clausen, Mark Brown, Liam Girdwood; +Cc: alsa-devel, Jarkko Nikula

On 01/06/2015 04:17 PM, Lars-Peter Clausen wrote:
> Use snd_soc_runtime_set_dai_fmt() to configure the format for the DAI link
> rather than configuring each DAI individually.

Acked-by: Peter Ujfalusi <peter.ujfalusi@ti.com>

> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  sound/soc/omap/omap-twl4030.c | 20 +-------------------
>  1 file changed, 1 insertion(+), 19 deletions(-)
> 
> diff --git a/sound/soc/omap/omap-twl4030.c b/sound/soc/omap/omap-twl4030.c
> index 5e551c7..fb1f6bb 100644
> --- a/sound/soc/omap/omap-twl4030.c
> +++ b/sound/soc/omap/omap-twl4030.c
> @@ -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 = {
> 


-- 
Péter

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] ASoC: Add helper function for changing the DAI link format
  2015-01-06 14:17 [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Lars-Peter Clausen
  2015-01-06 14:17 ` [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt() Lars-Peter Clausen
  2015-01-06 14:17 ` [PATCH 3/3] ASoC: mop500_ab8500: " Lars-Peter Clausen
@ 2015-01-07 18:04 ` Mark Brown
  2 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2015-01-07 18:04 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Peter Ujfalusi, alsa-devel, Liam Girdwood, Jarkko Nikula


[-- Attachment #1.1: Type: text/plain, Size: 336 bytes --]

On Tue, Jan 06, 2015 at 03:17:20PM +0100, Lars-Peter Clausen wrote:
> 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.

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-07 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-06 14:17 [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Lars-Peter Clausen
2015-01-06 14:17 ` [PATCH 2/3] ASoC: omap-twl4030: Use snd_soc_runtime_set_dai_fmt() Lars-Peter Clausen
2015-01-07 12:23   ` Peter Ujfalusi
2015-01-06 14:17 ` [PATCH 3/3] ASoC: mop500_ab8500: " Lars-Peter Clausen
2015-01-07 18:04 ` [PATCH 1/3] ASoC: Add helper function for changing the DAI link format Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.