Skip to content

Instantly share code, notes, and snippets.

@crojewsk
Last active May 21, 2024 16:41
Show Gist options
  • Save crojewsk/4e6382bfb0dbfaaf60513174211f29cb to your computer and use it in GitHub Desktop.
Save crojewsk/4e6382bfb0dbfaaf60513174211f29cb to your computer and use it in GitHub Desktop.
Enabling HDA (dsp) plus DMIC audio configuration on Skylake and Kabylake platforms

Linux: HDA+DMIC with skylake driver

Table of Contents


Audience

This document targets Skylake, Kabylake, Kabylake-refresh, Amberlake and some other platforms where audio is of SPT (PCH) type. HDA (with DSP capabilities) plus DMIC configuration is supported on these with skylake driver. Throughout this document said driver will also be refered to as snd_soc_skl. To see if your device matches the type, navigate to: /sys/devices/pci0000\:00/0000\:00\:1f.3/ and do: cat device. PCI device ids: 0x9d70 or 0x9d71 denote that indeed this doc is what you're looking for.

Requirements

Make sure your kernel is at least v5.4 before continuing. Several problems that had previously existed with skylake were addressed and merged with v5.7-rc1 sound PR. These fixes were then backported to v5.4 LTS kernel. Additional updates were provided later on to address issues troubling DMIC. Older kernels do not come with these fixes applied so HDA+DMIC configuration is unsupported.

For some of the steps it's best if you have your git at the ready. Configuration files may not be present by default on your machine. alsatplg tool, which will be handy for creating topology binaries should be installed by default but you can always follow official alsa-lib and alsa-utils guides to compile these by your own if available version does not suffice.

Limitations

skylake driver supports Realtek and HDMI (Intel) HDA codecs. Other vendors, such as Conexant are not supported.

Advanced users

Feel free to backport mentioned patches to earlier kernels. When doing so, please note commits which initially introduced hda-dsp machine driver came with v4.20. So, going below v4.20 requires extra work.

When compiling kernel yourself, remember to select kernel configuration options listed below. make menuconfig should help you with that.

Device Drivers
  Sound card support
    Advanced Linux Sound Architecture
      HD-Audio
        <M> HD Audio PCI
        <M> Build Realtek HD-audio codec support
        <M> Build HDMI/DisplayPort HD-audio codec support

      ALSA for SoC audio support
        [*] Intel ASoC SST drivers
          <M> Skylake Platforms
          <M> Kabylake Platforms
          [*] HDAudio codec support

        Intel Machine drivers
          <M> SKL/KBL/BXT/APL with HDA Codecs

With these, both skylake driver and skl_hda_dsp_generic machine board driver will be compiled and able to interact with each other during runtime.

Enabling the configuration

First check the device type, if indeed your audio DSP is of SPT-type as mentioned in Audience.

Topology

Topologies are stored in alsa-topology-conf repo and once compiled, should be moved to /lib/firmware/ directory. Their naming also needs to be precise. Default, exact name is complicated so it's recommended that you use a more friendly option. Topology search algorithm present in skl_tplg_init() fetches for topology binary three times before giving up:

  • Exact name: based on OEM and revision ids, plus PCI device id
  • Friendly name: <machine_driver_name>-tplg.bin. For HDA+DMIC configuration that's always: skl_hda_dsp_generic-tplg.bin
  • Fallback, static name: dfw_sst.bin

To manually install topology, clone alsa-topology-conf and navigate to /topology/hda-dsp subdirectory. Then, make use of alsatplg tool:

alsatplg -c skl_hda_dsp_generic-tplg.conf -o skl_hda_dsp_generic-tplg.bin

and move generated output to /lib/firmware/ so it can be consumed by skylake driver later on.

Kernel modules

While two drivers can support audio on our platforms of interest, only one, HDA legacy or HDA DSP driver may be running at a time. These are represented by snd_hda_intel and snd_soc_skl respectively. For HDA+DMIC you need the latter. Selection is performed with help of snd_intel_dspcfg module. See the source for more info regarding selection mechanism, especially the FLAG_XXX macros. Said module exposes dsp_driver parameter which influences driver selecting during runtime. To force skylake driver selection, append:

options snd_intel_dspcfg dsp_driver=2

within any or new file within /etc/modprobe.d/<file> directory. Value of 2 stands for SST - skylake. This needs to be done only once. To see if the selection succeeded, after reboot, navigate to: /sys/module/snd_intel_dspcfg/parameters/ and see the output of: cat dsp_driver.

NHLT overridding

This ACPI table takes part in configuring DMIC portion of our HDA+DMIC setup. Default table should be sufficient for supporting basic audio cases. Unfortunatelly, should is not always. Please, refer to initrd_table_override guide in order to override onboard NHLT with new one. You will also need acpi-overrides scripts. As currently no public tools are available to edit NHLT manually, it's best if you ask intel developers for help to obtain correct NHLT binary. You may also checkout NLHT speficication if you want to try to fix the problems yourself.

UseCaseManagement

Sometimes sound card's behaviour may be dummy or lackluster. Usually this comes from missing or incorrect use-case configuration. This is where UseCaseManagement (ucm) files come into play. These are officially available at alsa-ucm-conf and should be installed under /usr/share/alsa/ucm2. Each separate file or package targets concrete configuration. Here, we're looking for HDA+DMIC one: /ucm2/hda-dsp. Chances are, you already have plenty of these present so adding new or updating existing should be straightforward. Refer to alsaucm manual for additional information.

DSP Firmware (optional)

While proper DSP firmware binaries should already be present, it's worth noting these are located in /lib/firmware/intel/. You should notice pattern in their naming, only suffix gets changed: kbl goes for 0x9d71 devices, while release for 0x9d70 ones. Multiple firmware versions may be present, skylake driver loads only generically-named onces though. These are often symbolic links. If you ever need to update firmware file manually, checkout linux-firmware repo and simply backup and remove existing, generically-named file and create new symbolic link targeting your new file, e.g.:

ln -s dsp_fw_spt_release_vNewVersion.bin dsp_fw_release.bin

Do's when filing a ticket

When everything fails, feel free to send Intel a ticket. When doing so, it's worth remembering couple of important steps. These will help us in fixing your issue quicker so you can enjoy smooth audio experience sooner.

  • Provide dmesg output. dmesg > log.txt suffices. It's appreciated if said log contains early boot information i.e. dumped right after boot. If problem occurs later, you can provide two dmesg(s) instead: one from boot and one from runtime, once the problem presents itself. Please note that the default log level may not be sufficient. To enable debug logs, navigate to /etc/modprobe.d/ and similarly to snd_intel_dspcfg case, append within any or new file:
options snd_hda_core dyndbg==pmf
options snd_hda_codec dyndbg==pmf
options snd_soc_core dyndbg==pmf
options snd_soc_skl dyndbg==pmf

These ensure dmesg will be rich with audio related logs.

  • Attach kconfig, that is kernel config file which your kernel image is based on. These should be available in /boot/ directory. For exact match, check output of uname -r and select file matching: config-<uname -r> pattern.
  • Don't forget to add topology binary for HDA+DMIC configuration If your /lib/firmware/ directory contains it.
  • Dump NHLT table. To do that, do: cat /sys/firmware/acpi/tables/NLHT > ~/nhlt.dat
  • General ALSA information, output of: alsa-info.sh --no-upload
  • List of sound modules loaded: lsmod | grep snd
  • PCI device ID of hda bus: cat /sys/devices/pci0000\:00/0000\:00\:1f.3/device
@crojewsk
Copy link
Author

crojewsk commented May 9, 2023

Hello @paulhart, could you open a new issue for avs-topology-xml. I'd like this gist not to become an issue-tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment