diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-11-14 20:32:01 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-12-16 00:45:53 -0500 |
commit | 8ed92556761e1f383d28215d6de92fe4ada35001 (patch) | |
tree | c8e6fdec33367c7c398229dc392338aa5787a9c2 /drivers/input | |
parent | 97d86e07b71643086a6d22a60efae2fb095fa82a (diff) |
Input: gpio_keys - replace timer and workqueue with delayed workqueue
We do not need to roll our own implementation of delayed work now that we
have proper implementation of mod_delayed_work.
For interrupt-only driven buttons we retain the timer, but we rename
it to release_timer to better reflect its purpose.
Tested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r-- | drivers/input/keyboard/gpio_keys.c | 65 |
1 files changed, 31 insertions, 34 deletions
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index a5ece3ff19cb..eefd976ab4eb 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c | |||
@@ -35,9 +35,13 @@ | |||
35 | struct gpio_button_data { | 35 | struct gpio_button_data { |
36 | const struct gpio_keys_button *button; | 36 | const struct gpio_keys_button *button; |
37 | struct input_dev *input; | 37 | struct input_dev *input; |
38 | struct timer_list timer; | 38 | |
39 | struct work_struct work; | 39 | struct timer_list release_timer; |
40 | unsigned int timer_debounce; /* in msecs */ | 40 | unsigned int release_delay; /* in msecs, for IRQ-only buttons */ |
41 | |||
42 | struct delayed_work work; | ||
43 | unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */ | ||
44 | |||
41 | unsigned int irq; | 45 | unsigned int irq; |
42 | spinlock_t lock; | 46 | spinlock_t lock; |
43 | bool disabled; | 47 | bool disabled; |
@@ -116,11 +120,14 @@ static void gpio_keys_disable_button(struct gpio_button_data *bdata) | |||
116 | { | 120 | { |
117 | if (!bdata->disabled) { | 121 | if (!bdata->disabled) { |
118 | /* | 122 | /* |
119 | * Disable IRQ and possible debouncing timer. | 123 | * Disable IRQ and associated timer/work structure. |
120 | */ | 124 | */ |
121 | disable_irq(bdata->irq); | 125 | disable_irq(bdata->irq); |
122 | if (bdata->timer_debounce) | 126 | |
123 | del_timer_sync(&bdata->timer); | 127 | if (gpio_is_valid(bdata->button->gpio)) |
128 | cancel_delayed_work_sync(&bdata->work); | ||
129 | else | ||
130 | del_timer_sync(&bdata->release_timer); | ||
124 | 131 | ||
125 | bdata->disabled = true; | 132 | bdata->disabled = true; |
126 | } | 133 | } |
@@ -343,7 +350,7 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata) | |||
343 | static void gpio_keys_gpio_work_func(struct work_struct *work) | 350 | static void gpio_keys_gpio_work_func(struct work_struct *work) |
344 | { | 351 | { |
345 | struct gpio_button_data *bdata = | 352 | struct gpio_button_data *bdata = |
346 | container_of(work, struct gpio_button_data, work); | 353 | container_of(work, struct gpio_button_data, work.work); |
347 | 354 | ||
348 | gpio_keys_gpio_report_event(bdata); | 355 | gpio_keys_gpio_report_event(bdata); |
349 | 356 | ||
@@ -351,13 +358,6 @@ static void gpio_keys_gpio_work_func(struct work_struct *work) | |||
351 | pm_relax(bdata->input->dev.parent); | 358 | pm_relax(bdata->input->dev.parent); |
352 | } | 359 | } |
353 | 360 | ||
354 | static void gpio_keys_gpio_timer(unsigned long _data) | ||
355 | { | ||
356 | struct gpio_button_data *bdata = (struct gpio_button_data *)_data; | ||
357 | |||
358 | schedule_work(&bdata->work); | ||
359 | } | ||
360 | |||
361 | static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) | 361 | static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) |
362 | { | 362 | { |
363 | struct gpio_button_data *bdata = dev_id; | 363 | struct gpio_button_data *bdata = dev_id; |
@@ -366,11 +366,10 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id) | |||
366 | 366 | ||
367 | if (bdata->button->wakeup) | 367 | if (bdata->button->wakeup) |
368 | pm_stay_awake(bdata->input->dev.parent); | 368 | pm_stay_awake(bdata->input->dev.parent); |
369 | if (bdata->timer_debounce) | 369 | |
370 | mod_timer(&bdata->timer, | 370 | mod_delayed_work(system_wq, |
371 | jiffies + msecs_to_jiffies(bdata->timer_debounce)); | 371 | &bdata->work, |
372 | else | 372 | msecs_to_jiffies(bdata->software_debounce)); |
373 | schedule_work(&bdata->work); | ||
374 | 373 | ||
375 | return IRQ_HANDLED; | 374 | return IRQ_HANDLED; |
376 | } | 375 | } |
@@ -408,7 +407,7 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) | |||
408 | input_event(input, EV_KEY, button->code, 1); | 407 | input_event(input, EV_KEY, button->code, 1); |
409 | input_sync(input); | 408 | input_sync(input); |
410 | 409 | ||
411 | if (!bdata->timer_debounce) { | 410 | if (!bdata->release_delay) { |
412 | input_event(input, EV_KEY, button->code, 0); | 411 | input_event(input, EV_KEY, button->code, 0); |
413 | input_sync(input); | 412 | input_sync(input); |
414 | goto out; | 413 | goto out; |
@@ -417,9 +416,9 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id) | |||
417 | bdata->key_pressed = true; | 416 | bdata->key_pressed = true; |
418 | } | 417 | } |
419 | 418 | ||
420 | if (bdata->timer_debounce) | 419 | if (bdata->release_delay) |
421 | mod_timer(&bdata->timer, | 420 | mod_timer(&bdata->release_timer, |
422 | jiffies + msecs_to_jiffies(bdata->timer_debounce)); | 421 | jiffies + msecs_to_jiffies(bdata->release_delay)); |
423 | out: | 422 | out: |
424 | spin_unlock_irqrestore(&bdata->lock, flags); | 423 | spin_unlock_irqrestore(&bdata->lock, flags); |
425 | return IRQ_HANDLED; | 424 | return IRQ_HANDLED; |
@@ -429,10 +428,10 @@ static void gpio_keys_quiesce_key(void *data) | |||
429 | { | 428 | { |
430 | struct gpio_button_data *bdata = data; | 429 | struct gpio_button_data *bdata = data; |
431 | 430 | ||
432 | if (bdata->timer_debounce) | 431 | if (gpio_is_valid(bdata->button->gpio)) |
433 | del_timer_sync(&bdata->timer); | 432 | cancel_delayed_work_sync(&bdata->work); |
434 | 433 | else | |
435 | cancel_work_sync(&bdata->work); | 434 | del_timer_sync(&bdata->release_timer); |
436 | } | 435 | } |
437 | 436 | ||
438 | static int gpio_keys_setup_key(struct platform_device *pdev, | 437 | static int gpio_keys_setup_key(struct platform_device *pdev, |
@@ -466,7 +465,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
466 | button->debounce_interval * 1000); | 465 | button->debounce_interval * 1000); |
467 | /* use timer if gpiolib doesn't provide debounce */ | 466 | /* use timer if gpiolib doesn't provide debounce */ |
468 | if (error < 0) | 467 | if (error < 0) |
469 | bdata->timer_debounce = | 468 | bdata->software_debounce = |
470 | button->debounce_interval; | 469 | button->debounce_interval; |
471 | } | 470 | } |
472 | 471 | ||
@@ -484,9 +483,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
484 | bdata->irq = irq; | 483 | bdata->irq = irq; |
485 | } | 484 | } |
486 | 485 | ||
487 | INIT_WORK(&bdata->work, gpio_keys_gpio_work_func); | 486 | INIT_DELAYED_WORK(&bdata->work, gpio_keys_gpio_work_func); |
488 | setup_timer(&bdata->timer, | ||
489 | gpio_keys_gpio_timer, (unsigned long)bdata); | ||
490 | 487 | ||
491 | isr = gpio_keys_gpio_isr; | 488 | isr = gpio_keys_gpio_isr; |
492 | irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; | 489 | irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING; |
@@ -503,8 +500,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
503 | return -EINVAL; | 500 | return -EINVAL; |
504 | } | 501 | } |
505 | 502 | ||
506 | bdata->timer_debounce = button->debounce_interval; | 503 | bdata->release_delay = button->debounce_interval; |
507 | setup_timer(&bdata->timer, | 504 | setup_timer(&bdata->release_timer, |
508 | gpio_keys_irq_timer, (unsigned long)bdata); | 505 | gpio_keys_irq_timer, (unsigned long)bdata); |
509 | 506 | ||
510 | isr = gpio_keys_irq_isr; | 507 | isr = gpio_keys_irq_isr; |
@@ -514,7 +511,7 @@ static int gpio_keys_setup_key(struct platform_device *pdev, | |||
514 | input_set_capability(input, button->type ?: EV_KEY, button->code); | 511 | input_set_capability(input, button->type ?: EV_KEY, button->code); |
515 | 512 | ||
516 | /* | 513 | /* |
517 | * Install custom action to cancel debounce timer and | 514 | * Install custom action to cancel release timer and |
518 | * workqueue item. | 515 | * workqueue item. |
519 | */ | 516 | */ |
520 | error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata); | 517 | error = devm_add_action(&pdev->dev, gpio_keys_quiesce_key, bdata); |