linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: eve: implement set_bias_level function for rt5514
@ 2019-10-25  9:11 Brent Lu
  2019-10-25 14:05 ` [alsa-devel] " Pierre-Louis Bossart
  0 siblings, 1 reply; 6+ messages in thread
From: Brent Lu @ 2019-10-25  9:11 UTC (permalink / raw)
  To: alsa-devel
  Cc: Cezary Rojewski, Pierre-Louis Bossart, Liam Girdwood, Jie Yang,
	Mark Brown, Jaroslav Kysela, Takashi Iwai, Brent Lu,
	Subhransu S . Prusty, Richard Fontana, Tzung-Bi Shih,
	Kuninori Morimoto, Thomas Gleixner, Naveen M, linux-kernel

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.

Signed-off-by: Brent Lu <brent.lu@intel.com>
---
 .../soc/intel/boards/kbl_rt5663_rt5514_max98927.c  | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
index dc09a85..b546de8 100644
--- a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
+++ b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
@@ -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,
-- 
2.7.4


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

* Re: [alsa-devel] [PATCH] ASoC: eve: implement set_bias_level function for rt5514
  2019-10-25  9:11 [PATCH] ASoC: eve: implement set_bias_level function for rt5514 Brent Lu
@ 2019-10-25 14:05 ` Pierre-Louis Bossart
  2019-10-25 14:43   ` Lu, Brent
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre-Louis Bossart @ 2019-10-25 14:05 UTC (permalink / raw)
  To: Brent Lu, alsa-devel
  Cc: Cezary Rojewski, Liam Girdwood, Jie Yang, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Subhransu S . Prusty,
	Richard Fontana, Tzung-Bi Shih, Kuninori Morimoto,
	Thomas Gleixner, Naveen M, linux-kernel



On 10/25/19 4:11 AM, Brent Lu wrote:
> 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.

> 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.
> 
> Signed-off-by: Brent Lu <brent.lu@intel.com>
> ---
>   .../soc/intel/boards/kbl_rt5663_rt5514_max98927.c  | 50 ++++++++++++++++++++++
>   1 file changed, 50 insertions(+)
> 
> diff --git a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
> index dc09a85..b546de8 100644
> --- a/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
> +++ b/sound/soc/intel/boards/kbl_rt5663_rt5514_max98927.c
> @@ -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,
> 

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

* RE: [alsa-devel] [PATCH] ASoC: eve: implement set_bias_level function for rt5514
  2019-10-25 14:05 ` [alsa-devel] " Pierre-Louis Bossart
@ 2019-10-25 14:43   ` Lu, Brent
  2019-10-25 14:48     ` Pierre-Louis Bossart
  0 siblings, 1 reply; 6+ messages in thread
From: Lu, Brent @ 2019-10-25 14:43 UTC (permalink / raw)
  To: Pierre-Louis Bossart, alsa-devel
  Cc: Rojewski, Cezary, Liam Girdwood, Jie Yang, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Subhransu S . Prusty,
	Richard Fontana, Tzung-Bi Shih, Kuninori Morimoto,
	Thomas Gleixner, M, Naveen, linux-kernel

> On 10/25/19 4:11 AM, Brent Lu wrote:
> > 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
> > 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.
> >
> > Signed-off-by: Brent Lu <brent.lu@intel.com>


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

* Re: [alsa-devel] [PATCH] ASoC: eve: implement set_bias_level function for rt5514
  2019-10-25 14:43   ` Lu, Brent
@ 2019-10-25 14:48     ` Pierre-Louis Bossart
  2019-10-25 16:14       ` Lu, Brent
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre-Louis Bossart @ 2019-10-25 14:48 UTC (permalink / raw)
  To: Lu, Brent, alsa-devel
  Cc: Rojewski, Cezary, Liam Girdwood, Jie Yang, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Subhransu S . Prusty,
	Richard Fontana, Tzung-Bi Shih, Kuninori Morimoto,
	Thomas Gleixner, M, Naveen, linux-kernel



On 10/25/19 9:43 AM, Lu, Brent wrote:
>> On 10/25/19 4:11 AM, Brent Lu wrote:
>>> 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.

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.

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

* RE: [alsa-devel] [PATCH] ASoC: eve: implement set_bias_level function for rt5514
  2019-10-25 14:48     ` Pierre-Louis Bossart
@ 2019-10-25 16:14       ` Lu, Brent
  2019-10-25 16:57         ` Pierre-Louis Bossart
  0 siblings, 1 reply; 6+ messages in thread
From: Lu, Brent @ 2019-10-25 16:14 UTC (permalink / raw)
  To: Pierre-Louis Bossart, alsa-devel
  Cc: Rojewski, Cezary, Liam Girdwood, Jie Yang, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Subhransu S . Prusty,
	Richard Fontana, Tzung-Bi Shih, Kuninori Morimoto,
	Thomas Gleixner, M, Naveen, linux-kernel

> 
> 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.

> 
> 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

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

* Re: [alsa-devel] [PATCH] ASoC: eve: implement set_bias_level function for rt5514
  2019-10-25 16:14       ` Lu, Brent
@ 2019-10-25 16:57         ` Pierre-Louis Bossart
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre-Louis Bossart @ 2019-10-25 16:57 UTC (permalink / raw)
  To: Lu, Brent, alsa-devel
  Cc: Rojewski, Cezary, Kuninori Morimoto, Tzung-Bi Shih, linux-kernel,
	Jie Yang, Takashi Iwai, Liam Girdwood, Richard Fontana,
	Mark Brown, M, Naveen, Thomas Gleixner, Subhransu S . Prusty



On 10/25/19 11:14 AM, Lu, Brent wrote:
>>
>> 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.
> 
>>
>> 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.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>


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

end of thread, other threads:[~2019-10-25 16:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  9:11 [PATCH] ASoC: eve: implement set_bias_level function for rt5514 Brent Lu
2019-10-25 14:05 ` [alsa-devel] " Pierre-Louis Bossart
2019-10-25 14:43   ` Lu, Brent
2019-10-25 14:48     ` Pierre-Louis Bossart
2019-10-25 16:14       ` Lu, Brent
2019-10-25 16:57         ` Pierre-Louis Bossart

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).