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 ;
@@ -53,15 +51,15 @@ static int gpio_decoder_get_gpios_state(struct gpio_decoder *decoder)
53
51
return ret ;
54
52
}
55
53
56
- static void gpio_decoder_poll_gpios (struct input_polled_dev * poll_dev )
54
+ static void gpio_decoder_poll_gpios (struct input_dev * input )
57
55
{
58
- struct gpio_decoder * decoder = poll_dev -> private ;
56
+ struct gpio_decoder * decoder = input_get_drvdata ( input ) ;
59
57
int state ;
60
58
61
59
state = gpio_decoder_get_gpios_state (decoder );
62
60
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 );
65
63
decoder -> last_stable = state ;
66
64
}
67
65
}
@@ -70,20 +68,23 @@ static int gpio_decoder_probe(struct platform_device *pdev)
70
68
{
71
69
struct device * dev = & pdev -> dev ;
72
70
struct gpio_decoder * decoder ;
73
- struct input_polled_dev * poll_dev ;
71
+ struct input_dev * input ;
74
72
u32 max ;
75
73
int err ;
76
74
77
- decoder = devm_kzalloc (dev , sizeof (struct gpio_decoder ), GFP_KERNEL );
75
+ decoder = devm_kzalloc (dev , sizeof (* decoder ), GFP_KERNEL );
78
76
if (!decoder )
79
77
return - ENOMEM ;
80
78
79
+ decoder -> dev = dev ;
81
80
device_property_read_u32 (dev , "linux,axis" , & decoder -> axis );
81
+
82
82
decoder -> input_gpios = devm_gpiod_get_array (dev , NULL , GPIOD_IN );
83
83
if (IS_ERR (decoder -> input_gpios )) {
84
84
dev_err (dev , "unable to acquire input gpios\n" );
85
85
return PTR_ERR (decoder -> input_gpios );
86
86
}
87
+
87
88
if (decoder -> input_gpios -> ndescs < 2 ) {
88
89
dev_err (dev , "not enough gpios found\n" );
89
90
return - EINVAL ;
@@ -92,22 +93,25 @@ static int gpio_decoder_probe(struct platform_device *pdev)
92
93
if (device_property_read_u32 (dev , "decoder-max-value" , & max ))
93
94
max = (1U << decoder -> input_gpios -> ndescs ) - 1 ;
94
95
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 )
98
98
return - ENOMEM ;
99
99
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 );
103
101
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
+ }
107
111
108
- err = input_register_polled_device ( poll_dev );
112
+ err = input_register_device ( input );
109
113
if (err ) {
110
- dev_err (dev , "failed to register polled device\n" );
114
+ dev_err (dev , "failed to register input device\n" );
111
115
return err ;
112
116
}
113
117
0 commit comments