rk3566 android11 configure sound card (es7202 ADC)

Platform: rk3566 android11

kernel : 4.19.172

audio codec: es7202 ADC, this chip is just an encoding chip, without DAC function, that is, without decoding function, the audio signal cannot be decoded and output from this codec, so the audio can only be decoded and output from the onboard rk817, and the CPU side of this chip is used The PDM protocol, and the i2s protocol is generally used. The commonly used protocols are: i2c, PDM, PCM, TDM, etc.

A brief description of the PDM protocol:

A Modulation Method for Representing Analog Signals by Digital Signals

PCM uses the equal interval sampling method to represent the amplitude of the analog component of each sampling as an N-bit digital component (N = quantization depth), so the result of each sampling in the PCM method is N bit word-length data.

PDM, only 2 wires, transmit music, the encoding method is different from I2S.

Sine wave represented by PDM

Audio signals in PDM format can be routed near circuits with strong noise interference such as LCD screens.

The PDM-based architecture is different from I2S and TDM in that the decimation filter (Decimation Filter) is not in the sending device, but inside the receiving device. The source output is the original high sampling rate (oversample) modulated data, such as the output of the Sigma-Delta modulator, rather than the decimated data like in I2S. The application based on the PDM interface reduces the complexity of the sending device, and because the CODEC as a receiving device integrates a decimation filter inside, the overall system complexity is greatly reduced. For digital microphones, higher-efficiency decimation filters can be achieved by using finer silicon processes for CODEC or processor fabrication than those used for traditional microphones.

Audio Architecture focuses on literacy:

Hardware Driver: Audio hardware device driver, which consists of three parts, namely Machine, Platform, and Codec.

ASoC audio driver consists of three parts: platform, codec, machine.

The machine is controlled by the i2s connection between the platform and the codec, platform (cpu_dai) <----->codec_dai

Platform: Platform drivers include audio DMA engine drivers, digital audio interface (DAI) drivers (such as I2S, AC97, PCM), and any audio DSP drivers for that platform.
cpu dai: In embedded systems, it usually refers to the I2S and PCM bus controllers of the CPU, which are responsible for transferring audio data from the I2S tx FIFO to the CODEC (in the case of playback, the direction of recording is opposite). cpu_dai is registered through snd_soc_register_dai(). Note: DAI is the abbreviation of Digital Audio Interface, which is divided into cpu_dai and codec_dai, which are connected through I2S/PCM/pdm bus;
AIF is the abbreviation of Audio Interface, generally divided into I2S and PCM interfaces.
pcm dma: Responsible for transferring the audio data in the dmabuffer to the I2S tx FIFO. The logic of this part is more complicated, and the following articles will explain it in detail. The audio dma driver is registered through snd_soc_register_platform(). It is worth noting that the dma operation is not required in some cases, such as the direct connection between the Modem and the CODEC, because the Modem itself has already sent the data to the PCM FIFO. At this time, it is only necessary to start the codec_dai to receive the data; in this case, Machine driver dai_link needs to specify .platform_name = “snd-soc-dummy”, which is a virtual platform driver, see sound/soc/soc-utils.c for implementation.

Codec: The Codec driver is platform independent and contains audio controls, audio interface functions, codec DAPM definitions and codec IO functions. This class can be extended to BT, FM and MODEM IC if required. Codec class drivers should be generic code that can run on any architecture and machine.
For Playback, the PCM data sent by the userspace is a digital signal that has been sampled and quantized. The codec is converted into an analog signal by the DAC and sent to the external headphone output, so that we can hear the sound. Codec literally means codec, but there are many functional components in the chip, common ones are AIF, DAC, ADC, Mixer, PGA, Line-in, Line-out, and some high-end codec chips also have EQ, DSP, SRC, DRC, AGC, Echo canceller, Noise suppression and other components.


