diff options
-rw-r--r-- | drivers/input/keyboard/gpio_keys_polled.c | 39 | ||||
-rw-r--r-- | include/linux/gpio_keys.h | 3 |
2 files changed, 30 insertions, 12 deletions
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c index 432d36395f35..b7a514ced509 100644 --- a/drivers/input/keyboard/gpio_keys_polled.c +++ b/drivers/input/keyboard/gpio_keys_polled.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/ioport.h> | 23 | #include <linux/ioport.h> |
24 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/gpio/consumer.h> | ||
26 | #include <linux/gpio_keys.h> | 27 | #include <linux/gpio_keys.h> |
27 | #include <linux/of.h> | 28 | #include <linux/of.h> |
28 | #include <linux/of_platform.h> | 29 | #include <linux/of_platform.h> |
@@ -51,15 +52,14 @@ static void gpio_keys_polled_check_state(struct input_dev *input, | |||
51 | int state; | 52 | int state; |
52 | 53 | ||
53 | if (bdata->can_sleep) | 54 | if (bdata->can_sleep) |
54 | state = !!gpio_get_value_cansleep(button->gpio); | 55 | state = !!gpiod_get_value_cansleep(button->gpiod); |
55 | else | 56 | else |
56 | state = !!gpio_get_value(button->gpio); | 57 | state = !!gpiod_get_value(button->gpiod); |
57 | 58 | ||
58 | if (state != bdata->last_state) { | 59 | if (state != bdata->last_state) { |
59 | unsigned int type = button->type ?: EV_KEY; | 60 | unsigned int type = button->type ?: EV_KEY; |
60 | 61 | ||
61 | input_event(input, type, button->code, | 62 | input_event(input, type, button->code, state); |
62 | !!(state ^ button->active_low)); | ||
63 | input_sync(input); | 63 | input_sync(input); |
64 | bdata->count = 0; | 64 | bdata->count = 0; |
65 | bdata->last_state = state; | 65 | bdata->last_state = state; |
@@ -259,7 +259,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
259 | for (i = 0; i < pdata->nbuttons; i++) { | 259 | for (i = 0; i < pdata->nbuttons; i++) { |
260 | struct gpio_keys_button *button = &pdata->buttons[i]; | 260 | struct gpio_keys_button *button = &pdata->buttons[i]; |
261 | struct gpio_keys_button_data *bdata = &bdev->data[i]; | 261 | struct gpio_keys_button_data *bdata = &bdev->data[i]; |
262 | unsigned int gpio = button->gpio; | ||
263 | unsigned int type = button->type ?: EV_KEY; | 262 | unsigned int type = button->type ?: EV_KEY; |
264 | 263 | ||
265 | if (button->wakeup) { | 264 | if (button->wakeup) { |
@@ -267,15 +266,31 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) | |||
267 | return -EINVAL; | 266 | return -EINVAL; |
268 | } | 267 | } |
269 | 268 | ||
270 | error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN, | 269 | /* |
271 | button->desc ? : DRV_NAME); | 270 | * Legacy GPIO number so request the GPIO here and |
272 | if (error) { | 271 | * convert it to descriptor. |
273 | dev_err(dev, "unable to claim gpio %u, err=%d\n", | 272 | */ |
274 | gpio, error); | 273 | if (!button->gpiod && gpio_is_valid(button->gpio)) { |
275 | return error; | 274 | unsigned flags = 0; |
275 | |||
276 | if (button->active_low) | ||
277 | flags |= GPIOF_ACTIVE_LOW; | ||
278 | |||
279 | error = devm_gpio_request_one(&pdev->dev, button->gpio, | ||
280 | flags, button->desc ? : DRV_NAME); | ||
281 | if (error) { | ||
282 | dev_err(dev, "unable to claim gpio %u, err=%d\n", | ||
283 | button->gpio, error); | ||
284 | return error; | ||
285 | } | ||
286 | |||
287 | button->gpiod = gpio_to_desc(button->gpio); | ||
276 | } | 288 | } |
277 | 289 | ||
278 | bdata->can_sleep = gpio_cansleep(gpio); | 290 | if (IS_ERR(button->gpiod)) |
291 | return PTR_ERR(button->gpiod); | ||
292 | |||
293 | bdata->can_sleep = gpiod_cansleep(button->gpiod); | ||
279 | bdata->last_state = -1; | 294 | bdata->last_state = -1; |
280 | bdata->threshold = DIV_ROUND_UP(button->debounce_interval, | 295 | bdata->threshold = DIV_ROUND_UP(button->debounce_interval, |
281 | pdata->poll_interval); | 296 | pdata->poll_interval); |
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index 8b622468952c..ee2d8c6f9130 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _GPIO_KEYS_H | 2 | #define _GPIO_KEYS_H |
3 | 3 | ||
4 | struct device; | 4 | struct device; |
5 | struct gpio_desc; | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * struct gpio_keys_button - configuration parameters | 8 | * struct gpio_keys_button - configuration parameters |
@@ -17,6 +18,7 @@ struct device; | |||
17 | * disable button via sysfs | 18 | * disable button via sysfs |
18 | * @value: axis value for %EV_ABS | 19 | * @value: axis value for %EV_ABS |
19 | * @irq: Irq number in case of interrupt keys | 20 | * @irq: Irq number in case of interrupt keys |
21 | * @gpiod: GPIO descriptor | ||
20 | */ | 22 | */ |
21 | struct gpio_keys_button { | 23 | struct gpio_keys_button { |
22 | unsigned int code; | 24 | unsigned int code; |
@@ -29,6 +31,7 @@ struct gpio_keys_button { | |||
29 | bool can_disable; | 31 | bool can_disable; |
30 | int value; | 32 | int value; |
31 | unsigned int irq; | 33 | unsigned int irq; |
34 | struct gpio_desc *gpiod; | ||
32 | }; | 35 | }; |
33 | 36 | ||
34 | /** | 37 | /** |