All of lore.kernel.org
 help / color / mirror / Atom feed
From: <shumingf@realtek.com>
To: <broonie@kernel.org>, <lgirdwood@gmail.com>
Cc: <alsa-devel@alsa-project.org>, <lars@metafoo.de>,
	<flove@realtek.com>, <oder_chiou@realtek.com>,
	<jack.yu@realtek.com>, <derek.fang@realtek.com>,
	<Vijendar.Mukunda@amd.com>, Shuming Fan <shumingf@realtek.com>
Subject: [PATCH 2/2] ASoC: rt711-sdca: check pin sense when system resumes
Date: Fri, 21 Jul 2023 16:27:00 +0800	[thread overview]
Message-ID: <20230721082700.114069-1-shumingf@realtek.com> (raw)

From: Shuming Fan <shumingf@realtek.com>

If the jack is unplugged when the system was suspended,
the system will believe the jack exists for a while after the system resumes.
The codec needs some time, then alerts the host to detect whether the jack exists or not.
This patch wants to use the pin sense to detect whether the jack exists or not when the system resumes.
It could report the status immediately if the jack was unplugged.
It will improve the user experience.

Signed-off-by: Shuming Fan <shumingf@realtek.com>
---
 sound/soc/codecs/rt711-sdca-sdw.c | 18 ++++++++++++++++++
 sound/soc/codecs/rt711-sdca.c     |  2 +-
 sound/soc/codecs/rt711-sdca.h     |  2 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c
index cb27b4a98fb6..13a5316ba999 100644
--- a/sound/soc/codecs/rt711-sdca-sdw.c
+++ b/sound/soc/codecs/rt711-sdca-sdw.c
@@ -12,6 +12,7 @@
 #include <linux/soundwire/sdw_registers.h>
 #include <linux/module.h>
 #include <linux/pm_runtime.h>
+#include <sound/jack.h>
 
 #include "rt711-sdca.h"
 #include "rt711-sdca-sdw.h"
@@ -435,6 +436,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev)
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev);
 	unsigned long time;
+	unsigned int pin_sense;
+	int ret;
 
 	if (!rt711->first_hw_init)
 		return 0;
@@ -457,6 +460,21 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev)
 	regcache_sync(rt711->regmap);
 	regcache_cache_only(rt711->mbq_regmap, false);
 	regcache_sync(rt711->mbq_regmap);
+
+	/*
+	 * detect whether jack exists or not
+	 * if the jack is unplugged, we will report it immediately
+	 * if the jack exists, it will take some time to detect, then alert the host
+	 */
+	ret = rt711_sdca_index_read(rt711, RT711_VENDOR_REG, RT711_IRQ_FLAG_TABLE2, &pin_sense);
+	pin_sense = ((pin_sense & 0x100) >> 8);
+	if (ret < 0) {
+		dev_err(&slave->dev, "Pin Sense read failed:%d\n", ret);
+		return ret;
+	}
+	if (rt711->hs_jack && !pin_sense)
+		snd_soc_jack_report(rt711->hs_jack, 0, SND_JACK_HEADSET);
+
 	return 0;
 }
 
diff --git a/sound/soc/codecs/rt711-sdca.c b/sound/soc/codecs/rt711-sdca.c
index f1a93e3ffa1c..29dce5173f90 100644
--- a/sound/soc/codecs/rt711-sdca.c
+++ b/sound/soc/codecs/rt711-sdca.c
@@ -42,7 +42,7 @@ static int rt711_sdca_index_write(struct rt711_sdca_priv *rt711,
 	return ret;
 }
 
-static int rt711_sdca_index_read(struct rt711_sdca_priv *rt711,
+int rt711_sdca_index_read(struct rt711_sdca_priv *rt711,
 		unsigned int nid, unsigned int reg, unsigned int *value)
 {
 	int ret;
diff --git a/sound/soc/codecs/rt711-sdca.h b/sound/soc/codecs/rt711-sdca.h
index 11d421e8ab2b..aeedb38a0260 100644
--- a/sound/soc/codecs/rt711-sdca.h
+++ b/sound/soc/codecs/rt711-sdca.h
@@ -240,4 +240,6 @@ int rt711_sdca_init(struct device *dev, struct regmap *regmap,
 	       struct regmap *mbq_regmap, struct sdw_slave *slave);
 
 int rt711_sdca_jack_detect(struct rt711_sdca_priv *rt711, bool *hp, bool *mic);
+int rt711_sdca_index_read(struct rt711_sdca_priv *rt711,
+		unsigned int nid, unsigned int reg, unsigned int *value);
 #endif /* __RT711_SDCA_H__ */
-- 
2.34.1


                 reply	other threads:[~2023-07-21  8:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20230721082700.114069-1-shumingf@realtek.com \
    --to=shumingf@realtek.com \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=derek.fang@realtek.com \
    --cc=flove@realtek.com \
    --cc=jack.yu@realtek.com \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=oder_chiou@realtek.com \
    /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.