Skip to contentSkip to conversation

ASoC: Add GPIO based jack device

PATCH In review Dylan Reid 2 participants 2 messages May 26, 2015

Subsystems (3)
lore
Share & tools
lore

Dylan Reid

author
#0 lore raw

PATCH v2 1/1 ASoC: Add GPIO based jack device

Add a jack device that allows for separate headphone and mic detect GPIOs. This device will be used as an aux device and will registered the jack with the card at init time.

The gpios are each optional allowing for a headphone, microphone, or combination devices to be created depending on the board configuration. A board will be able to have several of these jacks, one for each physical connection.

---
Tested on Acer Chromebook 13 Tegra device.
I'm travelling this week, I'll try to get the rockchip team to integrate this with simple card for the 3288.

Changes since v1:
Static component_driver
Coding style
Improve error handling
Get GPIOs in device probe to better handle EPROBE_DEFER

---
 .../devicetree/bindings/sound/gpio-audio-jack.txt  |  39 ++++
 sound/soc/codecs/Kconfig                           |   5 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/gpio-audio-jack.c                 | 201 +++++++++++++++++++++
 4 files changed, 247 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/gpio-audio-jack.txt
 create mode 100644 sound/soc/codecs/gpio-audio-jack.c
Documentation/devicetree/bindings/sound/gpio-audio-jack.txt new file +39 -0
new file mode 100644
index 0000000..5505a49
@@ -0,0 +1,39 @@
+Gpio-Audio-Jack:
+
+GPIO based audio jacks.  This can represent a headphone, mic, or combo jack.
+
+Required properties:
+
+- compatible				: "linux,gpio-audio-jack"
+
+Optional properties:
+
+- gpio-audio-jack,jack-name		: Name of the jack. Normally
+					  'Headphone Jack', 'Mic Jack', or
+					  'Headset Jack'
+- gpio-audio-jack,sw-det-gpios		: Reference to GPIOs that signals when
+					  a jack is plugged.
+- gpio-audio-jack,gpio-names		: Names of the GPIOs. Must provide one
+					  per sw-det-gpio entry.
+- gpio-audio-jack,report-masks		: Jack report mask from
+					  dt-bindings/sound/audio-jack-events.h.
+					  Must have one per sw-det-gpio entry.
+- gpio-audio-jack,debounce-times	: Debounce time in milliseconds for each
+					  sw-det-gpio entry.
+
+Example of Headphone/Mic combo jack:
+
+audio_jack: gpio-audio-jack {
+	compatible = "linux,gpio-audio-jack";
+	gpio-audio-jack,jack-name = "Headset Jack";
+	gpio-audio-jack,sw-det-gpios =
+			<&gpio TEGRA_GPIO(I, 7) GPIO_ACTIVE_HIGH>,
+			<&gpio TEGRA_GPIO(R, 7) GPIO_ACTIVE_LOW>;
+	gpio-audio-jack,gpio-names = "Headphones", "Mic Jack";
+	gpio-audio-jack,report-masks = <JACK_HEADPHONE>, <JACK_MICROPHONE>;
+	gpio-audio-jack,debounce-times = <150>, <150>;
+};
+
+sound {
+	nvidia,headset-dev = <&audio_jack>;
+	...
sound/soc/codecs/Kconfig +5 -0
index 061c465..4147593 100644
@@ -62,6 +62,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_BT_SCO
 	select SND_SOC_ES8328_SPI if SPI_MASTER
 	select SND_SOC_ES8328_I2C if I2C
+	select SND_SOC_GPIO_AUDIO_JACK
 	select SND_SOC_ISABELLE if I2C
 	select SND_SOC_JZ4740_CODEC
 	select SND_SOC_LM4857 if I2C
@@ -444,6 +445,10 @@ config SND_SOC_ES8328_SPI
 	tristate
 	select SND_SOC_ES8328
 
+config SND_SOC_GPIO_AUDIO_JACK
+        tristate "GPIO based audio jack detection"
+	depends on GPIOLIB || COMPILE_TEST
+
 config SND_SOC_ISABELLE
         tristate
 
sound/soc/codecs/Makefile +2 -0
index abe2d7e..ae570f5 100644
@@ -55,6 +55,7 @@ snd-soc-dmic-objs := dmic.o
 snd-soc-es8328-objs := es8328.o
 snd-soc-es8328-i2c-objs := es8328-i2c.o
 snd-soc-es8328-spi-objs := es8328-spi.o
+snd-soc-gpio-audio-jack-objs := gpio-audio-jack.o
 snd-soc-isabelle-objs := isabelle.o
 snd-soc-jz4740-codec-objs := jz4740.o
 snd-soc-l3-objs := l3.o
@@ -240,6 +241,7 @@ obj-$(CONFIG_SND_SOC_DMIC)	+= snd-soc-dmic.o
 obj-$(CONFIG_SND_SOC_ES8328)	+= snd-soc-es8328.o
 obj-$(CONFIG_SND_SOC_ES8328_I2C)+= snd-soc-es8328-i2c.o
 obj-$(CONFIG_SND_SOC_ES8328_SPI)+= snd-soc-es8328-spi.o
+obj-$(CONFIG_SND_SOC_GPIO_AUDIO_JACK)	+= snd-soc-gpio-audio-jack.o
 obj-$(CONFIG_SND_SOC_ISABELLE)	+= snd-soc-isabelle.o
 obj-$(CONFIG_SND_SOC_JZ4740_CODEC)	+= snd-soc-jz4740-codec.o
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
sound/soc/codecs/gpio-audio-jack.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.2.1.62.g3f15098
maintainer
#1 lore raw

Documentation/devicetree/bindings/sound/gpio-audio-jack.txt line 7

Quoted 3 lines · Dylan Reid
Documentation/devicetree/bindings/sound/gpio-audio-jack.txt new file +3 -0
+Required properties:
+
+- compatible				: "linux,gpio-audio-jack"

As mentioned in the discussion of v1 I think we should drop gpio- from this - Lars is right that we should really be more generic and there's no reason this can't serve as a non-GPIO jack especially given that...

Documentation/devicetree/bindings/sound/gpio-audio-jack.txt line 15

Quoted 8 lines
Documentation/devicetree/bindings/sound/gpio-audio-jack.txt new file +8 -0
+
+Optional properties:
+
+- gpio-audio-jack,jack-name		: Name of the jack. Normally
+					  'Headphone Jack', 'Mic Jack', or
+					  'Headset Jack'
+- gpio-audio-jack,sw-det-gpios		: Reference to GPIOs that signals when
+					  a jack is plugged.

...GPIOs are optional anyway! However I think Lars had further concerns about abstraction which I seem to have missed.