Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Ryan Walklin <ryan@testtoast.com>,
	Chris Morgan <macromorgan@hotmail.com>,
	Philippe Simons <simons.philippe@gmail.com>,
	Mark Brown <broonie@kernel.org>, Sasha Levin <sashal@kernel.org>,
	lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com,
	wens@csie.org, jernej.skrabec@gmail.com, samuel@sholland.org,
	csokas.bence@prolan.hu, mesihkilinc@gmail.com,
	andre.przywara@arm.com, codekipper@gmail.com,
	jbrunet@baylibre.com, linux-sound@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev
Subject: [PATCH AUTOSEL 6.12 123/486] ASoC: sun4i-codec: support hp-det-gpios property
Date: Mon,  5 May 2025 18:33:19 -0400	[thread overview]
Message-ID: <20250505223922.2682012-123-sashal@kernel.org> (raw)
In-Reply-To: <20250505223922.2682012-1-sashal@kernel.org>

From: Ryan Walklin <ryan@testtoast.com>

[ Upstream commit a149377c033afe6557c50892ebbfc0e8b7e2e253 ]

Add support for GPIO headphone detection with the hp-det-gpios
property. In order for this to properly disable the path upon
removal of headphones, the output must be labelled Headphone which
is a common sink in the driver.

Describe a headphone jack and detection GPIO in the driver, check for
a corresponding device tree node, and enable jack detection in a new
machine init function if described.

Signed-off-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Ryan Walklin <ryan@testtoast.com>

--
Changelog v1..v2:
- Separate DAPM changes into separate patch and add rationale.

Tested-by: Philippe Simons <simons.philippe@gmail.com>
Link: https://patch.msgid.link/20250214220247.10810-4-ryan@testtoast.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/soc/sunxi/sun4i-codec.c | 53 +++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index 330bc0c09f56b..93dd88fb805dd 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -21,6 +21,7 @@
 #include <linux/gpio/consumer.h>
 
 #include <sound/core.h>
