Skip to content

bcm2835-i2s: fail capture open cleanly when FIFO clear has no clock - #7586

Merged
pelwell merged 1 commit into
raspberrypi:rpi-6.18.yfrom
gifflet:fix/bcm2835-i2s-capture-clockless-open
Sep 1, 2026
Merged

bcm2835-i2s: fail capture open cleanly when FIFO clear has no clock#7586
pelwell merged 1 commit into
raspberrypi:rpi-6.18.yfrom
gifflet:fix/bcm2835-i2s-capture-clockless-open

Conversation

@gifflet

@gifflet gifflet commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #7585

In clock-consumer (slave) mode the RX/TX FIFO clear requires PCM clock cycles to complete. When the external bit clock is absent at open time (source off/unplugged), the SYNC round trip times out, the FIFOs are left uncleared, and starting DMA on top of the stale RX FIFO makes capture free-run: DREQ sticks high, the same dead word is re-read at bus speed, and the poisoned state survives further stream cycles until reboot.

This change makes bcm2835_i2s_clear_fifos() return an error on SYNC timeout and propagates it in .prepare for the capture branch that clears stale RX data, so the open fails with -EIO instead of recording garbage. The hw_params-time clear stays tolerant on purpose: on clock-consumer links it legitimately runs before the provider's clocks are up, and the .prepare clear is the one that must succeed there.

Tested on: Raspberry Pi 4B, 6.18.34+rpt-rpi-v8, HiFiBerry Digi+ I/O (WM8804 as clock provider, dtoverlay=hifiberry-digi):

  • source unplugged + capture open → clean -EIO in ~0.6 s, zero bogus data (previously: instant "success" full of DC garbage + FIFO poisoned until reboot);
  • source reconnected → the very next capture is healthy (3.10 s wall for 3 s of audio), no reboot needed;
  • no regressions observed: normal boots capture on the first try; playback unaffected.

Comment thread sound/soc/bcm/bcm2835-i2s.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this FIXME with a one-line explanation of the slave mode problem, e.g.

The reset will timeout in clock consumer mode without an external clock.

@pelwell

pelwell commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

This PR is more readable than the associated issue (#7585), and would have been sufficient on its own. Apart from my comment about the FIXME and the commit title (drop the fix(...) and add a Fixes: tag), I think this is fine.

In clock-consumer (slave) mode the RX/TX FIFO clear requires PCM clock
cycles to complete. When the external bit clock is absent at open time
(source device off or unplugged), the SYNC round trip times out, the
FIFOs are left uncleared, and starting DMA on top of the stale RX FIFO
makes capture free-run: DREQ sticks high, the same dead word is re-read
at bus speed, and the poisoned state survives further stream cycles
until reboot.

Return an error from bcm2835_i2s_clear_fifos() on SYNC timeout and
propagate it in .prepare for the capture branch that clears stale RX
data, so the open fails with -EIO instead of recording garbage. The
hw_params-time clear stays tolerant: on clock-consumer links it runs
legitimately before the provider's clocks are up, and the .prepare
clear is the one that must succeed there.

Validated on a Raspberry Pi 4B (6.18.34+rpt-rpi-v8) with a WM8804
S/PDIF receiver board as clock provider: opening capture with the
optical source unplugged now fails cleanly in ~0.6s with no bogus
data, and the next open after the source returns captures normally,
with no reboot needed.

Fixes: c6aeb7d ("ASoC: Add support for BCM2835")
Signed-off-by: Guilherme Silva Sousa <guisousa09@hotmail.com>
@gifflet
gifflet force-pushed the fix/bcm2835-i2s-capture-clockless-open branch from 160e9c1 to 5acfe2b Compare September 1, 2026 12:34
@gifflet

gifflet commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All three points addressed in the updated commit:

  • FIXME replaced with your suggested one-line explanation;
  • commit title reworded to kernel style (dropped the fix(...) prefix);
  • added Fixes: c6aeb7de226d ("ASoC: Add support for BCM2835").

Re-tested on the same Pi 4B rig after the amend: unplugged-source capture opens still fail cleanly with -EIO and recovery on reconnect remains immediate.

@pelwell
pelwell merged commit e52b68e into raspberrypi:rpi-6.18.y Sep 1, 2026
12 checks passed
@pelwell

pelwell commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Thanks!

@gifflet
gifflet deleted the fix/bcm2835-i2s-capture-clockless-open branch September 1, 2026 13:14
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.

bcm2835-i2s: slave-mode capture free-runs and stays poisoned when BCLK is absent at open (FIFO clear needs clock; SYNC timeout is ignored)

2 participants