All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: Dharageswari R <dharageswari.r@intel.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	tiwai@suse.de,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	broonie@kernel.org
Subject: [PATCH 07/17] ASoC: Intel: Boards: tgl_max98373: add dai_trigger function
Date: Thu, 25 Jun 2020 14:12:58 -0500	[thread overview]
Message-ID: <20200625191308.3322-8-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20200625191308.3322-1-pierre-louis.bossart@linux.intel.com>

From: Dharageswari R <dharageswari.r@intel.com>

Speaker amplifier feedback is not modeled as being dependent on any
active output. Even when there is no playback happening, parts of the
graph, specifically the IV sense->speaker protection->output remains
active and this prevents the DSP from entering low-power states.

This patch suggests a machine driver level approach where the speaker
pins are enabled/disabled dynamically depending on stream start/stop
events. DPAM graph representations show the feedback loop is indeed
disabled and low-power states can be reached.

Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Dharageswari R <dharageswari.r@intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/intel/boards/sof_maxim_common.c | 45 +++++++++++++++++++++++
 sound/soc/intel/boards/sof_rt5682.c       |  9 +++++
 2 files changed, 54 insertions(+)

diff --git a/sound/soc/intel/boards/sof_maxim_common.c b/sound/soc/intel/boards/sof_maxim_common.c
index 1a549b32d1c9..b7014c424163 100644
--- a/sound/soc/intel/boards/sof_maxim_common.c
+++ b/sound/soc/intel/boards/sof_maxim_common.c
@@ -9,6 +9,8 @@
 #include <uapi/sound/asound.h>
 #include "sof_maxim_common.h"
 
+#define MAX_98373_PIN_NAME 16
+
 static const struct snd_soc_dapm_route max_98373_dapm_routes[] = {
 	/* speaker */
 	{ "Left Spk", NULL, "Left BE_OUT" },
@@ -57,8 +59,51 @@ static int max98373_hw_params(struct snd_pcm_substream *substream,
 	return 0;
 }
 
+static int max98373_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai;
+	int j;
+	int ret = 0;
+
+	for_each_rtd_codec_dais(rtd, j, codec_dai) {
+		struct snd_soc_component *component = codec_dai->component;
+		struct snd_soc_dapm_context *dapm =
+				snd_soc_component_get_dapm(component);
+		char pin_name[MAX_98373_PIN_NAME];
+
+		snprintf(pin_name, ARRAY_SIZE(pin_name), "%s Spk",
+			 codec_dai->component->name_prefix);
+
+		switch (cmd) {
+		case SNDRV_PCM_TRIGGER_START:
+		case SNDRV_PCM_TRIGGER_RESUME:
+		case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+			ret = snd_soc_dapm_enable_pin(dapm, pin_name);
+			if (!ret)
+				snd_soc_dapm_sync(dapm);
+			break;
+		case SNDRV_PCM_TRIGGER_STOP:
+		case SNDRV_PCM_TRIGGER_SUSPEND:
+		case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+			/* Make sure no streams are active before disable pin */
+			if (snd_soc_dai_active(codec_dai) != 1)
+				break;
+			ret = snd_soc_dapm_disable_pin(dapm, pin_name);
+			if (!ret)
+				snd_soc_dapm_sync(dapm);
+			break;
+		default:
+			break;
+		}
+	}
+
+	return ret;
+}
+
 struct snd_soc_ops max_98373_ops = {
 	.hw_params = max98373_hw_params,
+	.trigger = max98373_trigger,
 };
 
 int max98373_spk_codec_init(struct snd_soc_pcm_runtime *rtd)
diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c
index f80ed62025f3..20ab2664f7c8 100644
--- a/sound/soc/intel/boards/sof_rt5682.c
+++ b/sound/soc/intel/boards/sof_rt5682.c
@@ -318,6 +318,7 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 {
 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
 	struct snd_soc_component *component = NULL;
+	struct snd_soc_dapm_context *dapm = &card->dapm;
 	char jack_name[NAME_SIZE];
 	struct sof_hdmi_pcm *pcm;
 	int err;
@@ -356,6 +357,14 @@ static int sof_card_late_probe(struct snd_soc_card *card)
 		i++;
 	}
 
+	if (sof_rt5682_quirk & SOF_MAX98373_SPEAKER_AMP_PRESENT) {
+		/* Disable Left and Right Spk pin after boot */
+		snd_soc_dapm_disable_pin(dapm, "Left Spk");
+		snd_soc_dapm_disable_pin(dapm, "Right Spk");
+		err = snd_soc_dapm_sync(dapm);
+		if (err < 0)
+			return err;
+	}
 	return hdac_hdmi_jack_port_init(component, &card->dapm);
 }
 
-- 
2.20.1


  parent reply	other threads:[~2020-06-25 19:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-25 19:12 [PATCH 00/17] ASoC: Intel: machine driver updates for 5.9 Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 01/17] ASoC: SOF: nocodec: add missing .owner field Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 02/17] ASoC: Intel: cml_rt1011_rt5682: " Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 03/17] ASoC: Intel: sof_sdw: " Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 04/17] ASoC: Intel: bxt_rt298: " Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 05/17] ASoC: Intel: sof_sdw: add quirk override with kernel parameter Pierre-Louis Bossart
2020-06-25 19:12 ` [PATCH 06/17] ASoC: Intel: boards: byt*.c: remove cast in dev_info quirk log Pierre-Louis Bossart
2020-06-25 19:12 ` Pierre-Louis Bossart [this message]
2020-06-25 19:12 ` [PATCH 08/17] ASoC: Intel: Boards: tgl_max98373: Fix the comment for max_98373_components Pierre-Louis Bossart
2020-06-25 19:13 ` [PATCH 09/17] ASoC: intel: sof_rt5682: Add support for jsl-max98360a-rt5682 Pierre-Louis Bossart
2020-06-25 19:13 ` [PATCH 10/17] ASoC: Intel: Boards: cml_rt1011_rt5682: reduce log level for printing quirk Pierre-Louis Bossart
2020-06-25 19:13 ` [PATCH 11/17] ASoC: Intel: Boards: cml_rt1011_rt5682: use statically define codec config Pierre-Louis Bossart
2020-06-25 19:13 ` [PATCH 12/17] ASoC: intel: cml_rt1011_rt5682: use for_each_card_prelinks Pierre-Louis Bossart
2020-06-25 19:13 ` [PATCH 13/17] ASoC: Intel: Boards: tgl_max98373: Update TDM configuration in hw_params Pierre-Louis Bossart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200625191308.3322-8-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=dharageswari.r@intel.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.