提交 633a21d8 编写于 作者: A Aaron Lu 提交者: Rafael J. Wysocki

input: gpio_keys_polled: Add support for GPIO descriptors

GPIO descriptors are the preferred way over legacy GPIO numbers
nowadays. Convert the driver to use GPIO descriptors internally but
still allow passing legacy GPIO numbers from platform data to support
existing platforms.
Signed-off-by: NAaron Lu <aaron.lu@intel.com>
Signed-off-by: NMika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: NAlexandre Courbot <acourbot@nvidia.com>
Reviewed-by: NLinus Walleij <linus.walleij@linaro.org>
Acked-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
Acked-by: NGrant Likely <grant.likely@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 5c51277a
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <linux/ioport.h> #include <linux/ioport.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio_keys.h> #include <linux/gpio_keys.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
...@@ -51,15 +52,14 @@ static void gpio_keys_polled_check_state(struct input_dev *input, ...@@ -51,15 +52,14 @@ static void gpio_keys_polled_check_state(struct input_dev *input,
int state; int state;
if (bdata->can_sleep) if (bdata->can_sleep)
state = !!gpio_get_value_cansleep(button->gpio); state = !!gpiod_get_value_cansleep(button->gpiod);
else else
state = !!gpio_get_value(button->gpio); state = !!gpiod_get_value(button->gpiod);
if (state != bdata->last_state) { if (state != bdata->last_state) {
unsigned int type = button->type ?: EV_KEY; unsigned int type = button->type ?: EV_KEY;
input_event(input, type, button->code, input_event(input, type, button->code, state);
!!(state ^ button->active_low));
input_sync(input); input_sync(input);
bdata->count = 0; bdata->count = 0;
bdata->last_state = state; bdata->last_state = state;
...@@ -259,7 +259,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -259,7 +259,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
for (i = 0; i < pdata->nbuttons; i++) { for (i = 0; i < pdata->nbuttons; i++) {
struct gpio_keys_button *button = &pdata->buttons[i]; struct gpio_keys_button *button = &pdata->buttons[i];
struct gpio_keys_button_data *bdata = &bdev->data[i]; struct gpio_keys_button_data *bdata = &bdev->data[i];
unsigned int gpio = button->gpio;
unsigned int type = button->type ?: EV_KEY; unsigned int type = button->type ?: EV_KEY;
if (button->wakeup) { if (button->wakeup) {
...@@ -267,15 +266,31 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -267,15 +266,31 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
error = devm_gpio_request_one(&pdev->dev, gpio, GPIOF_IN, /*
button->desc ? : DRV_NAME); * Legacy GPIO number so request the GPIO here and
if (error) { * convert it to descriptor.
dev_err(dev, "unable to claim gpio %u, err=%d\n", */
gpio, error); if (!button->gpiod && gpio_is_valid(button->gpio)) {
return error; unsigned flags = 0;
if (button->active_low)
flags |= GPIOF_ACTIVE_LOW;
error = devm_gpio_request_one(&pdev->dev, button->gpio,
flags, button->desc ? : DRV_NAME);
if (error) {
dev_err(dev, "unable to claim gpio %u, err=%d\n",
button->gpio, error);
return error;
}
button->gpiod = gpio_to_desc(button->gpio);
} }
bdata->can_sleep = gpio_cansleep(gpio); if (IS_ERR(button->gpiod))
return PTR_ERR(button->gpiod);
bdata->can_sleep = gpiod_cansleep(button->gpiod);
bdata->last_state = -1; bdata->last_state = -1;
bdata->threshold = DIV_ROUND_UP(button->debounce_interval, bdata->threshold = DIV_ROUND_UP(button->debounce_interval,
pdata->poll_interval); pdata->poll_interval);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define _GPIO_KEYS_H #define _GPIO_KEYS_H
struct device; struct device;
struct gpio_desc;
/** /**
* struct gpio_keys_button - configuration parameters * struct gpio_keys_button - configuration parameters
...@@ -17,6 +18,7 @@ struct device; ...@@ -17,6 +18,7 @@ struct device;
* disable button via sysfs * disable button via sysfs
* @value: axis value for %EV_ABS * @value: axis value for %EV_ABS
* @irq: Irq number in case of interrupt keys * @irq: Irq number in case of interrupt keys
* @gpiod: GPIO descriptor
*/ */
struct gpio_keys_button { struct gpio_keys_button {
unsigned int code; unsigned int code;
...@@ -29,6 +31,7 @@ struct gpio_keys_button { ...@@ -29,6 +31,7 @@ struct gpio_keys_button {
bool can_disable; bool can_disable;
int value; int value;
unsigned int irq; unsigned int irq;
struct gpio_desc *gpiod;
}; };
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册