All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>,
	Stefan Binding <sbinding@opensource.cirrus.com>,
	Mark Brown <broonie@kernel.org>
Cc: patches@opensource.cirrus.com, alsa-devel@alsa-project.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/8] ASoC: cs42l42: Add Soundwire support
Date: Fri, 20 Jan 2023 13:55:00 -0600	[thread overview]
Message-ID: <c8a9ff9b-d1d0-1cef-bf51-e7fa247d24f4@linux.intel.com> (raw)
In-Reply-To: <32fd1755-0128-8f32-9a88-a92f1647f903@opensource.cirrus.com>



On 1/19/23 09:35, Richard Fitzgerald wrote:
> On 19/1/23 14:48, Pierre-Louis Bossart wrote:
>>
>>>>> +static int cs42l42_sdw_dai_startup(struct snd_pcm_substream
>>>>> *substream,
>>>>> +                   struct snd_soc_dai *dai)
>>>>> +{
>>>>> +    struct cs42l42_private *cs42l42 =
>>>>> snd_soc_component_get_drvdata(dai->component);
>>>>> +
>>>>> +    if (!cs42l42->init_done)
>>>>> +        return -ENODEV;
>>>>
>>>> Can this happen? IIRC the ASoC framework would use
>>>> pm_runtime_resume_and_get() before .startup, which would guarantee that
>>>> the device is initialized, no?
>>>>
>>>
>>> Yes, this can happen. Because of the way that the SoundWire enumeration
>>> was implemented in the core code, it isn't a probe event so we cannot
>>> call snd_soc_register_component() on enumeration because -EPROBE_DEFER
>>> wouldn't be handled. So the snd_soc_register_component() must be called
>>> from probe(). This leaves a limbo situation where we've registered the
>>> driver but in fact don't yet have any hardware. ALSA/ASoC doesn't know
>>> that we've registered before we are functional so they are happy to
>>> go ahead and try to use the soundcard. If for some reason the hardware
>>> failed to enumerate we can get here without having enumerated.
>>
>> Humm, yes, but you've also made the regmap cache-only, so is there
>> really a problem?
>>
> 
> It's true that normally we go past these stages in cache-only, but that
> is because normally (non-Soundwire) we already initialized the hardware
> to good state during probe().
> If we just carry on when it hasn't enumerated and we haven't initialized
> it yet, who knows what will happen if it enumerates some time later.
> 
> We could just ignore it and see if anyone has a problem but for the sake
> of a couple of lines of code I feel like I'd rather check for it.
> 
>> FWIW I don't see a startup callback in any other codec driver. It may be
>> wrong but it's also a sign that this isn't a problem we've seen so far
>> on existing Intel-based platforms.
>>
> 
> It's nicer to do the check in startup() because then the application
> open() will fail cleanly. We could delay until prepare - which is the
> point we really need the hardware to be accessible - and hope the
> hardware enumerated and initialized by that time. But that's not so
> nice from the app point of view.

Another way to avoid problems is to rely on the codec component .probe
to check if the SoundWire device is initialized before registering a card.

I just tried with a system where the ACPI info exposes a codec which is
not connected, it fails nicely. That avoids the pitfalls of creating a
card which isn't functional since all dependencies are not met.

[   64.616530] snd_soc_sof_sdw:mc_probe: sof_sdw sof_sdw: Entry
[   64.616549] snd_soc_sof_sdw:log_quirks: sof_sdw sof_sdw: quirk
SOF_SDW_PCH_DMIC enabled
[   64.616559] snd_soc_sof_sdw:sof_card_dai_links_create: sof_sdw
sof_sdw: sdw 2, ssp 0, dmic 2, hdmi 0
[   64.616587] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link SDW0-Playback, id 0
[   64.616600] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link SDW0-Capture, id 1
[   64.616607] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link dmic01, id 2
[   64.616614] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link dmic16k, id 3
[   69.757115] rt5682 sdw:0:025d:5682:00: Initialization not complete,
timed out
[   69.757128] rt5682 sdw:0:025d:5682:00: ASoC: error at
snd_soc_component_probe on sdw:0:025d:5682:00: -110
[   69.757224] sof_sdw sof_sdw: ASoC: failed to instantiate card -110
[   69.757734] sof_sdw sof_sdw: snd_soc_register_card failed -110

see
https://elixir.bootlin.com/linux/latest/source/sound/soc/codecs/rt5682.c#L2927

I think this is compatible with the device model and bind/unbind, but it
could be improved with the removal of the wait if we had a way to return
-EPROBEDEFER, and have a mechanism to force the deferred probe work to
be triggered when a device actually shows up. It's a generic problem
that the probe cannot always be a synchronous function but may complete
'later'.

WARNING: multiple messages have this Message-ID (diff)
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>,
	Stefan Binding <sbinding@opensource.cirrus.com>,
	Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: Re: [PATCH v2 6/8] ASoC: cs42l42: Add Soundwire support
Date: Fri, 20 Jan 2023 13:55:00 -0600	[thread overview]
Message-ID: <c8a9ff9b-d1d0-1cef-bf51-e7fa247d24f4@linux.intel.com> (raw)
In-Reply-To: <32fd1755-0128-8f32-9a88-a92f1647f903@opensource.cirrus.com>



On 1/19/23 09:35, Richard Fitzgerald wrote:
> On 19/1/23 14:48, Pierre-Louis Bossart wrote:
>>
>>>>> +static int cs42l42_sdw_dai_startup(struct snd_pcm_substream
>>>>> *substream,
>>>>> +                   struct snd_soc_dai *dai)
>>>>> +{
>>>>> +    struct cs42l42_private *cs42l42 =
>>>>> snd_soc_component_get_drvdata(dai->component);
>>>>> +
>>>>> +    if (!cs42l42->init_done)
>>>>> +        return -ENODEV;
>>>>
>>>> Can this happen? IIRC the ASoC framework would use
>>>> pm_runtime_resume_and_get() before .startup, which would guarantee that
>>>> the device is initialized, no?
>>>>
>>>
>>> Yes, this can happen. Because of the way that the SoundWire enumeration
>>> was implemented in the core code, it isn't a probe event so we cannot
>>> call snd_soc_register_component() on enumeration because -EPROBE_DEFER
>>> wouldn't be handled. So the snd_soc_register_component() must be called
>>> from probe(). This leaves a limbo situation where we've registered the
>>> driver but in fact don't yet have any hardware. ALSA/ASoC doesn't know
>>> that we've registered before we are functional so they are happy to
>>> go ahead and try to use the soundcard. If for some reason the hardware
>>> failed to enumerate we can get here without having enumerated.
>>
>> Humm, yes, but you've also made the regmap cache-only, so is there
>> really a problem?
>>
> 
> It's true that normally we go past these stages in cache-only, but that
> is because normally (non-Soundwire) we already initialized the hardware
> to good state during probe().
> If we just carry on when it hasn't enumerated and we haven't initialized
> it yet, who knows what will happen if it enumerates some time later.
> 
> We could just ignore it and see if anyone has a problem but for the sake
> of a couple of lines of code I feel like I'd rather check for it.
> 
>> FWIW I don't see a startup callback in any other codec driver. It may be
>> wrong but it's also a sign that this isn't a problem we've seen so far
>> on existing Intel-based platforms.
>>
> 
> It's nicer to do the check in startup() because then the application
> open() will fail cleanly. We could delay until prepare - which is the
> point we really need the hardware to be accessible - and hope the
> hardware enumerated and initialized by that time. But that's not so
> nice from the app point of view.

Another way to avoid problems is to rely on the codec component .probe
to check if the SoundWire device is initialized before registering a card.

I just tried with a system where the ACPI info exposes a codec which is
not connected, it fails nicely. That avoids the pitfalls of creating a
card which isn't functional since all dependencies are not met.

[   64.616530] snd_soc_sof_sdw:mc_probe: sof_sdw sof_sdw: Entry
[   64.616549] snd_soc_sof_sdw:log_quirks: sof_sdw sof_sdw: quirk
SOF_SDW_PCH_DMIC enabled
[   64.616559] snd_soc_sof_sdw:sof_card_dai_links_create: sof_sdw
sof_sdw: sdw 2, ssp 0, dmic 2, hdmi 0
[   64.616587] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link SDW0-Playback, id 0
[   64.616600] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link SDW0-Capture, id 1
[   64.616607] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link dmic01, id 2
[   64.616614] snd_soc_sof_sdw:init_dai_link: sof_sdw sof_sdw: create
dai link dmic16k, id 3
[   69.757115] rt5682 sdw:0:025d:5682:00: Initialization not complete,
timed out
[   69.757128] rt5682 sdw:0:025d:5682:00: ASoC: error at
snd_soc_component_probe on sdw:0:025d:5682:00: -110
[   69.757224] sof_sdw sof_sdw: ASoC: failed to instantiate card -110
[   69.757734] sof_sdw sof_sdw: snd_soc_register_card failed -110

see
https://elixir.bootlin.com/linux/latest/source/sound/soc/codecs/rt5682.c#L2927

I think this is compatible with the device model and bind/unbind, but it
could be improved with the removal of the wait if we had a way to return
-EPROBEDEFER, and have a mechanism to force the deferred probe work to
be triggered when a device actually shows up. It's a generic problem
that the probe cannot always be a synchronous function but may complete
'later'.

  parent reply	other threads:[~2023-01-20 19:56 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 16:04 [PATCH v2 0/8] ASoC: cs42l42: Add Soundwire support Stefan Binding
2023-01-18 16:04 ` Stefan Binding
2023-01-18 16:04 ` [PATCH v2 1/8] soundwire: stream: Add specific prep/deprep commands to port_prep callback Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:37   ` Pierre-Louis Bossart
2023-01-18 16:37     ` Pierre-Louis Bossart
2023-01-18 16:04 ` [PATCH v2 2/8] ASoC: cs42l42: Add SOFT_RESET_REBOOT register Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:41   ` Pierre-Louis Bossart
2023-01-18 16:41     ` Pierre-Louis Bossart
2023-01-19 13:33     ` Richard Fitzgerald
2023-01-19 13:33       ` Richard Fitzgerald
2023-01-18 16:04 ` [PATCH v2 3/8] ASoC: cs42l42: Ensure MCLKint is a multiple of the sample rate Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:46   ` Pierre-Louis Bossart
2023-01-18 16:46     ` Pierre-Louis Bossart
2023-01-18 16:04 ` [PATCH v2 4/8] ASoC: cs42l42: Separate ASP config from PLL config Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:04 ` [PATCH v2 5/8] ASoC: cs42l42: Export some functions for Soundwire Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:04 ` [PATCH v2 6/8] ASoC: cs42l42: Add Soundwire support Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 17:41   ` Pierre-Louis Bossart
2023-01-18 17:41     ` Pierre-Louis Bossart
2023-01-19 13:58     ` Richard Fitzgerald
2023-01-19 13:58       ` Richard Fitzgerald
2023-01-19 14:48       ` Pierre-Louis Bossart
2023-01-19 14:48         ` Pierre-Louis Bossart
2023-01-19 15:35         ` Richard Fitzgerald
2023-01-19 15:35           ` Richard Fitzgerald
2023-01-19 16:27           ` Pierre-Louis Bossart
2023-01-19 16:27             ` Pierre-Louis Bossart
2023-01-20 12:31             ` Richard Fitzgerald
2023-01-20 12:31               ` Richard Fitzgerald
2023-01-20 19:55           ` Pierre-Louis Bossart [this message]
2023-01-20 19:55             ` Pierre-Louis Bossart
2023-01-23 15:51             ` Richard Fitzgerald
2023-01-23 15:51               ` Richard Fitzgerald
2023-01-23 16:05               ` Pierre-Louis Bossart
2023-01-23 16:14                 ` Richard Fitzgerald
2023-01-23 16:14                   ` Richard Fitzgerald
2023-01-23 16:25                   ` Pierre-Louis Bossart
2023-01-18 16:04 ` [PATCH v2 7/8] ASoC: cs42l42: Don't set idle_bias_on Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 16:04 ` [PATCH v2 8/8] ASoC: cs42l42: Wait for debounce interval after resume Stefan Binding
2023-01-18 16:04   ` Stefan Binding
2023-01-18 17:43 ` [PATCH v2 0/8] ASoC: cs42l42: Add Soundwire support Pierre-Louis Bossart
2023-01-18 17:43   ` Pierre-Louis Bossart

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=c8a9ff9b-d1d0-1cef-bf51-e7fa247d24f4@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.com \
    --cc=sbinding@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.