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.

SK-AM62: How to enable the auto gain control on the TLV320AIC3106 Audio Codec

Part Number: SK-AM62
Other Parts Discussed in Thread: TLV320AIC3106, TLV320AIC3110, TLV320AIC3111, AM625

Hello, I am using SK-AM62 eval board and this comes with an Audio codec TLV320AIC3106 and from the datasheet of the codec, this has a build-in AGC for microphone and we would like to enable this and configure. But looking at the driver for the codec there isn't any access to the AGC configuration. Is there any way to control this? and do you have any example of configuring this via the I2C control interface on the codec from SoC?

Thanks 

  • Hi Mitesh,

    Did you look at the codec: sound/soc/codecs/tlv320aic3x.c

    I do see these 

    /*
    * Note: enable Automatic input Gain Controller with care. It can
    * adjust PGA to max value when ADC is on and will never go back.
    */
    SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
    SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum),
    SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum),
    SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum),
    SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum),
    SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum),
    SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum),

    Also please refer to this below document, that might be useful: 

    https://www.ti.com/lit/an/slaa446/slaa446.pdf

    I can route your query to the Audio codecs team, if these don't help you proceed.

    Best Regards,

    Suren

  • Thanks Suren!

    I can see that in tlv320aic3x.c but NOT in tlv320aic31xx.c

    I have two board and respective audio codecs TLV320AIC3106 and TLV320AIC3110 hence I was using tlv320aic31xx.c and NOT tlv320aic3x.c

    Which driver would you recommend to use for TLV320AIC3110  please?

    Thanks 

  • Hi Suren, this is what I am not understanding. In the SDK by default both drivers "TLV320AIC3x" & "TLV320AIC31xx" are enabled in Linux then which will be picked? for TLV320AIC3111 audio codec please? 

  • Hi Mitesh,

    If you refer in kernel code the Documentation/devicetree/bindings/sound/tlv320aic3x.yaml - You would see the compatible devices are TLV320AIC3x (Codec Driver) and for TLV320AIC3111 refer to Documentation/devicetree/bindings/sound/tlv320aic31xx.txt

    You would be able to differentiate from these strings which driver is going to be used.

    Hope this helps.

    Best Regards,

    Suren

  • Hi Suren, according to the documentations then I should use TLV320AIC31xx driver but then I don't have access to AGC?! 

  • Hi Suren, can you please confirm what should be codec settings for the TLV320AIC3111 thanks 

    codec_audio: sound {
    compatible = "simple-audio-card";
    simple-audio-card,name = "AM62x-SKEVM";
    simple-audio-card,widgets =
    "Headphone", "Headphone Jack",
    "Microphone", "Microphone Jack",
    "Speaker", "Speaker";
    simple-audio-card,routing =
    "MIC1LP", "Microphone Jack",
    "MIC1RP", "Microphone Jack",
    "MIC1LM", "MICBIAS",
    "Headphone Jack", "HPL",
    "Headphone Jack", "HPR",
    "Speaker", "SPL",
    "Speaker", "SPR";
    simple-audio-card,format = "dsp_b";
    simple-audio-card,bitclock-master = <&sound_master>;
    simple-audio-card,frame-master = <&sound_master>;
    simple-audio-card,bitclock-inversion;

    simple-audio-card,cpu {
    sound-dai = <&mcasp1>;
    };

    sound_master: simple-audio-card,codec {
    sound-dai = <&tlv320aic3111>;
    clocks = <&tlv320_mclk>;
    };
    };

  • Hi, Hiran

    In order to support you well, I want to know the kernel version? Which chip would you use aic3106, aic3110 or both?

    According to the yaml file, aic3106 uses TLV320AIC3x.c aic3110 uses tlv320aic31xx.c.

    Can you share the i2c setting for the code in dts file?

    Here is the link for codec setting in dts.

    TLV320AIC3120EVM-U: codec clock error at linux boot time - Audio forum - Audio - TI E2E support forums

    As to the AGC control, we can a kcontrol in the code, after confirming which chip you use?

    Looking forward to your feedback. Thanks.

    Good luck

    Shenghao Ding

  • Hi Shenghao, thanks for your message. 

    We would like to use AIC3110 and yes we came to the same conclusion about the aic31xx.c drivers to be correct for the said codec. 

    The kernel details are as follows : 

    Linux am62xx-evm 5.10.168-g2c23e6c538 #1 SMP PREEMPT Fri Jun 2 09:04:44 PDT 2023 aarch64 aarch64 aarch64 GNU/Linux

    I2C DTS:

    &main_i2c1 {
    pinctrl-names = "default";
    pinctrl-0 = <&main_i2c1_pins_default>;
    clock-frequency = <100000>;

    tlv320aic3111: audio-codec@18 {
    #sound-dai-cells = <0>;
    compatible = "ti,tlv320aic3111";
    reg = <0x18>;
    //ai3x-micbias-vg = <1>; /* 2.0V */
    ai31xx-micbias-vg = <2>; /* 2.5V */
    status = "okay";

    /* Regulators */
    AVDD-supply = <&vcc_3v3_sys>;
    IOVDD-supply = <&vcc_3v3_sys>;
    DVDD-supply = <&vcc_1v8>;
    HPVDD-supply = <&vcc_3v3_sys>;
    SPLVDD-supply = <&vcc_5v0>;
    SPRVDD-supply = <&vcc_5v0>;
    };
    };

  • And sound card settings in DTS:

    codec_audio: sound {
    compatible = "simple-audio-card";
    simple-audio-card,name = "AM62x-SKEVM";
    simple-audio-card,widgets =
    "Headphone", "Headphone Jack",
    "Microphone", "Microphone Jack",
    "Speaker", "External Speaker";
    simple-audio-card,routing =
    "MIC1LP", "Microphone Jack",
    "MIC1RP", "Microphone Jack",
    "MIC1LM", "MICBIAS",
    "Headphone Jack", "HPL",
    "Headphone Jack", "HPR",
    "External Speaker", "SPL",
    "External Speaker", "SPR";
    simple-audio-card,format = "dsp_b";
    simple-audio-card,bitclock-master = <&sound_master>;
    simple-audio-card,frame-master = <&sound_master>;
    simple-audio-card,bitclock-inversion;

    simple-audio-card,cpu {
    sound-dai = <&mcasp1>;
    };

    sound_master: simple-audio-card,codec {
    sound-dai = <&tlv320aic3111>;
    clocks = <&tlv320_mclk>;
    };
    };

  • compatible = "ti,tlv320aic3111"; change to 

    compatible = "ti,tlv320aic3110", and check whether the agc kcontrol appear

  • Thanks, could you tell us how to check kcontrols for agc please? 

  • Could you please review 'simple-audio-card,routing ' for us? I am not sure this is correct in our DTS.

  • Why use dsp-b instead of i2s? Would you use TDM?

  • was default on the SK-AM62 so left it to it. Should we change this? 

  • moreover this was the format needed to use the MCASP interface of the TI AM625 SoC. 

  • default format is i2s

  • Okay, I will change this . any comments on the simple-audio-card,routing? 

    and how to check the kcontrols for AGC please? 

  • type amixer in the command windows, and capture the log to me.

  • root@am62xx-evm:~# amixer
    Simple mixer control 'Speaker Analog',0
    Capabilities: pvolume
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 127
    Mono:
    Front Left: Playback 127 [100%] [0.00dB]
    Front Right: Playback 127 [100%] [0.00dB]
    Simple mixer control 'Speaker Driver',0
    Capabilities: pvolume pswitch
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 3
    Mono:
    Front Left: Playback 3 [100%] [24.00dB] [on]
    Front Right: Playback 3 [100%] [24.00dB] [on]
    Simple mixer control 'Speaker Left',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'Speaker Right',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'Mic PGA',0
    Capabilities: cvolume cvolume-joined
    Capture channels: Mono
    Limits: Capture 0 - 119
    Mono: Capture 53 [45%] [26.50dB]
    Simple mixer control 'ADC',0
    Capabilities: cvolume cvolume-joined cswitch cswitch-joined
    Capture channels: Mono
    Limits: Capture 0 - 64
    Mono: Capture 59 [92%] [9.50dB] [on]
    Simple mixer control 'ADC Fine',0
    Capabilities: cvolume cvolume-joined
    Capture channels: Mono
    Limits: Capture 0 - 4
    Mono: Capture 1 [25%] [0.10dB]
    Simple mixer control 'DAC',0
    Capabilities: pvolume
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 175
    Mono:
    Front Left: Playback 87 [50%] [-20.00dB]
    Front Right: Playback 87 [50%] [-20.00dB]
    Simple mixer control 'DAC Left Input',0
    Capabilities: enum
    Items: 'Off' 'Left Data' 'Right Data' 'Mono'
    Item0: 'Left Data'
    Simple mixer control 'DAC Right Input',0
    Capabilities: enum
    Items: 'Off' 'Right Data' 'Left Data' 'Mono'
    Item0: 'Right Data'
    Simple mixer control 'HP Analog',0
    Capabilities: pvolume
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 127
    Mono:
    Front Left: Playback 102 [80%] [-12.50dB]
    Front Right: Playback 102 [80%] [-12.50dB]
    Simple mixer control 'HP Driver',0
    Capabilities: pvolume pswitch
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 9
    Mono:
    Front Left: Playback 8 [89%] [8.00dB] [on]
    Front Right: Playback 8 [89%] [8.00dB] [on]
    Simple mixer control 'HP Left',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'HP Output Driver Power-On time',0
    Capabilities: enum
    Items: '0us' '15.3us' '153us' '1.53ms' '15.3ms' '76.2ms' '153ms' '304ms' '610ms' '1.22s' '3.04s' '6.1s'
    Item0: '304ms'
    Simple mixer control 'HP Output Driver Ramp-up step',0
    Capabilities: enum
    Items: '0ms' '0.98ms' '1.95ms' '3.9ms'
    Item0: '0ms'
    Simple mixer control 'HP Right',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'MIC1LM M-Terminal',0
    Capabilities: enum
    Items: 'Off' 'FFR 10 Ohm' 'FFR 20 Ohm' 'FFR 40 Ohm'
    Item0: 'Off'
    Simple mixer control 'MIC1LM P-Terminal',0
    Capabilities: enum
    Items: 'Off' 'FFR 10 Ohm' 'FFR 20 Ohm' 'FFR 40 Ohm'
    Item0: 'FFR 10 Ohm'
    Simple mixer control 'MIC1LP P-Terminal',0
    Capabilities: enum
    Items: 'Off' 'FFR 10 Ohm' 'FFR 20 Ohm' 'FFR 40 Ohm'
    Item0: 'FFR 10 Ohm'
    Simple mixer control 'MIC1RP P-Terminal',0
    Capabilities: enum
    Items: 'Off' 'FFR 10 Ohm' 'FFR 20 Ohm' 'FFR 40 Ohm'
    Item0: 'Off'
    Simple mixer control 'Output Left From Left DAC',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'Output Left From MIC1LP',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [off]
    Simple mixer control 'Output Left From MIC1RP',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [off]
    Simple mixer control 'Output Right From MIC1RP',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [off]
    Simple mixer control 'Output Right From Right DAC',0
    Capabilities: pswitch pswitch-joined
    Playback channels: Mono
    Mono: Playback [on]
    Simple mixer control 'Volume Soft Stepping',0
    Capabilities: enum
    Items: 'fast' 'slow' 'disabled'
    Item0: 'fast'
    root@am62xx-evm:~#

  • Do you want to add this agc into the kcontrol?

  • Hi Shenghao, yes please! 

  • Kindly dump the register to me. Thanks.

  • Here you go:

    root@am62xx-evm:~# i2cdump -y -f 1 0x18
    No size specified (using byte-data access)
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    00: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?...............
    10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 ...............?
    20: 06 3e 00 00 7f 7f 7f 7f 02 02 00 00 20 86 00 80 ?>..??????.. ?.?
    30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

  • Hi Mitesh

    Here is the quickest way that you may as well copy the AGC code in tlv320aic3x.c code to the tlv320aic31xx.c, only difference is the register no. 

  • Perfect, I was thinking to do the same. I will try this and let you know. Cheers. 

  • Hi Shenghao, I finally managed to get the AGC controls for the AIC31XX driver and seems to write to the right registers but doesn't work as expected. 

    aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: AM62xSKEVM [AM62x-SKEVM], device 0: davinci-mcasp.0-tlv320aic31xx-hifi tlv320aic31xx-hifi-0 [davinci-mcasp.0-tlv320aic31xx-hifi tlv320aic31xx-hifi-0]
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    Here's register dump of AIC3111 

    i2cdump -y -f 1 0x18
    No size specified (using byte-data access)
    0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
    00: 00 00 01 56 03 91 08 07 80 00 00 88 82 00 80 80 ..?V?????..??.??
    10: 08 00 88 82 80 80 04 00 00 00 01 4c 00 04 88 00 ?.?????...?L.??.
    20: 00 00 00 00 80 bb 11 00 00 00 00 00 00 00 00 00 ....???.........
    30: 00 00 00 02 32 12 03 02 02 11 10 00 01 04 00 d4 ...?2??????.??.?
    40: 0c f4 f4 00 6f 38 00 00 00 00 00 ee 10 d8 7e e3 ???.o8.....???~?
    50: 00 00 00 20 00 00 80 f4 50 30 20 00 00 00 00 00 ... ..??P0 .....
    60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    70: 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 .....?..........
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

    I have set the following:

    $> amixer set 'AGC' on

    #Set the Attack Time to 8ms
    $> amixer set 'AGC Attack Time' 416/Fs

    #Set the Decay Time to 100ms
    $> amixer set 'AGC Decay Time' 4608/Fs

    #Set the AGC Target Level to -10dB
    $> amixer cset numid=6,iface=MIXER,name='AGC Target level' 2

    #Set AGC hysteresis=DISABLE, noise threshold = -90dB
    $> amixer cset numid=7,iface=MIXER,name='AGC Hysterysis Setting' 3
    $> amixer cset numid=8,iface=MIXER,name='AGC Noise threshold' 31

    #Set the AGC Max Gain to 40dB
    $> amixer cset numid=9,iface=MIXER,name='AGC Max Gain' 80

    #To record microphone audio
    $> arecord -f dat -V mono -d 5 -t wav testMic.wav

    #To play the recording
    $> aplay testMic.wav

    But can't hear any voice as such!

    Also I'm using the microphone on the TLV320AIC3111EVM and irrespective to jumper W2 and W3, I can hear the taps, if I taps on the mic?! 

  • Following are the Kcontrols I have now. 

    $>amixer scontrols
    Simple mixer control 'Speaker Analog',0
    Simple mixer control 'Speaker Driver',0
    Simple mixer control 'Speaker Left',0
    Simple mixer control 'Speaker Right',0
    Simple mixer control 'Mic PGA',0
    Simple mixer control 'ADC',0
    Simple mixer control 'ADC Fine',0
    Simple mixer control 'AGC',0
    Simple mixer control 'AGC Attack Time',0
    Simple mixer control 'AGC Decay Time',0
    Simple mixer control 'AGC Hysterysis Setting',0
    Simple mixer control 'AGC Max Gain',0
    Simple mixer control 'AGC Noise Threshold',0
    Simple mixer control 'AGC Target Level',0
    Simple mixer control 'DAC',0
    Simple mixer control 'DAC Left Input',0
    Simple mixer control 'DAC Right Input',0
    Simple mixer control 'HP Analog',0
    Simple mixer control 'HP Driver',0
    Simple mixer control 'HP Left',0
    Simple mixer control 'HP Output Driver Power-On time',0
    Simple mixer control 'HP Output Driver Ramp-up step',0
    Simple mixer control 'HP Right',0
    Simple mixer control 'MIC1LM M-Terminal',0
    Simple mixer control 'MIC1LM P-Terminal',0
    Simple mixer control 'MIC1LP P-Terminal',0
    Simple mixer control 'MIC1RP P-Terminal',0
    Simple mixer control 'Output Left From Left DAC',0
    Simple mixer control 'Output Left From MIC1LP',0
    Simple mixer control 'Output Left From MIC1RP',0
    Simple mixer control 'Output Right From MIC1RP',0
    Simple mixer control 'Output Right From Right DAC',0
    Simple mixer control 'Volume Soft Stepping',0

  • Hi Guy,

    Can you share testMic.wav with me? Let me chek the bistream, first. I think you should adjust the gain instead of AGC.

  • Hi Shenghao, attached is the audio file. 

    I have Push To Talk microphone and from the audio you will hear there is some background noise when the PTT is off and when on the audio is clear. THis recording was with AGC disabled.

    Thanks

     

  • Let me ask our codec expert for support on the gain of playback.

  • Hi,

    AGC is not the tool to remove your noise when PTT is off. AGC is adjusting your PGA gain for a dynamic signal to be less dynamic, PGA does not have negative gain to reduce/remove. You need to take care of the noise outside or post process in the host.

    Regards.

  • Hi,

    Sure. I am trying to understand the cause for the noise. We have TLV320AIC3111 EVM board and have removed jumpers W2 and W3 and connected external microphone on J6. This external microphone is PTT. 

    What we notice is even after bypassing the on-board microphone (by removing jumpers) we hear audio from it and is the source of the noise. 

    Thanks

  • The noise in the wave file sounds like it's from the PTT set and not the on-board mic.

    You can remove all the jumpers highlighted below and set W7 to 1-2 for ac-coupled input.

  • Hi,

    after removing all the jumpers mentioned, there is no audio at all. 

    Added W1 (2-3), W7 (2-3), W4 jumpers and audio works but with noise.

    When I tap on the on-board microphone I can still hear the taps. However, when I tap on the PTT (external microphone) then there are no tapping noise.

    Thanks 

  • What feedforward resistor values would you use with your setup of removing all the jumpers and having just ac coupled for mic and without mic bias?

     MIC1LM_M = off

     MIC1LM_P = off

     MIC1LP_P = 10 Ohm

     MIC1RP_P = 10 Ohm

  • Audio works well with external mic (PTT) with following settings, and when the PTT is not enabled there is still background noise. 

    MIC1LM_M = 10 Ohm

     MIC1LM_P = off

     MIC1LP_P = 10 Ohm

     MIC1RP_P = off

    W1 (2-3)

    W2, W3, W4, W5, W6 open

    W7 (2-3)

    W8 (1-2)

  • So it looks like the PTT requires Micbias from codec, so place the Micbias jumper for your PTT.

    Are you providing the Micbias for the on-board MIC when you tap it?

    The on-board mic should have been powered down when Micbias is removed.