Skip to content

Commit 492ee52

Browse files
mastykin-astradtor
authored andcommitted
Input: goodix - add support for more then one touch-key
Some devices with a goodix touchscreen have more then 1 capacitive touch-key. This commit replaces the current support for a single touch-key, which ignored the reported key-code. With support for up to 7 touch-keys, based upon checking the key-code which is post-fixed to any reported touch-data. KEY_LEFTMETA is assigned to the first touch-key (it will still be the default keycode for devices with a single touch-key). KEY_F1, KEY_F2... are assigned as default keycode for the other touch-keys. This commit also add supports for keycode remapping, so that systemd-udev's hwdb can be used to remap the codes to send keycodes to match the icons on the buttons for devices with more then 1 touch-key. Signed-off-by: Dmitry Mastykin <[email protected]> Reviewed-by: Bastien Nocera <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 24ef83f commit 492ee52

File tree

1 file changed

+49
-13
lines changed

1 file changed

+49
-13
lines changed

drivers/input/touchscreen/goodix.c

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define GOODIX_CONTACT_SIZE 8
3939
#define GOODIX_MAX_CONTACT_SIZE 9
4040
#define GOODIX_MAX_CONTACTS 10
41+
#define GOODIX_MAX_KEYS 7
4142

4243
#define GOODIX_CONFIG_MIN_LENGTH 186
4344
#define GOODIX_CONFIG_911_LENGTH 186
@@ -55,6 +56,7 @@
5556
#define GOODIX_REG_ID 0x8140
5657

5758
#define GOODIX_BUFFER_STATUS_READY BIT(7)
59+
#define GOODIX_HAVE_KEY BIT(4)
5860
#define GOODIX_BUFFER_STATUS_TIMEOUT 20
5961

6062
#define RESOLUTION_LOC 1
@@ -100,6 +102,7 @@ struct goodix_ts_data {
100102
enum goodix_irq_pin_access_method irq_pin_access_method;
101103
unsigned int contact_size;
102104
u8 config[GOODIX_CONFIG_MAX_LENGTH];
105+
unsigned short keymap[GOODIX_MAX_KEYS];
103106
};
104107

105108
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)
302305
unsigned long max_timeout;
303306
int touch_num;
304307
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;
305315

306316
/*
307317
* 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)
310320
*/
311321
max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
312322
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);
315325
if (error) {
316326
dev_err(&ts->client->dev, "I2C transfer error: %d\n",
317327
error);
@@ -324,11 +334,10 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
324334
return -EPROTO;
325335

326336
if (touch_num > 1) {
327-
data += 1 + ts->contact_size;
337+
addr += header_contact_keycode_size;
338+
data += header_contact_keycode_size;
328339
error = goodix_i2c_read(ts->client,
329-
GOODIX_READ_COOR_ADDR +
330-
1 + ts->contact_size,
331-
data,
340+
addr, data,
332341
ts->contact_size *
333342
(touch_num - 1));
334343
if (error)
@@ -378,6 +387,25 @@ static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
378387
input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
379388
}
380389

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+
381409
/**
382410
* goodix_process_events - Process incoming events
383411
*
@@ -388,19 +416,15 @@ static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
388416
*/
389417
static void goodix_process_events(struct goodix_ts_data *ts)
390418
{
391-
u8 point_data[1 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
419+
u8 point_data[2 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
392420
int touch_num;
393421
int i;
394422

395423
touch_num = goodix_ts_read_input_report(ts, point_data);
396424
if (touch_num < 0)
397425
return;
398426

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);
404428

405429
for (i = 0; i < touch_num; i++)
406430
if (ts->contact_size == 9)
@@ -986,6 +1010,7 @@ static int goodix_i2c_test(struct i2c_client *client)
9861010
static int goodix_configure_dev(struct goodix_ts_data *ts)
9871011
{
9881012
int error;
1013+
int i;
9891014

9901015
ts->int_trigger_type = GOODIX_INT_TRIGGER;
9911016
ts->max_touch_num = GOODIX_MAX_CONTACTS;
@@ -1003,8 +1028,19 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
10031028
ts->input_dev->id.product = ts->id;
10041029
ts->input_dev->id.version = ts->version;
10051030

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+
10061035
/* 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+
}
10081044

10091045
input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X);
10101046
input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y);

0 commit comments

Comments
 (0)