2424#define TCA6416_INVERT 2
2525#define TCA6416_DIRECTION 3
2626
27+ #define TCA6416_POLL_INTERVAL 100 /* msec */
28+
2729static const struct i2c_device_id tca6416_id [] = {
2830 { "tca6416-keys" , 16 , },
2931 { "tca6408-keys" , 8 , },
@@ -43,7 +45,6 @@ struct tca6416_keypad_chip {
4345
4446 struct i2c_client * client ;
4547 struct input_dev * input ;
46- struct delayed_work dwork ;
4748 int io_size ;
4849 int irqnum ;
4950 u16 pinmask ;
@@ -85,9 +86,9 @@ static int tca6416_read_reg(struct tca6416_keypad_chip *chip, int reg, u16 *val)
8586 return 0 ;
8687}
8788
88- static void tca6416_keys_scan (struct tca6416_keypad_chip * chip )
89+ static void tca6416_keys_scan (struct input_dev * input )
8990{
90- struct input_dev * input = chip -> input ;
91+ struct tca6416_keypad_chip * chip = input_get_drvdata ( input ) ;
9192 u16 reg_val , val ;
9293 int error , i , pin_index ;
9394
@@ -122,33 +123,20 @@ static void tca6416_keys_scan(struct tca6416_keypad_chip *chip)
122123 */
123124static irqreturn_t tca6416_keys_isr (int irq , void * dev_id )
124125{
125- struct tca6416_keypad_chip * chip = dev_id ;
126-
127- tca6416_keys_scan (chip );
126+ tca6416_keys_scan (dev_id );
128127
129128 return IRQ_HANDLED ;
130129}
131130
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-
141131static int tca6416_keys_open (struct input_dev * dev )
142132{
143133 struct tca6416_keypad_chip * chip = input_get_drvdata (dev );
144134
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 );
151138 enable_irq (chip -> client -> irq );
139+ }
152140
153141 return 0 ;
154142}
@@ -157,9 +145,7 @@ static void tca6416_keys_close(struct input_dev *dev)
157145{
158146 struct tca6416_keypad_chip * chip = input_get_drvdata (dev );
159147
160- if (chip -> use_polling )
161- cancel_delayed_work_sync (& chip -> dwork );
162- else
148+ if (!chip -> use_polling )
163149 disable_irq (chip -> client -> irq );
164150}
165151
@@ -232,8 +218,6 @@ static int tca6416_keypad_probe(struct i2c_client *client)
232218 chip -> pinmask = pdata -> pinmask ;
233219 chip -> use_polling = pdata -> use_polling ;
234220
235- INIT_DELAYED_WORK (& chip -> dwork , tca6416_keys_work_func );
236-
237221 input -> phys = "tca6416-keys/input0" ;
238222 input -> name = client -> name ;
239223
@@ -267,13 +251,21 @@ static int tca6416_keypad_probe(struct i2c_client *client)
267251 if (error )
268252 return error ;
269253
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 {
271263 error = devm_request_threaded_irq (& client -> dev , client -> irq ,
272264 NULL , tca6416_keys_isr ,
273265 IRQF_TRIGGER_FALLING |
274266 IRQF_ONESHOT |
275267 IRQF_NO_AUTOEN ,
276- "tca6416-keypad" , chip );
268+ "tca6416-keypad" , input );
277269 if (error ) {
278270 dev_dbg (& client -> dev ,
279271 "Unable to claim irq %d; error %d\n" ,
0 commit comments