Skip to content

Commit 76aca10

Browse files
krzkbroonie
authored andcommitted
ASoC: soc-dapm: Add helper for comparing widget name
Some drivers use one event callback for multiple widgets but still need to perform a bit different actions based on actual widget. This is done by comparing widget name, however drivers tend to miss possible name prefix. Add a helper to solve common mistakes. Signed-off-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 1426b9b commit 76aca10

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/sound/soc-dapm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
469469

470470
int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
471471
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai);
472+
int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s);
472473

473474
/* dapm path setup */
474475
int snd_soc_dapm_new_widgets(struct snd_soc_card *card);

sound/soc/soc-component.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ int snd_soc_component_notify_control(struct snd_soc_component *component,
242242
char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
243243
struct snd_kcontrol *kctl;
244244

245+
/* When updating, change also snd_soc_dapm_widget_name_cmp() */
245246
if (component->name_prefix)
246247
snprintf(name, ARRAY_SIZE(name), "%s %s", component->name_prefix, ctl);
247248
else

sound/soc/soc-dapm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,18 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
27282728
}
27292729
EXPORT_SYMBOL_GPL(snd_soc_dapm_update_dai);
27302730

2731+
int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s)
2732+
{
2733+
struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
2734+
const char *wname = widget->name;
2735+
2736+
if (component->name_prefix)
2737+
wname += strlen(component->name_prefix) + 1; /* plus space */
2738+
2739+
return strcmp(wname, s);
2740+
}
2741+
EXPORT_SYMBOL_GPL(snd_soc_dapm_widget_name_cmp);
2742+
27312743
/*
27322744
* dapm_update_widget_flags() - Re-compute widget sink and source flags
27332745
* @w: The widget for which to update the flags

0 commit comments

Comments
 (0)