This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TLV320ADC3140: Configuration and Kernel Errors

Part Number: TLV320ADC3140
Other Parts Discussed in Thread: ADC3140EVM-PDK,

Hello everybody, 

I've tried for some time now to use the TLV320ADC3140 with the Raspberry Pi using the Linux Kernel driver. I am using the ADC3140EVM-PDK evaluation module (https://www.ti.com/tool/ADC3140EVM-PDK) wired up to a Raspberry Pi 4. I've read several resources including a post here in the audio forum: https://e2e.ti.com/support/audio-group/audio/f/audio-forum/1044970/tlv320adc5140-device-tree-on-raspberry-pi

The tlv320adcx140 kernel module is compiled on the device and configured via a device tree overlay:

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2837", "brcm,bcm2836", "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&i2s_clk_consumer>;
        __overlay__ {
            status = "okay";
        };
    };
    
    fragment@1 {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            ti_codec: tlv320adc3140@4c {
                compatible = "ti,tlv320adc3140";
                reg = <0x4c>;
                #sound-dai-cells = <0>;
                ti,mic-bias-source = <0>;
                ti,gpi-config = <0 0 0 0>;
                ti,gpio-config = <2 2>;
                ti,gpo-config-1 = <0 0>;
                ti,gpo-config-2 = <0 0>;
                reset-gpios = <&gpio 4 0>;
            };
        };
    };

    fragment@2 {
        target = <&sound>;
        __overlay__ {
            compatible = "simple-audio-card";
            i2s-controller = <&i2s_clk_consumer>;
            status = "okay";

            simple-audio-card,name = "TI";
            simple-audio-card,format = "i2s";
            simple-audio-card,bitclock-master = <&codec_dai>;
            simple-audio-card,frame-master = <&codec_dai>;

            cpu_dai: simple-audio-card,cpu {
                sound-dai = <&i2s_clk_consumer>;
                dai-tdm-slot-num = <2>;
                dai-tdm-slot-width = <32>;
            };

            codec_dai: simple-audio-card,codec {
                sound-dai = <&ti_codec>;
            };
        };
    };
};

When I boot the system the module most of the time seems to be loaded correctly, probing works and the ALSA interface is available. However from time to time, and especially whenever starting recordings, strange things start to happen. On a regular basis I get these errors writing registers via I2C:

[    4.229373] tlv320adcx140-codec 1-004c: ASoC: error at snd_soc_component_update_bits on tlv320adcx140-codec.1-004c for register: [0x00000007] -5
[    4.229600] tlv320adcx140-codec 1-004c: ASoC: error at snd_soc_component_update_bits on tlv320adcx140-codec.1-004c for register: [0x00000013] -5

In the following the kernel oopses and the device cannot be used anymore:

[ 4.229836] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000018
[ 4.229853] Mem abort info:
[ 4.229856] ESR = 0x0000000096000005
[ 4.229861] EC = 0x25: DABT (current EL), IL = 32 bits
[ 4.229866] SET = 0, FnV = 0
[ 4.229871] EA = 0, S1PTW = 0
[ 4.229875] FSC = 0x05: level 1 translation fault
[ 4.229879] Data abort info:
[ 4.229883] ISV = 0, ISS = 0x00000005
[ 4.229887] CM = 0, WnR = 0
[ 4.229891] user pgtable: 4k pages, 39-bit VAs, pgdp=0000000041fcc000
[ 4.229897] [0000000000000018] pgd=0000000000000000, p4d=0000000000000000, pud=0000000000000000
[ 4.229912] Internal error: Oops: 0000000096000005 [#1] PREEMPT SMP
[ 4.229920] Modules linked in: tlv320adcx140(O) binfmt_misc regmap_i2c hci_uart snd_soc_simple_card snd_soc_simple_card_utils brcmfmac btbcm snd_soc_bcm2835_i2s bluetooth rpivid_hevc(C) brcmutil snd_soc_core bcm2835_codec(C) bcm2835_v4l2(C) raspberrypi_hwmon bcm2835_isp(C) bcm2835_mmal_vchiq(C) v4l2_mem2mem videobuf2_dma_contig videobuf2_vmalloc snd_compress videobuf2_memops snd_bcm2835(C) snd_pcm_dmaengine videobuf2_v4l2 snd_pcm videobuf2_common ecdh_generic ecc snd_timer libaes videodev mc snd raspberrypi_gpiomem vc_sm_cma(C) nvmem_rmem uio_pdrv_genirq uio batman_adv bridge stp llc cfg80211 rfkill i2c_dev drm dm_mod drm_panel_orientation_quirks backlight fuse ip_tables x_tables ipv6 i2c_bcm2835
[ 4.230035] CPU: 1 PID: 9 Comm: kworker/u8:0 Tainted: G C O 6.1.0-rpi8-rpi-v8 #1 Debian 1:6.1.73-1+rpt1
[ 4.230045] Hardware name: Raspberry Pi 4 Model B Rev 1.5 (DT)
[ 4.230050] Workqueue: events_unbound deferred_probe_work_func
[ 4.230065] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[ 4.230072] pc : adcx140_pwr_ctrl+0x8c/0xfc [tlv320adcx140]
[ 4.230092] lr : adcx140_pwr_ctrl+0x84/0xfc [tlv320adcx140]
[ 4.230103] sp : ffffffc00806b990
[ 4.230107] x29: ffffffc00806b990 x28: 0000000000000000 x27: ffffff8042b88080
[ 4.230118] x26: ffffffeb4ff34000 x25: 0000000000000001 x24: 0000000000000080
[ 4.230127] x23: ffffff80440d1d80 x22: 0000000000000001 x21: 0000000000000000
[ 4.230136] x20: 00000000000000e0 x19: ffffff80440d1d80 x18: 00000000fffffffd
[ 4.230145] x17: 0000000000000000 x16: ffffffeb793fad10 x15: ffffffc00806b590
[ 4.230154] x14: 0000000000000001 x13: 2930347830202c62 x12: 3778302865746972
[ 4.230163] x11: 775f70616d676572 x10: 0000000000001a30 x9 : ffffffeb78fb37fc
[ 4.230172] x8 : ffffff8040271a90 x7 : 0000000000000000 x6 : 000000000e3ec98d
[ 4.230181] x5 : 0040001000000020 x4 : 0000000000000000 x3 : 00000000fffffffb
[ 4.230190] x2 : 0000000000000000 x1 : ffffff8040270000 x0 : 00000000fffffffb
[ 4.230200] Call trace:
[ 4.230205] adcx140_pwr_ctrl+0x8c/0xfc [tlv320adcx140]
[ 4.230217] adcx140_set_dai_fmt+0x210/0x22c [tlv320adcx140]
[ 4.230228] snd_soc_dai_set_fmt+0x34/0xa0 [snd_soc_core]
[ 4.230311] snd_soc_runtime_set_dai_fmt+0x5c/0x150 [snd_soc_core]
[ 4.230356] snd_soc_bind_card+0x638/0xb80 [snd_soc_core]
[ 4.230399] snd_soc_register_card+0xf8/0x110 [snd_soc_core]
[ 4.230444] devm_snd_soc_register_card+0x54/0xb0 [snd_soc_core]
[ 4.230488] asoc_simple_probe+0x20c/0x3bc [snd_soc_simple_card]
[ 4.230499] platform_probe+0x70/0xcc
[ 4.230508] really_probe+0xc4/0x2e0
[ 4.230514] __driver_probe_device+0x80/0x120
[ 4.230520] driver_probe_device+0xe0/0x164
[ 4.230526] __device_attach_driver+0xc0/0x13c
[ 4.230532] bus_for_each_drv+0x84/0xe0
[ 4.230541] __device_attach+0xa4/0x1a0
[ 4.230546] device_initial_probe+0x1c/0x2c
[ 4.230552] bus_probe_device+0xa4/0xb0
[ 4.230557] deferred_probe_work_func+0x90/0xd0
[ 4.230563] process_one_work+0x200/0x474
[ 4.230572] worker_thread+0x74/0x43c
[ 4.230579] kthread+0x110/0x114
[ 4.230586] ret_from_fork+0x10/0x20
[ 4.230595] Code: 531a6442 9400025a 2a0003e3 34000140 (f9400ea0) 
[ 4.230602] ---[ end trace 0000000000000000 ]---

I am wondering what I'm doing wrong or whether there is some error in the kernel module code or some configuration error. 

It would be great, If someone could help here or share a success story using the chip family and the Raspberry Pi SBC.

Thanks
Jonas

  • Kindly offer me the kernel version. try regmap_update_bits instead of snd_soc_component_update_bits 

  • I'm running the most recent Raspberry Pi version `bookworm`, running this kernel:

    $ uname -a
    Linux workshop-coelbe-jonas 6.1.0-rpi8-rpi-v8 #1 SMP PREEMPT Debian 1:6.1.73-1+rpt1 (2024-01-25) aarch64 GNU/Linux

  • The error remains, even after replacing all calls with regmap_update_bits. I'll now checkout the new implementation. 

  • The first issues I've encountered compiling the module were some kernel version dependencies, which turn out to be different for the Raspberry Pi Kernel, since that is a fork. I've worked around it by altering the if macros (version 6.2.0 to 6.1.0 in this case) at the respective failing locations, e.g.

    #if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE
    		FW_ACTION_UEVENT
    #else
    		FW_ACTION_HOTPLUG
    #endif

    Second issue was the device tree overlay. I've tried to load the one which is provided with the repository (genericstereoaudiocodec.dts), which does not compile. The overlay I came up with looks like this:


    /dts-v1/;
    /plugin/;
    
    / {
        compatible = "brcm,bcm2708";
    
        fragment@0 {
            target = <&sound>;
            __overlay__ {
                compatible = "simple-audio-card";
                simple-audio-card,name = "TI";
                status="okay";
    
                capture_link: simple-audio-card,dai-link@0 {
                    format = "i2s";
    
                    // Set RasPi to I2S slave
                    bitclock-master = <&r_codec_dai>;
                    frame-master = <&r_codec_dai>;
    
                    r_cpu_dai: cpu {
                        sound-dai = <&i2s>;
                        // TDM slot configuration for stereo
                        dai-tdm-slot-num = <2>;
                        dai-tdm-slot-width = <32>;
                    };
    
                    r_codec_dai: codec {
                        sound-dai = <&codec_in>;
                    };
                };
            };
        };
    
        fragment@1 {
            target = <&i2c1>;
            __overlay__ {
                #address-cells = <1>;
                #size-cells = <0>;
                status = "okay";
    
                codec_in: adc3140@4c {
                    compatible = "ti,adc3140";
    				reg = <0x4c>;
                    reset-gpios = <&gpio 4 0>;
    
                    #address-cells = <1>;
                    #size-cells = <0>;
                    #sound-dai-cells = <0>;
                    status = "okay";
    
                };
            };
        };
    
        fragment@2 {
            target = <&i2s>;
            __overlay__ {
                #sound-dai-cells = <0>;
                status = "okay";
            };
        };
    };

    The codec driver seems to be loaded, however there are again error messages in the kernel log when initializing the device:


    [    3.966342] pcmdevice-codec 1-004c: primary-device = 0x4c
    [    3.966384] pcmdevice-codec 1-004c: Looking up irq-gpio property failed -22
    [    3.967219] pcmdevice-codec 1-004c: Direct firmware load for adc3140-1dev-reg.bin failed with error -2
    [    3.968047] pcmdevice-codec 1-004c: Failed to read adc3140-1dev-reg.bin, no side-effect on driver running
    [    3.968070] pcmdevice-codec 1-004c: Firmware init complete

    When trying to record samples, the following kernel messages appear, and recording is not successful:

    [  112.402622] pcmdevice-codec 1-004c: pcmdevice_hw_params: Capture
    [  112.402641] pcmdevice-codec 1-004c: pcmdevice_hw_params: BCLK rate = 2116800 Channel = 2Sample rate = 44100 slot width = 24
    [  112.402947] bcm2835-i2s fe203000.i2s: I2S SYNC error!
    [  112.403125] pcmdevice-codec 1-004c: conf_no should be less than 0

    Any hints from your side?

  • Thank's for the hint. I had no windows at hand, so I've tried using wine, which failed. After that I've installed windows, which also failed:

    tool/regbin_parser.exe -i jsn/adc3140-1dev-reg.json
    File size not match, 8859 2064261152
    main Bin loading requested: 0

    I don't quite understand the error output, what's the deal here?

  • Hi Guy

    regbin_parser.exe is the parsing tool for the bin file.

    You must use the Non_Integrated_Bin_Tool_1.3.7.zip to convert jason file to bin file

  • Ah, I See. Reading the Guideline also helped quite a bit... Sorry. The firmware is now loaded, however it still didn't do the trick. When loading the module, these firmware get's loaded correctly, I assume:

    [    3.700094] pcmdevice-codec 1-004c: primary-device = 0x4c
    [    3.700129] pcmdevice-codec 1-004c: Looking up irq-gpio property failed -22
    [    3.701675] pcmdevice-codec 1-004c: pcmdev: regbin_ready start
    [    3.701693] pcmdevice-codec 1-004c: ndev = 1
    [    3.701697] pcmdevice-codec 1-004c: nconfig = 2
    [    3.701701] pcmdevice-codec 1-004c: img_sz = 540 total_config_sz = 248 offset = 292
    [    3.701820] pcmdevice-codec 1-004c: Firmware init complete

    Still, when trying recordings, it just results in Input/output errors:

    $ arecord -f S24_LE -D "hw:0" -c2 -r 48000                             
    Recording WAVE 'stdin' : Signed 24 bit Little Endian, Rate 48000 Hz, Stereo
    RIFF$?WAVEfmt ??data?arecord: pcm_read:2221: read error: Input/output error

    And this respective kernel messages:

    [ 3277.752317] pcmdevice-codec 1-004c: pcmdevice_hw_params: Capture
    [ 3277.752335] pcmdevice-codec 1-004c: pcmdevice_hw_params: BCLK rate = 2304000 Channel = 2Sample rate = 48000 slot width = 24
    [ 3277.752639] bcm2835-i2s fe203000.i2s: I2S SYNC error!
    [ 3277.752817] pcmdevice-codec 1-004c: select_cfg_blk: profile_conf_id = 0
    [ 3277.752822] pcmdevice-codec 1-004c: select_cfg_blk: conf 0, block type:PRE_POWER_UP	 device idx = 0x00
    [ 3287.806239] pcmdevice-codec 1-004c: select_cfg_blk: profile_conf_id = 0
    [ 3287.806257] pcmdevice-codec 1-004c: select_cfg_blk: conf 0, block type:PRE_SHUTDOWN	 device idx = 0x00

  • Kindly use scope to measure the I2S clk. In your dts, TLV320ADC3140 will be set as a master device, right?

  • I found the json file in the git.ti.com maybe do not match your requirement. Can you list your audio spec wanted to record? such as sample rate, bitwidth, bck clk and MClK. Thanks.

  • In the current DTS ADC314 is set as master device, yes. I've measured using the scope and do not see any clock signal on BCLK or FSYNC. 

    The concrete configuration doesn't matter too much right now, I just want to get the ADC3140EMV-PDK running with the onboard analog microphone as a quick prototype. So if another configuration works out of the box, that would also be fine. 

  • I have transferred your request to our hardware experts. They will support you. If you want to get  ADC3140EMV-PDK, I think you will purchase one from www.ti.com.

  • I have bought the ADC3140EMV-PDK. I'm just using the upper part of the system containing the TLV320ADC3140 and I'm wiring this board to the Raspberry Pi using the test points on the board. I don't think that the hardware is an issue here. 

    Wiring should be straight forward, so I'm also pretty sure there's nothing wrong there, just to make sure:

    • RPi GPIO 2 (SDA) <> ADC3140 SDA
    • RPi GPIO 3 (SCL) <> ADC3140 SCL
    • RPi GPIO 4 <> ADC3140 SHDNz (reset)
    • RPi GPIO 18 (I2S CLK) <> ADC3140 BCLK
    • RPi GPIO 19 (I2S FS) <> ADC3140 FSYNC
    • RPi GPIO 20 (DIN) <> ADC3140 DOUT

    Is there another way I confirm communication with the chip is functional?

  • Hi Jonas,

    Below I've attached a script that sets up the EVM to run in master mode with the onboard mic as the input. You can load this up to the EVM using PPC3 (I2C monitor at the bottom of the screen).

    ADC3140_Master_OnboardMic.cfg

    Make sure that J14,15, and 16 are connected and that your MCLK is connected to GPIO1. I also assumed that the MCLK would be 12.288MHz and the format is standard I2S. Those should be simple enough to change if you want. If you need further help with the EVM let me know.

    Best regards,
    Jeff McPherson