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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Shuming Fan <shumingf@xxxxxxxxxxx>

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




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux