aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/linux/linux-omap-psp-2.6.32/omap3-touchbook/0010-Touch-Book-turn-on-off-the-class-D-amplifier-dependi.patch
blob: 67d2b18907418a6acc5af8b34f76a3d2970d741b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From 98b1f1df855ead7eec5f8c9032736046752e5593 Mon Sep 17 00:00:00 2001
From: Tim Yamin <plasm@roo.me.uk>
Date: Wed, 29 Apr 2009 17:30:25 -0700
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.

Signed-off-by: Tim Yamin <plasm@roo.me.uk>
---
 sound/soc/omap/omap3beagle.c |   45 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/sound/soc/omap/omap3beagle.c b/sound/soc/omap/omap3beagle.c
index 248b789..8b2d9e4 100644
--- a/sound/soc/omap/omap3beagle.c
+++ b/sound/soc/omap/omap3beagle.c
@@ -20,7 +20,10 @@
  */
 
 #include <linux/clk.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
 #include <linux/platform_device.h>
+
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/soc.h>
@@ -35,6 +38,9 @@
 #include "omap-pcm.h"
 #include "../codecs/twl4030.h"
 
+#define TB_HEADPHONE_GPIO 56
+#define TB_HEADPHONE_IRQ  OMAP_GPIO_IRQ(TB_HEADPHONE_GPIO)
+
 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *params)
 {
@@ -113,6 +119,33 @@ static struct snd_soc_device omap3beagle_snd_devdata = {
 
 static struct platform_device *omap3beagle_snd_device;
 
+static void jack_work_func(struct work_struct *wq)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(omap3beagle_snd_device);
+	struct snd_soc_codec *codec = socdev->card->codec;
+
+	snd_soc_dapm_sync(codec);
+}
+DECLARE_WORK(jack_work, jack_work_func);
+
+static irqreturn_t touchbook_headphone_event(int irq, void *snd)
+{
+	int status = gpio_get_value(TB_HEADPHONE_GPIO);
+	struct snd_soc_device *socdev = platform_get_drvdata(omap3beagle_snd_device);
+	struct snd_soc_codec *codec = socdev->card->codec;
+
+	if(status) {
+		snd_soc_dapm_disable_pin(codec, "HFL");
+		snd_soc_dapm_disable_pin(codec, "HFR");
+        } else {
+		snd_soc_dapm_enable_pin(codec, "HFL");
+		snd_soc_dapm_enable_pin(codec, "HFR");
+	}
+
+	schedule_work(&jack_work);
+	return IRQ_HANDLED;
+}
+
 static int __init omap3beagle_soc_init(void)
 {
 	int ret;
@@ -133,10 +166,22 @@ static int __init omap3beagle_soc_init(void)
 	omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev;
 	*(unsigned int *)omap3beagle_dai.cpu_dai->private_data = 1; /* McBSP2 */
 
+	/* Touch Book -- headphone jack sensor */
+	omap_set_gpio_debounce(TB_HEADPHONE_GPIO, 1);
+	omap_set_gpio_debounce_time(TB_HEADPHONE_GPIO, 0xff);
+
+	ret = request_irq(TB_HEADPHONE_IRQ, touchbook_headphone_event, IRQF_TRIGGER_RISING |
+			  IRQF_TRIGGER_FALLING, "touchbook_headphone", omap3beagle_snd_device);
+	if (ret < 0)
+		goto err1;
+
 	ret = platform_device_add(omap3beagle_snd_device);
 	if (ret)
 		goto err1;
 
+	/* Detect headphone status */
+	touchbook_headphone_event(0, omap3beagle_snd_device);
+
 	return 0;
 
 err1:
-- 
1.6.6.1