mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>, broonie@kernel.org
Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com, Maxime Ripard <mripard@kernel.org>,
	Dave Stevenson <dave.stevenson@raspberrypi.com>,
	linux-rpi-kernel <linux-rpi-kernel@lists.infradead.org>,
	Florian Fainelli <florian.fainelli@broadcom.com>
Subject: Re: [PATCH v2] ASoC: soc-core: Create device_link to ensure correct suspend order
Date: Thu, 18 Jun 2026 15:12:03 +0200	[thread overview]
Message-ID: <1893eabe-29aa-4377-8cba-d1d1cc2972c6@samsung.com> (raw)
In-Reply-To: <c29c5ef0-cb10-428f-8ccd-8a84195dd504@samsung.com>

On 18.06.2026 14:58, Marek Szyprowski wrote:
> On 18.06.2026 13:22, Richard Fitzgerald wrote:
>> On 17/6/26 15:10, Marek Szyprowski wrote:
>>> On 11.06.2026 13:08, Richard Fitzgerald wrote:
>>>> 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.
>>>>
>>>> Creating a device_link is safe if there is already a device_link between
>>>> those devices because of multiple components sharing the same dev.
>>>> device_link_add() kernel doc says:
>>>>
>>>>   "if a device link between the given @consumer and @supplier pair
>>>>    exists already when this function is called for them, the existing link
>>>>    will be returned regardless of its current type and status ...
>>>>    The caller of this function is then expected to treat
>>>>    the link as though it has just been created, so (in particular) if
>>>>    DL_FLAG_STATELESS was passed in @flags, the link needs to be released
>>>>    explicitly when not needed any more"
>>>>
>>>> For the same reason it is safe if the codec driver or machine driver
>>>> later call device_link_add() to create a link between the same two
>>>> devices.
>>>>
>>>> (I have tested creating multiple links between the card->dev and a
>>>> component->dev and did not encounter any problems with suspend/resume or
>>>> module unloading.)
>>>>
>>>> The DL_FLAG_AUTOREMOVE_* flags assume that they are being called from
>>>> the probe() function of that device. This isn't guaranteed in ASoC card
>>>> binding because of deferred binding. The exact behavior and consequences
>>>> of the DL_FLAG_AUTOREMOVE_* are also unclear from the documentation.
>>>> So DL_FLAG_STATELESS is used for safety, and the links are removed
>>>> explicitly when the card unbinds or if the bind fails.
>>>>
>>>> Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
>>>> ---
>>>
>>> This patch landed recently in linux-next as commit 0f54ce994b23 ("ASoC:
>>> soc-core: Create device_link to ensure correct suspend order"). In my
>>> tests I found that it breaks probing of VC4 DRM subsystem on Raspberry Pi
>>> 3 and 4 boards due to an issue with hdmi-audio-codec:
>>>
>>> # dmesg | grep vc4
>>> vc4-drm gpu: bound fe400000.hvs (ops vc4_hvs_ops [vc4])
>>> vc4_hdmi fef00700.hdmi: Failed to create device link to hdmi-audio-codec.1.auto
>>> vc4_hdmi fef00700.hdmi: error -EINVAL: Could not register sound card
>>> vc4-drm gpu: failed to bind fef00700.hdmi (ops vc4_hdmi_ops [vc4]): -22
>>> vc4-drm gpu: adev bind failed: -22
>>> vc4-drm gpu: probe with driver vc4-drm failed with error -22
>>>
>> Where in device_link_add() does it fail?
>>
> It fails the following check at drivers/base/core.c line 766:
>
>        if (!device_pm_initialized(supplier)
>             || (!(flags & DL_FLAG_SYNC_STATE_ONLY) &&
>                   device_is_dependent(consumer, supplier))) {
>                 link = NULL;
>                 goto out;
>         }
>
> because device_is_dependent(consumer, supplier) is true for fef00700.hdmi and
> hdmi-audio-codec.1.auto.
This hack fixes VC4 probing (I'm aware that drivers/base/core.c change is not
acceptable):

diff --git a/drivers/base/core.c b/drivers/base/core.c
index bd2ddf2aab50..03e0909d5d68 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -300,7 +300,7 @@ bool device_link_flag_is_sync_state_only(u32 flags)
  * Check if @target depends on @dev or any device dependent on it (its child or
  * its consumer etc).  Return 1 if that is the case or 0 otherwise.
  */
-static int device_is_dependent(struct device *dev, void *target)
+int device_is_dependent(struct device *dev, void *target)
 {
        struct device_link *link;
        int ret;
@@ -330,6 +330,7 @@ static int device_is_dependent(struct device *dev, void *target)
        }
        return ret;
 }
+EXPORT_SYMBOL_GPL(device_is_dependent);

 static void device_link_init_status(struct device_link *link,
                                    struct device *consumer,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index ac9b2269c26e..ba70befea0e8 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2165,6 +2165,8 @@ static void snd_soc_unbind_card(struct snd_soc_card *card)
        }
 }

+extern int device_is_dependent(struct device *dev, void *target);
+
 static int snd_soc_bind_card(struct snd_soc_card *card)
 {
        struct snd_soc_pcm_runtime *rtd;
@@ -2304,7 +2306,8 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
                if (card->dev == component->dev)
                        continue;

-               if (!device_link_add(card->dev, component->dev, DL_FLAG_STATELESS)) {
+               if (!device_is_dependent(card->dev, component->dev) &&
+                   !device_link_add(card->dev, component->dev, DL_FLAG_STATELESS)) {
                        dev_warn(card->dev, "Failed to create device link to %s\n",
                                 dev_name(component->dev));
                        ret = -EINVAL;


Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


  reply	other threads:[~2026-06-18 13:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-11 11:08 Richard Fitzgerald
2026-06-11 19:38 ` Mark Brown
     [not found] ` <CGME20260617141046eucas1p2e85629d57bfc17449b135b16f9230d57@eucas1p2.samsung.com>
2026-06-17 14:10   ` Marek Szyprowski
2026-06-18 11:22     ` Richard Fitzgerald
2026-06-18 12:58       ` Marek Szyprowski
2026-06-18 13:12         ` Marek Szyprowski [this message]
2026-06-18 13:12         ` Richard Fitzgerald
2026-06-18 13:22           ` Marek Szyprowski
2026-06-19 13:33             ` Richard Fitzgerald
2026-06-19 15:51               ` Mark Brown
2026-06-19 15:54               ` Charles Keepax
2026-06-19 16:04                 ` Richard Fitzgerald
2026-06-19 17:19                   ` Mark Brown
2026-06-20 15:57     ` Richard Fitzgerald
2026-06-22  7:07       ` Marek Szyprowski
2026-06-23 10:22         ` Richard Fitzgerald

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=1893eabe-29aa-4377-8cba-d1d1cc2972c6@samsung.com \
    --to=m.szyprowski@samsung.com \
    --cc=broonie@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=florian.fainelli@broadcom.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mripard@kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@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

all inboxes | Powered by JetHome®