Skip to contentSkip to conversation

ASoC: DaVinci: i2s: don't bounce through rtd to get dai

PATCH Applied Troy Kisky 3 participants 12 messages Aug 6, 2009 – Aug 11, 2009 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore

Troy Kisky

author
#0 lore raw

PATCH 1/5 ASoC: DaVinci: i2s: don't bounce through rtd to get dai

dai is a parameter to the functions, so use it instead of looking it up.

---
 sound/soc/davinci/davinci-i2s.c |   14 +++++---------
 1 files changed, 5 insertions(+), 9 deletions(-)
sound/soc/davinci/davinci-i2s.c +5 -9
index e5cd97b..2a56fb7 100644
@@ -353,9 +353,8 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
 				 struct snd_pcm_hw_params *params,
 				 struct snd_soc_dai *dai)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data;
-	struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
+	struct davinci_pcm_dma_params *dma_params = dai->dma_data;
+	struct davinci_mcbsp_dev *dev = dai->private_data;
 	struct snd_interval *i = NULL;
 	int mcbsp_word_length;
 	unsigned int rcr, xcr, srgr;
@@ -425,8 +424,7 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
 static int davinci_i2s_prepare(struct snd_pcm_substream *substream,
 		struct snd_soc_dai *dai)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
+	struct davinci_mcbsp_dev *dev = dai->private_data;
 	int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 	davinci_mcbsp_stop(dev, playback);
 	if ((dev->pcr & DAVINCI_MCBSP_PCR_FSXM) == 0) {
@@ -439,8 +437,7 @@ static int davinci_i2s_prepare(struct snd_pcm_substream *substream,
 static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 			       struct snd_soc_dai *dai)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
+	struct davinci_mcbsp_dev *dev = dai->private_data;
 	int ret = 0;
 	int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 	if ((dev->pcr & DAVINCI_MCBSP_PCR_FSXM) == 0)
@@ -466,8 +463,7 @@ static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
 static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
 		struct snd_soc_dai *dai)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
+	struct davinci_mcbsp_dev *dev = dai->private_data;
 	int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 	davinci_mcbsp_stop(dev, playback);
 }
Signature · 1 line
1.5.6.3

A message that is not in the archive (sent off-list or not yet received): 1249602935-1267-1-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org

#2 lore raw

PATCH 2/5 ASoC: DaVinci: pcm, constrain buffer size to multiple of period

The dma setup code assumes that the buffer size is a multiple of the period size.

---
 sound/soc/davinci/davinci-pcm.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
sound/soc/davinci/davinci-pcm.c +5 -0
index fbda8ef..a294711 100644
@@ -244,6 +244,11 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
 	int ret = 0;
 
 	snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
+	/* ensure that buffer size is a multiple of period size */
+	ret = snd_pcm_hw_constraint_integer(runtime,
+						SNDRV_PCM_HW_PARAM_PERIODS);
+	if (ret < 0)
+		return ret;
 
 	prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
 	if (prtd == NULL)
Signature · 1 line
1.5.6.3
author
#3 lore raw

PATCH 3/5 ASoC: DaVinci: i2s, reduce underruns by combining into 1 element

Allow the left and right 16 bit samples to be shifted out as 1 32 bit sample.

---
 arch/arm/mach-davinci/include/mach/asp.h |    6 +++
 sound/soc/davinci/davinci-i2s.c          |   73 ++++++++++++++++++++++-------
 2 files changed, 61 insertions(+), 18 deletions(-)
arch/arm/mach-davinci/include/mach/asp.h +6 -0
index cdf1f44..73b60b6 100644
@@ -37,6 +37,12 @@ struct snd_platform_data {
 	u32 rx_dma_offset;
 	enum dma_event_q eventq_no;	/* event queue number */
 	unsigned int codec_fmt;
+	/*
+	 * Allowing this is more efficient and eliminates left and right swaps
+	 * caused by underruns, but will swap the left and right channels
+	 * when compared to previous behavior.
+	 */
+	unsigned disable_channel_combine:1;
 
 	/* McASP specific fields */
 	int tdm_slots;
sound/soc/davinci/davinci-i2s.c +55 -18

106 lines not on this page · raw message

Signature · 1 line
1.5.6.3
author
#4 lore raw

PATCH 4/5 ASoC: DaVinci: pcm, rename variables in prep for ping/pong

Rename variable master_lch to asp_master_lch
Rename variable slave_lch to asp_link_lch[0]

---
 sound/soc/davinci/davinci-pcm.c |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)
