Benoit Cousson | 24 Apr 14:01 2014

[RFT v3 0/3] 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
(Continue reading)

Benoit Cousson | 24 Apr 14:01 2014

[RFT v3 1/3] ASoC: core: Add helpers for dai link and aux dev init

From: Misael Lopez Cruz <misael.lopez <at> ti.com>

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.

Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
[fparent <at> baylibre.com: Adapt to 3.14+]
Signed-off-by: Fabien Parent <fparent <at> baylibre.com>
Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
---
 sound/soc/soc-core.c | 67 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 59 insertions(+), 8 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 980da92..f18112a 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
 <at>  <at>  -1266,6 +1266,63  <at>  <at>  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];
(Continue reading)

Mark Brown | 24 Apr 14:24 2014

Re: [RFT v3 1/3] ASoC: core: Add helpers for dai link and aux dev init

On Thu, Apr 24, 2014 at 02:01:44PM +0200, Benoit Cousson wrote:
> From: Misael Lopez Cruz <misael.lopez <at> ti.com>
> 
> 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.
On Thu, Apr 24, 2014 at 02:01:44PM +0200, Benoit Cousson wrote:
> From: Misael Lopez Cruz <misael.lopez <at> ti.com>
> 
> 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.
Benoit Cousson | 24 Apr 14:01 2014

[RFT v3 2/3] ASoC: core: Add one dai_get_widget helper instead of two rtd based ones

Replace 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.

Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
Cc: Lars-Peter Clausen <lars <at> metafoo.de>
---
 sound/soc/soc-pcm.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 2cedf09..88230ea 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
 <at>  <at>  -1012,21 +1012,12  <at>  <at>  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;
-}
-
(Continue reading)

Mark Brown | 24 Apr 14:25 2014

Re: [RFT v3 2/3] ASoC: core: Add one dai_get_widget helper instead of two rtd based ones

On Thu, Apr 24, 2014 at 02:01:45PM +0200, Benoit Cousson wrote:
> Replace rtd_get_codec_widget() and rtd_get_cpu_widget() by a simple
> dai_get_widget() in preparation for DAI-multicodec support, per Lars
> suggestion.

Applied, thanks.
On Thu, Apr 24, 2014 at 02:01:45PM +0200, Benoit Cousson wrote:
> Replace rtd_get_codec_widget() and rtd_get_cpu_widget() by a simple
> dai_get_widget() in preparation for DAI-multicodec support, per Lars
> suggestion.

Applied, thanks.
Benoit Cousson | 24 Apr 14:01 2014

[RFT v3 3/3] ASoC: core: Add support for DAI multicodec

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 or codec_name).

Fix a trailing space in the header as well.

Based on an original code done by Misael.

Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
Signed-off-by: Fabien Parent <fparent <at> baylibre.com>
---
 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(-)

diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index fad7676..6985851 100644
(Continue reading)

Lars-Peter Clausen | 26 Apr 14:51 2014
Picon

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On 04/24/2014 02:01 PM, Benoit Cousson wrote:
> 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 or codec_name).
>
> Fix a trailing space in the header as well.
>
> Based on an original code done by Misael.
>
> Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
> Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
> Signed-off-by: Fabien Parent <fparent <at> baylibre.com>

Looks mostly good. A few bits and pieces here and there, comments inline.

[...]
> diff --git a/include/sound/soc.h b/include/sound/soc.h
> index 0fadb3c..7933512 100644
> --- a/include/sound/soc.h
> +++ b/include/sound/soc.h
>  <at>  <at>  -821,6 +821,12  <at>  <at>  struct snd_soc_platform_driver {
>   	int (*bespoke_trigger)(struct snd_pcm_substream *, int);
(Continue reading)

Benoit Cousson | 29 Apr 19:53 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

Hi Lars,

On 26/04/2014 14:51, Lars-Peter Clausen wrote:
> On 04/24/2014 02:01 PM, Benoit Cousson wrote:
>> 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 or codec_name).
>>
>> Fix a trailing space in the header as well.
>>
>> Based on an original code done by Misael.
>>
>> Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
>> Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
>> Signed-off-by: Fabien Parent <fparent <at> baylibre.com>
>
> Looks mostly good. A few bits and pieces here and there, comments inline.

