All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Marian Postevca <posteuca@mutex.one>
Cc: Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>,
	linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org
Subject: Re: [PATCH 4/4] ASoC: amd: acp: Improve support for speaker power events
Date: Mon, 20 Mar 2023 21:01:12 +0000	[thread overview]
Message-ID: <0989fc51-fee7-4558-ba2c-084cc4fb6833@sirena.org.uk> (raw)
In-Reply-To: <20230320203519.20137-5-posteuca@mutex.one>

[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]

On Mon, Mar 20, 2023 at 10:35:19PM +0200, Marian Postevca wrote:
> In order to reduce the audible pops when speaker or headphones
> are activated or disabled we need to delay the switching of the
> GPIOs.

The usual mechanism for doing this is with the standard kernel delay
functions.  Why not use them in the DAPM event?

> We need to also disable/enable the speaker/headphones GPIOs when
> the audio stream is stopped/started. To avoid race conditions
> between the speaker power event callback and the trigger callback
> we use a ring buffer to save the events that we need to process
> in the delayed work callback.

Why is this required?  DAPM is integrated with stream start and stop,
and there's a mute callback to mask any noise played back from the SoC
while it stops and starts without requiring all this complexity.  If
there is any audible noise then why would it only affect the speaker?

> +static int acp3x_es83xx_trigger(struct snd_pcm_substream *substream, int cmd)
> +{
> +	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
> +	struct snd_soc_card *card = rtd->card;
> +	struct acp3x_es83xx_private *priv = get_mach_priv(card);
> +
> +	switch (cmd) {
> +	case SNDRV_PCM_TRIGGER_START:
> +	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> +	case SNDRV_PCM_TRIGGER_RESUME:
> +		if (substream->stream == 0) {
> +			dev_dbg(priv->codec_dev, "trigger start/release/resume, activating GPIOs\n");
> +			mutex_lock(&priv->rb_lock);

Triggers run in atomic context, you can't use mutexes in atomic context.
lockdep should tell you this.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Mark Brown <broonie@kernel.org>
To: Marian Postevca <posteuca@mutex.one>
Cc: Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org
Subject: Re: [PATCH 4/4] ASoC: amd: acp: Improve support for speaker power events
Date: Mon, 20 Mar 2023 21:01:12 +0000	[thread overview]
Message-ID: <0989fc51-fee7-4558-ba2c-084cc4fb6833@sirena.org.uk> (raw)
In-Reply-To: <20230320203519.20137-5-posteuca@mutex.one>

[-- Attachment #1: Type: text/plain, Size: 1556 bytes --]

On Mon, Mar 20, 2023 at 10:35:19PM +0200, Marian Postevca wrote:
> In order to reduce the audible pops when speaker or headphones
> are activated or disabled we need to delay the switching of the
> GPIOs.

The usual mechanism for doing this is with the standard kernel delay
functions.  Why not use them in the DAPM event?

> We need to also disable/enable the speaker/headphones GPIOs when
> the audio stream is stopped/started. To avoid race conditions
> between the speaker power event callback and the trigger callback
> we use a ring buffer to save the events that we need to process
> in the delayed work callback.

Why is this required?  DAPM is integrated with stream start and stop,
and there's a mute callback to mask any noise played back from the SoC
while it stops and starts without requiring all this complexity.  If
there is any audible noise then why would it only affect the speaker?

> +static int acp3x_es83xx_trigger(struct snd_pcm_substream *substream, int cmd)
> +{
> +	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
> +	struct snd_soc_card *card = rtd->card;
> +	struct acp3x_es83xx_private *priv = get_mach_priv(card);
> +
> +	switch (cmd) {
> +	case SNDRV_PCM_TRIGGER_START:
> +	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
> +	case SNDRV_PCM_TRIGGER_RESUME:
> +		if (substream->stream == 0) {
> +			dev_dbg(priv->codec_dev, "trigger start/release/resume, activating GPIOs\n");
> +			mutex_lock(&priv->rb_lock);

Triggers run in atomic context, you can't use mutexes in atomic context.
lockdep should tell you this.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2023-03-20 21:01 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 20:35 [PATCH 0/4] ASoC: amd: acp: Add sound support for a line of HUAWEI laptops Marian Postevca
2023-03-20 20:35 ` [PATCH 1/4] ASoC: es8316: Enable support for S32 LE format and MCLK div by 2 Marian Postevca
2023-03-20 20:43   ` Mark Brown
2023-03-20 20:43     ` Mark Brown
2023-03-21 17:09     ` Marian Postevca
2023-03-21 17:09       ` Marian Postevca
2023-03-21 17:21       ` Mark Brown
2023-03-21 17:21         ` Mark Brown
2023-03-20 20:35 ` [PATCH 2/4] ASoC: amd: acp: Add support for splitting the codec specific code from the ACP driver Marian Postevca
2023-03-20 20:35 ` [PATCH 3/4] ASoC: amd: acp: Add machine driver that enables sound for systems with a ES8336 codec Marian Postevca
2023-03-20 20:54   ` Mark Brown
2023-03-20 20:54     ` Mark Brown
2023-03-21 22:17     ` Marian Postevca
2023-03-21 22:17       ` Marian Postevca
2023-03-22  1:58       ` Pierre-Louis Bossart
2023-03-22 13:07       ` Mark Brown
2023-03-22 13:07         ` Mark Brown
2023-03-22 20:48         ` Marian Postevca
2023-03-22 20:48           ` Marian Postevca
2023-03-22 21:27           ` Mark Brown
2023-03-22 21:27             ` Mark Brown
2023-03-27 21:20             ` Marian Postevca
2023-03-27 21:20               ` Marian Postevca
2023-03-29 13:52               ` Mark Brown
2023-03-29 13:52                 ` Mark Brown
2023-08-17 21:09                 ` Marian Postevca
2023-08-17 21:47                   ` Mark Brown
2023-08-17 22:20                     ` Marian Postevca
2023-08-18 12:52                       ` Mark Brown
2023-08-20  9:32                         ` Marian Postevca
2023-08-21 14:09                           ` Mark Brown
2023-03-21  0:54   ` kernel test robot
2023-03-20 20:35 ` [PATCH 4/4] ASoC: amd: acp: Improve support for speaker power events Marian Postevca
2023-03-20 21:01   ` Mark Brown [this message]
2023-03-20 21:01     ` Mark Brown
2023-03-22 21:01     ` Marian Postevca
2023-03-22 21:01       ` Marian Postevca
2023-03-22 21:35       ` Mark Brown
2023-03-22 21:35         ` 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=0989fc51-fee7-4558-ba2c-084cc4fb6833@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=posteuca@mutex.one \
    --cc=tiwai@suse.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.