32
32
33
33
#define QT2160_NUM_LEDS_X 8
34
34
35
- #define QT2160_CYCLE_INTERVAL (2*HZ)
35
+ #define QT2160_CYCLE_INTERVAL 2000 /* msec - 2 sec */
36
36
37
37
static unsigned char qt2160_key2code [] = {
38
38
KEY_0 , KEY_1 , KEY_2 , KEY_3 ,
@@ -54,7 +54,6 @@ struct qt2160_led {
54
54
struct qt2160_data {
55
55
struct i2c_client * client ;
56
56
struct input_dev * input ;
57
- struct delayed_work dwork ;
58
57
unsigned short keycodes [ARRAY_SIZE (qt2160_key2code )];
59
58
u16 key_matrix ;
60
59
#ifdef CONFIG_LEDS_CLASS
@@ -155,10 +154,10 @@ static int qt2160_read_block(struct i2c_client *client,
155
154
return 0 ;
156
155
}
157
156
158
- static int qt2160_get_key_matrix (struct qt2160_data * qt2160 )
157
+ static void qt2160_get_key_matrix (struct input_dev * input )
159
158
{
159
+ struct qt2160_data * qt2160 = input_get_drvdata (input );
160
160
struct i2c_client * client = qt2160 -> client ;
161
- struct input_dev * input = qt2160 -> input ;
162
161
u8 regs [6 ];
163
162
u16 old_matrix , new_matrix ;
164
163
int ret , i , mask ;
@@ -173,7 +172,7 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160)
173
172
if (ret ) {
174
173
dev_err (& client -> dev ,
175
174
"could not perform chip read.\n" );
176
- return ret ;
175
+ return ;
177
176
}
178
177
179
178
old_matrix = qt2160 -> key_matrix ;
@@ -191,37 +190,17 @@ static int qt2160_get_key_matrix(struct qt2160_data *qt2160)
191
190
}
192
191
193
192
input_sync (input );
194
-
195
- return 0 ;
196
193
}
197
194
198
- static irqreturn_t qt2160_irq (int irq , void * _qt2160 )
195
+ static irqreturn_t qt2160_irq (int irq , void * data )
199
196
{
200
- struct qt2160_data * qt2160 = _qt2160 ;
197
+ struct input_dev * input = data ;
201
198
202
- mod_delayed_work ( system_wq , & qt2160 -> dwork , 0 );
199
+ qt2160_get_key_matrix ( input );
203
200
204
201
return IRQ_HANDLED ;
205
202
}
206
203
207
- static void qt2160_schedule_read (struct qt2160_data * qt2160 )
208
- {
209
- schedule_delayed_work (& qt2160 -> dwork , QT2160_CYCLE_INTERVAL );
210
- }
211
-
212
- static void qt2160_worker (struct work_struct * work )
213
- {
214
- struct qt2160_data * qt2160 =
215
- container_of (work , struct qt2160_data , dwork .work );
216
-
217
- dev_dbg (& qt2160 -> client -> dev , "worker\n" );
218
-
219
- qt2160_get_key_matrix (qt2160 );
220
-
221
- /* Avoid device lock up by checking every so often */
222
- qt2160_schedule_read (qt2160 );
223
- }
224
-
225
204
static int qt2160_read (struct i2c_client * client , u8 reg )
226
205
{
227
206
int ret ;
@@ -365,7 +344,6 @@ static int qt2160_probe(struct i2c_client *client)
365
344
366
345
qt2160 -> client = client ;
367
346
qt2160 -> input = input ;
368
- INIT_DELAYED_WORK (& qt2160 -> dwork , qt2160_worker );
369
347
370
348
input -> name = "AT42QT2160 Touch Sense Keyboard" ;
371
349
input -> id .bustype = BUS_I2C ;
@@ -382,6 +360,8 @@ static int qt2160_probe(struct i2c_client *client)
382
360
}
383
361
__clear_bit (KEY_RESERVED , input -> keybit );
384
362
363
+ input_set_drvdata (input , qt2160 );
364
+
385
365
/* Calibrate device */
386
366
error = qt2160_write (client , QT2160_CMD_CALIBRATE , 1 );
387
367
if (error ) {
@@ -390,13 +370,21 @@ static int qt2160_probe(struct i2c_client *client)
390
370
}
391
371
392
372
if (client -> irq ) {
393
- error = request_irq (client -> irq , qt2160_irq ,
394
- IRQF_TRIGGER_FALLING , "qt2160" , qt2160 );
373
+ error = request_threaded_irq (client -> irq , NULL , qt2160_irq ,
374
+ IRQF_TRIGGER_LOW | IRQF_ONESHOT ,
375
+ "qt2160" , input );
395
376
if (error ) {
396
377
dev_err (& client -> dev ,
397
378
"failed to allocate irq %d\n" , client -> irq );
398
379
goto err_free_mem ;
399
380
}
381
+ } else {
382
+ error = input_setup_polling (input , qt2160_get_key_matrix );
383
+ if (error ) {
384
+ dev_err (& client -> dev , "Failed to setup polling\n" );
385
+ goto err_free_mem ;
386
+ }
387
+ input_set_poll_interval (input , QT2160_CYCLE_INTERVAL );
400
388
}
401
389
402
390
error = qt2160_register_leds (qt2160 );
@@ -413,7 +401,6 @@ static int qt2160_probe(struct i2c_client *client)
413
401
}
414
402
415
403
i2c_set_clientdata (client , qt2160 );
416
- qt2160_schedule_read (qt2160 );
417
404
418
405
return 0 ;
419
406
@@ -438,8 +425,6 @@ static void qt2160_remove(struct i2c_client *client)
438
425
if (client -> irq )
439
426
free_irq (client -> irq , qt2160 );
440
427
441
- cancel_delayed_work_sync (& qt2160 -> dwork );
442
-
443
428
input_unregister_device (qt2160 -> input );
444
429
kfree (qt2160 );
445
430
}
0 commit comments