hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/input/misc/gpio_decoder.c
....@@ -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 @@
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 @@
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 @@
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);
107105
108
- err = input_register_polled_device(poll_dev);
106
+ err = input_setup_polling(input, gpio_decoder_poll_gpios);
109107 if (err) {
110
- dev_err(dev, "failed to register polled device\n");
108
+ dev_err(dev, "failed to set up polling\n");
109
+ return err;
110
+ }
111
+
112
+ err = input_register_device(input);
113
+ if (err) {
114
+ dev_err(dev, "failed to register input device\n");
111115 return err;
112116 }
113117