Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: Rafael Diniz <rafael@riseup.net>
Cc: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	patches@opensource.cirrus.com, linux-sound@vger.kernel.org
Subject: Re: [PATCH v2] ASoC: wm8731: power the converters together, activate the interface last
Date: Fri, 20 Nov 2026 10:11:43 +0000	[thread overview]
Message-ID: <awAc35H1iSr7fk5Z@opensource.cirrus.com> (raw)
In-Reply-To: <20261120080825.2078162-1-rafael@riseup.net>

On Fri, Nov 20, 2026 at 08:07:55AM +0000, Rafael Diniz wrote:
> With the codec as clock provider at 96 kHz from a 12 MHz crystal (USB
> mode), as on the AudioInjector stereo card for the Raspberry Pi, about
> one capture start in five then leaves the ADC delivering its DC offset
> and noise at their usual levels but no signal, until the interface is
> deactivated and activated again.  Both orders reproduce it on a running
> codec over I2C: the driver's start order (interface active, then ADC and
> line input powered up) went deaf in 1 of 8 trials, and powering the ADC
> and line input down and up under an active interface in 2 of 8.

Shame, but yeah this isn't uncommon for things with an equivalent
to this "ACTIVE" bit to get upset if stuff is changed whilst it
is on. And the power impact of this solution is probably better
than glitching active streams if a new one is opened.

> +#define WM8731_PWR_CONVERTERS (WM8731_PWR_LINEINPD | WM8731_PWR_ADCPD | WM8731_PWR_DACPD)
> +
> +static int wm8731_converters_event(struct snd_soc_dapm_widget *w,
> +				   struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
> +
> +	snd_soc_component_update_bits(component, WM8731_ACTIVE,
> +				      WM8731_ACTIVE_ACTIVE, 0);
> +
> +	switch (event) {
> +	case SND_SOC_DAPM_PRE_PMU:
> +		snd_soc_component_update_bits(component, WM8731_PWR,
> +					      WM8731_PWR_CONVERTERS, 0);
> +		break;
> +	case SND_SOC_DAPM_PRE_PMD:
> +		snd_soc_component_update_bits(component, WM8731_PWR,
> +					      WM8731_PWR_CONVERTERS,
> +					      WM8731_PWR_CONVERTERS);
> +		break;
> +	}
> +	return 0;
> +}
> +
> +static int wm8731_interface_event(struct snd_soc_dapm_widget *w,
> +				  struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
> +	unsigned int pwr = snd_soc_component_read(component, WM8731_PWR);
> +
> +	if (event == SND_SOC_DAPM_POST_PMU && !(pwr & WM8731_PWR_CONVERTERS))
> +		snd_soc_component_update_bits(component, WM8731_ACTIVE,
> +					      WM8731_ACTIVE_ACTIVE,
> +					      WM8731_ACTIVE_ACTIVE);
> +	return 0;
> +}
> +
>  static const struct snd_soc_dapm_widget wm8731_dapm_widgets[] = {
> -SND_SOC_DAPM_SUPPLY("ACTIVE",WM8731_ACTIVE, 0, 0, NULL, 0),
> +SND_SOC_DAPM_POST("Interface", wm8731_interface_event),

Would it be slightly neater to use an OUT_DRV widget instead?
The wm8731 doesn't have any of the widgets that run after it (nor
is it likely to acquire any) and it would allow for a slightly
more symmetrical handling of the ACTIVE bit rather than splitting
it across two widgets.

> +	/*
> +	 * One sample rate and word length serve both directions.  While the
> +	 * interface is active (the other direction running) its clocking is
> +	 * not rewritten: the same settings are kept, others are refused.
> +	 */
> +	if (snd_soc_component_read(component, WM8731_ACTIVE) & WM8731_ACTIVE_ACTIVE) {
> +		if (snd_soc_component_read(component, WM8731_SRATE) != srate ||
> +		    snd_soc_component_read(component, WM8731_IFACE) != iface) {
> +			dev_err(component->dev,
> +				"interface active at other settings: %d Hz, %d bits refused\n",
> +				params_rate(params), params_width(params));
> +			return -EBUSY;
> +		}
> +		return 0;
> +	}

Should symmetric_rate not cover the SRATE case? And would adding
setting symmetric_sample_bits fix the bit depth? Probably be
nicer to split this into two patches, one for the power issues,
one for this stuff. Better to have one patch per logic change.

Thanks,
Charles

  parent reply	other threads:[~2026-11-20 10:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  8:07 [PATCH v2] ASoC: wm8731: power the converters together, activate the interface last Rafael Diniz
2026-11-20  8:25 ` sashiko-bot
2026-11-20 10:11 ` Charles Keepax [this message]
2026-11-20 10:19   ` Charles Keepax

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=awAc35H1iSr7fk5Z@opensource.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=perex@perex.cz \
    --cc=rafael@riseup.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox