Linux kernel audio technology based on I2S interface

Publisher:和谐相处Latest update time:2024-05-10 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This article takes the I2S interface as an example to introduce Linux kernel audio related knowledge.


1. Introduction to terms

The following are some common abbreviations used in audio debugging.

1. AEC (Acoustic Echo Cancellor): echo cancellation.

2. AGC (Automatic Gain Control): Automatic gain compensation, adjust the MIC reception volume.

3. ALSA (Advanced Linux Sound Architecture): Advanced Linux sound architecture.

4. ANS (Automatic Noise Suppression): Background noise suppression. ANS can detect background noise with fixed frequency and eliminate background noise.

5. BCK (Bit Clock Line): Bit clock, corresponding to each bit of digital audio data. The standard is called SCK (Serial Clock), serial clock. SCK = 2x sampling frequency x number of sampling bits

6. DAI (Digital Audio Interface): digital audio interface.

7. DAPM (Dynamic Audio Power Management): Dynamic power management, DAPM allows the audio subsystem on Linux-based mobile devices to operate in the minimum power consumption state at all times.

8. DRC (Dynamic Range Control): Dynamic compression, controls audio output within a certain range.

9. EQ (Equaliser): Equalizer adjusts the tone by gaining or attenuating one or more frequency bands of the sound.

10. I2S (Inter-IC Sound): An interface standard for transmitting digital audio data between ICs, which uses a serial method to transmit two groups (left and right channel) of data.

11. LRCK (Left-Right Clock): frame clock, used to switch left and right channel data, 0: left channel; 1: right channel. The standard is called WS (World Select), channel selection; or FS (Frame Sync), frame synchronization; LRCK frequency = sampling frequency.

12. MCLK (Master Clock): Master clock, generally MCLK = 256*LRCK. It is not part of the I2S standard and is mainly used to synchronize the internal operation of the analog/digital converter.

13. Mono: mono.

14. OSS (Open Sound System): Open sound system.

15. PCM (Pulse Code Modulation): Pulse Code Modulation. I2S is a subset of PCM.

16. Ramp: Gradually increase or decrease the volume level to avoid rapid changes in sound. It is used to pause or resume music.

17. Stereo: dual channel

18. TDM (Time Division Multiplexing): Time Division Multiplexing. I2S can only transmit 2 channels of data at most, while TDM supports up to 16 channels.

2. I2S interface

I2S is a digital audio transmission standard defined by Philips and is used to transmit digital audio data between internal devices of a system.

I2S is a branch of PCM, and the interface definition is the same. The sampling rate of I2S is generally 44.1/48KHZ, and the sampling frequency of PCM is generally 8/16KHZ, etc.

The I2S interface has 4 groups of signals: SCK (bit clock), LRCK (frame clock), and SDI/SDO (data).

On the I2S bus, there can only be one master device and one sending device at the same time. The master device can be a sending device or a receiving device. The common I2S block diagram is as follows:

f8268c5a-d507-11ee-a297-92fbcf53809c.png

3. I2S Protocol

Common protocol modes of the I2S interface include: I2S normal mode, I2S left-aligned mode, and I2S right-aligned mode.

1. I2S normal mode

I2S normal mode is a special case of I2S left alignment, also called Philips mode. The figure below shows the waveform of I2S normal mode.

f82a98ea-d507-11ee-a297-92fbcf53809c.png

The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes low for the left channel and goes high for the right channel.

The SD (i2s_sdo, i2s_sdi) signal transmits MSB or LSB first and sends the first bit one SCLK clock cycle after LRCK changes.

SD signal width ranges from 16 to 32 bits.

2. I2S left-aligned mode

The figure below shows the waveform of I2S left-aligned mode.

f8371ebc-d507-11ee-a297-92fbcf53809c.png

The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes high for the left channel and goes low for the right channel.

The SD (i2s_sdo, i2s_sdi) signal is transmitted MSB or LSB first and the first bit is sent at the same time as LRCK changes.

SD signal width ranges from 16 to 32 bits.

3. I2S right-aligned mode

The figure below shows the waveform of I2S right-aligned mode.

f84e34a8-d507-11ee-a297-92fbcf53809c.png

The LRCK (i2s_LRCK_rx/i2s_LRCK_tx) signal goes high for the left channel and goes low for the right channel.

The SD (i2s_sdo, i2s_sdi) signals are transmitted MSB or LSB first, unlike the I2S normal or left-aligned mode, where the data is aligned with the last bit at the edge of the LRCK signal.

SD signal width ranges from 16 to 32 bits.

Other protocol formats include: PCM early mode, PCM late1 mode and PCM late2 mode.

4. ALSA framework

After Linux kernel 2.6, ALSA replaced OSS and became part of the Linux kernel audio subsystem.

The ALSA system includes:

1. alsa-driver: alsa system driver.

2. alsa-lib: alsa library, user space calls, and kernel space interactions.

3. alsa-utils: command line tool.

4. alsa-plugin: alsa plug-in.

5. alsa-tools: alsa tools.

The ALSA framework consists of the following:

f85d4a6a-d507-11ee-a297-92fbcf53809c.jpg

The related functions in alsa-driver are as follows (taking rockchip 4a board as an example):

1. Codec: The common part of the audio chip, including codec initialization function, control interface, register cache, controls, dapm components, audio routing, bias voltage setting function and other descriptive information.

Rockchip 4A single board, Codec uses ES8316 chip, the dts configuration of this chip is as follows:

f86c33d6-d507-11ee-a297-92fbcf53809c.jpg

2. Codec DAI: audio interface driver description on the codec, including: clock configuration, format configuration, capability description, etc.

Codec DAI related implementation is as follows:

f87b0b68-d507-11ee-a297-92fbcf53809c.png

3. CPU DAI: refers to the I2S and PCM bus controller of the SoC, which is responsible for moving audio data from the I2S tx FIFO to the codec.

The dts related configuration of RK3399 CPU DAI is as follows:

f87f4d0e-d507-11ee-a297-92fbcf53809c.png

4. DAI Link: Audio data link, which specifies the codec, codec_dai, cpu_dai and platform used in the link.

The Linux 4.4 kernel supports two ways to create a sound card: one is the general simple-card framework; the other is the traditional way of creating a custom machine driver.

Simple card is a simple and universal machine driver. If the simple-card framework can meet your needs, you can choose the simple card framework first.

The DTS-related configuration of DAI Link is as follows:

f88381da-d507-11ee-a297-92fbcf53809c.jpg

The relevant implementation of DAI Link is as follows:

f896b98a-d507-11ee-a297-92fbcf53809c.png

5. DAPM: Dynamic Power Management is based on the improved framework of kcontrol and adds corresponding power management mechanisms. Widget is the basic unit of DAPM.

The relevant implementations of kcontrol, dapm widget and dapm routes in Codec (es8316) are as follows:

f8a7b94c-d507-11ee-a297-92fbcf53809c.png

6. DMA: responsible for moving the audio data in the DMA buffer to the I2S tx FIFO.

5. Debugging commands

ALSA is the basic interface for Linux to process audio, but ALSA only provides a basic interface and the operation is relatively complicated. In general, you can directly use the utils toolset provided with it. The utils toolset is some encapsulated functional modules that are provided directly in the form of commands. Users only need to type in relevant commands and parameters to implement audio operation functions.


1. Check the sound card information


root@xiaotianbsp:~# cat /proc/asound/cards

0 [rockchipes8316c]: rockchip_es8316 - rockchip,es8316-codec

rockchip,es8316-codec

1 [HDMICODEC]: HDMI-CODEC - HDMI-CODEC

HDMI-CODEC

root@xiaotianbsp:~# ls -l /dev/snd/

total 0

drwxr-xr-x 2 root root 80 Aug 16 14:43 by-path

crw-rw----+ 1 root audio 116, 2 Aug 16 14:43 controlC0

crw-rw----+ 1 root audio 116, 5 Aug 16 14:43 controlC1

crw-rw----+ 1 root audio 116, 4 Aug 16 14:43 pcmC0D0c

crw-rw----+ 1 root audio 116, 3 Aug 16 14:43 pcmC0D0p

crw-rw----+ 1 root audio 116, 6 Aug 16 14:43 pcmC1D0p

crw-rw----+ 1 root audio 116, 1 Aug 16 14:43 seq

crw-rw----+ 1 root audio 116, 33 Aug 16 14:43 timer

controlCx: control interface, providing a flexible way to manage registered sound cards and query existing sound cards.


pcmCxDxc: PCM interface, corresponding to recording device.


pcmCxDxp: PCM interface, corresponding to the sound playback device.


timer: Supports sound synchronization events by providing a timer on the sound card.


seq: sequencer interface, a high-level interface for MIDI programming and sound synchronization that is more advanced than the original MIDI interface.


2. Check the sound card acquisition and playback PCM information


root@xiaotianbsp:~# cat /proc/asound/pcm

00-00: ff880000.i2s-ES8316 HiFi ES8316 HiFi-0 : : playback 1 : capture 1

01-00: ff8a0000.i2s-i2s-hifi i2s-hifi-0 : : playback 1

