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.

McBSP I2S master on dm365: problems with frequency

Hello,

On the dm365 with 2.6.32.17 kernel (from the dvsdk 4.02) on a custom board I'm using i2s driver in sound/soc to transfer the sound data to digital input of a GSM module. I need the dm365 to be a master on i2s bus so I had to do some changes in the driver, which are based mainly on the commit a4c8ea2ddaed2f461606c2828b19786524b551ac in arago repository. Now I'm able to play sound with aplay, but the waveform is played on the half of its frequency (4khz instead of 8khz). I checked it with the scope and I can see that the McBSP_FSX signal is correct (8khz) but each sample is doubled on the data line, which gaves me the frequency reduction. As far as I understand the datasheet of the McBSP this is not caused by the hw, but probably by the DMA.
McBSP registers state during the playing is following:

SPCR 0x02300000
RCR 0x00000000
XCR 0x00440040
SRGR 0x303C0FF8
MCR 0x00000000
RCER 0x00000000
XCER 0x00000000
PCR 0x00000A0C

The dma transfers are served in the davinci-pcm.c file but I don't understand it fully, yet. Maybe the problem can be hidden in the SNDRV_PCM_INFO_INTERLEAVED flag for the snd_pcm_hardware?

Could please someone who is familiar with the sound/soc driver for the dm365 give me any advice how to make the McBSP to behave properly?

best regards
Jan

  • Can you mention the data format that you are trying to make use of? Also, if possible please post a diff of the changes that you did to get I2S master mode working.

    Regards,

    Vaibhav

  • Dear Vaibhav,

    thank you for the answer. Diff of the sound/soc directory against the kernel in 4.02 dvsdk is attached. I want to be able to play PCM wavs 8 or 16 kHz.

    Now the driver is modified to send two words in a frame, which is probably correct - samples from mono sound are doubled in soc core when SNDRV_PCM_INFO_INTERLEAVED flag is set in davinci-pcm.c. When checking the signals on a scope I noticed that all samples are doubled, but except the first one. This leads into a case when there are different words in a frame - I suspect this is not correct, but I don't know how to fix it.

    I have also another question - the driver will be used with gsm module and during a call we need to play and capture sound simultaneously. Is the driver capable of it?

    Note: In davinci_i2s_hw_params() I use constant values for the clocking 8khz just for testing purposes.

    best regards
    Jan

  • Dear Vaibhav,

    do you please have any comments to my questions?

    best regards
    Jan 

  • Hi,

    Audio driver is capable of handling two different threads, one for recording and the other for playing.

    Right now I do not have the answer for your other question. Let me check and get back to you.

    Regards, Sudhakar

  • Hi Sudhakar,

    thank you for the answer. I'm looking forward to the next information...

    regards
    Jan 

  • Hi,

    I assume you have made sure that McBSP is configured correctly for the I2S mode like Frame sync polarity etc.

    I would suggest, you post this question in ALSA development mailing list (alsa-devel@alsa-project.org).

    Regards, Sudhakar

  • Hi Jan,

    You have mentioned that you are seeing the problem when you are playing the mono file. Can you let me know the behavior when a stereo file is played? I would expect a channel swap in this scenario.

    Also, can you report back the behavior with the below modification in the davinci-i2s.c file:

    Change From:
     
    case SNDRV_PCM_FORMAT_S16_LE:
    dma_params->data_type = 2;
    mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
    break;
     
    To:
     
    case SNDRV_PCM_FORMAT_S16_LE:
    dma_params->data_type = 4;
    mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
    break;
     
    Regards,
    Sudhakar
  • Hello Sudhakar,

    I have been busy with some other work, but now I'm back on the i2s.

    According to your advice I checked the situation with the stereo file. It is exactly the same situation as with the mono one.

    When using test sequence 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff (this is the raw audio stream) I see the sequence 0xff 0xff 0x00 0x00 0x00 0x00 0xff 0xff 0xff 0xff on the scope -> the first 16 bits are missing.

    Changing  dma_params->data_type to 4 does not help - first word is still missing.

    best regards
    Jan 

  • Hello,

    I have finally discovered what is eating the first sample in my audio. I'm not sure why I did not notice it earlier.
    In the davinci-i2s.c in the davinci_mcbsp_start function there is following block

    if (playback) {
    /* Stop the DMA to avoid data loss */
    /* while the transmitter is out of reset to handle XSYNCERR */
    if (platform->pcm_ops->trigger) {
    int ret = platform->pcm_ops->trigger(substream,
    SNDRV_PCM_TRIGGER_STOP);
    if (ret < 0)
    printk(KERN_DEBUG "Playback DMA stop failed\n");
    }

    /* Enable the transmitter */
    spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
    spcr |= DAVINCI_MCBSP_SPCR_XRST;
    davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr);

    /* wait for any unexpected frame sync error to occur */
    udelay(100);

    /* Disable the transmitter to clear any outstanding XSYNCERR */
    spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
    spcr &= ~DAVINCI_MCBSP_SPCR_XRST;
    davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr);
    toggle_clock(dev, playback);

    /* Restart the DMA */
    if (platform->pcm_ops->trigger) {
    int ret = platform->pcm_ops->trigger(substream,
    SNDRV_PCM_TRIGGER_START);
    if (ret < 0)
    printk(KERN_DEBUG "Playback DMA start failed\n");
    }

    It starts and stops a transfer on the mcbsp but even when the dma is stopped (to avoid data losses as comment says) the first sample is lost which leads to channel swap. I'm not sure if this part of code is neccessary and why it was there. So far it works well without it and all samples are transfered correctly.

    regards
    Jan