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: tiwai@suse.de,
	Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>,
	broonie@kernel.org, Rander Wang <rander.wang@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: [PATCH 12/21] ASoC: SOF: Intel: hda: Enable jack detection
Date: Mon, 22 Jul 2019 09:13:53 -0500	[thread overview]
Message-ID: <20190722141402.7194-13-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20190722141402.7194-1-pierre-louis.bossart@linux.intel.com>

From: Rander Wang <rander.wang@linux.intel.com>

In commit 7d4f606c50ff ("ALSA: hda - WAKEEN feature enabling for
runtime pm"), legacy HD-A driver sets hda controller in reset mode after
entering runtime-suspend. And when resuming from suspend mode, it checks
hda controller & codec status to detect headphone hotplug event. Now
this patch does the same job in SOF runtime pm functions.

And we need to check all the non-hdmi codecs for some cases like playback
with HDMI or capture with DMIC connected to dsp. In these cases, only
controller is active and codecs are suspended, so codecs can't send
unsolicited event to controller. The jack polling operation will activate
codecs and unsolicited event can work even codecs become suspended later.

Tested on whiskylake with hda codecs.

Signed-off-by: Rander Wang <rander.wang@linux.intel.com>
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/sof/intel/hda-codec.c | 44 +++++++++++++++++++++++++++++++--
 sound/soc/sof/intel/hda-dsp.c   | 21 ++++++++--------
 sound/soc/sof/intel/hda.h       |  2 ++
 3 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/sound/soc/sof/intel/hda-codec.c b/sound/soc/sof/intel/hda-codec.c
index b8b37f082309..74d75156135b 100644
--- a/sound/soc/sof/intel/hda-codec.c
+++ b/sound/soc/sof/intel/hda-codec.c
@@ -10,6 +10,7 @@
 
 #include <linux/module.h>
 #include <sound/hdaudio_ext.h>
+#include <sound/hda_register.h>
 #include <sound/hda_codec.h>
 #include <sound/hda_i915.h>
 #include <sound/sof.h>
@@ -37,16 +38,55 @@ static void hda_codec_load_module(struct hda_codec *codec)
 static void hda_codec_load_module(struct hda_codec *codec) {}
 #endif
 
+/* enable controller wake up event for all codecs with jack connectors */
+void hda_codec_jack_wake_enable(struct snd_sof_dev *sdev)
+{
+	struct hda_bus *hbus = sof_to_hbus(sdev);
+	struct hdac_bus *bus = sof_to_bus(sdev);
+	struct hda_codec *codec;
+	unsigned int mask = 0;
+
+	list_for_each_codec(codec, hbus)
+		if (codec->jacktbl.used)
+			mask |= BIT(codec->core.addr);
+
+	snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
+}
+
+/* check jack status after resuming from suspend mode */
+void hda_codec_jack_check(struct snd_sof_dev *sdev)
+{
+	struct hda_bus *hbus = sof_to_hbus(sdev);
+	struct hdac_bus *bus = sof_to_bus(sdev);
+	struct hda_codec *codec;
+
+	/* disable controller Wake Up event*/
+	snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, 0);
+
+	list_for_each_codec(codec, hbus)
+		/*
+		 * Wake up all jack-detecting codecs regardless whether an event
+		 * has been recorded in STATESTS
+		 */
+		if (codec->jacktbl.used)
+			schedule_delayed_work(&codec->jackpoll_work,
+					      codec->jackpoll_interval);
+}
+#else
+void hda_codec_jack_wake_enable(struct snd_sof_dev *sdev) {}
+void hda_codec_jack_check(struct snd_sof_dev *sdev) {}
 #endif /* CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC */
+EXPORT_SYMBOL(hda_codec_jack_wake_enable);
+EXPORT_SYMBOL(hda_codec_jack_check);
 
 /* probe individual codec */
 static int hda_codec_probe(struct snd_sof_dev *sdev, int address)
 {
-	struct hda_bus *hbus = sof_to_hbus(sdev);
-	struct hdac_device *hdev;
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
 	struct hdac_hda_priv *hda_priv;
 #endif
+	struct hda_bus *hbus = sof_to_hbus(sdev);
+	struct hdac_device *hdev;
 	u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) |
 		(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
 	u32 resp = -1;
diff --git a/sound/soc/sof/intel/hda-dsp.c b/sound/soc/sof/intel/hda-dsp.c
index 3d711d354fb9..f9579edbca68 100644
--- a/sound/soc/sof/intel/hda-dsp.c
+++ b/sound/soc/sof/intel/hda-dsp.c
@@ -295,6 +295,9 @@ static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend)
 	hda_dsp_ipc_int_disable(sdev);
 
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
+	if (runtime_suspend)
+		hda_codec_jack_wake_enable(sdev);
+
 	/* power down all hda link */
 	snd_hdac_ext_bus_link_power_down_all(bus);
 #endif
@@ -329,7 +332,7 @@ static int hda_suspend(struct snd_sof_dev *sdev, bool runtime_suspend)
 	return 0;
 }
 
-static int hda_resume(struct snd_sof_dev *sdev)
+static int hda_resume(struct snd_sof_dev *sdev, bool runtime_resume)
 {
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 	struct hdac_bus *bus = sof_to_bus(sdev);
@@ -343,7 +346,6 @@ static int hda_resume(struct snd_sof_dev *sdev)
 	 */
 	snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
 
-#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 	/* reset and start hda controller */
 	ret = hda_dsp_ctrl_init_chip(sdev, true);
 	if (ret < 0) {
@@ -352,13 +354,10 @@ static int hda_resume(struct snd_sof_dev *sdev)
 		return ret;
 	}
 
-	hda_dsp_ctrl_misc_clock_gating(sdev, false);
-
-	/* Reset stream-to-link mapping */
-	list_for_each_entry(hlink, &bus->hlink_list, list)
-		bus->io_ops->reg_writel(0, hlink->ml_addr + AZX_REG_ML_LOSIDV);
-
-	hda_dsp_ctrl_misc_clock_gating(sdev, true);
+#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
+	/* check jack status */
+	if (runtime_resume)
+		hda_codec_jack_check(sdev);
 
 	/* turn off the links that were off before suspend */
 	list_for_each_entry(hlink, &bus->hlink_list, list) {
@@ -407,13 +406,13 @@ static int hda_resume(struct snd_sof_dev *sdev)
 int hda_dsp_resume(struct snd_sof_dev *sdev)
 {
 	/* init hda controller. DSP cores will be powered up during fw boot */
-	return hda_resume(sdev);
+	return hda_resume(sdev, false);
 }
 
 int hda_dsp_runtime_resume(struct snd_sof_dev *sdev)
 {
 	/* init hda controller. DSP cores will be powered up during fw boot */
-	return hda_resume(sdev);
+	return hda_resume(sdev, true);
 }
 
 int hda_dsp_runtime_idle(struct snd_sof_dev *sdev)
diff --git a/sound/soc/sof/intel/hda.h b/sound/soc/sof/intel/hda.h
index 70909debfeb5..028e865d5e20 100644
--- a/sound/soc/sof/intel/hda.h
+++ b/sound/soc/sof/intel/hda.h
@@ -557,6 +557,8 @@ void sof_hda_bus_init(struct hdac_bus *bus, struct device *dev,
  * HDA Codec operations.
  */
 int hda_codec_probe_bus(struct snd_sof_dev *sdev);
+void hda_codec_jack_wake_enable(struct snd_sof_dev *sdev);
+void hda_codec_jack_check(struct snd_sof_dev *sdev);
 
 #endif /* CONFIG_SND_SOC_SOF_HDA */
 
-- 
2.20.1

  parent reply	other threads:[~2019-07-22 14:14 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 14:13 [PATCH 00/21] ASoC: SOF: updates for 5.4 Pierre-Louis Bossart
2019-07-22 14:13 ` [PATCH 01/21] ASoC: SOF: pci: mark last_busy value at runtime PM init Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: pci: mark last_busy value at runtime PM init" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 02/21] ASoC: SOF: reset DMA state in prepare Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: reset DMA state in prepare" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 03/21] ASoC: SOF: use common code to send PCM_FREE IPC Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: use common code to send PCM_FREE IPC" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 04/21] ASoC: SOF: ipc: use timeout configured at probe Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: ipc: use timeout configured at probe" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 05/21] ASoC: SOF: core: increase default IPC timeouts Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: core: increase default IPC timeouts" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 06/21] ASoC: SOF: Introduce snd_sof_dsp_get_bar_index ops Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Introduce snd_sof_dsp_get_bar_index ops" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 07/21] ASoC: SOF: loader: Use the BAR provided by FW Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: loader: Use the BAR provided by FW" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 08/21] ASoC: SOF: loader: Don't ignore SRAM block types Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: loader: Don't ignore SRAM block types" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 09/21] ASoC: SOF: remove unused state variable in suspend function Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: remove unused state variable in suspend function" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 10/21] ASoC: SOF: Intel: hda: correct ROM state mask Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: correct ROM state mask" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 11/21] ASoC: SOF: Intel: hda: reduce ifdef usage for hda Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: reduce ifdef usage for hda" to the asoc tree Mark Brown
2019-07-22 14:13 ` Pierre-Louis Bossart [this message]
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: Enable jack detection" " Mark Brown
2019-07-22 14:13 ` [PATCH 13/21] ASoC: SOF: Intel: hda: set position buffer in init chip Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: set position buffer in init chip" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 14/21] ASoC: SOF: Intel: hda: use SOF defined init chip in resume Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: use SOF defined init chip in resume" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 15/21] ASoC: SOF: Intel: hda: remove duplicated clear WAKESTS Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: remove duplicated clear WAKESTS" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 16/21] ASoC: SOF: Intel: hda: add a parameter to disable MSI Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: add a parameter to disable MSI" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 17/21] ASoC: SOF: Intel: hda: reset link DMA state in prepare Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: reset link DMA state in prepare" to the asoc tree Mark Brown
2019-07-22 14:13 ` [PATCH 18/21] ASoC: SOF: Intel: hda: fix link DMA config Pierre-Louis Bossart
2019-07-23 11:15   ` Mark Brown
2019-07-23 14:37     ` Pierre-Louis Bossart
2019-07-23 16:30       ` Mark Brown
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: fix link DMA config" to the asoc tree Mark Brown
2019-07-22 14:14 ` [PATCH 19/21] ASoC: SOF: Intel: hda: fix stream id setting Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: fix stream id setting" to the asoc tree Mark Brown
2019-07-22 14:14 ` [PATCH 20/21] ASoC: SOF: Intel: hda: remove misleading error trace from IRQ thread Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: hda: remove misleading error trace from IRQ thread" to the asoc tree Mark Brown
2019-07-22 14:14 ` [PATCH 21/21] ASoC: SOF: Intel: ssp: BCLK delay parameter Pierre-Louis Bossart
2019-07-23 11:29   ` Applied "ASoC: SOF: Intel: ssp: BCLK delay parameter" to the asoc tree Mark Brown

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=20190722141402.7194-13-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=guennadi.liakhovetski@linux.intel.com \
    --cc=rander.wang@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.