Skip to contentSkip to conversation

McBSP: Provide functions for ASoC frame syncronization

PATCH In review [email protected] 2 participants 10 messages Jan 13, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover McBSP: Provide functions for ASoC frame syncronization

From: Eero Nurkkala <[email protected]>

McBSP along with ASoC has currently an annoying feature of switching L and R channels at random. Perceive this with aplay, having two mono waves sent to the different channels:
aplay -fdat -c2 -I Side_Left.wav Front_Center.wav One acknowledges that sometimes L channel is in place of L, but often times R channel is in place of L.

This set of patches fixed this problem.

#1 lore raw

PATCH 1/3 ARM: OMAP: Fix ASoC by enabling writes to XCCR and RCCR

From: Tony Lindgren <tony () atomide ! com>

[Download message RAW]

From: Tony Lindgren <Lopez>

This patch enables writing to McBSP Transmit Configuration Control Register (XCCR) and Receive Configuration Control Register (RCCR) for 2430/34xx platforms. It also adds XCCR, RCCR entries in McBSP register configuration structure and bit definitions for both registers.

If we enable the writing to CCR registers for 2430/34xx and don't set the default values (setting 0 as a consequence) in ASoC driver, the Transmit/Receive DMA mode gets disabled and the the transmission/reception doesn't happen, ending with a "write error: Input/Output error" when playing with 'aplay'.

---
 arch/arm/plat-omap/include/mach/mcbsp.h |    7 +++++++
 arch/arm/plat-omap/mcbsp.c              |    4 ++++
 2 files changed, 11 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/mach/mcbsp.h +7 -0
index 6a0d1a0..cc48f2f 100644
@@ -231,11 +231,16 @@
 #define XPBBLK(value)		((value)<<7)	/* Bits 7:8 */
 
 /*********************** McBSP XCCR bit definitions *************************/
+#define EXTCLKGATE		0x8000
+#define PPCONNECT		0x4000
+#define DXENDLY(value)		((value)<<12)	/* Bits 12:13 */
+#define XFULL_CYCLE		0x0800
 #define DILB			0x0020
 #define XDMAEN			0x0008
 #define XDISABLE		0x0001
 
 /********************** McBSP RCCR bit definitions *************************/
+#define RFULL_CYCLE		0x0800
 #define RDMAEN			0x0008
 #define RDISABLE		0x0001
 
@@ -267,6 +272,8 @@ struct omap_mcbsp_reg_cfg {
 	u16 rcerh;
 	u16 xcerg;
 	u16 xcerh;
+	u16 xccr;
+	u16 rccr;
 };
 
 typedef enum {
arch/arm/plat-omap/mcbsp.c +4 -0
index af33fc7..f2401a8 100644
@@ -173,6 +173,10 @@ void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config)
 	OMAP_MCBSP_WRITE(io_base, MCR2, config->mcr2);
 	OMAP_MCBSP_WRITE(io_base, MCR1, config->mcr1);
 	OMAP_MCBSP_WRITE(io_base, PCR0, config->pcr0);
+	if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+		OMAP_MCBSP_WRITE(io_base, XCCR, config->xccr);
+		OMAP_MCBSP_WRITE(io_base, RCCR, config->rccr);
+	}
 }
 EXPORT_SYMBOL(omap_mcbsp_config);
 
Signature · 1 line
1.5.2
#2 lore raw

PATCH 2/3 McBSP: Provide functions for ASoC frame syncronization

From: Eero Nurkkala <[email protected]>

ASoC has an annoying bug letting either L or R channel to be played on L channel. In other words, L and R channels can switch at random. This provides McBSP funtionality that may be used to fix this feature.

---
 arch/arm/plat-omap/include/mach/mcbsp.h |    2 +
 arch/arm/plat-omap/mcbsp.c              |   52 +++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/mach/mcbsp.h +2 -0
index cc48f2f..07dfcd0 100644
@@ -385,6 +385,8 @@ int omap_mcbsp_request(unsigned int id);
 void omap_mcbsp_free(unsigned int id);
 void omap_mcbsp_start(unsigned int id);
 void omap_mcbsp_stop(unsigned int id);
+void omap_mcbsp_xmit_enable(unsigned int id, u8 enable);
+void omap_mcbsp_recv_enable(unsigned int id, u8 enable);
 void omap_mcbsp_xmit_word(unsigned int id, u32 word);
 u32 omap_mcbsp_recv_word(unsigned int id);
 
arch/arm/plat-omap/mcbsp.c +52 -0

58 lines not on this page · raw message

Signature · 1 line
1.5.2
#3 lore raw

PATCH 3/3 ASoC: Always syncronize audio transfers on frames

From: Eero Nurkkala <[email protected]>

All these steps are required for ASoC to behave correctly. This is, no RFIG or XFIG (Not defined in 34xx), correct initiliazation of rccr and xccr. They are format dependent, for example TDM audio has different values than I2S or DSP_A. Also the omap_mcbsp_xmit_enable and/or omap_mcbsp_recv_enable must be called right after the DMA has started. This provides no longer L and R channels switching at random.

---
 sound/soc/omap/omap-mcbsp.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
