Discussion:
[PATCH] ASoC: simple-card: Add mic and hp detect gpios.
Dylan Reid
2014-10-01 21:25:20 UTC
Permalink
Allow Headphone and Microphone jack detect gpios to be specified in
device tree. This will allow a few systems including rk3288_max98090
to use simple-card instead of having their own board file.

Signed-off-by: Dylan Reid <dgreid-F7+***@public.gmane.org>
---
.../devicetree/bindings/sound/simple-card.txt | 4 ++
sound/soc/generic/simple-card.c | 73 ++++++++++++++++++++++
2 files changed, 77 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt
index c2e9841..72d94b7 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
@@ -17,6 +17,10 @@ Optional properties:
source.
- simple-audio-card,mclk-fs : Multiplication factor between stream rate and codec
mclk.
+- simple-audio-card,hp_det_gpio : Reference to GPIO that signals when
+ headphones are attached.
+- simple-audio-card,mic_det_gpio : Reference to GPIO that signals when
+ a microphone is attached.

Optional subnodes:

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 709ce67..fcb431f 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -10,10 +10,13 @@
*/
#include <linux/clk.h>
#include <linux/device.h>
+#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/string.h>
+#include <sound/jack.h>
#include <sound/simple_card.h>
#include <sound/soc-dai.h>
#include <sound/soc.h>
@@ -25,6 +28,8 @@ struct simple_card_data {
struct asoc_simple_dai codec_dai;
} *dai_props;
unsigned int mclk_fs;
+ int gpio_hp_det;
+ int gpio_mic_det;
struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
};

@@ -54,6 +59,32 @@ static struct snd_soc_ops asoc_simple_card_ops = {
.hw_params = asoc_simple_card_hw_params,
};

+static struct snd_soc_jack simple_card_hp_jack;
+static struct snd_soc_jack_pin simple_card_hp_jack_pins[] = {
+ {
+ .pin = "Headphones",
+ .mask = SND_JACK_HEADPHONE,
+ },
+};
+static struct snd_soc_jack_gpio simple_card_hp_jack_gpio = {
+ .name = "Headphone detection",
+ .report = SND_JACK_HEADPHONE,
+ .debounce_time = 150,
+};
+
+static struct snd_soc_jack simple_card_mic_jack;
+static struct snd_soc_jack_pin simple_card_mic_jack_pins[] = {
+ {
+ .pin = "Mic Jack",
+ .mask = SND_JACK_MICROPHONE,
+ },
+};
+static struct snd_soc_jack_gpio simple_card_mic_jack_gpio = {
+ .name = "Mic detection",
+ .report = SND_JACK_MICROPHONE,
+ .debounce_time = 150,
+};
+
static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
struct asoc_simple_dai *set)
{
@@ -109,6 +140,28 @@ static int asoc_simple_card_dai_init(struct snd_soc_pcm_runtime *rtd)
if (ret < 0)
return ret;

+ if (gpio_is_valid(priv->gpio_hp_det)) {
+ snd_soc_jack_new(codec->codec, "Headphones", SND_JACK_HEADPHONE,
+ &simple_card_hp_jack);
+ snd_soc_jack_add_pins(&simple_card_hp_jack,
+ ARRAY_SIZE(simple_card_hp_jack_pins),
+ simple_card_hp_jack_pins);
+
+ simple_card_hp_jack_gpio.gpio = priv->gpio_hp_det;
+ snd_soc_jack_add_gpios(&simple_card_hp_jack, 1,
+ &simple_card_hp_jack_gpio);
+ }
+
+ if (gpio_is_valid(priv->gpio_mic_det)) {
+ snd_soc_jack_new(codec->codec, "Mic Jack", SND_JACK_MICROPHONE,
+ &simple_card_mic_jack);
+ snd_soc_jack_add_pins(&simple_card_mic_jack,
+ ARRAY_SIZE(simple_card_mic_jack_pins),
+ simple_card_mic_jack_pins);
+ simple_card_mic_jack_gpio.gpio = priv->gpio_mic_det;
+ snd_soc_jack_add_gpios(&simple_card_mic_jack, 1,
+ &simple_card_mic_jack_gpio);
+ }
return 0;
}

@@ -383,6 +436,16 @@ static int asoc_simple_card_parse_of(struct device_node *node,
return ret;
}

+ priv->gpio_hp_det = of_get_named_gpio(node,
+ "simple-audio-card,hp-det-gpio", 0);
+ if (priv->gpio_hp_det == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
+ priv->gpio_mic_det = of_get_named_gpio(node,
+ "simple-audio-card,mic-det-gpio", 0);
+ if (priv->gpio_mic_det == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
if (!priv->snd_card.name)
priv->snd_card.name = priv->snd_card.dai_link->name;

@@ -502,6 +565,16 @@ err:

static int asoc_simple_card_remove(struct platform_device *pdev)
{
+ struct snd_soc_card *card = platform_get_drvdata(pdev);
+ struct simple_card_data *priv = snd_soc_card_get_drvdata(card);
+
+ if (gpio_is_valid(priv->gpio_hp_det))
+ snd_soc_jack_free_gpios(&simple_card_hp_jack, 1,
+ &simple_card_hp_jack_gpio);
+ if (gpio_is_valid(priv->gpio_mic_det))
+ snd_soc_jack_free_gpios(&simple_card_mic_jack, 1,
+ &simple_card_mic_jack_gpio);
+
return asoc_simple_card_unref(pdev);
}
--
2.1.0.rc2.206.gedb03e5

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
2014-10-02 15:53:50 UTC
Permalink
Post by Dylan Reid
Allow Headphone and Microphone jack detect gpios to be specified in
device tree. This will allow a few systems including rk3288_max98090
to use simple-card instead of having their own board file.
Applied, thanks.
Geert Uytterhoeven
2014-10-07 12:32:57 UTC
Permalink
This post might be inappropriate. Click to display it.
Mark Brown
2014-10-07 12:38:56 UTC
Permalink
Post by Geert Uytterhoeven
sh-mobile-hdmi sh-mobile-hdmi: SH Mobile HDMI Audio Codec
sh-mobile-hdmi sh-mobile-hdmi: ASoC: DAPM unknown pin Headphones
sh-mobile-hdmi sh-mobile-hdmi: ASoC: DAPM unknown pin Mic Jack
sh-mobile-hdmi sh-mobile-hdmi: ASoC: DAPM unknown pin Headphones
Reverting commit 3fe240326cc395c66 ("ASoC: simple-card: Add mic and
hp detect gpios.") fixes this.
The fix here is to not allow 0 as a GPIO in the core code (which
should've been there already).
Geert Uytterhoeven
2014-10-07 13:10:01 UTC
Permalink
This post might be inappropriate. Click to display it.
Mark Brown
2014-10-07 16:36:54 UTC
Permalink
Post by Geert Uytterhoeven
Post by Mark Brown
The fix here is to not allow 0 as a GPIO in the core code (which
should've been there already).
Unfortunately it's not there.
And it's not as simple as changing the definition of gpio_is_valid()
gpiochip_add: GPIOs 0..211 (r8a7740_pfc) failed to register
sh-pfc pfc-r8a7740: failed to init GPIO chip, ignoring...
sh-pfc pfc-r8a7740: r8a7740_pfc support registered
Unable to handle kernel NULL pointer dereference at virtual address 0000004c
Right, obviously it's not going to work if the platform actually uses 0
as a valid GPIO.
Post by Geert Uytterhoeven
"Fixing the old global GPIO numberspace API is a waste of time IMO".
Hence I've just sent a patch to initialize the GPIO numbers with -ENOENT.
I do think it's worth renumbering the platforms since it's *relatively*
little work per platform compared to completing the gpiod transition.
Alexandre Courbot
2014-10-08 07:05:59 UTC
Permalink
Post by Mark Brown
Post by Geert Uytterhoeven
Post by Mark Brown
The fix here is to not allow 0 as a GPIO in the core code (which
should've been there already).
Unfortunately it's not there.
And it's not as simple as changing the definition of gpio_is_valid()
gpiochip_add: GPIOs 0..211 (r8a7740_pfc) failed to register
sh-pfc pfc-r8a7740: failed to init GPIO chip, ignoring...
sh-pfc pfc-r8a7740: r8a7740_pfc support registered
Unable to handle kernel NULL pointer dereference at virtual address 0000004c
Right, obviously it's not going to work if the platform actually uses 0
as a valid GPIO.
Post by Geert Uytterhoeven
"Fixing the old global GPIO numberspace API is a waste of time IMO".
Hence I've just sent a patch to initialize the GPIO numbers with -ENOENT.
I do think it's worth renumbering the platforms since it's *relatively*
little work per platform compared to completing the gpiod transition.
But transition to gpiod is the way to ultimately fix this issue, as
well as many others. Not to mention that renumbering GPIOs will
certainly make a few users of the GPIO sysfs (another abomination,
agreed) unhappy. I can only recommend switching drivers to gpiod when
such issues are spotted.
--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Linus Walleij
2014-10-08 08:50:00 UTC
Permalink
Post by Alexandre Courbot
Post by Mark Brown
Right, obviously it's not going to work if the platform actually uses 0
as a valid GPIO.
Post by Geert Uytterhoeven
"Fixing the old global GPIO numberspace API is a waste of time IMO".
Hence I've just sent a patch to initialize the GPIO numbers with -ENOENT.
I do think it's worth renumbering the platforms since it's *relatively*
little work per platform compared to completing the gpiod transition.
But transition to gpiod is the way to ultimately fix this issue, as
well as many others. Not to mention that renumbering GPIOs will
certainly make a few users of the GPIO sysfs (another abomination,
agreed) unhappy. I can only recommend switching drivers to gpiod when
such issues are spotted.
Yeah that is another issue ... we end up in catch 22 situations like
that, renumber the GPIOs, OK, then we break the ABI.

Admittedly that "ABI" is something people break all the time,
/sys/*gpioN just isnt what it should be, not stable at all.

I'm not against renumbering GPIO if it's minor effort, but if it
start to consume hundreds of hours and regressions and what not,
that time is better spent focusing on the gpiod transition.

Yours,
Linus Walleij
Mark Brown
2014-10-08 11:40:24 UTC
Permalink
Post by Linus Walleij
Post by Alexandre Courbot
But transition to gpiod is the way to ultimately fix this issue, as
well as many others. Not to mention that renumbering GPIOs will
certainly make a few users of the GPIO sysfs (another abomination,
agreed) unhappy. I can only recommend switching drivers to gpiod when
such issues are spotted.
Yeah that is another issue ... we end up in catch 22 situations like
that, renumber the GPIOs, OK, then we break the ABI.
Admittedly that "ABI" is something people break all the time,
/sys/*gpioN just isnt what it should be, not stable at all.
I'm not against renumbering GPIO if it's minor effort, but if it
start to consume hundreds of hours and regressions and what not,
that time is better spent focusing on the gpiod transition.
My guess is that it's relatively little work for most platforms - with
the systems I've done enough work on to notice everything is keyed off a
few defines in the header file. Things tend to be worse in out of tree
code but mainline's generally been pretty good.
Lars-Peter Clausen
2014-10-02 16:25:23 UTC
Permalink
Post by Dylan Reid
diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt b/Documentation/devicetree/bindings/sound/simple-card.txt
index c2e9841..72d94b7 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
source.
- simple-audio-card,mclk-fs : Multiplication factor between stream rate and codec
mclk.
+- simple-audio-card,hp_det_gpio : Reference to GPIO that signals when
+ headphones are attached.
+- simple-audio-card,mic_det_gpio : Reference to GPIO that signals when
The code has this correct, the "_"s should be "-"s.

- Lars

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Dylan Reid
2014-10-02 16:57:59 UTC
Permalink
Post by Lars-Peter Clausen
Post by Dylan Reid
diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt
b/Documentation/devicetree/bindings/sound/simple-card.txt
index c2e9841..72d94b7 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
source.
- simple-audio-card,mclk-fs : Multiplication factor between
stream rate and codec
mclk.
+- simple-audio-card,hp_det_gpio : Reference to GPIO that
signals when
+ headphones are attached.
+- simple-audio-card,mic_det_gpio : Reference to GPIO that signals
when
The code has this correct, the "_"s should be "-"s.
Indeed, my fault. Sorry about that. I will post a patch once the
first one propagates.
Post by Lars-Peter Clausen
- Lars
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Jianqun
2014-10-22 06:44:51 UTC
Permalink
Post by Dylan Reid
Allow Headphone and Microphone jack detect gpios to be specified in
device tree. This will allow a few systems including rk3288_max98090
to use simple-card instead of having their own board file.
---
.../devicetree/bindings/sound/simple-card.txt | 4 ++
sound/soc/generic/simple-card.c | 73 ++++++++++++=
++++++++++
Post by Dylan Reid
2 files changed, 77 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/simple-card.txt =
b/Documentation/devicetree/bindings/sound/simple-card.txt
Post by Dylan Reid
index c2e9841..72d94b7 100644
--- a/Documentation/devicetree/bindings/sound/simple-card.txt
+++ b/Documentation/devicetree/bindings/sound/simple-card.txt
source.
- simple-audio-card,mclk-fs : Multiplication factor betw=
een stream rate and codec
Post by Dylan Reid
mclk.
+- simple-audio-card,hp_det_gpio : Reference to GPIO that signals wh=
en
Post by Dylan Reid
+ headphones are attached.
+- simple-audio-card,mic_det_gpio : Reference to GPIO that signals wh=
en
Post by Dylan Reid
+ a microphone is attached.
=20
=20
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simp=
le-card.c
Post by Dylan Reid
index 709ce67..fcb431f 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -10,10 +10,13 @@
*/
#include <linux/clk.h>
#include <linux/device.h>
+#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/string.h>
+#include <sound/jack.h>
#include <sound/simple_card.h>
#include <sound/soc-dai.h>
#include <sound/soc.h>
@@ -25,6 +28,8 @@ struct simple_card_data {
struct asoc_simple_dai codec_dai;
} *dai_props;
unsigned int mclk_fs;
+ int gpio_hp_det;
+ int gpio_mic_det;
struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
};
=20
@@ -54,6 +59,32 @@ static struct snd_soc_ops asoc_simple_card_ops =3D=
{
Post by Dylan Reid
.hw_params =3D asoc_simple_card_hw_params,
};
=20
+static struct snd_soc_jack simple_card_hp_jack;
+static struct snd_soc_jack_pin simple_card_hp_jack_pins[] =3D {
+ {
+ .pin =3D "Headphones",
+ .mask =3D SND_JACK_HEADPHONE,
+ },
+};
+static struct snd_soc_jack_gpio simple_card_hp_jack_gpio =3D {
+ .name =3D "Headphone detection",
+ .report =3D SND_JACK_HEADPHONE,
+ .debounce_time =3D 150,
I think some board needs "invert" trigger level, i.e need to add "inver=
t" property in dt ?
Pinky board do need it.
Post by Dylan Reid
+};
+
+static struct snd_soc_jack simple_card_mic_jack;
+static struct snd_soc_jack_pin simple_card_mic_jack_pins[] =3D {
+ {
+ .pin =3D "Mic Jack",
+ .mask =3D SND_JACK_MICROPHONE,
+ },
+};
+static struct snd_soc_jack_gpio simple_card_mic_jack_gpio =3D {
+ .name =3D "Mic detection",
+ .report =3D SND_JACK_MICROPHONE,
+ .debounce_time =3D 150,
+};
+
static int __asoc_simple_card_dai_init(struct snd_soc_dai *dai,
struct asoc_simple_dai *set)
{
@@ -109,6 +140,28 @@ static int asoc_simple_card_dai_init(struct snd_=
soc_pcm_runtime *rtd)
Post by Dylan Reid
if (ret < 0)
return ret;
=20
+ if (gpio_is_valid(priv->gpio_hp_det)) {
+ snd_soc_jack_new(codec->codec, "Headphones", SND_JACK_HEADPHONE,
+ &simple_card_hp_jack);
+ snd_soc_jack_add_pins(&simple_card_hp_jack,
+ ARRAY_SIZE(simple_card_hp_jack_pins),
+ simple_card_hp_jack_pins);
+
+ simple_card_hp_jack_gpio.gpio =3D priv->gpio_hp_det;
+ snd_soc_jack_add_gpios(&simple_card_hp_jack, 1,
+ &simple_card_hp_jack_gpio);
+ }
+
+ if (gpio_is_valid(priv->gpio_mic_det)) {
+ snd_soc_jack_new(codec->codec, "Mic Jack", SND_JACK_MICROPHONE,
+ &simple_card_mic_jack);
+ snd_soc_jack_add_pins(&simple_card_mic_jack,
+ ARRAY_SIZE(simple_card_mic_jack_pins),
+ simple_card_mic_jack_pins);
+ simple_card_mic_jack_gpio.gpio =3D priv->gpio_mic_det;
+ snd_soc_jack_add_gpios(&simple_card_mic_jack, 1,
+ &simple_card_mic_jack_gpio);
+ }
return 0;
}
=20
@@ -383,6 +436,16 @@ static int asoc_simple_card_parse_of(struct devi=
ce_node *node,
Post by Dylan Reid
return ret;
}
=20
+ priv->gpio_hp_det =3D of_get_named_gpio(node,
+ "simple-audio-card,hp-det-gpio", 0);
+ if (priv->gpio_hp_det =3D=3D -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
+ priv->gpio_mic_det =3D of_get_named_gpio(node,
+ "simple-audio-card,mic-det-gpio", 0);
+ if (priv->gpio_mic_det =3D=3D -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+
if (!priv->snd_card.name)
priv->snd_card.name =3D priv->snd_card.dai_link->name;
=20
=20
static int asoc_simple_card_remove(struct platform_device *pdev)
{
+ struct snd_soc_card *card =3D platform_get_drvdata(pdev);
+ struct simple_card_data *priv =3D snd_soc_card_get_drvdata(card);
+
+ if (gpio_is_valid(priv->gpio_hp_det))
+ snd_soc_jack_free_gpios(&simple_card_hp_jack, 1,
+ &simple_card_hp_jack_gpio);
+ if (gpio_is_valid(priv->gpio_mic_det))
+ snd_soc_jack_free_gpios(&simple_card_mic_jack, 1,
+ &simple_card_mic_jack_gpio);
+
return asoc_simple_card_unref(pdev);
}
=20
--=20
Jianqun Xu

***********************************************************************=
*****
*IMPORTANT NOTICE:*This email is from Fuzhou Rockchip Electronics Co.,
Ltd .The contents of this email and any attachments may contain
information that is privileged, confidential and/or exempt from
disclosure under applicable law and relevant NDA. If you are not the
intended recipient, you are hereby notified that any disclosure,
copying, distribution, or use of the information is STRICTLY PROHIBITED=
=2E
Please immediately contact the sender as soon as possible and destroy
the material in its entirety in any format. Thank you.
***********************************************************************=
*****


--
To unsubscribe from this list: send the line "unsubscribe devicetree" i=
n
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...