3. Check the ALSA driver version


root@xiaotianbsp:~# cat /proc/asound/version

Advanced Linux Sound Architecture Driver Version k4.4.154-90-rockchip-ga14f6502e045.

4. Check the information of sound card 0


root@xiaotianbsp:~# cat /proc/asound/card0/pcm0p/sub0/status

closed

5. Check the register


## regmap name

root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/1-0011/name

es8316

root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/ff880000.i2s/name

rockchip-i2s


##rk3399 i2s0 controller registers

root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/ff880000.i2s/registers

00: 0000000f

04: 0000000f

08: 00033f3f

0c: 00000000

10: 000f0010

14: 01f00000

18: XXXXXXXX

1c: 00000000

20: XXXXXXXX

28: 00000000


## es8316 registers

root@xiaotianbsp:~# cat /sys/kernel/debug/regmap/1-0011/registers

00: c0

01: f3

02: 08

03: 20

04: 11

05: 00

06: 11

07: 00

08: 00

09: 04

0a: 0c

0b: 0c

0c: ff

0d: 3f

[1] [2]
Reference address:Linux kernel audio technology based on I2S interface

Previous article:Tips on microphone selection
Next article:Analysis of washing machine motor controller circuit

Recommended ReadingLatest update time:2024-11-16 09:17

Linux device tree learning (2) Transfer and use of device tree
1. uboot and device tree When the bootloader starts the kernel, it will set three registers r0, r1, and r2. r0 is generally set to 0; r1 is generally set to machine id (there are special files defining machine codes in uboot and Linux) (this parameter is not used when using the device tree); r2 generally sets the star
[Microcontroller]
Linux device tree learning (2) Transfer and use of device tree
STC8H Development (Part 2): Configuring and using the FwLib_STC8 package library in Linux VSCode
The previous section introduces the use of FwLib_STC8 in the Keil5 environment of Windows. The following describes the environment setup under VSCode in Linux (Ubuntu 20.04 is used in this article) Configure the VSCode development environment to run the demonstration case premise VSCode + PlatformIO environment has
[Microcontroller]
STC8H Development (Part 2): Configuring and using the FwLib_STC8 package library in Linux VSCode
OK6410A development board (eight) 7 linux-5.11 OK6410A usb camera transplant
Code : https://github.com/lisider/linux/tree/ok6410a-linux-5.11 Submit id : 0cf53aa024fbd417f0796a77ff7f9b891680dac8 defconfig : arch/arm/configs/ok6410A_sdboot_mini_net_lcd_x11_usb_debug_uvc_defconfig User space code uvc_cam_test Makefile CROSS_COMPILE =arm-none-linux-gnueabi- KERNELDIR = CFLAGS = -I$(KERNELDIR)
[Microcontroller]
Embedded Linux: ARM Linux boot process
The ARM Linux boot process is roughly as follows: bootloader ---- kernel---- root filesystem. The bootloader takes control of the CPU as soon as the power is on, and the bootloader implements hardware initialization. The bootloader has become the "first to try" code after power on. When it comes to this, we have to
[Microcontroller]
Embedded Linux: ARM Linux boot process
OK6410A Development Board (VIII) 62 linux-5.11 Common abnormal scenarios and analysis of OK6410A linux application space
When the application is running, it cannot feel other processes. When the application is running, there are three situations 1. User space execution instructions 2. An exception occurs and the kernel is trapped 6 types of exceptions // excluding reset exceptions, reset exceptions cannot be recovered after they o
[Microcontroller]
(Linux self-study notes) GPIO character driver under Linux environment
There are three types of drivers in the Linux environment: character device drivers, block device drivers, and network device drivers. Linux drivers can be written as modules and loaded into the kernel. The operating devices of Linux are in the form of files. Simple IO port driver, d
[Microcontroller]
Qt-embedded-linux-opensource-src-4.5.1 ported to mini2440 development board technical description
Friends who have used FriendlyArm know that the built-in interface design of FriendlyArm mini2440 is qt2, but now q4 is gradually becoming the mainstream. It is not easy to successfully transplant qt4 to mini2440. I also spent a lot of effort to complete such a project. Now I share my experience with you, hoping tha
[Microcontroller]
OK6410A Development Board (VIII) 125 linux-5.11 OK6410A Process Communication Pipe
Overview The essence of a pipeline is to use __get_free_page to apply for a space in the kernel space and initialize it as a circular buffer. When writing, fill this buffer. When it is full, block or non-block according to the IO settings. Write to non-empty and wake up the reading process. When reading, the value is
[Microcontroller]
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号