Skip to content

Commit ff68cf0

Browse files
committed
Input: gpio_decoder - 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_decoder driver to use the polling mode of standard input devices and removes dependency on INPUT_POLLDEV. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 36bc368 commit ff68cf0

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

drivers/input/misc/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ config INPUT_GPIO_BEEPER
290290
config INPUT_GPIO_DECODER
291291
tristate "Polled GPIO Decoder Input driver"
292292
depends on GPIOLIB || COMPILE_TEST
293-
select INPUT_POLLDEV
294293
help
295294
Say Y here if you want driver to read status of multiple GPIO
296295
lines and report the encoded value as an absolute integer to

drivers/input/misc/gpio_decoder.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
#include <linux/device.h>
1818
#include <linux/gpio/consumer.h>
1919
#include <linux/input.h>
20-
#include <linux/input-polldev.h>
2120
#include <linux/kernel.h>
2221
#include <linux/module.h>
2322
#include <linux/of.h>
2423
#include <linux/platform_device.h>
2524

2625
struct gpio_decoder {
27-
struct input_polled_dev *poll_dev;
2826
struct gpio_descs *input_gpios;
2927
struct device *dev;
3028
u32 axis;
@@ -53,15 +51,15 @@ static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
5351
return ret;
5452
}
5553

56-
static void gpio_decoder_poll_gpios(struct input_polled_dev *poll_dev)
54+
static void gpio_decoder_poll_gpios(struct input_dev *input)
5755
{
58-
struct gpio_decoder *decoder = poll_dev->private;
56+
struct gpio_decoder *decoder = input_get_drvdata(input);
5957
int state;
6058

6159
state = gpio_decoder_get_gpios_state(decoder);
6260
if (state >= 0 && state != decoder->last_stable) {
63-
input_report_abs(poll_dev->input, decoder->axis, state);
64-
input_sync(poll_dev->input);
61+
input_report_abs(input, decoder->axis, state);
62+
input_sync(input);
6563
decoder->last_stable = state;
6664
}
6765
}
@@ -70,20 +68,23 @@ static int gpio_decoder_probe(struct platform_device *pdev)
7068
{
7169
struct device *dev = &pdev->dev;
7270
struct gpio_decoder *decoder;
73-
struct input_polled_dev *poll_dev;
71+
struct input_dev *input;
7472
u32 max;
7573
int err;
7674

77-
decoder = devm_kzalloc(dev, sizeof(struct gpio_decoder), GFP_KERNEL);
75+
decoder = devm_kzalloc(dev, sizeof(*decoder), GFP_KERNEL);
7876
if (!decoder)
7977
return -ENOMEM;
8078

79+
decoder->dev = dev;
8180
device_property_read_u32(dev, "linux,axis", &decoder->axis);
81+
8282
decoder->input_gpios = devm_gpiod_get_array(dev, NULL, GPIOD_IN);
8383
if (IS_ERR(decoder->input_gpios)) {
8484
dev_err(dev, "unable to acquire input gpios\n");
8585
return PTR_ERR(decoder->input_gpios);
8686
}
87+
8788
if (decoder->input_gpios->ndescs < 2) {
8889
dev_err(dev, "not enough gpios found\n");
8990
return -EINVAL;
@@ -92,22 +93,25 @@ static int gpio_decoder_probe(struct platform_device *pdev)
9293
if (device_property_read_u32(dev, "decoder-max-value", &max))
9394
max = (1U << decoder->input_gpios->ndescs) - 1;
9495

95-
decoder->dev = dev;
96-
poll_dev = devm_input_allocate_polled_device(decoder->dev);
97-
if (!poll_dev)
96+
input = devm_input_allocate_device(dev);
97+
if (!input)
9898
return -ENOMEM;
9999

100-
poll_dev->private = decoder;
101-
poll_dev->poll = gpio_decoder_poll_gpios;
102-
decoder->poll_dev = poll_dev;
100+
input_set_drvdata(input, decoder);
103101

104-
poll_dev->input->name = pdev->name;
105-
poll_dev->input->id.bustype = BUS_HOST;
106-
input_set_abs_params(poll_dev->input, decoder->axis, 0, max, 0, 0);
102+
input->name = pdev->name;
103+
input->id.bustype = BUS_HOST;
104+
input_set_abs_params(input, decoder->axis, 0, max, 0, 0);
105+
106+
err = input_setup_polling(input, gpio_decoder_poll_gpios);
107+
if (err) {
108+
dev_err(dev, "failed to set up polling\n");
109+
return err;
110+
}
107111

108-
err = input_register_polled_device(poll_dev);
112+
err = input_register_device(input);
109113
if (err) {
110-
dev_err(dev, "failed to register polled device\n");
114+
dev_err(dev, "failed to register input device\n");
111115
return err;
112116
}
113117

0 commit comments

Comments
 (0)