diff mbox

[5/8] input: gpio_keys_polled: precompute threshold value in the probe routine

Message ID 1291142663-1011-6-git-send-email-juhosg@openwrt.org (mailing list archive)
State New, archived
Headers show

Commit Message

Gabor Juhos Nov. 30, 2010, 6:44 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index c9e0d1c..5af0be9 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -32,6 +32,7 @@ 
 struct gpio_keys_button_data {
 	int last_state;
 	int count;
+	int threshold;
 	int can_sleep;
 };
 
@@ -69,15 +70,13 @@  static void gpio_keys_polled_poll(struct input_polled_dev *dev)
 	struct gpio_keys_polled_dev *bdev = dev->private;
 	struct gpio_keys_platform_data *pdata = bdev->pdata;
 	struct input_dev *input = dev->input;
-	int i, threshold;
+	int i;
 
 	for (i = 0; i < bdev->pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
 		struct gpio_keys_button_data *bdata = &bdev->data[i];
 
-		threshold = DIV_ROUND_UP(button->debounce_interval,
-					 pdata->poll_interval);
-		if (bdata->count < threshold)
+		if (bdata->count < bdata->threshold)
 			bdata->count++;
 		else
 			gpio_keys_polled_check_state(input, button, bdata);
@@ -151,6 +150,7 @@  static int __devinit gpio_keys_polled_probe(struct platform_device *pdev)
 
 	for (i = 0; i < pdata->nbuttons; i++) {
 		struct gpio_keys_button *button = &pdata->buttons[i];
+		struct gpio_keys_button_data *bdata = &bdev->data[i];
 		unsigned int gpio = button->gpio;
 		unsigned int type = button->type ?: EV_KEY;
 
@@ -176,8 +176,10 @@  static int __devinit gpio_keys_polled_probe(struct platform_device *pdev)
 			goto err_free_gpio;
 		}
 
-		bdev->data[i].can_sleep = gpio_cansleep(gpio);
-		bdev->data[i].last_state = -1;
+		bdata->can_sleep = gpio_cansleep(gpio);
+		bdata->last_state = -1;
+		bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
+						pdata->poll_interval);
 
 		input_set_capability(input, type, button->code);
 	}