Skip to content

Fix H616/H618 HDMI audio clocking#9916

Merged
igorpecovnik merged 1 commit into
armbian:mainfrom
joakimtoe1:fix-sunxi-h616-hdmi-audio
Jun 1, 2026
Merged

Fix H616/H618 HDMI audio clocking#9916
igorpecovnik merged 1 commit into
armbian:mainfrom
joakimtoe1:fix-sunxi-h616-hdmi-audio

Conversation

@joakimtoe1
Copy link
Copy Markdown
Contributor

@joakimtoe1 joakimtoe1 commented May 31, 2026

Description

Fix HDMI audio on H616/H618 boards using the Armbian sunxi64 current and edge kernel patch stacks.

On Orange Pi Zero 2W / H618, HDMI video worked and the HDMI ALSA card was created correctly. ELD was valid, ASoC routing was active, DW-HDMI
I2S setup was reached, and PCM playback entered RUNNING, but no audible sound was produced by the TV.

This PR updates the existing H616 digital audio patch for both sunxi-6.18 and sunxi-7.0 to:

  • expose/use the real H616 audio PLL clocks for AHUB: CLK_PLL_AUDIO_HS and CLK_PLL_AUDIO_4X
  • remove the fixed post divider from pll-audio-hs so exact SDM audio rates are used
  • parent the AHUB module clock to pll-audio-4x
  • set the AHUB module rate to the full requested output rate instead of freq_out / 2
  • program the AHUB BCLK divider field with the raw divider map value instead of bclk_ratio - 2
  • make the HDMI controller node a DAI provider with #sound-dai-cells = <0>, so a separate local hdmi-audio-fix overlay is no longer needed

GitHub issue reference: none
Jira reference number: none

Documentation summary for feature / change

No main documentation entry is expected. This is a kernel patch-stack fix for HDMI audio behavior on affected H616/H618 boards.

How Has This Been Tested?

Tested on Orange Pi Zero 2W / H618 with Armbian sunxi64 Linux 6.18.33.

  • Verified original failure mode: HDMI card present, ELD valid, PCM RUNNING, no audible sound
  • Verified BCLK-only patch was not sufficient
  • Verified final patch set with HDMI as card 0 while analog codec was disabled
  • Verified final patch set without local hdmi-audio-fix overlay:
    • user_overlays=
    • HDMI card present as card 1 with analog codec enabled
    • ELD valid
    • speaker-test -D hw:1,0 -c 2 -r 48000 -F S32_LE -t sine runs
    • speaker-test -D hw:1,0 -c 2 -r 48000 -F S16_LE -t sine runs
    • PCM state RUNNING
    • 0x0509730c = 0x00000090
    • pll-audio-hs = 98.304 MHz
    • pll-audio-4x = 98.304 MHz
    • audio-hub = 98.304 MHz

Also compared runtime AHUB/I2S/DW-HDMI registers against a working Batocera H616/H618 reference board. The relevant playback clock/register
state matched after this fix.

Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Bug Fixes
    • Fixed HDMI audio clock configuration on H616/H618 devices to use correct audio PLL sources.
    • Corrected audio module clock programming and I2S divider calculations in the audio driver for proper audio output routing.
    • Restored proper clock parent relationships to improve overall audio functionality stability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4fc4d078-d7b2-428b-959b-adf1734a3c0d

📥 Commits

Reviewing files that changed from the base of the PR and between 5542199 and 3452d03.

📒 Files selected for processing (2)
  • patch/kernel/archive/sunxi-6.18/patches.armbian/0702-arm64-dts-sun50i-h616-add-digital-audio-node.patch
  • patch/kernel/archive/sunxi-7.0/patches.armbian/0702-arm64-dts-sun50i-h616-add-digital-audio-node.patch
🚧 Files skipped from review as they are similar to previous changes (1)
  • patch/kernel/archive/sunxi-7.0/patches.armbian/0702-arm64-dts-sun50i-h616-add-digital-audio-node.patch

📝 Walkthrough

Walkthrough

Patches expose H616 audio PLL clocks to DT, remove pll-audio-hs fixed post-divider, update AHUB DAM DTS to use the PLL clocks and add a disabled machine node, and adjust AHUB drivers to program module rate/divider and properly acquire/release clk_pll_audio_4x (applies to 6.18 and 7.0).

Changes

H616 Audio PLL and AHUB Clock Fixes