sound/soc/omap/omap-mcbsp.c +14 -2
index 8485a8a..06b6367 100644
@@ -178,6 +178,11 @@ static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd)
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
 		if (!mcbsp_data->active++)
 			omap_mcbsp_start(mcbsp_data->bus_id);
+		/* Make sure data transfer is frame synchronized */
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			omap_mcbsp_xmit_enable(mcbsp_data->bus_id, 1);
+		else
+			omap_mcbsp_recv_enable(mcbsp_data->bus_id, 1);
 		break;
 
 	case SNDRV_PCM_TRIGGER_STOP:
@@ -293,19 +298,26 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 	/* Generic McBSP register settings */
 	regs->spcr2	|= XINTM(3) | FREE;
 	regs->spcr1	|= RINTM(3);
-	regs->rcr2	|= RFIG;
-	regs->xcr2	|= XFIG;
+	/* RFIG and XFIG are not defined in 34xx */
+	if (!cpu_is_omap34xx()) {
+		regs->rcr2	|= RFIG;
+		regs->xcr2	|= XFIG;
+	}
 
 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
 	case SND_SOC_DAIFMT_I2S:
 		/* 1-bit data delay */
 		regs->rcr2	|= RDATDLY(1);
 		regs->xcr2	|= XDATDLY(1);
+		regs->rccr	|= RFULL_CYCLE | RDMAEN | RDISABLE;
+		regs->xccr	|= (DXENDLY(1) | XDMAEN | XDISABLE);
 		break;
 	case SND_SOC_DAIFMT_DSP_A:
 		/* 0-bit data delay */
 		regs->rcr2      |= RDATDLY(0);
 		regs->xcr2      |= XDATDLY(0);
+		regs->rccr	|= RFULL_CYCLE | RDMAEN | RDISABLE;
+		regs->xccr	|= (DXENDLY(1) | XDMAEN | XDISABLE);
 		break;
 	default:
 		/* Unsupported data format */
Signature · 1 line
1.5.2
#4 lore raw

Re: [PATCH 3/3] ASoC: Always syncronize audio transfers on frames

Quoted 11 lines · On Tue, 13 Jan 2009 09:52:15 +0200 "ext [email protected]"…

From: Eero Nurkkala <[email protected]>

All these steps are required for ASoC to behave correctly. This is, no RFIG or XFIG (Not defined in 34xx), correct initiliazation of rccr and xccr. They are format dependent, for example TDM audio has different values than I2S or DSP_A. Also the omap_mcbsp_xmit_enable and/or omap_mcbsp_recv_enable must be called right after the DMA has started. This provides no longer L and R channels switching at random.

This needs to be separated. Misael have already patch for xccr and rccr initialization in sound/soc/omap/omap-mcbsp.c and he's waiting first patch to be integrated into mainline before posting into alsa-devel.

sound/soc/omap/omap-mcbsp.c static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai, · line 305

Quoted 11 lines
sound/soc/omap/omap-mcbsp.c +5 -2
@@ -293,19 +298,26 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
 	/* Generic McBSP register settings */
 	regs->spcr2	|= XINTM(3) | FREE;
 	regs->spcr1	|= RINTM(3);
-	regs->rcr2	|= RFIG;
-	regs->xcr2	|= XFIG;
+	/* RFIG and XFIG are not defined in 34xx */
+	if (!cpu_is_omap34xx()) {
+		regs->rcr2	|= RFIG;
+		regs->xcr2	|= XFIG;
+	}

This is true (checked now :-)) that RFIG and XFIG are not defined for 34xx (and 2430 as well!) but writing doesn't have any effect since the bit is read only. But since it's marked reserved, then better to not write it.

If you can generate patch against Torvald's tree, i.e. 2.6.29-rc1 and send to alsa-devel, I can ack it.

Jarkko

#5 lore raw

Re: [PATCH 3/3] ASoC: Always syncronize audio transfers on frames

Quoted 4 lines · Jarkko Nikula

This is true (checked now :-)) that RFIG and XFIG are not defined for 34xx (and 2430 as well!) but writing doesn't have any effect since the bit is read only. But since it's marked reserved, then better to not write it.

Good. This particular register setting caused troubles on the very first audio playback to never be played! =)

It needed the ASoC to finish the Damp, and after that, the thing was good to go for good. Thus, I highly consider this as something that is needed.

Quoted 5 lines

If you can generate patch against Torvald's tree, i.e. 2.6.29-rc1 and send to alsa-devel, I can ack it.

Jarkko

#6 lore raw
In reply to [email protected]
Quoted 7 lines · On Tue, 13 Jan 2009 09:52:14 +0200 "ext [email protected]"…

From: Eero Nurkkala <[email protected]>

ASoC has an annoying bug letting either L or R channel to be played on L channel. In other words, L and R channels can switch at random. This provides McBSP funtionality that may be used to fix this feature.

I can confirm this. Long lasting problem unfortunately not solved yet. This is visible on 2420 as well so this patch is not enough.

http://marc.info/?l=linux-omap&m=120643770810683&w=2

...

