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.

How to use multiple ALSA devices from shell ?

Guru 20755 points
Other Parts Discussed in Thread: TVP5158

Hello,

I configured kernel with 2 devices in one card with the following configuration:

line_in +  mic                 ---  mcasp 2 - codec 0x18 
line_out+headphone

line_in +  mic                 ---  mcasp 3 - codec 0x19
line_out+headphone

It seems that both are loaded correctly when I configure each one seperately, but on trying to load both I get the following error in boot:

usbcore: registered new interface driver snd-usb-audio
PM: Adding info for platform:soc-audio.0

PM: Adding info for No Bus:TLV320AIC3X_2
asoc: tlv320aic3x-hifi <-> davinci-mcasp.2 mapping ok
snd_soc_instantiate_card 7
tlv320aic3x-codec 2-0019: tlv320aic3x-codec.2-0019: Failed to add PCM Playback Volume: -16
asoc: failed to add dapm kcontrol Right HPCOM Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Left HPCOM Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Right HP Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Left HP Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Mono Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Right Line Mixer Line2L Bypass Switch: -16
asoc: failed to add dapm kcontrol Left Line Mixer Line2L Bypass Switch: -16
asoc: failed to add kcontrol Right Line2R Mux
asoc: failed to add kcontrol Right Line1R Mux
asoc: failed to add kcontrol Right Line1L Mux
asoc: failed to add dapm kcontrol Right PGA Mixer Line1R Switch: -16
asoc: failed to add kcontrol Left Line2L Mux
asoc: failed to add kcontrol Left Line1R Mux
asoc: failed to add kcontrol Left Line1L Mux
asoc: failed to add dapm kcontrol Left PGA Mixer Line1L Switch: -16
asoc: failed to add kcontrol Right HPCOM Mux
asoc: failed to add kcontrol Right DAC Mux
asoc: failed to add kcontrol Left HPCOM Mux
asoc: failed to add kcontrol Left DAC Mux
PM: Adding info for No Bus:TLV320AIC3X_3
asoc: tlv320aic3x-hifi <-> davinci-mcasp.3 mapping ok
PM: Adding info for No Bus:card0
PM: Adding info for No Bus:pcmC0D1p
PM: Adding info for No Bus:pcmC0D1c
PM: Adding info for No Bus:pcmC0D0p
PM: Adding info for No Bus:pcmC0D0c
PM: Adding info for No Bus:controlC0
ALSA device list:
#0: TI81XX SOUND0

Is it becuase the driver except that these control will work with single device only ? (In my case there are 2 devices)

If yes -  what changes do I need to make in code to support control for 2 devices ?

Another thing is that I see (when both devices are configured) it as following;

root@dm814x:~# cat /proc/asound/devices
0: [ 0] : control
16: [ 0- 0]: digital audio playback
17: [ 0- 1]: digital audio playback
24: [ 0- 0]: digital audio capture
25: [ 0- 1]: digital audio capture
33: : timer

It seems that I have 2 capture device and 2 playback device.

But according to the configuration I expected 4 capture device and 4 playback devices:

line_in  (capture)
mic    (capture)             ---  mcasp 2 - codec 0x18 
line_out  (playback)
headphone (playback)

line_in (capture)
mic (capture)                ---  mcasp 3 - codec 0x19
line_out (playback)
headphone (playback)

Why do I see only 2 capture and 2 playback devices ?

I also get that speed of the recorded file with the first codec and mcasp2 is faster then the original recorded file.

Thanks,

