]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00137340-1 ASOC: add headphone detection support for imx-sgtl5000.c
authorZhang Jiejing <jiejing.zhang@freescale.com>
Fri, 15 Apr 2011 01:59:03 +0000 (09:59 +0800)
committerOliver Wendt <ow@karo-electronics.de>
Mon, 30 Sep 2013 12:08:58 +0000 (14:08 +0200)
add a asoc headphone detection, it's a generic way using by asoc area.

Signed-off-by: Zhang Jiejing <jiejing.zhang@freescale.com>
include/linux/fsl_devices.h
sound/soc/imx/imx-sgtl5000.c

index d28f9db2d4eda43974078ba24dead0247d83e4d0..6cc1a4e755816dee46dcdf328e055682e4ecdff9 100644 (file)
@@ -271,8 +271,8 @@ struct mxc_audio_platform_data {
        int ext_ram;
        struct clk *ssi_clk[2];
 
-       int hp_irq;
-       int (*hp_status) (void);
+       int hp_gpio;
+       int hp_active_low;      /* headphone irq is active loaw */
 
        int sysclk;
 
index 3ccf26368039234fbc142930567bd4f7ba7f16f1..4da55ad781bf0064afae5bf301ad8db094c3e148 100644 (file)
 #include <linux/moduleparam.h>
 #include <linux/device.h>
 #include <linux/i2c.h>
+#include <linux/fsl_devices.h>
+#include <linux/gpio.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/soc.h>
+#include <sound/jack.h>
 #include <sound/soc-dapm.h>
 #include <asm/mach-types.h>
 #include <mach/audmux.h>
-#include <linux/fsl_devices.h>
 
 #include "../codecs/sgtl5000.h"
 #include "imx-ssi.h"
@@ -32,8 +34,27 @@ static struct imx_sgtl5000_priv {
        struct platform_device *pdev;
 } card_priv;
 
+static struct snd_soc_jack hs_jack;
 static struct snd_soc_card imx_sgtl5000;
 
+/* Headphones jack detection DAPM pins */
+static struct snd_soc_jack_pin hs_jack_pins[] = {
+       {
+               .pin = "Headphone Jack",
+               .mask = SND_JACK_HEADPHONE,
+       },
+};
+
+/* Headphones jack detection gpios */
+static struct snd_soc_jack_gpio hs_jack_gpios[] = {
+       [0] = {
+               /* gpio is set on per-platform basis */
+               .name           = "hp-gpio",
+               .report         = SND_JACK_HEADPHONE,
+               .debounce_time  = 200,
+       },
+};
+
 static int sgtl5000_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
@@ -226,9 +247,28 @@ static int imx_3stack_sgtl5000_init(struct snd_soc_pcm_runtime *rtd)
 
        snd_soc_dapm_disable_pin(&codec->dapm, "Line In Jack");
        snd_soc_dapm_enable_pin(&codec->dapm, "Headphone Jack");
-
        snd_soc_dapm_sync(&codec->dapm);
 
+       /* Jack detection API stuff */
+       ret = snd_soc_jack_new(codec, "Headphone Jack",
+                              SND_JACK_HEADPHONE, &hs_jack);
+       if (ret)
+               return ret;
+
+       ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
+                               hs_jack_pins);
+       if (ret) {
+               printk(KERN_ERR "failed to call  snd_soc_jack_add_pins\n");
+               return ret;
+       }
+
+       ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
+                               hs_jack_gpios);
+       if (ret) {
+               printk(KERN_ERR "failed to call snd_soc_jack_add_gpios\n");
+               return ret;
+       }
+
        return 0;
 }
 
@@ -291,6 +331,9 @@ static int __devinit imx_sgtl5000_probe(struct platform_device *pdev)
 
        card_priv.sysclk = plat->sysclk;
 
+       hs_jack_gpios[0].gpio = plat->hp_gpio;
+       hs_jack_gpios[0].invert = plat->hp_active_low;
+
        return 0;
 }