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

I2S ADC Headaches



  • Just when I thought I've got this I2S thing all figured out I've hit a deadend with trying to integrate an ADC to record some audio.

    I have managed to configure I2S to play audio through a PCM5102 device link this cheapy from banggood PCM5102a.

    I now need to record and since I had the PCM5102 as a DAC I decided why not look at what else Texes Instruments has to offer in terms of its counterpart the ADC. Sure enough I came across a ADC part number PCM1860 and its all been downhill from there.

    Ive got the PCM1860 connected to the Omega I2S's CLK, WS and SDI pins. however I am struggling to get the device recognised. This is most likely due to incorrect Device Tree configuration as I could not find a device tree binding for this specific ADC, closest was PCM186x, however this seem to be for the PCM1862+ which have I2C control pins whereas the PCM1860 is HW controlled through pullup/downs etc.

    In the hope that someone might point me in the correct direction these are the dtsi configurations I have tried, but none expose the ADC in arecord -l.

    This DTSI allows the DAC only to function
    https://pastebin.com/z9H67DHd

    These are my attempts at including the DAC with the ADC:
    https://pastebin.com/RLsKNsiR
    https://pastebin.com/rmJVcCz1

    Do share if anyone has managed to do any I2S audio capture.
    Thanks,
    UFD



  • If it helps anyone, I think I made some headway here.

    After much messing around and multiple builds later I started getting a basic understanding of codecs (i.e. devices that support sound playback and/or capture), alsa and linux kernels.

    codecs are built as part of the kernel build process. codec IC's are apparently made by multiple manufactures and although most comply with standard protocols like I2S or PCM (for audio data transfer) they each have differences in how they are controlled. like one chip might have 4 ADC sound inputs, or offer sound level control functionality. These control commands are not supported by the I2S protocol and are rather implemented using I2C(mostly) or SPI or general gpio 1/0. With I2C etc each chip will have different registers to set and configure its functionality. This is why you need a codec for your specific chip. Codecs supported by linux are listed here codec documents.

    Here are some of the gotchas i faced:

    1. Codecs are continually added to linux kernel source. openwrt(what onion runs) is still on version 4.14 of the kernel whereas some codecs were added later. I found it was not as simple as patching in the missing files as there were lower level dependancies.

    2. Device tree configuration is not as trivial as I imagined, especially if you are new and are trying to implement something not very common.

    3. I did not succeed in finding a way to enable debugging logs of sort to aid with the codec loading issues. My approach was: change something, rebuild, test, repeat x100

    However for "simple" I2S devices with no control protocol, like the PCM5102a, MAX98367A or PCM1860 you might get away with two generic codecs supported by the kernel i.e. spdif-receiver and spdif-transmitter, which to my knowledge are generic devices with limited capabilities.

    Using these generic codecs I have managed to create a build that supports both playback and capture. I2S_Audio_Image based on latest code 0.3.2 b233.

    The Device Tree modifications include:

        sound {
                compatible = "simple-audio-card";
                simple-audio-card,name = "Audio-I2S";
                simple-audio-card,format = "i2s";
                simple-audio-card,widgets =
                        "Speaker", "External Speaker",
                        "Microphone", "Microphone Jack";
    
                simple-audio-card,dai-link@0{
                    format = "i2s";
                    cpu {
                        sound-dai = <&i2s>;
                    };
                    codec {
                        sound-dai = <&codec_out>;
                   };
               };
    
               simple-audio-card,dai-link@1{
                   format = "i2s";
                   cpu {
                       sound-dai = <&i2s>;
                   };
                   codec {
                       sound-dai = <&codec_in>;
                   };
               };
    
        };
    
        codec_out: txcodec {
            #sound-dai-cells = <0>;
            #address-cells = <0>;
            #size-cells = <0>;
            compatible = "linux,spdif-dit";
            status = "okay";
        };
    
        codec_in: rxcodec {
            #sound-dai-cells = <0>;
            compatible = "linux,spdif-dir";
        };
    

    Regards,
    UFD



  • I am very, very interested in getting this i2s module to work with Omega.
    Do you have a connection guide?



  • Hi, @UFD, can you share your build config? I failed to replicate your build. After hours of trying I was able to replicate your device tree (with help of this topic), but I still got 0 soundcards. I suspect its the lack of snd_soc_spdif_tx/rx modules to blame, but I cant figure out how to add them.



  • @zazu-z You already quoted the thread where I described my i2s adventures from a few years back now. I struggled a long time to get the extra codec I wanted to build, but in the end it was a few lines added to target/linux/ramips/modules.mk.

    Maybe looking at my original patch here, which adds the max98357A codec, might help to do the same for any of the other codecs available (visible in build_dir/target-mipsel_24kc_musl/linux-ramips_mt76x8/linux-4.14.151/sound/soc/codecs).



  • Hey @zazu-z , indeed @luz is correct.

    You will need to add the config to target/linux/ramips/modules.mk

    At the end of the file my changes are as follows:

    define KernelPackage/sound-mt7620
      TITLE:=MT7620 PCM/I2S Alsa Driver
      DEPENDS:=@TARGET_ramips +kmod-sound-soc-core +kmod-regmap +kmod-dma-ralink @!TARGET_ramips_rt288x
      KCONFIG:= \
        CONFIG_SND_RALINK_SOC_I2S \
        CONFIG_SND_SIMPLE_CARD \
        CONFIG_SND_SIMPLE_CARD_UTILS \
        CONFIG_SND_SOC_SPDIF
      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/generic/snd-soc-simple-card-utils.ko \
        $(LINUX_DIR)/sound/soc/codecs/snd-soc-spdif-rx.ko \
        $(LINUX_DIR)/sound/soc/codecs/snd-soc-spdif-tx.ko
      AUTOLOAD:=$(call AutoLoad,90,snd-soc-spdif-rx snd-soc-spdif-tx snd-soc-ralink-i2s snd-soc-simple-card)
      $(call AddDepends/sound)
    endef
    
    define KernelPackage/sound-mt7620/description
     Alsa modules for ralink i2s controller.
    endef
    

    If I recall correctly the above can also more correctly be achieved by doing a:

    make kernel_menuconfig
    

    And enabling the SPDIF module in:

    Device Drivers -> Sound card support -> Advanced Linux Sound Architecture -> ALSA for SoC audio support -> CODEC drivers
    

    Hope that helps.
    Regards,
    UFD



  • @luz, @UFD guys, you are awesome. I wasted about week to get it work and you told me an answer withing few hours. I can confirm working i2s virtual card. I still can't get sound from mic, but this is hardware problem as I understand.



  • @zazu-z , Its only because I've spend the last 6 months trying to figure it out. I've also found value in the forum and therefore Im always happy to give back.
    The solution is not perfect and I am actually experiencing alsa overrun issues when recording. In my books it's still a challenge that needs a fully understood solution.



  • @UFD
    What are you recording onto? bigger also buffer or making the process run as a higher priority can help.

    I tried your build as I have also spent ages trying to get i2s audio out
    and it does work well with my 1502 board( own design) - thanks.

    I never got any official reply on whether i2s audio I/o would be part if the 'factory' builds... šŸ˜ž There is project in the docs that says i2s audio is included and shows
    a setup , but its out of date and doesn't work.

    I'm looking at manufacturing a combined pcm1502a + pcm186x board
    and currently considering the omega2+ as the host processor.



  • @Denis-Mikhalsky

    For playback into a pcm1502a board the wiring here will work:
    https://onion.io/2bt-omega-i2s-audio/
    You can ignore the setup stuff, just use UFDs build and it works.



  • @luz said in I2S ADC Headaches:

    max98357A

    Hi @luz I was trying to make max98357A work and have find your post and patches but it doens't work, please let me now your thoughts about the process I've followed..

    Basically I've downloaded a clean onion distro and download 210-omega2-sound-max98357a.diff. After configure onion-minimal-build.sh I've apply your patch. "make" works but alsa shows now audio cards.

    I'm afraid that I've to insert max98357A module after board boots.. but not sure. It would be nice to know your opinion.



  • @sergiosmail do you get anything when doing the following?

    root@pixelboard:~# cat /proc/asound/cards
    0 [AudioI2S       ]: Audio-I2S - Audio-I2S
                          Audio-I2S
    

    If not, please check that you have enabled the kernel package sound-mt7620 in menuconfig.

    The 210-omega2-sound-max98357a.diff patch makes sure that the snd_soc_max98357a module should get automatically loaded at startup. You can check in /etc/modules.d:

    root@pixelboard:~# ls -la /etc/modules.d/*sound*
    -rw-r--r--    1 root     root           126 Jan 30  2019 /etc/modules.d/30-sound-core
    -rw-r--r--    1 root     root            13 Jan 30  2019 /etc/modules.d/55-sound-soc-core
    -rw-r--r--    1 root     root            72 Jan 30  2019 /etc/modules.d/90-sound-mt7620
    
    root@pixelboard:~# cat /etc/modules.d/90-sound-mt7620
    snd-soc-wm8960
    snd-soc-max98357a
    snd-soc-ralink-i2s
    snd-soc-simple-card
    

    Finally, before you can play sounds:

    root@pixelboard:~# alsactl init
    Found hardware: "Audio-I2S" "" "" "" ""
    Hardware is initialized using a generic method
    

    From here on aplay and other sound tools should work

    aplay /path/to/sound.wav
    

    If you want more control, such as a mixer with two separate volumes for background music and game sounds, look at pixelboard's asound.conf

    Also, playing mod files is fun (need very littel disk space, lots of tunes can be found online), possible with the hxcmodplayer package



  • @luz I've repeat all the mentioned steps and it works now... I can't belive šŸ˜„

    My fault was that I wasn't applying 210-omega2-sound-max98357a.diff correctly. The patch fails for 0.3.2 b238, and I wasn't applying it correctly (doing changes manually)

    I've tested using mpg123 mp3 player and aplay commands. Works fine.

    Also thank you for the tip about mixer and hxcmodplayer


Log in to reply
 

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