Ran

  • Ran,

    From what I understand, your system has two McASP instances (2 and 3) connected to two external audio codecs:

    McASP2 <-----> AIC3x

    McASP3 <-----> other AIC3x

    I think you should be able to use these two audio codecs on the same sound card (card 0), but mapped as different devices.

    MCASP2: card 0, device 0 (hw:0,0)
    McASP3: card 0, device 1 (hw:0,1)

    In the PSP porting guide we have this stated:

    processors.wiki.ti.com/.../TI81xx_PSP_Porting_Guide

    In order to have multiple McASPs working ....
    If everything is fine, on kernel bootup you should see multiple sub-devices for the sound card.

    On DM814x TI EVM we have McASP2 <----> AIC3106 and also HDMI audio. Both are mapped to card 0, AIC3106 as device 0 (hw0:0), HDMI audio codec as device 1 (hw:0,1):

    root@dm814x-evm:~# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: EVM [TI81XX EVM], device 0: AIC3X tlv320aic3x-hifi-0 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    card 0: EVM [TI81XX EVM], device 1: hdmi HDMI-DAI-CODEC-1 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0

    Could you please state which audio codec you are using for McASP2 and for McASP3? Please provide me the below files:

    board-ti8148evm.c (or the board file you are actually using), devices.c and davinci-evm.c

    BR
    Pavel
  • Hi Pavel,

    I am using tlv320aic3x codec.

    Attached are the files I'm using.

    It is configured now as 2 codecs (devices) in the same card (this is also what is stated in the proting wiki guide in TI's as how to deal with more than one codec).

    According to some threads it seems that the failure I'm dealing with codec relates more to problem in alsa driver when registring the controls of codec. 

    I wander if seperating the 2 codec to different cards (one codec for each crad) might resolve this naming issue.

    0456.ti81xx-evm.c

    2671.devices.c

    0020.board-ti8148evm.c

    Regards,

    Ran

  • I am using this configuration:
    ======================

    card0:

    device 0:
    McASP2 <-----> AIC3x

    device1:
    McASP3 <-----> AIC3x (other codec)

    I hope that changing it to the following configuration might reoslve this issue (but haven't tried it yet):

    suggested configuration:

    ============
    card0:

    device 0:
    McASP2 <-----> AIC3x

    card1:

    device0:
    McASP3 <-----> AIC3x (other codec)


    Regards,
    Ran

  • Ran,

    The below e2e post seems related to the card0,card1 approach that you want to test:

    e2e.ti.com/.../255120

    BR
    Pavel
  • Ran Shalit said:
    I wander if seperating the 2 codec to different cards (one codec for each crad) might resolve this naming issue.

    In ti81xx-evm.c you have:

    .codec_name = "tlv320aic3x-codec.2-0019",


    This means this aic should be attached to I2C1/0x4802A000 at address 0x19. Could you please double check this?

    The codec_name is made up of the name used in the codec driver along with the I2C bus and I2C address (1-0018 for the EVM):

    .codec_name = "tlv320aic3x-codec.1-0018",

    BR
    Pavel
  • In board-ti8148evm.c you have only one ti81xx_register_mcasp() function invocation, while for register two McASPs, you should have (for example):

    ti81xx_register_mcasp(0, &aic3x_snd_data); //McASP2

    ti81xx_register_mcasp(1, &aic3x_snd_data_elbit); //McASP3

    I see other possible mistakes also. Please refer to my files (davinci-evm.c, board-ti8148evm.c and devices.c) as a reference, where I enable McASP0 and register it in card 0, device 1. I have no error messages during linux kernel boot up. I can not test McASP0 as I have no audio codec attached to it.

    5466.davinci-evm.c

    2500.board-ti8148evm.c

    0842.devices.c

    BR
    Pavel

  • Hi Pavel,



    Thank you very much for the feedback and suggestions.

    I will try them first thing in lab.

    1. I did notice that in the code you've attached the codec name is identical for both codecs ("tlv320aic3x-codec.1-0018"), when using 2 devices I think that each should have his own codec:

    static struct snd_soc_dai_link ti81xx_evm_dai[] = {

    {
    .name = "TLV320AIC3X",
    .stream_name = "AIC3X",
    .codec_dai_name = "tlv320aic3x-hifi",
    .codec_name = "tlv320aic3x-codec.1-0018",
    .platform_name = "davinci-pcm-audio",
    .init = evm_aic3x_init,
    .ops = &evm_ops,
    },
    {
    .name = "TLV320AIC3X_MCASP0",
    .stream_name = "AIC3X",
    .codec_dai_name = "tlv320aic3x-hifi",
    //.codec_dai_name = "HDMI-DAI-CODEC",
    .codec_name = "tlv320aic3x-codec.1-0018",
    //.codec_name = "hdmi-dummy-codec",
    .platform_name = "davinci-pcm-audio",
    .init = evm_aic3x_init,
    .ops = &evm_ops,
    },

    2. As to the mcasp registration, I'm not sure this is it, becuase I see 2 registration, the format is a bit different then given in your message:

    platform_device_register(&ti81xx_mcasp_aic_device);

    platform_device_register(&ti81xx_mcasp_aic_device_elbit);

    3. I am using "tlv320aic3x-codec.2-0019" & "tlv320aic3x-codec.2-0018" this is i2c1, (which is seen in linux as i2c-2 bus), i.e.
    > sudo i2cdetect -r -y 2

    0 1 2 3 4 5 6 7 8 9 a b c d e f
    00: -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- UU UU -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- -- --


    Thanks,
    Ran
  • I also suspect that this issue might be related to prefix_name bug in alsa code.

    According to following thread:

    This might be the reason for the failure.

    I hope that seperating the devices into 2 codecs, will solve this issue for me, so that I won't need to apply the given patch (in that thread),

    Thanks,

    Ran

  • Ran Shalit said:
    1. I did notice that in the code you've attached the codec name is identical for both codecs ("tlv320aic3x-codec.1-0018"), when using 2 devices I think that each should have his own codec:

    Agree. I made it just as an example how to add additional McASP instance (McASP0). I do not modify the codec name, as I have no audio codec (or anything) attached to McASP0 in the DM814x TI EVM.

    Ran Shalit said:
    2. As to the mcasp registration, I'm not sure this is it, becuase I see 2 registration, the format is a bit different then given in your message:

    platform_device_register(&ti81xx_mcasp_aic_device);

    platform_device_register(&ti81xx_mcasp_aic_device_elbit);

    I would recommend you to try also with the other approach (provided in my files) to see if you will have any improvement.

    BR
    Pavel

  • Hi Pavel,



    When working with 2 cards instead of 2 device at the same card, I get no error for this issue of 'ALSA control name already busy'.
    I guess it is some ALSA bug. I think that working in such configuration should be good enough , Right? I rather do this simple fix instead of applying the prefix_name patch.


    This is the boot log with this configuration:

    ...

    usbcore: registered new interface driver snd-usb-audio
    Registered tvp5158 audio codec
    PM: Adding info for platform:soc-audio.0
    PM: Adding info for No Bus:TLV320AIC3X_2
    asoc: tlv320aic3x-hifi <-> davinci-mcasp.2 mapping ok
    PM: Adding info for No Bus:card0
    PM: Adding info for No Bus:pcmC0D0p
    PM: Adding info for No Bus:pcmC0D0c
    PM: Adding info for No Bus:controlC0
    PM: Adding info for platform:soc-audio.1
    snd_soc_instantiate_card 4
    PM: Adding info for No Bus:TLV320AIC3X_3
    asoc: tlv320aic3x-hifi <-> davinci-mcasp.3 mapping ok
    PM: Adding info for No Bus:card1
    PM: Adding info for No Bus:pcmC1D0p
    PM: Adding info for No Bus:pcmC1D0c
    PM: Adding info for No Bus:controlC1
    ALSA device list:
    #0: TI81XX SOUND0
    #1: TI81XX SOUND1
    TCP cubic registered
    NET: Registered protocol family 17

    Regards,

    Ran

  • Ran,

    Ran Shalit said:
    I think that working in such configuration should be good enough , Right?

    Are you able to use aplay with McASP2/3 correctly? If yes, then I think this configuration should be also fine. This configuration is used for other newer devices, like OMAP5, see the below pointers:

    Could you please also share the final versions of your files (devices.c, board-ti8148evm.c, ti81xx-evm.c)? And have you made changes in other files?

    BR
    Pavel

  • Hi Pavel,

    On trying to do aplay, arecord, I get success with mcasp2 , card0, but not with mcasp3, card1.

    For now I just try to call this utilities, not yet checking the sound. With card0, mcasp2, the aplay, arecord return and no error is printed.

    With mcasp3, card1, it hangs, and does not return. I don't know the internal of this utilities, but it seems that it wait for some events.

    I had to make to changed for this to function without errors (but it still hangs):

    1. At first it made some errors, but after removing the reserved dma for dma 56-, It continue without errors.

    2. asp.h (also attached) was added with dma events for mcasp3 (it was missing in that file):

    asp.h

    ====

    added line:

    #define TI81XX_ASP3_BASE 0x4A1A2000

    /* EDMA channels of ti81xx McASP3 */
    #define TI81XX_DMA_MCASP3_AXEVT 56
    #define TI81XX_DMA_MCASP3_AREVT 57

    devices.c

    ==========

    ti81xx_mcasp_aic_device_elbit.id = 3;
    ti81xx_mcasp_aic_device_elbit.resource = ti81xx_mcasp3_resource;
    ti81xx_mcasp_aic_device_elbit.num_resources = ARRAY_SIZE(ti81xx_mcasp3_resource);

    platform_device_register(&ti81xx_mcasp_aic_device_elbit);

    platform_device_register(&ti81xx_mcasp_aic_device);

    static struct resource ti81xx_mcasp3_resource[] = {
    {
    .name = "mcasp",
    .start = TI81XX_ASP3_BASE,
    .end = TI81XX_ASP3_BASE + (SZ_1K * 12) - 1,
    .flags = IORESOURCE_MEM,
    },
    /* TX event */
    {
    .start = TI81XX_DMA_MCASP3_AXEVT,
    .end = TI81XX_DMA_MCASP3_AXEVT,
    .flags = IORESOURCE_DMA,
    },
    /* RX event */
    {
    .start = TI81XX_DMA_MCASP3_AREVT,
    .end = TI81XX_DMA_MCASP3_AREVT,
    .flags = IORESOURCE_DMA,
    },
    };


    static const s16 ti814x_dma_rsv_chans[][2] = {
    /* (offset, number) */
    {0, 2},
    {14, 2},
    {26, 6},
    {48, 4},
    //ranran {56, 8},
    {-1, -1}
    };

    static const s16 ti814x_dma_rsv_slots[][2] = {
    /* (offset, number) */
    {0, 2},
    {14, 2},
    {26, 6},
    {48, 4},
    //ranran {56, 8},
    {64, 127},
    {248, 264},
    {-1, -1}
    };

    #ifdef CONFIG_ELBIT_BOARD
    /* McASP3 <-> AIC3101 */
    static struct snd_platform_data aic3x_snd_data_elbit = {
    .tx_dma_offset = 0x4A1A5000,
    .rx_dma_offset = 0x4A1A5000,
    .op_mode = DAVINCI_MCASP_IIS_MODE,
    .num_serializer = ARRAY_SIZE(aic3x_iis_serializer_direction_elbit),
    .tdm_slots = 2,
    .serial_dir = aic3x_iis_serializer_direction_elbit,
    .asp_chan_q = EVENTQ_0,
    .version = MCASP_VERSION_2,
    .txnumevt = 32,
    .rxnumevt = 32,
    /* McASP21_AHCLKX out to feed CODEC CLK*/
    .clk_input_pin = MCASP_AHCLKX_OUT,
    };
    #endif

    1106.shared.zip

    I think that the issue now with mcasp3, is not related to the device/cards, but more to DMA or event.

    I don't yet understand why it hangs with mcasp3...

    Thank you very much,

    Ran

  • Hi,

    I also checked the working device (plughw 0:0), and see that arecord can capture sound, but when I play the sound it sounds much faster than the real speed

    Maybe it is related to the clock configuration :

    fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF :

    sysclk = 24576000
    codec clk & FRM master
    L data MSB during FRM LRC
    invert BCLK + nor FRM
    Master Clock Directions: SND_SOC_CLOCK_OUT

    Regards,
    Ran
  • Ran,

    Are you using the same sample rate (8KHz, 11.025KHz, 16KHz, 22.05KHz, 32KHz, 44.1KHz, 48KHz, 64KHz, 88.2KHz and 96KHz) for both capture and playback?

    See also if the below e2e thread will be in help:
    e2e.ti.com/.../443431

    BR
    Pavel
  • Ran,

    You might also find useful info in the below e2e threads:

    e2e.ti.com/.../346626
    e2e.ti.com/.../246885
    e2e.ti.com/.../189626
    e2e.ti.com/.../253850

    BR
    Pavel
  • Hi Pavel,

    Thanks for the links.
    As to the speed issue (recorded file speed is not the real speed):
    I see that with the evaluation board aplay/arecord with no speed issues.
    I also know that I made no changes in terms of alsa in sw between the evm and custom board (except for pinmux, and added mcasp3 & codec ), so I suspect there must be some hw pll/clock defferences between custom board and evm.

    Regards,
    Ran
  • Hi,

    Is there any reason that can explain why card2 (mcasp3) call to arecord (capture) hangs ?
    Is it related to wrong dma configuration ? Or wrong interrupt ?
    I've checked and re-checked but found no error yet in the configurations.

    Thanks,
    Ran
  • Ran,

    If you disable McASP2 and enable McASP3 only, will aplay and arecord work fine on McASP3?

    BR
    Pavel
  • Hi Pavel,

    It still does not work , I suspect it some kind of HW issue ?
    It Probably means that there is wrong HW connectivity in the reciever side between codec->dma->mcasp3 , Right ?

    If this is the case, I better focus now on the problem with the more functional device (mcasp2).
    The speed issue (the speed in the recorded file is faster then the original captured audio): What can be wrong here ? As far as I understand we work with oscillator 24.5, which is the same as EVM, so I don't yet understand why it works fine in EVM, but not in the custom board.
    On opening the recorded file in audacity I see that sample rate is always 44100 (according to audacity and vlc info), even when arecord samples it in 8000. The thigs is that it sound correct in evaluation board but in custom board it sounf faster (speed is faster in rate of ~44.1/36 according to my testing).


    Regards,
    Ran

  • Ran,

    Ran Shalit said:
    It still does not work , I suspect it some kind of HW issue ?
    It Probably means that there is wrong HW connectivity in the reciever side between codec->dma->mcasp3 , Right ?

    If you suspect HW malfunction, I will recommend you to check your HW with the McASP diagnostic test, it is for DM814x EVM, so it might required some adjustment for you custom board:

    aic3106/

    This CCS test application configures the McASP2 on the DM814X EVM board and also the AIC3106 for the following.
    1. Playback on head phones
    2. Playback on Line-Out
    3. Record from Microphone and playback on Head-phones
    4. Record from Line-In and playback on Head-phones

    The test application executes in the above mentioned sequence. The Audio codec is configured to record and playback at 48 KHz sampling. The Codec is kept as I2S master with the Bit-clock & Frame-sync being input the McASP.

    You can also try to run aplay/arecord with --verbose option, to check if there will be some informative message before the hang.

    Note also that by default audio driver works in McASPx slave, codec master format.

    BR
    Pavel

  • Ran Shalit said:
    If this is the case, I better focus now on the problem with the more functional device (mcasp2).
    The speed issue (the speed in the recorded file is faster then the original captured audio): What can be wrong here ? As far as I understand we work with oscillator 24.5, which is the same as EVM, so I don't yet understand why it works fine in EVM, but not in the custom board.
    On opening the recorded file in audacity I see that sample rate is always 44100 (according to audacity and vlc info), even when arecord samples it in 8000. The thigs is that it sound correct in evaluation board but in custom board it sounf faster (speed is faster in rate of ~44.1/36 according to my testing).

    I assume you do not refer OSC or AUX but the oscillator providing the clock to the MCLK input of the AIC codec, the frequency there is 24.5760MHz.

    I would suggest to measure the frequencies of BCLK, WCLK and MCLK and compare the values between EVM and your custom board.

    BR
    Pavel

  • Hi Pavel,

    How are these clock configured ? Is it sw configuration or hardware ?
    I am trying to understand if there is some difference in code between evm and custom board which can explain this issue ?

    Regards,
    Ran
  • Ran,

    Check the below e2e thread regarding McASP and AIC clock config:

    e2e.ti.com/.../1632035

    BR
    Pavel
  • Hi Pavel,

    Thank you very much for this assistance.
    when we checked the schema of the evm board we see that the oscilator for MCLK is not 24.576Mhz but something else (I think 22.579MHz ), so maybe that explain the issue? The strange thing is that I see in code( Ti81xx_evm.c )that sysclk is explicitly written as 24576000.

    Is it correct that evm oscillator is not 24.5Mhz but other value?
    Are there any dividers which make 24576000 sysclk from that 26Mhz ? Can this explain the speed issue?

    Many Thanks,
    Ran

  • Another thing I would like to ask:

    Is this the configuration in evm:
    MCA2_ACLKX <------------ AIC_BCLK
    MCA2_AFSX <------------ AIC_WCLK

    MCA2_AHCLKX -----------> AIC_MCLK
    MCA2_AXR0 ------------> AIC_DIN
    MCA2_AXR1 <------------ AIC_DOUT

    If mcasp2 drives out the MCLK, why is it said that the codec is the master ?

    Thank you,
    Ran

  • Hi,

    I better close this thread and open another one concerning the speed issue.

    e2e.ti.com/.../453769

    Thank you,
    Ran