24
24
#define TCA6416_INVERT 2
25
25
#define TCA6416_DIRECTION 3
26
26
27
+ #define TCA6416_POLL_INTERVAL 100 /* msec */
28
+
27
29
static const struct i2c_device_id tca6416_id [] = {
28
30
{ "tca6416-keys" , 16 , },
29
31
{ "tca6408-keys" , 8 , },
@@ -43,7 +45,6 @@ struct tca6416_keypad_chip {
43
45
44
46
struct i2c_client * client ;
45
47
struct input_dev * input ;
46
- struct delayed_work dwork ;
47
48
int io_size ;
48
49
int irqnum ;
49
50
u16 pinmask ;
@@ -85,9 +86,9 @@ static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val)
85
86
return 0 ;
86
87
}
87
88
88
- static void tca6416_keys_scan (struct tca6416_keypad_chip * chip )
89
+ static void tca6416_keys_scan (struct input_dev * input )
89
90
{
90
- struct input_dev * input = chip -> input ;
91
+ struct tca6416_keypad_chip * chip = input_get_drvdata ( input ) ;
91
92
u16 reg_val , val ;
92
93
int error , i , pin_index ;
93
94
@@ -122,33 +123,20 @@ static void tca6416_keys_scan(struct tca6416_keypad_chip *chip)
122
123
*/
123
124
static irqreturn_t tca6416_keys_isr (int irq , void * dev_id )
124
125
{
125
- struct tca6416_keypad_chip * chip = dev_id ;
126
-
127
- tca6416_keys_scan (chip );
126
+ tca6416_keys_scan (dev_id );
128
127
129
128
return IRQ_HANDLED ;
130
129
}
131
130
132
- static void tca6416_keys_work_func (struct work_struct * work )
133
- {
134
- struct tca6416_keypad_chip * chip =
135
- container_of (work , struct tca6416_keypad_chip , dwork .work );
136
-
137
- tca6416_keys_scan (chip );
138
- schedule_delayed_work (& chip -> dwork , msecs_to_jiffies (100 ));
139
- }
140
-
141
131
static int tca6416_keys_open (struct input_dev * dev )
142
132
{
143
133
struct tca6416_keypad_chip * chip = input_get_drvdata (dev );
144
134
145
- /* Get initial device state in case it has switches */
146
- tca6416_keys_scan (chip );
147
-
148
- if (chip -> use_polling )
149
- schedule_delayed_work (& chip -> dwork , msecs_to_jiffies (100 ));
150
- else
135
+ if (!chip -> use_polling ) {
136
+ /* Get initial device state in case it has switches */
137
+ tca6416_keys_scan (dev );
151
138
enable_irq (chip -> client -> irq );
139
+ }
152
140
153
141
return 0 ;
154
142
}
@@ -157,9 +145,7 @@ static void tca6416_keys_close(struct input_dev *dev)
157
145
{
158
146
struct tca6416_keypad_chip * chip = input_get_drvdata (dev );
159
147
160
- if (chip -> use_polling )
161
- cancel_delayed_work_sync (& chip -> dwork );
162
- else
148
+ if (!chip -> use_polling )
163
149
disable_irq (chip -> client -> irq );
164
150
}
165
151
@@ -232,8 +218,6 @@ static int tca6416_keypad_probe(struct i2c_client *client)
232
218
chip -> pinmask = pdata -> pinmask ;
233
219
chip -> use_polling = pdata -> use_polling ;
234
220
235
- INIT_DELAYED_WORK (& chip -> dwork , tca6416_keys_work_func );
236
-
237
221
input -> phys = "tca6416-keys/input0" ;
238
222
input -> name = client -> name ;
239
223
@@ -267,13 +251,21 @@ static int tca6416_keypad_probe(struct i2c_client *client)
267
251
if (error )
268
252
return error ;
269
253
270
- if (!chip -> use_polling ) {
254
+ if (chip -> use_polling ) {
255
+ error = input_setup_polling (input , tca6416_keys_scan );
256
+ if (error ) {
257
+ dev_err (& client -> dev , "Failed to setup polling\n" );
258
+ return error ;
259
+ }
260
+
261
+ input_set_poll_interval (input , TCA6416_POLL_INTERVAL );
262
+ } else {
271
263
error = devm_request_threaded_irq (& client -> dev , client -> irq ,
272
264
NULL , tca6416_keys_isr ,
273
265
IRQF_TRIGGER_FALLING |
274
266
IRQF_ONESHOT |
275
267
IRQF_NO_AUTOEN ,
276
- "tca6416-keypad" , chip );
268
+ "tca6416-keypad" , input );
277
269
if (error ) {
278
270
dev_dbg (& client -> dev ,
279
271
"Unable to claim irq %d; error %d\n" ,
0 commit comments