Re: [PATCH v3 3/3] ASoC: simple-card: Add support for codec2codec DAI links

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2/22/20 9:45 PM, Samuel Holland wrote:
> Following the example in cb2cf0de1174 ("ASoC: soc-core: care Codec <->
> Codec case by non_legacy_dai_naming"), determine if a DAI link contains
> only codec DAIs by examining the non_legacy_dai_naming flag in each
> DAI's component.
> 
> For now, we assume there is only one or a small set of valid PCM stream
> parameters, so num_params == 1 is good enough. We also assume that the
> same params are valid for all supported streams. params is set to the
> subset of parameters common among all DAIs, and then the existing code
> automatically chooses the highest quality of the remaining values when
> the link is brought up.
> 
> Signed-off-by: Samuel Holland <samuel@xxxxxxxxxxxx>
> ---
>  Documentation/sound/soc/codec-to-codec.rst |  9 +++-
>  sound/soc/generic/simple-card-utils.c      | 49 ++++++++++++++++++++++
>  2 files changed, 56 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/sound/soc/codec-to-codec.rst b/Documentation/sound/soc/codec-to-codec.rst
> index 810109d7500d..4eaa9a0c41fc 100644
> --- a/Documentation/sound/soc/codec-to-codec.rst
> +++ b/Documentation/sound/soc/codec-to-codec.rst
> @@ -104,5 +104,10 @@ Make sure to name your corresponding cpu and codec playback and capture
>  dai names ending with "Playback" and "Capture" respectively as dapm core
>  will link and power those dais based on the name.
>  
> -Note that in current device tree there is no way to mark a dai_link
> -as codec to codec. However, it may change in future.
> +A dai_link in a "simple-audio-card" will automatically be detected as
> +codec to codec when all DAIs on the link belong to codec components.
> +The dai_link will be initialized with the subset of stream parameters
> +(channels, format, sample rate) supported by all DAIs on the link. Since
> +there is no way to provide these parameters in the device tree, this is
> +mostly useful for communication with simple fixed-function codecs, such
> +as a Bluetooth controller or cellular modem.
> diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
> index 9b794775df53..54294367a40f 100644
> --- a/sound/soc/generic/simple-card-utils.c
> +++ b/sound/soc/generic/simple-card-utils.c
> @@ -331,6 +331,51 @@ static int asoc_simple_init_dai(struct snd_soc_dai *dai,
>  	return 0;
>  }
>  
> +static int asoc_simple_init_dai_link_params(struct snd_soc_pcm_runtime *rtd,
> +					    struct simple_dai_props *dai_props)
> +{
> +	struct snd_soc_dai_link *dai_link = rtd->dai_link;
> +	struct snd_soc_component *component;
> +	struct snd_soc_rtdcom_list *rtdcom;

This variable is unused in v3. I can send a v4.

> +	struct snd_soc_pcm_stream *params;
> +	struct snd_pcm_hardware hw;
> +	int i, ret, stream;
> +
> +	/* Only codecs should have non_legacy_dai_naming set. */
> +	for_each_rtd_components(rtd, i, component) {
> +		if (!component->driver->non_legacy_dai_naming)
> +			return 0;
> +	}
> +
> +	/* Assumes the capabilities are the same for all supported streams */
> +	for (stream = 0; stream < 2; stream++) {
> +		ret = snd_soc_runtime_calc_hw(rtd, &hw, stream);
> +		if (ret == 0)
> +			break;
> +	}
> +
> +	if (ret < 0) {
> +		dev_err(rtd->dev, "simple-card: no valid dai_link params\n");
> +		return ret;
> +	}
> +
> +	params = devm_kzalloc(rtd->dev, sizeof(*params), GFP_KERNEL);
> +	if (!params)
> +		return -ENOMEM;
> +
> +	params->formats = hw.formats;
> +	params->rates = hw.rates;
> +	params->rate_min = hw.rate_min;
> +	params->rate_max = hw.rate_max;
> +	params->channels_min = hw.channels_min;
> +	params->channels_max = hw.channels_max;
> +
> +	dai_link->params = params;
> +	dai_link->num_params = 1;
> +
> +	return 0;
> +}
> +
>  int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
>  {
>  	struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
> @@ -347,6 +392,10 @@ int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
>  	if (ret < 0)
>  		return ret;
>  
> +	ret = asoc_simple_init_dai_link_params(rtd, dai_props);
> +	if (ret < 0)
> +		return ret;
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(asoc_simple_dai_init);
> 




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux