public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] at73c213: Fix DMA size at the end of DMA buffer
@ 2008-03-10 14:43 Atsushi Nemoto
  2008-03-14  9:44 ` Haavard Skinnemoen
  0 siblings, 1 reply; 8+ messages in thread
From: Atsushi Nemoto @ 2008-03-10 14:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Hans-Christian Egtvedt, Haavard Skinnemoen, Andrew Victor

The interrupt handler always provide runtime->period_size data, but it
should provide additional residual data when the pointer back to zero.

This patch fixes periodic click noise when runtime->buffer_size was
not multiple of runtime->period_size.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
This patch depends on a patch titled "at73c213: Monaural support".

diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 7c077c6..d614a8c 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -355,6 +355,7 @@ static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
 	u32 status;
 	int offset;
 	int block_size;
+	int size;
 	int next_period;
 	int retval = IRQ_NONE;
 
@@ -372,11 +373,14 @@ static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
 			next_period = 0;
 
 		offset = block_size * next_period;
+		size = runtime->period_size * runtime->channels;
+		if (next_period == runtime->periods - 1)
+			size += (runtime->buffer_size % runtime->period_size)
+				* runtime->channels;
 
 		ssc_writel(chip->ssc->regs, PDC_TNPR,
 				(long)runtime->dma_addr + offset);
-		ssc_writel(chip->ssc->regs, PDC_TNCR,
-				runtime->period_size * runtime->channels);
+		ssc_writel(chip->ssc->regs, PDC_TNCR, size);
 		retval = IRQ_HANDLED;
 	}
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-10 14:43 [PATCH] at73c213: Fix DMA size at the end of DMA buffer Atsushi Nemoto
@ 2008-03-14  9:44 ` Haavard Skinnemoen
  2008-03-14 13:29   ` Atsushi Nemoto
  0 siblings, 1 reply; 8+ messages in thread
From: Haavard Skinnemoen @ 2008-03-14  9:44 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: linux-kernel, Hans-Christian Egtvedt, Andrew Victor

On Mon, 10 Mar 2008 23:43:06 +0900 (JST)
Atsushi Nemoto <anemo@mba.ocn.ne.jp> wrote:

> +		size = runtime->period_size * runtime->channels;
> +		if (next_period == runtime->periods - 1)
> +			size += (runtime->buffer_size % runtime->period_size)
> +				* runtime->channels;

Ow. That looks expensive. Isn't there any way we can force the client
to select sane values of buffer_size and period_size?

It seems like a reasonable demand that buffer_size is a multiple of
period_size, doesn't it?

Haavard

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-14  9:44 ` Haavard Skinnemoen
@ 2008-03-14 13:29   ` Atsushi Nemoto
  2008-03-14 13:39     ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Atsushi Nemoto @ 2008-03-14 13:29 UTC (permalink / raw)
  To: haavard.skinnemoen; +Cc: linux-kernel, hcegtvedt, avictor.za, tiwai

On Fri, 14 Mar 2008 10:44:45 +0100, Haavard Skinnemoen <haavard.skinnemoen@atmel.com> wrote:
> > +		size = runtime->period_size * runtime->channels;
> > +		if (next_period == runtime->periods - 1)
> > +			size += (runtime->buffer_size % runtime->period_size)
> > +				* runtime->channels;
> 
> Ow. That looks expensive. Isn't there any way we can force the client
> to select sane values of buffer_size and period_size?

Well, I suppose it is not _too_ expensive. :)

> It seems like a reasonable demand that buffer_size is a multiple of
> period_size, doesn't it?

But actually it can happen.  And I gave up understanding how are these
parameters determined...  If there were any way the driver can enforce
that constraint, it would be better fix.

Iwai-san, any comments from alsa guru?

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-14 13:29   ` Atsushi Nemoto
@ 2008-03-14 13:39     ` Takashi Iwai
  2008-03-17 13:00       ` Atsushi Nemoto
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2008-03-14 13:39 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: haavard.skinnemoen, linux-kernel, hcegtvedt, avictor.za

At Fri, 14 Mar 2008 22:29:32 +0900 (JST),
Atsushi Nemoto wrote:
> 
> On Fri, 14 Mar 2008 10:44:45 +0100, Haavard Skinnemoen <haavard.skinnemoen@atmel.com> wrote:
> > > +		size = runtime->period_size * runtime->channels;
> > > +		if (next_period == runtime->periods - 1)
> > > +			size += (runtime->buffer_size % runtime->period_size)
> > > +				* runtime->channels;
> > 
> > Ow. That looks expensive. Isn't there any way we can force the client
> > to select sane values of buffer_size and period_size?
> 
> Well, I suppose it is not _too_ expensive. :)
> 
> > It seems like a reasonable demand that buffer_size is a multiple of
> > period_size, doesn't it?
> 
> But actually it can happen.  And I gave up understanding how are these
> parameters determined...  If there were any way the driver can enforce
> that constraint, it would be better fix.
> 
> Iwai-san, any comments from alsa guru?

Add the following constraint in the open callback:

	err = snd_pcm_hw_constraint_integer(runtime,
					SNDRV_PCM_HW_PARAM_PERIODS);
	if (err < 0)
		return err;

This will guarantee that the period size fits with the buffer size.


Takashi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-14 13:39     ` Takashi Iwai
@ 2008-03-17 13:00       ` Atsushi Nemoto
  2008-03-17 13:21         ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Atsushi Nemoto @ 2008-03-17 13:00 UTC (permalink / raw)
  To: tiwai; +Cc: haavard.skinnemoen, linux-kernel, hcegtvedt, avictor.za

