]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ASoC: soc-dapm: Add helper for comparing widget name
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Tue, 3 Oct 2023 15:57:09 +0000 (17:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 8 Nov 2023 13:08:59 +0000 (14:08 +0100)
[ Upstream commit 76aca10ccb7c23a7b7a0d56e0bfde2c8cdddfe24 ]

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 <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20231003155710.821315-2-krzysztof.kozlowski@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/sound/soc-dapm.h
sound/soc/soc-component.c
sound/soc/soc-dapm.c

index 87f8e1793af1587a7a846616a116be92f514b618..295d63437e4d8a1ea5bac5900524fbb73a6e5fd4 100644 (file)
@@ -423,6 +423,7 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card);
 
 int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
                            struct snd_pcm_hw_params *params, struct snd_soc_dai *dai);
+int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s);
 
 /* dapm path setup */
 int snd_soc_dapm_new_widgets(struct snd_soc_card *card);
index 4356cc320fea01cd7a2fda539659fd8f0759ae64..10b5fe5a3af853434f5a466efb20ce5a0bd17070 100644 (file)
@@ -242,6 +242,7 @@ int snd_soc_component_notify_control(struct snd_soc_component *component,
        char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
        struct snd_kcontrol *kctl;
 
+       /* When updating, change also snd_soc_dapm_widget_name_cmp() */
        if (component->name_prefix)
                snprintf(name, ARRAY_SIZE(name), "%s %s", component->name_prefix, ctl);
        else
index 3091e8160bad77c22255e2655273051601994fee..5fd32185fe63d63ae7dd27b07e42c8df79b845ae 100644 (file)
@@ -2726,6 +2726,18 @@ int snd_soc_dapm_update_dai(struct snd_pcm_substream *substream,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_update_dai);
 
+int snd_soc_dapm_widget_name_cmp(struct snd_soc_dapm_widget *widget, const char *s)
+{
+       struct snd_soc_component *component = snd_soc_dapm_to_component(widget->dapm);
+       const char *wname = widget->name;
+
+       if (component->name_prefix)
+               wname += strlen(component->name_prefix) + 1; /* plus space */
+
+       return strcmp(wname, s);
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_widget_name_cmp);
+
 /*
  * dapm_update_widget_flags() - Re-compute widget sink and source flags
  * @w: The widget for which to update the flags