Skip to contentSkip to conversation

ASoC: da7219: check SRM lock in trigger callback

PATCH In review Brent Lu 7 participants 21 messages Feb 10, 2020 – Feb 19, 2020

Subsystems (3)
lore
Share & tools
lore

Brent Lu

author
#0 lore raw

PATCH 1/1 ASoC: da7219: check SRM lock in trigger callback

Intel sst firmware turns on BCLK/WCLK in START Ioctl call which timing is later than the DAPM SUPPLY event handler da7219_dai_event is called (in PREPARED state). Therefore, the SRM lock check always fail.

Moving the check to trigger callback could ensure the SRM is locked before DSP starts to process data and avoid possisble noise.

---
 sound/soc/codecs/da7219.c | 68 +++++++++++++++++++++++++++++++----------------
 1 file changed, 45 insertions(+), 23 deletions(-)
sound/soc/codecs/da7219.c +45 -23
index f83a6ea..0fb5ea5 100644
@@ -794,9 +794,7 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
 	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
 	struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
 	struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX];
-	u8 pll_ctrl, pll_status;
-	int i = 0, ret;
-	bool srm_lock = false;
+	int ret;
 
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
@@ -820,26 +818,6 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
 		/* PC synchronised to DAI */
 		snd_soc_component_update_bits(component, DA7219_PC_COUNT,
 				    DA7219_PC_FREERUN_MASK, 0);
-
-		/* Slave mode, if SRM not enabled no need for status checks */
-		pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL);
-		if ((pll_ctrl & DA7219_PLL_MODE_MASK) != DA7219_PLL_MODE_SRM)
-			return 0;
-
-		/* Check SRM has locked */
-		do {
-			pll_status = snd_soc_component_read32(component, DA7219_PLL_SRM_STS);
-			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
-				srm_lock = true;
-			} else {
-				++i;
-				msleep(50);
-			}
-		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
-
-		if (!srm_lock)
-			dev_warn(component->dev, "SRM failed to lock\n");
-
 		return 0;
 	case SND_SOC_DAPM_POST_PMD:
 		/* PC free-running */
@@ -1658,12 +1636,56 @@ static int da7219_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+static int da7219_set_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+				  struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *component = dai->component;
+	u8 pll_ctrl, pll_status;
+	int i = 0;
+	bool srm_lock = false;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* Slave mode, if SRM not enabled no need for status checks */
+		pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL);
+		if ((pll_ctrl & DA7219_PLL_MODE_MASK) != DA7219_PLL_MODE_SRM)
+			return 0;
+
+		/* Check SRM has locked */
+		do {
+			pll_status = snd_soc_component_read32(component,
+							DA7219_PLL_SRM_STS);
+			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
+				srm_lock = true;
+			} else {
+				++i;
+				msleep(50);
+			}
+		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
+
+		if (!srm_lock)
+			dev_warn(component->dev, "SRM failed to lock\n");
+
+		break;
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dai_ops da7219_dai_ops = {
 	.hw_params	= da7219_hw_params,
 	.set_sysclk	= da7219_set_dai_sysclk,
 	.set_pll	= da7219_set_dai_pll,
 	.set_fmt	= da7219_set_dai_fmt,
 	.set_tdm_slot	= da7219_set_dai_tdm_slot,
+	.trigger	= da7219_set_dai_trigger,
 };
 
 #define DA7219_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Brent Lu

Intel sst firmware turns on BCLK/WCLK in START Ioctl call which timing is later than the DAPM SUPPLY event handler da7219_dai_event is called (in PREPARED state). Therefore, the SRM lock check always fail.

Moving the check to trigger callback could ensure the SRM is locked before DSP starts to process data and avoid possisble noise.

Could ensure? This change seems specific to Intel DSP based systems, at least from the description. Having looked through the core, the trigger code for a codec is seemingly always called before the trigger for the CPU. How will this work for other platforms, assuming their clocks are enabled in the CPU DAI trigger function by default?

Can we always guarantee the CPU side isn't going to send anything other than 0s until after SRM has locked?

Quoted 66 lines
---
 sound/soc/codecs/da7219.c | 68 +++++++++++++++++++++++++++++++--------
--------
 1 file changed, 45 insertions(+), 23 deletions(-)
sound/soc/codecs/da7219.c +1 -3
index f83a6ea..0fb5ea5 100644
@@ -794,9 +794,7 @@ static int da7219_dai_event(struct snd_soc_dapm_widget
 *w,
 	struct snd_soc_component *component =
 snd_soc_dapm_to_component(w->dapm);
 	struct da7219_priv *da7219 =
 snd_soc_component_get_drvdata(component);
 	struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX];