Quoted 11 lines
arch/arm/plat-omap/mcbsp.c +11 -0
+void omap_mcbsp_xmit_enable(unsigned int id, u8 enable)
+{
+	struct omap_mcbsp *mcbsp;
+	void __iomem *io_base;
+	u16 w;
+
+	if (!(cpu_is_omap2430() || cpu_is_omap34xx()))
+		return;
+
+	if (!omap_mcbsp_check_valid_id(id)) {
+		printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);

arch/arm/plat-omap/mcbsp.c void omap_mcbsp_stop(unsigned int id) · line 401

Quoted 10 lines
arch/arm/plat-omap/mcbsp.c +10 -0
+		return;
+	}
+
+	mcbsp = id_to_mcbsp_ptr(id);
+	io_base = mcbsp->io_base;
+
+	w = OMAP_MCBSP_READ(io_base, XCCR);
+
+	if (enable)
+		OMAP_MCBSP_WRITE(io_base, XCCR, w & ~(XDISABLE));

This doesn't fix problem on 2420. I assume when it works on 2420, the same fix will fix the 34xx as well. I fear the mcbsp initialization procedure in omap_mcbsp_start is not correct somewhat for 2420-34xx.

Jarkko

#7 lore raw
Quoted 3 lines · Jarkko Nikula

This doesn't fix problem on 2420. I assume when it works on 2420, the same fix will fix the 34xx as well. I fear the mcbsp initialization procedure in omap_mcbsp_start is not correct somewhat for 2420-34xx.

I somewhat disagree. I think this works OK, just fine. The "feature" appears, especially if codec (aic) is a master.

One cannot say in which state the WCLK (provided by aic) is. Aic is started prior to McBSP, right?
So when the DMA transfer starts, the WCLK may be about (depending on CPU load etc) to transition down, and then the L data goes into R data. As the BCLK clocks in the data. Right?

Of course I might be wrong.

#8 lore raw
Quoted 8 lines · On Tue, 13 Jan 2009 10:41:20 +0200 Eero Nurkkala <[email protected]>…
Quoted 3 lines · Jarkko Nikula

This doesn't fix problem on 2420. I assume when it works on 2420, the same fix will fix the 34xx as well. I fear the mcbsp initialization procedure in omap_mcbsp_start is not correct somewhat for 2420-34xx.

I somewhat disagree. I think this works OK, just fine. The "feature" appears, especially if codec (aic) is a master.

For me, the omap_mcbsp_xmit_enable and omap_mcbsp_recv_enable looks null op for 2420 so how it can fix problem on N810 (it has AIC33 as a master)?

Quoted 6 lines

One cannot say in which state the WCLK (provided by aic) is. Aic is started prior to McBSP, right?
So when the DMA transfer starts, the WCLK may be about (depending on CPU load etc) to transition down, and then the L data goes into R data. As the BCLK clocks in the data. Right?

Channel switching is easy to measure just by looking when playing L or R data only, that data transfer is started at random WCLK polarity. If it works, then e.g. left channel data should visible only in low-level of WCLK when using I2S (+1 bit delay).

IMO, it's task of McBSP block to synhronize properly independently is the McBSP master or slave for WCLK and to not start DMA transfer at random edge like it's doing now sometimes.

But something is clearly wrong why DMA transfer now sometimes starts at random edge? And why it seems to affect only playback, not capture?

Jarkko

#9 lore raw
Quoted 8 lines · Jarkko Nikula
Quoted 5 lines · On Tue, 13 Jan 2009 10:41:20 +0200 Eero Nurkkala <[email protected]>…
Quoted 3 lines · Jarkko Nikula

This doesn't fix problem on 2420. I assume when it works on 2420, the same fix will fix the 34xx as well. I fear the mcbsp initialization procedure in omap_mcbsp_start is not correct somewhat for 2420-34xx.

Quoted 6 lines
Quoted 3 lines

I somewhat disagree. I think this works OK, just fine. The "feature" appears, especially if codec (aic) is a master.

For me, the omap_mcbsp_xmit_enable and omap_mcbsp_recv_enable looks null op for 2420 so how it can fix problem on N810 (it has AIC33 as a master)?

I was talking about the initilization procedure only. Sorry for the open door for misinformation.

Quoted 9 lines

Channel switching is easy to measure just by looking when playing L or R data only, that data transfer is started at random WCLK polarity. If it works, then e.g. left channel data should visible only in low-level of WCLK when using I2S (+1 bit delay).

IMO, it's task of McBSP block to synhronize properly independently is the McBSP master or slave for WCLK and to not start DMA transfer at random edge like it's doing now sometimes.

That would be definitely a nice feature. Possibly something that cannot be fixed in 2420? (Maybe the XCCR and RCCR come to save the case).

Quoted 2 lines

But something is clearly wrong why DMA transfer now sometimes starts at random edge? And why it seems to affect only playback, not capture?

I've tried also to use 32bit DMA transfers unsuccessfully. (as TRM has a note that no less than 32 bit transfers should be used for McBSP). Unsuccessfully meaning it still gets out of L/R sync.

Hmm. Interesting, if it doesn't affect the capture; but it's somewhat different in the McBSP, possibly behaving differently. Something to be discussed with TI I guess...