On Fri, 14 Mar 2008 14:39:42 +0100, Takashi Iwai <tiwai@suse.de> wrote:
> Add the following constraint in the open callback:
> 
> 	err = snd_pcm_hw_constraint_integer(runtime,
> 					SNDRV_PCM_HW_PARAM_PERIODS);
> 	if (err < 0)
> 		return err;
> 
> This will guarantee that the period size fits with the buffer size.

Thank you!  It works fine.  Here is a new patch.


------------------------------------------------------
Subject: [PATCH] at73c213: Add constraints for periods value
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>

The interrupt handler always provide runtime->period_size data, so it
works correctly only if buffer_size was a multiple of period_size.

This patch fixes periodic click noise.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
This patch obsoletes a patch titled "at73c213: fix DMA size at the end
of DMA buffer" in git-alsa-tiwai.patch in mm tree.

diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 7c077c6..9a5c118 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -210,7 +210,13 @@ static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
 {
 	struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
 	struct snd_pcm_runtime *runtime = substream->runtime;
+	int err;
 
+	/* ensure buffer_size is a multiple of period_size */
+	err = snd_pcm_hw_constraint_integer(runtime,
+					SNDRV_PCM_HW_PARAM_PERIODS);
+	if (err < 0)
+		return err;
 	snd_at73c213_playback_hw.rate_min = chip->bitrate;
 	snd_at73c213_playback_hw.rate_max = chip->bitrate;
 	runtime->hw = snd_at73c213_playback_hw;

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-17 13:00       ` Atsushi Nemoto
@ 2008-03-17 13:21         ` Takashi Iwai
  2008-03-17 13:32           ` Atsushi Nemoto
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2008-03-17 13:21 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: haavard.skinnemoen, linux-kernel, hcegtvedt, avictor.za

At Mon, 17 Mar 2008 22:00:27 +0900 (JST),
Atsushi Nemoto wrote:
> 
> On Fri, 14 Mar 2008 14:39:42 +0100, Takashi Iwai <tiwai@suse.de> wrote:
> > Add the following constraint in the open callback:
> > 
> > 	err = snd_pcm_hw_constraint_integer(runtime,
> > 					SNDRV_PCM_HW_PARAM_PERIODS);
> > 	if (err < 0)
> > 		return err;
> > 
> > This will guarantee that the period size fits with the buffer size.
> 
> Thank you!  It works fine.  Here is a new patch.

Thanks for the patch.  So, I should revert your last patch, right?
It's already on ALSA tree...


Takashi

> 
> ------------------------------------------------------
> Subject: [PATCH] at73c213: Add constraints for periods value
> From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> 
> The interrupt handler always provide runtime->period_size data, so it
> works correctly only if buffer_size was a multiple of period_size.
> 
> This patch fixes periodic click noise.
> 
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
> ---
> This patch obsoletes a patch titled "at73c213: fix DMA size at the end
> of DMA buffer" in git-alsa-tiwai.patch in mm tree.
> 
> diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
> index 7c077c6..9a5c118 100644
> --- a/sound/spi/at73c213.c
> +++ b/sound/spi/at73c213.c
> @@ -210,7 +210,13 @@ static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
>  {
>  	struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
>  	struct snd_pcm_runtime *runtime = substream->runtime;
> +	int err;
>  
> +	/* ensure buffer_size is a multiple of period_size */
> +	err = snd_pcm_hw_constraint_integer(runtime,
> +					SNDRV_PCM_HW_PARAM_PERIODS);
> +	if (err < 0)
> +		return err;
>  	snd_at73c213_playback_hw.rate_min = chip->bitrate;
>  	snd_at73c213_playback_hw.rate_max = chip->bitrate;
>  	runtime->hw = snd_at73c213_playback_hw;
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-17 13:21         ` Takashi Iwai
@ 2008-03-17 13:32           ` Atsushi Nemoto
  2008-03-17 13:54             ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Atsushi Nemoto @ 2008-03-17 13:32 UTC (permalink / raw)
  To: tiwai; +Cc: haavard.skinnemoen, linux-kernel, hcegtvedt, avictor.za

On Mon, 17 Mar 2008 14:21:16 +0100, Takashi Iwai <tiwai@suse.de> wrote:
> > Thank you!  It works fine.  Here is a new patch.
> 
> Thanks for the patch.  So, I should revert your last patch, right?
> It's already on ALSA tree...

Yes, please.  Thank you.

---
Atsushi Nemoto

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] at73c213: Fix DMA size at the end of DMA buffer
  2008-03-17 13:32           ` Atsushi Nemoto
@ 2008-03-17 13:54             ` Takashi Iwai
  0 siblings, 0 replies; 8+ messages in thread
From: Takashi Iwai @ 2008-03-17 13:54 UTC (permalink / raw)
  To: Atsushi Nemoto; +Cc: haavard.skinnemoen, linux-kernel, hcegtvedt, avictor.za

At Mon, 17 Mar 2008 22:32:29 +0900 (JST),
Atsushi Nemoto wrote:
> 
> On Mon, 17 Mar 2008 14:21:16 +0100, Takashi Iwai <tiwai@suse.de> wrote:
> > > Thank you!  It works fine.  Here is a new patch.
> > 
> > Thanks for the patch.  So, I should revert your last patch, right?
> > It's already on ALSA tree...
> 
> Yes, please.  Thank you.

Done.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-03-17 13:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-10 14:43 [PATCH] at73c213: Fix DMA size at the end of DMA buffer Atsushi Nemoto
2008-03-14  9:44 ` Haavard Skinnemoen
2008-03-14 13:29   ` Atsushi Nemoto
2008-03-14 13:39     ` Takashi Iwai
2008-03-17 13:00       ` Atsushi Nemoto
2008-03-17 13:21         ` Takashi Iwai
2008-03-17 13:32           ` Atsushi Nemoto
2008-03-17 13:54             ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox