Skip to contentSkip to conversation

ASoC: eve: implement set_bias_level function for rt5514

PATCH In review Brent Lu 3 participants 7 messages Oct 25, 2019 – Oct 28, 2019

Subsystems (3)
lore
Share & tools
lore

Brent Lu

author
#0 lore raw

PATCH 1/1 ASoC: eve: implement set_bias_level function for rt5514

The first DMIC capture always fail (zero sequence data from PCM port) after using DSP hotwording function (i.e. Google assistant).

This rt5514 codec requires to control mclk directly in the set_bias_level function. Implement this function in machine driver to control the ssp1_mclk clock explicitly could fix this issue.

---
 .../soc/intel/boards/kbl_rt5663_rt5514_max98927.c  | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +50 -0
index dc09a85..b546de8 100644
@@ -653,6 +653,55 @@ static struct snd_soc_dai_link kabylake_dais[] = {
 	},
 };
 
+static int kabylake_set_bias_level(struct snd_soc_card *card,
+	struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
+{
+	struct snd_soc_component *component = dapm->component;
+	struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
+	int ret = 0;
+
+	if (!component || strcmp(component->name, RT5514_DEV_NAME))
+		return 0;
+
+	if (IS_ERR(priv->mclk))
+		return 0;
+
+	/*
+	 * It's required to control mclk directly in the set_bias_level
+	 * function for rt5514 codec or the recording function could
+	 * break.
+	 */
+	switch (level) {
+	case SND_SOC_BIAS_PREPARE:
+		if (dapm->bias_level == SND_SOC_BIAS_ON) {
+			dev_dbg(card->dev, "Disable mclk");
+			clk_disable_unprepare(priv->mclk);
+		} else {
+			dev_dbg(card->dev, "Enable mclk");
+			ret = clk_set_rate(priv->mclk, 24000000);
+			if (ret) {
+				dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
+					ret);
+				return ret;
+			}
+
+			ret = clk_prepare_enable(priv->mclk);
+			if (ret) {
+				dev_err(card->dev, "Can't enable mclk, err: %d\n",
+					ret);
+
+				/* mclk is already enabled in FW */
+				ret = 0;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return ret;
+}
+
 static int kabylake_card_late_probe(struct snd_soc_card *card)
 {
 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
@@ -692,6 +741,7 @@ static struct snd_soc_card kabylake_audio_card = {
 	.owner = THIS_MODULE,
 	.dai_link = kabylake_dais,
 	.num_links = ARRAY_SIZE(kabylake_dais),
+	.set_bias_level = kabylake_set_bias_level,
 	.controls = kabylake_controls,
 	.num_controls = ARRAY_SIZE(kabylake_controls),
 	.dapm_widgets = kabylake_widgets,
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Brent Lu

The first DMIC capture always fail (zero sequence data from PCM port) after using DSP hotwording function (i.e. Google assistant).

Can you clarify where the DSP hotwording is done? Intel DSP or rt5514?

Turning on the MCLK with the BIAS info might force the Intel DSP to remain on, which would impact power consumption if it was supposed to remain off.

Quoted 78 lines

This rt5514 codec requires to control mclk directly in the set_bias_level function. Implement this function in machine driver to control the ssp1_mclk clock explicitly could fix this issue.

---
  .../soc/intel/boards/kbl_rt5663_rt5514_max98927.c  | 50 ++++++++++++++++++++++
  1 file changed, 50 insertions(+)
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +50 -0
index dc09a85..b546de8 100644
@@ -653,6 +653,55 @@ static struct snd_soc_dai_link kabylake_dais[] = {
  	},
  };
 
+static int kabylake_set_bias_level(struct snd_soc_card *card,
+	struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
+{
+	struct snd_soc_component *component = dapm->component;
+	struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
+	int ret = 0;
+
+	if (!component || strcmp(component->name, RT5514_DEV_NAME))
+		return 0;
+
+	if (IS_ERR(priv->mclk))
+		return 0;
+
+	/*
+	 * It's required to control mclk directly in the set_bias_level
+	 * function for rt5514 codec or the recording function could
+	 * break.
+	 */
+	switch (level) {
+	case SND_SOC_BIAS_PREPARE:
+		if (dapm->bias_level == SND_SOC_BIAS_ON) {
+			dev_dbg(card->dev, "Disable mclk");
+			clk_disable_unprepare(priv->mclk);
+		} else {
+			dev_dbg(card->dev, "Enable mclk");
+			ret = clk_set_rate(priv->mclk, 24000000);
+			if (ret) {
+				dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
+					ret);
+				return ret;
+			}
+
+			ret = clk_prepare_enable(priv->mclk);
+			if (ret) {
+				dev_err(card->dev, "Can't enable mclk, err: %d\n",
+					ret);
+
+				/* mclk is already enabled in FW */
+				ret = 0;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return ret;
+}
+
  static int kabylake_card_late_probe(struct snd_soc_card *card)
  {
  	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
@@ -692,6 +741,7 @@ static struct snd_soc_card kabylake_audio_card = {
  	.owner = THIS_MODULE,
  	.dai_link = kabylake_dais,
  	.num_links = ARRAY_SIZE(kabylake_dais),
+	.set_bias_level = kabylake_set_bias_level,
  	.controls = kabylake_controls,
  	.num_controls = ARRAY_SIZE(kabylake_controls),
  	.dapm_widgets = kabylake_widgets,
author
#2 lore raw
Quoted 9 lines · Brent Lu
Quoted 2 lines

The first DMIC capture always fail (zero sequence data from PCM port) after using DSP hotwording function (i.e. Google assistant).

Can you clarify where the DSP hotwording is done? Intel DSP or rt5514?

Turning on the MCLK with the BIAS info might force the Intel DSP to remain on, which would impact power consumption if it was supposed to remain off.

Hi Pierre,

It's done in rt5514's DSP and the interface is SPI instead of I2S for the voice wake up function.

There is a driver rt5514-spi.c which provides platform driver and DAI. User space application first uses the mixer to turn on the voice wake up function:

amixer -c0 cset name='DSP Voice Wake Up' on

Then open and read data from the PCM port which goes to the SPI platform and dai code. Finally it uses same mixer to turn off the function and return to normal codec mode. The DMIC recording (from I2S) and the voice wake on function should be mutually exclusive according to the driver design.

In the codec driver rt5514.c there is a rt5514_set_bias_level function. It's expected to turn on/off mclk here according to Realtek people's say but our ssp clock requires set rate function to be called in advance so I implement the code in machine driver.

Regards,
Brent

Quoted 5 lines
Quoted 5 lines

This rt5514 codec requires to control mclk directly in the set_bias_level function. Implement this function in machine driver to control the ssp1_mclk clock explicitly could fix this issue.

#3 lore raw
Quoted 20 lines · Brent
Quoted 9 lines · Brent Lu
Quoted 2 lines

The first DMIC capture always fail (zero sequence data from PCM port) after using DSP hotwording function (i.e. Google assistant).

Can you clarify where the DSP hotwording is done? Intel DSP or rt5514?

Turning on the MCLK with the BIAS info might force the Intel DSP to remain on, which would impact power consumption if it was supposed to remain off.

Hi Pierre,

It's done in rt5514's DSP and the interface is SPI instead of I2S for the voice wake up function.

There is a driver rt5514-spi.c which provides platform driver and DAI. User space application first uses the mixer to turn on the voice wake up function:

amixer -c0 cset name='DSP Voice Wake Up' on

Quoted 8 lines

Then open and read data from the PCM port which goes to the SPI platform and dai code. Finally it uses same mixer to turn off the function and return to normal codec mode. The DMIC recording (from I2S) and the voice wake on function should be mutually exclusive according to the driver design.

In the codec driver rt5514.c there is a rt5514_set_bias_level function. It's expected to turn on/off mclk here according to Realtek people's say but our ssp clock requires set rate function to be called in advance so I implement the code in machine driver.

Can you clarify if the rt5514 needs the MCLK while it's doing the hotword detection?

My point is really that this patch uses a card-level BIAS indication, and I'd like to make sure this does not interfere with the audio DSP being in D3 state.

author
#4 lore raw
Quoted 3 lines

Can you clarify if the rt5514 needs the MCLK while it's doing the hotword detection?

No, running the detection does not raise the bias level so the set_bias_level will not be called. The mclk is only turned on then off in mixer control's handler (rt5514_dsp_voice_wake_up_put) when enabling the hotword detection.

Quoted 3 lines

My point is really that this patch uses a card-level BIAS indication, and I'd like to make sure this does not interfere with the audio DSP being in D3 state.

The function checks the name of dapm so it would only react when rt5514's bias level is changing. And also the idle_bias_off of the codec driver is true so it's target_bias_level should not be overwritten in the dapm_power_widgets() function. The behavior should be similar to the previous patch which is using supply widget.

Regards,
Brent

#5 lore raw
Quoted 9 lines · Brent
Quoted 3 lines

Can you clarify if the rt5514 needs the MCLK while it's doing the hotword detection?

No, running the detection does not raise the bias level so the set_bias_level will not be called. The mclk is only turned on then off in mixer control's handler (rt5514_dsp_voice_wake_up_put) when enabling the hotword detection.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

My point is really that this patch uses a card-level BIAS indication, and I'd like to make sure this does not interfere with the audio DSP being in D3 state.

The function checks the name of dapm so it would only react when rt5514's bias level is changing. And also the idle_bias_off of the codec driver is true so it's target_bias_level should not be overwritten in the dapm_power_widgets() function. The behavior should be similar to the previous patch which is using supply widget.

Ah yes, I did miss this test:

+ if (!component || strcmp(component->name, RT5514_DEV_NAME))
+ return 0;

Looks good then, thanks for the explanations.

maintainer
#6 lore raw

[alsa-devel] Applied "ASoC: eve: implement set_bias_level function for rt5514" to the asoc tree

In reply to Brent Lu

The patch

ASoC: eve: implement set_bias_level function for rt5514

has been applied to the asoc tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-5.5

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

From 15747a80207585fe942416025540c0ff34e2aef8 Mon Sep 17 00:00:00 2001
From: Brent Lu <[email protected]>
Date: Fri, 25 Oct 2019 17:11:31 +0800
Subject: [PATCH] ASoC: eve: implement set_bias_level function for rt5514

The first DMIC capture always fail (zero sequence data from PCM port) after using DSP hotwording function (i.e. Google assistant).

This rt5514 codec requires to control mclk directly in the set_bias_level function. Implement this function in machine driver to control the ssp1_mclk clock explicitly could fix this issue.

---
 .../intel/boards/kbl_rt5663_rt5514_max98927.c | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c +50 -0
index dc09a85e4c74..b546de8ba1e3 100644
@@ -653,6 +653,55 @@ static struct snd_soc_dai_link kabylake_dais[] = {
 	},
 };
 
+static int kabylake_set_bias_level(struct snd_soc_card *card,
+	struct snd_soc_dapm_context *dapm, enum snd_soc_bias_level level)
+{
+	struct snd_soc_component *component = dapm->component;
+	struct kbl_codec_private *priv = snd_soc_card_get_drvdata(card);
+	int ret = 0;
+
+	if (!component || strcmp(component->name, RT5514_DEV_NAME))
+		return 0;
+
+	if (IS_ERR(priv->mclk))
+		return 0;
+
+	/*
+	 * It's required to control mclk directly in the set_bias_level
+	 * function for rt5514 codec or the recording function could
+	 * break.
+	 */
+	switch (level) {
+	case SND_SOC_BIAS_PREPARE:
+		if (dapm->bias_level == SND_SOC_BIAS_ON) {
+			dev_dbg(card->dev, "Disable mclk");
+			clk_disable_unprepare(priv->mclk);
+		} else {
+			dev_dbg(card->dev, "Enable mclk");
+			ret = clk_set_rate(priv->mclk, 24000000);
+			if (ret) {
+				dev_err(card->dev, "Can't set rate for mclk, err: %d\n",
+					ret);
+				return ret;
+			}
+
+			ret = clk_prepare_enable(priv->mclk);
+			if (ret) {
+				dev_err(card->dev, "Can't enable mclk, err: %d\n",
+					ret);
+
+				/* mclk is already enabled in FW */
+				ret = 0;
+			}
+		}
+		break;
+	default:
+		break;
+	}
+
+	return ret;
+}
+
 static int kabylake_card_late_probe(struct snd_soc_card *card)
 {
 	struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
@@ -692,6 +741,7 @@ static struct snd_soc_card kabylake_audio_card = {
 	.owner = THIS_MODULE,
 	.dai_link = kabylake_dais,
 	.num_links = ARRAY_SIZE(kabylake_dais),
+	.set_bias_level = kabylake_set_bias_level,
 	.controls = kabylake_controls,
 	.num_controls = ARRAY_SIZE(kabylake_controls),
 	.dapm_widgets = kabylake_widgets,
Signature · 6 lines
2.20.1

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