1 From 98b1f1df855ead7eec5f8c9032736046752e5593 Mon Sep 17 00:00:00 2001
2 From: Tim Yamin <plasm@roo.me.uk>
3 Date: Wed, 29 Apr 2009 17:30:25 -0700
4 Subject: [PATCH 10/14] Touch Book: turn on/off the class D amplifier depending on whether the headphones are plugged into the jack or not.
6 Signed-off-by: Tim Yamin <plasm@roo.me.uk>
8 sound/soc/omap/omap3beagle.c | 45 ++++++++++++++++++++++++++++++++++++++++++
9 1 files changed, 45 insertions(+), 0 deletions(-)
11 diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c
12 index 248b789..8b2d9e4 100644
13 --- a/sound/soc/omap/omap3beagle.c
14 +++ b/sound/soc/omap/omap3beagle.c
18 #include <linux/clk.h>
19 +#include <linux/irq.h>
20 +#include <linux/interrupt.h>
21 #include <linux/platform_device.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/soc.h>
28 #include "../codecs/twl4030.h"
30 +#define TB_HEADPHONE_GPIO 56
31 +#define TB_HEADPHONE_IRQ OMAP_GPIO_IRQ(TB_HEADPHONE_GPIO)
33 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
34 struct snd_pcm_hw_params *params)
36 @@ -113,6 +119,33 @@ static struct snd_soc_device omap3beagle_snd_devdata = {
38 static struct platform_device *omap3beagle_snd_device;
40 +static void jack_work_func(struct work_struct *wq)
42 + struct snd_soc_device *socdev = platform_get_drvdata(omap3beagle_snd_device);
43 + struct snd_soc_codec *codec = socdev->card->codec;
45 + snd_soc_dapm_sync(codec);
47 +DECLARE_WORK(jack_work, jack_work_func);
49 +static irqreturn_t touchbook_headphone_event(int irq, void *snd)
51 + int status = gpio_get_value(TB_HEADPHONE_GPIO);
52 + struct snd_soc_device *socdev = platform_get_drvdata(omap3beagle_snd_device);
53 + struct snd_soc_codec *codec = socdev->card->codec;
56 + snd_soc_dapm_disable_pin(codec, "HFL");
57 + snd_soc_dapm_disable_pin(codec, "HFR");
59 + snd_soc_dapm_enable_pin(codec, "HFL");
60 + snd_soc_dapm_enable_pin(codec, "HFR");
63 + schedule_work(&jack_work);
67 static int __init omap3beagle_soc_init(void)
70 @@ -133,10 +166,22 @@ static int __init omap3beagle_soc_init(void)
71 omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev;
72 *(unsigned int *)omap3beagle_dai.cpu_dai->private_data = 1; /* McBSP2 */
74 + /* Touch Book -- headphone jack sensor */
75 + omap_set_gpio_debounce(TB_HEADPHONE_GPIO, 1);
76 + omap_set_gpio_debounce_time(TB_HEADPHONE_GPIO, 0xff);
78 + ret = request_irq(TB_HEADPHONE_IRQ, touchbook_headphone_event, IRQF_TRIGGER_RISING |
79 + IRQF_TRIGGER_FALLING, "touchbook_headphone", omap3beagle_snd_device);
83 ret = platform_device_add(omap3beagle_snd_device);
87 + /* Detect headphone status */
88 + touchbook_headphone_event(0, omap3beagle_snd_device);