ASoC: dapm: add code to configure dai link parameters
PATCH v7 1/1 ASoC: dapm: add code to configure dai link parameters
dai-link params for codec-codec links were fixed. The fixed link between codec and another chip which may be another codec, baseband, bluetooth codec etc may require run time configuaration changes. This change provides an optional alsa control to select one of the params from a list of params.
--- include/sound/soc-dapm.h | 3 + include/sound/soc.h | 1 + sound/soc/soc-core.c | 6 +- sound/soc/soc-dapm.c | 154 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 157 insertions(+), 7 deletions(-)
include/sound/soc-dapm.h +3 -0
@@ -378,6 +378,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, +unsigned int num_params,struct snd_soc_dapm_widget *source,struct snd_soc_dapm_widget *sink);
@@ -533,6 +534,8 @@ struct snd_soc_dapm_widget {void *priv;/* widget specific data */ struct regulator *regulator;/* attached regulator */ const struct snd_soc_pcm_stream *params;/* params for dai links */ +unsigned int num_params;/* number of params for dai links */ +unsigned int params_select;/* currently selected param for dai link */ /* dapm control */ int reg;/* negative reg = no direct dapm */
include/sound/soc.h +1 -0
@@ -942,6 +942,7 @@ struct snd_soc_dai_link {int be_id;/* optional ID for machine driver BE identification */ const struct snd_soc_pcm_stream *params; +unsigned int num_params;unsigned int dai_fmt;/* format to set on init */
sound/soc/soc-core.c +4 -2
@@ -1292,7 +1292,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card, 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); + dai_link->num_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);
@@ -1304,7 +1305,8 @@ static int soc_link_dai_widgets(struct snd_soc_card *card, 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); + dai_link->num_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);
sound/soc/soc-dapm.c +149 -5
210 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Mark Brown
maintainerOn Fri, Nov 28, 2014 at 05:01:41PM +0000, Nikesh Oswal wrote:
This doesn't apply cleanly against current code, it appears to have been generated against Linus' tree rather than latest ASoC.
include/sound/soc.h struct snd_soc_dai_link { · line 948
Quoted 11 lines
index 7ba7130..db60701 100644
include/sound/soc.h +1
-0@@ -942,6 +942,7 @@ struct snd_soc_dai_link {int be_id;/* optional ID for machine driver BE identification */ const struct snd_soc_pcm_stream *params; +unsigned int num_params;unsigned int dai_fmt;/* format to set on init */
Here we add num_params to the existing params; several existing drivers use params but they've not been updated.
include/sound/soc.h
Quoted 11 lines
include/sound/soc.h +11
-0+/* create new dapm dai link control */ +static int dapm_new_dai_link (struct snd_soc_dapm_widget *w) +{ +int i, ret; +struct snd_kcontrol *kcontrol; +struct snd_soc_dapm_context *dapm = w->dapm; +struct snd_card *card = dapm->card->snd_card; + +/* skip control creation for links with 1 config */ +if (w->num_params ==1 ) +return 0 ;
Here we skip control creation if num_params is not 1. This means we'll try to create a control if num_params is zero which it will be for all existing users. This should actually work out fine due to the way loop iteration works but this appears to be entirely by accident, it's not obvious from the code. Either num_params needs to become mandatory for users and all existing users updated to provide it or the code should explicitly cope with num_params being zero.
include/sound/soc.h static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, · line 3244
Quoted 7 lines
include/sound/soc.h +3
-0@@ -3206,6 +3239,9 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, source = source_p->source->priv; sink = sink_p->sink->priv; +/* Select the configuration set by alsa control */ + config = &config[w->params_select]; +
This is needlessly obscure. We're first using config as shorthand for the array of configuration options and then using it as the option we selected. It'd be better to change the initial dereference to also have the array selection.
include/sound/soc.h static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
Quoted 4 lines
include/sound/soc.h +4
-0+ private_value = + (unsigned long )devm_kmemdup (card->dev, + (void *)(kcontrol_dai_link[0 ].private_value), +sizeof (struct soc_enum ),GFP_KERNEL );
This doesn't resemble the Linux coding style very strongly; normally the arguments of the function call would be indented with respect to the line with the function name.
include/sound/soc.h
Quoted 12 lines
include/sound/soc.h +12
-0+outfree_w: +kfree (w); +outfree_kcontrol_news: +kfree (template.kcontrol_news); +outfree_private_value: +kfree ((void *)private_value); +outfree_link_name: +kfree (link_name); +outfree_w_param: +for (count =0 ; count < num_params; count++) +kfree (w_param_text[count]); +kfree (w_param_text);
You're paring devm_ allocations with kfree(), that's going to break. Managed allocations need managed frees.