67d2b18907418a6acc5af8b34f76a3d2970d741b
[openembedded.git] /
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.
5
6 Signed-off-by: Tim Yamin <plasm@roo.me.uk>
7 ---
8  sound/soc/omap/omap3beagle.c |   45 ++++++++++++++++++++++++++++++++++++++++++
9  1 files changed, 45 insertions(+), 0 deletions(-)
10
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
15 @@ -20,7 +20,10 @@
16   */
17  
18  #include <linux/clk.h>
19 +#include <linux/irq.h>
20 +#include <linux/interrupt.h>
21  #include <linux/platform_device.h>
22 +
23  #include <sound/core.h>
24  #include <sound/pcm.h>
25  #include <sound/soc.h>
26 @@ -35,6 +38,9 @@
27  #include "omap-pcm.h"
28  #include "../codecs/twl4030.h"
29  
30 +#define TB_HEADPHONE_GPIO 56
31 +#define TB_HEADPHONE_IRQ  OMAP_GPIO_IRQ(TB_HEADPHONE_GPIO)
32 +
33  static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
34         struct snd_pcm_hw_params *params)
35  {
36 @@ -113,6 +119,33 @@ static struct snd_soc_device omap3beagle_snd_devdata = {
37  
38  static struct platform_device *omap3beagle_snd_device;
39  
40 +static void jack_work_func(struct work_struct *wq)
41 +{
42 +       struct snd_soc_device *socdev = platform_get_drvdata(omap3beagle_snd_device);
43 +       struct snd_soc_codec *codec = socdev->card->codec;
44 +
45 +       snd_soc_dapm_sync(codec);
46 +}
47 +DECLARE_WORK(jack_work, jack_work_func);
48 +
49 +static irqreturn_t touchbook_headphone_event(int irq, void *snd)
50 +{
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;
54 +
55 +       if(status) {
56 +               snd_soc_dapm_disable_pin(codec, "HFL");
57 +               snd_soc_dapm_disable_pin(codec, "HFR");
58 +        } else {
59 +               snd_soc_dapm_enable_pin(codec, "HFL");
60 +               snd_soc_dapm_enable_pin(codec, "HFR");
61 +       }
62 +
63 +       schedule_work(&jack_work);
64 +       return IRQ_HANDLED;
65 +}
66 +
67  static int __init omap3beagle_soc_init(void)
68  {
69         int ret;
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 */
73  
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);
77 +
78 +       ret = request_irq(TB_HEADPHONE_IRQ, touchbook_headphone_event, IRQF_TRIGGER_RISING |
79 +                         IRQF_TRIGGER_FALLING, "touchbook_headphone", omap3beagle_snd_device);
80 +       if (ret < 0)
81 +               goto err1;
82 +
83         ret = platform_device_add(omap3beagle_snd_device);
84         if (ret)
85                 goto err1;
86  
87 +       /* Detect headphone status */
88 +       touchbook_headphone_event(0, omap3beagle_snd_device);
89 +
90         return 0;
91  
92  err1:
93 -- 
94 1.6.6.1
95