Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

+23 -20
-1
drivers/input/misc/Kconfig
··· 290 290 config INPUT_GPIO_DECODER 291 291 tristate "Polled GPIO Decoder Input driver" 292 292 depends on GPIOLIB || COMPILE_TEST 293 - select INPUT_POLLDEV 294 293 help 295 294 Say Y here if you want driver to read status of multiple GPIO 296 295 lines and report the encoded value as an absolute integer to
+23 -19
drivers/input/misc/gpio_decoder.c
··· 17 17 #include <linux/device.h> 18 18 #include <linux/gpio/consumer.h> 19 19 #include <linux/input.h> 20 - #include <linux/input-polldev.h> 21 20 #include <linux/kernel.h> 22 21 #include <linux/module.h> 23 22 #include <linux/of.h> 24 23 #include <linux/platform_device.h> 25 24 26 25 struct gpio_decoder { 27 - struct input_polled_dev *poll_dev; 28 26 struct gpio_descs *input_gpios; 29 27 struct device *dev; 30 28 u32 axis; ··· 51 53 return ret; 52 54 } 53 55 54 - static void gpio_decoder_poll_gpios(struct input_polled_dev *poll_dev) 56 + static void gpio_decoder_poll_gpios(struct input_dev *input) 55 57 { 56 - struct gpio_decoder *decoder = poll_dev->private; 58 + struct gpio_decoder *decoder = input_get_drvdata(input); 57 59 int state; 58 60 59 61 state = gpio_decoder_get_gpios_state(decoder); 60 62 if (state >= 0 && state != decoder->last_stable) { 61 - input_report_abs(poll_dev->input, decoder->axis, state); 62 - input_sync(poll_dev->input); 63 + input_report_abs(input, decoder->axis, state); 64 + input_sync(input); 63 65 decoder->last_stable = state; 64 66 } 65 67 } ··· 68 70 { 69 71 struct device *dev = &pdev->dev; 70 72 struct gpio_decoder *decoder; 71 - struct input_polled_dev *poll_dev; 73 + struct input_dev *input; 72 74 u32 max; 73 75 int err; 74 76 75 - decoder = devm_kzalloc(dev, sizeof(struct gpio_decoder), GFP_KERNEL); 77 + decoder = devm_kzalloc(dev, sizeof(*decoder), GFP_KERNEL); 76 78 if (!decoder) 77 79 return -ENOMEM; 78 80 81 + decoder->dev = dev; 79 82 device_property_read_u32(dev, "linux,axis", &decoder->axis); 83 + 80 84 decoder->input_gpios = devm_gpiod_get_array(dev, NULL, GPIOD_IN); 81 85 if (IS_ERR(decoder->input_gpios)) { 82 86 dev_err(dev, "unable to acquire input gpios\n"); 83 87 return PTR_ERR(decoder->input_gpios); 84 88 } 89 + 85 90 if (decoder->input_gpios->ndescs < 2) { 86 91 dev_err(dev, "not enough gpios found\n"); 87 92 return -EINVAL; ··· 93 92 if (device_property_read_u32(dev, "decoder-max-value", &max)) 94 93 max = (1U << decoder->input_gpios->ndescs) - 1; 95 94 96 - decoder->dev = dev; 97 - poll_dev = devm_input_allocate_polled_device(decoder->dev); 98 - if (!poll_dev) 95 + input = devm_input_allocate_device(dev); 96 + if (!input) 99 97 return -ENOMEM; 100 98 101 - poll_dev->private = decoder; 102 - poll_dev->poll = gpio_decoder_poll_gpios; 103 - decoder->poll_dev = poll_dev; 99 + input_set_drvdata(input, decoder); 104 100 105 - poll_dev->input->name = pdev->name; 106 - poll_dev->input->id.bustype = BUS_HOST; 107 - input_set_abs_params(poll_dev->input, decoder->axis, 0, max, 0, 0); 101 + input->name = pdev->name; 102 + input->id.bustype = BUS_HOST; 103 + input_set_abs_params(input, decoder->axis, 0, max, 0, 0); 108 104 109 - err = input_register_polled_device(poll_dev); 105 + err = input_setup_polling(input, gpio_decoder_poll_gpios); 110 106 if (err) { 111 - dev_err(dev, "failed to register polled device\n"); 107 + dev_err(dev, "failed to set up polling\n"); 108 + return err; 109 + } 110 + 111 + err = input_register_device(input); 112 + if (err) { 113 + dev_err(dev, "failed to register input device\n"); 112 114 return err; 113 115 } 114 116