Layer / File(s) Summary
Patch descriptions and DTS machine node
patch/kernel/archive/sunxi-6.18/patches.armbian/0702-*.patch, patch/kernel/archive/sunxi-7.0/patches.armbian/0702-*.patch
Patch headers updated; add ahub_dam_mach machine node and switch AHUB DAM platform clocks in sun50i-h616.dtsi to CLK_PLL_AUDIO_HS / CLK_PLL_AUDIO_4X; add #sound-dai-cells = <0> to hdmi.
CCU pll-audio-hs configuration
drivers/clk/sunxi/ccu-sun50i-h616.c
Remove fixed_post_div usage and CCU_FEATURE_FIXED_POSTDIV from pll-audio-hs, preserving sigma-delta modulation only.
DT clock ID exports
include/dt-bindings/clock/sun50i-h616-ccu.h
Add exported clock ID macros: CLK_PLL_AUDIO_HS and CLK_PLL_AUDIO_4X.
AHUB module clock rate and BCLK divider programming
sound/soc/sunxi/snd-sunxi-ahub.c
Program clk_module rate to freq_out (removed / 2) and write BCLK divider register with raw bclk_ratio (removed - 2).
AHUB DAM clk acquisition, parenting, and cleanup
sound/soc/sunxi/snd-sunxi-ahub-dam.c
Re-enable clk_pll_audio_4x acquisition, set clk_module parent to that PLL, and update init/error/remove paths to clk_put() the clk_pll_audio_4x handle.

Sequence Diagram(s)

sequenceDiagram
  participant DeviceTree
  participant AHUB_Driver
  participant CLK_PLL_AUDIO_4X
  participant CLK_MODULE
  participant BCLK_Register

  DeviceTree->>AHUB_Driver: provide clk-pll-audio-hs & clk-pll-audio-4x phandles
  AHUB_Driver->>CLK_PLL_AUDIO_4X: clk_get(clk_pll_audio_4x)
  AHUB_Driver->>CLK_MODULE: clk_set_parent(clk_module, clk_pll_audio_4x)
  AHUB_Driver->>CLK_MODULE: clk_set_rate(clk_module, freq_out)
  AHUB_Driver->>CLK_MODULE: clk_enable(clk_module)
  AHUB_Driver->>BCLK_Register: write BCLK divider = bclk_ratio
  Note over AHUB_Driver: on remove or error
  AHUB_Driver->>CLK_PLL_AUDIO_4X: clk_put(clk_pll_audio_4x)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I nibble code and tune the clocks,
PLLs now hum in measured walks.
AHUB reparented, dividers true,
HDMI timing finds its cue.
Kernel hops and audio talks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main objective—fixing H616/H618 HDMI audio clocking—which aligns with the core changes across both patch files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added size/large PR with 250 lines or more 05 Milestone: Second quarter release labels May 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hey @joakimtoe1! 👋

Thanks for submitting your first pull request to the Armbian project — we're excited to have you contributing! 🧡
Your effort doesn’t just improve Armbian — it benefits the entire community of users and developers.

If you'd like to stay informed about project updates or collaborate more closely with the team,
you can optionally share some personal contact preferences at armbian.com/update-data.
This helps us keep in touch without relying solely on GitHub notifications.

Also, don’t forget to ⭐ star the repo if you haven’t already — and welcome aboard! 🚀

@github-actions github-actions Bot added Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels May 31, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
patch/kernel/archive/sunxi-7.0/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch (1)

99-112: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Same resource leak as the 6.18 patch: clk_put(clk_info->clk_pll) is still commented out.

Apply the same fix here to uncomment line 110.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@patch/kernel/archive/sunxi-7.0/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch`
around lines 99 - 112, The cleanup path is leaking clk_pll because the
clk_put(clk_info->clk_pll) call is still commented out; in the error unwind
labels (err_module_clk_enable / err_pll_clk_enable / err_set_parent_clk /
err_pllx4_clk) restore the missing release by uncommenting the
clk_put(clk_info->clk_pll) call under the err_pllx4_clk / err_pll_clk labels so
that clk_put(clk_info->clk_pll) is invoked during error unwind before calling
clk_put(clk_info->clk_module); keep the existing label order (err_set_parent_clk
→ err_pllx4_clk → err_pll_clk) and ensure no duplicate frees are introduced.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@patch/kernel/archive/sunxi-6.18/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch`:
- Around line 99-112: The cleanup path for err_pllx4_clk currently doesn't
release clk_info->clk_pll, causing a resource leak; update the
err_pllx4_clk/err_set_parent_clk cleanup sequence to call
clk_put(clk_info->clk_pll) when err_pllx4_clk is reached (i.e., ensure
clk_put(clk_info->clk_pll) is executed before proceeding to release clk_module),
so that when clk_pllx4 acquisition fails the previously acquired clk_pll is
properly put.

---

Duplicate comments:
In
`@patch/kernel/archive/sunxi-7.0/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch`:
- Around line 99-112: The cleanup path is leaking clk_pll because the
clk_put(clk_info->clk_pll) call is still commented out; in the error unwind
labels (err_module_clk_enable / err_pll_clk_enable / err_set_parent_clk /
err_pllx4_clk) restore the missing release by uncommenting the
clk_put(clk_info->clk_pll) call under the err_pllx4_clk / err_pll_clk labels so
that clk_put(clk_info->clk_pll) is invoked during error unwind before calling
clk_put(clk_info->clk_module); keep the existing label order (err_set_parent_clk
→ err_pllx4_clk → err_pll_clk) and ensure no duplicate frees are introduced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2bd32f8c-d2a1-4351-99ac-5ff0cb9be17d

📥 Commits

Reviewing files that changed from the base of the PR and between 7829b2a and 77e5990.

