[PATCH] ASoC: soc-core: Create device_link to ensure correct suspend order
From: Richard Fitzgerald
Date: Mon Jun 01 2026 - 10:38:23 EST
In snd_soc_bind_card() create a device_link from card to all components
to ensure correct order of system_suspend. The card is the consumer and
the components are the supplier, so that the card will system_suspend
before any of the components.
The PM core will normally system_suspend drivers in the opposite order
that they registered. This ensures children are suspended before their
parents, for example users of a bus driver should suspend before the bus
driver suspends.
For ASoC, snd_soc_suspend() shuts down any active audio, which requires
that the components are still able to communicate with their hardware.
Previously there was nothing to ensure this ordering, because there is
(usually) no relationship between a machine driver and component drivers.
If the machine driver registered before the codec drivers, the codec
drivers would be suspended before the machine driver snd_soc_suspend()
runs, so that ASoC is attempting to stop audio on a driver that has
already suspended.
Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
Mark,
I think it would be ok to put this into -next and let it get some wider
testing before it goes into 7.1 or older.
sound/soc/soc-core.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c0599031a3e4..1820143a144a 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2297,6 +2297,21 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
if (!snd_soc_component_active(component))
pinctrl_pm_select_sleep_state(component->dev);
+ /*
+ * Add device_link from card to component so that system_suspend
+ * will be done in the correct order. The card must suspend first
+ * to stop audio activity before the components suspend.
+ */
+ for_each_card_components(card, component) {
+ if (!device_link_add(card->dev, component->dev,
+ DL_FLAG_AUTOREMOVE_CONSUMER)) {
+ dev_warn(card->dev, "Failed to create device link to %s\n",
+ dev_name(component->dev));
+ ret = -EINVAL;
+ goto probe_end;
+ }
+ }
+
probe_end:
if (ret < 0)
soc_cleanup_card_resources(card);
--
2.47.3