]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: soc-core: Add core support for ignoring suspend on selected DAPM widgets
authorChancel Liu <chancel.liu@nxp.com>
Thu, 7 May 2026 01:36:53 +0000 (10:36 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 25 May 2026 12:37:15 +0000 (13:37 +0100)
Some audio systems require specific DAPM widgets to remain powered
during system suspend. Introduce a generic and reusable mechanism in
the ASoC core to mark selected DAPM widgets as ignore_suspend.

The unified mechanism consists of two parts:
1. Parse and store the name list of widgets to ignore suspend in
struct snd_soc_card

The list of widgets can be provided either by the machine driver or
parsed from Device Tree. Different machines have different routing and
power requirements. Each machine can specify its own widgets to ignore
suspend through DT property. It enables flexible policy without hard
code. A new helper, snd_soc_of_parse_ignore_suspend_widgets() is added
for this purpose.

2. Apply ignore_suspend flags during snd_soc_bind_card()

After all components have been probed and all DAPM widgets have been
registered, snd_soc_bind_card() performs a unified lookup of the
configured widget names across all DAPM contexts of the card and marks
the matching widgets with ignore_suspend = 1.

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
Link: https://patch.msgid.link/20260507013654.2945915-3-chancel.liu@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-dapm.h
include/sound/soc.h
sound/soc/soc-core.c
sound/soc/soc-dapm.c

index c1e4f467efda737b66153a7717351eb0dfa9a2fe..b0a135b9af50f56587bec3c22763d9b59b715f28 100644 (file)
@@ -636,6 +636,7 @@ int snd_soc_dapm_new_dai_widgets(struct snd_soc_dapm_context *dapm, struct snd_s
 void snd_soc_dapm_free_widget(struct snd_soc_dapm_widget *w);
 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_ignore_suspend_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);
index 5e3eb617d8323ac64a4d7567059363bf12606ade..7d6fa79f48e3f45361e8811fce0719054de54143 100644 (file)
@@ -1057,10 +1057,14 @@ struct snd_soc_card {
        int num_dapm_widgets;
        const struct snd_soc_dapm_route *dapm_routes;
        int num_dapm_routes;
+       const char **ignore_suspend_widgets;
+       int num_ignore_suspend_widgets;
        const struct snd_soc_dapm_widget *of_dapm_widgets;
        int num_of_dapm_widgets;
        const struct snd_soc_dapm_route *of_dapm_routes;
        int num_of_dapm_routes;
+       const char **of_ignore_suspend_widgets;
+       int num_of_ignore_suspend_widgets;
 
        /* lists of probed devices belonging to this card */
        struct list_head component_dev_list;
@@ -1339,6 +1343,7 @@ void snd_soc_of_parse_node_prefix(struct device_node *np,
 int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
                                   const char *propname);
 int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname);
+int snd_soc_of_parse_ignore_suspend_widgets(struct snd_soc_card *card, const char *propname);
 
 unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt);
 unsigned int snd_soc_daifmt_clock_provider_from_bitmap(unsigned int bit_frame);
index 3fecf9fc903c004c7c39f7ebca7f8291656c4257..705181dae47205e50968c15611ce7d6919cb2c6f 100644 (file)
@@ -2289,6 +2289,10 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
        if (ret < 0)
                goto probe_end;
 
+       ret = snd_soc_dapm_ignore_suspend_widgets(card);
+       if (ret < 0)
+               goto probe_end;
+
        snd_soc_dapm_new_widgets(card);
        snd_soc_card_fixup_controls(card);
 
@@ -3294,6 +3298,45 @@ int snd_soc_of_parse_aux_devs(struct snd_soc_card *card, const char *propname)
 }
 EXPORT_SYMBOL_GPL(snd_soc_of_parse_aux_devs);
 
+int snd_soc_of_parse_ignore_suspend_widgets(struct snd_soc_card *card,
+                                           const char *propname)
+{
+       struct device_node *np = card->dev->of_node;
+       int num_widgets;
+       const char **widgets;
+       int i;
+
+       num_widgets = of_property_count_strings(np, propname);
+       if (num_widgets < 0) {
+               dev_err(card->dev,
+                       "ASoC: Property '%s' does not exist\n", propname);
+               return -EINVAL;
+       }
+
+       widgets = devm_kcalloc(card->dev, num_widgets, sizeof(char *), GFP_KERNEL);
+       if (!widgets)
+               return -ENOMEM;
+
+       for (i = 0; i < num_widgets; i++) {
+               const char *name;
+               int ret = of_property_read_string_index(np, propname, i, &name);
+
+               if (ret) {
+                       dev_err(card->dev,
+                               "ASoC: Property '%s' could not be read: %d\n",
+                               propname, ret);
+                       return -EINVAL;
+               }
+               widgets[i] = name;
+       }
+
+       card->num_of_ignore_suspend_widgets = num_widgets;
+       card->of_ignore_suspend_widgets = widgets;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_of_parse_ignore_suspend_widgets);
+
 unsigned int snd_soc_daifmt_clock_provider_flipped(unsigned int dai_fmt)
 {
        unsigned int inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
index a26771c8e6ee6947607f78a2526a8e3dd898754c..4e3feb43836ccba01692249b278a224b369df525 100644 (file)
@@ -4604,6 +4604,36 @@ void snd_soc_dapm_connect_dai_link_widgets(struct snd_soc_card *card)
        }
 }
 
+int snd_soc_dapm_ignore_suspend_widgets(struct snd_soc_card *card)
+{
+       struct snd_soc_dapm_widget *w;
+       int i;
+
+       for (i = 0; i < card->num_ignore_suspend_widgets; i++) {
+               w = dapm_find_widget(snd_soc_card_to_dapm(card),
+                                    card->ignore_suspend_widgets[i], true);
+               if (!w) {
+                       dev_err(card->dev, "ASoC: DAPM unknown ignore suspend widget %s\n",
+                               card->ignore_suspend_widgets[i]);
+                       return -EINVAL;
+               }
+               w->ignore_suspend = 1;
+       }
+
+       for (i = 0; i < card->num_of_ignore_suspend_widgets; i++) {
+               w = dapm_find_widget(snd_soc_card_to_dapm(card),
+                                    card->of_ignore_suspend_widgets[i], true);
+               if (!w) {
+                       dev_err(card->dev, "ASoC: DAPM unknown ignore suspend widget %s\n",
+                               card->of_ignore_suspend_widgets[i]);
+                       return -EINVAL;
+               }
+               w->ignore_suspend = 1;
+       }
+
+       return 0;
+}
+
 static void dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream, int event)
 {
        struct snd_soc_dai *dai;