All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/3] ASoC: simple-card-utils: add support for componants provideing jack events via set_jack
@ 2021-12-28 18:09 ` Carl Philipp Klemm
  0 siblings, 0 replies; 30+ messages in thread
From: Carl Philipp Klemm @ 2021-12-28 18:09 UTC (permalink / raw)
  To: alsa-devel; +Cc: merlijn, tony, sre, linux-omap, kuninori.morimoto.gx

This allows componants that want a jack to report state on to do so by calling
set_jack on components implementing this function.

Im not entirely sure this is the right way to do this so RFC

Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
---
 include/sound/simple_card_utils.h     |  6 ++--
 sound/soc/generic/simple-card-utils.c | 47 +++++++++++++++++++--------
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/include/sound/simple_card_utils.h b/include/sound/simple_card_utils.h
index 51b3b485a92e..547ad537613d 100644
--- a/include/sound/simple_card_utils.h
+++ b/include/sound/simple_card_utils.h
@@ -57,8 +57,8 @@ struct asoc_simple_priv {
 		struct prop_nums num;
 		unsigned int mclk_fs;
 	} *dai_props;
-	struct asoc_simple_jack hp_jack;
-	struct asoc_simple_jack mic_jack;
+	struct asoc_simple_jack *hp_jack;
+	struct asoc_simple_jack *mic_jack;
 	struct snd_soc_dai_link *dai_link;
 	struct asoc_simple_dai *dais;
 	struct snd_soc_dai_link_component *dlcs;
@@ -173,7 +173,7 @@ int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
 				   char *prefix);
 
 int asoc_simple_init_jack(struct snd_soc_card *card,
-			       struct asoc_simple_jack *sjack,
+			       struct asoc_simple_jack **sjack,
 			       int is_hp, char *prefix, char *pin);
 int asoc_simple_init_priv(struct asoc_simple_priv *priv,
 			       struct link_info *li);
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index 10c63b73900c..1899feba16cc 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -395,6 +395,7 @@ int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
 	struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
 	struct simple_dai_props *props = simple_priv_to_props(priv, rtd->num);
 	struct asoc_simple_dai *dai;
+	struct snd_soc_component *component;
 	int i, ret;
 
 	for_each_prop_dai_codec(props, i, dai) {
@@ -412,6 +413,21 @@ int asoc_simple_dai_init(struct snd_soc_pcm_runtime *rtd)
 	if (ret < 0)
 		return ret;
 
+	for_each_rtd_components(rtd, i, component) {
+		if (component->driver->set_jack) {
+			if (!priv->hp_jack) {
+				priv->hp_jack = devm_kzalloc(priv->snd_card.dev,
+					sizeof(*priv->hp_jack), GFP_KERNEL);
+				snd_soc_card_jack_new(&priv->snd_card,
+					"Headphones",
+					SND_JACK_HEADPHONE,
+					&priv->hp_jack->jack,
+					NULL, 0);
+			}
+			snd_soc_component_set_jack(component, &priv->hp_jack->jack, NULL);
+		}
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(asoc_simple_dai_init);
@@ -554,7 +570,7 @@ int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
 EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches);
 
 int asoc_simple_init_jack(struct snd_soc_card *card,
-			  struct asoc_simple_jack *sjack,
+			  struct asoc_simple_jack **sjack,
 			  int is_hp, char *prefix,
 			  char *pin)
 {
@@ -569,8 +585,6 @@ int asoc_simple_init_jack(struct snd_soc_card *card,
 	if (!prefix)
 		prefix = "";
 
-	sjack->gpio.gpio = -ENOENT;
-
 	if (is_hp) {
 		snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix);
 		pin_name	= pin ? pin : "Headphones";
@@ -588,21 +602,26 @@ int asoc_simple_init_jack(struct snd_soc_card *card,
 		return -EPROBE_DEFER;
 
 	if (gpio_is_valid(det)) {
-		sjack->pin.pin		= pin_name;
-		sjack->pin.mask		= mask;
+		struct asoc_simple_jack *sjack_d;
+
+		sjack = devm_kzalloc(dev, sizeof(*(*sjack)), GFP_KERNEL);
+		sjack_d = *sjack;
+
+		sjack_d->pin.pin		= pin_name;
+		sjack_d->pin.mask		= mask;
 
-		sjack->gpio.name	= gpio_name;
-		sjack->gpio.report	= mask;
-		sjack->gpio.gpio	= det;
-		sjack->gpio.invert	= !!(flags & OF_GPIO_ACTIVE_LOW);
-		sjack->gpio.debounce_time = 150;
+		sjack_d->gpio.name	= gpio_name;
+		sjack_d->gpio.report	= mask;
+		sjack_d->gpio.gpio	= det;
+		sjack_d->gpio.invert	= !!(flags & OF_GPIO_ACTIVE_LOW);
+		sjack_d->gpio.debounce_time = 150;
 
 		snd_soc_card_jack_new(card, pin_name, mask,
-				      &sjack->jack,
-				      &sjack->pin, 1);
+				      &sjack_d->jack,
+				      &sjack_d->pin, 1);
 
-		snd_soc_jack_add_gpios(&sjack->jack, 1,
-				       &sjack->gpio);
+		snd_soc_jack_add_gpios(&sjack_d->jack, 1,
+				       &sjack_d->gpio);
 	}
 
 	return 0;
-- 
2.34.1

^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2022-02-20  0:31 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 18:09 [RFC PATCH 1/3] ASoC: simple-card-utils: add support for componants provideing jack events via set_jack Carl Philipp Klemm
2021-12-28 18:09 ` Carl Philipp Klemm
2021-12-28 18:11 ` [RFC PATCH 2/3] ARM: dts: motorola-mapphone: add interrupt for headphone detection Carl Philipp Klemm
2021-12-28 18:11   ` Carl Philipp Klemm
2021-12-28 18:15   ` [RFC PATCH 3/3] ASoC: cpcap: add headphone jack plug detection support Carl Philipp Klemm
2021-12-28 18:15     ` Carl Philipp Klemm
2022-01-04 15:50     ` [RFC PATCH 3/3 V2] " Carl Philipp Klemm
2022-01-04 15:51       ` Carl Philipp Klemm
2022-01-05  5:36 ` [RFC PATCH 1/3] ASoC: simple-card-utils: add support for componants provideing jack events via set_jack kuninori.morimoto.gx
2022-01-05  5:36   ` kuninori.morimoto.gx
2022-01-05  9:10   ` Carl Philipp Klemm
2022-01-05  9:10     ` Carl Philipp Klemm
2022-01-06  1:47     ` kuninori.morimoto.gx
2022-01-06  1:47       ` kuninori.morimoto.gx
2022-01-08 13:57       ` Carl Philipp Klemm
2022-01-08 13:57         ` Carl Philipp Klemm
2022-01-10 23:27         ` Kuninori Morimoto
2022-01-10 23:27           ` Kuninori Morimoto
2022-02-20  0:14           ` [PATCH 1/6] ASoC: simple_card_utils: call snd_soc_component_set_jack() at asoc_simple_init_jack() Carl Philipp Klemm
2022-02-20  0:14             ` Carl Philipp Klemm
2022-02-20  0:15           ` [PATCH 2/6] ASoC: audio-graph-card: use new functionality in simple_card_utils to implement has-hp-jack of property Carl Philipp Klemm
2022-02-20  0:15             ` Carl Philipp Klemm
2022-02-20  0:15           ` [PATCH 3/6] ASoC: cpcap: add headphone jack plug detection support Carl Philipp Klemm
2022-02-20  0:15             ` Carl Philipp Klemm
2022-02-20  0:15           ` [PATCH 4/6] ARM: dts: motorola-mapphone: add interrupt for headphone detection Carl Philipp Klemm
2022-02-20  0:15             ` Carl Philipp Klemm
2022-02-20  0:15           ` [PATCH 5/6] ARM: dts: motorola-mapphone: add has-hp-jack for audio-graph-card Carl Philipp Klemm
2022-02-20  0:15             ` Carl Philipp Klemm
2022-02-20  0:18           ` [PATCH 6/6] Documentation: sound: audio-graph-card: update dts bindings to add has-hp-jack Carl Philipp Klemm
2022-02-20  0:18             ` Carl Philipp Klemm

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.