aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/s3c24xx/patches-2.6.24/1123-fix-jack-debounce.patch.patch
blob: 45d4a07f7a42ef0280c81c7d2af102e7f6f8d226 (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
46pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
From 9a5d2d81c0bf5c8fe2ac58d267033876904ed925 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@openmoko.com>
Date: Sun, 13 Apr 2008 07:25:57 +0100
Subject: [PATCH] fix-jack-debounce.patch

Headphone jack detection is bouncy, it can trigger multiple interrupts
on insertion or removal.  This patch adds a workqueue that waits out the
interrupt spew in 100ms units, and if it sees no more interrupts for 100ms
only then samples and reports the jack state.  I was unable to get a bounce
after 20 or so tries after this.

Signed-off-by: Andy Green <andy@openmoko.com>
---
 drivers/input/keyboard/neo1973kbd.c |   63 ++++++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/drivers/input/keyboard/neo1973kbd.c b/drivers/input/keyboard/neo1973kbd.c
index 06fa8e0..6c96660 100644
--- a/drivers/input/keyboard/neo1973kbd.c
+++ b/drivers/input/keyboard/neo1973kbd.c
@@ -21,6 +21,7 @@
 #include <linux/jiffies.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/workqueue.h>
 
 #include <asm/gpio.h>
 #include <asm/mach-types.h>
@@ -28,6 +29,11 @@
 struct neo1973kbd {
 	struct input_dev *input;
 	unsigned int suspended;
+	struct work_struct work;
+	int work_in_progress;
+	int hp_irq_count_in_work;
+	int hp_irq_count;
+	int jack_irq;
 };
 
 static irqreturn_t neo1973kbd_aux_irq(int irq, void *dev_id)
@@ -52,14 +58,61 @@ static irqreturn_t neo1973kbd_hold_irq(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+
+static void neo1973kbd_debounce_jack(struct work_struct *work)
+{
+	struct neo1973kbd *kbd = container_of(work, struct neo1973kbd, work);
+
+	/* we wait out any multiple interrupt stuttering in 100ms lumps */
+
+	do {
+		kbd->hp_irq_count_in_work = kbd->hp_irq_count;
+		msleep(100);
+	} while (kbd->hp_irq_count != kbd->hp_irq_count_in_work);
+
+	/* no new interrupts on jack for 100ms... ok we will report it */
+
+	input_report_switch(kbd->input,
+			    SW_HEADPHONE_INSERT,
+			    gpio_get_value(irq_to_gpio(kbd->jack_irq)));
+	input_sync(kbd->input);
+
+	/* next time we get an interrupt on jack we need new work action */
+	kbd->work_in_progress = 0;
+}
+
+
+
 static irqreturn_t neo1973kbd_headphone_irq(int irq, void *dev_id)
 {
 	struct neo1973kbd *neo1973kbd_data = dev_id;
 
-	int key_pressed = gpio_get_value(irq_to_gpio(irq));
-	input_report_switch(neo1973kbd_data->input,
-			    SW_HEADPHONE_INSERT, key_pressed);
-	input_sync(neo1973kbd_data->input);
+	/*
+	 * this interrupt is prone to bouncing and userspace doesn't like
+	 * to have to deal with that kind of thing.  So we do not accept
+	 * that a jack interrupt is equal to a jack event.  Instead we fire
+	 * some work on the first interrupt, and it hangs about in 100ms units
+	 * until no more interrupts come.  Then it accepts the state it finds
+	 * for jack insert and reports it once
+	 */
+
+	neo1973kbd_data->hp_irq_count++;
+	/*
+	 * the first interrupt we see for a while, we fire the work item
+	 * and record the interrupt count when we did that.  If more interrupts
+	 * come in the meanwhile, we can tell by the difference in that
+	 * stored count and hp_irq_count which increments every interrupt
+	 */
+	if (!neo1973kbd_data->work_in_progress) {
+		neo1973kbd_data->jack_irq = irq;
+		neo1973kbd_data->hp_irq_count_in_work =
+						neo1973kbd_data->hp_irq_count;
+		if (!schedule_work(&neo1973kbd_data->work))
+			printk(KERN_ERR
+				"Unable to schedule headphone debounce\n");
+		else
+			neo1973kbd_data->work_in_progress = 1;
+	}
 
 	return IRQ_HANDLED;
 }
@@ -120,6 +173,8 @@ static int neo1973kbd_probe(struct platform_device *pdev)
 
 	neo1973kbd->input = input_dev;
 
+	INIT_WORK(&neo1973kbd->work, neo1973kbd_debounce_jack);
+
 	input_dev->name = "Neo1973 Buttons";
 	input_dev->phys = "neo1973kbd/input0";
 	input_dev->id.bustype = BUS_HOST;
-- 
1.5.6.5