-	u8 pll_ctrl, pll_status;
-	int i = 0, ret;
-	bool srm_lock = false;
+	int ret;
sound/soc/codecs/da7219.c +0 -4
 	switch (event) {
 	case SND_SOC_DAPM_PRE_PMU:
@@ -820,26 +818,6 @@ static int da7219_dai_event(struct
 snd_soc_dapm_widget *w,
 		/* PC synchronised to DAI */
 		snd_soc_component_update_bits(component,
 DA7219_PC_COUNT,
 				    DA7219_PC_FREERUN_MASK, 0);
-
-		/* Slave mode, if SRM not enabled no need for status checks */
-		pll_ctrl = snd_soc_component_read32(component,
 DA7219_PLL_CTRL);
-		if ((pll_ctrl & DA7219_PLL_MODE_MASK) !=

DA7219_PLL_MODE_SRM)

sound/soc/codecs/da7219.c +0 -5
-			return 0;
-
-		/* Check SRM has locked */
-		do {
-			pll_status = snd_soc_component_read32(component,

DA7219_PLL_SRM_STS);

sound/soc/codecs/da7219.c +3 -11
-			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
-				srm_lock = true;
-			} else {
-				++i;
-				msleep(50);
-			}
-		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
-
-		if (!srm_lock)
-			dev_warn(component->dev, "SRM failed to lock\n");
-
 		return 0;
 	case SND_SOC_DAPM_POST_PMD:
 		/* PC free-running */
@@ -1658,12 +1636,56 @@ static int da7219_hw_params(struct
 snd_pcm_substream *substream,
 	return 0;
 }
 
+static int da7219_set_dai_trigger(struct snd_pcm_substream *substream, int
 cmd,
+				  struct snd_soc_dai *dai)
+{

sound/soc/codecs/da7219.c static int da7219_hw_params(struct · line 1653

Quoted 10 lines
sound/soc/codecs/da7219.c +9 -0
+	struct snd_soc_component *component = dai->component;
+	u8 pll_ctrl, pll_status;
+	int i = 0;
+	bool srm_lock = false;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* Slave mode, if SRM not enabled no need for status checks */
+		pll_ctrl = snd_soc_component_read32(component,
 DA7219_PLL_CTRL);

I was under the impression that 'trigger()' was atomic? We'd have to have some kind of workqueue to do all of this, which means we'd almost certainly lose some PCM data at the start of a stream.

Quoted 45 lines
sound/soc/codecs/da7219.c +32 -0
+		if ((pll_ctrl & DA7219_PLL_MODE_MASK) !=
 DA7219_PLL_MODE_SRM)
+			return 0;
+
+		/* Check SRM has locked */
+		do {
+			pll_status = snd_soc_component_read32(component,
+							DA7219_PLL_SRM_STS);
+			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
+				srm_lock = true;
+			} else {
+				++i;
+				msleep(50);
+			}
+		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
+
+		if (!srm_lock)
+			dev_warn(component->dev, "SRM failed to lock\n");
+
+		break;
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	default:
+		break;
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dai_ops da7219_dai_ops = {
 	.hw_params	= da7219_hw_params,
 	.set_sysclk	= da7219_set_dai_sysclk,
 	.set_pll	= da7219_set_dai_pll,
 	.set_fmt	= da7219_set_dai_fmt,
 	.set_tdm_slot	= da7219_set_dai_tdm_slot,
+	.trigger	= da7219_set_dai_trigger,
 };
 
 #define DA7219_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |

SNDRV_PCM_FMTBIT_S20_3LE |\
--
2.7.4

author
#2 lore raw
Quoted 10 lines

Could ensure? This change seems specific to Intel DSP based systems, at least from the description. Having looked through the core, the trigger code for a codec is seemingly always called before the trigger for the CPU. How will this work for other platforms, assuming their clocks are enabled in the CPU DAI trigger function by default?

Can we always guarantee the CPU side isn't going to send anything other than 0s until after SRM has locked?

I think the patch is for those systems which enable I2S clocks in pcm_start instead of pcm_prepare. It has no effect on systems already be able to turn on clocks in supply widgets or set_bias_level() function.

If the trigger type in the DAI link is TRIGGER_PRE, then the trigger function of FE port (component or CPU DAI) will be called before codec driver's trigger function. In this case we will be able to turn on the clock in time. However, if the trigger type is TRIGGER_POST, then the patch does not help because just like what you said, codec driver's trigger function is called first.

In my experiment with the patch, the SRM is locked in the second read and cost 50ms to wait.

Quoted 5 lines

I was under the impression that 'trigger()' was atomic? We'd have to have some kind of workqueue to do all of this, which means we'd almost certainly lose some PCM data at the start of a stream.

#3 lore raw
Quoted 9 lines
Quoted 9 lines

Could ensure? This change seems specific to Intel DSP based systems, at least from the description. Having looked through the core, the trigger code for a codec is seemingly always called before the trigger for the CPU. How will this work for other platforms, assuming their clocks are enabled in the CPU DAI trigger function by default?

Can we always guarantee the CPU side isn't going to send anything other than 0s until after SRM has locked?

Not with the default mode for the SSP, all clocks are enabled at trigger time.
We can enable the MCLK and BCLK ahead of time (which would require a change in firmware). But if we want to enable the FSYNC (word-clock), then we have to trigger DMA transfers with pretend-buffers, this is a lot more invasive.

So just to be clear, which of the MCLK, BCLK, FSYNC do you need enabled?

Quoted 9 lines

I think the patch is for those systems which enable I2S clocks in pcm_start instead of pcm_prepare. It has no effect on systems already be able to turn on clocks in supply widgets or set_bias_level() function.

If the trigger type in the DAI link is TRIGGER_PRE, then the trigger function of FE port (component or CPU DAI) will be called before codec driver's trigger function. In this case we will be able to turn on the clock in time. However, if the trigger type is TRIGGER_POST, then the patch does not help because just like what you said, codec driver's trigger function is called first.

IIRC we recently did a change to deal with underflows. Ranjani, can you remind us what the issue was? Thanks
-Pierre

#4 lore raw
Quoted 12 lines
Quoted 3 lines

I think the patch is for those systems which enable I2S clocks in

pcm_start instead

Quoted 1 line

of pcm_prepare. It has no effect on systems already be able to turn on

clocks in

Quoted 3 lines

supply widgets or set_bias_level() function.

If the trigger type in the DAI link is TRIGGER_PRE, then the trigger

function of FE port

Quoted 1 line

(component or CPU DAI) will be called before codec driver's trigger

function. In this

Quoted 8 lines
Quoted 1 line

case we will be able to turn on the clock in time. However, if the

trigger type is

Quoted 1 line

TRIGGER_POST, then the patch does not help because just like what you

said, codec

Quoted 1 line

driver's trigger function is called first.

IIRC we recently did a change to deal with underflows. Ranjani, can you remind us what the issue was?

Hi Pierre,

Are you talking about the change in this commit acbf27746ecfa96b "ASoC: pcm: update FE/BE trigger order based on the command"?

We made this change to handle xruns during pause/release particularly on the Intel HDA platforms.

Thanks,
Ranjani
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#5 lore raw
Quoted 20 lines · Ranjani

> I think the patch is for those systems which enable I2S clocks in
pcm_start instead
> of pcm_prepare. It has no effect on systems already be able to
turn on clocks in
> supply widgets or set_bias_level() function.
>
> If the trigger type in the DAI link is TRIGGER_PRE, then the
trigger function of FE port
> (component or CPU DAI) will be called before codec driver's
trigger function. In this
> case we will be able to turn on the clock in time. However, if
the trigger type is
> TRIGGER_POST, then the patch does not help because just like what
you said, codec
> driver's trigger function is called first.

IIRC we recently did a change to deal with underflows. Ranjani, can you remind us what the issue was?

Quoted 6 lines

Hi Pierre,

Are you talking about the change in this commit acbf27746ecfa96b "ASoC: pcm: update FE/BE trigger order based on the command"?

We made this change to handle xruns during pause/release particularly on the Intel HDA platforms.

this change was just to mirror the behavior between start/stop, I thought there was a patch where we moved to TRIGGER_POST by default?

What I am trying to figure out if whether using TRIGGER_PRE is ok or not for the SOF firmware.

Thanks!
-Pierre

#6 lore raw
Quoted 8 lines
Quoted 8 lines

Hi Pierre,

Are you talking about the change in this commit acbf27746ecfa96b "ASoC: pcm: update FE/BE trigger order based on the command"?

Quoted 9 lines
Quoted 2 lines

We made this change to handle xruns during pause/release particularly on the Intel HDA platforms.

this change was just to mirror the behavior between start/stop, I thought there was a patch where we moved to TRIGGER_POST by default?

What I am trying to figure out if whether using TRIGGER_PRE is ok or not for the SOF firmware.

Ahh yes, it was part of the same series as this one. fd274c2b7267b "ASoC:
SOF: topology: set trigger order for FE DAI link"

TRIGGER_PRE won't really work in the case of SOF. We need the BE DAI to be triggered before the FE DAI during start to prevent the xruns during pause/release.

Thanks,
Ranjani
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#7 lore raw
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines

Are you talking about the change in this commit acbf27746ecfa96b "ASoC: pcm: update FE/BE trigger order based on the command"?

Quoted 9 lines
Quoted 2 lines

We made this change to handle xruns during pause/release particularly on the Intel HDA platforms.

this change was just to mirror the behavior between start/stop, I thought there was a patch where we moved to TRIGGER_POST by default?

What I am trying to figure out if whether using TRIGGER_PRE is ok or not for the SOF firmware.

Quoted 6 lines

Ahh yes, it was part of the same series as this one. fd274c2b7267b "ASoC:
SOF: topology: set trigger order for FE DAI link"

TRIGGER_PRE won't really work in the case of SOF. We need the BE DAI to be triggered before the FE DAI during start to prevent the xruns during pause/release.

Thanks Ranjani. That information closes the door on the idea of playing with the trigger order suggested earlier in the thread, so my guess is that we really need to expose the MCLK/BCLK with the clk API and turn them on/off from the machine driver as needed. I hope is that we don't need the FSYNC as well, that would be rather painful to implement.

#8 lore raw
Quoted 36 lines · Pierre-Louis Bossart

-----Original Message-----
From: Pierre-Louis Bossart <[email protected]>
Sent: 11 February 2020 21:49
To: Sridharan, Ranjani <[email protected]>
Cc: [email protected]; Support Opensource <[email protected]>; Takashi Iwai <[email protected]>; Liam Girdwood <[email protected]>; [email protected]; Chiang, Mac <[email protected]>; Mark Brown <[email protected]>; Ranjani Sridharan <[email protected]>; Adam Thomson <[email protected]>; Lu, Brent <[email protected]>; [email protected]
Subject: Re: [alsa-devel] [PATCH] ASoC: da7219: check SRM lock in trigger callback
Importance: High

Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

Are you talking about the change in this commit acbf27746ecfa96b "ASoC: pcm: update FE/BE trigger order based on the command"?

We made this change to handle xruns during pause/release particularly on the Intel HDA platforms.

this change was just to mirror the behavior between start/stop, I thought there was a patch where we moved to TRIGGER_POST by default?

What I am trying to figure out if whether using TRIGGER_PRE is ok or not for the SOF firmware.

Quoted 6 lines

Ahh yes, it was part of the same series as this one. fd274c2b7267b "ASoC:
SOF: topology: set trigger order for FE DAI link"

TRIGGER_PRE won't really work in the case of SOF. We need the BE DAI to be triggered before the FE DAI during start to prevent the xruns during pause/release.

Quoted 5 lines

Thanks Ranjani. That information closes the door on the idea of playing with the trigger order suggested earlier in the thread, so my guess is that we really need to expose the MCLK/BCLK with the clk API and turn them on/off from the machine driver as needed. I hope is that we don't need the FSYNC as well, that would be rather painful to implement.

Am not going to make myself popular here. It's MCLK and FSYNC (or WCLK as it's termed for our device) that is required for SRM to lock in the PLL.

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in the driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

maintainer
#9 lore raw
Quoted 6 lines · Adam Thomson

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in the driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

This really needs the componentisation refactoring I think, that way we can annotate individual devices and links with what they need rather than essentially guessing about what works most of the time which is more or less what we do at the minute. Like you say as things are at the minute there's a lot of crack papering going on.

#10 lore raw
In reply to Adam Thomson
Quoted 10 lines
Quoted 6 lines

Thanks Ranjani. That information closes the door on the idea of playing with the trigger order suggested earlier in the thread, so my guess is that we really need to expose the MCLK/BCLK with the clk API and turn them on/off from the machine driver as needed. I hope is that we don't need the FSYNC as well, that would be rather painful to implement.

Am not going to make myself popular here. It's MCLK and FSYNC (or WCLK as it's termed for our device) that is required for SRM to lock in the PLL.

Quoted 6 lines

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in the driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

Sorry, you lost me at "the solution that's in place right now". There is nothing in the bxt_da7219_max98357a.c code that deals with clocks or defines a trigger order?

#11 lore raw
Quoted 14 lines · Pierre-Louis Bossart
Quoted 7 lines
Quoted 5 lines

Thanks Ranjani. That information closes the door on the idea of playing with the trigger order suggested earlier in the thread, so my guess is that we really need to expose the MCLK/BCLK with the clk API and turn them on/off from the machine driver as needed. I hope is that we don't need the FSYNC as well, that would be rather painful to implement.

Am not going to make myself popular here. It's MCLK and FSYNC (or WCLK as

it's

Quoted 6 lines

termed for our device) that is required for SRM to lock in the PLL.

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in

Quoted 7 lines

the

Quoted 2 lines

driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

Sorry, you lost me at "the solution that's in place right now". There is nothing in the bxt_da7219_max98357a.c code that deals with clocks or defines a trigger order?

I meant solution in the context of the codec driver. The approach or expectation (maybe more suitable wording) for the driver is that the required clocking can be enabled prior to the DAI widget for the codec being powered via DAPM as part of an audio path. This approach has been there since the beginning, for want of a better option, and I've always highlighted this need when platforms are using our device with SRM.

You're right though that this isn't taken care of in existing mainline Linux machine files that use this device with SRM.

author
#12 lore raw
In reply to Adam Thomson
Quoted 10 lines

Am not going to make myself popular here. It's MCLK and FSYNC (or WCLK as it's termed for our device) that is required for SRM to lock in the PLL.

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in the driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