📒 Files selected for processing (4)
  • patch/kernel/archive/sunxi-6.18/patches.armbian/0700-clk-sunxi-ng-h616-fix-audio-pll-for-hdmi.patch
  • patch/kernel/archive/sunxi-6.18/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch
  • patch/kernel/archive/sunxi-7.0/patches.armbian/0700-clk-sunxi-ng-h616-fix-audio-pll-for-hdmi.patch
  • patch/kernel/archive/sunxi-7.0/patches.armbian/0703-sunxi-h616-fix-ahub-hdmi-audio-clock-path.patch

@EvilOlaf
Copy link
Copy Markdown
Member

I wonder how this was tested when the patches were not even applied (lacking entry in series.conf)

@joakimtoe1 joakimtoe1 marked this pull request as draft May 31, 2026 14:07
@joakimtoe1 joakimtoe1 force-pushed the fix-sunxi-h616-hdmi-audio branch from d20c811 to 026b92f Compare May 31, 2026 14:12
@joakimtoe1 joakimtoe1 marked this pull request as ready for review May 31, 2026 14:49
@joakimtoe1
Copy link
Copy Markdown
Contributor Author

I wonder how this was tested when the patches were not even applied (lacking entry in series.conf)

You were right; the first version added standalone patch files but did not wire them into series.conf, so a clean patch-stack application would not have picked them up.

I reworked the PR so the HDMI audio fix is folded into the existing 0702-arm64-dts-sun50i-h616-add-digital-audio-node.patch, which is already listed in both sunxi-6.18/series.conf and sunxi-7.0/series.conf. The branch has also been cleaned up to a single commit and rebuilt from that exact commit; the patch stage passes and the generated image/dtb packages were installed and tested on Orange Pi Zero 2W / H618 with audible HDMI audio confirmed.

@joakimtoe1 joakimtoe1 closed this May 31, 2026
@joakimtoe1 joakimtoe1 reopened this May 31, 2026
@joakimtoe1 joakimtoe1 force-pushed the fix-sunxi-h616-hdmi-audio branch from 026b92f to 746da82 Compare May 31, 2026 17:03
@joakimtoe1 joakimtoe1 force-pushed the fix-sunxi-h616-hdmi-audio branch from 746da82 to 4c350f4 Compare May 31, 2026 20:11
Fix HDMI audio on H616/H618 boards using the Armbian sunxi64 current and edge kernel patch stacks.

On Orange Pi Zero 2W / H618, HDMI video worked and the HDMI ALSA card was created correctly. ELD was valid, ASoC routing was active, DW-HDMI I2S setup was reached, and PCM playback entered RUNNING, but no audible sound was produced by the TV.

The failure needs both AHUB clock path correction and AHUB BCLK divider correction. A BCLK-only test programmed SUNXI_AHUB_I2S_CLKD(1) to the working 0x90 value, but left audio-hub at 43 MHz with pll-audio-hs/pll-audio-4x at 688 MHz and remained silent.

This change folds the HDMI audio fix into the already-applied H616 digital audio patch for sunxi-6.18 and sunxi-7.0:

- expose CLK_PLL_AUDIO_HS and CLK_PLL_AUDIO_4X to DT
- use those real audio PLL clocks for AHUB DAM instead of audio-codec clocks
- remove the fixed post divider from pll-audio-hs so exact SDM audio rates are used
- parent the AHUB module clock to pll-audio-4x
- set the AHUB module clock to the full requested rate instead of freq_out / 2
- program the AHUB BCLK divider field with the raw divider map value instead of bclk_ratio - 2
- make the HDMI controller node a DAI provider with #sound-dai-cells = <0>, so the local hdmi-audio-fix overlay is no longer needed

Validated on Orange Pi Zero 2W / H618 with 48 kHz S16_LE and S32_LE HDMI speaker-test playback. The working runtime state has pll-audio-hs, pll-audio-4x, and audio-hub at 98.304 MHz, with SUNXI_AHUB_I2S_CLKD(1) programmed to 0x90. The final test was run without the hdmi-audio-fix overlay; HDMI still registered and ELD remained valid.

Signed-off-by: joakimtoe <joakimtoe@gmail.com>
@joakimtoe1 joakimtoe1 force-pushed the fix-sunxi-h616-hdmi-audio branch from 4c350f4 to 3452d03 Compare May 31, 2026 20:13
@joakimtoe1
Copy link
Copy Markdown
Contributor Author

@coderabbitai resume

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

✅ Actions performed

Reviews resumed.

Copy link
Copy Markdown
Member

@EvilOlaf EvilOlaf left a comment

Choose a reason for hiding this comment

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

lgtm

@igorpecovnik igorpecovnik merged commit 6b33a05 into armbian:main Jun 1, 2026
12 checks passed
@github-actions github-actions Bot added the Ready to merge Reviewed, tested and ready for merge label Jun 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions Bot removed the Needs review Seeking for review label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

05 Milestone: Second quarter release Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... Ready to merge Reviewed, tested and ready for merge size/large PR with 250 lines or more

Development

Successfully merging this pull request may close these issues.

3 participants