Cool, it is getting closer :-)

>
> [...]
(Continue reading)

Benoit Cousson | 15 May 17:01 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

Hi Lars,

I'm struggling a little bit to understand one of your comment :-)

On 26/04/2014 14:51, Lars-Peter Clausen wrote:
> On 04/24/2014 02:01 PM, Benoit Cousson wrote:
>>  <at>  <at>  -870,6 +876,10  <at>  <at>  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.

[...]

>>  <at>  <at>  -1586,16 +1626,21  <at>  <at>  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++) {
(Continue reading)

Lars-Peter Clausen | 16 May 12:44 2014
Picon

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On 05/15/2014 05:01 PM, Benoit Cousson wrote:
> Hi Lars,
>
> I'm struggling a little bit to understand one of your comment :-)
>
> On 26/04/2014 14:51, Lars-Peter Clausen wrote:
>> On 04/24/2014 02:01 PM, Benoit Cousson wrote:
>>>  <at>  <at>  -870,6 +876,10  <at>  <at>  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.

That shouldn't be a problem. The const applies to the data the pointer 
points to, not the pointer itself.

>
> [...]
>
>>>  <at>  <at>  -1586,16 +1626,21  <at>  <at>  static int soc_probe_link_dais(struct
>>> snd_soc_card *card, int num, int order)
>>>                            codec2codec_close_delayed_work);
>>>
>>>                /* link the DAI widgets */
(Continue reading)

Benoit Cousson | 16 May 13:31 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On 16/05/2014 12:44, Lars-Peter Clausen wrote:
> On 05/15/2014 05:01 PM, Benoit Cousson wrote:
>> Hi Lars,
>>
>> I'm struggling a little bit to understand one of your comment :-)
>>
>> On 26/04/2014 14:51, Lars-Peter Clausen wrote:
>>> On 04/24/2014 02:01 PM, Benoit Cousson wrote:
>>>>  <at>  <at>  -870,6 +876,10  <at>  <at>  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.
>
> 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 :-)

>> [...]
>>
(Continue reading)

Lars-Peter Clausen | 6 May 13:24 2014
Picon

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On 04/24/2014 02:01 PM, Benoit Cousson wrote:
> 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 or codec_name).
>
> Fix a trailing space in the header as well.
>
> Based on an original code done by Misael.
>
> Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
> Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
> Signed-off-by: Fabien Parent <fparent <at> baylibre.com>

Some thoughts on the parameter fixup.

> ---
>   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 ++++++++++++++++++++++++++++++++---------------
(Continue reading)

Sinan Akman | 16 May 22:06 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On 05/06/2014 07:24 AM, Lars-Peter Clausen wrote:
> [...]
> 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 | 17 May 13:46 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

On Fri, May 16, 2014 at 04:06:50PM -0400, Sinan Akman wrote:

>   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.
On Fri, May 16, 2014 at 04:06:50PM -0400, Sinan Akman wrote:

>   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
(Continue reading)

Benoit Cousson | 23 Jun 16:26 2014

Re: [RFT v3 3/3] ASoC: core: Add support for DAI multicodec

Hi Lars,

I finally got some BW to address your second email :-)

On 06/05/2014 13:24, Lars-Peter Clausen wrote:
> On 04/24/2014 02:01 PM, Benoit Cousson wrote:
>> 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 or codec_name).
>>
>> Fix a trailing space in the header as well.
>>
>> Based on an original code done by Misael.
>>
>> Signed-off-by: Benoit Cousson <bcousson <at> baylibre.com>
>> Signed-off-by: Misael Lopez Cruz <misael.lopez <at> ti.com>
>> Signed-off-by: Fabien Parent <fparent <at> baylibre.com>
>
> Some thoughts on the parameter fixup.
>
>> ---
>>   include/sound/soc-dai.h  |   5 +
(Continue reading)


Gmane