diff mbox series

[2/2] ASoC: rt711-sdca: check pin sense when system resumes

Message ID 20230721082700.114069-1-shumingf@realtek.com (mailing list archive)
State New, archived
Headers show
Series [1/2] ASoC: rt711-sdca: fix key tone missing | expand

Commit Message

Shuming [θŒƒζ›ΈιŠ˜] July 21, 2023, 8:27 a.m. UTC
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 mbox series

Patch

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__ */