Skip to content

ASoC: wm8731: power the converters together, activate the interface last - #7777

Open
rafael2k wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
rafael2k:wm8731-interface-last
Open

rafael2k wants to merge 1 commit into
raspberrypi:rpi-6.18.yfrom
rafael2k:wm8731-interface-last

Conversation

@rafael2k

@rafael2k rafael2k commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #7776.

On a WM8731 card with the codec as clock provider (audioinjector-wm8731-audio: 12 MHz crystal, 96 kHz, USB mode), about one start in five of a playback and capture pair leaves the capture without signal. The ADC keeps delivering its DC offset and noise, and stays like that until the interface is deactivated and activated again. Tests on a running codec over I2C point to the ADC being powered up while the interface is active (details and figures are in the issue). That happens with the driver's DAPM layout:

  • ACTIVE is a supply widget, set before the converters on every stream start;
  • the ADC and DAC have widgets of their own, so a capture starting next to a running playback powers the ADC up under an active interface.

The patch:

  • powers the ADC, DAC and line input together from one supply widget, while the interface is inactive;
  • sets ACTIVE from a DAPM post widget once a stream's widgets are up, and clears it before the converters go down. A second stream then finds the converters powered and leaves the interface alone;
  • in hw_params, keeps an active interface's rate and word length when they match and refuses others with -EBUSY, instead of rewriting SRATE and IFACE under the running direction.

The ADC and DAC are now powered whenever either direction runs, which costs a few mW while a stream is open.

Testing:

  • builds as a module against 6.18.60+rpt-rpi-v8, and with W=1 on mainline; checkpatch is clean (apart from not knowing the Fixes: commit in a shallow clone);
  • the trigger was reproduced on a Pi 4 with the stock driver: 1 of 8 trials going deaf with the driver's order, 2 of 8 with an ADC power cycle under an active interface, 0 of 42 with the interface activated after the converters, 0 of 12 with SRATE/IFACE rewritten under an active interface;
  • with this patch as a module on the same Pi 4: 30 of 30 full-duplex stream starts had the test signal in the capture, none deaf and none with swapped channels (about 6 in 30 deaf expected with the stock driver). The patched module has been running on two such boards since.

The commit carries Fixes: 8a27bd9a3318 (the change that made ACTIVE a supply widget). Mainline has the same widget layout and hw_params; the same patch is going to the ASoC list, and I'll link the thread here.

The analysis, the reproducers, the patch and its changelog were written with Claude Code (Claude Opus 5.5), which also ran the hardware tests at my direction; see the changelog.

🤖 Generated with Claude Code

@popcornmix

Copy link
Copy Markdown
Collaborator

This looks like an upstream file unmodified by this repo. As such, the fix belongs upstream.
Please submit it upstream and let us know when it's accepted - we are usually willing to backport it.

@rafael2k

Copy link
Copy Markdown
Author

Hardware result with this patch, as a module built against 6.18.60+rpt-rpi-v8 on a Pi 4 with the AudioInjector stereo card (codec as clock provider, 96 kHz, S32_LE): 30 starts of a full-duplex stream pair, each followed by a test signal on the line input. 30 of 30 captures had the signal; none came up deaf, and none with swapped channels. With the stock driver the same setup goes deaf on about one start in five (about 6 in 30 expected; the chance of 0 in 30 at that rate is about 0.1 %). After stream start the codec's registers end in the same state as with the stock driver (R6 0x042, R7 0x04e, R8 0x01d, R9 0x001).

The datasheet's power-up sequence powers the converters, sets the other
registers and activates the digital audio interface last.  The driver
has ACTIVE as a supply widget, which DAPM powers ahead of the ADC, DAC
and line input, and gives each converter a widget of its own, so a
capture starting next to a running playback powers the ADC up under an
active interface.

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.
Activating the interface with the converters already powered stayed
healthy in 42 of 42, and rewriting SRATE or IFACE with their values
under an active interface in 12 of 12.

Power the ADC, DAC and line input from one supply, with the interface
inactive, set ACTIVE from a DAPM post widget once a stream's widgets are
up, and clear it before the converters go down.  A second stream then
finds the converters powered and leaves the interface as it is.

A second stream's hw_params also rewrote the sample rate and format
registers of an interface already active for the other direction.  One
rate and word length serve both directions: keep matching settings as
they are and refuse others with -EBUSY while the interface is active.

Tested on a Raspberry Pi 4 with that card, 6.18.60 (Raspberry Pi
kernel, where the driver is the same): with this patch, 30 of 30
full-duplex stream starts had the test signal in the capture, against
about one in five deaf without it.  Built with W=1 on mainline.

The analysis, the I2C reproducers, the patch and this changelog were
written with Claude Code (Claude Opus 5.5) from the reported fault and
the kernel sources, and the tool ran the hardware tests on the
submitter's test setup at the submitter's direction.

Fixes: 8a27bd9 ("ASoC: Manage WM8731 ACTIVE bit as a supply widget")
Link: raspberrypi#7776
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Rafael Diniz <rafael@riseup.net>
@rafael2k
rafael2k force-pushed the wm8731-interface-last branch from 2e100f9 to 7f90d54 Compare November 19, 2026 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wm8731: capture sometimes starts deaf: ADC powered up while the interface is active

2 participants