Commit 9584bded authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: gpio_keys_polled - switch to using polled mode of input devices

We have added polled mode to the normal input devices with the intent of
retiring input_polled_dev. This converts gpio_keys_polled driver to use
the polling mode of standard input devices and removes dependency on
INPUT_POLLDEV.

Note that we still keep polled and non-polled gpio-keys drivers separate,
as they are different enough and mixing them up would make the code pretty
confusing.
Acked-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarMarco Felsch <m.felsch@pengutronix.de>
Link: https://lore.kernel.org/r/20191017204217.106453-9-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent c028c44f
...@@ -248,7 +248,6 @@ config KEYBOARD_GPIO ...@@ -248,7 +248,6 @@ config KEYBOARD_GPIO
config KEYBOARD_GPIO_POLLED config KEYBOARD_GPIO_POLLED
tristate "Polled GPIO buttons" tristate "Polled GPIO buttons"
depends on GPIOLIB depends on GPIOLIB
select INPUT_POLLDEV
help help
This driver implements support for buttons connected This driver implements support for buttons connected
to GPIO pins that are not capable of generating interrupts. to GPIO pins that are not capable of generating interrupts.
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input-polldev.h>
#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>
...@@ -34,7 +33,7 @@ struct gpio_keys_button_data { ...@@ -34,7 +33,7 @@ struct gpio_keys_button_data {
}; };
struct gpio_keys_polled_dev { struct gpio_keys_polled_dev {
struct input_polled_dev *poll_dev; struct input_dev *input;
struct device *dev; struct device *dev;
const struct gpio_keys_platform_data *pdata; const struct gpio_keys_platform_data *pdata;
unsigned long rel_axis_seen[BITS_TO_LONGS(REL_CNT)]; unsigned long rel_axis_seen[BITS_TO_LONGS(REL_CNT)];
...@@ -42,12 +41,11 @@ struct gpio_keys_polled_dev { ...@@ -42,12 +41,11 @@ struct gpio_keys_polled_dev {
struct gpio_keys_button_data data[0]; struct gpio_keys_button_data data[0];
}; };
static void gpio_keys_button_event(struct input_polled_dev *dev, static void gpio_keys_button_event(struct input_dev *input,
const struct gpio_keys_button *button, const struct gpio_keys_button *button,
int state) int state)
{ {
struct gpio_keys_polled_dev *bdev = dev->private; struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
struct input_dev *input = dev->input;
unsigned int type = button->type ?: EV_KEY; unsigned int type = button->type ?: EV_KEY;
if (type == EV_REL) { if (type == EV_REL) {
...@@ -66,7 +64,7 @@ static void gpio_keys_button_event(struct input_polled_dev *dev, ...@@ -66,7 +64,7 @@ static void gpio_keys_button_event(struct input_polled_dev *dev,
} }
} }
static void gpio_keys_polled_check_state(struct input_polled_dev *dev, static void gpio_keys_polled_check_state(struct input_dev *input,
const struct gpio_keys_button *button, const struct gpio_keys_button *button,
struct gpio_keys_button_data *bdata) struct gpio_keys_button_data *bdata)
{ {
...@@ -74,10 +72,10 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev, ...@@ -74,10 +72,10 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev,
state = gpiod_get_value_cansleep(bdata->gpiod); state = gpiod_get_value_cansleep(bdata->gpiod);
if (state < 0) { if (state < 0) {
dev_err(dev->input->dev.parent, dev_err(input->dev.parent,
"failed to get gpio state: %d\n", state); "failed to get gpio state: %d\n", state);
} else { } else {
gpio_keys_button_event(dev, button, state); gpio_keys_button_event(input, button, state);
if (state != bdata->last_state) { if (state != bdata->last_state) {
bdata->count = 0; bdata->count = 0;
...@@ -86,11 +84,10 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev, ...@@ -86,11 +84,10 @@ static void gpio_keys_polled_check_state(struct input_polled_dev *dev,
} }
} }
static void gpio_keys_polled_poll(struct input_polled_dev *dev) static void gpio_keys_polled_poll(struct input_dev *input)
{ {
struct gpio_keys_polled_dev *bdev = dev->private; struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
const struct gpio_keys_platform_data *pdata = bdev->pdata; const struct gpio_keys_platform_data *pdata = bdev->pdata;
struct input_dev *input = dev->input;
int i; int i;
memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen)); memset(bdev->rel_axis_seen, 0, sizeof(bdev->rel_axis_seen));
...@@ -101,10 +98,10 @@ static void gpio_keys_polled_poll(struct input_polled_dev *dev) ...@@ -101,10 +98,10 @@ static void gpio_keys_polled_poll(struct input_polled_dev *dev)
if (bdata->count < bdata->threshold) { if (bdata->count < bdata->threshold) {
bdata->count++; bdata->count++;
gpio_keys_button_event(dev, &pdata->buttons[i], gpio_keys_button_event(input, &pdata->buttons[i],
bdata->last_state); bdata->last_state);
} else { } else {
gpio_keys_polled_check_state(dev, &pdata->buttons[i], gpio_keys_polled_check_state(input, &pdata->buttons[i],
bdata); bdata);
} }
} }
...@@ -122,18 +119,20 @@ static void gpio_keys_polled_poll(struct input_polled_dev *dev) ...@@ -122,18 +119,20 @@ static void gpio_keys_polled_poll(struct input_polled_dev *dev)
input_sync(input); input_sync(input);
} }
static void gpio_keys_polled_open(struct input_polled_dev *dev) static int gpio_keys_polled_open(struct input_dev *input)
{ {
struct gpio_keys_polled_dev *bdev = dev->private; struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
const struct gpio_keys_platform_data *pdata = bdev->pdata; const struct gpio_keys_platform_data *pdata = bdev->pdata;
if (pdata->enable) if (pdata->enable)
pdata->enable(bdev->dev); pdata->enable(bdev->dev);
return 0;
} }
static void gpio_keys_polled_close(struct input_polled_dev *dev) static void gpio_keys_polled_close(struct input_dev *input)
{ {
struct gpio_keys_polled_dev *bdev = dev->private; struct gpio_keys_polled_dev *bdev = input_get_drvdata(input);
const struct gpio_keys_platform_data *pdata = bdev->pdata; const struct gpio_keys_platform_data *pdata = bdev->pdata;
if (pdata->disable) if (pdata->disable)
...@@ -232,7 +231,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -232,7 +231,6 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
struct fwnode_handle *child = NULL; struct fwnode_handle *child = NULL;
const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev); const struct gpio_keys_platform_data *pdata = dev_get_platdata(dev);
struct gpio_keys_polled_dev *bdev; struct gpio_keys_polled_dev *bdev;
struct input_polled_dev *poll_dev;
struct input_dev *input; struct input_dev *input;
int error; int error;
int i; int i;
...@@ -255,19 +253,13 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -255,19 +253,13 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
poll_dev = devm_input_allocate_polled_device(dev); input = devm_input_allocate_device(dev);
if (!poll_dev) { if (!input) {
dev_err(dev, "no memory for polled device\n"); dev_err(dev, "no memory for input device\n");
return -ENOMEM; return -ENOMEM;
} }
poll_dev->private = bdev; input_set_drvdata(input, bdev);
poll_dev->poll = gpio_keys_polled_poll;
poll_dev->poll_interval = pdata->poll_interval;
poll_dev->open = gpio_keys_polled_open;
poll_dev->close = gpio_keys_polled_close;
input = poll_dev->input;
input->name = pdata->name ?: pdev->name; input->name = pdata->name ?: pdev->name;
input->phys = DRV_NAME"/input0"; input->phys = DRV_NAME"/input0";
...@@ -277,6 +269,9 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -277,6 +269,9 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
input->id.product = 0x0001; input->id.product = 0x0001;
input->id.version = 0x0100; input->id.version = 0x0100;
input->open = gpio_keys_polled_open;
input->close = gpio_keys_polled_close;
__set_bit(EV_KEY, input->evbit); __set_bit(EV_KEY, input->evbit);
if (pdata->rep) if (pdata->rep)
__set_bit(EV_REP, input->evbit); __set_bit(EV_REP, input->evbit);
...@@ -352,11 +347,19 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -352,11 +347,19 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
fwnode_handle_put(child); fwnode_handle_put(child);
bdev->poll_dev = poll_dev; bdev->input = input;
bdev->dev = dev; bdev->dev = dev;
bdev->pdata = pdata; bdev->pdata = pdata;
error = input_register_polled_device(poll_dev); error = input_setup_polling(input, gpio_keys_polled_poll);
if (error) {
dev_err(dev, "unable to set up polling, err=%d\n", error);
return error;
}
input_set_poll_interval(input, pdata->poll_interval);
error = input_register_device(input);
if (error) { if (error) {
dev_err(dev, "unable to register polled device, err=%d\n", dev_err(dev, "unable to register polled device, err=%d\n",
error); error);
...@@ -365,7 +368,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev) ...@@ -365,7 +368,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
/* report initial state of the buttons */ /* report initial state of the buttons */
for (i = 0; i < pdata->nbuttons; i++) for (i = 0; i < pdata->nbuttons; i++)
gpio_keys_polled_check_state(poll_dev, &pdata->buttons[i], gpio_keys_polled_check_state(input, &pdata->buttons[i],
&bdev->data[i]); &bdev->data[i]);
input_sync(input); input_sync(input);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment