@@ -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;
}
@@ -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;
@@ -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__ */