Audio Adaptation Guide (ALC5640 Example)
This guide uses the Realtek ALC5640 audio codec as an example describe the driver adaptation, device tree configuration, kernel configuration, system integration, and common testing methods on the NG4500-CB01 platform.
Terms and Explanations
Terms | Explanations |
---|---|
I2S | Serial interface for digital audio transmission between ICs, commonly used to connect external audio devices. |
DSPK | Digital speaker interface for connecting and controlling digital speakers; supports digital speaker output. |
DMIC | Digital microphone controller for managing and processing digital microphone input,supports various digital mic types. |
Mixer | Mixer module that combines multiple audio input signals into a single output. |
AMX | Audio multiplexer that merges multiple audio signals into a single output channel. |
ADX | Audio demultiplexer that splits a single audio signal into multiple independent channels. |
SFC | Sample rate converter for transforming audio signals between different sampling rates to improve system compatibility. |
MVC | Master volume controller for unified adjustment of audio channel output volume. |
ADMA | Audio-specific Direct Memory Access controller for efficient audio data transfer, supporting up to 32 audio channels. |
ADMAIF | AHUB DMA interface enabling data exchange between audio hardware modules and system memory; supports 20 TX/RX channels, optimized for Jetson. |
XBAR | Audio crossbar (router) for dynamically routing audio signals between multiple sources and destinations; the core of audio path configuration. |
APE | Dedicated audio processing engine on the Jetson platform, featuring low power consumption and high performance for tasks like audio decoding. |
AHUB | Core component of APE that integrates multiple NVIDIA proprietary hardware modules for audio routing, processing, and inter-module communication. |
Software Driver Architecture
- ALSA ASoC(Audio System on Chip) is the mainline Linux audio subsystem,provide better ALSA support for embedded system on chip procesors.。
- ASoC system architecture consists of three core driver components:
- Codec Driver:Manages ALC5640 registers and audio signal paths
- Platform Driver:Handles Tegra DMA and I2S interface operations
- Machine Driver:Binds hardware components and defines audio routing
- The NVIDIA Jetson platform integrates a proprietary audio architecture featuring the APE engine and AHUB module, supporting XBAR dynamic routing and multi-channel DMA via ADMAIF.
ALC5640 Driver Configuration Process
Prerequisites
-
Confirm the I2C address of the ALC5640 codec chip.
-
Refer to the datasheet to determine the ALC5640 operating mode (Master/Slave) and required clock signals (e.g., MCLK, BCLK, LRCK).
Device Tree Configuration
Locate or create the device tree file in Linux_for_Tegra/source/hardware/nvidia/t23x/nv-public/nv-platform/tegra234-NG45XX-p3768-0000+p3767-0000-common.dts
, configure the following:
-
I2C Node – Add Codec Configuration as shown below:
i2c@3160000 {
status = "okay";
rt5640: audio-codec@1c {
status = "okay";
compatible = "realtek,rt5640";
reg = <0x1c>;
interrupt-parent = <&gpio>;
interrupts = <TEGRA234_MAIN_GPIO(P, 6) 0>;
clocks = <&bpmp TEGRA234_CLK_AUD_MCLK>;
clock-names = "mclk";
realtek,dmic1-data-pin = <RT5640_DMIC1_DATA_PIN_NONE>;
realtek,dmic2-data-pin = <RT5640_DMIC2_DATA_PIN_NONE>;
realtek,jack-detect-source = <RT5640_JD_SRC_HDA_HEADER>;
sound-name-prefix = "CVB-RT";
sel_jd_source = <3>;
port {
rt5640_ep: endpoint {
remote-endpoint = <&i2s4_dap>;
mclk-fs = <256>;
};
};
};
}; -
I2S Node,Enable AHUB, I2S Controller, and Connect Codec to
r&t5640_ep codec
chip as shown below:aconnect@2900000 {
status = "okay";
ahub@2900800 {
status = "okay";
i2s@2901300 {
status = "okay";
ports {
port@1 {
endpoint {
dai-format = "i2s";
remote-endpoint = <&rt5640_ep>;
};
};
};
};
};
}; -
Sound card node definition and routing configuration as shown below :
sound {
status = "okay";
compatible = "nvidia,tegra186-audio-graph-card",
"nvidia,tegra186-ape";
nvidia-audio-card,mclk-fs = <256>;
label = "NVIDIA Jetson Orin Nano APE";
nvidia-audio-card,widgets =
"Headphone", "CVB-RT Headphone Jack",
"Microphone", "CVB-RT Mic Jack",
"Speaker", "CVB-RT Int Spk",
"Microphone", "CVB-RT Int Mic";
nvidia-audio-card,routing =
"CVB-RT Headphone Jack", "CVB-RT HPOL",
"CVB-RT Headphone Jack", "CVB-RT HPOR",
"CVB-RT Headphone Jack", "CVB-RT LOUTL",
"CVB-RT Headphone Jack", "CVB-RT LOUTR",
"CVB-RT IN1P", "CVB-RT Mic Jack",
"CVB-RT IN2P", "CVB-RT Mic Jack",
"CVB-RT IN3P", "CVB-RT Mic Jack",
"CVB-RT Int Spk", "CVB-RT SPOLP",
"CVB-RT Int Spk", "CVB-RT SPORP",
"CVB-RT DMIC1", "CVB-RT Int Mic",
"CVB-RT DMIC2", "CVB-RT Int Mic";
}; -
DAI Link , linking the CPU ADMA intermediate xbar to the codec alc5640
nvidia-audio-card,dai-link@79 {
link-name = "rt5640-playback";
codec {
sound-dai = <&rt5640 0>;
prefix = "CVB-RT";
};
};
Kernel Configuration
Edit the following fileLinux_for_Tegra/source/kernel/kernel-jammy-src/arch/arm64/configs/defconfig
add the following commands.
CONFIG_SND_SOC_ALC5640=m
System Integration & Driver Loading
- Boot the target device (AIBOX),Transfer the compiled DTB and kernel module via
scp
from your host machine
cd Linux_for_Tegra/source
scp ./kernel-devicetree/generic-dts/dtbs/tegra234-NG45XX-p3768-0000+p3767-0003-nv-super.dtb milesight@192.168.60.3:/home/milesight
scp ./kernel/kernel-jammy-src/sound/soc/codecs/snd-soc-rt5640.ko milesight@192.168.60.3:/home/milesight
- copy the
snd-soc-rt5640.ko
to the kernel module path and rundepmod
to load driver.
sudo cp ./snd-soc-rt5640.ko /lib/modules/5.15.148-tegra/kernel/sound/soc/codecs/snd-soc-rt5640.ko
sudo depmod
- Finally, reboot the device to apply the configuration.
Debugging
- Headphone / Internal Speaker Playback Test
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"
amixer -c APE cset name="CVB-RT DAC MIXL INF1 Switch" "on"
amixer -c APE cset name="CVB-RT DAC MIXR INF1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo DAC MIXL DAC L1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo DAC MIXR DAC R1 Switch" "on"
amixer -c APE cset name="CVB-RT HPO MIX DAC1 Switch" "on"
amixer -c APE cset name="CVB-RT HP L Playback Switch" "on"
amixer -c APE cset name="CVB-RT HP R Playback Switch" "on"
amixer -c APE cset name="CVB-RT HP Playback Volume" "31,31"
amixer -c APE cset name="CVB-RT DAC1 Playback Volume" "175,175"
#Testing
aplay xxx.wav
- Headset Microphone Recording Test
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"
amixer -c APE cset name="CVB-RT IN1 Boost" 8
amixer -c APE cset name="CVB-RT RECMIXL BST1 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo ADC1 Mux" "ADC"
amixer -c APE cset name="CVB-RT Stereo ADC MIXL ADC1 Switch" "on"
amixer -c APE cset name="CVB-RT Stereo ADC MIXR ADC1 Switch" "on"
amixer -c APE cset name='CVB-RT ADC Capture Switch' on
#Record and playback
arecord -Dhw:APE,1 -c 2 -r 44100 -f S16_LE -d 5 xxx.wav
aplay xxx.wav
- External Speaker Playback Test
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"
amixer -c APE cset name="CVB-RT Speaker Channel Switch" on
amixer -c APE cset name="CVB-RT Speaker L Playback Switch" on
amixer -c APE cset name="CVB-RT Speaker R Playback Switch" on
amixer -c APE cset name="CVB-RT Speaker Playback Volume" 50%
amixer -c APE cset name="CVB-RT DAC1 Playback Volume" "175,175"
amixer -c APE cset name="CVB-RT DAC MIXL INF1 Switch" on
amixer -c APE cset name="CVB-RT DAC MIXR INF1 Switch" on
amixer -c APE cset name="CVB-RT SPK MIXL DAC L1 Switch" on
amixer -c APE cset name="CVB-RT SPK MIXR DAC R1 Switch" on
amixer -c APE cset name="CVB-RT SPOL MIX SPKVOL L Switch" on
amixer -c APE cset name="CVB-RT SPOR MIX SPKVOL R Switch" on
amixer -c APE cset name="CVB-RT OUT MIXL SPK MIXL Switch" on
amixer -c APE cset name="CVB-RT OUT MIXR SPK MIXR Switch" on
#Testing
aplay xxx.wav
- External Microphone Recording Test
amixer -c APE cset name="I2S4 Mux" "ADMAIF1"
amixer -c APE cset name="CVB-RT IN2 Boost" 8
amixer -c APE cset name="CVB-RT IN3 Boost" 8
amixer -c APE cset name="CVB-RT RECMIXL BST2 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST2 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXL BST3 Switch" "on"
amixer -c APE cset name="CVB-RT RECMIXR BST3 Switch" "on"
amixer -c APE cset name='CVB-RT ADC Capture Switch' on
#Testing: Recording and Playback
arecord -Dhw:APE,1 -c 2 -r 44100 -f S16_LE -d 5 xxx.wav
aplay xxx.wav
Troubleshooting
-
No audio output
-
Verify MCLK/BCLK are present and stable
-
Check the I2S interface
-
Check the amixer routing settings
-
-
Recording noise
- Ensure correct sampling rate
References
Audio Setup and Development — NVIDIA Jetson Linux Developer Guide
For adapting other audio codecs, the procedure is largely similar. Key focus should be on driver support and device tree configuration.