mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Astrid Rost <astrid.rost@axis.com>
To: Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: <kernel@axis.com>,
	alsa-devel-mejlinglistan <alsa-devel@alsa-project.org>,
	Astrid Rost <astrid.rost@axis.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH] ASoC: ts3a227e: allow enabling the jack detect in driver
Date: Fri, 9 Sep 2022 11:30:01 +0200	[thread overview]
Message-ID: <20220909093001.13110-1-astrid.rost@axis.com> (raw)

ti,jack-detect enables the jack detection input device

Signed-off-by: Astrid Rost <astrid.rost@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


             reply	other threads:[~2022-09-09  9:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09  9:30 Astrid Rost [this message]
2022-09-09 17:45 ` Mark Brown
2022-09-12  7:17   ` Astrid Rost
2022-09-10  2:17 ` kernel test robot
2022-09-10 14:37 ` kernel test robot

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=20220909093001.13110-1-astrid.rost@axis.com \
    --to=astrid.rost@axis.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kernel@axis.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®