-
-static const char *event_array_jack[2][4] = {
- [0] = {
- "SWITCH_NAME=headset",
- "SWITCH_STATE=0",
- "EVENT=remove",
- NULL
- },
- [1] = {
- "SWITCH_NAME=headset",
- "SWITCH_STATE=1",
- "EVENT=insert",
- NULL
- },
-};
-
-static void gta02kbd_jack_event(struct device *dev, int num)
-{
- kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, (char **)event_array_jack[!!num]);
-}
-
-
-static void gta02kbd_debounce_jack(struct work_struct *work)
-{
- struct gta02kbd *kbd = container_of(work, struct gta02kbd, work);
- unsigned long flags;
- int loop = 0;
- int level;
-
- do {
- /*
- * 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
- */
- level = gpio_get_value(kbd->pdev->resource[GTA02_KEY_JACK].start);
- input_report_switch(kbd->input, SW_HEADPHONE_INSERT, level);
- input_sync(kbd->input);
- gta02kbd_jack_event(kbd->cdev, level);
- /*
- * we go around the outer loop again if we detect that more
- * interrupts came while we are servicing here. But we have
- * to sequence it carefully with interrupts off
- */
- local_save_flags(flags);
- /* no interrupts during this work means we can exit the work */
- loop = !!(kbd->hp_irq_count != kbd->hp_irq_count_in_work);
- if (!loop)
- kbd->work_in_progress = 0;
- local_irq_restore(flags);
- /*
- * interrupt that comes here will either queue a new work action
- * since work_in_progress is cleared now, or be dealt with
- * when we loop.
- */
- } while (loop);
-}
-
-
-static irqreturn_t gta02kbd_headphone_irq(int irq, void *dev_id)
-{
- struct gta02kbd *gta02kbd_data = dev_id;
-
- /*
- * 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
- */
-
- gta02kbd_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 (!gta02kbd_data->work_in_progress) {
- gta02kbd_data->jack_irq = irq;
- gta02kbd_data->hp_irq_count_in_work =
- gta02kbd_data->hp_irq_count;
- if (!schedule_work(>a02kbd_data->work))
- printk(KERN_ERR
- "Unable to schedule headphone debounce\n");
- else
- gta02kbd_data->work_in_progress = 1;
- }
-
- return IRQ_HANDLED;
-}
-