[ar71xx] remove duplicated includes
[openwrt.git] / target / linux / s3c24xx / patches-2.6.24 / 1123-fix-jack-debounce.patch.patch
1 From 9a5d2d81c0bf5c8fe2ac58d267033876904ed925 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Sun, 13 Apr 2008 07:25:57 +0100
4 Subject: [PATCH] fix-jack-debounce.patch
5
6 Headphone jack detection is bouncy, it can trigger multiple interrupts
7 on insertion or removal. This patch adds a workqueue that waits out the
8 interrupt spew in 100ms units, and if it sees no more interrupts for 100ms
9 only then samples and reports the jack state. I was unable to get a bounce
10 after 20 or so tries after this.
11
12 Signed-off-by: Andy Green <andy@openmoko.com>
13 ---
14 drivers/input/keyboard/neo1973kbd.c | 63 ++++++++++++++++++++++++++++++++--
15 1 files changed, 59 insertions(+), 4 deletions(-)
16
17 diff --git a/drivers/input/keyboard/neo1973kbd.c b/drivers/input/keyboard/neo1973kbd.c
18 index 06fa8e0..6c96660 100644
19 --- a/drivers/input/keyboard/neo1973kbd.c
20 +++ b/drivers/input/keyboard/neo1973kbd.c
21 @@ -21,6 +21,7 @@
22 #include <linux/jiffies.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 +#include <linux/workqueue.h>
26
27 #include <asm/gpio.h>
28 #include <asm/mach-types.h>
29 @@ -28,6 +29,11 @@
30 struct neo1973kbd {
31 struct input_dev *input;
32 unsigned int suspended;
33 + struct work_struct work;
34 + int work_in_progress;
35 + int hp_irq_count_in_work;
36 + int hp_irq_count;
37 + int jack_irq;
38 };
39
40 static irqreturn_t neo1973kbd_aux_irq(int irq, void *dev_id)
41 @@ -52,14 +58,61 @@ static irqreturn_t neo1973kbd_hold_irq(int irq, void *dev_id)
42 return IRQ_HANDLED;
43 }
44
45 +
46 +static void neo1973kbd_debounce_jack(struct work_struct *work)
47 +{
48 + struct neo1973kbd *kbd = container_of(work, struct neo1973kbd, work);
49 +
50 + /* we wait out any multiple interrupt stuttering in 100ms lumps */
51 +
52 + do {
53 + kbd->hp_irq_count_in_work = kbd->hp_irq_count;
54 + msleep(100);
55 + } while (kbd->hp_irq_count != kbd->hp_irq_count_in_work);
56 +
57 + /* no new interrupts on jack for 100ms... ok we will report it */
58 +
59 + input_report_switch(kbd->input,
60 + SW_HEADPHONE_INSERT,
61 + gpio_get_value(irq_to_gpio(kbd->jack_irq)));
62 + input_sync(kbd->input);
63 +
64 + /* next time we get an interrupt on jack we need new work action */
65 + kbd->work_in_progress = 0;
66 +}
67 +
68 +
69 +
70 static irqreturn_t neo1973kbd_headphone_irq(int irq, void *dev_id)
71 {
72 struct neo1973kbd *neo1973kbd_data = dev_id;
73
74 - int key_pressed = gpio_get_value(irq_to_gpio(irq));
75 - input_report_switch(neo1973kbd_data->input,
76 - SW_HEADPHONE_INSERT, key_pressed);
77 - input_sync(neo1973kbd_data->input);
78 + /*
79 + * this interrupt is prone to bouncing and userspace doesn't like
80 + * to have to deal with that kind of thing. So we do not accept
81 + * that a jack interrupt is equal to a jack event. Instead we fire
82 + * some work on the first interrupt, and it hangs about in 100ms units
83 + * until no more interrupts come. Then it accepts the state it finds
84 + * for jack insert and reports it once
85 + */
86 +
87 + neo1973kbd_data->hp_irq_count++;
88 + /*
89 + * the first interrupt we see for a while, we fire the work item
90 + * and record the interrupt count when we did that. If more interrupts
91 + * come in the meanwhile, we can tell by the difference in that
92 + * stored count and hp_irq_count which increments every interrupt
93 + */
94 + if (!neo1973kbd_data->work_in_progress) {
95 + neo1973kbd_data->jack_irq = irq;
96 + neo1973kbd_data->hp_irq_count_in_work =
97 + neo1973kbd_data->hp_irq_count;
98 + if (!schedule_work(&neo1973kbd_data->work))
99 + printk(KERN_ERR
100 + "Unable to schedule headphone debounce\n");
101 + else
102 + neo1973kbd_data->work_in_progress = 1;
103 + }
104
105 return IRQ_HANDLED;
106 }
107 @@ -120,6 +173,8 @@ static int neo1973kbd_probe(struct platform_device *pdev)
108
109 neo1973kbd->input = input_dev;
110
111 + INIT_WORK(&neo1973kbd->work, neo1973kbd_debounce_jack);
112 +
113 input_dev->name = "Neo1973 Buttons";
114 input_dev->phys = "neo1973kbd/input0";
115 input_dev->id.bustype = BUS_HOST;
116 --
117 1.5.6.5
118
This page took 0.045949 seconds and 5 git commands to generate.