Attaching PCM5102 to Omega2 (I2S)



  • Hi,

    I'd like to connect my PCM5102 I2C DAC board (technically it's a "Hifiberry-DAC") to Omega2.

    I saw articles about other I2S peripheral (WM8960 based) but those seems overkill for my purpose (and additionally my PCM5102 based board is already built), it has a plenty of features accessible / control through I2C interface which is not necessary for me.

    So, my question, is it possible to interface my PCM5102 based device to Omega2 (mainly firmware point of view, the hardware seems pretty straightforward since the I2S line are wired out on the Omega2 board)?

    If possible, how? Which kernel modules do I need / is there anything I have to set to get sound on the output?

    Thanks,

    /sza2



  • @sza2-sza2

    Can you provide links to articles on Omega and WM8960.



  • OK, it's not Omega2 + WM8960.

    Actually it's LinkIt Smart + WM8960:

    https://docs.labs.mediatek.com/resource/linkit-smart-7688/en/tutorials/audio-playback-and-recording

    However both designs based on MT7688. Additionally, as far as I see, the firmware of Omega2 contains WM8960 kernel driver by default.

    Probably I just mix these two stuffs.

    /sza2



  • @sza2-sza2

    Thanks.



  • Hi,

    No one has any info on this?

    /sza2



  • I have not yet received my Omega2, but I will try the same. By theory, you need to get kernel drivers for the hifiberry running and also you need to connect the i2c lines.



  • I'm trying a similar thing (connecting a MAX98357A i2s audio amp), so I'd be interested in hearing about any experience with i2s from others.

    I'm currently trying to test the hardware setup with the very simple dma-to-i2s kernel driver vocore-gdma which just uses MT7688's GDMA to shove out 2M of raw sound data to i2s. Right now, something is not working yet, I can only produce a small hissing noise :-(



  • I spent the weekend trying to get this (Omega2 + MAX98357A connected via i2s) working. Not yet successful, but here's the status:

    Most of the time I spent trying to understand ALSA (Advanced Linux Sound Architecture), ASoC (ALSA for SoCs), and what components and device tree entries are needed for finally putting a "sound card" together that can be used with the alsactl and aplay utilities.

    Now I have such a setup, but unfortunately, trying to play a sound file with aplay immediately crashes the Omega2 :-(

    In order to get the simple MAX98357A codec (similar to PCM5102 in that its a pure output device, with no i2c configuration) built, I had to do three things in LEDE (patches see below):

    • patch the makefile that configures the build for sound-mt7620 to include the snd-soc-max98357a codec
    • add a kernel patch that actually enables building soc-max98357a at all
    • extend the Omega2 device tree to include sound

    Then, in make menuconfig in Kernel modules -> Sound support I enabled kmod-sound-mt7620 and in Sound I selected alsa-utils

    With this, I get a LEDE build where I can see that I have a "sound card" with cat /proc/asound/cards, and successfully (no error, no crash) initialize alsa with alsactl init.

    But as soon as I try to aplay /tmp/mysoundfile, the Omega2 crashes apparently while memmapping something :-(

    Any ideas welcome…

    BTW: The pcm5102 will probably work with the soc-max98357a driver as well. The only difference I see is that the MAX chip has a input (SDMODE) to switch off the amplifier when not in use, via a GPIO. I set gpio 18 for that (via the sdmode-gpios line in the .dts), but it can be omitted.

    Crash:

    [  322.634556] Kernel bug detected[#1]:
    [  322.638208] CPU: 0 PID: 1123 Comm: aplay Tainted: G        W       4.4.61 #0
    [  322.645359] task: 83920000 ti: 83bba000 task.ti: 83bba000
    [  322.650828] $ 0   : 00000000 00000001 00000002 00000002
    [  322.656147] $ 4   : 8310f400 82d89948 82d89948 00004000
    [  322.661457] $ 8   : 00000018 80008c58 77c07000 00004000
    [  322.666770] $12   : 00001000 00006000 fffffffc 00004000
    [  322.672081] $16   : 8310f400 00000008 82d8c500 82c10600
    [  322.677389] $20   : 77c00000 77c04000 00000000 00000004
    [  322.682699] $24   : 00001072 77b74e00                  
    [  322.688011] $28   : 83bba000 83bbbdf8 00000000 83092250
    [  322.693321] Hi    : 00000000
    [  322.696238] Lo    : 00000004
    [  322.699223] epc   : 83092160 snd_pcm_lib_default_mmap+0x30/0x48 [snd_pcm]
    [  322.706121] ra    : 83092250 snd_pcm_mmap_data+0xd8/0xe60 [snd_pcm]
    [  322.712470] Status: 1100e403	KERNEL EXL IE 
    [  322.716723] Cause : 10800024 (ExcCode 09)
    [  322.720787] PrId  : 00019655 (MIPS 24KEc)
    [  322.724847] Modules linked in: i2c_gpio_custom p44_ledchain pppoe ppp_async iptable_nat pppox ppp_generic pl2303 nf_nat_ipv4 nf_conntrack_ipv6 nf_conntrack_ipv4 ipt_REJECT ipt_MASQUERADE ftdi_sio cp210x xt_time xt_tcpudp xt_state xt_nat xt_multiport xt_mark xt_mac xt_limit xt_conntrack xt_comment xt_TCPMSS xt_REDIRECT xt_LOG usbserial spidev spi_gpio spi_bitbang slhc nf_reject_ipv4 nf_nat_redirect nf_nat_masquerade_ipv4 nf_nat nf_log_ipv4 nf_defrag_ipv6 nf_defrag_ipv4 nf_conntrack_rtcache nf_conntrack iptable_mangle iptable_filter ip_tables crc_ccitt snd_soc_simple_card snd_soc_ralink_i2s snd_soc_max98357a snd_soc_wm8960 i2c_mt7621 i2c_gpio snd_soc_core i2c_algo_bit ralink_gdma virt_dma mt76x2e mt7603e i2c_dev mt76 mac80211 cfg80211 compat ledtrig_oneshot ip6t_REJECT nf_reject_ipv6 nf_log_ipv6 nf_log_common ip6table_mangle ip6table_filter ip6_tables x_tables snd_pcm_dmaengine snd_compress snd_pcm_oss snd_mixer_oss snd_pcm snd_timer snd_rawmidi snd_seq_device snd_hwdep snd input_core soundcore regmap_spi regmap_mmio regmap_i2c i2c_core regmap_core lzo_decompress lzo_compress leds_gpio ohci_platform ohci_hcd ledtrig_transient ehci_platform ehci_hcd gpio_button_hotplug usbcore nls_base usb_common
    [  322.832567] Process aplay (pid: 1123, threadinfo=83bba000, task=83920000, tls=77c11d48)
    [  322.840675] Stack : 77c00000 77c04000 00000000 00000000 82d89948 80098938 00000000 00004000
    	  82d8c500 00004000 000000fb 00000000 82d8c500 00000000 00000000 00000010
    	  00000020 803e0000 00000001 82d89478 82d8948c 82d89488 77c00000 000000fb
    	  82d8c500 00004000 00000001 00000002 00000000 00000004 82c10600 80098f38
    	  77c09e24 00000000 83920000 83920030 00000000 832d9020 82c10634 82d8c500
    	  ...
    [  322.876798] Call Trace:
    [  322.879297] [<83092160>] snd_pcm_lib_default_mmap+0x30/0x48 [snd_pcm]
    [  322.885863] [<83092250>] snd_pcm_mmap_data+0xd8/0xe60 [snd_pcm]
    [  322.891903] [<80098938>] mmap_region+0x29c/0x544
    [  322.896589] [<80098f38>] do_mmap+0x358/0x3d4
    [  322.900943] [<8008a558>] vm_mmap_pgoff+0x70/0xb8
    [  322.905631] [<8009744c>] SyS_mmap_pgoff+0x8c/0xd8
    [  322.910413] [<8000682c>] syscall_common+0x30/0x54
    [  322.915178] 
    [  322.916685] 
    Code: 24020002  14620002  00000000 <000c000d> 3c02830a  2442ce08  aca20048  03e00008  00001021 
    [  322.926894] ---[ end trace 23ba50ddf57c2faa ]---
    [  322.934722] Fatal exception: panic in 5 seconds
    [  327.941901] Kernel panic - not syncing: Fatal exception
    [  327.949339] Rebooting in 3 seconds..
    

    Patch for the makefile:

    --- a/target/linux/ramips/modules.mk
    +++ b/target/linux/ramips/modules.mk
    @@ -120,12 +120,14 @@ define KernelPackage/sound-mt7620
       KCONFIG:= \
            CONFIG_SND_RALINK_SOC_I2S \
            CONFIG_SND_SIMPLE_CARD \
    -       CONFIG_SND_SOC_WM8960
    +       CONFIG_SND_SOC_WM8960 \
    +       CONFIG_SND_SOC_MAX98357A
       FILES:= \
            $(LINUX_DIR)/sound/soc/ralink/snd-soc-ralink-i2s.ko \
            $(LINUX_DIR)/sound/soc/generic/snd-soc-simple-card.ko \
    -       $(LINUX_DIR)/sound/soc/codecs/snd-soc-wm8960.ko
    -  AUTOLOAD:=$(call AutoLoad,90,snd-soc-wm8960 snd-soc-ralink-i2s snd-soc-simple-card)
    +       $(LINUX_DIR)/sound/soc/codecs/snd-soc-wm8960.ko \
    +       $(LINUX_DIR)/sound/soc/codecs/snd-soc-max98357a.ko
    +  AUTOLOAD:=$(call AutoLoad,90,snd-soc-wm8960 snd-soc-max98357a snd-soc-ralink-i2s snd-soc-simple-card)
       $(call AddDepends/sound)
     endef
    

    Patch for the kernel config

    --- /dev/null
    +++ b/target/linux/ramips/patches-4.4/0722-asoc-enable-max98357a-kconfig.patch
    @@ -0,0 +1,11 @@
    +--- a/sound/soc/codecs/Kconfig
    ++++ b/sound/soc/codecs/Kconfig
    +@@ -487,7 +487,7 @@
    +        tristate
    +
    + config SND_SOC_MAX98357A
    +-       tristate
    ++  tristate "Maxim MAX98357A CODEC"
    +
    + config SND_SOC_MAX98925
    +        tristate
    

    Patch for the OMEGA2.dtsi device tree source

    --- a/target/linux/ramips/dts/OMEGA2.dtsi
    +++ b/target/linux/ramips/dts/OMEGA2.dtsi
    @@ -30,6 +30,31 @@
                            linux,code = <KEY_RESTART>;
                    };
            };
    +
    +       sound {
    +               compatible = "simple-audio-card";
    +               simple-audio-card,name = "Audio-I2S";
    +               simple-audio-card,format = "i2s";
    +               simple-audio-card,bitclock-master = <&cpu_dai_master>;
    +               simple-audio-card,frame-master = <&cpu_dai_master>;
    +               simple-audio-card,widgets =
    +                       "Speaker", "External Speaker";
    +
    +               cpu_dai_master: simple-audio-card,cpu {
    +                       sound-dai = <&i2s>;
    +               };
    +
    +               dailink0_master: simple-audio-card,codec {
    +                       sound-dai = <&codec>;
    +               };
    +       };
    +
    +  codec: max98357a {
    +               #sound-dai-cells = <0>;
    +    compatible = "maxim,max98357a";
    +    sdmode-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
    +  };
    +
     };
     
     &pinctrl {
    @@ -51,7 +76,7 @@
     
                    i2s {
                            ralink,group = "i2s";
    -                       ralink,function = "gpio";
    +                       ralink,function = "i2s";
                    };
     
                    spis {
    @@ -170,5 +195,6 @@
     };
     
     &i2s {
    +       #sound-dai-cells = <0>;
            status = "okay";
     };
    

Log in to reply
 

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.