[PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver

Astrid Rost astrid.rost at axis.com
Fri Sep 9 11:30:01 CEST 2022


ti,jack-detect enables the jack detection input device

Signed-off-by: Astrid Rost <astrid.rost at axis.com>
---
 sound/soc/codecs/Kconfig    |  2 ++
 sound/soc/codecs/ts3a227e.c | 62 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index d16b4efb88a7..cb86e52cd02f 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -1671,6 +1671,8 @@ config SND_SOC_TLV320ADCX140
 config SND_SOC_TS3A227E
 	tristate "TI Headset/Mic detect and keypress chip"
 	depends on I2C
+	select SND_JACK
+	select SND_JACK_INPUT_DEV
 
 config SND_SOC_TSCS42XX
 	tristate "Tempo Semiconductor TSCS42xx CODEC"
diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index d8ab0810fceb..b5d0d32cafdb 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -38,6 +38,32 @@ static const int ts3a227e_buttons[] = {
 	SND_JACK_BTN_3,
 };
 
+/* Headphones jack detection DAPM pin */
+static struct snd_soc_jack_pin ts3a227e_jack_pins[] = {
+
+	{
+		.pin = "Headphone Jack",
+		.mask = SND_JACK_HEADPHONE,
+	},
+	{
+		.pin = "Internal Speaker",
+		/* disable speaker when hp jack is inserted */
+		.mask = SND_JACK_HEADPHONE,
+		.invert	= 1,
+	},
+	{
+		.pin = "Headset Mic",
+		.mask = SND_JACK_MICROPHONE,
+	},
+	{
+		.pin = "Internal Mic",
+		/* disable microphone when microphone jack is inserted */
+		.mask = SND_JACK_MICROPHONE,
+		.invert	= 1,
+	},
+
+};
+
 #define TS3A227E_NUM_BUTTONS 4
 #define TS3A227E_JACK_MASK (SND_JACK_HEADPHONE | \
 			    SND_JACK_MICROPHONE | \
@@ -250,7 +276,12 @@ int ts3a227e_enable_jack_detect(struct snd_soc_component *component,
 }
 EXPORT_SYMBOL_GPL(ts3a227e_enable_jack_detect);
 
-static struct snd_soc_component_driver ts3a227e_soc_driver;
+static int ts3a227e_probe(struct snd_soc_component *component);
+
+static const struct snd_soc_component_driver ts3a227e_soc_driver = {
+	.name = "Audio Accessory Detection ts3a227e",
+	.probe = ts3a227e_probe,
+};
 
 static const struct regmap_config ts3a227e_regmap_config = {
 	.val_bits = 8,
@@ -355,6 +386,35 @@ static int ts3a227e_resume(struct device *dev)
 }
 #endif
 
+static int ts3a227e_probe(struct snd_soc_component *component)
+{
+	int ret = 0;
+	bool enable = 0;
+	struct snd_soc_card *card = component->card;
+	struct ts3a227e *ts3a227e = snd_soc_component_get_drvdata(component);
+
+	enable = device_property_read_bool(component->dev, "ti,jack-detect");
+	if (enable) {
+		/* Enable Headset and 4 Buttons Jack detection */
+		ts3a227e->jack = devm_kzalloc(component->dev,
+				sizeof(struct snd_soc_jack), GFP_KERNEL);
+
+		ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
+					    SND_JACK_HEADSET |
+					    SND_JACK_BTN_0 | SND_JACK_BTN_1 |
+					    SND_JACK_BTN_2 | SND_JACK_BTN_3,
+					    ts3a227e->jack,
+					    ts3a227e_jack_pins,
+					    ARRAY_SIZE(ts3a227e_jack_pins));
+		if (ret)
+			return ret;
+
+		ret = ts3a227e_enable_jack_detect(component, ts3a227e->jack);
+	}
+
+	return ret;
+}
+
 static const struct dev_pm_ops ts3a227e_pm = {
 	SET_SYSTEM_SLEEP_PM_OPS(ts3a227e_suspend, ts3a227e_resume)
 };
-- 
2.20.1



More information about the Alsa-devel mailing list