diff mbox

[15/49] ASoC: simple-card-core: add asoc_simple_card_init_jack()

Message ID 87zirlqd4t.wl%kuninori.morimoto.gx@renesas.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show

Commit Message

Kuninori Morimoto May 20, 2016, 9:48 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

simple-card is supporting jack/gpio.
This patch makes this method simple style standard.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 include/sound/simple_card_core.h     | 18 +++++++++++
 sound/soc/generic/simple-card-core.c | 60 ++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+)

Comments

Mark Brown May 30, 2016, 5:14 p.m. UTC | #1
On Fri, May 20, 2016 at 09:48:38AM +0000, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> simple-card is supporting jack/gpio.
> This patch makes this method simple style standard.

There was some recent discussion about a more complete core binding
for this based on the work that Dylan Reid had been pushing a while ago
- it's not clear that the simple-card binding is great for
generalization here.
Kuninori Morimoto May 31, 2016, 2:08 a.m. UTC | #2
Hi Mark

> > From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> > 
> > simple-card is supporting jack/gpio.
> > This patch makes this method simple style standard.
> 
> There was some recent discussion about a more complete core binding
> for this based on the work that Dylan Reid had been pushing a while ago
> - it's not clear that the simple-card binding is great for
> generalization here.

Can you show me where can I see it ?
Anyway, I will keep this related function as static in simple-card,
not simple-card-utils in v2.

Best regards
---
Kuninori Morimoto
Mark Brown May 31, 2016, 2:51 p.m. UTC | #3
On Tue, May 31, 2016 at 02:08:31AM +0000, Kuninori Morimoto wrote:

> > There was some recent discussion about a more complete core binding
> > for this based on the work that Dylan Reid had been pushing a while ago
> > - it's not clear that the simple-card binding is great for
> > generalization here.

> Can you show me where can I see it ?
> Anyway, I will keep this related function as static in simple-card,
> not simple-card-utils in v2.

This is the proposal from Dylan I was thinking of:

   http://thread.gmane.org/gmane.linux.alsa.devel/138906
diff mbox

Patch

diff --git a/include/sound/simple_card_core.h b/include/sound/simple_card_core.h
index 5e2e824..d37acee 100644
--- a/include/sound/simple_card_core.h
+++ b/include/sound/simple_card_core.h
@@ -11,6 +11,13 @@ 
 #define __SIMPLE_CARD_CORE_H
 
 #include <sound/soc.h>
+#include <sound/jack.h>
+
+struct asoc_simple_jack {
+	struct snd_soc_jack jack;
+	struct snd_soc_jack_pin pin;
+	struct snd_soc_jack_gpio gpio;
+};
 
 struct asoc_simple_dai {
 	const char *name;
@@ -76,4 +83,15 @@  int asoc_simple_card_parse_endpoint(struct device_node *port_np,
 void asoc_simple_card_parse_dpcm(struct snd_soc_dai_link *dai_link,
 			int (*be_fixup)(struct snd_soc_pcm_runtime *rtd,
 					struct snd_pcm_hw_params *params));
+
+#define asoc_simple_card_init_hp(card, sjack, prefix)		\
+	asoc_simple_card_init_jack(card, sjack, 1, prefix)
+#define asoc_simple_card_init_mic(card, sjack, prefix)		\
+	asoc_simple_card_init_jack(card, sjack, 0, prefix)
+int asoc_simple_card_init_jack(struct snd_soc_card *card,
+			       struct asoc_simple_jack *sjack,
+			       int is_hp, char *prefix);
+
+void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack);
+
 #endif /* __SIMPLE_CARD_CORE_H */
diff --git a/sound/soc/generic/simple-card-core.c b/sound/soc/generic/simple-card-core.c
index d3aab6d..86f64da 100644
--- a/sound/soc/generic/simple-card-core.c
+++ b/sound/soc/generic/simple-card-core.c
@@ -9,6 +9,7 @@ 
  */
 #include <linux/clk.h>
 #include <linux/of.h>
+#include <linux/of_gpio.h>
 #include <sound/simple_card_core.h>
 
 int asoc_simple_card_parse_daifmt(struct device *dev,
@@ -271,3 +272,62 @@  void asoc_simple_card_parse_dpcm(struct snd_soc_dai_link *dai_link,
 	dai_link->dpcm_capture		= 1;
 }
 EXPORT_SYMBOL_GPL(asoc_simple_card_parse_dpcm);
+
+int asoc_simple_card_init_jack(struct snd_soc_card *card,
+			       struct asoc_simple_jack *sjack,
+			       int is_hp, char *prefix)
+{
+	struct device *dev = card->dev;
+	enum of_gpio_flags flags;
+	char prop[128];
+	char *pin_name;
+	char *gpio_name;
+	int mask;
+	int det;
+
+	sjack->gpio.gpio = -ENOENT;
+
+	if (is_hp) {
+		snprintf(prop, sizeof(prop), "%shp-det-gpio", prefix);
+		pin_name	= "Headphones";
+		gpio_name	= "Headphone detection";
+		mask		= SND_JACK_HEADPHONE;
+	} else {
+		snprintf(prop, sizeof(prop), "%smic-det-gpio", prefix);
+		pin_name	= "Mic Jack";
+		gpio_name	= "Mic detection";
+		mask		= SND_JACK_MICROPHONE;
+	}
+
+	det = of_get_named_gpio_flags(dev->of_node, prop, 0, &flags);
+	if (det == -EPROBE_DEFER)
+		return -EPROBE_DEFER;
+
+	if (gpio_is_valid(det)) {
+		sjack->pin.pin		= pin_name;
+		sjack->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;
+
+		snd_soc_card_jack_new(card, pin_name, mask,
+				      &sjack->jack,
+				      &sjack->pin, 1);
+
+		snd_soc_jack_add_gpios(&sjack->jack, 1,
+				       &sjack->gpio);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack);
+
+void asoc_simple_card_remove_jack(struct asoc_simple_jack *sjack)
+{
+	if (gpio_is_valid(sjack->gpio.gpio))
+		snd_soc_jack_free_gpios(&sjack->jack, 1, &sjack->gpio);
+}
+EXPORT_SYMBOL_GPL(asoc_simple_card_remove_jack);