Skip to contentSkip to conversation

ASoC: Add Multi CPU DAI support

RFC PATCH Superseded Bard liao 4 participants 16 messages Jan 15, 2020 – Jan 17, 2020

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Bard liao

author
#0 lore raw

v2 cover ASoC: Add Multi CPU DAI support

As discussed in [1], ASoC core supports multi codec DAIs on a DAI link. However it does not do so for CPU DAIs.

So, add support for multi CPU DAIs on a DAI Link by adding multi CPU DAI in Card instantiation, suspend and resume functions, PCM ops, stream handling functions and DAPM.

[1]: https://www.spinics.net/lists/alsa-devel/msg71369.html

changes in v2:
- rebase on asoc-next
- fix some typo
- compare and merge Kuninori Morimoto's version
- add warning if the function is not support multi cpu yet

Bard liao (1):
ASoC: add warning if the function is not support multi cpu yet.

Shreyas NC (3):
ASoC: Add initial support for multiple CPU DAIs
ASoC: Add multiple CPU DAI support for PCM ops
ASoC: Add multiple CPU DAI support in DAPM

 include/sound/soc.h                   |  15 +
 sound/soc/soc-compress.c              |   7 +-
 sound/soc/soc-core.c                  | 222 ++++++-----
 sound/soc/soc-dapm.c                  | 131 +++---
 sound/soc/soc-generic-dmaengine-pcm.c |  12 +
 sound/soc/soc-pcm.c                   | 547 +++++++++++++++++---------
 6 files changed, 599 insertions(+), 335 deletions(-)
Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
author
#1 lore raw

RFC PATCH v2 1/4 ASoC: Add initial support for multiple CPU DAIs

From: Shreyas NC <[email protected]>

ASoC core supports multiple codec DAIs but supports only a CPU DAI. To support multiple cpu DAIs, add cpu_dai and num_cpu_dai in snd_soc_dai_link and snd_soc_pcm_runtime structures similar to support for codec_dai. This is intended as a preparatory patch to eventually support the unification of the Codec and CPU DAI.

Inline with multiple codec DAI approach, add support to allocate, init, bind and probe multiple cpu_dai on init if driver specifies that. Also add support to loop over multiple cpu_dai during suspend and resume.

This is intended as a preparatory patch to eventually unify the CPU and Codec DAI into DAI components.

---
 include/sound/soc.h  |  15 +++
 sound/soc/soc-core.c | 222 ++++++++++++++++++++++++-------------------
 2 files changed, 139 insertions(+), 98 deletions(-)
include/sound/soc.h +15 -0
index f0e4f36f83bf..4163f5e06126 100644
@@ -855,6 +855,11 @@ struct snd_soc_dai_link {
 	     ((platform) = &link->platforms[i]);			\
 	     (i)++)
 
+#define for_each_link_cpus(link, i, cpu)				\
+	for ((i) = 0;							\
+	     ((i) < link->num_cpus) && ((cpu) = &link->cpus[i]);	\
+	     (i)++)
+
 /*
  * Sample 1 : Single CPU/Codec/Platform
  *
@@ -1132,6 +1137,9 @@ struct snd_soc_pcm_runtime {
 	struct snd_soc_dai **codec_dais;
 	unsigned int num_codecs;
 
+	struct snd_soc_dai **cpu_dais;
+	unsigned int num_cpus;
+
 	struct delayed_work delayed_work;
 	void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
 #ifdef CONFIG_DEBUG_FS
@@ -1159,6 +1167,13 @@ struct snd_soc_pcm_runtime {
 #define for_each_rtd_codec_dai_rollback(rtd, i, dai)		\
 	for (; ((--i) >= 0) && ((dai) = rtd->codec_dais[i]);)
 
+#define for_each_rtd_cpu_dai(rtd, i, dai)\
+	for ((i) = 0;						       \
+	     ((i) < rtd->num_cpus) && ((dai) = rtd->cpu_dais[i]); \
+	     (i)++)
+#define for_each_rtd_cpu_dai_rollback(rtd, i, dai)		\
+	for (; ((--i) >= 0) && ((dai) = rtd->cpu_dais[i]);)
+
 void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd);
 
 /* mixer control */
sound/soc/soc-core.c +124 -98

359 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
author
#2 lore raw

RFC PATCH v2 2/4 ASoC: Add multiple CPU DAI support for PCM ops

In reply to Bard liao

From: Shreyas NC <[email protected]>

Add support in PCM operations to invoke multiple cpu dais as we do for multiple codec dais. Also the symmetry calculations are updated to reflect multiple cpu dais.

---
 sound/soc/soc-pcm.c | 535 +++++++++++++++++++++++++++++---------------
 1 file changed, 357 insertions(+), 178 deletions(-)
sound/soc/soc-pcm.c +357 -178
index 74d340d1c9f7..52c6f3c3ab63 100644
@@ -40,24 +40,28 @@
  */
 void snd_soc_runtime_activate(struct snd_soc_pcm_runtime *rtd, int stream)
 {
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i;
 
 	lockdep_assert_held(&rtd->card->pcm_mutex);
 
 	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		cpu_dai->playback_active++;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+			cpu_dai->playback_active++;
 		for_each_rtd_codec_dai(rtd, i, codec_dai)
 			codec_dai->playback_active++;
 	} else {
-		cpu_dai->capture_active++;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+			cpu_dai->capture_active++;
 		for_each_rtd_codec_dai(rtd, i, codec_dai)
 			codec_dai->capture_active++;
 	}
 
-	cpu_dai->active++;
-	cpu_dai->component->active++;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		cpu_dai->active++;
+		cpu_dai->component->active++;
+	}
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		codec_dai->active++;
 		codec_dai->component->active++;
@@ -76,24 +80,28 @@ 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)
 {
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i;
 
 	lockdep_assert_held(&rtd->card->pcm_mutex);
 
 	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
-		cpu_dai->playback_active--;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+			cpu_dai->playback_active--;
 		for_each_rtd_codec_dai(rtd, i, codec_dai)
 			codec_dai->playback_active--;
 	} else {
-		cpu_dai->capture_active--;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+			cpu_dai->capture_active--;
 		for_each_rtd_codec_dai(rtd, i, codec_dai)
 			codec_dai->capture_active--;
 	}
 
-	cpu_dai->active--;
-	cpu_dai->component->active--;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		cpu_dai->active--;
+		cpu_dai->component->active--;
+	}
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		codec_dai->component->active--;
 		codec_dai->active--;
@@ -233,7 +241,7 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
 				struct snd_pcm_hw_params *params)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	unsigned int rate, channels, sample_bits, symmetry, i;
 
@@ -242,40 +250,60 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
 	sample_bits = snd_pcm_format_physical_width(params_format(params));
 
 	/* reject unmatched parameters when applying symmetry */
-	symmetry = cpu_dai->driver->symmetric_rates ||
-		rtd->dai_link->symmetric_rates;
+	symmetry = rtd->dai_link->symmetric_rates;
+
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		symmetry |= cpu_dai->driver->symmetric_rates;
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		symmetry |= codec_dai->driver->symmetric_rates;
 
-	if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) {
-		dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
-				cpu_dai->rate, rate);
-		return -EINVAL;
+	if (symmetry) {
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->rate && cpu_dai->rate != rate) {
+				dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",
+					cpu_dai->rate, rate);
+				return -EINVAL;
+			}
+		}
 	}
 
-	symmetry = cpu_dai->driver->symmetric_channels ||
-		rtd->dai_link->symmetric_channels;
+	symmetry = rtd->dai_link->symmetric_channels;
+
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		symmetry |= cpu_dai->driver->symmetric_channels;
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		symmetry |= codec_dai->driver->symmetric_channels;
 
-	if (symmetry && cpu_dai->channels && cpu_dai->channels != channels) {
-		dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
-				cpu_dai->channels, channels);
-		return -EINVAL;
+	if (symmetry) {
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->channels &&
+			    cpu_dai->channels != channels) {
+				dev_err(rtd->dev, "ASoC: unmatched channel symmetry: %d - %d\n",
+					cpu_dai->channels, channels);
+				return -EINVAL;
+			}
+		}
 	}
 
-	symmetry = cpu_dai->driver->symmetric_samplebits ||
-		rtd->dai_link->symmetric_samplebits;
+	symmetry = rtd->dai_link->symmetric_samplebits;
+
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		symmetry |= cpu_dai->driver->symmetric_samplebits;
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		symmetry |= codec_dai->driver->symmetric_samplebits;
 