sound/soc/davinci/davinci-pcm.c +19 -19
index a294711..3489f18 100644
@@ -51,8 +51,8 @@ static struct snd_pcm_hardware davinci_pcm_hardware = {
 struct davinci_runtime_data {
 	spinlock_t lock;
 	int period;		/* current DMA period */
-	int master_lch;		/* Master DMA channel */
-	int slave_lch;		/* linked parameter RAM reload slot */
+	int asp_master_lch;	/* Master DMA channel */
+	int asp_link_lch[2];	/* asp parameter link channel, ping/pong */
 	struct davinci_pcm_dma_params *params;	/* DMA params */
 };
 
@@ -60,7 +60,7 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
 {
 	struct davinci_runtime_data *prtd = substream->runtime->private_data;
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	int lch = prtd->slave_lch;
+	int lch = prtd->asp_link_lch[0];
 	unsigned int period_size;
 	unsigned int dma_offset;
 	dma_addr_t dma_pos;
@@ -140,15 +140,15 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
 				  EVENTQ_0);
 	if (ret < 0)
 		return ret;
-	prtd->master_lch = ret;
+	prtd->asp_master_lch = ret;
 
 	/* Request parameter RAM reload slot */
-	ret = edma_alloc_slot(EDMA_CTLR(prtd->master_lch), EDMA_SLOT_ANY);
+	ret = edma_alloc_slot(EDMA_CTLR(prtd->asp_master_lch), EDMA_SLOT_ANY);
 	if (ret < 0) {
-		edma_free_channel(prtd->master_lch);
+		edma_free_channel(prtd->asp_master_lch);
 		return ret;
 	}
-	prtd->slave_lch = ret;
+	prtd->asp_link_lch[0] = ret;
 
 	/* Issue transfer completion IRQ when the channel completes a
 	 * transfer, then always reload from the same slot (by a kind
@@ -159,10 +159,10 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
 	 * the buffer and its length (ccnt) ... use it as a template
 	 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
 	 */
-	edma_read_slot(prtd->slave_lch, &p_ram);
-	p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->master_lch));
-	p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->slave_lch) << 5;
-	edma_write_slot(prtd->slave_lch, &p_ram);
+	edma_read_slot(prtd->asp_link_lch[0], &p_ram);
+	p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_master_lch));
+	p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->asp_link_lch[0]) << 5;
+	edma_write_slot(prtd->asp_link_lch[0], &p_ram);
 
 	return 0;
 }
@@ -178,12 +178,12 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		edma_start(prtd->master_lch);
+		edma_start(prtd->asp_master_lch);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		edma_stop(prtd->master_lch);
+		edma_stop(prtd->asp_master_lch);
 		break;
 	default:
 		ret = -EINVAL;
@@ -204,8 +204,8 @@ static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
 	davinci_pcm_enqueue_dma(substream);
 
 	/* Copy self-linked parameter RAM entry into master channel */
-	edma_read_slot(prtd->slave_lch, &temp);
-	edma_write_slot(prtd->master_lch, &temp);
+	edma_read_slot(prtd->asp_link_lch[0], &temp);
+	edma_write_slot(prtd->asp_master_lch, &temp);
 	davinci_pcm_enqueue_dma(substream);
 
 	return 0;
@@ -222,7 +222,7 @@ davinci_pcm_pointer(struct snd_pcm_substream *substream)
 
 	spin_lock(&prtd->lock);
 
-	edma_get_position(prtd->master_lch, &src, &dst);
+	edma_get_position(prtd->asp_master_lch, &src, &dst);
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		count = src - runtime->dma_addr;
 	else
@@ -272,10 +272,10 @@ static int davinci_pcm_close(struct snd_pcm_substream *substream)
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct davinci_runtime_data *prtd = runtime->private_data;
 
-	edma_unlink(prtd->slave_lch);
+	edma_unlink(prtd->asp_link_lch[0]);
 
-	edma_free_slot(prtd->slave_lch);
-	edma_free_channel(prtd->master_lch);
+	edma_free_slot(prtd->asp_link_lch[0]);
+	edma_free_channel(prtd->asp_master_lch);
 
 	kfree(prtd);
 
Signature · 1 line
1.5.6.3
author
#5 lore raw

PATCH 5/5 ASoC: DaVinci: pcm, fix underruns by using sram

Fix underruns by using dma to copy 1st to sram in a ping/pong buffer style and then copying from the sram to the ASP. This also has the advantage of tolerating very long interrupt latency on dma completion.

---
 arch/arm/mach-davinci/include/mach/asp.h |    2 +
 sound/soc/davinci/davinci-i2s.c          |    5 +-
 sound/soc/davinci/davinci-pcm.c          |  471 +++++++++++++++++++++++++++---
 sound/soc/davinci/davinci-pcm.h          |    1 +
 4 files changed, 435 insertions(+), 44 deletions(-)
arch/arm/mach-davinci/include/mach/asp.h +2 -0
index 73b60b6..0fdbf45 100644
@@ -43,6 +43,8 @@ struct snd_platform_data {
 	 * when compared to previous behavior.
 	 */
 	unsigned disable_channel_combine:1;
+	unsigned sram_size_playback;
+	unsigned sram_size_capture;
 
 	/* McASP specific fields */
 	int tdm_slots;
sound/soc/davinci/davinci-i2s.c +4 -1
index 9587e00..129684d 100644
@@ -559,8 +559,11 @@ static int davinci_i2s_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto err_release_region;
 	}
-	if (pdata)
+	if (pdata) {
 		dev->disable_channel_combine = pdata->disable_channel_combine;
+		davinci_i2s_pcm_out.sram_size = pdata->sram_size_playback;
+		davinci_i2s_pcm_in.sram_size = pdata->sram_size_capture;
+	}
 	dev->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk)) {
 		ret = -ENODEV;
sound/soc/davinci/davinci-pcm.c +428 -43

591 lines not on this page · raw message

sound/soc/davinci/davinci-pcm.h +1 -0
index eb4287f..8d66b35 100644
@@ -20,6 +20,7 @@ struct davinci_pcm_dma_params {
 	char *name;			/* stream identifier */
 	int channel;			/* sync dma channel ID */
 	dma_addr_t dma_addr;		/* device physical address for DMA */
+	unsigned sram_size;
 	enum dma_event_q eventq_no;	/* event queue number */
 	unsigned char data_type;	/* xfer data type */
 	unsigned char convert_mono_stereo;
Signature · 1 line
1.5.6.3
author
#6 lore raw

Re: [PATCH 5/5] ASoC: DaVinci: pcm, fix underruns by using sram

Quoted 39 lines · Troy Kisky

Fix underruns by using dma to copy 1st to sram in a ping/pong buffer style and then copying from the sram to the ASP. This also has the advantage of tolerating very long interrupt latency on dma completion.

static int davinci_pcm_dma_request(struct snd_pcm_substream *substream) {

sound/soc/davinci/davinci-pcm.c +7 -13
+	struct snd_dma_buffer *iram_dma;
 	struct davinci_runtime_data *prtd = substream->runtime->private_data;
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
-	struct edmacc_param p_ram;
-	int ret;
+	int lch;
 
 	if (!dma_data)
 		return -ENODEV;
 
 	prtd->params = dma_data;
 
-	/* Request master DMA channel */
-	ret = edma_alloc_channel(prtd->params->channel,
-				  davinci_pcm_dma_irq, substream,
-				  EVENTQ_0);
-	if (ret < 0)
-		return ret;
-	prtd->asp_master_lch = ret;
+	/* Request asp master DMA channel */
+	lch = prtd->asp_master_lch = edma_alloc_channel(dma_data->channel,
+			davinci_pcm_dma_irq, substream, EVENTQ_0);
+	if (lch < 0)
+		goto exit1;
 
-	/* Request parameter RAM reload slot */
-	ret = edma_alloc_slot(EDMA_CTLR(prtd->asp_master_lch), EDMA_SLOT_ANY);
-	if (ret < 0) {
-		edma_free_channel(prtd->asp_master_lch);

sound/soc/davinci/davinci-pcm.c static void davinci_pcm_dma_irq(unsigned lch, u16 ch_status, void *data) · line 444

Quoted 10 lines
sound/soc/davinci/davinci-pcm.c +7 -3
-		return ret;
-	}
-	prtd->asp_link_lch[0] = ret;
+	/* Request asp link channels */
+	lch = prtd->asp_link_lch[0] = edma_alloc_slot(
+			EDMA_CTLR(prtd->asp_master_lch), EDMA_SLOT_ANY);
+	if (lch < 0)
+		goto exit2;
+
+	allocate_sram(substream, dma_data->sram_size);

This is allocated too late for the "ensure that buffer size is a multiple of period size" constraint.

I have a patch after fixing other feedback.

Troy

#7 lore raw

Re: [PATCH 5/5] ASoC: DaVinci: pcm, fix underruns by using sram

Quoted 4 lines · Troy Kisky

This is allocated too late for the "ensure that buffer size is a multiple of period size" constraint.

I have a patch after fixing other feedback.

It looks good to me - I've no issues with the patch except for the one I mentioned last time about considering ignoring the data in SRAM when reporting the current position but I'm happy either way. The patch will run into the cross tree issues with the platform data like the channel combining one, probably best to submit patches against Kevin's tree for now (or wait until after the merge window).

Have you tested with PulseAudio? If not it'd be worth giving it a spin
- it's one of the more demanding applications.

author
#8 lore raw

Re: [PATCH 5/5] ASoC: DaVinci: pcm, fix underruns by using sram

Quoted 14 lines · Mark Brown
Quoted 4 lines · Troy Kisky

This is allocated too late for the "ensure that buffer size is a multiple of period size" constraint.

I have a patch after fixing other feedback.

It looks good to me - I've no issues with the patch except for the one I mentioned last time about considering ignoring the data in SRAM when reporting the current position but I'm happy either way. The patch will run into the cross tree issues with the platform data like the channel combining one, probably best to submit patches against Kevin's tree for now (or wait until after the merge window).

Quoted 3 lines

Have you tested with PulseAudio? If not it'd be worth giving it a spin
- it's one of the more demanding applications.

I haven't tested with PulseAudio, and I don't have time to look into it currently. Any volunteers?

On question I had concerns davinci_pcm_hardware. It is currently for both playback and capture. Since allocate_sram contains "davinci_pcm_hardware.period_bytes_max = size;," should I change davinci_pcm_hardware to playback_pcm_hardware, capture_pcm_hardware?

#9 lore raw

Re: [PATCH 5/5] ASoC: DaVinci: pcm, fix underruns by using sram

Quoted 3 lines · Troy Kisky

On question I had concerns davinci_pcm_hardware. It is currently for both playback and capture. Since allocate_sram contains "davinci_pcm_hardware.period_bytes_max = size;," should I change davinci_pcm_hardware to playback_pcm_hardware, capture_pcm_hardware?

I guess you'll need to, yes.

#10 lore raw

Re: [PATCH 3/5] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element

In reply to Troy Kisky

arch/arm/mach-davinci/include/mach/asp.h struct snd_platform_data { · line 45

Quoted 10 lines · Troy Kisky
arch/arm/mach-davinci/include/mach/asp.h +6 -0
@@ -37,6 +37,12 @@ struct snd_platform_data {
 	u32 rx_dma_offset;
 	enum dma_event_q eventq_no;	/* event queue number */
 	unsigned int codec_fmt;
+	/*
+	 * Allowing this is more efficient and eliminates left and right swaps
+	 * caused by underruns, but will swap the left and right channels
+	 * when compared to previous behavior.
+	 */
+	unsigned disable_channel_combine:1;

It seems rather surprising to have this be enabled by default given that it does swap the channels - I'd expect it to catch people out and it's not really obvious that Linux would do something like this and it's not quite so discoverable as it might be. On the other hand, it does sound like a useful performance win though I'm not sure how bad the problems are in general and if the use of SRAM won't deal with things well enough.

I'll apply the patch, copying the comment here into the commit message to make things more discoverable, but I'd strongly suggest considering a followup patch which changes the default to the original behaviour. It might even be worth making the behaviour runtime configurable.

Acked-by
#11 lore raw

Re: [PATCH 3/5] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element

Quoted 4 lines · Mark Brown

I'll apply the patch, copying the comment here into the commit message to make things more discoverable, but I'd strongly suggest considering a followup patch which changes the default to the original behaviour. It might even be worth making the behaviour runtime configurable.

...or not, the change to asp.h doesn't apply at all in ASoC - the platform data is only present in Kevin's tree at the minute. I'm happy for it to get merged that way, but best to check for cross tree issues and I would like to see something about the L/R swap in the commit log for discoverabiity (or the default changing).