Commit ff68cf0b authored by Dmitry Torokhov's avatar Dmitry Torokhov

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/20191017204217.106453-18-dmitry.torokhov@gmail.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 36bc3684
...@@ -290,7 +290,6 @@ config INPUT_GPIO_BEEPER ...@@ -290,7 +290,6 @@ config INPUT_GPIO_BEEPER
config INPUT_GPIO_DECODER config INPUT_GPIO_DECODER
tristate "Polled GPIO Decoder Input driver" tristate "Polled GPIO Decoder Input driver"
depends on GPIOLIB || COMPILE_TEST depends on GPIOLIB || COMPILE_TEST
select INPUT_POLLDEV
help help
Say Y here if you want driver to read status of multiple GPIO Say Y here if you want driver to read status of multiple GPIO
lines and report the encoded value as an absolute integer to lines and report the encoded value as an absolute integer to
......
...@@ -17,14 +17,12 @@ ...@@ -17,14 +17,12 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/input-polldev.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
struct gpio_decoder { struct gpio_decoder {
struct input_polled_dev *poll_dev;
struct gpio_descs *input_gpios; struct gpio_descs *input_gpios;
struct device *dev; struct device *dev;
u32 axis; u32 axis;
...@@ -53,15 +51,15 @@ static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder) ...@@ -53,15 +51,15 @@ static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
return ret; return ret;
} }
static void gpio_decoder_poll_gpios(struct input_polled_dev *poll_dev) static void gpio_decoder_poll_gpios(struct input_dev *input)
{ {
struct gpio_decoder *decoder = poll_dev->private; struct gpio_decoder *decoder = input_get_drvdata(input);
int state; int state;
state = gpio_decoder_get_gpios_state(decoder); state = gpio_decoder_get_gpios_state(decoder);
if (state >= 0 && state != decoder->last_stable) { if (state >= 0 && state != decoder->last_stable) {
input_report_abs(poll_dev->input, decoder->axis, state); input_report_abs(input, decoder->axis, state);
input_sync(poll_dev->input); input_sync(input);
decoder->last_stable = state; decoder->last_stable = state;
} }
} }
...@@ -70,20 +68,23 @@ static int gpio_decoder_probe(struct platform_device *pdev) ...@@ -70,20 +68,23 @@ static int gpio_decoder_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct gpio_decoder *decoder; struct gpio_decoder *decoder;
struct input_polled_dev *poll_dev; struct input_dev *input;
u32 max; u32 max;
int err; int err;
decoder = devm_kzalloc(dev, sizeof(struct gpio_decoder), GFP_KERNEL); decoder = devm_kzalloc(dev, sizeof(*decoder), GFP_KERNEL);
if (!decoder) if (!decoder)
return -ENOMEM; return -ENOMEM;
decoder->dev = dev;
device_property_read_u32(dev, "linux,axis", &decoder->axis); device_property_read_u32(dev, "linux,axis", &decoder->axis);
decoder->input_gpios = devm_gpiod_get_array(dev, NULL, GPIOD_IN); decoder->input_gpios = devm_gpiod_get_array(dev, NULL, GPIOD_IN);
if (IS_ERR(decoder->input_gpios)) { if (IS_ERR(decoder->input_gpios)) {
dev_err(dev, "unable to acquire input gpios\n"); dev_err(dev, "unable to acquire input gpios\n");
return PTR_ERR(decoder->input_gpios); return PTR_ERR(decoder->input_gpios);
} }
if (decoder->input_gpios->ndescs < 2) { if (decoder->input_gpios->ndescs < 2) {
dev_err(dev, "not enough gpios found\n"); dev_err(dev, "not enough gpios found\n");
return -EINVAL; return -EINVAL;
...@@ -92,22 +93,25 @@ static int gpio_decoder_probe(struct platform_device *pdev) ...@@ -92,22 +93,25 @@ static int gpio_decoder_probe(struct platform_device *pdev)
if (device_property_read_u32(dev, "decoder-max-value", &max)) if (device_property_read_u32(dev, "decoder-max-value", &max))
max = (1U << decoder->input_gpios->ndescs) - 1; max = (1U << decoder->input_gpios->ndescs) - 1;
decoder->dev = dev; input = devm_input_allocate_device(dev);
poll_dev = devm_input_allocate_polled_device(decoder->dev); if (!input)
if (!poll_dev)
return -ENOMEM; return -ENOMEM;
poll_dev->private = decoder; input_set_drvdata(input, decoder);
poll_dev->poll = gpio_decoder_poll_gpios;
decoder->poll_dev = poll_dev;
poll_dev->input->name = pdev->name; input->name = pdev->name;
poll_dev->input->id.bustype = BUS_HOST; input->id.bustype = BUS_HOST;
input_set_abs_params(poll_dev->input, decoder->axis, 0, max, 0, 0); input_set_abs_params(input, decoder->axis, 0, max, 0, 0);
err = input_setup_polling(input, gpio_decoder_poll_gpios);
if (err) {
dev_err(dev, "failed to set up polling\n");
return err;
}
err = input_register_polled_device(poll_dev); err = input_register_device(input);
if (err) { if (err) {
dev_err(dev, "failed to register polled device\n"); dev_err(dev, "failed to register input device\n");
return err; return err;
} }
......
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