linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: AMD: Add delay before starting to capture
@ 2019-01-03 10:18 Agrawal, Akshu
  2019-01-04 12:27 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Agrawal, Akshu @ 2019-01-03 10:18 UTC (permalink / raw)
  Cc: Agrawal, Akshu, djkurtz, Deucher, Alexander, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, Mukunda, Vijendar,
	Kuninori Morimoto, Wei Yongjun,
	moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

On capture through dmic we observe a glitch at the start of record.
This is because we start capturing even before dmic is ready to send
out data. The glitch seen last for ~20msec.

Signed-off-by: Akshu Agrawal <akshu.agrawal@amd.com>
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 sound/soc/amd/acp-da7219-max98357a.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/sound/soc/amd/acp-da7219-max98357a.c b/sound/soc/amd/acp-da7219-max98357a.c
index a5daad9..72b1cf4 100644
--- a/sound/soc/amd/acp-da7219-max98357a.c
+++ b/sound/soc/amd/acp-da7219-max98357a.c
@@ -44,6 +44,8 @@
 
 #define CZ_PLAT_CLK 48000000
 #define DUAL_CHANNEL		2
+#define ADAU7002_DELAY_MS  20
+
 
 static struct snd_soc_jack cz_jack;
 static struct clk *da7219_dai_clk;
@@ -213,6 +215,7 @@ static int cz_dmic0_startup(struct snd_pcm_substream *substream)
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_card *card = rtd->card;
 	struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
+	int ret;
 
 	/*
 	 * On this platform for PCM device we support stereo
@@ -225,7 +228,17 @@ static int cz_dmic0_startup(struct snd_pcm_substream *substream)
 				   &constraints_rates);
 
 	machine->cap_i2s_instance = I2S_BT_INSTANCE;
-	return da7219_clk_enable(substream);
+	ret = da7219_clk_enable(substream);
+	if (ret)
+		return ret;
+	/*
+	 * On some platforms, it takes ~20 msec for PDM DMICs and ADAU7002
+	 * to settle and start producing proper audio data.
+	 */
+	msleep(ADAU7002_DELAY_MS);
+	/* Delay in frames for 48Khz, 16bit, 2 channel */
+	runtime->delay = ADAU7002_DELAY_MS * 48;
+	return 0;
 }
 
 static int cz_dmic1_startup(struct snd_pcm_substream *substream)
@@ -234,6 +247,7 @@ static int cz_dmic1_startup(struct snd_pcm_substream *substream)
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
 	struct snd_soc_card *card = rtd->card;
 	struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
+	int ret;
 
 	/*
 	 * On this platform for PCM device we support stereo
@@ -247,7 +261,17 @@ static int cz_dmic1_startup(struct snd_pcm_substream *substream)
 
 	machine->cap_i2s_instance = I2S_SP_INSTANCE;
 	machine->capture_channel = CAP_CHANNEL0;
-	return da7219_clk_enable(substream);
+	ret = da7219_clk_enable(substream);
+	if (ret)
+		return ret;
+	/*
+	 * On some platforms, it takes ~20 msec for PDM DMICs and ADAU7002
+	 * to settle and start producing proper audio data.
+	 */
+	msleep(ADAU7002_DELAY_MS);
+	/* Delay in frames for 48Khz, 16bit, 2 channel */
+	runtime->delay = ADAU7002_DELAY_MS * 48;
+	return 0;
 }
 
 static void cz_dmic_shutdown(struct snd_pcm_substream *substream)
-- 
1.9.1


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

* Re: [PATCH] ASoC: AMD: Add delay before starting to capture
  2019-01-03 10:18 [PATCH] ASoC: AMD: Add delay before starting to capture Agrawal, Akshu
@ 2019-01-04 12:27 ` Mark Brown
  2019-01-07  6:00   ` Agrawal, Akshu
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2019-01-04 12:27 UTC (permalink / raw)
  To: Agrawal, Akshu
  Cc: djkurtz, Deucher, Alexander, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Mukunda, Vijendar, Kuninori Morimoto, Wei Yongjun,
	moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list

[-- Attachment #1: Type: text/plain, Size: 787 bytes --]

On Thu, Jan 03, 2019 at 10:18:13AM +0000, Agrawal, Akshu wrote:
> On capture through dmic we observe a glitch at the start of record.
> This is because we start capturing even before dmic is ready to send
> out data. The glitch seen last for ~20msec.
> 

> +	/*
> +	 * On some platforms, it takes ~20 msec for PDM DMICs and ADAU7002
> +	 * to settle and start producing proper audio data.
> +	 */
> +	msleep(ADAU7002_DELAY_MS);

If the delay is required for external components to start up the delay
should be going in the drivers for those components rather than in the
driver for the CPU side, that way other systems using those components
get the benefit and non-affected boards don't pay the cost.  There's
already some support for this in the DMIC driver at least.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] ASoC: AMD: Add delay before starting to capture
  2019-01-04 12:27 ` Mark Brown
@ 2019-01-07  6:00   ` Agrawal, Akshu
  0 siblings, 0 replies; 3+ messages in thread
From: Agrawal, Akshu @ 2019-01-07  6:00 UTC (permalink / raw)
  To: Mark Brown
  Cc: djkurtz, Deucher, Alexander, Liam Girdwood, Jaroslav Kysela,
	Takashi Iwai, Mukunda, Vijendar, Kuninori Morimoto, Wei Yongjun,
	moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM...,
	open list



On 1/4/2019 5:57 PM, Mark Brown wrote:
> On Thu, Jan 03, 2019 at 10:18:13AM +0000, Agrawal, Akshu wrote:
>> On capture through dmic we observe a glitch at the start of record.
>> This is because we start capturing even before dmic is ready to send
>> out data. The glitch seen last for ~20msec.
>>
> 
>> +	/*
>> +	 * On some platforms, it takes ~20 msec for PDM DMICs and ADAU7002
>> +	 * to settle and start producing proper audio data.
>> +	 */
>> +	msleep(ADAU7002_DELAY_MS);
> 
> If the delay is required for external components to start up the delay
> should be going in the drivers for those components rather than in the
> driver for the CPU side, that way other systems using those components
> get the benefit and non-affected boards don't pay the cost.  There's
> already some support for this in the DMIC driver at least.
> 

Agreed, we can use the similar to wakeup_delay in dmic driver in our
codec driver. Will post the patch on same lines.

Thanks,
Akshu

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

end of thread, other threads:[~2019-01-07  6:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-03 10:18 [PATCH] ASoC: AMD: Add delay before starting to capture Agrawal, Akshu
2019-01-04 12:27 ` Mark Brown
2019-01-07  6:00   ` Agrawal, Akshu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).