ASoC: Add Multi CPU DAI support
Subsystems (4)
v5 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 v5:
- rebase to latest kernel base
Bard Liao (2):
ASoC: Return error if the function does not support multi-cpu
ASoC: pcm: check if cpu-dai supports a given stream
Shreyas NC (4):
ASoC: Add initial support for multiple CPU DAIs
ASoC: Add multiple CPU DAI support for PCM ops
ASoC: Add dapm_add_valid_dai_widget helper
ASoC: Add multiple CPU DAI support in DAPM
include/sound/soc.h | 15 + sound/soc/soc-compress.c | 5 +- sound/soc/soc-core.c | 168 +++++----- sound/soc/soc-dapm.c | 133 ++++---- sound/soc/soc-generic-dmaengine-pcm.c | 18 + sound/soc/soc-pcm.c | 463 ++++++++++++++++++-------- 6 files changed, 531 insertions(+), 271 deletions(-)
Signature · 1 line
2.17.1
PATCH v5 1/6 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 | 168 +++++++++++++++++++++++-------------------- 2 files changed, 106 insertions(+), 77 deletions(-)
include/sound/soc.h +15 -0
@@ -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 +91 -77
246 lines not on this page · raw message
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: Add initial support for multiple CPU DAIs" to the asoc tree
The patch
ASoC: Add initial support for multiple CPU DAIs
has been applied to the asoc tree at
https://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
From 76afa64374a79c22b2dab61aebef99a967783bf0 Mon Sep 17 00:00:00 2001
From: Shreyas NC <[email protected]>
Date: Tue, 25 Feb 2020 21:39:12 +0800
Subject: [PATCH] ASoC: Add initial support for multiple CPU DAIs
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 | 168 +++++++++++++++++++++++-------------------- 2 files changed, 106 insertions(+), 77 deletions(-)
include/sound/soc.h +15 -0
@@ -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 +91 -77
246 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v5 2/6 ASoC: Add multiple CPU DAI support for PCM ops
In reply to Bard LiaoFrom: 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 | 396 +++++++++++++++++++++++++++++--------------- 1 file changed, 261 insertions(+), 135 deletions(-)
sound/soc/soc-pcm.c +261 -135
@@ -253,18 +253,22 @@ static int soc_rtd_trigger(struct snd_soc_pcm_runtime *rtd,static void snd_soc_runtime_action (struct snd_soc_pcm_runtime *rtd,int stream,int action) { -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); - cpu_dai->stream_active[stream] += action; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) + cpu_dai->stream_active[stream] += action; +for_each_rtd_codec_dai (rtd, i, codec_dai) codec_dai->stream_active[stream] += action; - cpu_dai->active += action; - cpu_dai->component->active += action; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + cpu_dai->active += action; + cpu_dai->component->active += action; + }for_each_rtd_codec_dai (rtd, i, codec_dai) { codec_dai->active += action; codec_dai->component->active += action;
@@ -434,7 +438,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;
@@ -443,40 +447,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 ;
@@ -485,14 +509,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 ||
@@ -520,12 +550,12 @@ 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;struct snd_soc_pcm_stream *pcm_codec, *pcm_cpu;int stream = substream->stream;int i; -unsigned int bits =0 , cpu_bits; +unsigned int bits =0 , cpu_bits =0 ;for_each_rtd_codec_dai (rtd, i, codec_dai) { pcm_codec =snd_soc_dai_get_pcm_stream (codec_dai, stream);
@@ -537,8 +567,15 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) bits =max (pcm_codec->sig_bits, bits); } - pcm_cpu =snd_soc_dai_get_pcm_stream (cpu_dai, stream); - cpu_bits = pcm_cpu->sig_bits; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + pcm_cpu =snd_soc_dai_get_pcm_stream (cpu_dai, stream); + +if (pcm_cpu->sig_bits ==0 ) { + cpu_bits =0 ; +break ; + } + cpu_bits =max (pcm_cpu->sig_bits, cpu_bits); + }soc_pcm_set_msb (substream, bits);soc_pcm_set_msb (substream, cpu_bits);
@@ -550,18 +587,32 @@ 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 *cpu_dai;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 stream = substream->stream;int i; - cpu_stream =snd_soc_dai_get_pcm_stream (rtd->cpu_dai, stream); +/* first calculate min/max only for CPUs in the DAI link */ +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (cpu_dai, stream); + + 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); + } -/* first calculate min/max only for CODECs in the DAI link */ +/* second calculate min/max only for CODECs in the DAI link */ for_each_rtd_codec_dai (rtd, i, codec_dai) {/*
@@ -589,27 +640,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); }
@@ -681,7 +733,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;
@@ -689,9 +741,11 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)snd_soc_runtime_deactivate (rtd, substream->stream); -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);
@@ -726,9 +780,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)
@@ -751,11 +806,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) }/* 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 cpu_dai_err; +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 cpu_dai_err; + } }for_each_rtd_codec_dai (rtd, i, codec_dai) {
@@ -783,34 +840,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) {
@@ -822,7 +884,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);
@@ -840,7 +902,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)for_each_rtd_codec_dai (rtd, i, codec_dai)snd_soc_dai_shutdown (codec_dai, substream); cpu_dai_err: -snd_soc_dai_shutdown (cpu_dai, substream); +for_each_rtd_cpu_dai (rtd, i, cpu_dai) +snd_soc_dai_shutdown (cpu_dai, substream);soc_rtd_shutdown (rtd, substream); rtd_startup_err:
@@ -879,7 +942,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 ;
@@ -911,11 +974,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 */
@@ -931,7 +996,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);
@@ -978,7 +1044,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 ;
@@ -1042,17 +1108,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);
@@ -1072,10 +1140,14 @@ 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) { +snd_soc_dai_hw_free (cpu_dai, substream); + cpu_dai->rate =0 ; + } + i = rtd->num_codecs; codec_err:
@@ -1099,7 +1171,7 @@ 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;
@@ -1107,10 +1179,12 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)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 ; +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 ; + } }for_each_rtd_codec_dai (rtd, i, codec_dai) {
@@ -1146,7 +1220,8 @@ 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) +snd_soc_dai_hw_free (cpu_dai, substream);mutex_unlock (&rtd->card->pcm_mutex);return 0 ;
@@ -1156,7 +1231,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;
@@ -1170,9 +1245,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);
@@ -1187,7 +1264,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;
@@ -1197,9 +1274,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);
@@ -1240,7 +1319,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;
@@ -1250,9 +1329,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 ; }
@@ -1264,12 +1345,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 */
@@ -1280,7 +1362,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,
@@ -1403,13 +1489,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,if (!be->dai_link->no_pcm)continue ; - w =snd_soc_dai_get_widget (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + w =snd_soc_dai_get_widget (dai, stream); -dev_dbg (card->dev,"ASoC: try BE : %s\n" , - w ? w->name :"(not set)" ); +dev_dbg (card->dev,"ASoC: try BE : %s\n" , + w ? w->name :"(not set)" ); -if (w == widget) -return be; +if (w == widget) +return be; + }for_each_rtd_codec_dai (be, i, dai) { w =snd_soc_dai_get_widget (dai, stream);
@@ -1492,10 +1580,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 =snd_soc_dai_get_widget (dpcm->be->cpu_dai, stream); + do_prune =1 ; +for_each_rtd_cpu_dai (dpcm->be, i, dai) { + widget =snd_soc_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 */
@@ -1792,11 +1888,17 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,struct snd_soc_pcm_runtime *be = dpcm->be;struct snd_soc_pcm_stream *codec_stream;struct snd_soc_pcm_stream *cpu_stream; +struct snd_soc_dai *dai; +int i; - cpu_stream =snd_soc_dai_get_pcm_stream (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); - *channels_min =max (*channels_min, cpu_stream->channels_min); - *channels_max =min (*channels_max, cpu_stream->channels_max); + *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
@@ -1837,11 +1939,15 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,struct snd_soc_dai *dai;int i; - cpu_stream =snd_soc_dai_get_pcm_stream (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); - *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); + *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) {/*
@@ -1866,13 +1972,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,
@@ -1909,18 +2019,21 @@ 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; + for_each_rtd_cpu_dai (fe, i, fe_cpu_dai) { +/* 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; + } }/* apply symmetry for BE */
@@ -1930,6 +2043,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 */
@@ -1944,11 +2058,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) {
@@ -2863,7 +2979,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 ];
@@ -2881,6 +2997,16 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) SNDRV_PCM_STREAM_CAPTURE :SNDRV_PCM_STREAM_PLAYBACK ;for_each_rtd_codec_dai (rtd, i, codec_dai) { +if (rtd->num_cpus ==1 ) { + cpu_dai = rtd->cpu_dais[0 ]; + }else if (rtd->num_cpus == rtd->num_codecs) { + cpu_dai = rtd->cpu_dais[i]; + }else { +dev_err (rtd->card->dev, +"N cpus to M codecs link is not supported yet\n" ); +return -EINVAL ; + } +if (snd_soc_dai_stream_valid (codec_dai,SNDRV_PCM_STREAM_PLAYBACK ) &&snd_soc_dai_stream_valid (cpu_dai, cpu_playback)) playback =1 ;
@@ -3001,7 +3127,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 · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: Add multiple CPU DAI support for PCM ops" to the asoc tree
The patch
ASoC: Add multiple CPU DAI support for PCM ops
has been applied to the asoc tree at
https://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
From 19bdcc7aeed4169820be6a683c422fc06d030136 Mon Sep 17 00:00:00 2001
From: Shreyas NC <[email protected]>
Date: Tue, 25 Feb 2020 21:39:13 +0800
Subject: [PATCH] ASoC: Add multiple CPU DAI support for PCM ops
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 | 396 +++++++++++++++++++++++++++++--------------- 1 file changed, 261 insertions(+), 135 deletions(-)
sound/soc/soc-pcm.c +261 -135
@@ -253,18 +253,22 @@ static int soc_rtd_trigger(struct snd_soc_pcm_runtime *rtd,static void snd_soc_runtime_action (struct snd_soc_pcm_runtime *rtd,int stream,int action) { -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); - cpu_dai->stream_active[stream] += action; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) + cpu_dai->stream_active[stream] += action; +for_each_rtd_codec_dai (rtd, i, codec_dai) codec_dai->stream_active[stream] += action; - cpu_dai->active += action; - cpu_dai->component->active += action; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + cpu_dai->active += action; + cpu_dai->component->active += action; + }for_each_rtd_codec_dai (rtd, i, codec_dai) { codec_dai->active += action; codec_dai->component->active += action;
@@ -434,7 +438,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;
@@ -443,40 +447,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 ;
@@ -485,14 +509,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 ||
@@ -520,12 +550,12 @@ 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;struct snd_soc_pcm_stream *pcm_codec, *pcm_cpu;int stream = substream->stream;int i; -unsigned int bits =0 , cpu_bits; +unsigned int bits =0 , cpu_bits =0 ;for_each_rtd_codec_dai (rtd, i, codec_dai) { pcm_codec =snd_soc_dai_get_pcm_stream (codec_dai, stream);
@@ -537,8 +567,15 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream) bits =max (pcm_codec->sig_bits, bits); } - pcm_cpu =snd_soc_dai_get_pcm_stream (cpu_dai, stream); - cpu_bits = pcm_cpu->sig_bits; +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + pcm_cpu =snd_soc_dai_get_pcm_stream (cpu_dai, stream); + +if (pcm_cpu->sig_bits ==0 ) { + cpu_bits =0 ; +break ; + } + cpu_bits =max (pcm_cpu->sig_bits, cpu_bits); + }soc_pcm_set_msb (substream, bits);soc_pcm_set_msb (substream, cpu_bits);
@@ -550,18 +587,32 @@ 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 *cpu_dai;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 stream = substream->stream;int i; - cpu_stream =snd_soc_dai_get_pcm_stream (rtd->cpu_dai, stream); +/* first calculate min/max only for CPUs in the DAI link */ +for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (cpu_dai, stream); + + 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); + } -/* first calculate min/max only for CODECs in the DAI link */ +/* second calculate min/max only for CODECs in the DAI link */ for_each_rtd_codec_dai (rtd, i, codec_dai) {/*
@@ -589,27 +640,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); }
@@ -681,7 +733,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;
@@ -689,9 +741,11 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)snd_soc_runtime_deactivate (rtd, substream->stream); -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);
@@ -726,9 +780,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)
@@ -751,11 +806,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) }/* 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 cpu_dai_err; +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 cpu_dai_err; + } }for_each_rtd_codec_dai (rtd, i, codec_dai) {
@@ -783,34 +840,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) {
@@ -822,7 +884,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);
@@ -840,7 +902,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)for_each_rtd_codec_dai (rtd, i, codec_dai)snd_soc_dai_shutdown (codec_dai, substream); cpu_dai_err: -snd_soc_dai_shutdown (cpu_dai, substream); +for_each_rtd_cpu_dai (rtd, i, cpu_dai) +snd_soc_dai_shutdown (cpu_dai, substream);soc_rtd_shutdown (rtd, substream); rtd_startup_err:
@@ -879,7 +942,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 ;
@@ -911,11 +974,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 */
@@ -931,7 +996,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);
@@ -978,7 +1044,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 ;
@@ -1042,17 +1108,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);
@@ -1072,10 +1140,14 @@ 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) { +snd_soc_dai_hw_free (cpu_dai, substream); + cpu_dai->rate =0 ; + } + i = rtd->num_codecs; codec_err:
@@ -1099,7 +1171,7 @@ 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;
@@ -1107,10 +1179,12 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)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 ; +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 ; + } }for_each_rtd_codec_dai (rtd, i, codec_dai) {
@@ -1146,7 +1220,8 @@ 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) +snd_soc_dai_hw_free (cpu_dai, substream);mutex_unlock (&rtd->card->pcm_mutex);return 0 ;
@@ -1156,7 +1231,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;
@@ -1170,9 +1245,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);
@@ -1187,7 +1264,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;
@@ -1197,9 +1274,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);
@@ -1240,7 +1319,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;
@@ -1250,9 +1329,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 ; }
@@ -1264,12 +1345,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 */
@@ -1280,7 +1362,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,
@@ -1403,13 +1489,15 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card,if (!be->dai_link->no_pcm)continue ; - w =snd_soc_dai_get_widget (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + w =snd_soc_dai_get_widget (dai, stream); -dev_dbg (card->dev,"ASoC: try BE : %s\n" , - w ? w->name :"(not set)" ); +dev_dbg (card->dev,"ASoC: try BE : %s\n" , + w ? w->name :"(not set)" ); -if (w == widget) -return be; +if (w == widget) +return be; + }for_each_rtd_codec_dai (be, i, dai) { w =snd_soc_dai_get_widget (dai, stream);
@@ -1492,10 +1580,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 =snd_soc_dai_get_widget (dpcm->be->cpu_dai, stream); + do_prune =1 ; +for_each_rtd_cpu_dai (dpcm->be, i, dai) { + widget =snd_soc_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 */
@@ -1792,11 +1888,17 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,struct snd_soc_pcm_runtime *be = dpcm->be;struct snd_soc_pcm_stream *codec_stream;struct snd_soc_pcm_stream *cpu_stream; +struct snd_soc_dai *dai; +int i; - cpu_stream =snd_soc_dai_get_pcm_stream (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); - *channels_min =max (*channels_min, cpu_stream->channels_min); - *channels_max =min (*channels_max, cpu_stream->channels_max); + *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
@@ -1837,11 +1939,15 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,struct snd_soc_dai *dai;int i; - cpu_stream =snd_soc_dai_get_pcm_stream (be->cpu_dai, stream); +for_each_rtd_cpu_dai (be, i, dai) { + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); - *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); + *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) {/*
@@ -1866,13 +1972,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,
@@ -1909,18 +2019,21 @@ 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; + for_each_rtd_cpu_dai (fe, i, fe_cpu_dai) { +/* 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; + } }/* apply symmetry for BE */
@@ -1930,6 +2043,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 */
@@ -1944,11 +2058,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) {
@@ -2863,7 +2979,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 ];
@@ -2881,6 +2997,16 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) SNDRV_PCM_STREAM_CAPTURE :SNDRV_PCM_STREAM_PLAYBACK ;for_each_rtd_codec_dai (rtd, i, codec_dai) { +if (rtd->num_cpus ==1 ) { + cpu_dai = rtd->cpu_dais[0 ]; + }else if (rtd->num_cpus == rtd->num_codecs) { + cpu_dai = rtd->cpu_dais[i]; + }else { +dev_err (rtd->card->dev, +"N cpus to M codecs link is not supported yet\n" ); +return -EINVAL ; + } +if (snd_soc_dai_stream_valid (codec_dai,SNDRV_PCM_STREAM_PLAYBACK ) &&snd_soc_dai_stream_valid (cpu_dai, cpu_playback)) playback =1 ;
@@ -3001,7 +3127,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 · 1 line
2.20.1
PATCH v5 3/6 ASoC: Add dapm_add_valid_dai_widget helper
In reply to Bard LiaoFrom: Shreyas NC <[email protected]>
Adding a helper to connect widget for a specific cpu and codec dai The helper will help dapm_connect_dai_link_widgets() to reduce indents.
--- sound/soc/soc-dapm.c | 119 +++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 56 deletions(-)
sound/soc/soc-dapm.c +63 -56
@@ -4277,16 +4277,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;
@@ -4298,67 +4297,75 @@ 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)); + goto capture; } -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 ); } - } -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 ); +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 ); + } + +capture: +/* 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)); +return ; } -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 ); +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; + +for_each_rtd_codec_dai (rtd, i, codec_dai) +dapm_add_valid_dai_widget (card, rtd, + codec_dai, rtd->cpu_dais[0 ]); +} +static void soc_dapm_dai_stream_event (struct snd_soc_dai *dai,int stream,int event) {
Signature · 1 line
2.17.1
PATCH v5 4/6 ASoC: Add multiple CPU DAI support in DAPM
In reply to Bard LiaoFrom: 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 | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
sound/soc/soc-dapm.c +16 -4
@@ -4361,9 +4361,19 @@ static void dapm_connect_dai_link_widgets(struct snd_soc_card *card,struct snd_soc_dai *codec_dai;int i; -for_each_rtd_codec_dai (rtd, i, codec_dai) -dapm_add_valid_dai_widget (card, rtd, - codec_dai, rtd->cpu_dais[0 ]); +if (rtd->num_cpus ==1 ) { +for_each_rtd_codec_dai (rtd, i, codec_dai) +dapm_add_valid_dai_widget (card, rtd, codec_dai, + rtd->cpu_dais[0 ]); + }else 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" ); + } + } static void soc_dapm_dai_stream_event(struct snd_soc_dai *dai, int stream,
@@ -4424,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 (rtd->cpu_dai, stream, event);for_each_rtd_codec_dai (rtd, i, codec_dai)soc_dapm_dai_stream_event (codec_dai, stream, event);
Signature · 1 line
2.17.1
PATCH v5 5/6 ASoC: Return error if the function does not support multi-cpu
In reply to Bard LiaoMulti cpu is not supported by all functions yet. Add an error message and return.
--- sound/soc/soc-compress.c | 5 +++-- sound/soc/soc-generic-dmaengine-pcm.c | 18 ++++++++++++++++++ sound/soc/soc-pcm.c | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-)
sound/soc/soc-compress.c +3 -2
@@ -810,9 +810,10 @@ 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 >1 ) {dev_err (rtd->card->dev, -"Compress ASoC: Multicodec not supported\n" ); +"Compress ASoC: Multi CPU/Codec not supported\n" );return -EINVAL ; }
sound/soc/soc-generic-dmaengine-pcm.c +18 -0
@@ -62,6 +62,12 @@ 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_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } + dma_data =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); ret =snd_hwparams_to_dma_slave_config (substream, params, slave_config);
@@ -118,6 +124,12 @@ dmaengine_pcm_set_runtime_hwparams(struct snd_soc_component *component,struct snd_dmaengine_dai_dma_data *dma_data;struct snd_pcm_hardware hw; +if (rtd->num_cpus >1 ) { +dev_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +if (pcm->config && pcm->config->pcm_hardware)return snd_soc_set_runtime_hwparams (substream, pcm->config->pcm_hardware);
@@ -185,6 +197,12 @@ 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_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return NULL ; + } + 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 +18 -0
@@ -125,6 +125,12 @@ static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,int stream;char *buf; +if (fe->num_cpus >1 ) { +dev_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } + buf =kmalloc (out_count,GFP_KERNEL );if (!buf)return -ENOMEM ;
@@ -1550,6 +1556,12 @@ 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_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +/* 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);
@@ -2834,6 +2846,12 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)int count, paths;int ret; +if (fe->num_cpus >1 ) { +dev_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +if (!fe->dai_link->dynamic)return 0 ;
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: Return error if the function does not support multi-cpu" to the asoc tree
The patch
ASoC: Return error if the function does not support multi-cpu
has been applied to the asoc tree at
https://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
From 6e1276a5e613d25af71e3494b2dcb331d24f06ce Mon Sep 17 00:00:00 2001
From: Bard Liao <[email protected]>
Date: Tue, 25 Feb 2020 21:39:16 +0800
Subject: [PATCH] ASoC: Return error if the function does not support multi-cpu
Multi cpu is not supported by all functions yet. Add an error message and return.
--- sound/soc/soc-compress.c | 5 +++-- sound/soc/soc-generic-dmaengine-pcm.c | 18 ++++++++++++++++++ sound/soc/soc-pcm.c | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-)
sound/soc/soc-compress.c +3 -2
@@ -810,9 +810,10 @@ 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 >1 ) {dev_err (rtd->card->dev, -"Compress ASoC: Multicodec not supported\n" ); +"Compress ASoC: Multi CPU/Codec not supported\n" );return -EINVAL ; }
sound/soc/soc-generic-dmaengine-pcm.c +18 -0
@@ -62,6 +62,12 @@ 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_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } + dma_data =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); ret =snd_hwparams_to_dma_slave_config (substream, params, slave_config);
@@ -118,6 +124,12 @@ dmaengine_pcm_set_runtime_hwparams(struct snd_soc_component *component,struct snd_dmaengine_dai_dma_data *dma_data;struct snd_pcm_hardware hw; +if (rtd->num_cpus >1 ) { +dev_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +if (pcm->config && pcm->config->pcm_hardware)return snd_soc_set_runtime_hwparams (substream, pcm->config->pcm_hardware);
@@ -185,6 +197,12 @@ 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_err (rtd->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return NULL ; + } + 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 +18 -0
@@ -125,6 +125,12 @@ static ssize_t dpcm_state_read_file(struct file *file, char __user *user_buf,int stream;char *buf; +if (fe->num_cpus >1 ) { +dev_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } + buf =kmalloc (out_count,GFP_KERNEL );if (!buf)return -ENOMEM ;
@@ -1550,6 +1556,12 @@ 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_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +/* 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);
@@ -2834,6 +2846,12 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)int count, paths;int ret; +if (fe->num_cpus >1 ) { +dev_err (fe->dev, +"%s doesn't support Multi CPU yet\n" , __func__); +return -EINVAL ; + } +if (!fe->dai_link->dynamic)return 0 ;
Signature · 1 line
2.20.1
PATCH v5 6/6 ASoC: pcm: check if cpu-dai supports a given stream
In reply to Bard LiaoNow multi-cpu-dais are supported, we can skip cpi-dais which don't support the current stream, following the example of multi-codec-dais.
--- sound/soc/soc-pcm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
sound/soc/soc-pcm.c +50 -1
@@ -607,6 +607,20 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)/* first calculate min/max only for CPUs in the DAI link */ for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + +/* +* Skip CPUs which don't support the current stream type. +* Otherwise, since the rate, channel, and format values will +* zero in that case, we would have no usable settings left, +* causing the resulting setup to fail. +* At least one CPU should match, otherwise we should have +* bailed out on a higher level, since there would be no +* CPU to support the transfer direction in that case. +*/ +if (!snd_soc_dai_stream_valid (cpu_dai, + substream->stream)) +continue ; + cpu_stream =snd_soc_dai_get_pcm_stream (cpu_dai, stream); cpu_chan_min =max (cpu_chan_min, cpu_stream->channels_min);
@@ -1115,6 +1129,13 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, }for_each_rtd_cpu_dai (rtd, i, cpu_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 (cpu_dai, substream->stream)) +continue ; + ret =snd_soc_dai_hw_params (cpu_dai, substream, params);if (ret <0 ) goto interface_err;
@@ -1150,6 +1171,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, 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 ; }
@@ -1226,8 +1250,12 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)snd_soc_dai_hw_free (codec_dai, substream); } -for_each_rtd_cpu_dai (rtd, i, cpu_dai) +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 ;
@@ -1904,6 +1932,13 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,int i;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 ; + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); *channels_min = max(*channels_min,
@@ -1952,6 +1987,13 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,int i;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 ; + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); *rate_min =max (*rate_min, cpu_stream->rate_min);
@@ -1989,6 +2031,13 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)int i;for_each_rtd_cpu_dai (rtd, i, cpu_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 (cpu_dai, substream->stream)) +continue ; + cpu_dai_drv = cpu_dai->driver;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK )dpcm_init_runtime_hw (runtime, &cpu_dai_drv->playback);
Signature · 1 line
2.17.1
Mark Brown
maintainerApplied "ASoC: pcm: check if cpu-dai supports a given stream" to the asoc tree
The patch
ASoC: pcm: check if cpu-dai supports a given stream
has been applied to the asoc tree at
https://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
From 0e9cf4c452ad7e2776441cbac0b9983abaf17ff0 Mon Sep 17 00:00:00 2001
From: Bard Liao <[email protected]>
Date: Tue, 25 Feb 2020 21:39:17 +0800
Subject: [PATCH] ASoC: pcm: check if cpu-dai supports a given stream
Now multi-cpu-dais are supported, we can skip cpi-dais which don't support the current stream, following the example of multi-codec-dais.
--- sound/soc/soc-pcm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-)
sound/soc/soc-pcm.c +50 -1
@@ -607,6 +607,20 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_substream *substream)/* first calculate min/max only for CPUs in the DAI link */ for_each_rtd_cpu_dai (rtd, i, cpu_dai) { + +/* +* Skip CPUs which don't support the current stream type. +* Otherwise, since the rate, channel, and format values will +* zero in that case, we would have no usable settings left, +* causing the resulting setup to fail. +* At least one CPU should match, otherwise we should have +* bailed out on a higher level, since there would be no +* CPU to support the transfer direction in that case. +*/ +if (!snd_soc_dai_stream_valid (cpu_dai, + substream->stream)) +continue ; + cpu_stream =snd_soc_dai_get_pcm_stream (cpu_dai, stream); cpu_chan_min =max (cpu_chan_min, cpu_stream->channels_min);
@@ -1115,6 +1129,13 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, }for_each_rtd_cpu_dai (rtd, i, cpu_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 (cpu_dai, substream->stream)) +continue ; + ret =snd_soc_dai_hw_params (cpu_dai, substream, params);if (ret <0 ) goto interface_err;
@@ -1150,6 +1171,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream, 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 ; }
@@ -1226,8 +1250,12 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)snd_soc_dai_hw_free (codec_dai, substream); } -for_each_rtd_cpu_dai (rtd, i, cpu_dai) +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 ;
@@ -1904,6 +1932,13 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,int i;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 ; + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); *channels_min = max(*channels_min,
@@ -1952,6 +1987,13 @@ static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,int i;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 ; + cpu_stream =snd_soc_dai_get_pcm_stream (dai, stream); *rate_min =max (*rate_min, cpu_stream->rate_min);
@@ -1989,6 +2031,13 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)int i;for_each_rtd_cpu_dai (rtd, i, cpu_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 (cpu_dai, substream->stream)) +continue ; + cpu_dai_drv = cpu_dai->driver;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK )dpcm_init_runtime_hw (runtime, &cpu_dai_drv->playback);
Signature · 1 line
2.20.1