From 66d7e503797c7f66df0db1593f78e20cf6c3fe93 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sat, 2 Mar 2024 14:55:31 +0100
Subject: [PATCH 190/484] ASoC: sun8i-codec: Allow the jack type to be set via
 device tree

This makes the codec's jack detection functionality usable from within
simple-sound-card.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 sound/soc/sunxi/sun8i-codec.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sound/soc/sunxi/sun8i-codec.c b/sound/soc/sunxi/sun8i-codec.c
index 8b9eb1a202f7..4f44f35819e2 100644
--- a/sound/soc/sunxi/sun8i-codec.c
+++ b/sound/soc/sunxi/sun8i-codec.c
@@ -1563,6 +1563,18 @@ static void sun8i_codec_disable_jack_detect(struct snd_soc_component *component)
 	scodec->jack = NULL;
 }
 
+static int sun8i_codec_component_get_jack_type(struct snd_soc_component *component)
+{
+	struct device_node *node = component->dev->of_node;
+
+	if (of_property_match_string(node, "jack-type", "headset") >= 0)
+		return SND_JACK_HEADSET | SUN8I_CODEC_BUTTONS;
+	else if (of_property_match_string(node, "jack-type", "headphone") >= 0)
+		return SND_JACK_HEADPHONE;
+
+	return 0;
+}
+
 static int sun8i_codec_component_set_jack(struct snd_soc_component *component,
 					  struct snd_soc_jack *jack, void *data)
 {
@@ -1584,6 +1596,7 @@ static const struct snd_soc_component_driver sun8i_soc_component = {
 	.dapm_routes		= sun8i_codec_dapm_routes,
 	.num_dapm_routes	= ARRAY_SIZE(sun8i_codec_dapm_routes),
 	.set_jack		= sun8i_codec_component_set_jack,
+	.get_jack_type		= sun8i_codec_component_get_jack_type,
 	.probe			= sun8i_codec_component_probe,
 	.idle_bias_on		= 1,
 	.suspend_bias_off	= 1,
-- 
2.49.0