Hi Adam,

For Google CTS requirement (200ms cold output latency), we plan to upload a patch which reduces the recheck number to 4 and interval to 20ms so the total delay here would be 80ms for our platform. We think the time is still sufficient for other platforms to generate a stable WCLK and for the codec SRM to lock but still needs your confirmation. How do you think?

Regards,
Brent

#13 lore raw
Quoted 10 lines · Brent
Quoted 9 lines

Am not going to make myself popular here. It's MCLK and FSYNC (or WCLK as it's termed for our device) that is required for SRM to lock in the PLL.

So far I've not found a way in the codec driver to be able to get around this. I spent a very long time with Sathya in the early days (Apollo Lake) looking at options but nothing would fit which is why I have the solution that's in place right now. We could probably reduce the number of rechecks before timeout in the driver but that's really just papering over the crack and there's still the possibility of noise later when SRM finally does lock.

Quoted 7 lines

Hi Adam,

For Google CTS requirement (200ms cold output latency), we plan to upload a patch which reduces the recheck number to 4 and interval to 20ms so the total delay here would be 80ms for our platform. We think the time is still sufficient for other platforms to generate a stable WCLK and for the codec SRM to lock but still needs your confirmation. How do you think?

Hi Brent,

I'm concerned that just setting a timeout to suit the Google CTS requirement isn't necessarily suitable for all targets, and this doesn't actually fix the real problem here.

How long do you determine platforms will take to generate a stable WCLK? Do we have an idea of how long that might be in a worst case scenario? If so then we can look at adjusting this down, but I'd like to be clear.

Quoted 4 lines

Regards,
Brent

#14 lore raw
In reply to Brent Lu
Quoted 6 lines · Brent Lu

Intel sst firmware turns on BCLK/WCLK in START Ioctl call which timing is later than the DAPM SUPPLY event handler da7219_dai_event is called (in PREPARED state). Therefore, the SRM lock check always fail.

Moving the check to trigger callback could ensure the SRM is locked before DSP starts to process data and avoid possisble noise.

This codec is used quite a bit by Chromebooks across multiple generations and with both SST and SOF drivers, we need to be careful about changes. I am personally not aware of any issues and never saw an 'SRM failed to lock message'. On which platform did you see a problem?

Quoted 106 lines
---
  sound/soc/codecs/da7219.c | 68 +++++++++++++++++++++++++++++++----------------
  1 file changed, 45 insertions(+), 23 deletions(-)
sound/soc/codecs/da7219.c +45 -23
index f83a6ea..0fb5ea5 100644
@@ -794,9 +794,7 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
  	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
  	struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
  	struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX];
-	u8 pll_ctrl, pll_status;
-	int i = 0, ret;
-	bool srm_lock = false;
+	int ret;
 
  	switch (event) {
  	case SND_SOC_DAPM_PRE_PMU:
@@ -820,26 +818,6 @@ static int da7219_dai_event(struct snd_soc_dapm_widget *w,
  		/* PC synchronised to DAI */
  		snd_soc_component_update_bits(component, DA7219_PC_COUNT,
  				    DA7219_PC_FREERUN_MASK, 0);
-
-		/* Slave mode, if SRM not enabled no need for status checks */
-		pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL);
-		if ((pll_ctrl & DA7219_PLL_MODE_MASK) != DA7219_PLL_MODE_SRM)
-			return 0;
-
-		/* Check SRM has locked */
-		do {
-			pll_status = snd_soc_component_read32(component, DA7219_PLL_SRM_STS);
-			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
-				srm_lock = true;
-			} else {
-				++i;
-				msleep(50);
-			}
-		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
-
-		if (!srm_lock)
-			dev_warn(component->dev, "SRM failed to lock\n");
-
  		return 0;
  	case SND_SOC_DAPM_POST_PMD:
  		/* PC free-running */
@@ -1658,12 +1636,56 @@ static int da7219_hw_params(struct snd_pcm_substream *substream,
  	return 0;
  }
 
+static int da7219_set_dai_trigger(struct snd_pcm_substream *substream, int cmd,
+				  struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *component = dai->component;
+	u8 pll_ctrl, pll_status;
+	int i = 0;
+	bool srm_lock = false;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* Slave mode, if SRM not enabled no need for status checks */
+		pll_ctrl = snd_soc_component_read32(component, DA7219_PLL_CTRL);
+		if ((pll_ctrl & DA7219_PLL_MODE_MASK) != DA7219_PLL_MODE_SRM)
+			return 0;
+
+		/* Check SRM has locked */
+		do {
+			pll_status = snd_soc_component_read32(component,
+							DA7219_PLL_SRM_STS);
+			if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
+				srm_lock = true;
+			} else {
+				++i;
+				msleep(50);
+			}
+		} while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
+
+		if (!srm_lock)
+			dev_warn(component->dev, "SRM failed to lock\n");
+
+		break;
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+	default:
+		break;
+	}
+
+	return 0;
+}
+
  static const struct snd_soc_dai_ops da7219_dai_ops = {
  	.hw_params	= da7219_hw_params,
  	.set_sysclk	= da7219_set_dai_sysclk,
  	.set_pll	= da7219_set_dai_pll,
  	.set_fmt	= da7219_set_dai_fmt,
  	.set_tdm_slot	= da7219_set_dai_tdm_slot,
+	.trigger	= da7219_set_dai_trigger,
  };
 
  #define DA7219_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
