Rockchip RK3399 – ALSA Proc Info

—————————————————————————————————————————-

Development Board: NanoPC-T4 Development BoardeMMC: 16GBLPDDR3: 4GBDisplay: 15.6 Inch HDMI Interface Displayu-boot: 2023.04Linux: 6.3—————————————————————————————————————————-

The /proc directory on Linux systems is a type of file system, known as the proc file system. Unlike other common file systems, /proc is a pseudo file system (i.e., a virtual file system) that stores a series of special files representing the current running state of the kernel. Users can access these files to view information about system hardware and currently running processes, and even change certain files to modify the kernel’s operational state.

Due to the uniqueness of the /proc file system as described above, the files within it are often referred to as virtual files and possess some unique characteristics. For example, some files may return a large amount of information when viewed with commands, but the size of the file itself may show as 0 bytes. Additionally, most of these special files typically have their time and date attributes set to the current system time and date, which is related to the fact that they can be refreshed at any time (stored in RAM).

1. /proc/asound

ALSA has its own proc tree, where many detailed information about sound cards can be found under the /proc/asound directory,Proc Files of ALSA Drivers.

root@rk3399:/# ll /proc/asound
 dr-xr-xr-x   5 root root 0 Aug  6 16:43 card0/
 dr-xr-xr-x   5 root root 0 Aug  6 16:55 card1/
 -r--r--r--   1 root root 0 Aug  6 15:10 cards
 -r--r--r--   1 root root 0 Aug  6 16:55 devices
 lrwxrwxrwx   1 root root 5 Aug  6 16:55 hdmisound -> card0/
 -r--r--r--   1 root root 0 Aug  6 16:55 pcm
 lrwxrwxrwx   1 root root 5 Aug  6 16:55 realtekrt5651co -> card1/
 dr-xr-xr-x   6 root root 0 Aug  6 16:55 seq/
 -r--r--r--   1 root root 0 Aug  6 16:55 timers
 -r--r--r--   1 root root 0 Aug  6 16:55 version

The main nodes are as follows:

  • • cardx: Represents the registered sound card;
  • • cards: Displays the currently configured ALSA Drivers, index, the id string, short and long descriptions;
  • • version: Displays the version string;
  • • devices: Lists the device mappings on this machine;
  • • pcm: Lists the currently available PCM devices, in the format:: : : ;

This section mainly explains the /proc/asound directory tree created in the ALSA core and how it is achieved.

In the alsa_sound_init function, the snd_info_init function is called to create the /proc/asound directory and save this entry in the global variable snd_proc_root (i.e., as the sound proc root entry), as shown in the code below:

int __init snd_info_init(void)
{
    //1. Create alsa proc root entry;
    snd_proc_root = snd_info_create_entry("asound", NULL);
    if (!snd_proc_root)
        return -ENOMEM;
    snd_proc_root->mode = S_IFDIR | 0555;
    //2. Create dir: /proc/asound
    snd_proc_root->p = proc_mkdir("asound", NULL);
    if (!snd_proc_root->p)
        goto error;
#ifdef CONFIG_SND_OSSEMUL
    snd_oss_root = create_subdir(THIS_MODULE, "oss");
    if (!snd_oss_root)
        goto error;
#endif
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
    snd_seq_root = create_subdir(THIS_MODULE, "seq");
    if (!snd_seq_root)
        goto error;
#endif
    if (snd_info_version_init() < 0 ||    //3. Create file: /proc/asound/version
        snd_minor_info_init() < 0 ||    //4. Create file: /proc/asound/devices
        snd_minor_info_oss_init() < 0 ||
        snd_card_info_init() < 0 ||        //5. Create file: /proc/asound/cards
        snd_info_minor_register() < 0)
        goto error;
    return 0;

 error:
    snd_info_free_entry(snd_proc_root);
    return -ENOMEM;
}

1.1 version file

As shown in the code above, in the snd_info_init function, in addition to creating /proc/asound, the “version” file (i.e., /proc/asound/version) is created immediately under the snd_proc_root entry (i.e., using snd_proc_root entry as the parent entry) and provides a read method. The code explanation is omitted, and the output of cat /proc/asound/version is as follows:

root@rk3399:/#  cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k6.3.0.

1.2 devices file

Next, the “devices” file (i.e., /proc/asound/devices) is created under the snd_proc_root entry, which provides a read method. The output of cat /proc/asound/devices is as follows:

root@rk3399:/# cat /proc/asound/devices
  1:        : sequencer
  2: [ 0- 0]: digital audio playback
  3: [ 0- 0]: digital audio capture
  4: [ 0]   : control
  5: [ 1- 0]: digital audio playback
  6: [ 1- 0]: digital audio capture
  7: [ 1]   : control
 33:        : timer

The print format for devices is as follows:

  • • Control device: “minor: [card_id] : control”;
  • • PCM device: “minor: [card_id- device_id]: digital audio playback/capture”;
  • • Timer device: “minor: : timer”;

1.3 cards file

Next, the “cards” file (i.e., /proc/asound/cards) is created under the snd_proc_root entry, which provides a read method. The output of cat /proc/asound/cards is as follows:

root@rk3399:/# cat /proc/asound/cards
 0 [hdmisound      ]: simple-card - hdmi-sound
                      hdmi-sound
 1 [realtekrt5651co]: simple-card - realtek,rt5651-codec
                      realtek,rt5651-codec

The print format for cards is as follows:

card_id [card_id_string    ]:    card_driver - card_shortname
                            card_longname

1.4 cardx directory

We have previously analyzed the execution flow of the snd_card_new function, which internally calls snd_info_card_create to create the

Leave a Comment