Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Richard Fitzgerald <rf@opensource.cirrus.com>
To: broonie@kernel.org
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH] ASoC: soc-core: Create device_link to ensure correct suspend order
Date: Mon,  1 Jun 2026 15:28:35 +0100	[thread overview]
Message-ID: <20260601142835.282301-1-rf@opensource.cirrus.com> (raw)

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@opensource.cirrus.com>
---
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


             reply	other threads:[~2026-06-01 14:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 14:28 Richard Fitzgerald [this message]
2026-06-02  8:46 ` [PATCH] ASoC: soc-core: Create device_link to ensure correct suspend order Charles Keepax
2026-06-02 13:31 ` Mark Brown
2026-06-02 13:34   ` Richard Fitzgerald
2026-06-02 13:46     ` Mark Brown
2026-06-02 13:55       ` Richard Fitzgerald
2026-06-02 14:52         ` Mark Brown
2026-06-05  8:55 ` Richard Fitzgerald
2026-06-05 16:32   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260601142835.282301-1-rf@opensource.cirrus.com \
    --to=rf@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox