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.

Porting adau1761 codec

Hi,


I wan to port the adau1761 codec driver to custom 8148 board the codec is connected mcasp2, I have been following link [1] I can see the probe is being called

but the probe from snd_soc_codec_driver isnt called.

any pointers what could be missing ?

[1]

Cheers,

Steve

  • Steve,

    Please see also the below wiki page and the FAQ at the bottom of this wiki page:

    processors.wiki.ti.com/.../TI81XX_PSP_AUDIO_Driver_User_Guide

    See the attached Audio.ppt, it also has info regarding audio codec porting.

    BR
    Pavel
  • Hi Pavel,

    Thanks for the links, I have managed to call the codec probe now. but I see some issues
    In the tlv320aic3x there isnt set_pll() implemented but in our codec it is implemented, so how do I configure it ?
    How should make davinci-mcasp to call the set_pll() of the codec ?

    Cheers,
    -Steve
  • Hi Pavel,

    Some further progress!

    when I do a arecord it fails with this message 'asoc: can't set codec adau1761-aif1 hw params' tracing where exactly it fails pointed me to
    function davinci_pcm_hw_params(), inside this it uses snd_pcm_lib_malloc_pages() to which this call fails.

    Any pointers why malloc pages fails ?

    My codec is connected mcasp2 as tlvc codec, so I have kept ti8148_evm_snd_data as is in board file.

    Cheers,
    Steve
  • Steve,

    ADAU1761 has integrated PLL, while AIC3x not. DM814x device PSP is based on linux kernel 2.6.37

    The first step from the Audio.ppt is:

    1. Find the supported codec from the list <kernel src>/sound/soc/codec/*
    codec must be compatible with the Audio interface(TDM/I2S) data format

    The AIC3x codec driver is:
    <kernel src>/sound/soc/codec/tlv320aic3x.c

    What about the ADAU1761 codec driver, I can not find it in the list of available audio codec drivers, which one you are using?

    BR
    Pavel

  • Hi Pavel,

    Yes that codec driver is not part of 2.6.37 kernel, due to which I took the driver form 3.2 and back ported it to 2.6.37, changing a few bits in sound core.

    any reason why snd_pcm_lib_malloc_pages() should fail ?

    Cheers,
    -Steve
  • Steve,

    Steve Hooper said:
    when I do a arecord it fails

    Could you provide me your steps to do arecord to check them on my side?

    Steve Hooper said:
    fails with this message 'asoc: can't set codec adau1761-aif1 hw params' tracing where exactly it fails pointed me to
    function davinci_pcm_hw_params(), inside this it uses snd_pcm_lib_malloc_pages() to which this call fails.

    Any pointers why malloc pages fails ?

    What is the software release you are using? Is it DM814x EZSDK 5.05.02.00?

    BR
    Pavel

  • Hi Pavel,

    Following is the log:
    $ arecord -f cd
    Recording WAVE 'stdin' : Signed 16 bit Little En[ 109.320000] dbg1
    dian, Rate 44100[ 109.320000] dbg2
    Hz, Stereo
    [ 109.320000] dbg3
    [ 109.330000] dbg4
    [ 109.330000] dbg5
    [ 109.330000] dbg6
    [ 109.330000] dbg7
    [ 109.460000] dbg8
    [ 109.460000] dbg9
    [ 109.460000] dbg20
    [ 109.460000] dbg21
    [ 109.460000] dbg22
    [ 109.460000] dbg23
    [ 109.470000] dbg24
    [ 109.470000] dbg25
    [ 109.470000] dbg26!!!!
    RIFF$�WAVEfmt D��data�
    [ 119.470000] ALSA sound/core/pcm_lib.c:1765: capture write error (DMA or IRQ trouble?)
    arecord: pcm_read:2031: read error: Input/output error

    $ speaker-test -c2 -t sine

    speaker-test 1.0.28

    Playback device is default
    Stream parameters are 48000Hz, S16_LE, 2 channels
    Sine wave rate is 440.0000Hz
    Rate set to 4800[ 427.780000] dbg1
    0Hz (requested 4[ 427.780000] dbg2
    8000Hz)
    Buffer [ 427.780000] dbg3
    size range from [ 427.790000] dbg4
    16 to 32768
    Per[ 427.790000] dbg5
    iod size range f[ 427.790000] dbg6
    rom 8 to 2048
    U[ 427.790000] dbg7
    sing max buffer size 32768
    Periods = 4
    [ 427.920000] dbg8
    [ 427.920000] dbg9
    [ 427.940000] dbg20
    [ 427.940000] dbg21
    [ 427.940000] dbg22
    [ 427.940000] dbg23
    [ 427.940000] dbg24
    [ 427.950000] dbg25
    [ 427.950000] dbg26!!!!
    was set period_size = 2048
    was set buffer_size = 32768
    0 - Front Left

    [ 438.010000] ALSA sound/core/pcm_lib.c:1765: playback write error (DMA or IRQ trouble?)


    [ 448.010000] ALSA sound/core/pcm_lib.c:1765: playback write error (DMA or IRQ trouble?)
    Write error: -5,Input/output error
    xrun_recovery failed: -5,Input/output error
    Transfer failed: Input/output error


    Yes I am using DM814x EZSDK 5.05.02.00

    Cheers,
    --Steve
  • Hi Pavel,

    One more thing that I am using below audio format:

    #define AUDIO_FORMAT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM)

    But it in some file it mentioned davinci doesnt support i2s mode. Is it the case I cant use I2S mode ?

    Cheers,
    Steve
  • Steve,

    Steve Hooper said:
    $ arecord -f cd
    Recording WAVE 'stdin' : Signed 16 bit Little En[ 109.320000] dbg1
    dian, Rate 44100[ 109.320000] dbg2
    Hz, Stereo
    [ 109.320000] dbg3
    [ 109.330000] dbg4
    [ 109.330000] dbg5
    [ 109.330000] dbg6
    [ 109.330000] dbg7
    [ 109.460000] dbg8
    [ 109.460000] dbg9
    [ 109.460000] dbg20
    [ 109.460000] dbg21
    [ 109.460000] dbg22
    [ 109.460000] dbg23
    [ 109.470000] dbg24
    [ 109.470000] dbg25
    [ 109.470000] dbg26!!!!
    RIFF$�WAVEfmt D��data�
    [ 119.470000] ALSA sound/core/pcm_lib.c:1765: capture write error (DMA or IRQ trouble?)
    arecord: pcm_read:2031: read error: Input/output error

    Can you try the below commands, what is the result?

    root@dm814x-evm:~# arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: EVM [TI81XX EVM], device 0: AIC3X tlv320aic3x-hifi-0 []
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    root@dm814x-evm:~# arecord -D 'hw:0,0' -r 44100 -d 10 -f cd song.dat
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
    root@dm814x-evm:~#

    hw:0,0 parameter comes from card 0, device 0

    BR
    Pavel

  • Hi Pavel,

    Following is the log:

    $ arecord -l
    **** List of CAPTURE Hardware Devices ****
    card 0: EVM [TI81XX EVM], device 0: adau1761 adau1761-aif1-0 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    $ arecord -D 'hw:0,0' -r 44100 -d 10 -f cd song.dat
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
    [ 115.610000] asoc: can't set codec adau1761-aif1 hw params
    arecord: set_params:1297: Unable to install hw params:
    ACCESS: RW_INTERLEAVED
    FORMAT: S16_LE
    SUBFORMAT: STD
    SAMPLE_BITS: 16
    FRAME_BITS: 32
    CHANNELS: 2
    RATE: 44100
    PERIOD_TIME: (46439 46440)
    PERIOD_SIZE: 2048
    PERIOD_BYTES: 8192
    PERIODS: 11
    BUFFER_TIME: (510839 510840)
    BUFFER_SIZE: 22528
    BUFFER_BYTES: 90112
    TICK_TIME: 0

    I have changed it to:
    #define AUDIO_FORMAT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM)

    Connection McASP2
    -----------------
    Transmit bit clock XCLK sourced from ACLKX input pin.
    Receive bit clock RCLK sourced from internal XCLK.
    Transmit frame sync sourced from AFSX input pin.
    Receive frame sync sourced from AFSX input pin.
    Data out on MCA2_AXR0.
    Data in on MCA2_AXR1.
    I2S mode, 24 bit data.

    As per above do I need to change ti8148_evm_snd_data in board file ?

    Cheers,
    Steve
  • Steve,

    Steve Hooper said:
    #define AUDIO_FORMAT (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM)

    But it in some file it mentioned davinci doesnt support i2s mode. Is it the case I cant use I2S mode ?

    See the below e2e thread, it might help you:

    BR
    Pavel

  • Steve,

    Steve Hooper said:
    [ 115.610000] asoc: can't set codec adau1761-aif1 hw params
    arecord: set_params:1297: Unable to install hw params:

    May be the audio codec (adau1761) can not accept these settings, check its datasheet if these settings are supported. Check also with the snd_pcm_hw_params_test_ <<parameter>>  function:

    snd_pcm_hw_params_test_ <<parameter>> - Test the availability of important parameters like number of channels, sample rate etc. For e.g. snd_pcm_hw_params_test_format, snd_pcm_hw_params_test_rate etc.

    BR
    Pavel

  • Hi Pavel,

    Thanks for the links. I am debugging it.
    Any pointer to change the params_rate(params) its always 44100 I want it 48K

    Cheers,
    Steve
  • Steve,

    Steve Hooper said:
    Any pointer to change the params_rate(params) its always 44100 I want it 48K

    From ALSA utils (arecord), you can pass the rate with -r:

    # arecord -D 'hw:0,0' -r 48000 -f S16_LE -c 2  song.dat

    For the user space application, you should set in the rate variable:

    int main (int argc, char *argv[])
    {
      int err;
      short buf[BUFF_SIZE];
      int rate = 44100; /* Sample rate */
      unsigned int exact_rate; /* Sample rate returned by */

    .........

    /* Set sample rate. If the exact rate is not supported by the hardware, use nearest possible rate. */
      exact_rate = rate;
      if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, &exact_rate, 0)) < 0) {
        fprintf (stderr, "cannot set sample rate (%s)\n", snd_strerror (err));
        exit (1);
      }
    
      if (rate != exact_rate) {
        fprintf(stderr, "The rate %d Hz is not supported by your hardware.\n ==> Using %d Hz instead.\n", rate, exact_rate);
      }

    Pavel

  • Hi Pavel,

    I tried the following:
    # arecord -D 'hw:0,0' -r 48000 -d 10 -f cd song.dat

    and printed the Params rate in evm_hw_params() in davinci-evm.c
    but its the following:
    Recording WAVE '[ 33.240000] Params rate: 44100
    song.dat' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

    Does the davinci mcasp set it to 44100 by default ? I searched in the driver but couldnt find anything .

    Cheers,
    Steve
  • Steve,

    Steve Hooper said:
    Does the davinci mcasp set it to 44100 by default ? I searched in the driver but couldnt find anything .

    No, I do not think so. The sample rate can be also set in the root filesystem (/usr/share/alsa/), but by default it is not.

    Steve Hooper said:
    I tried the following:
    # arecord -D 'hw:0,0' -r 48000 -d 10 -f cd song.dat

    and printed the Params rate in evm_hw_params() in davinci-evm.c
    but its the following:
    Recording WAVE '[ 33.240000] Params rate: 44100
    song.dat' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

    I have the same at my side:

    root@dm814x-evm:~# arecord -D 'hw:0,0' -r 48000 -d 10 -f cd song.dat
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

    I think this is caused by the format (-f cd). This "-f cd" is short cut to this whole command:

    -f S16_LE -c2 -r44100

    Like "-f dat" is short cut to:

    -f S16_LE -c2 -r48000

    This is what I have on my side:

    root@dm814x-evm:~# arecord -D 'hw:0,0' -r 48000 -f S16_LE -d 10 song.dat     
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

    root@dm814x-evm:~# arecord -D 'hw:0,0' -r 48000 -f S16_LE -c 2 -d 10 song.dat
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

    root@dm814x-evm:~# arecord -D 'hw:0,0' -r 48000 -d 10 -f dat song.dat
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo

    root@dm814x-evm:~# arecord -D 'hw:0,0' -d 10 -f dat song.dat         
    Recording WAVE 'song.dat' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo


    Regards,
    Pavel