Machine: The Machine driver acts as the glue that describes and binds other component drivers to form an ALSA "sound card device". It handles any machine-specific controls and machine-level audio events (for example, turning on the amp when playback starts).
Machine can be understood as an abstraction of the development board. The development board may include multiple sound cards, and the corresponding Machine part contains multiple links.
Machine refers to a certain machine, which links the audio interfaces of cpu_dai, codec_dai, and modem_dai by defining dai_link, and then registers snd_soc_card. Unlike the above two, Platform and CODEC drivers are generally reusable, while Machine has its specific hardware characteristics and is almost not reusable. The so-called hardware features refer to: the link between DAIs; opening the Amplifier through a certain GPIO; detecting the insertion and removal of headphones through a certain GPIO; using a certain clock such as MCLK/External OSC as the reference clock source of I2S and CODEC modules, etc.

Platform driver: The platform driver is the control code of the cpu part, which abstracts two structures snd_soc_dai_driver and snd_soc_platform_driver;

codec driver: The codec driver is the control code of the codec part, which abstracts two structures, namely snd_soc_dai_driver and snd_soc_codec_driver;

Machine driver: The machine driver controls and manages the connection matching between platform and codec, manages controls, widgets and routes, and its abstract structure is snd_soc_card.
Platform drivers include audio DMA engine drivers (PCM DMA), digital audio interface (CPU DAI) drivers (such as I2S, AC97, PCM), and any audio DSP drivers for the platform. The commonly used ones are CPU DAI and PCM DMA drivers.

CPU DAI: In embedded systems, it usually refers to the I2S and PCM bus controllers of the CPU. For playback, it is responsible for moving audio data from I2S TX FIFO to CODEC (Capture is in the opposite direction). cpu_dai is registered through snd_soc_register_dai().

PCM DMA: For playback, it is responsible for moving the audio data in the dma buffer to the I2S TX FIFO (Capture is in the opposite direction). The audio dma driver is registered through snd_soc_register_platform().

Configuration:

&i2c3 {
	status = "okay";
	clock-frequency = <400000>;
	es7202: es7202@37 {
		status = "okay";
		#sound-dai-cells = <0>;
		compatible = "ES7202_PDM_ADC_1";
		reg = <0x37>;
	};
	
};

&pdm {
    status = "okay";
    #sound-dai-cells = <0>;
    rockchip,path-map = <1 0 3 2>;//录音声道顺序
    clocks = <&cru MCLK_PDM>, <&cru HCLK_PDM>;
    clock-names = "pdm_clk", "pdm_hclk";
    pinctrl-names = "default";
    pinctrl-0 = <&pdmm0_clk1
                 &pdmm0_sdi1>;
};

	es7202-sound {
		status = "okay";
		compatible = "simple-audio-card";
		simple-audio-card,format = "pdm";
		simple-audio-card,name = "rockchip,es7202";
		simple-audio-card,mclk-fs = <256>;
		simple-audio-card,cpu {
			sound-dai = <&pdm>;
		};
		simple-audio-card,codec {
			sound-dai = <&es7202>;
		};
	};

audio codec debugging command:

Confirm that the sound card registration is successful through proc fs
# cat /proc/asound/cards
0 [rockchiprk809co]: rockchip_rk809- - rockchip,rk809-codec
rockchip,rk809-codec
7 [Loopback
]: Loopback - Loopback
Loopback 1
# ls /dev/snd/
by-path controlC7 pcmC0D0p pcmC7D0p pcmC7D1p
controlC0 pcmC0D0c pcmC7D0c pcmC7D1c timer

/proc/asound # cat   devices                                                                                                

  1: : sequencer
  2: [ 0- 0]: digital audio playback
  3: [ 0- 0]: digital audio capture
  4: [ 0]   : control
  5: [ 1- 0]: digital audio capture
  6: [ 1]   : control
  33:        : timer

 Note: There is a problem with the manufacturer's es7202 driver. If your pdm data line is directly returned to the CPU, you need to modify the driver. I will upload it to the resource. Please download it yourself if necessary.

Attach the hardware schematic diagram:

        

 

 

 

Guess you like

Origin blog.csdn.net/qq_48709036/article/details/123730413