Hi, as we will be using multiple codecs on McASP, we have put the codecs as slaves.
We are also using a 8.192MHz external master clock.
Linux is v3.3; at the moment, we have patched davinci-mcasp.c to handle this mode ("SND_SOC_DAIFMT_EM_CBS_CFS"), and refer to it for the CPU DAI configuration in the machine driver:
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c index 95441bf..167d5cf 100644 --- a/sound/soc/davinci/davinci-mcasp.c +++ b/sound/soc/davinci/davinci-mcasp.c @@ -461,6 +496,21 @@ static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR); break; + + case SND_SOC_DAIFMT_EM_CBS_CFS: + /* external master clock, cpu generates bit and frame clocks */ + mcasp_clr_bits(base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); + mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); + mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); + + mcasp_clr_bits(base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); + mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); + mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); + + mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, AHCLKX | AHCLKR); + mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, ACLKX | ACLKR); + mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, AFSX | AFSR); + break; default: return -EINVAL;
Our setup currently has an AIC3X codec, connected to the TX clocks of McASP.
The RX clocks are not used, they are left hanging, so we need to enable the TX clocks even when recording:
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c index 95441bf..167d5cf 100644 --- a/sound/soc/davinci/davinci-mcasp.c +++ b/sound/soc/davinci/davinci-mcasp.c @@ -291,6 +292,9 @@ #define DAVINCI_MCASP_NUM_SERIALIZER 16 +static int playing = 0; +static int recording = 0; static inline void mcasp_set_bits(void __iomem *reg, u32 val) { __raw_writel(__raw_readl(reg) | val, reg); @@ -346,6 +355,12 @@ static void mcasp_start_rx(struct davinci_audio_dev *dev) mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); + + if (!playing) { + pr_debug("%s: also starting tx\n", __func__); + mcasp_start_tx(dev); + } + } static void mcasp_start_tx(struct davinci_audio_dev *dev) @@ -384,23 +406,36 @@ static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream) mcasp_set_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); mcasp_start_tx(dev); + playing = 1; } else { if (dev->rxnumevt) /* enable FIFO */ mcasp_set_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); mcasp_start_rx(dev); + recording = 1; } } static void mcasp_stop_rx(struct davinci_audio_dev *dev) { + recording = 0; + pr_debug("%s\n", __func__); mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, 0); mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); + if (!playing) { + pr_debug("%s: not playing, shutting down tx too\n", __func__); + mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); + } } static void mcasp_stop_tx(struct davinci_audio_dev *dev) { - mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); + playing = 0; + pr_debug("%s\n", __func__); + if (!recording) { + pr_debug("%s: not recording, shutting down\n", __func__); + mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); + } mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); } @@ -641,11 +691,21 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) # wrong numbers mcasp_clr_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); if (stream == SNDRV_PCM_STREAM_PLAYBACK) { - /* bit stream is MSB first with no delay */ + /* bit stream is MSB first with no delay */ /* DSP_B mode */ + /* HACK: disable master transmit clock generation mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); + */ mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask); mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD); @@ -661,13 +721,22 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) /* bit stream is MSB first with no delay */ /* DSP_B mode */ mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD); + /* HACK: disable master receive clock generation mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); + */ mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask); - if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) + if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) { mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRMOD(dev->tdm_slots), FSRMOD(0x1FF)); + + if (!playing) { + /* HACK: generate frame sync for Tx too */ + mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, + FSXMOD(dev->tdm_slots), FSXMOD(0x1FF)); + } + } else printk(KERN_ERR "capture tdm slot %d not supported\n", dev->tdm_slots);
We only plan to support 32kHz, so currently we have left an ugly hack in the code:
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c index 95441bf..167d5cf 100644 --- a/sound/soc/davinci/davinci-mcasp.c +++ b/sound/soc/davinci/davinci-mcasp.c @@ -641,11 +691,21 @@ static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) mcasp_clr_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); + /* UGLY: set clock divider, no support for frequencies != 32k + * + * We want 32kHz FCLK with 32bits (left, right) transferred for + * every frame, so it makes a 1.024MHz BCLK (/8). + */ + mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXDIV(8-1), + ACLKXDIV_MASK); + if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
It almost works, but we have a nasty problem:
- When performing a capture alone, the sound is recorded as expected
- When performing a playback alone, no problem
- When starting a playback then a capture, no problem
- When starting a capture then a playback, the playback will hang, the stream won't accept more data; no perturbation on the recording side
Currently I am reviewing the McASP code with regards to SPRUH77A (OMAP-L138 Technical Reference Manual), but some help would be appreciated.
Regards,