+#include <sound/jack.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
@@ -235,6 +236,7 @@ struct sun4i_codec {
 	struct clk	*clk_module;
 	struct reset_control *rst;
 	struct gpio_desc *gpio_pa;
+	struct gpio_desc *gpio_hp;
 
 	/* ADC_FIFOC register is at different offset on different SoCs */
 	struct regmap_field *reg_adc_fifoc;
@@ -1263,6 +1265,49 @@ static struct snd_soc_dai_driver dummy_cpu_dai = {
 	.ops = &dummy_dai_ops,
 };
 
+static struct snd_soc_jack sun4i_headphone_jack;
+
+static struct snd_soc_jack_pin sun4i_headphone_jack_pins[] = {
+	{ .pin = "Headphone", .mask = SND_JACK_HEADPHONE },
+};
+
+static struct snd_soc_jack_gpio sun4i_headphone_jack_gpio = {
+	.name = "hp-det",
+	.report = SND_JACK_HEADPHONE,
+	.debounce_time = 150,
+};
+
+static int sun4i_codec_machine_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_card *card = rtd->card;
+	struct sun4i_codec *scodec = snd_soc_card_get_drvdata(card);
+	int ret;
+
+	if (scodec->gpio_hp) {
+		ret = snd_soc_card_jack_new_pins(card, "Headphone Jack",
+						 SND_JACK_HEADPHONE,
+						 &sun4i_headphone_jack,
+						 sun4i_headphone_jack_pins,
+						 ARRAY_SIZE(sun4i_headphone_jack_pins));
+		if (ret) {
+			dev_err(rtd->dev,
+				"Headphone jack creation failed: %d\n", ret);
+			return ret;
+		}
+
+		sun4i_headphone_jack_gpio.desc = scodec->gpio_hp;
+		ret = snd_soc_jack_add_gpios(&sun4i_headphone_jack, 1,
+					     &sun4i_headphone_jack_gpio);
+
+		if (ret) {
+			dev_err(rtd->dev, "Headphone GPIO not added: %d\n", ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev,
 							int *num_links)
 {
@@ -1288,6 +1333,7 @@ static struct snd_soc_dai_link *sun4i_codec_create_link(struct device *dev,
 	link->codecs->name	= dev_name(dev);
 	link->platforms->name	= dev_name(dev);
 	link->dai_fmt		= SND_SOC_DAIFMT_I2S;
+	link->init		= sun4i_codec_machine_init;
 
 	*num_links = 1;
 
@@ -1728,6 +1774,13 @@ static int sun4i_codec_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	scodec->gpio_hp = devm_gpiod_get_optional(&pdev->dev, "hp-det", GPIOD_IN);
+	if (IS_ERR(scodec->gpio_hp)) {
+		ret = PTR_ERR(scodec->gpio_hp);
+		dev_err_probe(&pdev->dev, ret, "Failed to get hp-det gpio\n");
+		return ret;
+	}
+
 	/* reg_field setup */
 	scodec->reg_adc_fifoc = devm_regmap_field_alloc(&pdev->dev,
 							scodec->regmap,
-- 
2.39.5


  parent reply	other threads:[~2025-05-05 22:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250505223922.2682012-1-sashal@kernel.org>
2025-05-05 22:31 ` [PATCH AUTOSEL 6.12 032/486] ASoC: codecs: wsa884x: Correct VI sense channel mask Sasha Levin
2025-05-05 22:31 ` [PATCH AUTOSEL 6.12 033/486] ASoC: codecs: wsa883x: " Sasha Levin
2025-05-05 22:33 ` [PATCH AUTOSEL 6.12 109/486] ASoC: pcm6240: Drop bogus code handling IRQ as GPIO Sasha Levin
2025-05-05 22:33 ` [PATCH AUTOSEL 6.12 110/486] ASoC: mediatek: mt6359: Add stub for mt6359_accdet_enable_jack_detect Sasha Levin
2025-05-05 22:33 ` Sasha Levin [this message]
2025-05-05 22:33 ` [PATCH AUTOSEL 6.12 162/486] ASoC: qcom: sm8250: explicitly set format in sm8250_be_hw_params_fixup() Sasha Levin
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 179/486] ALSA: seq: Improve data consistency at polling Sasha Levin
2025-05-05 22:34 ` [PATCH AUTOSEL 6.12 214/486] ALSA: hda/realtek: Enable PC beep passthrough for HP EliteBook 855 G7 Sasha Levin
2025-05-05 22:35 ` [PATCH AUTOSEL 6.12 255/486] ASoC: mediatek: mt8188: Treat DMIC_GAINx_CUR as non-volatile Sasha Levin
2025-05-05 22:35 ` [PATCH AUTOSEL 6.12 256/486] ASoC: mediatek: mt8188: Add reference for dmic clocks Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 326/486] ASoC: ops: Enforce platform maximum on initial value Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 327/486] ASoC: tas2764: Add reg defaults for TAS2764_INT_CLK_CFG Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 328/486] ASoC: tas2764: Mark SW_RESET as volatile Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 329/486] ASoC: tas2764: Power up/down amp on mute ops Sasha Levin
2025-05-05 22:36 ` [PATCH AUTOSEL 6.12 330/486] ASoC: soc-dai: check return value at snd_soc_dai_set_tdm_slot() Sasha Levin
2025-05-05 22:37 ` [PATCH AUTOSEL 6.12 357/486] soundwire: amd: change the soundwire wake enable/disable sequence Sasha Levin
2025-05-05 22:37 ` [PATCH AUTOSEL 6.12 358/486] soundwire: cadence_master: set frame shape and divider based on actual clk freq Sasha Levin
2025-05-05 22:38 ` [PATCH AUTOSEL 6.12 448/486] ASoC: codecs: pcm3168a: Allow for 24-bit in provider mode Sasha Levin
2025-05-05 22:38 ` [PATCH AUTOSEL 6.12 449/486] ASoC: soc-core: Stop using of_property_read_bool() for non-boolean properties Sasha Levin
2025-05-05 22:38 ` [PATCH AUTOSEL 6.12 450/486] ASoC: rt722-sdca: Add some missing readable registers Sasha Levin
2025-05-05 22:39 ` [PATCH AUTOSEL 6.12 473/486] ASoC: hdmi-codec: allow to refine formats actually supported Sasha Levin

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=20250505223922.2682012-123-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andre.przywara@arm.com \
    --cc=broonie@kernel.org \
    --cc=codekipper@gmail.com \
    --cc=csokas.bence@prolan.hu \
    --cc=jbrunet@baylibre.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=macromorgan@hotmail.com \
    --cc=mesihkilinc@gmail.com \
    --cc=perex@perex.cz \
    --cc=ryan@testtoast.com \
    --cc=samuel@sholland.org \
    --cc=simons.philippe@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=wens@csie.org \
    /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