-	if (symmetry && cpu_dai->sample_bits && cpu_dai->sample_bits != sample_bits) {
-		dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
-				cpu_dai->sample_bits, sample_bits);
-		return -EINVAL;
+	if (symmetry) {
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->sample_bits &&
+			    cpu_dai->sample_bits != sample_bits) {
+				dev_err(rtd->dev, "ASoC: unmatched sample bits symmetry: %d - %d\n",
+					cpu_dai->sample_bits, sample_bits);
+				return -EINVAL;
+			}
+		}
 	}
 
 	return 0;
@@ -284,14 +312,20 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
 static bool soc_pcm_has_symmetry(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai_driver *cpu_driver = rtd->cpu_dai->driver;
 	struct snd_soc_dai_link *link = rtd->dai_link;
 	struct snd_soc_dai *codec_dai;
+	struct snd_soc_dai *cpu_dai;
 	unsigned int symmetry, i;
 
-	symmetry = cpu_driver->symmetric_rates || link->symmetric_rates ||
-		cpu_driver->symmetric_channels || link->symmetric_channels ||
-		cpu_driver->symmetric_samplebits || link->symmetric_samplebits;
+	symmetry = link->symmetric_rates ||
+		link->symmetric_channels ||
+		link->symmetric_samplebits;
+
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		symmetry = symmetry ||
+			cpu_dai->driver->symmetric_rates ||
+			cpu_dai->driver->symmetric_channels ||
+			cpu_dai->driver->symmetric_samplebits;
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		symmetry = symmetry ||
@@ -319,10 +353,10 @@ static void soc_pcm_set_msb(struct snd_pcm_substream *substream, int bits)
 static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i;
-	unsigned int bits = 0, cpu_bits;
+	unsigned int bits = 0, cpu_bits = 0;
 
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
 		for_each_rtd_codec_dai(rtd, i, codec_dai) {
@@ -332,7 +366,14 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
 			}
 			bits = max(codec_dai->driver->playback.sig_bits, bits);
 		}
-		cpu_bits = cpu_dai->driver->playback.sig_bits;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->driver->playback.sig_bits == 0) {
+				cpu_bits = 0;
+				break;
+			}
+			cpu_bits = max(cpu_dai->driver->playback.sig_bits,
+				       bits);
+		}
 	} else {
 		for_each_rtd_codec_dai(rtd, i, codec_dai) {
 			if (codec_dai->driver->capture.sig_bits == 0) {
@@ -341,7 +382,13 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream)
 			}
 			bits = max(codec_dai->driver->capture.sig_bits, bits);
 		}
-		cpu_bits = cpu_dai->driver->capture.sig_bits;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->driver->capture.sig_bits == 0) {
+				cpu_bits = 0;
+				break;
+			}
+			cpu_bits = max(cpu_dai->driver->capture.sig_bits, bits);
+		}
 	}
 
 	soc_pcm_set_msb(substream, bits);
@@ -354,22 +401,40 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
 	struct snd_pcm_hardware *hw = &runtime->hw;
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_dai *codec_dai;
-	struct snd_soc_dai_driver *cpu_dai_drv = rtd->cpu_dai->driver;
+	struct snd_soc_dai *cpu_dai;
+	struct snd_soc_dai_driver *cpu_dai_drv;
 	struct snd_soc_dai_driver *codec_dai_drv;
 	struct snd_soc_pcm_stream *codec_stream;
 	struct snd_soc_pcm_stream *cpu_stream;
 	unsigned int chan_min = 0, chan_max = UINT_MAX;
+	unsigned int cpu_chan_min = 0, cpu_chan_max = UINT_MAX;
 	unsigned int rate_min = 0, rate_max = UINT_MAX;
-	unsigned int rates = UINT_MAX;
+	unsigned int cpu_rate_min = 0, cpu_rate_max = UINT_MAX;
+	unsigned int rates = UINT_MAX, cpu_rates = UINT_MAX;
 	u64 formats = ULLONG_MAX;
 	int i;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		cpu_stream = &cpu_dai_drv->playback;
-	else
-		cpu_stream = &cpu_dai_drv->capture;
+	/* first calculate min/max only for CPUs in the DAI link */
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		if (!snd_soc_dai_stream_valid(cpu_dai,
+					      substream->stream))
+			continue;
 
-	/* first calculate min/max only for CODECs in the DAI link */
+		cpu_dai_drv = cpu_dai->driver;
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			cpu_stream = &cpu_dai_drv->playback;
+		else
+			cpu_stream = &cpu_dai_drv->capture;
+		cpu_chan_min = max(cpu_chan_min, cpu_stream->channels_min);
+		cpu_chan_max = min(cpu_chan_max, cpu_stream->channels_max);
+		cpu_rate_min = max(cpu_rate_min, cpu_stream->rate_min);
+		cpu_rate_max = min_not_zero(cpu_rate_max, cpu_stream->rate_max);
+		formats &= cpu_stream->formats;
+		cpu_rates = snd_pcm_rate_mask_intersect(cpu_stream->rates,
+							cpu_rates);
+	}
+
+	/* second calculate min/max only for CODECs in the DAI link */
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 
 		/*
@@ -400,27 +465,28 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)
 
 	/*
 	 * chan min/max cannot be enforced if there are multiple CODEC DAIs
-	 * connected to a single CPU DAI, use CPU DAI's directly and let
+	 * connected to CPU DAI(s), use CPU DAI's directly and let
 	 * channel allocation be fixed up later
 	 */
 	if (rtd->num_codecs > 1) {
-		chan_min = cpu_stream->channels_min;
-		chan_max = cpu_stream->channels_max;
+		chan_min = cpu_chan_min;
+		chan_max = cpu_chan_max;
 	}
 
-	hw->channels_min = max(chan_min, cpu_stream->channels_min);
-	hw->channels_max = min(chan_max, cpu_stream->channels_max);
+	/* finally find a intersection between CODECs and CPUs */
+	hw->channels_min = max(chan_min, cpu_chan_min);
+	hw->channels_max = min(chan_max, cpu_chan_max);
 	if (hw->formats)
-		hw->formats &= formats & cpu_stream->formats;
+		hw->formats &= formats;
 	else
-		hw->formats = formats & cpu_stream->formats;
-	hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_stream->rates);
+		hw->formats = formats;
+	hw->rates = snd_pcm_rate_mask_intersect(rates, cpu_rates);
 
 	snd_pcm_limit_hw_rates(runtime);
 
-	hw->rate_min = max(hw->rate_min, cpu_stream->rate_min);
+	hw->rate_min = max(hw->rate_min, cpu_rate_min);
 	hw->rate_min = max(hw->rate_min, rate_min);
-	hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max);
+	hw->rate_max = min_not_zero(hw->rate_max, cpu_rate_max);
 	hw->rate_max = min_not_zero(hw->rate_max, rate_max);
 }
 
@@ -482,9 +548,10 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	const char *codec_dai_name = "multicodec";
+	const char *cpu_dai_name = "multicpu";
 	int i, ret = 0;
 
 	for_each_rtd_components(rtd, i, component)
@@ -496,11 +563,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
 
 	/* startup the audio subsystem */
-	ret = snd_soc_dai_startup(cpu_dai, substream);
-	if (ret < 0) {
-		dev_err(cpu_dai->dev, "ASoC: can't open interface %s: %d\n",
-			cpu_dai->name, ret);
-		goto out;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_startup(cpu_dai, substream);
+		if (ret < 0) {
+			dev_err(cpu_dai->dev, "ASoC: can't open interface %s: %d\n",
+				cpu_dai->name, ret);
+			goto interface_err;
+		}
 	}
 
 	ret = soc_pcm_components_open(substream, &component);
@@ -541,34 +610,39 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 	if (rtd->num_codecs == 1)
 		codec_dai_name = rtd->codec_dai->name;
 
+	if (rtd->num_cpus == 1)
+		cpu_dai_name = rtd->cpu_dai->name;
+
 	if (soc_pcm_has_symmetry(substream))
 		runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
 
 	ret = -EINVAL;
 	if (!runtime->hw.rates) {
 		printk(KERN_ERR "ASoC: %s <-> %s No matching rates\n",
-			codec_dai_name, cpu_dai->name);
+			codec_dai_name, cpu_dai_name);
 		goto config_err;
 	}
 	if (!runtime->hw.formats) {
 		printk(KERN_ERR "ASoC: %s <-> %s No matching formats\n",
-			codec_dai_name, cpu_dai->name);
+			codec_dai_name, cpu_dai_name);
 		goto config_err;
 	}
 	if (!runtime->hw.channels_min || !runtime->hw.channels_max ||
 	    runtime->hw.channels_min > runtime->hw.channels_max) {
 		printk(KERN_ERR "ASoC: %s <-> %s No matching channels\n",
-				codec_dai_name, cpu_dai->name);
+				codec_dai_name, cpu_dai_name);
 		goto config_err;
 	}
 
 	soc_pcm_apply_msb(substream);
 
 	/* Symmetry only applies if we've already got an active stream. */
-	if (cpu_dai->active) {
-		ret = soc_pcm_apply_symmetry(substream, cpu_dai);
-		if (ret != 0)
-			goto config_err;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		if (cpu_dai->active) {
+			ret = soc_pcm_apply_symmetry(substream, cpu_dai);
+			if (ret != 0)
+				goto config_err;
+		}
 	}
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
@@ -580,7 +654,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 	}
 
 	pr_debug("ASoC: %s <-> %s info:\n",
-			codec_dai_name, cpu_dai->name);
+		 codec_dai_name, cpu_dai_name);
 	pr_debug("ASoC: rate mask 0x%x\n", runtime->hw.rates);
 	pr_debug("ASoC: min ch %d max ch %d\n", runtime->hw.channels_min,
 		 runtime->hw.channels_max);
@@ -608,8 +682,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 component_err:
 	soc_pcm_components_close(substream, component);
 
-	snd_soc_dai_shutdown(cpu_dai, substream);
-out:
+	i = rtd->num_cpus;
+
+interface_err:
+	for_each_rtd_cpu_dai_rollback(rtd, i, cpu_dai)
+		snd_soc_dai_shutdown(cpu_dai, substream);
+
 	mutex_unlock(&rtd->card->pcm_mutex);
 
 	for_each_rtd_components(rtd, i, component) {
@@ -643,7 +721,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i;
 
@@ -652,17 +730,21 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
 	snd_soc_runtime_deactivate(rtd, substream->stream);
 
 	/* clear the corresponding DAIs rate when inactive */
-	if (!cpu_dai->active)
-		cpu_dai->rate = 0;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		if (!cpu_dai->active)
+			cpu_dai->rate = 0;
+	}
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		if (!codec_dai->active)
 			codec_dai->rate = 0;
 	}
 
-	snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		snd_soc_dai_digital_mute(cpu_dai, 1, substream->stream);
 
-	snd_soc_dai_shutdown(cpu_dai, substream);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		snd_soc_dai_shutdown(cpu_dai, substream);
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		snd_soc_dai_shutdown(codec_dai, substream);
@@ -697,7 +779,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i, ret = 0;
 
@@ -731,11 +813,13 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
 		}
 	}
 
-	ret = snd_soc_dai_prepare(cpu_dai, substream);
-	if (ret < 0) {
-		dev_err(cpu_dai->dev,
-			"ASoC: cpu DAI prepare error: %d\n", ret);
-		goto out;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_prepare(cpu_dai, substream);
+		if (ret < 0) {
+			dev_err(cpu_dai->dev,
+				"ASoC: cpu DAI prepare error: %d\n", ret);
+			goto out;
+		}
 	}
 
 	/* cancel any delayed stream shutdown that is pending */
@@ -751,7 +835,8 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		snd_soc_dai_digital_mute(codec_dai, 0,
 					 substream->stream);
-	snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		snd_soc_dai_digital_mute(cpu_dai, 0, substream->stream);
 
 out:
 	mutex_unlock(&rtd->card->pcm_mutex);
@@ -796,7 +881,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i, ret = 0;
 
@@ -862,17 +947,19 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
 		snd_soc_dapm_update_dai(substream, &codec_params, codec_dai);
 	}
 
-	ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
-	if (ret < 0)
-		goto interface_err;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_hw_params(cpu_dai, substream, params);
+		if (ret < 0)
+			goto interface_err;
 
-	/* store the parameters for each DAIs */
-	cpu_dai->rate = params_rate(params);
-	cpu_dai->channels = params_channels(params);
-	cpu_dai->sample_bits =
-		snd_pcm_format_physical_width(params_format(params));
+		/* store the parameters for each DAI */
+		cpu_dai->rate = params_rate(params);
+		cpu_dai->channels = params_channels(params);
+		cpu_dai->sample_bits =
+			snd_pcm_format_physical_width(params_format(params));
 
-	snd_soc_dapm_update_dai(substream, params, cpu_dai);
+		snd_soc_dapm_update_dai(substream, params, cpu_dai);
+	}
 
 	for_each_rtd_components(rtd, i, component) {
 		ret = snd_soc_component_hw_params(component, substream, params);
@@ -892,10 +979,17 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
 component_err:
 	soc_pcm_components_hw_free(substream, component);
 
-	snd_soc_dai_hw_free(cpu_dai, substream);
-	cpu_dai->rate = 0;
+	i = rtd->num_cpus;
 
 interface_err:
+	for_each_rtd_cpu_dai_rollback(rtd, i, cpu_dai) {
+		if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
+			continue;
+
+		snd_soc_dai_hw_free(cpu_dai, substream);
+		cpu_dai->rate = 0;
+	}
+
 	i = rtd->num_codecs;
 
 codec_err:
@@ -920,20 +1014,23 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
 static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	bool playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
 	int i;
 
 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
 
-	/* clear the corresponding DAIs parameters when going to be inactive */
-	if (cpu_dai->active == 1) {
-		cpu_dai->rate = 0;
-		cpu_dai->channels = 0;
-		cpu_dai->sample_bits = 0;
+	/* clear all CPU DAIs parameters when inactive */
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		if (cpu_dai->active == 1) {
+			cpu_dai->rate = 0;
+			cpu_dai->channels = 0;
+			cpu_dai->sample_bits = 0;
+		}
 	}
 
+	/* clear all CODEC DAIs parameters when inactive */
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		if (codec_dai->active == 1) {
 			codec_dai->rate = 0;
@@ -965,7 +1062,12 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
 		snd_soc_dai_hw_free(codec_dai, substream);
 	}
 
-	snd_soc_dai_hw_free(cpu_dai, substream);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		if (!snd_soc_dai_stream_valid(cpu_dai, substream->stream))
+			continue;
+
+		snd_soc_dai_hw_free(cpu_dai, substream);
+	}
 
 	mutex_unlock(&rtd->card->pcm_mutex);
 	return 0;
@@ -975,7 +1077,7 @@ static int soc_pcm_trigger_start(struct snd_pcm_substream *substream, int cmd)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i, ret;
 
@@ -991,9 +1093,11 @@ static int soc_pcm_trigger_start(struct snd_pcm_substream *substream, int cmd)
 			return ret;
 	}
 
-	ret = snd_soc_dai_trigger(cpu_dai, substream, cmd);
-	if (ret < 0)
-		return ret;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_trigger(cpu_dai, substream, cmd);
+		if (ret < 0)
+			return ret;
+	}
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		ret = snd_soc_dai_trigger(codec_dai, substream, cmd);
@@ -1008,7 +1112,7 @@ static int soc_pcm_trigger_stop(struct snd_pcm_substream *substream, int cmd)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_component *component;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i, ret;
 
@@ -1018,9 +1122,11 @@ static int soc_pcm_trigger_stop(struct snd_pcm_substream *substream, int cmd)
 			return ret;
 	}
 
-	ret = snd_soc_dai_trigger(cpu_dai, substream, cmd);
-	if (ret < 0)
-		return ret;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_trigger(cpu_dai, substream, cmd);
+		if (ret < 0)
+			return ret;
+	}
 
 	for_each_rtd_components(rtd, i, component) {
 		ret = snd_soc_component_trigger(component, substream, cmd);
@@ -1063,7 +1169,7 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
 				   int cmd)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	int i, ret;
 
@@ -1073,9 +1179,11 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
 			return ret;
 	}
 
-	ret = snd_soc_dai_bespoke_trigger(cpu_dai, substream, cmd);
-	if (ret < 0)
-		return ret;
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		ret = snd_soc_dai_bespoke_trigger(cpu_dai, substream, cmd);
+		if (ret < 0)
+			return ret;
+	}
 
 	return 0;
 }
