1. Origin of ASoC

ASoC–ALSA System on Chip is a software architecture built on the standard ALSA driver layer to better support audio Codec in embedded processors and mobile devices. Before THE advent of ASoc, the kernel already had partial support for audio in soCs, but there were some limitations:

  • The low level coupling of the Codec driver to the SoC CPU was too tight, which resulted in code duplication, for example, in the wM8731 driver alone, when there were four separate drivers in Linux.
  • There is no standard way to notify the user of audio events, such as the plugging and detection of headphones and microphones, which are common in mobile devices and often require machine-specific code to reconfigure the audio circuit.
  • When playing or recording, the driver keeps the entire Codec powered up, which is fine for a PC, but can mean wasting a lot of power on a mobile device. It is also not supported to save power by changing the over-sampling frequency and bias current.

ASoC was proposed to address these issues and is now integrated into the kernel’s code tree: Sound/SOC. ASoC cannot exist alone, it is simply built on top of the standard ALSA driver and it must be combined with the standard ALSA driver framework to work.

/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / statement: This Po by http://blog.csdn.net/droidphone, to the original, reproduced please indicate the source, thank you! / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / \

2. Hardware architecture

In general, just like abstraction and reuse in the software world, the audio system of embedded devices can be divided into three major parts: onboard hardware (Machine), Soc (Platform), and Codec, as shown in the following figure:

Figure 2.1 Audio system structure

  • Machine refers to a certain Machine, which can be a certain device, a certain development board, or a certain smart phone. It can be seen from this that Machine is almost not reusable. The hardware implementation of each Machine may be different, including CPU, Codec, and audio input and output devices. Machine provides a carrier for CPU, Codec, I/O devices.
  • Platform generally refers to a SoC Platform, such as PxAXxx, S3CXXXX, OMAPXXX, etc., and audio related usually includes the clock, DMA, I2S, PCM, etc. As long as the SoC is specified, we can assume that it will have a corresponding Platform. It is only related to SoC, not Machine, so that we can abstract Platform, so that the same SoC can be used in different machines without making any changes. In fact, it’s better to think of Platform as a SoC.
  • Codec literally means Codec. Codec contains I2S interface, D/A, A/D, Mixer, PA (power amplifier), and usually contains multiple inputs (Mic, Line-In, I2S, PCM) and multiple outputs (headphones, speakers, earphones, line-out). Codec, like Platform, is a reusable component, and the same Codec can be used by different machines. Embedded Codec usually controls internal registers via I2C.

3. Software architecture

At the software level, ASoC also divides the audio system of embedded devices into three parts: Machine, Platform and Codec.

  • One of the key design principles in THE Codec driver ASoC is to require the Codec driver to be platform independent, which includes audio Controls, audio interfaces, DAMP (Dynamic Audio Power Management) definitions, and some Codec IO functionality. To ensure hardware independence, any Platform – and machine-specific code is moved to the Platform and Machine drivers. All Codec drivers should provide the following features:

    • Configuration information for Codec DAI and PCM;
    • IO control mode of Codec (I2C, SPI, etc.);
    • Mixer and other audio controls;
    • Codec ALSA audio operation interface;

If necessary, the following functions can also be provided:

    • DAPM description;
    • DAPM event handler;
    • DAC digital mute control
  • It contains the configuration and control of the AUDIO DMA and audio interface for the SoC Platform (I2S, PCM, AC97, etc.); It also cannot contain any board – or machine-specific code.
  • The Machine driver handles controls and audio events specific to the Machine (for example, an amplifier needs to be turned on before audio is played); Platform and Codec drivers alone do not work, it must be combined by Machine drivers to do the audio processing for the entire device.

4. Data structure

The whole ASoC is composed of a series of data structures. In order to understand the working mechanism of ASoC, it is necessary to understand the relationships and functions among these data structures. The following diagram shows the association modes among important data structures in ASoC:

\

Figure 4.1 Static relationship of each structure in kernel-2.6.35-ASOC

ASoC implements the sound card as a Platform Device and then makes use of the dev field in the Platform_device structure: dev.drvdata, which actually points to an SNd_soc_device structure. Snd_soc_device can be thought of as the root of the entire ASoC data structure, from which a series of data structures were introduced to express the various features and functions of audio. The snd_soc_device structure introduces the snd_soc_card and soc_codec_device structures. Then snd_soc_card leads to snd_soc_platform, snd_soc_dai_link, and snd_soc_codec structures. As mentioned above, ASoC is divided into Machine, Platform and Codec. From these data structures, SNd_COdec_device and SNd_soc_card represent Machine drivers. Snd_soc_platform represents the Platform driver, snd_soc_codec and soc_codec_device represent the Codec driver, and snd_soc_DAI_link connects the Platform and Codec.

5. Improvements to ASoC in the 3.0 kernel

The original reference for this article was 2.6.35, but a CSDN friend pointed out that ASoC has made major changes in kernel version 3.0. So I downloaded the 3.0 code, and found that there is indeed a change. The following is a static diagram of the data structure:

\

Figure 5.1 ASoC data structure in Kernel 3.0

The snd_soc_device structure has been removed and replaced by snd_soc_card, and the snd_soc_pcM_runtime has been enhanced. Two additional data structures, SNd_soc_codec_driver and snd_soc_platform_driver, were also added to explicitly represent Codec drivers and Platform drivers.

The details and relationships of Machine and Platform and Codec drivers will be covered in subsequent chapters.