38
38
#define GOODIX_CONTACT_SIZE 8
39
39
#define GOODIX_MAX_CONTACT_SIZE 9
40
40
#define GOODIX_MAX_CONTACTS 10
41
+ #define GOODIX_MAX_KEYS 7
41
42
42
43
#define GOODIX_CONFIG_MIN_LENGTH 186
43
44
#define GOODIX_CONFIG_911_LENGTH 186
55
56
#define GOODIX_REG_ID 0x8140
56
57
57
58
#define GOODIX_BUFFER_STATUS_READY BIT(7)
59
+ #define GOODIX_HAVE_KEY BIT(4)
58
60
#define GOODIX_BUFFER_STATUS_TIMEOUT 20
59
61
60
62
#define RESOLUTION_LOC 1
@@ -100,6 +102,7 @@ struct goodix_ts_data {
100
102
enum goodix_irq_pin_access_method irq_pin_access_method ;
101
103
unsigned int contact_size ;
102
104
u8 config [GOODIX_CONFIG_MAX_LENGTH ];
105
+ unsigned short keymap [GOODIX_MAX_KEYS ];
103
106
};
104
107
105
108
static int goodix_check_cfg_8 (struct goodix_ts_data * ts ,
@@ -302,6 +305,13 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
302
305
unsigned long max_timeout ;
303
306
int touch_num ;
304
307
int error ;
308
+ u16 addr = GOODIX_READ_COOR_ADDR ;
309
+ /*
310
+ * We are going to read 1-byte header,
311
+ * ts->contact_size * max(1, touch_num) bytes of coordinates
312
+ * and 1-byte footer which contains the touch-key code.
313
+ */
314
+ const int header_contact_keycode_size = 1 + ts -> contact_size + 1 ;
305
315
306
316
/*
307
317
* The 'buffer status' bit, which indicates that the data is valid, is
@@ -310,8 +320,8 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
310
320
*/
311
321
max_timeout = jiffies + msecs_to_jiffies (GOODIX_BUFFER_STATUS_TIMEOUT );
312
322
do {
313
- error = goodix_i2c_read (ts -> client , GOODIX_READ_COOR_ADDR ,
314
- data , ts -> contact_size + 1 );
323
+ error = goodix_i2c_read (ts -> client , addr , data ,
324
+ header_contact_keycode_size );
315
325
if (error ) {
316
326
dev_err (& ts -> client -> dev , "I2C transfer error: %d\n" ,
317
327
error );
@@ -324,11 +334,10 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
324
334
return - EPROTO ;
325
335
326
336
if (touch_num > 1 ) {
327
- data += 1 + ts -> contact_size ;
337
+ addr += header_contact_keycode_size ;
338
+ data += header_contact_keycode_size ;
328
339
error = goodix_i2c_read (ts -> client ,
329
- GOODIX_READ_COOR_ADDR +
330
- 1 + ts -> contact_size ,
331
- data ,
340
+ addr , data ,
332
341
ts -> contact_size *
333
342
(touch_num - 1 ));
334
343
if (error )
@@ -378,6 +387,25 @@ static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
378
387
input_report_abs (ts -> input_dev , ABS_MT_WIDTH_MAJOR , input_w );
379
388
}
380
389
390
+ static void goodix_ts_report_key (struct goodix_ts_data * ts , u8 * data )
391
+ {
392
+ int touch_num ;
393
+ u8 key_value ;
394
+ int i ;
395
+
396
+ if (data [0 ] & GOODIX_HAVE_KEY ) {
397
+ touch_num = data [0 ] & 0x0f ;
398
+ key_value = data [1 + ts -> contact_size * touch_num ];
399
+ for (i = 0 ; i < GOODIX_MAX_KEYS ; i ++ )
400
+ if (key_value & BIT (i ))
401
+ input_report_key (ts -> input_dev ,
402
+ ts -> keymap [i ], 1 );
403
+ } else {
404
+ for (i = 0 ; i < GOODIX_MAX_KEYS ; i ++ )
405
+ input_report_key (ts -> input_dev , ts -> keymap [i ], 0 );
406
+ }
407
+ }
408
+
381
409
/**
382
410
* goodix_process_events - Process incoming events
383
411
*
@@ -388,19 +416,15 @@ static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
388
416
*/
389
417
static void goodix_process_events (struct goodix_ts_data * ts )
390
418
{
391
- u8 point_data [1 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS ];
419
+ u8 point_data [2 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS ];
392
420
int touch_num ;
393
421
int i ;
394
422
395
423
touch_num = goodix_ts_read_input_report (ts , point_data );
396
424
if (touch_num < 0 )
397
425
return ;
398
426
399
- /*
400
- * Bit 4 of the first byte reports the status of the capacitive
401
- * Windows/Home button.
402
- */
403
- input_report_key (ts -> input_dev , KEY_LEFTMETA , point_data [0 ] & BIT (4 ));
427
+ goodix_ts_report_key (ts , point_data );
404
428
405
429
for (i = 0 ; i < touch_num ; i ++ )
406
430
if (ts -> contact_size == 9 )
@@ -986,6 +1010,7 @@ static int goodix_i2c_test(struct i2c_client *client)
986
1010
static int goodix_configure_dev (struct goodix_ts_data * ts )
987
1011
{
988
1012
int error ;
1013
+ int i ;
989
1014
990
1015
ts -> int_trigger_type = GOODIX_INT_TRIGGER ;
991
1016
ts -> max_touch_num = GOODIX_MAX_CONTACTS ;
@@ -1003,8 +1028,19 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
1003
1028
ts -> input_dev -> id .product = ts -> id ;
1004
1029
ts -> input_dev -> id .version = ts -> version ;
1005
1030
1031
+ ts -> input_dev -> keycode = ts -> keymap ;
1032
+ ts -> input_dev -> keycodesize = sizeof (ts -> keymap [0 ]);
1033
+ ts -> input_dev -> keycodemax = GOODIX_MAX_KEYS ;
1034
+
1006
1035
/* Capacitive Windows/Home button on some devices */
1007
- input_set_capability (ts -> input_dev , EV_KEY , KEY_LEFTMETA );
1036
+ for (i = 0 ; i < GOODIX_MAX_KEYS ; ++ i ) {
1037
+ if (i == 0 )
1038
+ ts -> keymap [i ] = KEY_LEFTMETA ;
1039
+ else
1040
+ ts -> keymap [i ] = KEY_F1 + (i - 1 );
1041
+
1042
+ input_set_capability (ts -> input_dev , EV_KEY , ts -> keymap [i ]);
1043
+ }
1008
1044
1009
1045
input_set_capability (ts -> input_dev , EV_ABS , ABS_MT_POSITION_X );
1010
1046
input_set_capability (ts -> input_dev , EV_ABS , ABS_MT_POSITION_Y );
0 commit comments