#15 lore raw

+Jimmy Cheng-Yi Chiang <[email protected]>

This error is causing pcm_open commands to fail timing requirements, sometimes taking +500ms to open the PCM as a result. This work around is required so we can meet the timing requirements. The bug is explained in detail here https://github.com/thesofproject/sof/issues/2124

Quoted 136 lines · Pierre-Louis Bossart
Quoted 5 lines · Brent Lu

Intel sst firmware turns on BCLK/WCLK in START Ioctl call which timing is later than the DAPM SUPPLY event handler da7219_dai_event is called (in PREPARED state). Therefore, the SRM lock check always fail.

Moving the check to trigger callback could ensure the SRM is locked

before

Quoted 1 line

DSP starts to process data and avoid possisble noise.

This codec is used quite a bit by Chromebooks across multiple generations and with both SST and SOF drivers, we need to be careful about changes.
I am personally not aware of any issues and never saw an 'SRM failed to lock message'. On which platform did you see a problem?

Quoted 4 lines
---
  sound/soc/codecs/da7219.c | 68

+++++++++++++++++++++++++++++++----------------

sound/soc/codecs/da7219.c static int da7219_dai_event(struct

Quoted 7 lines
  1 file changed, 45 insertions(+), 23 deletions(-)
sound/soc/codecs/da7219.c +0 -0
index f83a6ea..0fb5ea5 100644
@@ -794,9 +794,7 @@ static int da7219_dai_event(struct

snd_soc_dapm_widget *w,

sound/soc/codecs/da7219.c static int da7219_dai_event(struct · line 794

Quoted 1 line
sound/soc/codecs/da7219.c +0 -0
      struct snd_soc_component *component =

snd_soc_dapm_to_component(w->dapm);

sound/soc/codecs/da7219.c static int da7219_dai_event(struct · line 795

Quoted 1 line
sound/soc/codecs/da7219.c +0 -0
      struct da7219_priv *da7219 =

snd_soc_component_get_drvdata(component);

sound/soc/codecs/da7219.c static int da7219_dai_event(struct

Quoted 9 lines
sound/soc/codecs/da7219.c +1 -3
      struct clk *bclk = da7219->dai_clks[DA7219_DAI_BCLK_IDX];
-     u8 pll_ctrl, pll_status;
-     int i = 0, ret;
-     bool srm_lock = false;
+     int ret;
 
      switch (event) {
      case SND_SOC_DAPM_PRE_PMU:
@@ -820,26 +818,6 @@ static int da7219_dai_event(struct

snd_soc_dapm_widget *w,

sound/soc/codecs/da7219.c static int da7219_dai_event(struct snd_soc_dapm_widget *w,

Quoted 5 lines
sound/soc/codecs/da7219.c +0 -2
              /* PC synchronised to DAI */
              snd_soc_component_update_bits(component, DA7219_PC_COUNT,
                                  DA7219_PC_FREERUN_MASK, 0);
-
-             /* Slave mode, if SRM not enabled no need for status

checks */

sound/soc/codecs/da7219.c static int da7219_dai_event(struct · line 825

Quoted 1 line
sound/soc/codecs/da7219.c +0 -1
-             pll_ctrl = snd_soc_component_read32(component,

DA7219_PLL_CTRL);

sound/soc/codecs/da7219.c static int da7219_dai_event(struct · line 826

Quoted 1 line
sound/soc/codecs/da7219.c +0 -1
-             if ((pll_ctrl & DA7219_PLL_MODE_MASK) !=

DA7219_PLL_MODE_SRM)

sound/soc/codecs/da7219.c static int da7219_dai_event(struct snd_soc_dapm_widget *w,

Quoted 5 lines
sound/soc/codecs/da7219.c +0 -5
-                     return 0;
-
-             /* Check SRM has locked */
-             do {
-                     pll_status = snd_soc_component_read32(component,

DA7219_PLL_SRM_STS);

sound/soc/codecs/da7219.c static int da7219_hw_params(struct

Quoted 15 lines
sound/soc/codecs/da7219.c +0 -11
-                     if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
-                             srm_lock = true;
-                     } else {
-                             ++i;
-                             msleep(50);
-                     }
-             } while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
-
-             if (!srm_lock)
-                     dev_warn(component->dev, "SRM failed to lock\n");
-
              return 0;
      case SND_SOC_DAPM_POST_PMD:
              /* PC free-running */
@@ -1658,12 +1636,56 @@ static int da7219_hw_params(struct

snd_pcm_substream *substream,

sound/soc/codecs/da7219.c static int da7219_hw_params(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/da7219.c +1 -0
      return 0;
  }
 
+static int da7219_set_dai_trigger(struct snd_pcm_substream *substream,

int cmd,

sound/soc/codecs/da7219.c static int da7219_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/da7219.c +10 -0
+                               struct snd_soc_dai *dai)
+{
+     struct snd_soc_component *component = dai->component;
+     u8 pll_ctrl, pll_status;
+     int i = 0;
+     bool srm_lock = false;
+
+     switch (cmd) {
+     case SNDRV_PCM_TRIGGER_START:
+             /* Slave mode, if SRM not enabled no need for status

checks */

sound/soc/codecs/da7219.c static int da7219_hw_params(struct · line 1650

Quoted 1 line
sound/soc/codecs/da7219.c +1 -0
+             pll_ctrl = snd_soc_component_read32(component,

DA7219_PLL_CTRL);

sound/soc/codecs/da7219.c static int da7219_hw_params(struct · line 1651

Quoted 1 line
sound/soc/codecs/da7219.c +1 -0
+             if ((pll_ctrl & DA7219_PLL_MODE_MASK) !=

DA7219_PLL_MODE_SRM)

sound/soc/codecs/da7219.c static int da7219_hw_params(struct snd_pcm_substream *substream, · line 1665

Quoted 6 lines
sound/soc/codecs/da7219.c +6 -0
+                     return 0;
+
+             /* Check SRM has locked */
+             do {
+                     pll_status = snd_soc_component_read32(component,
+

DA7219_PLL_SRM_STS);

Quoted 33 lines
sound/soc/codecs/da7219.c +25 -0
+                     if (pll_status & DA7219_PLL_SRM_STS_SRM_LOCK) {
+                             srm_lock = true;
+                     } else {
+                             ++i;
+                             msleep(50);
+                     }
+             } while ((i < DA7219_SRM_CHECK_RETRIES) && (!srm_lock));
+
+             if (!srm_lock)
+                     dev_warn(component->dev, "SRM failed to lock\n");
+
+             break;
+     case SNDRV_PCM_TRIGGER_RESUME:
+     case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+     case SNDRV_PCM_TRIGGER_STOP:
+     case SNDRV_PCM_TRIGGER_SUSPEND:
+     case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+     default:
+             break;
+     }
+
+     return 0;
+}
+
  static const struct snd_soc_dai_ops da7219_dai_ops = {
      .hw_params      = da7219_hw_params,
      .set_sysclk     = da7219_set_dai_sysclk,
      .set_pll        = da7219_set_dai_pll,
      .set_fmt        = da7219_set_dai_fmt,
      .set_tdm_slot   = da7219_set_dai_tdm_slot,
+     .trigger        = da7219_set_dai_trigger,
  };
 
Quoted 8 lines

sound/soc/codecs/da7219.c static int da7219_hw_params(struct · line 1691

Quoted 1 line
sound/soc/codecs/da7219.c +0 -0
  #define DA7219_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |

SNDRV_PCM_FMTBIT_S20_3LE |\

Quoted 1 line

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#16 lore raw
Quoted 6 lines · Curtis Malainey

+Jimmy Cheng-Yi Chiang <[email protected]>

This error is causing pcm_open commands to fail timing requirements, sometimes taking +500ms to open the PCM as a result. This work around is required so we can meet the timing requirements. The bug is explained in detail here https://github.com/thesofproject/sof/issues/2124

Ah, thanks for the pointer, but this still does not tell me if it's a GLK-only issue or not. And if yes, there are alternate proposals discussed in that issue #2124, which has been idle since November 25.

What I am really worried is side effects on unrelated platforms.

#17 lore raw

+Fletcher Woodruff <[email protected]>
See comment #3 in the bug. This is not a GLK specific issue. If I remember correctly Fletcher found that this was occurring on 2-3 platforms. SST has the ability to turn on clocks on demand which is why this has not been an issue previously from what I understand on the bug.

And that is a fair point, we do need to consider other users of the codec.

Quoted 10 lines · Pierre-Louis Bossart
Quoted 6 lines · Curtis Malainey

+Jimmy Cheng-Yi Chiang <[email protected]>

This error is causing pcm_open commands to fail timing requirements, sometimes taking +500ms to open the PCM as a result. This work around is required so we can meet the timing requirements. The bug is explained in detail here https://github.com/thesofproject/sof/issues/2124

Quoted 6 lines

Ah, thanks for the pointer, but this still does not tell me if it's a GLK-only issue or not. And if yes, there are alternate proposals discussed in that issue #2124, which has been idle since November 25.

What I am really worried is side effects on unrelated platforms.

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#18 lore raw
Quoted 3 lines · Curtis Malainey

+Fletcher Woodruff
See comment #3 in the bug. This is not a GLK specific issue. If I remember correctly Fletcher found that this was occurring on 2-3 platforms.

Yes, I tested this and saw the same bug on a Pixelbook Go which I believe is Comet Lake.

Quoted 22 lines

SST has the ability to turn on clocks on demand which is why this has not been an issue previously from what I understand on the bug.

And that is a fair point, we do need to consider other users of the codec.

Quoted 16 lines · Pierre-Louis Bossart
Quoted 6 lines · Curtis Malainey

+Jimmy Cheng-Yi Chiang <[email protected]>

This error is causing pcm_open commands to fail timing requirements, sometimes taking +500ms to open the PCM as a result. This work around is required so we can meet the timing requirements. The bug is explained in detail here https://github.com/thesofproject/sof/issues/2124

Ah, thanks for the pointer, but this still does not tell me if it's a GLK-only issue or not. And if yes, there are alternate proposals discussed in that issue #2124, which has been idle since November 25.

What I am really worried is side effects on unrelated platforms.

maintainer
#19 lore raw
In reply to Brent Lu
Quoted 6 lines · Brent Lu

Intel sst firmware turns on BCLK/WCLK in START Ioctl call which timing is later than the DAPM SUPPLY event handler da7219_dai_event is called (in PREPARED state). Therefore, the SRM lock check always fail.

Moving the check to trigger callback could ensure the SRM is locked before DSP starts to process data and avoid possisble noise.

Independently of any other discussion trigger is expected to run very fast so doesn't feel like a good place to do this - given that we're talking about doing this to avoid noise the mute operation seems like a more idiomatic place to do this, it exists to avoid playing back glitches from the digitial interface during startup.

author
#20 lore raw
Quoted 6 lines

Independently of any other discussion trigger is expected to run very fast so doesn't feel like a good place to do this - given that we're talking about doing this to avoid noise the mute operation seems like a more idiomatic place to do this, it exists to avoid playing back glitches from the digitial interface during startup.

It still take 50ms waiting for lock on in the trigger so I guess it's not a good implementation here. And I thought digital mute is called in the pcm_prepare? I'm afraid it does not work in our case...

Regards,
Brent