]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Input: gpio_keys_polled - always use gpiod_get_value_cansleep
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 19 Oct 2016 23:36:19 +0000 (16:36 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 8 Nov 2016 00:24:29 +0000 (16:24 -0800)
It does not matter if given GPIO may sleep or not when reading state,
polling is always done in a non-atomic context, so we should always
be able to simply use gpiod_get_value_cansleep().

Also let's note in the logs when we fail to read gpio state.

Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/gpio_keys_polled.c

index 2cf407831f0686d44eecf78438d0b9c33a3459c4..72b350315d4390cf76798b8cdc5b3246baa85956 100644 (file)
@@ -34,7 +34,6 @@ struct gpio_keys_button_data {
        int last_state;
        int count;
        int threshold;
-       int can_sleep;
 };
 
 struct gpio_keys_polled_dev {
@@ -76,16 +75,17 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev,
 {
        int state;
 
-       if (bdata->can_sleep)
-               state = !!gpiod_get_value_cansleep(bdata->gpiod);
-       else
-               state = !!gpiod_get_value(bdata->gpiod);
-
-       gpio_keys_button_event(dev, button, state);
+       state = gpiod_get_value_cansleep(bdata->gpiod);
+       if (state < 0) {
+               dev_err(dev->input->dev.parent,
+                       "failed to get gpio state: %d\n", state);
+       } else {
+               gpio_keys_button_event(dev, button, state);
 
-       if (state != bdata->last_state) {
-               bdata->count = 0;
-               bdata->last_state = state;
+               if (state != bdata->last_state) {
+                       bdata->count = 0;
+                       bdata->last_state = state;
+               }
        }
 }
 
@@ -342,7 +342,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
                        }
                }
 
-               bdata->can_sleep = gpiod_cansleep(bdata->gpiod);
                bdata->last_state = -1;
                bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
                                                pdata->poll_interval);