1 From 0143ee8d373f04e443645072a24ff0c7c87036c6 Mon Sep 17 00:00:00 2001
2 From: Andy Green <andy@openmoko.com>
3 Date: Fri, 25 Jul 2008 23:06:05 +0100
4 Subject: [PATCH] fix-jack-interrupt-debounce-loss-window.patch
6 Make sure we can't lose a jack interrupt in debounce, despite it is
7 a one-in-a-million thing that just needs replug to clear
9 Signed-off-by: Andy Green <andy@openmoko.com>
11 drivers/input/keyboard/neo1973kbd.c | 50 +++++++++++++++++++++++-----------
12 1 files changed, 34 insertions(+), 16 deletions(-)
14 diff --git a/drivers/input/keyboard/neo1973kbd.c b/drivers/input/keyboard/neo1973kbd.c
15 index a1fc7a3..8b9a420 100644
16 --- a/drivers/input/keyboard/neo1973kbd.c
17 +++ b/drivers/input/keyboard/neo1973kbd.c
18 @@ -62,27 +62,45 @@ static irqreturn_t neo1973kbd_hold_irq(int irq, void *dev_id)
19 static void neo1973kbd_debounce_jack(struct work_struct *work)
21 struct neo1973kbd *kbd = container_of(work, struct neo1973kbd, work);
23 - /* we wait out any multiple interrupt stuttering in 100ms lumps */
24 + unsigned long flags;
28 - kbd->hp_irq_count_in_work = kbd->hp_irq_count;
30 - } while (kbd->hp_irq_count != kbd->hp_irq_count_in_work);
32 - /* no new interrupts on jack for 100ms... ok we will report it */
34 - input_report_switch(kbd->input,
35 - SW_HEADPHONE_INSERT,
36 - gpio_get_value(irq_to_gpio(kbd->jack_irq)));
37 - input_sync(kbd->input);
39 - /* next time we get an interrupt on jack we need new work action */
40 - kbd->work_in_progress = 0;
42 + * we wait out any multiple interrupt
43 + * stuttering in 100ms lumps
46 + kbd->hp_irq_count_in_work = kbd->hp_irq_count;
48 + } while (kbd->hp_irq_count != kbd->hp_irq_count_in_work);
50 + * no new interrupts on jack for 100ms...
51 + * ok we will report it
53 + input_report_switch(kbd->input, SW_HEADPHONE_INSERT,
54 + gpio_get_value(irq_to_gpio(kbd->jack_irq)));
55 + input_sync(kbd->input);
57 + * we go around the outer loop again if we detect that more
58 + * interrupts came while we are servicing here. But we have
59 + * to sequence it carefully with interrupts off
61 + local_save_flags(flags);
62 + /* no interrupts during this work means we can exit the work */
63 + loop = !!(kbd->hp_irq_count != kbd->hp_irq_count_in_work);
65 + kbd->work_in_progress = 0;
66 + local_irq_restore(flags);
68 + * interrupt that comes here will either queue a new work action
69 + * since work_in_progress is cleared now, or be dealt with
77 static irqreturn_t neo1973kbd_headphone_irq(int irq, void *dev_id)
79 struct neo1973kbd *neo1973kbd_data = dev_id;