Skip to content

audio: run the outputs from hifi_pll on g12, sm1, sc2 and t7 - #60

Open
matthane wants to merge 7 commits into
CoreELEC:5.15.196_20260225from
matthane:pr/ce-audio-hifipll
Open

matthane wants to merge 7 commits into
CoreELEC:5.15.196_20260225from
matthane:pr/ce-audio-hifipll

Conversation

@matthane

@matthane matthane commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

On t7 it needs the spdif links to the dummy codec from #59. Without them, while another output holds hifi_pll at the other rate family, the card's own spdif clock set is refused and logged before the output claims its spare. The commits are split as asked in review, into the t7 PLL range, the output clock claim and one device tree commit per SoC. The device tree commits need the claim, and the t7 one also needs the PLL range.

Problem

On G12A, G12B, SM1, SC2, T7 and T7C audio outputs run from MPLL clocks for one or both rate families, and those run 20 to 23 ppm slow, so the audio clock loses 70 to 84 ms per hour. On SC2, HDMI PCM and 44.1 kHz passthrough share one MPLL, so a 48 kHz PCM title after a 44.1 kHz passthrough title plays 0.7% slow, and a 44.1 kHz passthrough stream opened beside a 48 kHz PCM stream slows the PCM stream by 8%.

SamuriHL found that the G12B MPLL runs the 48 kHz audio clock about 20 ppm slow, in the real_player branch of his CoreELEC Kodi fork (https://github.com/SamuriHL/coreelec-xbmc).

Change

"clk: t7: set hifi_pll from an m range" lets T7's hifi_pll take m from 125 to 250 on 64-bit, as G12A and SC2 do, instead of a one-entry 48 kHz table, so it makes both rate families. "audio: let an output claim a pll both rate families share" makes an open stream hold its PLL at its rate with clk_set_rate_exclusive. A stream at the other family then runs from the spare MPLL the device tree names as clk_src_mpll. Other rate sets, such as the card's own clock set and the fine-tune controls, still set the PLL directly. If another output holds it at the other family, such a set is refused and logged as a kernel warning instead of retuning the PLL under the running stream. Boards without a spare set the rate as before. The S/PDIF shared-buffer path now passes the clock it holds. The five device tree commits move every output (HDMI PCM, HDMI passthrough, optical and analog) of G12A, G12B, SM1, SC2 and T7 to hifi_pll, which makes 491.52 MHz and 451.584 MHz to within 0.03 ppm on G12A, G12B, SM1 and SC2 and exactly on T7. Boards whose own device tree sets the TDM-B clocks (Ugoos AM7 and X4, the 2nd-generation Fire TV Cube) keep TDM-B on their own PLL, as on stock. On the AM7 and X4, the S/PDIF output that mirrors a 44.1 kHz TDM-B stream now runs from that PLL too, as it already did at 48 kHz.

Tested with

The output rate is the hardware playback position fitted against the box's raw monotonic clock over 150 s, in ppm. The position moves in 512-byte fetches, so a value is the middle of the rates that fit every reading, which reach 1.3 to 4.8 ppm either side of it. Without this PR is the stock nightly kernel, with neither this PR nor "audio: report the FRDDR FIFO fill as playback delay". Kodi plays the HDMI rows, and optical and analog play through aplay with Kodi idle. A cell gives the range over the four devices and names a device that stands apart. Every value of -19.5 to -23.2 ppm is an output on an MPLL. With this PR the clock tree shows every output of the AM6B+, R 4K Plus and Fire TV Cube on hifi_pll. The AM9 Pro, whose device tree this PR does not change, runs within 0.7 ppm on both kernels. Full data in the measurement data. Every sample ran on each device listed under Tested on, without this PR on the stock nightly of 2026-11-27 and with it on the nightly of 2026-12-01.

Sample Without this PR, output rate (ppm) With this PR, output rate (ppm)
PCM 2.0 48 kHz, HDMI -0.3 to -0.1, AM6B+ -20.0, R 4K Plus -20.2 -0.2 to +0.1
PCM 2.0 44.1 kHz, HDMI -22.6 to -22.3, AM9 Pro +0.6 0.0 to +0.5
AC-3 48 kHz passthrough, HDMI 0.0 to +0.2, AM6B+ -20.0 -0.4 to +0.3
AC-3 44.1 kHz passthrough, HDMI -23.2 to -22.8, AM9 Pro +0.4 -0.1 to +0.3
TrueHD passthrough (HBR), HDMI +0.1 to +0.3, AM6B+ -19.8 +0.1 to +0.4
PCM 2.0 48 kHz, optical -0.3 to +0.7, AM6B+ -19.5 -0.1 to +0.1
PCM 2.0 44.1 kHz, optical -23.1 to -22.4, AM9 Pro 0.0 -0.2 to +0.2
PCM 2.0 48 kHz, analog -0.1 to +0.1, AM6B+ -19.7 0.0 to +0.3
PCM 2.0 44.1 kHz, analog -23.0 to -22.5, AM9 Pro +0.1 -0.3 to +0.1

The second table reads each stream's output clock in the clock tree while two streams play at once on different outputs (aplay), and while Kodi plays 44.1 kHz PCM, 44.1 kHz AC-3 passthrough and then 48 kHz PCM. A cell gives each clock's distance from its nominal rate, 12288000 or 11289600 Hz for PCM and 6144000 or 5644800 Hz for S/PDIF at 48 and 44.1 kHz. The tree gives whole Hz, so a clock within 10 ppm of nominal runs at the rate its stream set. Without this PR is again the stock nightly of 2026-11-27. The first two rows are cases the stock kernel already gets right.

Sample Without this PR, output clock from nominal (ppm) With this PR, output clock from nominal (ppm)
Optical 48 kHz, then HDMI PCM 44.1 kHz at once first -4.9 to 0.0, second -8.9 to 0.0 first 0.0, second -8.9 to 0.0
HDMI PCM 44.1 kHz, then optical 48 kHz at once first -8.9 to 0.0, second -4.9 to 0.0 first 0.0, second -4.9 to 0.0
HDMI PCM 48 kHz, then HDMI AC-3 44.1 kHz at once first -5.0 to 0.0, R 4K Plus -81258.1, second -8.9 to 0.0 first 0.0, second -8.9 to 0.0
Kodi playing 44.1 kHz PCM, 44.1 kHz AC-3, then 48 kHz PCM 44.1 kHz items -8.9 to 0.0, 48 kHz PCM -5.0 to 0.0, R 4K Plus -6765.5 every item 0.0

Result

Audio keeps its rate through a whole film at both rate families, also after a passthrough title, and a second program on another output no longer changes the first stream's speed. G12A and SM1 share G12B's clock driver, T7C shares T7's, and the output clock claim also changes the TDM shared-buffer parent on S4 with force_mpll at 48 kHz, but we have none of these boxes to run them on.

Tested on

CoreELEC 22 nightly of 2026-12-01 with this PR's commits, "DT: t7 and s4: link the spdif outputs to the dummy codec", "audio: report the FRDDR FIFO fill as playback delay", "amlvideo: report the field of each dequeued frame", the CoreELEC/xbmc A/V sync PRs and the ffmpeg patch "ffmpeg: add patch to time a TrueHD major sync after skipped units", common_drivers on Linux 5.15.196, tested 2026-12-02 and 2026-12-03. Without this PR ran on the stock nightly of 2026-11-27, tested 2026-11-29. Both kernels carry two audio capture taps and a snapshot of the audio playback ring, which these readings do not use. This PR needs no library change and no CoreELEC patch. AM9 Pro (S905X5), AM6B+ (S922X), R 4K Plus (S905X4), Fire TV Cube 3rd gen (T7).

@matthane
matthane force-pushed the pr/ce-audio-hifipll branch 2 times, most recently from f1a4ca4 to 84ce833 Compare November 30, 2026 03:32
@matthane
matthane force-pushed the pr/ce-audio-hifipll branch from 84ce833 to cdd1e3a Compare November 30, 2026 20:46
The t7 hifi_pll takes its rate from a one-entry table that fixes the
DCO near 3932.16 MHz, so it only makes the 48 kHz family and cannot
reach the 44.1 kHz family (451584000 Hz). The g12a and sc2 hifi_pll
take m from a range and make both families.
The outputs set their rate on the source PLL without holding it, so
outputs that share one retune it under each other. On sc2, HDMI PCM
and 44.1 kHz passthrough share MPLL2, and a passthrough start slows a
running 48 kHz PCM stream by 8%. hifi_pll makes both rate families
within 0.03 ppm, but every output would share it.
The g12a audio outputs run from MPLLs for both rate families. The MPLLs
run about 20 ppm slow, so audio drifts against video by about 1.2 ms a
minute. hifi_pll makes both families within 0.03 ppm. g12a has no free
MPLL for a private spare on spdif_b.
The g12b audio outputs run from MPLLs for both rate families. The MPLLs
run about 20 ppm slow, so audio drifts against video by about 1.2 ms a
minute. hifi_pll makes both families within 0.03 ppm.
The sm1 audio outputs run from MPLLs for both rate families. The MPLLs
run about 20 ppm slow, so audio drifts against video by about 1.2 ms a
minute. hifi_pll makes both families within 0.03 ppm.
The sc2 HDMI PCM output runs from an MPLL for both rate families, the
other outputs for the 44.1 kHz family. The MPLLs run about 20 ppm slow,
so that audio drifts against video by about 1.2 ms a minute. hifi_pll
makes both families within 0.03 ppm.
The t7 audio outputs run from MPLLs for the 44.1 kHz family. The MPLLs
run about 20 ppm slow, so 44.1 kHz audio drifts against video by about
1.2 ms a minute. hifi_pll makes both families exactly.
@matthane
matthane force-pushed the pr/ce-audio-hifipll branch from cdd1e3a to 6b558cd Compare December 3, 2026 14:54
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.

1 participant