# Linux Audio - ASoC [TOC] ## Abstractions and Hierarchies See [ALSA SoC Layer Overview](https://www.kernel.org/doc/html/latest/sound/soc/overview.html) and [ALSA SoC Layer](https://www.kernel.org/doc/html/latest/sound/soc/index.html) in kernel documentation. ### The "component" drivers The ALSA SoC framework breaks down what used to be in a single ALSA driver into smaller *component* drivers, each of them are a `struct snd_soc_component_driver`. ![Screenshot 2024-01-07 at 8.38.22 PM](https://hackmd.io/_uploads/HkKIofudT.png) ![Screenshot 2024-01-07 at 8.33.26 PM](https://hackmd.io/_uploads/H1MH5fuua.png) In ALSA, components are divided into two categories: *codec* and *CPU DAI*s. The former ones represent a standalone DSP external to the SoC; the later ones are abstraction for the intrinsic functionalities of the SoC itself. See [ALSA overview](https://wiki.st.com/stm32mpu/wiki/ALSA_overview) for further information. ### DAIs An *DAI* of a component describes an interface with which a component can connect to other components in ALSA. They are They are provided by instances of `snd_soc_dai_driver`. Every component is associate with a sets of DAI. Components can be connected to each other by connecting the DAIs. The DAIs for a component are provided alone with the component driver when it is registered. For example, in the [`devm_snd_soc_register_component()`](https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-devres.c#L56) ```c int devm_snd_soc_register_component(struct device *dev, const struct snd_soc_component_driver *cmpnt_drv, struct snd_soc_dai_driver *dai_drv, int num_dai) ``` The parameters with which the data stream should use when passing through the DAI is decrbed in the [`snd_soc_pcm_stream`](https://elixir.bootlin.com/linux/latest/source/include/sound/soc.h#L620), in particular the `capture` and `playback` member. ### Codec Drivers ### Machine Drivers A *machine* driver glues the components together by connecting. With each combination of components there in theory should be a different machine driver for that combination, making it a board-specific driver. ## Special Files For some devices using the ASoC framework (for example, the sound open firmware), the `struct snd_card` is wrapped in the [`struct snd_soc_card`](https://elixir.bootlin.com/linux/latest/source/include/sound/soc.h#L927), and the names are initialized in the [`snd_soc_bind_card()`](https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L2149) of the `sound/soc/soc-core.c`: ```c ... snd_soc_set_dmi_name(card, NULL); soc_setup_card_name(card, card->snd_card->shortname, card->name, NULL); soc_setup_card_name(card, card->snd_card->longname, card->long_name, card->name); soc_setup_card_name(card, card->snd_card->driver, card->driver_name, card->name); ... ``` `devm_snd_soc_register_card()` then `snd_soc_register_card()` then `snd_soc_bind_card()` ## Userspace Tools ## References ### [ASoC: Supporting Audio on an Embedded Board - Alexandre Belloni, Bootlin](https://youtu.be/572T8RDHK_A) {%youtube 572T8RDHK_A%} ### [Generic ALSA SoC Sound Card History (Simple/Graph) - Kuninori Morimoto, Renesas Electronics](https://youtu.be/usRwGpJJkpk) {%youtube usRwGpJJkpk %} ### [Insight of an Audio Driver Based on ALSA - Chandrasekar Ramakrishnan, Samsung](https://youtu.be/6R8Wjytv-eQ) Note that the slides are available [here](https://static.sched.com/hosted_files/ossna2022/78/OSS_ELC_2022_INSIGHT_OF_AN_AUDIO_DRIVER_BASED_ON_ALSA.pdf). {%youtube 6R8Wjytv-eQ %}