ASoC: core: Add support for DAI multicodec
Subsystems (3)
v3 cover ASoC: core: Add support for DAI multicodec
Hi Mark, Liam and Lars,
Sorry for the delay. Here is the third version of the multicodec series.
I changed the way to store the multiple codec_dai as suggested by Lars and added the missing iterations in all the places pointed by Lars in his comments.
Please note that I have a very simple setup based on BBB to check if the series is working, so it will be good to test it on various platforms to ensure this is not generating any regression. Hence this version is still RFT.
The series is based on asoc/for-next (v3.15-rc2).
Test and comments are welcome.
Thanks,
Benoit
v1: http://comments.gmane.org/gmane.linux.alsa.devel/120532
v2: http://comments.gmane.org/gmane.linux.alsa.devel/121024
- Split the first version in several patches.
- Remove the TDM fixup
v3:
- Fixed all the places that were not iterating over all the codecs.
- Change the structure and split it.
Benoit Cousson (2):
ASoC: core: Add one dai_get_widget helper instead of two rtd based ones
ASoC: core: Add support for DAI multicodec
Misael Lopez Cruz (1):
ASoC: core: Add helpers for dai link and aux dev init
include/sound/soc-dai.h | 5 + include/sound/soc.h | 13 ++ sound/soc/soc-compress.c | 83 +++++--- sound/soc/soc-core.c | 401 +++++++++++++++++++++++++---------- sound/soc/soc-dapm.c | 71 ++++--- sound/soc/soc-pcm.c | 529 +++++++++++++++++++++++++++++++---------------- 6 files changed, 763 insertions(+), 339 deletions(-)
Signature · 1 line
1.8.3.2
PATCH v3 1/3 ASoC: core: Add helpers for dai link and aux dev init
From: Misael Lopez Cruz <[email protected]>
Separate DAI link and aux dev initialization in preparation for DAI multicodec support.
Since aux dev will remain using single codecs but DAI links will be able to support multiple codecs.
No functional change.
--- sound/soc/soc-core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-)
sound/soc/soc-core.c +59 -8
@@ -1266,6 +1266,63 @@ static void rtd_release(struct device *dev)kfree (dev); } +static int soc_aux_dev_init (struct snd_soc_card *card, +struct snd_soc_codec *codec, +int num) +{ +struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num]; +struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num]; +const char *temp; +int ret; + + rtd->card = card; + + temp = codec->name_prefix; + codec->name_prefix =NULL ; + +/* do machine specific initialization */ +if (aux_dev->init) { + ret = aux_dev->init (&codec->dapm); +if (ret <0 ) +return ret; + } + + codec->name_prefix = temp; + + rtd->codec = codec; + +return 0 ; +} + +static int soc_dai_link_init (struct snd_soc_card *card, +struct snd_soc_codec *codec, +int num) +{ +struct snd_soc_dai_link *dai_link = &card->dai_link[num]; +struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; +const char *temp; +int ret; + + rtd->card = card; + +/* machine controls, routes and widgets are not prefixed */ + temp = codec->name_prefix; + codec->name_prefix =NULL ; + +/* do machine specific initialization */ +if (dai_link->init) { + ret = dai_link->init (rtd); +if (ret <0 ) +return ret; + } + + codec->name_prefix = temp; + + rtd->codec = codec; + +return 0 ; +} +static int soc_post_component_init (struct snd_soc_card *card,struct snd_soc_codec *codec,int num,int dailess)
@@ -1280,26 +1337,20 @@ static int soc_post_component_init(struct snd_soc_card *card, dai_link = &card->dai_link[num]; rtd = &card->rtd[num]; name = dai_link->name; + ret =soc_dai_link_init (card, codec, num); }else { aux_dev = &card->aux_dev[num]; rtd = &card->rtd_aux[num]; name = aux_dev->name; + ret =soc_aux_dev_init (card, codec, num); } - rtd->card = card; -/* do machine specific initialization */ -if (!dailess && dai_link->init) - ret = dai_link->init (rtd); -else if (dailess && aux_dev->init) - ret = aux_dev->init (&codec->dapm);if (ret <0 ) {dev_err (card->dev,"ASoC: failed to init %s: %d\n" , name, ret);return ret; }/* register the rtd device */ - rtd->codec = codec; - rtd->dev =kzalloc (sizeof (struct device ),GFP_KERNEL );if (!rtd->dev)return -ENOMEM ;
Signature · 1 line
1.8.3.2
Re: [RFT v3 1/3] ASoC: core: Add helpers for dai link and aux dev init
Quoted 6 lines · Benoit Cousson
From: Misael Lopez Cruz <[email protected]>
Separate DAI link and aux dev initialization in preparation for DAI multicodec support.
Since aux dev will remain using single codecs but DAI links will be able to support multiple codecs.
Applied, thanks.
PATCH v3 2/3 ASoC: core: Add one dai_get_widget helper instead of two rtd based ones
In reply to Benoit CoussonReplace rtd_get_codec_widget() and rtd_get_cpu_widget() by a simple dai_get_widget() in preparation for DAI-multicodec support, per Lars suggestion.
No functional change.
--- sound/soc/soc-pcm.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
sound/soc/soc-pcm.c +5 -14
@@ -1012,21 +1012,12 @@ static struct snd_soc_pcm_runtime *dpcm_get_be(struct snd_soc_card *card, }static inline struct snd_soc_dapm_widget * -rtd_get_cpu_widget (struct snd_soc_pcm_runtime *rtd,int stream) +dai_get_widget (struct snd_soc_dai *dai,int stream) {if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) -return rtd->cpu_dai->playback_widget; +return dai->playback_widget;else -return rtd->cpu_dai->capture_widget; -} - -static inline struct snd_soc_dapm_widget * -rtd_get_codec_widget (struct snd_soc_pcm_runtime *rtd,int stream) -{ -if (stream ==SNDRV_PCM_STREAM_PLAYBACK ) -return rtd->codec_dai->playback_widget; -else -return rtd->codec_dai->capture_widget; +return dai->capture_widget; } static int widget_in_list(struct snd_soc_dapm_widget_list *list,
@@ -1076,14 +1067,14 @@ static int dpcm_prune_paths(struct snd_soc_pcm_runtime *fe, int stream,list_for_each_entry (dpcm, &fe->dpcm[stream].be_clients, list_be) {/* is there a valid CPU DAI widget for this BE */ - widget =rtd_get_cpu_widget (dpcm->be, stream); + widget =dai_get_widget (dpcm->be->cpu_dai, stream);/* prune the BE if it's no longer in our active list */ if (widget &&widget_in_list (list, widget))continue ;/* is there a valid CODEC DAI widget for this BE */ - widget =rtd_get_codec_widget (dpcm->be, stream); + widget =dai_get_widget (dpcm->be->codec_dai, stream);/* prune the BE if it's no longer in our active list */ if (widget &&widget_in_list (list, widget))
Signature · 1 line
1.8.3.2
Re: [RFT v3 2/3] ASoC: core: Add one dai_get_widget helper instead of two rtd based ones
Quoted 3 lines · Benoit Cousson
Replace
rtd_get_codec_widget()andrtd_get_cpu_widget()by a simpledai_get_widget()in preparation for DAI-multicodec support, per Lars suggestion.
Applied, thanks.
PATCH v3 3/3 ASoC: core: Add support for DAI multicodec
In reply to Benoit CoussonDAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.
Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new 'snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node or codec_name).
Fix a trailing space in the header as well.
Based on an original code done by Misael.
--- include/sound/soc-dai.h | 5 + include/sound/soc.h | 13 ++ sound/soc/soc-compress.c | 83 +++++--- sound/soc/soc-core.c | 364 ++++++++++++++++++++++----------- sound/soc/soc-dapm.c | 71 ++++--- sound/soc/soc-pcm.c | 512 ++++++++++++++++++++++++++++++++--------------- 6 files changed, 715 insertions(+), 333 deletions(-)
include/sound/soc-dai.h +5 -0
@@ -274,6 +274,11 @@ struct snd_soc_dai {struct snd_soc_codec *codec;struct snd_soc_component *component; +/* CODEC TDM slot masks and params (for fixup) */ +unsigned int tx_mask; +unsigned int rx_mask; +struct snd_pcm_hw_params params[2 ]; +struct snd_soc_card *card;struct list_head list;
include/sound/soc.h +13 -0
@@ -821,6 +821,12 @@ struct snd_soc_platform_driver {int (*bespoke_trigger)(struct snd_pcm_substream *,int ); }; +struct snd_soc_dai_link_component { +const char *name; +const struct device_node *of_node; +const char *dai_name; +}; +struct snd_soc_platform {const char *name;int id;
@@ -870,6 +876,10 @@ struct snd_soc_dai_link {const struct device_node *codec_of_node;/* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + +struct snd_soc_dai_link_component *codecs; +unsigned int num_codecs; +/* * You MAY specify the link's platform/PCM/DMA driver, either by * device name, or by DT/OF node, but not both. Some forms of link
@@ -1059,6 +1069,9 @@ struct snd_soc_pcm_runtime {struct snd_soc_dai *codec_dai;struct snd_soc_dai *cpu_dai; +struct snd_soc_dai **codec_dais; +unsigned int num_codecs; +struct delayed_work delayed_work;#ifdef CONFIG_DEBUG_FS struct dentry *debugfs_dpcm_root;
sound/soc/soc-compress.c +50 -33
138 lines not on this page · raw message
sound/soc/soc-core.c +247 -117
655 lines not on this page · raw message
sound/soc/soc-dapm.c +48 -23
116 lines not on this page · raw message
sound/soc/soc-pcm.c +352 -160
878 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 12 lines · Benoit Cousson
DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new '
snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node orcodec_name).
Quoted 7 lines
Fix a trailing space in the header as well.
Based on an original code done by Misael.
Signed-off-by Benoit Cousson <[email protected]>Signed-off-by Misael Lopez Cruz <[email protected]>Signed-off-by Fabien Parent <[email protected]>
Looks mostly good. A few bits and pieces here and there, comments inline.
[...]
Quoted 18 lines
include/sound/soc.h +6
-0@@ -821,6 +821,12 @@ struct snd_soc_platform_driver {int (*bespoke_trigger)(struct snd_pcm_substream *,int ); }; +struct snd_soc_dai_link_component { +const char *name; +const struct device_node *of_node; +const char *dai_name; +}; +struct snd_soc_platform {const char *name;int id;
include/sound/soc.h struct snd_soc_dai_link { · line 880
Quoted 5 lines
include/sound/soc.h +2
-0@@ -870,6 +876,10 @@ struct snd_soc_dai_link {const struct device_node *codec_of_node;/* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + +struct snd_soc_dai_link_component *codecs;
Should probably be const
Quoted 5 lines
include/sound/soc.h +2
-0+unsigned int num_codecs; +/* * You MAY specify the link's platform/PCM/DMA driver, either by * device name, or by DT/OF node, but not both. Some forms of link
[...]
Quoted 25 lines
include/sound/soc.h +4
-11@@ -620,23 +631,26 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) {struct snd_soc_codec *codec = rtd->codec;struct snd_soc_platform *platform = rtd->platform; -struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai;struct snd_compr *compr;struct snd_pcm *be_pcm;char new_name[64 ]; -int ret =0 , direction =0 ; +int i, ret =0 , direction =0 ; -/* check client and interface hw capabilities */ -snprintf (new_name,sizeof (new_name),"%s %s-%d" , - rtd->dai_link->stream_name, codec_dai->name, num); -if (codec_dai->driver->playback.channels_min) - direction =SND_COMPRESS_PLAYBACK ; -else if (codec_dai->driver->capture.channels_min) - direction =SND_COMPRESS_CAPTURE ; -else -return -EINVAL ; +for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +/* check client and interface hw capabilities */
include/sound/soc.h int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) · line 653
Quoted 10 lines
include/sound/soc.h +10
-0+snprintf (new_name,sizeof (new_name),"%s %s-%d" , + rtd->dai_link->stream_name, codec_dai->name, num); + +if (codec_dai->driver->playback.channels_min) + direction =SND_COMPRESS_PLAYBACK ; +else if (codec_dai->driver->capture.channels_min) + direction =SND_COMPRESS_CAPTURE ; +else +return -EINVAL ; + }
This loop makes no sense, you just end up overwriting new_name and direction with each loop iteration.
Quoted 21 lines
include/sound/soc.h +5
-2compr =kzalloc (sizeof (*compr),GFP_KERNEL );if (compr ==NULL ) {@@ -690,8 +704,11 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) rtd->compr = compr; compr->private_data = rtd; -printk (KERN_INFO "compress asoc: %s <-> %s mapping ok\n" , codec_dai->name, - cpu_dai->name); +for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +printk (KERN_INFO "compress asoc: %s <-> %s mapping ok\n" , + codec_dai->name, cpu_dai->name); + }return ret; compr_err:sound/soc/soc-core.c +0
-0
[...]
Quoted 16 lines
sound/soc/soc-core.c +3
-5@@ -1294,20 +1324,28 @@ static int soc_aux_dev_init(struct snd_soc_card *card,return 0 ; } -static int soc_dai_link_init (struct snd_soc_card *card, -struct snd_soc_codec *codec, -int num) +static int soc_dai_link_init (struct snd_soc_card *card,int num) {struct snd_soc_dai_link *dai_link = &card->dai_link[num];struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; -const char *temp; -int ret; +const char **temp; +int i, ret;
sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1340
Quoted 10 lines
sound/soc/soc-core.c +5
-3rtd->card = card; -/* machine controls, routes and widgets are not prefixed */ - temp = codec->name_prefix; - codec->name_prefix =NULL ; + temp =devm_kzalloc (card->dev, rtd->num_codecs *sizeof (char *), +GFP_KERNEL ); +if (!temp) +return -ENOMEM ; +
Setting name_prefix temporarily to NULL is no longer necessary, see the patch I just sent out.
Quoted 11 lines
sound/soc/soc-core.c +8
-0+for (i =0 ; i < rtd->num_codecs; i++) { +/* Make sure all DAPM widgets are instantiated */ +snd_soc_dapm_new_widgets (rtd->codec_dais[i]->codec->dapm.card); + +/* machine controls, routes and widgets are not prefixed */ + temp[i] = rtd->codec_dais[i]->codec->name_prefix; + rtd->codec_dais[i]->codec->name_prefix =NULL ; + }/* do machine specific initialization */ if (dai_link->init) {
[...]
sound/soc/soc-core.c static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) · line 1631
Quoted 11 lines
sound/soc/soc-core.c +3
-4@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);/* link the DAI widgets */ - ret =soc_link_dai_widgets (card, dai_link, - cpu_dai, codec_dai); -if (ret) -return ret; +for (i =0 ; i < rtd->num_codecs; i++) { + ret =soc_link_dai_widgets (card, dai_link, + cpu_dai, rtd->codec_dais[i]);
This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
So there should only be one DAI link widget per DAI link, with the CPU DAI on one side and the CODEC DAIs on the other side. Note that you'll also need to re-work snd_soc_dai_link_event() to handle multiple inputs/outputs. I'd factor that part out into a separate patch.
Quoted 21 lines
sound/soc/soc-core.c +8
-2+if (ret) +return ret; + } } }/* add platform data for AC97 devices */ -if (rtd->codec_dai->driver->ac97_control) -snd_ac97_dev_add_pdata (codec->ac97, rtd->cpu_dai->ac97_pdata); +for (i =0 ; i < rtd->num_codecs; i++) { +if (rtd->codec_dais[i]->driver->ac97_control) +snd_ac97_dev_add_pdata (rtd->codec_dais[i]->codec->ac97, + rtd->cpu_dai->ac97_pdata); + }return 0 ; }@@ -1635,7 +1680,20 @@ static int soc_register_ac97_codec(struct snd_soc_codec *codec,static int soc_register_ac97_dai_link (struct snd_soc_pcm_runtime *rtd) {
sound/soc/soc-core.c static int soc_register_ac97_codec(struct snd_soc_codec *codec, · line 1691
Quoted 10 lines
sound/soc/soc-core.c +9
-1-return soc_register_ac97_codec (rtd->codec, rtd->codec_dai); +int i, ret; + +for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; + + ret =soc_register_ac97_codec (codec_dai->codec, codec_dai); +if (ret) { +while (--i >=0 ) +soc_unregister_ac97_codec (codec_dai->codec);
You use soc_unregister_ac97_codec here ...
sound/soc/soc-core.c static void soc_unregister_ac97_codec(struct snd_soc_codec *codec) · line 1707
Quoted 11 lines
sound/soc/soc-core.c +5
-0+return ret; + } + } + +return 0 ; }static void soc_unregister_ac97_codec (struct snd_soc_codec *codec)@@ -1648,7 +1706,10 @@ static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)static void soc_unregister_ac97_dai_link (struct snd_soc_pcm_runtime *rtd)
... but only define it here. This causes a compile error. Just move soc_unregister_ac97_dai_link before soc_register_ac97_codec
Quoted 9 lines
sound/soc/soc-core.c +4
-1{ -soc_unregister_ac97_codec (rtd->codec); +int i; + +for (i =0 ; i < rtd->num_codecs; i++) +soc_unregister_ac97_codec (rtd->codec_dais[i]->codec); }#endif
[...]
sound/soc/soc-core.c
Quoted 8 lines
sound/soc/soc-core.c +5
-2+static void soc_dapm_stream_event (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_dai *cpu_dai, +struct snd_soc_dai *codec_dai, +int stream,int event) +{struct snd_soc_dapm_widget *w_cpu, *w_codec; -struct snd_soc_dai *cpu_dai = rtd->cpu_dai; -struct snd_soc_dai *codec_dai = rtd->codec_dai;
The way this should be implemented is:
* Update CPU DAI (set active, mark widget dirty)
* Update all CODEC DAIs
* Run dapm_power_widgets()
Quoted 3 lines
if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
w_cpu = cpu_dai->playback_widget;[...]
sound/soc/soc-core.c void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream) · line 124
Quoted 13 lines
sound/soc/soc-core.c +4
-2@@ -107,11 +115,15 @@ void snd_soc_runtime_deactivate(struct snd_soc_pcm_runtime *rtd, int stream)*/ bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd) { +int i, ignore =0 ; +if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)return true; -return rtd->cpu_dai->component->ignore_pmdown_time && - rtd->codec_dai->component->ignore_pmdown_time; +for (i =0 ; (i < rtd->num_codecs) && !ignore; i++) + ignore |= rtd->codec_dais[i]->component->ignore_pmdown_time;
The power-down delay must only be ignored if all components connected to the DAI link agree that it can be ignored.
Quoted 16 lines
sound/soc/soc-core.c +3
-2+ +return rtd->cpu_dai->component->ignore_pmdown_time && ignore; }/** @@ -222,8 +234,7 @@ static int soc_pcm_params_symmetry(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 *codec_dai = rtd->codec_dai; -unsigned int rate, channels, sample_bits, symmetry; +unsigned int rate, channels, sample_bits, symmetry, i; rate =params_rate (params); channels =params_channels (params);
sound/soc/soc-core.c static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream, · line 249
Quoted 9 lines
sound/soc/soc-core.c +4
-1@@ -231,8 +242,12 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,/* reject unmatched parameters when applying symmetry */ symmetry = cpu_dai->driver->symmetric_rates || - codec_dai->driver->symmetric_rates || rtd->dai_link->symmetric_rates; + +for (i =0 ; i < rtd->num_codecs; i++) + symmetry = rtd->codec_dais[i]->driver->symmetric_rates || + symmetry;
Just writing symmetery |= ... should be fine, that makes it a bit shorter. Same comment for the same pattern below.
Quoted 5 lines
sound/soc/soc-core.c +1
-0+if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) {dev_err (rtd->dev,"ASoC: unmatched rate symmetry: %d - %d\n" , cpu_dai->rate, rate);@@ -240,8 +255,12 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
[...]
Quoted 14 lines
sound/soc/soc-core.c +2
-2@@ -418,22 +487,22 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) 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; }
sound/soc/soc-core.c static int soc_pcm_open(struct snd_pcm_substream *substream) · line 505
Quoted 10 lines
sound/soc/soc-core.c +2
-2if (!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, codec_dai); +soc_pcm_apply_msb (substream, rtd->codec_dais[0 ]);
The msb constraint that gets applied for the CODEC side should be the maximum over all the CODECs sig_bits. If one of them is 0 there is no constraint from the CODEC side.
Quoted 3 lines
sound/soc/soc-core.c +0
-0soc_pcm_apply_msb (substream, cpu_dai);/* Symmetry only applies if we've already got an active stream. */
[...]
Quoted 23 lines
sound/soc/soc-core.c +3
-7@@ -2181,22 +2364,28 @@ 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_platform *platform = rtd->platform; -struct snd_soc_dai *codec_dai = rtd->codec_dai; +struct snd_soc_dai *codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai;struct snd_pcm *pcm;char new_name[64 ];int ret =0 , playback =0 , capture =0 ; +int i;if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { playback = rtd->dai_link->dpcm_playback; capture = rtd->dai_link->dpcm_capture; }else { -if (codec_dai->driver->playback.channels_min && - cpu_dai->driver->playback.channels_min) - playback =1 ; -if (codec_dai->driver->capture.channels_min && - cpu_dai->driver->capture.channels_min) - capture =1 ; +for (i =0 ; i < rtd->num_codecs; i++) {
sound/soc/soc-core.c static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream) · line 2388
Quoted 10 lines
sound/soc/soc-core.c +10
-0+ codec_dai = rtd->codec_dais[i]; +if (codec_dai->driver->playback.channels_min && + cpu_dai->driver->playback.channels_min) + playback++; +if (codec_dai->driver->capture.channels_min && + cpu_dai->driver->capture.channels_min) + capture++; + } + capture = (rtd->num_codecs == capture); + playback = (rtd->num_codecs == playback);
I think it should be sufficent if at least one of them has a channels_min != 0 to create the stream. Not all of the CODEC necesarrily do have to have data flowing in both directions. So thing like:
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->playback.channels_min)
codec_playback = true;
if (codec_dai->driver->capture.channels_min)
codec_capture = true;
}
if (cpu_dai->driver->playback.channels_min &&
codec_playback)
playback = true;
...Quoted 1 line
sound/soc/soc-core.c +0
-0}
[...]
Hi Lars,
Quoted 15 lines · Lars-Peter Clausen
Quoted 14 lines · Benoit Cousson
DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new '
snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node orcodec_name).Fix a trailing space in the header as well.
Quoted 7 lines
Quoted 5 lines
Based on an original code done by Misael.
Signed-off-by Benoit Cousson <[email protected]>Signed-off-by Misael Lopez Cruz <[email protected]>Signed-off-by Fabien Parent <[email protected]>Looks mostly good. A few bits and pieces here and there, comments inline.
Cool, it is getting closer :-)
Quoted 19 lines
[...]
Quoted 17 lines
include/sound/soc.h +6
-0@@ -821,6 +821,12 @@ struct snd_soc_platform_driver {int (*bespoke_trigger)(struct snd_pcm_substream *,int ); }; +struct snd_soc_dai_link_component { +const char *name; +const struct device_node *of_node; +const char *dai_name; +}; +struct snd_soc_platform {const char *name;int id;
Quoted 8 lines
include/sound/soc.h struct snd_soc_dai_link { · line 880
Quoted 6 lines
include/sound/soc.h +2
-0@@ -870,6 +876,10 @@ struct snd_soc_dai_link {const struct device_node *codec_of_node;/* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + +struct snd_soc_dai_link_component *codecs;Should probably be const
OK.
Quoted 38 lines
Quoted 6 lines
include/sound/soc.h +2
-0+unsigned int num_codecs; +/* * You MAY specify the link's platform/PCM/DMA driver, either by * device name, or by DT/OF node, but not both. Some forms of link [...]
Quoted 31 lines
include/sound/soc.h +9
-11@@ -620,23 +631,26 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) {struct snd_soc_codec *codec = rtd->codec;struct snd_soc_platform *platform = rtd->platform; -struct snd_soc_dai *codec_dai = rtd->codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai;struct snd_compr *compr;struct snd_pcm *be_pcm;char new_name[64 ]; -int ret =0 , direction =0 ; +int i, ret =0 , direction =0 ; -/* check client and interface hw capabilities */ -snprintf (new_name,sizeof (new_name),"%s %s-%d" , - rtd->dai_link->stream_name, codec_dai->name, num); -if (codec_dai->driver->playback.channels_min) - direction =SND_COMPRESS_PLAYBACK ; -else if (codec_dai->driver->capture.channels_min) - direction =SND_COMPRESS_CAPTURE ; -else -return -EINVAL ; +for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +/* check client and interface hw capabilities */ +snprintf (new_name,sizeof (new_name),"%s %s-%d" , + rtd->dai_link->stream_name, codec_dai->name, num); + +if (codec_dai->driver->playback.channels_min) + direction =SND_COMPRESS_PLAYBACK ;
Quoted 8 lines
include/sound/soc.h int soc_new_compress(struct snd_soc_pcm_runtime · line 654
Quoted 5 lines
include/sound/soc.h +5
-0+else if (codec_dai->driver->capture.channels_min) + direction =SND_COMPRESS_CAPTURE ; +else +return -EINVAL ; + }This loop makes no sense, you just end up overwriting
new_nameand direction with each loop iteration.
Mmm, indeed! I just did a dumb search and replace without understanding what that was doing :-)
In that case we could potentially check that everything codecs does have the same direction... hoping it will be the case.
Quoted 44 lines
Quoted 24 lines
include/sound/soc.h +5
-2compr =kzalloc (sizeof (*compr),GFP_KERNEL );if (compr ==NULL ) {@@ -690,8 +704,11 @@ int soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) rtd->compr = compr; compr->private_data = rtd; -printk (KERN_INFO "compress asoc: %s <-> %s mapping ok\n" , codec_dai->name, - cpu_dai->name); + for (i = 0; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +printk (KERN_INFO "compress asoc: %s <-> %s mapping ok\n" , + codec_dai->name, cpu_dai->name); + }return ret;
compr_err:sound/soc/soc-core.c +0
-0[...]
Quoted 19 lines
sound/soc/soc-core.c +3
-5@@ -1294,20 +1324,28 @@ static int soc_aux_dev_init(structsnd_soc_card *card, return 0; } -static int soc_dai_link_init (struct snd_soc_card *card, -struct snd_soc_codec *codec, -int num) +static int soc_dai_link_init (struct snd_soc_card *card,int num) {struct snd_soc_dai_link *dai_link = &card->dai_link[num];struct snd_soc_pcm_runtime *rtd = &card->rtd[num]; -const char *temp; -int ret; +const char **temp; +int i, ret; rtd->card = card;
Quoted 11 lines
sound/soc/soc-core.c static int soc_aux_dev_init(struct snd_soc_card *card, · line 1340
Quoted 8 lines
sound/soc/soc-core.c +5
-3-/* machine controls, routes and widgets are not prefixed */ - temp = codec->name_prefix; - codec->name_prefix =NULL ; + temp =devm_kzalloc (card->dev, rtd->num_codecs *sizeof (char *), +GFP_KERNEL ); +if (!temp) +return -ENOMEM ; +Setting
name_prefixtemporarily to NULL is no longer necessary, see the patch I just sent out.
Yep, I saw it. Sorry for pulling some code you've just removed.
Quoted 33 lines
Quoted 12 lines
sound/soc/soc-core.c +8
-0+for (i =0 ; i < rtd->num_codecs; i++) { +/* Make sure all DAPM widgets are instantiated */ +snd_soc_dapm_new_widgets (rtd->codec_dais[i]->codec->dapm.card); + +/* machine controls, routes and widgets are not prefixed */ + temp[i] = rtd->codec_dais[i]->codec->name_prefix; + rtd->codec_dais[i]->codec->name_prefix =NULL ; + }/* do machine specific initialization */ if (dai_link->init) {[...]
sound/soc/soc-core.c static int soc_probe_link_dais(struct · line 1632
Quoted 12 lines
sound/soc/soc-core.c +3
-4@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);/* link the DAI widgets */ - ret =soc_link_dai_widgets (card, dai_link, - cpu_dai, codec_dai); -if (ret) -return ret; +for (i =0 ; i < rtd->num_codecs; i++) { + ret =soc_link_dai_widgets (card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
Quoted 4 lines
So there should only be one DAI link widget per DAI link, with the CPU DAI on one side and the CODEC DAIs on the other side. Note that you'll also need to re-work
snd_soc_dai_link_event()to handle multiple inputs/outputs. I'd factor that part out into a separate patch.
OK.
Quoted 47 lines
Quoted 23 lines
sound/soc/soc-core.c +8
-2+if (ret) +return ret; + } } }/* add platform data for AC97 devices */ -if (rtd->codec_dai->driver->ac97_control) -snd_ac97_dev_add_pdata (codec->ac97, rtd->cpu_dai->ac97_pdata); +for (i =0 ; i < rtd->num_codecs; i++) { +if (rtd->codec_dais[i]->driver->ac97_control) +snd_ac97_dev_add_pdata (rtd->codec_dais[i]->codec->ac97, + rtd->cpu_dai->ac97_pdata); + }return 0 ;}sound/soc/soc-core.c +0
-0@@ -1635,7 +1680,20 @@ static int soc_register_ac97_codec(struct snd_soc_codec *codec, static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd) {sound/soc/soc-core.c static int soc_register_ac97_codec(struct · line 1692
Quoted 10 lines
sound/soc/soc-core.c +9
-1-return soc_register_ac97_codec (rtd->codec, rtd->codec_dai); +int i, ret; + +for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; + + ret =soc_register_ac97_codec (codec_dai->codec, codec_dai); +if (ret) { +while (--i >=0 ) +soc_unregister_ac97_codec (codec_dai->codec);You use
soc_unregister_ac97_codechere ...Quoted 11 lines
sound/soc/soc-core.c +5
-0+return ret; + } + } + +return 0 ; }static void
soc_unregister_ac97_codec(struct snd_soc_codec *codec)sound/soc/soc-core.c +0
-0@@ -1648,7 +1706,10 @@ static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
Quoted 6 lines
sound/soc/soc-core.c static void soc_unregister_ac97_codec(struct · line 1709
Quoted 2 lines
sound/soc/soc-core.c +0
-0static void soc_unregister_ac97_dai_link (struct snd_soc_pcm_runtime *rtd)... but only define it here. This causes a compile error. Just move
soc_unregister_ac97_dai_linkbeforesoc_register_ac97_codec
Oops, I did not have the CONFIG_SND_SOC_AC97_BUS enabled and missed that issue.
Quoted 10 lines
Quoted 9 lines
sound/soc/soc-core.c +4
-1{ -soc_unregister_ac97_codec (rtd->codec); +int i; + +for (i =0 ; i < rtd->num_codecs; i++) +soc_unregister_ac97_codec (rtd->codec_dais[i]->codec); }#endif[...]
Quoted 13 lines
sound/soc/soc-core.c
Quoted 8 lines
sound/soc/soc-core.c +5
-2+static void soc_dapm_stream_event (struct snd_soc_pcm_runtime *rtd, +struct snd_soc_dai *cpu_dai, +struct snd_soc_dai *codec_dai, +int stream,int event) +{struct snd_soc_dapm_widget *w_cpu, *w_codec; -struct snd_soc_dai *cpu_dai = rtd->cpu_dai; -struct snd_soc_dai *codec_dai = rtd->codec_dai;The way this should be implemented is:
* Update CPU DAI (set active, mark widget dirty)
* Update all CODEC DAIs
* Rundapm_power_widgets()
OK.
Quoted 16 lines
Quoted 4 lines
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { w_cpu = cpu_dai->playback_widget;[...]
Quoted 11 lines
sound/soc/soc-core.c +2
-0@@ -107,11 +115,15 @@ void snd_soc_runtime_deactivate(structsnd_soc_pcm_runtime *rtd, int stream) */ bool snd_soc_runtime_ignore_pmdown_time (struct snd_soc_pcm_runtime *rtd) { +int i, ignore =0 ; +if (!rtd->pmdown_time || rtd->dai_link->ignore_pmdown_time)return true;
Quoted 7 lines
sound/soc/soc-core.c void snd_soc_runtime_deactivate(struct · line 126
Quoted 4 lines
sound/soc/soc-core.c +2
-2-return rtd->cpu_dai->component->ignore_pmdown_time && - rtd->codec_dai->component->ignore_pmdown_time; +for (i =0 ; (i < rtd->num_codecs) && !ignore; i++) + ignore |= rtd->codec_dais[i]->component->ignore_pmdown_time;The power-down delay must only be ignored if all components connected to the DAI link agree that it can be ignored.
OK, so it should be an "&" then.
Quoted 20 lines
Quoted 20 lines
sound/soc/soc-core.c +2
-0+ +return rtd->cpu_dai->component->ignore_pmdown_time && ignore; }/**
sound/soc/soc-core.c +1
-2@@ -222,8 +234,7 @@ static int soc_pcm_params_symmetry(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 *codec_dai = rtd->codec_dai; -unsigned int rate, channels, sample_bits, symmetry; +unsigned int rate, channels, sample_bits, symmetry, i; rate =params_rate (params);channels = params_channels(params);sound/soc/soc-core.c +0
-0@@ -231,8 +242,12 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,
Quoted 11 lines
sound/soc/soc-core.c static int soc_pcm_params_symmetry(struct · line 250
Quoted 8 lines
sound/soc/soc-core.c +4
-1/* reject unmatched parameters when applying symmetry */ symmetry = cpu_dai->driver->symmetric_rates || - codec_dai->driver->symmetric_rates || rtd->dai_link->symmetric_rates; + +for (i =0 ; i < rtd->num_codecs; i++) + symmetry = rtd->codec_dais[i]->driver->symmetric_rates || + symmetry;Just writing symmetery |= ... should be fine, that makes it a bit shorter. Same comment for the same pattern below.
OK.
Quoted 31 lines
Quoted 7 lines
sound/soc/soc-core.c +1
-0+if (symmetry && cpu_dai->rate && cpu_dai->rate != rate) { dev_err(rtd->dev, "ASoC: unmatched rate symmetry: %d - %d\n",cpu_dai->rate, rate);sound/soc/soc-core.c +0
-0@@ -240,8 +255,12 @@ static int soc_pcm_params_symmetry(struct snd_pcm_substream *substream,[...]
Quoted 23 lines
sound/soc/soc-core.c +3
-3@@ -418,22 +487,22 @@ static int soc_pcm_open(struct snd_pcm_substream *substream) 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; }
Quoted 6 lines
sound/soc/soc-core.c static int soc_pcm_open(struct snd_pcm_substream · line 506
Quoted 2 lines
sound/soc/soc-core.c +1
-1-soc_pcm_apply_msb (substream, codec_dai); +soc_pcm_apply_msb (substream, rtd->codec_dais[0 ]);The msb constraint that gets applied for the CODEC side should be the maximum over all the CODECs
sig_bits. If one of them is 0 there is no constraint from the CODEC side.
OK.
Quoted 44 lines
Quoted 4 lines
sound/soc/soc-core.c +0
-0soc_pcm_apply_msb (substream, cpu_dai);/* Symmetry only applies if we've already got an active stream. */[...]
Quoted 24 lines
sound/soc/soc-core.c +3
-7@@ -2181,22 +2364,28 @@ 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_platform *platform = rtd->platform; -struct snd_soc_dai *codec_dai = rtd->codec_dai; +struct snd_soc_dai *codec_dai;struct snd_soc_dai *cpu_dai = rtd->cpu_dai;struct snd_pcm *pcm;char new_name[64 ];int ret =0 , playback =0 , capture =0 ; +int i;if (rtd->dai_link->dynamic || rtd->dai_link->no_pcm) { playback = rtd->dai_link->dpcm_playback; capture = rtd->dai_link->dpcm_capture; }else { -if (codec_dai->driver->playback.channels_min && - cpu_dai->driver->playback.channels_min) - playback =1 ; -if (codec_dai->driver->capture.channels_min && - cpu_dai->driver->capture.channels_min) - capture =1 ; +for (i =0 ; i < rtd->num_codecs; i++) {sound/soc/soc-core.c static int dpcm_fe_dai_close(struct · line 2389
Quoted 10 lines
sound/soc/soc-core.c +10
-0+ codec_dai = rtd->codec_dais[i]; +if (codec_dai->driver->playback.channels_min && + cpu_dai->driver->playback.channels_min) + playback++; +if (codec_dai->driver->capture.channels_min && + cpu_dai->driver->capture.channels_min) + capture++; + } + capture = (rtd->num_codecs == capture); + playback = (rtd->num_codecs == playback);I think it should be sufficent if at least one of them has a
channels_min!= 0 to create the stream. Not all of the CODEC necesarrily do have to have data flowing in both directions. So thing like:
Quoted 13 lines
for (i = 0; i < rtd->num_codecs; i++) {
codec_dai = rtd->codec_dais[i];
if (codec_dai->driver->playback.channels_min)
codec_playback = true;
if (codec_dai->driver->capture.channels_min)
codec_capture = true;
}
if (cpu_dai->driver->playback.channels_min &&
codec_playback)
playback = true;
...OK.
Quoted 3 lines
Quoted 2 lines
sound/soc/soc-core.c +0
-0}[...]
Thanks for exhaustive review and comments.
I'll try to update faster than for the v3, but I'm stuck at ELC this week.
Regards,
Benoit
Signature · 4 lines
Benoît Cousson BayLibre Embedded Linux Technology Lab www.baylibre.com
Hi Lars,
I'm struggling a little bit to understand one of your comment :-)
Quoted 9 lines · Lars-Peter Clausen
include/sound/soc.h struct snd_soc_dai_link { · line 880
Quoted 6 lines · Benoit Cousson
include/sound/soc.h +2
-0@@ -870,6 +876,10 @@ struct snd_soc_dai_link {const struct device_node *codec_of_node;/* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + +struct snd_soc_dai_link_component *codecs;Should probably be const
In fact, I don't think this is not possible, since this struct will be initialized at runtime in the legacy case when the regular codec struct is the one used by the driver.
[...]
Quoted 4 lines
Quoted 4 lines
sound/soc/soc-core.c +0
-0@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);
Quoted 15 lines
sound/soc/soc-core.c static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) · line 1631
Quoted 8 lines
sound/soc/soc-core.c +3
-4/* link the DAI widgets */ - ret =soc_link_dai_widgets (card, dai_link, - cpu_dai, codec_dai); -if (ret) -return ret; +for (i =0 ; i < rtd->num_codecs; i++) { + ret =soc_link_dai_widgets (card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
I've got that point, but now I'm wondering what struct should be per codec_dai. Should we consider one source and several sinks to represent the multiple codecs?
Quoted 4 lines
So there should only be one DAI link widget per DAI link, with the CPU DAI on one side and the CODEC DAIs on the other side. Note that you'll also need to re-work
snd_soc_dai_link_event()to handle multiple inputs/outputs. I'd factor that part out into a separate patch.
Here, I'm lost :-)
What struct should be made multiple in that case?
Should we consider that the following list can handle multiple sink/source?
/* We only support a single source and sink, pick the first */ source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, list_sink); sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, list_source);
[...]
Thanks,
Benoit
Signature · 4 lines
Benoît Cousson BayLibre Embedded Linux Technology Lab www.baylibre.com
Quoted 15 lines · Benoit Cousson
Hi Lars,
I'm struggling a little bit to understand one of your comment :-)
Quoted 9 lines · Lars-Peter Clausen
Review struct snd_soc_dai_link { · line 880
Quoted 6 lines · Benoit Cousson
(quoted diff) +2
-0@@ -870,6 +876,10 @@ struct snd_soc_dai_link { const struct device_node *codec_of_node; /* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + + struct snd_soc_dai_link_component *codecs;Should probably be const
Quoted 1 line
In fact, I don't think this is not possible, since this struct will be initialized at runtime in the legacy case when the regular codec struct is the one used by the driver.
That shouldn't be a problem. The const applies to the data the pointer points to, not the pointer itself.
Quoted 23 lines
[...]
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);Quoted 15 lines
Review static int soc_probe_link_dais(struct · line 1632
Quoted 8 lines
(quoted diff) +3
-4/* link the DAI widgets */ - ret = soc_link_dai_widgets(card, dai_link, - cpu_dai, codec_dai); - if (ret) - return ret; + for (i = 0; i < rtd->num_codecs; i++) { + ret = soc_link_dai_widgets(card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
Quoted 1 line
I've got that point, but now I'm wondering what struct should be per
codec_dai. Should we consider one source and several sinks to represent the multiple codecs?
The soc_link_dai_widgets function should take the rtd as a parameter instead of the CODEC and CPU DAIs. Same goes for snd_soc_dapm_new_pcm() then you create one dai_link widget per stream (i.e. one for capture of there is capture support, one for playback if there is playback support). And then create the paths between the dai_link widgets and the DAI widgets accordingly.
Quoted 12 lines
Quoted 5 lines
So there should only be one DAI link widget per DAI link, with the CPU DAI on one side and the CODEC DAIs on the other side. Note that you'll also need to re-work
snd_soc_dai_link_event()to handle multiple inputs/outputs. I'd factor that part out into a separate patch.Here, I'm lost :-)
What struct should be made multiple in that case?
Should we consider that the following list can handle multiple sink/source?
Quoted 7 lines
/* We only support a single source and sink, pick the first */ source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, list_sink); sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, list_source);[...]
See the attached patch.
If you don't want to worry about these things for now it should be fine to add a check in soc_probe_link_dais() and make sure that num_codecs == 1 for the CODEC to CODEC case. This means we'll not support multi-codec links for CODEC to CODEC links, which should in my opinion be fine for now.
Quoted 1 line
From
feea1b5612da70bef7dc15a8af8797e56a93e129Mon Sep 17 00:00:00 2001
From: Lars-Peter Clausen <[email protected]>
Date: Sun, 4 May 2014 13:06:15 +0200
Subject: [PATCH] ASoC: dapm: Handle multiple DAIs in snd_soc_dai_link_event()
--- sound/soc/soc-dapm.c | 115 ++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 61 deletions(-)
sound/soc/soc-dapm.c +54 -61
@@ -3139,35 +3139,60 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm, }EXPORT_SYMBOL_GPL (snd_soc_dapm_new_controls); +static void snd_soc_dai_event (struct snd_soc_dapm_widget *w,int event, +struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) +{ +struct snd_soc_dai *dai = w->priv; +int ret; + +switch (event) { +case SND_SOC_DAPM_PRE_PMU : +if (dai->driver->ops && dai->driver->ops->hw_params) { + ret = dai->driver->ops->hw_params (substream, params, + source); +if (ret !=0 ) { +dev_err (dai->dev, +"ASoC: hw_params() failed: %d\n" , ret); +return ret; + } + } +break ; +case SND_SOC_DAPM_POST_PMU : + ret =snd_soc_dai_digital_mute (dai,0 , stream); +if (ret !=0 && ret != -ENOTSUPP ) +dev_warn (dai->dev,"ASoC: Failed to unmute: %d\n" , ret); + ret =0 ; +break ; + +case SND_SOC_DAPM_PRE_PMD : + ret =snd_soc_dai_digital_mute (dai,1 , stream); +if (ret !=0 && ret != -ENOTSUPP ) +dev_warn (dai->dev,"ASoC: Failed to mute: %d\n" , ret); + ret =0 ; +break ; + +default : +WARN (1 ,"Unknown event %d\n" , event); +return -EINVAL ; + } + +return 0 ; +} + +static int snd_soc_dai_link_event (struct snd_soc_dapm_widget *w,struct snd_kcontrol *kcontrol,int event) { -struct snd_soc_dapm_path *source_p, *sink_p; -struct snd_soc_dai *source, *sink;const struct snd_soc_pcm_stream *config = w->params;struct snd_pcm_substream substream;struct snd_pcm_hw_params *params =NULL ; +struct snd_soc_dapm_path *p;u64 fmt;int ret; -if (WARN_ON (!config) || -WARN_ON (list_empty (&w->sources) ||list_empty (&w->sinks))) +if (WARN_ON (!config))return -EINVAL ; -/* We only support a single source and sink, pick the first */ - source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, - list_sink); - sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path, - list_source); - -if (WARN_ON (!source_p || !sink_p) || -WARN_ON (!sink_p->source || !source_p->sink) || -WARN_ON (!source_p->source || !sink_p->sink)) -return -EINVAL ; - - source = source_p->source->priv; - sink = sink_p->sink->priv; -/* Be a little careful as we don't want to overflow the mask array */ if (config->formats) { fmt =ffs (config->formats) -1 ;
@@ -3197,50 +3222,18 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,memset (&substream,0 ,sizeof (substream)); -switch (event) { -case SND_SOC_DAPM_PRE_PMU : -if (source->driver->ops && source->driver->ops->hw_params) { - substream.stream =SNDRV_PCM_STREAM_CAPTURE ; - ret = source->driver->ops->hw_params (&substream, - params, source); -if (ret !=0 ) { -dev_err (source->dev, -"ASoC: hw_params() failed: %d\n" , ret); - goto out; - } - } - -if (sink->driver->ops && sink->driver->ops->hw_params) { - substream.stream =SNDRV_PCM_STREAM_PLAYBACK ; - ret = sink->driver->ops->hw_params (&substream, params, - sink); -if (ret !=0 ) { -dev_err (sink->dev, -"ASoC: hw_params() failed: %d\n" , ret); - goto out; - } - } -break ; - -case SND_SOC_DAPM_POST_PMU : - ret =snd_soc_dai_digital_mute (sink,0 , -SNDRV_PCM_STREAM_PLAYBACK ); -if (ret !=0 && ret != -ENOTSUPP ) -dev_warn (sink->dev,"ASoC: Failed to unmute: %d\n" , ret); - ret =0 ; -break ; - -case SND_SOC_DAPM_PRE_PMD : - ret =snd_soc_dai_digital_mute (sink,1 , -SNDRV_PCM_STREAM_PLAYBACK ); -if (ret !=0 && ret != -ENOTSUPP ) -dev_warn (sink->dev,"ASoC: Failed to mute: %d\n" , ret); - ret =0 ; -break ; + substream.stream =SNDRV_PCM_STREAM_CAPTURE ; +list_for_each_entry (p, &w->sources, list_sink) { + ret =snd_soc_dai_event (p->source, event, params, &substream); +if (ret) + goto out; + } -default : -WARN (1 ,"Unknown event %d\n" , event); -return -EINVAL ; + substream.stream =SNDRV_PCM_STREAM_PLAYBACK ; +list_for_each_entry (p, &w->sinks, list_source) { + ret =snd_soc_dai_event (p->sink, event, params, &substream); +if (ret) + goto out; } out:
Signature · 1 line
1.8.0
Quoted 16 lines · Lars-Peter Clausen
Quoted 15 lines · Benoit Cousson
Hi Lars,
I'm struggling a little bit to understand one of your comment :-)
Quoted 9 lines · Lars-Peter Clausen
Review struct snd_soc_dai_link { · line 880
Quoted 6 lines · Benoit Cousson
(quoted diff) +2
-0@@ -870,6 +876,10 @@ struct snd_soc_dai_link { const struct device_node *codec_of_node; /* You MUST specify the DAI name within the codec */ const char *codec_dai_name; + + struct snd_soc_dai_link_component *codecs;Should probably be const
Quoted 6 lines
Quoted 3 lines
In fact, I don't think this is not possible, since this struct will be initialized at runtime in the legacy case when the regular codec struct is the one used by the driver.
That shouldn't be a problem. The const applies to the data the pointer points to, not the pointer itself.
Yeah, I know. But in that case, we populate the data based on the ones in the codec struct. We do not just assign the pointer. The fact is the compiler is complaining about that anyway :-)
Quoted 26 lines
Quoted 22 lines
[...]
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);Quoted 15 lines
Review static int soc_probe_link_dais(struct · line 1632
Quoted 8 lines
(quoted diff) +3
-4/* link the DAI widgets */ - ret = soc_link_dai_widgets(card, dai_link, - cpu_dai, codec_dai); - if (ret) - return ret; + for (i = 0; i < rtd->num_codecs; i++) { + ret = soc_link_dai_widgets(card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
Quoted 3 lines
I've got that point, but now I'm wondering what struct should be per
codec_dai. Should we consider one source and several sinks to represent the multiple codecs?
Quoted 6 lines
The
soc_link_dai_widgetsfunction should take the rtd as a parameter instead of the CODEC and CPU DAIs. Same goes forsnd_soc_dapm_new_pcm()then you create onedai_linkwidget per stream (i.e. one for capture of there is capture support, one for playback if there is playback support). And then create the paths between thedai_linkwidgets and the DAI widgets accordingly.
Yep, I've done that part already, but this is widget -> dai relation that was not clear to me.
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines
So there should only be one DAI link widget per DAI link, with the CPU DAI on one side and the CODEC DAIs on the other side. Note that you'll also need to re-work
snd_soc_dai_link_event()to handle multiple inputs/outputs. I'd factor that part out into a separate patch.Here, I'm lost :-)
What struct should be made multiple in that case?
Should we consider that the following list can handle multiple sink/source?
/* We only support a single source and sink, pick the first */ source_p = list_first_entry(&w->sources, struct snd_soc_dapm_path, list_sink); sink_p = list_first_entry(&w->sinks, struct snd_soc_dapm_path,But
Quoted 5 lines
Quoted 3 lines
list_source);[...]
See the attached patch.
Cool, thanks for that.
Quoted 4 lines
If you don't want to worry about these things for now it should be fine to add a check in
soc_probe_link_dais()and make sure thatnum_codecs== 1 for the CODEC to CODEC case. This means we'll not support multi-codec links for CODEC to CODEC links, which should in my opinion be fine for now.
That sounds like a good plan to me. The patch is already pretty big, and assumning it will not generate regression in the regular case (single codec), it might be good to start merging the current work in progress and add the full multi codec support later.
I'll repost to fix the current comments and let you decide what you'll do with that code :-)
Thanks for the help,
Benoit
Signature · 4 lines
Benoît Cousson BayLibre Embedded Linux Technology Lab www.baylibre.com
Hi Lars,
Quoted 1 line · Lars-Peter Clausen
On 05/15/2014 05:01 PM, Benoit Cousson wrote:
[...]
Quoted 24 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);Quoted 15 lines
Review static int soc_probe_link_dais(struct · line 1632
Quoted 8 lines
(quoted diff) +3
-4/* link the DAI widgets */ - ret = soc_link_dai_widgets(card, dai_link, - cpu_dai, codec_dai); - if (ret) - return ret; + for (i = 0; i < rtd->num_codecs; i++) { + ret = soc_link_dai_widgets(card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
Quoted 3 lines
I've got that point, but now I'm wondering what struct should be per
codec_dai. Should we consider one source and several sinks to represent the multiple codecs?
Quoted 6 lines
The
soc_link_dai_widgetsfunction should take the rtd as a parameter instead of the CODEC and CPU DAIs. Same goes forsnd_soc_dapm_new_pcm()then you create onedai_linkwidget per stream (i.e. one for capture of there is capture support, one for playback if there is playback support). And then create the paths between thedai_linkwidgets and the DAI widgets accordingly.
I'm still not 100% sure how it should work so here is a tentative patch to try to handle that part. Please note that in my setup none of that code is ever called :-( I'm not sure why!
Please ignore the extra DEBUG code I added and there is probably some way to factorize some code, but I'd like to be sure that this is the proper way to handle the routes in the multicodec case before re-sending that series.
Thanks,
Benoit
---
Quoted 1 line
From
565bfa3f31abbe2b677238ed423eb9fa99609086Mon Sep 17 00:00:00 2001
From: Benoit Cousson <[email protected]>
Date: Thu, 22 May 2014 08:54:54 +0200
Subject: [PATCH] ASoC: Temp: Tentative multicodec adaptation for dapm routes
--- include/sound/soc-dapm.h | 3 +- sound/soc/soc-core.c | 31 +---------- sound/soc/soc-dapm.c | 132 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 113 insertions(+), 53 deletions(-)
include/sound/soc-dapm.h +1 -2
@@ -381,8 +381,7 @@ int snd_soc_dapm_link_dai_widgets(struct snd_soc_card *card);void snd_soc_dapm_connect_dai_link_widgets (struct snd_soc_card *card);int snd_soc_dapm_new_pcm (struct snd_soc_card *card,const struct snd_soc_pcm_stream *params, -struct snd_soc_dapm_widget *source, -struct snd_soc_dapm_widget *sink); +struct snd_soc_pcm_runtime *rtd);/* dapm path setup */ int snd_soc_dapm_new_widgets (struct snd_soc_card *card);
sound/soc/soc-core.c +1 -30
@@ -1483,37 +1483,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card,struct snd_soc_dai_link *dai_link, struct snd_soc_pcm_runtime *rtd) { - struct snd_soc_dai *cpu_dai = rtd->cpu_dai; -struct snd_soc_dai *codec_dai = rtd->codec_dai; -struct snd_soc_dapm_widget *play_w, *capture_w; -int ret; - /* link the DAI widgets */ - play_w = codec_dai->playback_widget; - capture_w = cpu_dai->capture_widget; -if (play_w && capture_w) { - ret =snd_soc_dapm_new_pcm (card, dai_link->params, - capture_w, play_w); -if (ret !=0 ) { -dev_err (card->dev,"ASoC: Can't link %s to %s: %d\n" , - play_w->name, capture_w->name, ret); -return ret; - } - } - - play_w = cpu_dai->playback_widget; - capture_w = codec_dai->capture_widget; -if (play_w && capture_w) { - ret =snd_soc_dapm_new_pcm (card, dai_link->params, - capture_w, play_w); -if (ret !=0 ) { -dev_err (card->dev,"ASoC: Can't link %s to %s: %d\n" , - play_w->name, capture_w->name, ret); -return ret; - } - } - -return 0 ; + return snd_soc_dapm_new_pcm(card, dai_link->params,rtd); }static int soc_probe_link_dais (struct snd_soc_card *card,int num,int order)
sound/soc/soc-dapm.c +111 -21
162 lines not on this page · raw message
Signature · 9 lines
1.8.3.2 -- Benoît Cousson BayLibre Embedded Linux Technology Lab www.baylibre.com
Quoted 38 lines · Benoit Cousson
Hi Lars,
Quoted 1 line · Lars-Peter Clausen
On 05/15/2014 05:01 PM, Benoit Cousson wrote:
[...]
Quoted 24 lines
Quoted 20 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0
-0@@ -1586,16 +1626,21 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order) codec2codec_close_delayed_work);Quoted 15 lines
Review static int soc_probe_link_dais(struct · line 1632
Quoted 8 lines
(quoted diff) +3
-4/* link the DAI widgets */ - ret = soc_link_dai_widgets(card, dai_link, - cpu_dai, codec_dai); - if (ret) - return ret; + for (i = 0; i < rtd->num_codecs; i++) { + ret = soc_link_dai_widgets(card, dai_link, + cpu_dai, rtd->codec_dais[i]);This will create a DAI link widget for each CODEC DAI. The DAI link widget will configure the CPU and the CODEC DAI that are connected to it. If there is one DAI link widget per CODEC DAI this means that the CPU DAI will be connected to multiple DAI link widgets, which means it will be configured once for each CODEC DAI (with possible conflicting configurations).
Quoted 3 lines
I've got that point, but now I'm wondering what struct should be per
codec_dai. Should we consider one source and several sinks to represent the multiple codecs?Quoted 6 lines
The
soc_link_dai_widgetsfunction should take the rtd as a parameter instead of the CODEC and CPU DAIs. Same goes forsnd_soc_dapm_new_pcm()then you create onedai_linkwidget per stream (i.e. one for capture of there is capture support, one for playback if there is playback support). And then create the paths between thedai_linkwidgets and the DAI widgets accordingly.
Quoted 3 lines
I'm still not 100% sure how it should work so here is a tentative patch to try to handle that part. Please note that in my setup none of that code is ever called :-( I'm not sure why!
Please ignore the extra DEBUG code I added and there is probably some way to factorize some code, but I'd like to be sure that this is the proper way to handle the routes in the multicodec case before re-sending that series.
If we do not want to support CODEC<-->CODEC links with multiple CODECs you do not have to care about this for now. But I think the code looks good. The result should look something like this:
+----------+
| Playback | --> [ CODEC 1 DAI ]
[ CPU ] --> | DAI LINK | --> [ CODEC 2 DAI ]
| | --> [ CODEC 3 DAI ]
+----------+ +----------+
[ CODEC 1 DAI ]-- > | Capture |
[ CODEC 2 DAI ] --> | DAI LINK | --> [ CPU DAI ]
[ CODEC 3 DAI ] --> | |
+----------+Also note that the code in upstream is now using snd_soc_dapm_add_path() rather than snd_soc_dapm_add_route()
- Lars
Quoted 12 lines · Benoit Cousson
DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new '
snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node orcodec_name).
Quoted 7 lines
Fix a trailing space in the header as well.
Based on an original code done by Misael.
Signed-off-by Benoit Cousson <[email protected]>Signed-off-by Misael Lopez Cruz <[email protected]>Signed-off-by Fabien Parent <[email protected]>
Some thoughts on the parameter fixup.
Quoted 14 lines
--- include/sound/soc-dai.h | 5 + include/sound/soc.h | 13 ++ sound/soc/soc-compress.c | 83 +++++--- sound/soc/soc-core.c | 364 ++++++++++++++++++++++----------- sound/soc/soc-dapm.c | 71 ++++--- sound/soc/soc-pcm.c | 512 ++++++++++++++++++++++++++++++++--------------- 6 files changed, 715 insertions(+), 333 deletions(-)include/sound/soc-dai.h +0
-0
include/sound/soc-dai.h struct snd_soc_dai { · line 280
Quoted 7 lines
include/sound/soc-dai.h +4
-0@@ -274,6 +274,11 @@ struct snd_soc_dai {struct snd_soc_codec *codec;struct snd_soc_component *component; +/* CODEC TDM slot masks and params (for fixup) */ +unsigned int tx_mask; +unsigned int rx_mask; +struct snd_pcm_hw_params params[2 ];
snd_pcm_hw_params is rather large, given that for a lot of setups we don't need it it might be better to make this a pointer and only allocate the params struct when needed.
[...]
Quoted 6 lines
include/sound/soc-dai.h +2
-0@@ -3624,17 +3697,26 @@ static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,int snd_soc_dai_set_tdm_slot (struct snd_soc_dai *dai,unsigned int tx_mask,unsigned int rx_mask,int slots,int slot_width) { +int ret =0 ; +
include/sound/soc-dai.h static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, · line 3711
Quoted 10 lines
include/sound/soc-dai.h +4
-0if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) dai->driver->ops->xlate_tdm_slot_mask (slots, &tx_mask, &rx_mask);else snd_soc_xlate_tdm_slot_mask (slots, &tx_mask, &rx_mask); +if (dai->codec) { + dai->tx_mask = tx_mask; + dai->rx_mask = rx_mask; + }
I don't think it makes sense to artificially limit this to just CODECs. While we do not support multiple CPU DAIs (yet?) adding the check for CODECs just makes the code more complex, but doesn't gain us anything.
[...]
include/sound/soc-dai.h static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, · line 3716
Quoted 5 lines
include/sound/soc-dai.h +5
-0+for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +struct snd_pcm_hw_params *codec_params; + + codec_params = &codec_dai->params[substream->stream];
The fixed up params are only ever used in here. Do we really need to keep two copies per CODEC DAI around?
include/sound/soc-dai.h static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
Quoted 12 lines
include/sound/soc-dai.h +12
-0+ +/* copy params for each codec */ +memcpy (codec_params, params,sizeof (struct snd_pcm_hw_params )); + +/* fixup params based on TDM slot masks */ +if (codec_dai->tx_mask) +soc_pcm_codec_params_fixup (codec_params, + codec_dai->tx_mask); +if (codec_dai->rx_mask) +soc_pcm_codec_params_fixup (codec_params, + codec_dai->rx_mask); +
If we fix-up the number of channels to be always the number of slots should we also setup a constraint for userspace that the number of channels must match the number of channels specified in the CPU DAI mask? Or should we check how many of the channels in the CODEC mask are actually active and fix-up the the number of channels according to that?
include/sound/soc-dai.h
Quoted 11 lines
include/sound/soc-dai.h +10
-0+if (codec_dai->driver->ops && + codec_dai->driver->ops->hw_params) { + ret = codec_dai->driver->ops->hw_params (substream, + codec_params, codec_dai); +if (ret <0 ) { +dev_err (codec_dai->dev, +"ASoC: can't set %s hw params: %d\n" , + codec_dai->name, ret); + goto codec_err; + } }
I think it makes sense to factor this whole block out into a helper function. E.g. soc_dai_hw_params(struct snd_soc_dai* dai, struct hw_params *params);. This will make it possible to also use it in other places like the dapm_dai_link_event() function.
Quoted 7 lines
include/sound/soc-dai.h +5
-0+ + codec_dai->rate =params_rate (codec_params); + codec_dai->channels =params_channels (codec_params); + codec_dai->sample_bits =snd_pcm_format_physical_width ( +params_format (codec_params)); }
[...]
Quoted 4 lines · Lars-Peter Clausen
[...]
I don't think it makes sense to artificially limit this to just CODECs. While we do not support multiple CPU DAIs (yet?) adding the check for CODECs just makes the code more complex, but doesn't gain us anything.
I have a related question. I am trying to put together something
that would "bridge" a spdif rx into say ssi tx on iMX6. I am just not sure how this would fit into the alsa model. Would multiple CPU DAIs be the recommended model for this. In this case I will follow this thread and try to extend/use that multiple CPU DAIs idea.
I apologise if this is not related enough to the current thread.
If it is the case I'll start a new thread.
Thanks
-- sinan
Mark Brown
maintainerQuoted 5 lines · Sinan Akman
I have a related question. I am trying to put together something
that would "bridge" a spdif rx into say ssi tx on iMX6. I am just not sure how this would fit into the alsa model. Would multiple CPU DAIs be the recommended model for this. In this case I will follow this thread and try to extend/use that multiple CPU DAIs idea.
Ideally we'd be able to set up a route between the two DAIs and then have the framework arrange for data to go from one to the other. There are hardware limitations in being able to do this - you either need ASRC in the hardware or you need to be able to ensure that all the clocks are synchronous. Right now you have to bounce everything through the application layer.
It is a somewhat different issue to the one Benoit is trying to address though.
Hi Lars,
I finally got some BW to address your second email :-)
Quoted 41 lines · Lars-Peter Clausen
Quoted 12 lines · Benoit Cousson
DAI link assumes a one to one mapping between CPU DAI and CODEC. In some cases, the same CPU DAI can be connected to several codecs. This is the case for example, if you connect two mono codecs to the same I2S link in order to have a stereo card.
The current ASoC implementation does not allow such setup.Add support for DAI links composed of a single CPU DAI and multiple CODECs. Sound cards have to pass the CODECs array in the corresponding DAI link through a new '
snd_soc_dai_link_component' struct. Each CODEC in this array is described in the same manner single CODEC DAIs are (either DT/OF node orcodec_name).Quoted 7 lines
Fix a trailing space in the header as well.
Based on an original code done by Misael.
Signed-off-by Benoit Cousson <[email protected]>Signed-off-by Misael Lopez Cruz <[email protected]>Signed-off-by Fabien Parent <[email protected]>Some thoughts on the parameter fixup.
Quoted 18 lines
--- include/sound/soc-dai.h | 5 + include/sound/soc.h | 13 ++ sound/soc/soc-compress.c | 83 +++++--- sound/soc/soc-core.c | 364 ++++++++++++++++++++++----------- sound/soc/soc-dapm.c | 71 ++++--- sound/soc/soc-pcm.c | 512 ++++++++++++++++++++++++++++++++--------------- 6 files changed, 715 insertions(+), 333 deletions(-)include/sound/soc-dai.h +0
-0@@ -274,6 +274,11 @@ struct snd_soc_dai {struct snd_soc_codec *codec;struct snd_soc_component *component;
Quoted 8 lines
include/sound/soc-dai.h struct snd_soc_dai { · line 280
Quoted 4 lines
include/sound/soc-dai.h +4
-0+/* CODEC TDM slot masks and params (for fixup) */ +unsigned int tx_mask; +unsigned int rx_mask; +struct snd_pcm_hw_params params[2 ];
snd_pcm_hw_paramsis rather large, given that for a lot of setups we don't need it it might be better to make this a pointer and only allocate the params struct when needed.
OK.
Quoted 16 lines
[...]
Quoted 14 lines
include/sound/soc-dai.h +2
-0@@ -3624,17 +3697,26 @@ static int snd_soc_xlate_tdm_slot_mask(unsigned int slots, int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width) { + int ret = 0; +if (dai->driver && dai->driver->ops->xlate_tdm_slot_mask) dai->driver->ops->xlate_tdm_slot_mask (slots, &tx_mask, &rx_mask);else snd_soc_xlate_tdm_slot_mask (slots, &tx_mask, &rx_mask);
Quoted 8 lines
include/sound/soc-dai.h static int · line 3713
Quoted 4 lines
include/sound/soc-dai.h +4
-0+if (dai->codec) { + dai->tx_mask = tx_mask; + dai->rx_mask = rx_mask; + }I don't think it makes sense to artificially limit this to just CODECs. While we do not support multiple CPU DAIs (yet?) adding the check for CODECs just makes the code more complex, but doesn't gain us anything.
OK, makes sense.
Quoted 11 lines
[...]
include/sound/soc-dai.h
Quoted 5 lines
include/sound/soc-dai.h +5
-0+for (i =0 ; i < rtd->num_codecs; i++) { +struct snd_soc_dai *codec_dai = rtd->codec_dais[i]; +struct snd_pcm_hw_params *codec_params; + + codec_params = &codec_dai->params[substream->stream];The fixed up params are only ever used in here. Do we really need to keep two copies per CODEC DAI around?
Well, we can indeed, create a local copy that will be used for the fixup. Moreover, it will avoid allocating the data dynamically.
Quoted 10 lines
Quoted 10 lines
include/sound/soc-dai.h +10
-0+ +/* copy params for each codec */ +memcpy (codec_params, params,sizeof (struct snd_pcm_hw_params )); + +/* fixup params based on TDM slot masks */ +if (codec_dai->tx_mask) +soc_pcm_codec_params_fixup (codec_params, + codec_dai->tx_mask); +if (codec_dai->rx_mask) + soc_pcm_codec_params_fixup(codec_params,
Quoted 8 lines
include/sound/soc-dai.h
Quoted 2 lines
include/sound/soc-dai.h +2
-0+ codec_dai->rx_mask); +If we fix-up the number of channels to be always the number of slots should we also setup a constraint for userspace that the number of channels must match the number of channels specified in the CPU DAI mask? Or should we check how many of the channels in the CODEC mask are actually active and fix-up the the number of channels according to that?
That's a pretty good question.
I've tried to check the current users of the snd_soc_dai_set_tdm_slot to understand how it is used in cpu/codec dais.
There are only ~10 users, and it seems that the definition of the mask is dependent of the user. I don't know if we can really enforce anything because of that :-(
Quoted 12 lines
include/sound/soc-dai.h
Quoted 11 lines
include/sound/soc-dai.h +10
-0+if (codec_dai->driver->ops && + codec_dai->driver->ops->hw_params) { + ret = codec_dai->driver->ops->hw_params (substream, + codec_params, codec_dai); +if (ret <0 ) { +dev_err (codec_dai->dev, +"ASoC: can't set %s hw params: %d\n" , + codec_dai->name, ret); + goto codec_err; + } }
Quoted 4 lines
I think it makes sense to factor this whole block out into a helper function. E.g.
soc_dai_hw_params(struct snd_soc_dai* dai, struct hw_params *params);. This will make it possible to also use it in other places like thedapm_dai_link_event()function.
OK, good point.
Thanks,
Benoit
Signature · 4 lines
Benoît Cousson BayLibre Embedded Linux Technology Lab www.baylibre.com