HifiBerry DAC – Linux configuration

To use the HiFiBerry DAC, you need a specific Linux kernel. The kernels from the standard distributions will not work, because the I2S module is not part of the standard kernel yet. There are two ways to get the kernel.

Compile the Linux kernel including PCM5102A support

Note that this guide is based on the special Linux 3.8 kernel. Since 3.10.23, HiFiBerry DAC support is already included in the standard Raspberry Pi kernel sources. You can use the sources, that come with your distribution instead of using the sources from Git as shown below.

The original guide to the compilation of the Linux kernel with I2S support was written on the Noise is good blog. I will only summarize the important steps here. This guide uses an Ubuntu Linux distribution. It is only needed to cross-compile the kernel.

    1. Backup the SD card of the Raspberry Pi. We will replace the kernel of the operating system. If anything goes wrong, the Raspberry Pi will not boot anymore. Therefore it is a good idea, to have a backup. I usually dump the whole SD card on my Mac using dd.
    2. Get the necessary tools and the ARM crosscompiler
      sudo apt-get update
      sudo apt-get install git gcc-arm-linux-gnueabi make ncurses-dev
      cd tools
      git clone git://github.com/raspberrypi/tools.git
      # we don't use the compiler from the tools package, but from the ubuntu package
      CCPREFIX=/usr/bin/arm-linux-gnueabi-
    3. Download the Linux kernel code with enabled I2S support from Github
      cd
      mkdir linux
      cd linux
      git init
      git fetch git://github.com/koalo/linux.git rpi-3.8.y-asocdev:refs/remotes/origin/rpi-3.8.y-asocdev
      git checkout rpi-3.8.y-asocdev

      For the newer 3.10 kernel use the following commands:
      git fetch git://github.com/koalo/linux.git rpi-3.10.y:refs/remotes/origin/rpi-3.10.y
      git checkout rpi-3.10.y
    4. Clean up everything
      cd ~/linux
      make mrproper
    5. Get the Kernel configuration from your Raspberry Pi
      1. Log on to your Raspberry Pi
      2. sudo zcat /proc/config.gz > .config
      3. Copy the .config file to the ~/linux directory on your computer
    6. Enable the DMA module and the SOC codec driver
      1. ARCH=arm CROSS_COMPILE=${CCPREFIX} make oldconfig
        ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig
      2. Device drivers –> Sound card support –> Advanced Linux Sound Architecture –> Alsa for SOC audio support –> Enable PCM5102 driver (or “build all ASoC CODEC drivers”)
      3. Device drivers –> DMA engine support –> BCM2708 DMA Engine support
    7. Compile the kernel and the modules
      ARCH=arm CROSS_COMPILE=${CCPREFIX} make -j6
      mkdir ~/modules
      MODULES_TEMP=~/modules/
      ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make modules_install
    8. Collect all parts and transfer them to the Raspberry Pi
      # package the kernel
      cd ~/tools/mkimage
      ./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage
      # Copy the files
      scp kernel.img pi@ip-of-your-raspberry-pi:
      cd ~/modules
      tar cvfz ../modules.tar.gz ./*
      scp ../modules.tar.gz pi@ip-of-your-raspberry-pi:
    9. Extract the data on your Raspberry Pi
      cd /
      rm -rf lib/modules lib/firmware
      tar xvfz ~pi/modules.tar.gz
      cp ~pi/kernel.img /boot
      sync
      reboot

If everything is correct, the Raspberry Pi should boot as usual.

Configure modules to load

Use the following /etc/modules.conf configuration:

$ more /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
#loop
#snd-bcm2835
snd_soc_bcm2708
snd_soc_bcm2708_i2s
bcm2708_dmaengine
snd_soc_pcm5102a
snd_soc_rpi_pcm5102a

This disables the onboard sound card and enables the HiFiBerry Mini DAC.

Also check the /etc/modprobe.d directory for all *blacklist.conf files. Have a look at all of them if one of the modules configured in /etc/modules.conf is blacklisted. Often the i2c-bcm2708 module is blacklisted. Delete those lines.

Reboot again.

Check if the Linux kernel recognizes the sound card

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndrpipcm5102a [snd_rpi_pcm5102a], device 0: PCM5102A HiFi pcm5102a-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

That’s it, you can now use HifiBerry Mini like any other sound card.

 

17 thoughts on “HifiBerry DAC – Linux configuration

  1. Pingback: HiFiBerry Mini and RaspyFi – the 192kHz/24bit FLAC solution | Crazy Audio

  2. Thomas Kilvaer

    Nice DAC. Currently residing inside a PiHut Wooden Enclosure resulting in a stylish apparence and actually giving reasonable output directly into my AKG702 HeadPhones (Going to build a matching tube dac when time).

    One question. What DAC chips is used?

    Reply
    1. Daniel Post author

      The current version uses the PCM5102B. It is interesting to see, that you can drive your headphones directly. The chip is not designed for this, but it seems to work in your case. As the current is limited by the output filter, you will not get full 2Vrms on your headphones. Using a separate headphone amplifier will most likely improve the sound quality.

      Reply
      1. Thomas Kilvaer

        I will add a small tube-amp in the same style when I get around to build it, but no rush… The sound is suprisingly good… And the AKG 702s are no easy load… I wonder if you could actually drive some horn-loaded high sensitivity speakers with this set-up…. hmmm

        Reply
        1. Daniel Post author

          No, this won’t work. Output resistance of the DAC ist >500 Ohm, this will not work with any speaker, even high-sensitivity speakers.

          Reply
  3. petterware

    Hello,

    If I use hifiberry DAC for stereo, can I still use HDMI 5.1 channel for surround sound? Will they work simultaneously? Or will I have to change the configuration every time?

    Thanks

    Reply
  4. Daniel Post author

    Hi,

    In general Linux can work with multiple audio devices. It depends on the software, if it can output 5.1 on HDMI and 2-channel on the DAC. What software are you using?

    Best regards
    Daniel

    Reply
      1. Daniel Post author

        As far as I know XBMC does not support different sound outputs yet. But I would recommend asking this question in the Raspbmc forum. Maybe a user there has a solution for this.

        Reply
  5. Elliott

    I want to use OpenElec, which currently comes with kernel 3.10.20. Will these instructions allow me to update that kernel too?
    And since OpenElec doesn’t have aplay, is there another way to check if it’s installed properly?

    Reply
    1. Daniel Post author

      OpenElec does not support HiFiBerry yet. The developers got a card from us, we hope this will work in the near future.

      Reply
        1. Daniel Post author

          Yes, Sam already has one. The latest nightly release should support the DAC, but I was not able to test it yet.

          Reply
  6. JMA

    Hi,
    Looking to get a DAC+, but wondering if I can get it to work as follows with openelec :-

    HDMI audio output from XBMC
    DAC+ audio out from squeezeplayer

    I am hoping both apps can be configured to use their own output as it would be a pain to have to manually change this each time, especially as the plan is to control audio from a tablet so dont want to have to turn tv on to change the config.

    My alternative is another pi just for picoreplayer, but this seems needless – any advice appreciated. Thanks.

    Reply

Leave a Reply