Skip to content

CAINIAO CNIoT-CORE: use ALSA UCM instead of asound.state #8307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

retro98boy
Copy link
Contributor

Description

There is a drawback to configuring audio routing using asound.state. Although you can specify the device of the axg-sound card via commands to output sound to either HDMI or the internal speaker, in a desktop environment, there is only one analog output (defaulting to HDMI). This is because the device actually has only one sound card. By using ALSA UCM to manage sound instances and audio routing, you can freely choose between HDMI or the built-in speaker output in a desktop environment. This is because PipeWire/WirePlumber will parse ALSA UCM and create sinks.

IMG20250616221758

How Has This Been Tested?

build image

boot form usb drive

test sound in CLI and DE

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Walkthrough

This change set removes a static ALSA state configuration file for the CAINIAO CNIoT-CORE board and introduces a new ALSA UCM (Use Case Manager) configuration system. It adds two new configuration files: one defining the HiFi audio setup with audio routes, device priorities, and mixer control sequences, and another defining the main board audio configuration with use case and boot sequence settings. The board configuration script is updated to install these new UCM files, create required directories and symbolic links, and provide usage instructions for ALSA UCM. Additionally, a conditional check in the Meson G12B family configuration is consolidated for board-specific U-Boot hooks.

Suggested labels

ready to merge

Suggested reviewers

  • igorpecovnik
  • clee
  • rpardini
  • catalinii
  • SuperKali
  • TheSnowfield

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9ae00 and 2fafd70.

📒 Files selected for processing (5)
  • config/boards/cainiao-cniot-core.csc (2 hunks)
  • config/sources/families/meson-g12b.conf (1 hunks)
  • packages/blobs/asound.state/asound.state.cainiao-cniot-core (0 hunks)
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core-HiFi.conf (1 hunks)
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/blobs/asound.state/asound.state.cainiao-cniot-core
🚧 Files skipped from review as they are similar to previous changes (4)
  • config/sources/families/meson-g12b.conf
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf
  • config/boards/cainiao-cniot-core.csc
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core-HiFi.conf
✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch cainiao-cniot-core-audio
  • Post Copyable Unit Tests in Comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added 08 Milestone: Third quarter release size/large PR with 250 lines or more Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... BSP Board Support Packages labels Jun 16, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 16, 2025
Copy link
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: 0

🧹 Nitpick comments (5)
packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf (1)

38-43: Boot sequence mutes all TDMOUT_A lanes – intentional?
Setting every lane volume to 0 dBFS ≠ 0x00 in Amlogic mixes; value 0 actually mutes them.
If the intent is “unity gain”, use 120 (or whatever the SoC defines as 0 dB) instead of 0.

config/sources/families/meson-g12b.conf (1)

24-26: Nit: use == for string equality to avoid pattern-matching surprises.

-elif [[ $BOARD = khadas-vim3 ]] || [[ $BOARD = cainiao-cniot-core ]]; then
+elif [[ $BOARD == khadas-vim3 ]] || [[ $BOARD == cainiao-cniot-core ]]; then
config/boards/cainiao-cniot-core.csc (1)

90-107: Guard against an undefined $destination and factor out the common UCM path.

-function post_family_tweaks_bsp__cainiao-cniot-core() {
+function post_family_tweaks_bsp__cainiao-cniot-core() {
+	: "${destination:?destination rootfs path not set}"
+	local ucm_dir="${destination}/usr/share/alsa/ucm2/Amlogic/axg-sound-card"
 	install -Dm644 "${SRC}/packages/bsp/cainiao-cniot-core/cainiao-cniot-core-HiFi.conf" \
-		"${destination}/usr/share/alsa/ucm2/Amlogic/axg-sound-card/cainiao-cniot-core-HiFi.conf"
+		"${ucm_dir}/cainiao-cniot-core-HiFi.conf"
 	install -Dm644 "${SRC}/packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf" \
-		"${destination}/usr/share/alsa/ucm2/Amlogic/axg-sound-card/cainiao-cniot-core.conf"
+		"${ucm_dir}/cainiao-cniot-core.conf"
-	if [ ! -d "${destination}/usr/share/alsa/ucm2/conf.d/axg-sound-card" ]; then
-		mkdir -p "${destination}/usr/share/alsa/ucm2/conf.d/axg-sound-card"
-	fi
-	ln -sfv /usr/share/alsa/ucm2/Amlogic/axg-sound-card/cainiao-cniot-core.conf \
-		"${destination}/usr/share/alsa/ucm2/conf.d/axg-sound-card/cainiao-cniot-core.conf"
+	install -d "${destination}/usr/share/alsa/ucm2/conf.d/axg-sound-card"
+	ln -sfv /usr/share/alsa/ucm2/Amlogic/axg-sound-card/cainiao-cniot-core.conf \
+		"${destination}/usr/share/alsa/ucm2/conf.d/axg-sound-card/cainiao-cniot-core.conf"
 }
packages/bsp/cainiao-cniot-core/cainiao-cniot-core-HiFi.conf (2)

14-16: In the verb’s EnableSequence you explicitly turn HDMI off – could be misleading.

Because the HDMI device’s own EnableSequence later turns it on again, this double toggle is harmless but adds mixer churn and complicates trace logs. Consider dropping the TOHDMITX Switch off here and rely solely on the device-level sequences.


24-25: Maxing out ACODEC Playback Volume (255) risks clipping on the speaker.

Typical unity gain on the Amlogic ACODEC is ~192. Unless you have measured headroom, lower this value to preserve dynamic range.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 989f255 and 1d9ae00.

⛔ Files ignored due to path filters (3)
  • patch/kernel/archive/meson64-6.12/dt/meson-g12b-a311d-cainiao-cniot-core.dts is excluded by !patch/**
  • patch/kernel/archive/meson64-6.15/dt/meson-g12b-a311d-cainiao-cniot-core.dts is excluded by !patch/**
  • patch/u-boot/v2025.04/board_cainiao-cniot-core/add-board-cainiao-cniot-core.patch is excluded by !patch/**
📒 Files selected for processing (5)
  • config/boards/cainiao-cniot-core.csc (2 hunks)
  • config/sources/families/meson-g12b.conf (1 hunks)
  • packages/blobs/asound.state/asound.state.cainiao-cniot-core (0 hunks)
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core-HiFi.conf (1 hunks)
  • packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/blobs/asound.state/asound.state.cainiao-cniot-core
🔇 Additional comments (1)
packages/bsp/cainiao-cniot-core/cainiao-cniot-core.conf (1)

1-3: Confirm target userspace ships alsa-lib ≥ 1.2.6 (required by ‘Syntax 4’ UCM files).
UCM v4 files will be ignored by older alsa-lib, falling back to an empty card definition and leaving audio non-functional.

#!/usr/bin/env bash
# Check that the rootfs pulls in libasound2 >= 1.2.6
fd -e list 'packages' -x grep -H -E 'libasound2.*(1\.2\.[0-5]|1\.1\.)' {} \; || echo "✓ no version pin <1.2.6 detected"

@retro98boy retro98boy force-pushed the cainiao-cniot-core-audio branch from 1d9ae00 to 2fafd70 Compare June 16, 2025 15:31
@github-actions github-actions bot removed the Ready to merge Reviewed, tested and ready for merge label Jun 16, 2025
@coderabbitai coderabbitai bot added the Ready to merge Reviewed, tested and ready for merge label Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 Milestone: Third quarter release BSP Board Support Packages Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review 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.

1 participant