Skip to content

Commit 0ff950a

Browse files
Frank Schaefermchehab
authored andcommitted
[media] em28xx: reduce the polling interval for GPI connected buttons
For GPI-connected buttons without (hardware) debouncing, the polling interval needs to be reduced to detect button presses properly. Signed-off-by: Frank Schäfer <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent a03636c commit 0ff950a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

drivers/media/usb/em28xx/em28xx-input.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
#include "em28xx.h"
3232

33-
#define EM28XX_SNAPSHOT_KEY KEY_CAMERA
34-
#define EM28XX_BUTTONS_QUERY_INTERVAL 500
33+
#define EM28XX_SNAPSHOT_KEY KEY_CAMERA
34+
#define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
35+
#define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
3536

3637
static unsigned int ir_debug;
3738
module_param(ir_debug, int, 0644);
@@ -546,7 +547,7 @@ static void em28xx_query_buttons(struct work_struct *work)
546547
}
547548
/* Schedule next poll */
548549
schedule_delayed_work(&dev->buttons_query_work,
549-
msecs_to_jiffies(EM28XX_BUTTONS_QUERY_INTERVAL));
550+
msecs_to_jiffies(dev->button_polling_interval));
550551
}
551552

552553
static int em28xx_register_snapshot_button(struct em28xx *dev)
@@ -594,6 +595,7 @@ static void em28xx_init_buttons(struct em28xx *dev)
594595
u8 i = 0, j = 0;
595596
bool addr_new = 0;
596597

598+
dev->button_polling_interval = EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL;
597599
while (dev->board.buttons[i].role >= 0 &&
598600
dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) {
599601
struct em28xx_button *button = &dev->board.buttons[i];
@@ -609,18 +611,18 @@ static void em28xx_init_buttons(struct em28xx *dev)
609611
if (addr_new && dev->num_button_polling_addresses
610612
>= EM28XX_NUM_BUTTON_ADDRESSES_MAX) {
611613
WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
612-
addr_new = 0;
614+
goto next_button;
613615
}
614616
/* Button role specific checks and actions */
615617
if (button->role == EM28XX_BUTTON_SNAPSHOT) {
616618
/* Register input device */
617619
if (em28xx_register_snapshot_button(dev) < 0)
618-
addr_new = 0;
620+
goto next_button;
619621
} else if (button->role == EM28XX_BUTTON_ILLUMINATION) {
620622
/* Check sanity */
621623
if (!em28xx_find_led(dev, EM28XX_LED_ILLUMINATION)) {
622624
em28xx_errdev("BUG: illumination button defined, but no illumination LED.\n");
623-
addr_new = 0;
625+
goto next_button;
624626
}
625627
}
626628
/* Add read address to list of polling addresses */
@@ -629,6 +631,11 @@ static void em28xx_init_buttons(struct em28xx *dev)
629631
dev->button_polling_addresses[index] = button->reg_r;
630632
dev->num_button_polling_addresses++;
631633
}
634+
/* Reduce polling interval if necessary */
635+
if (!button->reg_clearing)
636+
dev->button_polling_interval =
637+
EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL;
638+
next_button:
632639
/* Next button */
633640
i++;
634641
}
@@ -640,7 +647,7 @@ static void em28xx_init_buttons(struct em28xx *dev)
640647
INIT_DELAYED_WORK(&dev->buttons_query_work,
641648
em28xx_query_buttons);
642649
schedule_delayed_work(&dev->buttons_query_work,
643-
msecs_to_jiffies(EM28XX_BUTTONS_QUERY_INTERVAL));
650+
msecs_to_jiffies(dev->button_polling_interval));
644651
}
645652
}
646653

drivers/media/usb/em28xx/em28xx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ struct em28xx {
681681
u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
682682
u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
683683
u8 num_button_polling_addresses;
684+
u16 button_polling_interval; /* [ms] */
684685
/* Snapshot button input device */
685686
char snapshot_button_path[30]; /* path of the input dev */
686687
struct input_dev *sbutton_input_dev;

0 commit comments

Comments
 (0)