@@ -1087,12 +1195,13 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
 static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
 {
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_dai *codec_dai;
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	snd_pcm_uframes_t offset = 0;
 	snd_pcm_sframes_t delay = 0;
 	snd_pcm_sframes_t codec_delay = 0;
+	snd_pcm_sframes_t cpu_delay = 0;
 	int i;
 
 	/* clearing the previous total delay */
@@ -1103,7 +1212,11 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
 	/* base delay if assigned in pointer callback */
 	delay = runtime->delay;
 
-	delay += snd_soc_dai_delay(cpu_dai, substream);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		cpu_delay = max(cpu_delay,
+				snd_soc_dai_delay(cpu_dai, substream));
+	}
+	delay += cpu_delay;
 
 	for_each_rtd_codec_dai(rtd, i, codec_dai) {
 		codec_delay = max(codec_delay,
@@ -1229,6 +1342,7 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
 {
 	struct snd_soc_pcm_runtime *be;
 	struct snd_soc_dai *dai;
+	struct snd_soc_dai *cpu_dai;
 	int i;
 
 	dev_dbg(card->dev, "ASoC: find BE for widget %s\n", widget->name);
@@ -1239,12 +1353,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
 			if (!be->dai_link->no_pcm)
 				continue;
 
-			dev_dbg(card->dev, "ASoC: try BE : %s\n",
-				be->cpu_dai->playback_widget ?
-				be->cpu_dai->playback_widget->name : "(not set)");
+			for_each_rtd_cpu_dai(be, i, cpu_dai) {
+				dev_dbg(card->dev, "ASoC: try BE : %s\n",
+					cpu_dai->playback_widget ?
+					cpu_dai->playback_widget->name :
+					"(not set)");
 
-			if (be->cpu_dai->playback_widget == widget)
-				return be;
+				if (cpu_dai->playback_widget == widget)
+					return be;
+			}
 
 			for_each_rtd_codec_dai(be, i, dai) {
 				if (dai->playback_widget == widget)
@@ -1258,12 +1375,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,
 			if (!be->dai_link->no_pcm)
 				continue;
 
-			dev_dbg(card->dev, "ASoC: try BE %s\n",
-				be->cpu_dai->capture_widget ?
-				be->cpu_dai->capture_widget->name : "(not set)");
+			for_each_rtd_cpu_dai(be, i, cpu_dai) {
+				dev_dbg(card->dev, "ASoC: try BE %s\n",
+					cpu_dai->capture_widget ?
+					cpu_dai->capture_widget->name :
+					"(not set)");
 
-			if (be->cpu_dai->capture_widget == widget)
-				return be;
+				if (cpu_dai->capture_widget == widget)
+					return be;
+			}
 
 			for_each_rtd_codec_dai(be, i, dai) {
 				if (dai->capture_widget == widget)
@@ -1313,8 +1433,10 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
 			if (!rtd->dai_link->no_pcm)
 				continue;
 
-			if (rtd->cpu_dai->playback_widget == widget)
-				return true;
+			for_each_rtd_cpu_dai(rtd, i, dai) {
+				if (dai->playback_widget == widget)
+					return true;
+			}
 
 			for_each_rtd_codec_dai(rtd, i, dai) {
 				if (dai->playback_widget == widget)
@@ -1326,8 +1448,10 @@ static bool dpcm_end_walk_at_be(struct snd_soc_dapm_widget *widget,
 			if (!rtd->dai_link->no_pcm)
 				continue;
 
-			if (rtd->cpu_dai->capture_widget == widget)
-				return true;
+			for_each_rtd_cpu_dai(rtd, i, dai) {
+				if (dai->capture_widget == widget)
+					return true;
+			}
 
 			for_each_rtd_codec_dai(rtd, i, dai) {
 				if (dai->capture_widget == widget)
@@ -1370,10 +1494,18 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,
 		unsigned int i;
 
 		/* is there a valid CPU DAI widget for this BE */
-		widget = dai_get_widget(dpcm->be->cpu_dai, stream);
+		do_prune = 1;
+		for_each_rtd_cpu_dai(dpcm->be, i, dai) {
+			widget = dai_get_widget(dai, stream);
 
-		/* prune the BE if it's no longer in our active list */
-		if (widget && widget_in_list(list, widget))
+			/*
+			 * The BE is pruned only if none of the cpu_dai
+			 * widgets are in the active list.
+			 */
+			if (widget && widget_in_list(list, widget))
+				do_prune = 0;
+		}
+		if (!do_prune)
 			continue;
 
 		/* is there a valid CODEC DAI widget for this BE */
@@ -1672,18 +1804,32 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,
 
 	for_each_dpcm_be(fe, stream, dpcm) {
 		struct snd_soc_pcm_runtime *be = dpcm->be;
-		struct snd_soc_dai_driver *cpu_dai_drv =  be->cpu_dai->driver;
+		struct snd_soc_dai_driver *cpu_dai_drv;
 		struct snd_soc_dai_driver *codec_dai_drv;
 		struct snd_soc_pcm_stream *codec_stream;
 		struct snd_soc_pcm_stream *cpu_stream;
+		struct snd_soc_dai *dai;
+		int i;
 
-		if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-			cpu_stream = &cpu_dai_drv->playback;
-		else
-			cpu_stream = &cpu_dai_drv->capture;
+		for_each_rtd_cpu_dai(be, i, dai) {
+			/*
+			 * Skip CPUs which don't support the current stream
+			 * type. See soc_pcm_init_runtime_hw() for more details
+			 */
+			if (!snd_soc_dai_stream_valid(dai, stream))
+				continue;
 
-		*channels_min = max(*channels_min, cpu_stream->channels_min);
-		*channels_max = min(*channels_max, cpu_stream->channels_max);
+			cpu_dai_drv =  dai->driver;
+			if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+				cpu_stream = &cpu_dai_drv->playback;
+			else
+				cpu_stream = &cpu_dai_drv->capture;
+
+			*channels_min = max(*channels_min,
+					    cpu_stream->channels_min);
+			*channels_max = min(*channels_max,
+					    cpu_stream->channels_max);
+		}
 
 		/*
 		 * chan min/max cannot be enforced if there are multiple CODEC
@@ -1724,21 +1870,33 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
 
 	for_each_dpcm_be(fe, stream, dpcm) {
 		struct snd_soc_pcm_runtime *be = dpcm->be;
-		struct snd_soc_dai_driver *cpu_dai_drv =  be->cpu_dai->driver;
+		struct snd_soc_dai_driver *cpu_dai_drv;
 		struct snd_soc_dai_driver *codec_dai_drv;
 		struct snd_soc_pcm_stream *codec_stream;
 		struct snd_soc_pcm_stream *cpu_stream;
 		struct snd_soc_dai *dai;
 		int i;
 
-		if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-			cpu_stream = &cpu_dai_drv->playback;
-		else
-			cpu_stream = &cpu_dai_drv->capture;
+		for_each_rtd_cpu_dai(be, i, dai) {
+			/*
+			 * Skip CPUs which don't support the current stream
+			 * type. See soc_pcm_init_runtime_hw() for more details
+			 */
+			if (!snd_soc_dai_stream_valid(dai, stream))
+				continue;
 
-		*rate_min = max(*rate_min, cpu_stream->rate_min);
-		*rate_max = min_not_zero(*rate_max, cpu_stream->rate_max);
-		*rates = snd_pcm_rate_mask_intersect(*rates, cpu_stream->rates);
+			cpu_dai_drv =  dai->driver;
+			if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+				cpu_stream = &cpu_dai_drv->playback;
+			else
+				cpu_stream = &cpu_dai_drv->capture;
+
+			*rate_min = max(*rate_min, cpu_stream->rate_min);
+			*rate_max = min_not_zero(*rate_max,
+						 cpu_stream->rate_max);
+			*rates = snd_pcm_rate_mask_intersect(*rates,
+						cpu_stream->rates);
+		}
 
 		for_each_rtd_codec_dai(be, i, dai) {
 			/*
@@ -1767,13 +1925,17 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
+	struct snd_soc_dai *cpu_dai;
+	struct snd_soc_dai_driver *cpu_dai_drv;
+	int i;
 
-	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback);
-	else
-		dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+		cpu_dai_drv = cpu_dai->driver;
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			dpcm_init_runtime_hw(runtime, &cpu_dai_drv->playback);
+		else
+			dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture);
+	}
 
 	dpcm_runtime_merge_format(substream, &runtime->hw.formats);
 	dpcm_runtime_merge_chan(substream, &runtime->hw.channels_min,
@@ -1810,18 +1972,22 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
 {
 	struct snd_soc_dpcm *dpcm;
 	struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
-	struct snd_soc_dai *fe_cpu_dai = fe->cpu_dai;
+	struct snd_soc_dai *fe_cpu_dai;
 	int err;
+	int i;
 
 	/* apply symmetry for FE */
 	if (soc_pcm_has_symmetry(fe_substream))
 		fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
 
 	/* Symmetry only applies if we've got an active stream. */
-	if (fe_cpu_dai->active) {
-		err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
-		if (err < 0)
-			return err;
+	/* Do we need to support Multi cpu for FE? */
+	for_each_rtd_cpu_dai(fe, i, fe_cpu_dai) {
+		if (fe_cpu_dai->active) {
+			err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
+			if (err < 0)
+				return err;
+		}
 	}
 
 	/* apply symmetry for BE */
@@ -1831,6 +1997,7 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
 			snd_soc_dpcm_get_substream(be, stream);
 		struct snd_soc_pcm_runtime *rtd;
 		struct snd_soc_dai *codec_dai;
+		struct snd_soc_dai *cpu_dai;
 		int i;
 
 		/* A backend may not have the requested substream */
@@ -1845,11 +2012,13 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
 			be_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
 
 		/* Symmetry only applies if we've got an active stream. */
-		if (rtd->cpu_dai->active) {
-			err = soc_pcm_apply_symmetry(fe_substream,
-						     rtd->cpu_dai);
-			if (err < 0)
-				return err;
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (cpu_dai->active) {
+				err = soc_pcm_apply_symmetry(fe_substream,
+							     cpu_dai);
+				if (err < 0)
+					return err;
+			}
 		}
 
 		for_each_rtd_codec_dai(rtd, i, codec_dai) {
@@ -2836,7 +3005,7 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 {
 	struct snd_soc_dai *codec_dai;
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+	struct snd_soc_dai *cpu_dai;
 	struct snd_soc_component *component;
 	struct snd_pcm *pcm;
 	char new_name[64];
@@ -2847,23 +3016,33 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 		playback = rtd->dai_link->dpcm_playback;
 		capture = rtd->dai_link->dpcm_capture;
 	} else {
+		int stream_playback;
+		int stream_capture;
 		/* Adapt stream for codec2codec links */
-		struct snd_soc_pcm_stream *cpu_capture = rtd->dai_link->params ?
-			&cpu_dai->driver->playback : &cpu_dai->driver->capture;
-		struct snd_soc_pcm_stream *cpu_playback = rtd->dai_link->params ?
-			&cpu_dai->driver->capture : &cpu_dai->driver->playback;
+		if (rtd->dai_link->params) {
+			stream_playback = SNDRV_PCM_STREAM_CAPTURE;
+			stream_capture  = SNDRV_PCM_STREAM_PLAYBACK;
+		} else {
+			stream_playback = SNDRV_PCM_STREAM_PLAYBACK;
+			stream_capture  = SNDRV_PCM_STREAM_CAPTURE;
+		}
 
-		for_each_rtd_codec_dai(rtd, i, codec_dai) {
-			if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
-			    snd_soc_dai_stream_valid(cpu_dai,   SNDRV_PCM_STREAM_PLAYBACK))
-				playback = 1;
-			if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) &&
-			    snd_soc_dai_stream_valid(cpu_dai,   SNDRV_PCM_STREAM_CAPTURE))
-				capture = 1;
+		playback = 1;
+		capture = 1;
+
+		for_each_rtd_cpu_dai(rtd, i, cpu_dai) {
+			if (!snd_soc_dai_stream_valid(cpu_dai, stream_playback))
+				playback = 0;
+			if (!snd_soc_dai_stream_valid(cpu_dai, stream_capture))
+				capture = 0;
 		}
 
-		capture = capture && cpu_capture->channels_min;
-		playback = playback && cpu_playback->channels_min;
+		for_each_rtd_codec_dai(rtd, i, codec_dai) {
+			if (!snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK))
+				playback = 0;
+			if (!snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE))
+				capture = 0;
+		}
 	}
 
 	if (rtd->dai_link->playback_only) {
@@ -2977,7 +3156,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 out:
 	dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
 		 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
-		 cpu_dai->name);
+		 (rtd->num_cpus > 1) ? "multicpu" : rtd->cpu_dai->name);
 	return ret;
 }
 
Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#3 lore raw

Re: [alsa-devel] [PATCH RFC v2 2/4] ASoC: Add multiple CPU DAI support for PCM ops

Quoted 16 lines
sound/soc/soc-pcm.c +2 -2
@@ -1810,18 +1972,22 @@ static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,
  {
  	struct snd_soc_dpcm *dpcm;
  	struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
-	struct snd_soc_dai *fe_cpu_dai = fe->cpu_dai;
+	struct snd_soc_dai *fe_cpu_dai;
  	int err;
+	int i;
 
  	/* apply symmetry for FE */
  	if (soc_pcm_has_symmetry(fe_substream))
  		fe_substream->runtime->hw.info |= SNDRV_PCM_INFO_JOINT_DUPLEX;
 
  	/* Symmetry only applies if we've got an active stream. */
-	if (fe_cpu_dai->active) {

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, · line 1990

Quoted 10 lines
sound/soc/soc-pcm.c +7 -3
-		err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
-		if (err < 0)
-			return err;
+	/* Do we need to support Multi cpu for FE? */
+	for_each_rtd_cpu_dai(fe, i, fe_cpu_dai) {
+		if (fe_cpu_dai->active) {
+			err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
+			if (err < 0)
+				return err;
+		}

that part seems inconsistent with Patch 4 where you add warnings/error everywhere there's a FE with num_cpus>1
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#4 lore raw

Re: [alsa-devel] [PATCH RFC v2 2/4] ASoC: Add multiple CPU DAI support for PCM ops

Quoted 36 lines

-----Original Message-----
From: Pierre-Louis Bossart [mailto:[email protected]]
Sent: Thursday, January 16, 2020 9:48 AM
To: Bard liao <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Liao, Bard <[email protected]>
Subject: Re: [alsa-devel] [PATCH RFC v2 2/4] ASoC: Add multiple CPU DAI support for PCM ops

Review static int dpcm_apply_symmetry(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -1810,18 +1972,22 @@ static int dpcm_apply_symmetry(struct

snd_pcm_substream *fe_substream,

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,

Quoted 11 lines
sound/soc/soc-pcm.c +2 -1
  {
  	struct snd_soc_dpcm *dpcm;
  	struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
-	struct snd_soc_dai *fe_cpu_dai = fe->cpu_dai;
+	struct snd_soc_dai *fe_cpu_dai;
  	int err;
+	int i;
 
  	/* apply symmetry for FE */
  	if (soc_pcm_has_symmetry(fe_substream))
  		fe_substream->runtime->hw.info |=

SNDRV_PCM_INFO_JOINT_DUPLEX;

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,

Quoted 10 lines
sound/soc/soc-pcm.c +4 -4
  	/* Symmetry only applies if we've got an active stream. */
-	if (fe_cpu_dai->active) {
-		err = soc_pcm_apply_symmetry(fe_substream, fe_cpu_dai);
-		if (err < 0)
-			return err;
+	/* Do we need to support Multi cpu for FE? */
+	for_each_rtd_cpu_dai(fe, i, fe_cpu_dai) {
+		if (fe_cpu_dai->active) {
+			err = soc_pcm_apply_symmetry(fe_substream,

fe_cpu_dai);

Quoted 6 lines

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, · line 1990

Quoted 3 lines
sound/soc/soc-pcm.c +3 -0
+			if (err < 0)
+				return err;
+		}

that part seems inconsistent with Patch 4 where you add warnings/error everywhere there's a FE with num_cpus>1

Actually, I have a question here. Do we need to support Multi cpu for FE? If yes, what is the use case?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw

Re: [alsa-devel] [PATCH RFC v2 2/4] ASoC: Add multiple CPU DAI support for PCM ops

Quoted 13 lines
Quoted 6 lines

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream,

Quoted 5 lines
sound/soc/soc-pcm.c +4 -0
+	/* Do we need to support Multi cpu for FE? */
+	for_each_rtd_cpu_dai(fe, i, fe_cpu_dai) {
+		if (fe_cpu_dai->active) {
+			err = soc_pcm_apply_symmetry(fe_substream,

fe_cpu_dai);

Quoted 6 lines

sound/soc/soc-pcm.c static int dpcm_apply_symmetry(struct snd_pcm_substream *fe_substream, · line 1990

Quoted 3 lines
sound/soc/soc-pcm.c +3 -0
+			if (err < 0)
+				return err;
+		}

that part seems inconsistent with Patch 4 where you add warnings/error everywhere there's a FE with num_cpus>1

Quoted 2 lines

Actually, I have a question here. Do we need to support Multi cpu for FE? If yes, what is the use case?

I can't think of any case where we'd need a multi-cpu FE, and if you look at the existing code it doesn't look possible:

we have code in soc-dapm.c that checks that num_cpus==num_codecs and flags an error if you had 2 cpu_dais and 1 codec_dai.

And if you continue with soc-topology, we have hard-coded num_cpus = 1; and num_codecs = 1; for topology-created FE dailinks.

In other words, we'd a major topology change to support a multi-cpu FE, quite unlikely for now.

The multi-cpu representation is IMO only needed for specific hardware setups, just like the multi-codec part is tied to TDM usages.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author
#6 lore raw

RFC PATCH v2 3/4 ASoC: Add multiple CPU DAI support in DAPM

In reply to Bard liao

From: Shreyas NC <[email protected]>

DAPM handles DAIs during soc_dapm_stream_event() and during addition and creation of DAI widgets i.e., dapm_add_valid_dai_widget() and dapm_connect_dai_link_widgets().

Extend these functions to handle multiple cpu dai.

---
 sound/soc/soc-dapm.c | 131 +++++++++++++++++++++++++------------------
 1 file changed, 75 insertions(+), 56 deletions(-)
sound/soc/soc-dapm.c +75 -56
index 442846f12cd4..7a0538b45faf 100644
@@ -4274,16 +4274,15 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card)
 	return 0;
 }
 
-static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
-					  struct snd_soc_pcm_runtime *rtd)
+static void dapm_add_valid_dai_widget(struct snd_soc_card *card,
+				      struct snd_soc_pcm_runtime *rtd,
+				      struct snd_soc_dai *codec_dai,
+				      struct snd_soc_dai *cpu_dai)
 {
-	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-	struct snd_soc_dai *codec_dai;
 	struct snd_soc_dapm_widget *playback = NULL, *capture = NULL;
 	struct snd_soc_dapm_widget *codec, *playback_cpu, *capture_cpu;
 	struct snd_pcm_substream *substream;
 	struct snd_pcm_str *streams = rtd->pcm->streams;
-	int i;
 
 	if (rtd->dai_link->params) {
 		playback_cpu = cpu_dai->capture_widget;
@@ -4295,64 +4294,82 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
 		capture_cpu = capture;
 	}
 
-	for_each_rtd_codec_dai(rtd, i, codec_dai) {
-		/* connect BE DAI playback if widgets are valid */
-		codec = codec_dai->playback_widget;
-
-		if (playback_cpu && codec) {
-			if (!playback) {
-				substream = streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
-				playback = snd_soc_dapm_new_dai(card, substream,
-								"playback");
-				if (IS_ERR(playback)) {
-					dev_err(rtd->dev,
-						"ASoC: Failed to create DAI %s: %ld\n",
-						codec_dai->name,
-						PTR_ERR(playback));
-					continue;
-				}
-
-				snd_soc_dapm_add_path(&card->dapm, playback_cpu,
-						      playback, NULL, NULL);
+	/* connect BE DAI playback if widgets are valid */
+	codec = codec_dai->playback_widget;
+
+	if (playback_cpu && codec) {
+		if (!playback) {
+			substream = streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
+			playback = snd_soc_dapm_new_dai(card, substream,
+							"playback");
+			if (IS_ERR(playback)) {
+				dev_err(rtd->dev,
+					"ASoC: Failed to create DAI %s: %ld\n",
+					codec_dai->name,
+					PTR_ERR(playback));
+				return;
 			}
 
-			dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
-				cpu_dai->component->name, playback_cpu->name,
-				codec_dai->component->name, codec->name);
-
-			snd_soc_dapm_add_path(&card->dapm, playback, codec,
-					      NULL, NULL);
+			snd_soc_dapm_add_path(&card->dapm, playback_cpu,
+					      playback, NULL, NULL);
 		}
+
+		dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
+			cpu_dai->component->name, playback_cpu->name,
+			codec_dai->component->name, codec->name);
+
+		snd_soc_dapm_add_path(&card->dapm, playback, codec,
+				      NULL, NULL);
 	}
 
-	for_each_rtd_codec_dai(rtd, i, codec_dai) {
-		/* connect BE DAI capture if widgets are valid */
-		codec = codec_dai->capture_widget;
-
-		if (codec && capture_cpu) {
-			if (!capture) {
-				substream = streams[SNDRV_PCM_STREAM_CAPTURE].substream;
-				capture = snd_soc_dapm_new_dai(card, substream,
-							       "capture");
-				if (IS_ERR(capture)) {
-					dev_err(rtd->dev,
-						"ASoC: Failed to create DAI %s: %ld\n",
-						codec_dai->name,
-						PTR_ERR(capture));
-					continue;
-				}
-
-				snd_soc_dapm_add_path(&card->dapm, capture,
-						      capture_cpu, NULL, NULL);
-			}
+	/* connect BE DAI capture if widgets are valid */
+	codec = codec_dai->capture_widget;
 
-			dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
-				codec_dai->component->name, codec->name,
-				cpu_dai->component->name, capture_cpu->name);
+	if (codec && capture_cpu) {
+		if (!capture) {
+			substream = streams[SNDRV_PCM_STREAM_CAPTURE].substream;
+			capture = snd_soc_dapm_new_dai(card, substream,
+						       "capture");
+			if (IS_ERR(capture)) {
+				dev_err(rtd->dev,
+					"ASoC: Failed to create DAI %s: %ld\n",
+					codec_dai->name,
+					PTR_ERR(capture));
+				return;
+			}
 
-			snd_soc_dapm_add_path(&card->dapm, codec, capture,
-					      NULL, NULL);
+			snd_soc_dapm_add_path(&card->dapm, capture,
+					      capture_cpu, NULL, NULL);
 		}
+
+		dev_dbg(rtd->dev, "connected DAI link %s:%s -> %s:%s\n",
+			codec_dai->component->name, codec->name,
+			cpu_dai->component->name, capture_cpu->name);
+
+		snd_soc_dapm_add_path(&card->dapm, codec, capture,
+				      NULL, NULL);
+	}
+}
+
+static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,
+					  struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_dai *codec_dai;
+	int i;
+
+	if (rtd->num_cpus > 1) {
+		if (rtd->num_codecs == rtd->num_cpus)
+			for_each_rtd_codec_dai(rtd, i, codec_dai)
+				dapm_add_valid_dai_widget(card, rtd,
+							  codec_dai,
+							  rtd->cpu_dais[i]);
+		else
+			dev_err(card->dev,
+				"N cpus to M codecs link is not supported yet\n");
+	} else {
+		for_each_rtd_codec_dai(rtd, i, codec_dai)
+			dapm_add_valid_dai_widget(card, rtd,
+						  codec_dai, rtd->cpu_dais[0]);
 	}
 }
 
@@ -4417,9 +4434,11 @@ static void soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,
 	int event)
 {
 	struct snd_soc_dai *codec_dai;
+	struct snd_soc_dai *cpu_dai;
 	int i;
 
-	soc_dapm_dai_stream_event(rtd->cpu_dai, stream, event);
+	for_each_rtd_cpu_dai(rtd, i, cpu_dai)
+		soc_dapm_dai_stream_event(cpu_dai, stream, event);
 	for_each_rtd_codec_dai(rtd, i, codec_dai)
 		soc_dapm_dai_stream_event(codec_dai, stream, event);
 
Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
author
#7 lore raw

RFC PATCH v2 4/4 ASoC: add warning if the function is not support multi cpu yet.

In reply to Bard liao

Multi cpu is not supported by all functions yet. Add a warning message to warn it.

---
 sound/soc/soc-compress.c              |  7 ++++---
 sound/soc/soc-generic-dmaengine-pcm.c | 12 ++++++++++++
 sound/soc/soc-pcm.c                   | 12 ++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
sound/soc/soc-compress.c +4 -3
index 223cd045719e..bf9d6a21bcd9 100644
@@ -810,10 +810,11 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
 	int playback = 0, capture = 0;
 	int i;
 
-	if (rtd->num_codecs > 1) {
+	if (rtd->num_cpus > 1 ||
+	    rtd->num_codecs) {
 		dev_err(rtd->card->dev,
-			"Compress ASoC: Multicodec not supported\n");
-		return -EINVAL;
+			"Compress ASoC: Multi CPU/Codec not supported\n");
+		return -ENOTSUPP;
 	}
 
 	/* check client and interface hw capabilities */
sound/soc/soc-generic-dmaengine-pcm.c +12 -0
index df57ec47ad60..a6c8623d03be 100644
@@ -62,6 +62,10 @@ int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
 	struct snd_dmaengine_dai_dma_data *dma_data;
 	int ret;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 
 	ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
@@ -119,6 +123,10 @@ dmaengine_pcm_set_runtime_hwparams(struct snd_soc_component *component,
 	struct snd_pcm_hardware hw;
 	int ret;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	if (pcm->config && pcm->config->pcm_hardware)
 		return snd_soc_set_runtime_hwparams(substream,
 				pcm->config->pcm_hardware);
@@ -183,6 +191,10 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel(
 	struct snd_dmaengine_dai_dma_data *dma_data;
 	dma_filter_fn fn = NULL;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 
 	if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) && pcm->chan[0])
sound/soc/soc-pcm.c +12 -0
index 52c6f3c3ab63..e16af8effffa 100644
@@ -1469,6 +1469,10 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
 	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
 	int paths;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	/* get number of valid DAI paths and their widgets */
 	paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
 			dpcm_end_walk_at_be);
@@ -2812,6 +2816,10 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
 	struct snd_soc_dapm_widget_list *list;
 	int count, paths;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	if (!fe->dai_link->dynamic)
 		return 0;
 
@@ -3368,6 +3376,10 @@ static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
 	ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
 	char *buf;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+
 	buf = kmalloc(out_count, GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
Signature · 6 lines
2.17.1

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#8 lore raw

Re: [alsa-devel] [PATCH RFC v2 4/4] ASoC: add warning if the function is not support multi cpu yet.

Quoted 2 lines · Bard liao

Multi cpu is not supported by all functions yet. Add a warning message to warn it.

Shouldn't we be consistent and return an error when we have an unexpected number of cpu dais? see below

Quoted 15 lines
---
  sound/soc/soc-compress.c              |  7 ++++---
  sound/soc/soc-generic-dmaengine-pcm.c | 12 ++++++++++++
  sound/soc/soc-pcm.c                   | 12 ++++++++++++
  3 files changed, 28 insertions(+), 3 deletions(-)
sound/soc/soc-compress.c +0 -0
index 223cd045719e..bf9d6a21bcd9 100644
@@ -810,10 +810,11 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num)
  	int playback = 0, capture = 0;

sound/soc/soc-compress.c int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) · line 817

Quoted 10 lines
sound/soc/soc-compress.c +4 -3
  	int i;
 
-	if (rtd->num_codecs > 1) {
+	if (rtd->num_cpus > 1 ||
+	    rtd->num_codecs) {
  		dev_err(rtd->card->dev,
-			"Compress ASoC: Multicodec not supported\n");
-		return -EINVAL;
+			"Compress ASoC: Multi CPU/Codec not supported\n");
+		return -ENOTSUPP;

so this is an error...

Quoted 8 lines
sound/soc/soc-compress.c +0 -0
  	}
 
  	/* check client and interface hw capabilities */
sound/soc/soc-generic-dmaengine-pcm.c +0 -0
index df57ec47ad60..a6c8623d03be 100644

sound/soc/soc-generic-dmaengine-pcm.c int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream, · line 68

Quoted 7 lines
sound/soc/soc-generic-dmaengine-pcm.c +4 -0
@@ -62,6 +62,10 @@ int snd_dmaengine_pcm_prepare_slave_config(struct snd_pcm_substream *substream,
  	struct snd_dmaengine_dai_dma_data *dma_data;
  	int ret;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+

but here a warning...

sound/soc/soc-generic-dmaengine-pcm.c dmaengine_pcm_set_runtime_hwparams(struct snd_soc_component *component, · line 129

Quoted 11 lines
sound/soc/soc-generic-dmaengine-pcm.c +4 -0
  	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 
  	ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
@@ -119,6 +123,10 @@ dmaengine_pcm_set_runtime_hwparams(struct snd_soc_component *component,
  	struct snd_pcm_hardware hw;
  	int ret;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+

and a warning here as well

sound/soc/soc-generic-dmaengine-pcm.c static struct dma_chan *dmaengine_pcm_compat_request_channel( · line 197

Quoted 11 lines
sound/soc/soc-generic-dmaengine-pcm.c +4 -0
  	if (pcm->config && pcm->config->pcm_hardware)
  		return snd_soc_set_runtime_hwparams(substream,
  				pcm->config->pcm_hardware);
@@ -183,6 +191,10 @@ static struct dma_chan *dmaengine_pcm_compat_request_channel(
  	struct snd_dmaengine_dai_dma_data *dma_data;
  	dma_filter_fn fn = NULL;
 
+	if (rtd->num_cpus > 1)
+		dev_warn(rtd->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+

warning again...

Quoted 8 lines
sound/soc/soc-generic-dmaengine-pcm.c +0 -0
  	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
 
  	if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) && pcm->chan[0])
sound/soc/soc-pcm.c +0 -0
index 52c6f3c3ab63..e16af8effffa 100644

sound/soc/soc-pcm.c int dpcm_path_get(struct snd_soc_pcm_runtime *fe, · line 1475

Quoted 7 lines
sound/soc/soc-pcm.c +4 -0
@@ -1469,6 +1469,10 @@ int dpcm_path_get(struct snd_soc_pcm_runtime *fe,
  	struct snd_soc_dai *cpu_dai = fe->cpu_dai;
  	int paths;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+

and warning again...

sound/soc/soc-pcm.c static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new) · line 2821

Quoted 10 lines
sound/soc/soc-pcm.c +3 -0
  	/* get number of valid DAI paths and their widgets */
  	paths = snd_soc_dapm_dai_get_connected_widgets(cpu_dai, stream, list,
  			dpcm_end_walk_at_be);
@@ -2812,6 +2816,10 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
  	struct snd_soc_dapm_widget_list *list;
  	int count, paths;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__ > +

warning

sound/soc/soc-pcm.c static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf, · line 3382

Quoted 11 lines
sound/soc/soc-pcm.c +4 -0
  	if (!fe->dai_link->dynamic)
  		return 0;
 
@@ -3368,6 +3376,10 @@ static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,
  	ssize_t out_count = PAGE_SIZE, offset = 0, ret = 0;
  	char *buf;
 
+	if (fe->num_cpus > 1)
+		dev_warn(fe->dev,
+			 "%s doesn't support Multi CPU yet\n", __func__);
+

warning

sound/soc/soc-pcm.c static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf, · line 3385

Quoted 4 lines
sound/soc/soc-pcm.c +0 -0
  	buf = kmalloc(out_count, GFP_KERNEL);
  	if (!buf)
  		return -ENOMEM;

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#9 lore raw

Re: [alsa-devel] [PATCH RFC v2 4/4] ASoC: add warning if the function is not support multi cpu yet.

Quoted 39 lines

-----Original Message-----
From: Pierre-Louis Bossart [mailto:[email protected]]
Sent: Thursday, January 16, 2020 9:50 AM
To: Bard liao <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; Liao, Bard <[email protected]>; [email protected]
Subject: Re: [alsa-devel] [PATCH RFC v2 4/4] ASoC: add warning if the function is not support multi cpu yet.

Quoted 2 lines · Bard liao

Multi cpu is not supported by all functions yet. Add a warning message to warn it.

Shouldn't we be consistent and return an error when we have an unexpected number of cpu dais? see below

sound/soc/soc-compress.c int snd_soc_new_compress(struct

Quoted 14 lines
---
  sound/soc/soc-compress.c              |  7 ++++---
  sound/soc/soc-generic-dmaengine-pcm.c | 12 ++++++++++++
  sound/soc/soc-pcm.c                   | 12 ++++++++++++
  3 files changed, 28 insertions(+), 3 deletions(-)
sound/soc/soc-compress.c index renamed from sound/soc/soc-compress.c +0 -0

223cd045719e..bf9d6a21bcd9 100644

sound/soc/soc-compress.c +0 -0
@@ -810,10 +810,11 @@ int snd_soc_new_compress(struct

snd_soc_pcm_runtime *rtd, int num)

Quoted 3 lines
sound/soc/soc-compress.c +0 -0
  	int playback = 0, capture = 0;
  	int i;
 
Quoted 10 lines

sound/soc/soc-compress.c int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) · line 817

Quoted 8 lines
sound/soc/soc-compress.c +4 -3
-	if (rtd->num_codecs > 1) {
+	if (rtd->num_cpus > 1 ||
+	    rtd->num_codecs) {
  		dev_err(rtd->card->dev,
-			"Compress ASoC: Multicodec not supported\n");
-		return -EINVAL;
+			"Compress ASoC: Multi CPU/Codec not supported\n");
+		return -ENOTSUPP;

so this is an error...

Changing to -ENOTSUPP will prevent below to return error in soc_init_pcm_runtime().

/* create compress_device if possible */ ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);

if (ret != -ENOTSUPP) {
	if (ret < 0)
		dev_err(card->dev, "ASoC: can't create compress %s\n",
			dai_link->stream_name);
	return ret;
}

So it is to prevent an error actually. But I agree it is better to return an error when we have an unexpected number of cpu dais. What do you think? @Morimoto-san

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#10 lore raw

Re: [alsa-devel] [PATCH RFC v2 4/4] ASoC: add warning if the function is not support multi cpu yet.

Hi Liao

Quoted 31 lines
Quoted 8 lines

sound/soc/soc-compress.c int snd_soc_new_compress(struct

Quoted 4 lines

223cd045719e..bf9d6a21bcd9 100644

sound/soc/soc-compress.c +0 -0
@@ -810,10 +810,11 @@ int snd_soc_new_compress(struct

snd_soc_pcm_runtime *rtd, int num)

Quoted 3 lines
sound/soc/soc-compress.c +0 -0
  	int playback = 0, capture = 0;
  	int i;
 
Quoted 10 lines

sound/soc/soc-compress.c int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) · line 817

Quoted 8 lines
sound/soc/soc-compress.c +4 -3
-	if (rtd->num_codecs > 1) {
+	if (rtd->num_cpus > 1 ||
+	    rtd->num_codecs) {
  		dev_err(rtd->card->dev,
-			"Compress ASoC: Multicodec not supported\n");
-		return -EINVAL;
+			"Compress ASoC: Multi CPU/Codec not supported\n");
+		return -ENOTSUPP;

so this is an error...

Changing to -ENOTSUPP will prevent below to return error in soc_init_pcm_runtime().

/* create compress_device if possible */ ret = snd_soc_dai_compress_new(cpu_dai, rtd, num);

if (ret != -ENOTSUPP) {
	if (ret < 0)
		dev_err(card->dev, "ASoC: can't create compress %s\n",
			dai_link->stream_name);
	return ret;
}
Quoted 3 lines

So it is to prevent an error actually. But I agree it is better to return an error when we have an unexpected number of cpu dais. What do you think? @Morimoto-san

Yes, it should return error (= should not prevent error) I think

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#11 lore raw
In reply to Bard liao

Hi Bard

Quoted 23 lines

As discussed in [1], ASoC core supports multi codec DAIs on a DAI link. However it does not do so for CPU DAIs.

So, add support for multi CPU DAIs on a DAI Link by adding multi CPU DAI in Card instantiation, suspend and resume functions, PCM ops, stream handling functions and DAPM.

[1]: https://www.spinics.net/lists/alsa-devel/msg71369.html

changes in v2:
- rebase on asoc-next
- fix some typo
- compare and merge Kuninori Morimoto's version
- add warning if the function is not support multi cpu yet

Bard liao (1):
ASoC: add warning if the function is not support multi cpu yet.

Shreyas NC (3):
ASoC: Add initial support for multiple CPU DAIs
ASoC: Add multiple CPU DAI support for PCM ops
ASoC: Add multiple CPU DAI support in DAPM

Quoted 7 lines
 include/sound/soc.h                   |  15 +
 sound/soc/soc-compress.c              |   7 +-
 sound/soc/soc-core.c                  | 222 ++++++-----
 sound/soc/soc-dapm.c                  | 131 +++---
 sound/soc/soc-generic-dmaengine-pcm.c |  12 +
 sound/soc/soc-pcm.c                   | 547 +++++++++++++++++---------
 6 files changed, 599 insertions(+), 335 deletions(-)

Thank you for merging my version !!

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#12 lore raw
In reply to Bard liao
Quoted 6 lines · Bard liao

As discussed in [1], ASoC core supports multi codec DAIs on a DAI link. However it does not do so for CPU DAIs.

So, add support for multi CPU DAIs on a DAI Link by adding multi CPU DAI in Card instantiation, suspend and resume functions, PCM ops, stream handling functions and DAPM.

Maybe a tangential question, but I am a bit confused on the code cleanups.

After this series of patches is applied, we have this in soc.h:

	struct snd_soc_dai *codec_dai;
	struct snd_soc_dai *cpu_dai;

	struct snd_soc_dai **codec_dais;
	unsigned int num_codecs;

	struct snd_soc_dai **cpu_dais;
	unsigned int num_cpus;

What is the intent behind keeping the two fields codec_dai and cpu_dai?

Shouldn't we use the multi-dai structures in all cases, possible degraded to a single element rather than maintaining what looks like duplicate ways of accessing the same element?

If removing these fields across all drivers is just too invasive for now, shouldn't we start defining access macros so that those fields can be deprecated and removed at a later time, platform-by-platform?

Thanks
-Pierre
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#13 lore raw

Hi Pierre-Louis

Quoted 13 lines

After this series of patches is applied, we have this in soc.h:

	struct snd_soc_dai *codec_dai;
	struct snd_soc_dai *cpu_dai;

	struct snd_soc_dai **codec_dais;
	unsigned int num_codecs;

	struct snd_soc_dai **cpu_dais;
	unsigned int num_cpus;

What is the intent behind keeping the two fields codec_dai and cpu_dai?

Quoted 7 lines

Shouldn't we use the multi-dai structures in all cases, possible degraded to a single element rather than maintaining what looks like duplicate ways of accessing the same element?

If removing these fields across all drivers is just too invasive for now, shouldn't we start defining access macros so that those fields can be deprecated and removed at a later time, platform-by-platform?

Actually, I have this patch (= remove cpu_dai/codec_dai from all drivers, and use macro for it), and have plan to post it.

But, I have many extra cleanup patches in my tree, and I want to post it before that
(to avoid extra re-ordering dpendency break).

Thank you for your help !!
Best regards
---
Kuninori Morimoto
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#14 lore raw
Quoted 23 lines
Quoted 15 lines

After this series of patches is applied, we have this in soc.h:

	struct snd_soc_dai *codec_dai;
	struct snd_soc_dai *cpu_dai;

	struct snd_soc_dai **codec_dais;
	unsigned int num_codecs;

	struct snd_soc_dai **cpu_dais;
	unsigned int num_cpus;

What is the intent behind keeping the two fields codec_dai and cpu_dai?

Quoted 7 lines

Shouldn't we use the multi-dai structures in all cases, possible degraded to a single element rather than maintaining what looks like duplicate ways of accessing the same element?

If removing these fields across all drivers is just too invasive for now, shouldn't we start defining access macros so that those fields can be deprecated and removed at a later time, platform-by-platform?

Quoted 6 lines

Actually, I have this patch (= remove cpu_dai/codec_dai from all drivers, and use macro for it), and have plan to post it.

But, I have many extra cleanup patches in my tree, and I want to post it before that
(to avoid extra re-ordering dpendency break).

ok, thanks for the precisions!
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#15 lore raw
In reply to Bard liao
Quoted 7 lines · Bard liao

As discussed in [1], ASoC core supports multi codec DAIs on a DAI link. However it does not do so for CPU DAIs.

So, add support for multi CPU DAIs on a DAI Link by adding multi CPU DAI in Card instantiation, suspend and resume functions, PCM ops, stream handling functions and DAPM.

Quoted 7 lines

[1]: https://www.spinics.net/lists/alsa-devel/msg71369.html

changes in v2:
- rebase on asoc-next
- fix some typo
- compare and merge Kuninori Morimoto's version
- add warning if the function is not support multi cpu yet

I checked the code and didn't find blatant issues, except for inconsistent errors/warnings for the multi-cpu case, see other emails.

Looks really good to me otherwise, thanks Bard and Morimoto-san, nice work!

Quoted 9 lines

Bard liao (1):
ASoC: add warning if the function is not support multi cpu yet.

Shreyas NC (3):
ASoC: Add initial support for multiple CPU DAIs
ASoC: Add multiple CPU DAI support for PCM ops
ASoC: Add multiple CPU DAI support in DAPM

Quoted 8 lines
  include/sound/soc.h                   |  15 +
  sound/soc/soc-compress.c              |   7 +-
  sound/soc/soc-core.c                  | 222 ++++++-----
  sound/soc/soc-dapm.c                  | 131 +++---
  sound/soc/soc-generic-dmaengine-pcm.c |  12 +
  sound/soc/soc-pcm.c                   | 547 +++++++++++++++++---------
  6 files changed, 599 insertions(+), 335 deletions(-)

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel