We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

[Resolved] Attaching PCM5102 to Omega2 (I2S)

  • @CPU-Hacker PCM5102 does not have I2C interface.

  • @luz Hi Luz,

    It's been a long time that I opened this thread - and also that you were here...

    Based on your guide I tried to mimic what you did to reproduce the issue but I stuck at the very beginning.

    I've compiled an image with the default settings based on the following:


    The image built successfully, and run correctly on Omega2.

    Then I applied patches you shared, but I cannot find sound related menu in the menuconfig (kernel sound support appears, enabled, compiled, but there is no sound / alsa-utils available in the top level menu).

    Actually, I patched OMEGA2.dtsi manually as the whole section:

     &i2s {
    +       #sound-dai-cells = <0>;
            status = "okay";

    was missing.

    Do you have any advice what else should I modify / configure (or what I missed)?




    Finally I've managed to install alsa stuff by uncommenting some lines in feeds.conf.default and running an update, so now I have alsa.
    However, I cannot see any soundcard:

    root@LEDE:/# cat /proc/asound/cards
    --- no soundcards ---
    root@LEDE:/# cat /proc/asound/devices
     33:        : timer
    root@LEDE:/# cat /proc/asound/timers
    G0: system timer : 10000.000us (10000000 ticks)
    root@LEDE:/# cat /proc/asound/version
    Advanced Linux Sound Architecture Driver Version k4.9.34.

    Thus alsactl init does nothing:

    root@LEDE:/# alsactl init
    alsactl: init:1758: No soundcards found...

    The MAX98357A module (snd_soc_max98357a) is loaded:

    i2c_core               20006 15 snd_soc_wm8960,v4l2_common,videodev,i2c_tiny_usb,i2c_mt7621,i2c_gpio,i2c_algo_pcf,i2c_algo_pca,i2c_algo_bit,i2c_mux_pca954x,i2c_mux_pca9541,i2c_mux_gpio,i2c_mux,i2c_dev,regmap_i2c
    input_core             25126  5 uvcvideo,rotary_encoder,gpio_beeper,snd,input_polldev
    regmap_core            32572  6 snd_soc_ralink_i2s,snd_soc_wm8960,snd_soc_core,regmap_spi,regmap_mmio,regmap_i2c,[permanent]
    regmap_i2c              2298  1 snd_soc_wm8960
    regmap_mmio             2020  1 snd_soc_ralink_i2s
    snd                    41166 10 snd_soc_wm8960,snd_soc_core,snd_compress,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_rawmidi,snd_seq_device,snd_hwdep
    snd_compress            7076  0
    snd_hwdep               4382  0
    snd_mixer_oss          12761  1 snd_pcm_oss
    snd_pcm                63733  5 snd_soc_ralink_i2s,snd_soc_wm8960,snd_soc_core,snd_pcm_dmaengine,snd_pcm_oss
    snd_pcm_dmaengine       2907  1 snd_soc_core
    snd_pcm_oss            35793  0
    snd_rawmidi            15370  0
    snd_seq_device          2191  1 snd_rawmidi
    snd_soc_core          100019  5 snd_soc_max98357a,snd_soc_simple_card,snd_soc_simple_card_utils,snd_soc_ralink_i2s,snd_soc_wm8960
    snd_soc_max98357a       1808  0
    snd_soc_ralink_i2s      6320  0
    snd_soc_simple_card     4304  0
    snd_soc_simple_card_utils    2299  1 snd_soc_simple_card
    snd_soc_wm8960         23360  0
    snd_timer              15310  1 snd_pcm
    soundcore               3836  1 snd

    but it does not seem to used by any other module.

  • Hi @sza2-sza2,

    glad I'm not the only one still trying to get this working 😉

    Maybe you can compare your LEDE diffconfig with my diffconfig that you find here at github. This should reveal what things are missing/different.

    The diffconfig ist the delta between a fresh LEDE default configuration and the configuration used to build a particular image. To create your diffconfig:

    ./scripts/diffconfig.sh >"diffconfig-for-my-setup"

    I'm usually building my images from the lede-17.01 branch, my last attempt with alsa soundcard present, but not sound coming out the i2s was built from commit 524ed5088e900821307694180d77038df5a3ea9a. I also apply a few more patches to LEDE than the ones shown above (all patches are collected here), but none of the other ones should be relevant for i2s/sound.

    Hope that helps. It would be nice if we can figure out i2s sound eventually!

  • @luz Hi,

    Here is my diffconfig output. I did not find significant differences compared to yours.

    Additionally, dmesg and lsmod.

    I cannot see any MAX98357A related lines in dmesg and the use count of snd_soc_max98357a module is 0 reported by lsmod.

    I have no clue.

    Do you think you could share a binary image to test?


    Edit: I tried with several kernel configuration (enable / disable stuffs like GPIO / I2C / SPI /whatever - from which I thought that can influence: no success). If I enable "dummy" in sound drivers dummy device appears in /proc/asound/cards and then obviously displayed with alsactl init as well).

  • @sza2-sza2 here's my lsmod snd section:

        snd                    40910 10 snd_soc_wm8960,snd_soc_core,snd_compress,snd_pcm_oss,snd_mixer_oss,snd_pcm,snd_timer,snd_rawmidi,snd_seq_device,snd_hwdep
    snd_compress            6303  0 
    snd_hwdep               4350  0 
    snd_mixer_oss          12761  1 snd_pcm_oss
    snd_pcm                63018  5 snd_soc_ralink_i2s,snd_soc_wm8960,snd_soc_core,snd_pcm_dmaengine,snd_pcm_oss
    snd_pcm_dmaengine       2779  1 snd_soc_core
    snd_pcm_oss            35825  0 
    snd_rawmidi            15402  0 
    snd_seq_device          2191  1 snd_rawmidi
    snd_soc_core           97120  4 snd_soc_simple_card,snd_soc_ralink_i2s,snd_soc_max98357a,snd_soc_wm8960
    snd_soc_max98357a       1776  1 
    snd_soc_ralink_i2s      6064  2 
    snd_soc_simple_card     5216  0 
    snd_soc_wm8960         22720  0 
    snd_timer              15598  1 snd_pcm
    soundcore               3836  1 snd

    The difference to yours seems to be that in my case snd_soc_ralink_i2s has a use count of 2.

    I'd guess that snd_soc_ralink_i2s not being used at all must be something in the device tree, so below are my target/linux/ramips/dts/mt7628an.dtsi and target/linux/ramips/dts/OMEGA2.dtsi files. I would have preferred to upload them here, but board software says I am not allowed to upload?! Pastebin, then.

  • @luz Hi,

    Thanks to your help it works now correctly, aplay plays the wav files.

    I played a 2ch / 16bit / 44.1Hz wav (1kHz, 0dB).

    The output on the I2S lines:

    The waveform on the output of the DAC:

    So, now we have to figure out why yours is crashing.


  • @sza2-sza2 Wow! Terrific news!!

    Thanks a lot for the nice diagrams (Saleae Logic is great 😉

    Did you apply all of my patches, in particular, did you apply 942-omega2-dma-bughunt-WIP?

    Because since that patch, I can use aplay without crash, and I even see the WS clock running during the time a sound plays, but there is zero output on the data line. So I thought that something is wrong in the DMA setup, such that no data reaches the i2s engine. But if it works in your case, it can't be a fundamental DMA problem. Maybe something as mundane as a short on my PCB… (I'll re-check that, although needs some time to disassemble the pixelboard)

    BTW: what is the SHA of the LEDE (git rev-parse HEAD) you've been using?

  • @luz Hi,

    Actually, I did not apply all the patches. I modified some files manually as the patching was failed (probably the delta was to big to successfully apply - I did not spend so much time to figure out why).

    I cloned the repo first last week commit 78057457912170ceba29792ef02ba441abe8f246 and I did a lot of tinkering, I don't remember the several config changes I made.

    So yesterday I cloned again (cb2a3911e15df3be15126fc17fabe6f3671eee7b) to have a fresh copy and I did the following:

    1. added MAX98357A related stuff to target/linux/ramips/modules.mk (based on your patch)
    2. added target/linux/ramips/patches-4.4/0722-asoc-enable-max98357a-kconfig.patch
      (well, I'm not a kernel guru, so I don't understand why it is necessary to replace tristate with tristate "Maxim MAX98357A CODEC" in Kconfig but the compilation stopped with errors if I did not apply this)
    3. added lines to OMEGA2.dtsi based on your patches (my current OMEGA2.dtsi) - modifications in mt7628an.dtsi was not necessary

    The result of the above was a kernel which supports MAX98357A (thus PCM5102 too).

    Hope this helps.


    PS: I like Saleae - however I ran into trouble due to its limitation that no continuous sampling to disk, but the maximum is the free RAM size. Although the support was good, they offer a full refund of price of the two Logic Pro 16 - well, we chose not to send back but use for other tasks 🙂

  • @sza2-sza2 it works now!! 😄

    Thanks a lot for the detailed steps!

    I was using lede-17.01 before, which is still on kernel 4.4 and had the problem with DMA that made it either crash or (with my attempt to fix it with 942-omega2-dma-bughunt-WIP) not transfer data to the output.

    Apparently, some work and bugfixes for the mt76xx SoCs got upstreamed into Linux mainline between 4.4 and 4.9. At least, the DMA related LEDE patch target/linux/generic/patches-4.4/132-mips_inline_dma_ops.patch that contains the code which was causing the crash, has disappeared in LEDE master.

    Anyway - i2s sound output with max98357a works now, with less patching than before! Great!

    But no advance without new problems - with kernel 4.9 the PWM support (/sys/class/pwm/)… does not work any more, because it tries and fails to claim gpio18 for some unknown reason, which is already claimed by something else, for another unknown reason 😉

  • @luz Hi,

    Glad to hear that I2S works - bad, that something else broken 😞 Currently, I don't plan to use any PWM stuff - but as a newbie I still struggling even with simple GPIOs (it works with official v0.1.9-b159 - so I'm almost sure it is a kernel configuration difference or some user space mistake I made).


  • Hi @luz & @sza2-sza2 have you already tested the quality of sound through i2s on Omega? How is it? Is it worth the fort of compiling custom fw, or it is better to use simple USB-SoundCards?
    Can someone of you please share fw image with working i2s for omega2 or omega2p?

  • @Xplatforms I haven't really tested it, because in my application it's for game sounds (more beeping than music) and connected to a very tiny loudspeaker of limited quality.

    But I see no reason why the sound should be inferior to USB soundcards. i2s as such is lossless, it only depends on the output chip and its specs. I am using the MAX98357A, a really tiny (3x3mm housing) class D mono amplifier chip designed for phone and tablet speakers, and I'd say my setup sounds like a phone.

    On the contrary, USB sound is much more complicated and probably also needs more CPU time from the Omega2.

  • @luz I'm asking because of that comment from onion admins: 0_1502276838089_omega.png
    in this topic: https://community.onion.io/topic/287/solved-i2s-pins-on-omega/5

    Can you share your image for test purpose please?

  • @Xplatforms said in [Resolved] Attaching PCM5102 to Omega2 (I2S):

    @luz I'm asking because of that comment from onion admins: 0_1502276838089_omega.png
    in this topic: https://community.onion.io/topic/287/solved-i2s-pins-on-omega/5

    I see. No idea why Boken came to that conclusion - but then, that was two years ago with the Omega1/AR9331. Could well be that ASoC (ALSA for SoCs) wasn't ready back then. After all, ASoC for the MT7688 started working apparently only with a kernel newer than 4.4.

    Can you share your image for test purpose please?

    The image is highly customized for the application (the "pixelboard" - tetris/game-of-life lounge table)), so it might be a bit difficult to use, but here's the image where aplay works via MAX98357A. You might need to enter "failsafe" mode and edit out the "*" in /etc/shadow for the root user to be able to login.

  • @Xplatforms Hi,

    First of all, I not an audiophile guy. Although my experience with the DAC mentioned in the topic title is pretty good - at least to my ears. You can also take a look at the sine wave I captured, there's no distortion, no noticeable noise on it, that's a quite good waveform.

    I've tested the channels by a 20W class-D amplifier (TPA3100 based), and it was good too. Obviously, the analog part is sensitive to the digital noise generated by the Omega2.

    Regarding the USB sound cards, there are huge differences between specific models. Years ago, I bought one for ~2USD but its sound is terrible (I've tested it with the same Omega2 HW a few month ago - that's why I decided to find some way to use the I2S DAC).

    On the other hand, I heard the sound of a so called Hi-Fi USB sound card and that was rather like my I2S HW (I cannot decide whether it was better or worse, but about the same quality).

    I cannot say anything about the resource side, I assume @luz is right.


  • @luz , @sza2-sza2 thank you very much for your answers and sharing image! I'll try it today

  • @luz I think the gpio18 is used for the max98357a at the dts file,

    sdmode-gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;

    you can remove that pin config, and try.

  • JFYI: I2S support has landed in official Omega2 FW: https://community.onion.io/post/16473

  • I rechecked all the parameters of the i2s signal from omega2 and found the problem. i2s signal from omega 2 leaves really 16 bits per channel, but by default the data type is unsigned (u16). In the standard, I2S signal must be signed, and because of this, I have distortions with overload for TDA1543. At tests with MAX98357 these problems did not arise (probably) because it understands 16 24 and 32 bits, because of what the bit of the sign is shifted. When I try to reproduce the sign type of the signal (for example "mpg123 -e s16 test.mp3"), omega 2 is restarting.

  • @Andrew-Naumenko and others
    I also get 99% distorded audio with my quality i2s dac that should get proper I2S (i2s = philips format with data 1 bitclock delayed left justified ) to play correctly . You probably found the culprit with the unsigned (u16) subject (corrected by the maxim ic) ? Hope people can help us get normal i2s (philips I2S) (for the most of users) stock driver config in the coming days/weeks. personnaly I do not want to get that maxim MX integratedampchip (when there are many more interesting i2s dacs and amps available everywhere) to fix when I already have better here. thanks for the future helpers

Log in to reply

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