hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/input/touchscreen/goodix.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Driver for Goodix Touchscreens
34 *
....@@ -9,11 +10,6 @@
910 * 2010 - 2012 Goodix Technology.
1011 */
1112
12
-/*
13
- * This program is free software; you can redistribute it and/or modify it
14
- * under the terms of the GNU General Public License as published by the Free
15
- * Software Foundation; version 2 of the License.
16
- */
1713
1814 #include <linux/kernel.h>
1915 #include <linux/dmi.h>
....@@ -27,34 +23,11 @@
2723 #include <linux/delay.h>
2824 #include <linux/irq.h>
2925 #include <linux/interrupt.h>
26
+#include <linux/regulator/consumer.h>
3027 #include <linux/slab.h>
3128 #include <linux/acpi.h>
3229 #include <linux/of.h>
3330 #include <asm/unaligned.h>
34
-
35
-struct goodix_ts_data;
36
-
37
-struct goodix_chip_data {
38
- u16 config_addr;
39
- int config_len;
40
- int (*check_config)(struct goodix_ts_data *, const struct firmware *);
41
-};
42
-
43
-struct goodix_ts_data {
44
- struct i2c_client *client;
45
- struct input_dev *input_dev;
46
- const struct goodix_chip_data *chip;
47
- struct touchscreen_properties prop;
48
- unsigned int max_touch_num;
49
- unsigned int int_trigger_type;
50
- struct gpio_desc *gpiod_int;
51
- struct gpio_desc *gpiod_rst;
52
- u16 id;
53
- u16 version;
54
- const char *cfg_name;
55
- struct completion firmware_loading_complete;
56
- unsigned long irq_flags;
57
-};
5831
5932 #define GOODIX_GPIO_INT_NAME "irq"
6033 #define GOODIX_GPIO_RST_NAME "reset"
....@@ -63,11 +36,15 @@
6336 #define GOODIX_MAX_WIDTH 4096
6437 #define GOODIX_INT_TRIGGER 1
6538 #define GOODIX_CONTACT_SIZE 8
39
+#define GOODIX_MAX_CONTACT_SIZE 9
6640 #define GOODIX_MAX_CONTACTS 10
41
+#define GOODIX_MAX_KEYS 7
6742
68
-#define GOODIX_CONFIG_MAX_LENGTH 240
43
+#define GOODIX_CONFIG_MIN_LENGTH 186
6944 #define GOODIX_CONFIG_911_LENGTH 186
7045 #define GOODIX_CONFIG_967_LENGTH 228
46
+#define GOODIX_CONFIG_GT9X_LENGTH 240
47
+#define GOODIX_CONFIG_MAX_LENGTH 240
7148
7249 /* Register defines */
7350 #define GOODIX_REG_COMMAND 0x8040
....@@ -79,39 +56,121 @@
7956 #define GOODIX_REG_ID 0x8140
8057
8158 #define GOODIX_BUFFER_STATUS_READY BIT(7)
59
+#define GOODIX_HAVE_KEY BIT(4)
8260 #define GOODIX_BUFFER_STATUS_TIMEOUT 20
8361
8462 #define RESOLUTION_LOC 1
8563 #define MAX_CONTACTS_LOC 5
8664 #define TRIGGER_LOC 6
8765
66
+/* Our special handling for GPIO accesses through ACPI is x86 specific */
67
+#if defined CONFIG_X86 && defined CONFIG_ACPI
68
+#define ACPI_GPIO_SUPPORT
69
+#endif
70
+
71
+struct goodix_ts_data;
72
+
73
+enum goodix_irq_pin_access_method {
74
+ IRQ_PIN_ACCESS_NONE,
75
+ IRQ_PIN_ACCESS_GPIO,
76
+ IRQ_PIN_ACCESS_ACPI_GPIO,
77
+ IRQ_PIN_ACCESS_ACPI_METHOD,
78
+};
79
+
80
+struct goodix_chip_data {
81
+ u16 config_addr;
82
+ int config_len;
83
+ int (*check_config)(struct goodix_ts_data *ts, const u8 *cfg, int len);
84
+ void (*calc_config_checksum)(struct goodix_ts_data *ts);
85
+};
86
+
87
+struct goodix_chip_id {
88
+ const char *id;
89
+ const struct goodix_chip_data *data;
90
+};
91
+
92
+#define GOODIX_ID_MAX_LEN 4
93
+
94
+struct goodix_ts_data {
95
+ struct i2c_client *client;
96
+ struct input_dev *input_dev;
97
+ const struct goodix_chip_data *chip;
98
+ struct touchscreen_properties prop;
99
+ unsigned int max_touch_num;
100
+ unsigned int int_trigger_type;
101
+ struct regulator *avdd28;
102
+ struct regulator *vddio;
103
+ struct gpio_desc *gpiod_int;
104
+ struct gpio_desc *gpiod_rst;
105
+ int gpio_count;
106
+ int gpio_int_idx;
107
+ char id[GOODIX_ID_MAX_LEN + 1];
108
+ u16 version;
109
+ const char *cfg_name;
110
+ bool reset_controller_at_probe;
111
+ bool load_cfg_from_disk;
112
+ struct completion firmware_loading_complete;
113
+ unsigned long irq_flags;
114
+ enum goodix_irq_pin_access_method irq_pin_access_method;
115
+ unsigned int contact_size;
116
+ u8 config[GOODIX_CONFIG_MAX_LENGTH];
117
+ unsigned short keymap[GOODIX_MAX_KEYS];
118
+};
119
+
88120 static int goodix_check_cfg_8(struct goodix_ts_data *ts,
89
- const struct firmware *cfg);
121
+ const u8 *cfg, int len);
90122 static int goodix_check_cfg_16(struct goodix_ts_data *ts,
91
- const struct firmware *cfg);
123
+ const u8 *cfg, int len);
124
+static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts);
125
+static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts);
92126
93127 static const struct goodix_chip_data gt1x_chip_data = {
94128 .config_addr = GOODIX_GT1X_REG_CONFIG_DATA,
95
- .config_len = GOODIX_CONFIG_MAX_LENGTH,
129
+ .config_len = GOODIX_CONFIG_GT9X_LENGTH,
96130 .check_config = goodix_check_cfg_16,
131
+ .calc_config_checksum = goodix_calc_cfg_checksum_16,
97132 };
98133
99134 static const struct goodix_chip_data gt911_chip_data = {
100135 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
101136 .config_len = GOODIX_CONFIG_911_LENGTH,
102137 .check_config = goodix_check_cfg_8,
138
+ .calc_config_checksum = goodix_calc_cfg_checksum_8,
103139 };
104140
105141 static const struct goodix_chip_data gt967_chip_data = {
106142 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
107143 .config_len = GOODIX_CONFIG_967_LENGTH,
108144 .check_config = goodix_check_cfg_8,
145
+ .calc_config_checksum = goodix_calc_cfg_checksum_8,
109146 };
110147
111148 static const struct goodix_chip_data gt9x_chip_data = {
112149 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
113
- .config_len = GOODIX_CONFIG_MAX_LENGTH,
150
+ .config_len = GOODIX_CONFIG_GT9X_LENGTH,
114151 .check_config = goodix_check_cfg_8,
152
+ .calc_config_checksum = goodix_calc_cfg_checksum_8,
153
+};
154
+
155
+static const struct goodix_chip_id goodix_chip_ids[] = {
156
+ { .id = "1151", .data = &gt1x_chip_data },
157
+ { .id = "1158", .data = &gt1x_chip_data },
158
+ { .id = "5663", .data = &gt1x_chip_data },
159
+ { .id = "5688", .data = &gt1x_chip_data },
160
+ { .id = "917S", .data = &gt1x_chip_data },
161
+ { .id = "9286", .data = &gt1x_chip_data },
162
+
163
+ { .id = "911", .data = &gt911_chip_data },
164
+ { .id = "9271", .data = &gt911_chip_data },
165
+ { .id = "9110", .data = &gt911_chip_data },
166
+ { .id = "9111", .data = &gt911_chip_data },
167
+ { .id = "927", .data = &gt911_chip_data },
168
+ { .id = "928", .data = &gt911_chip_data },
169
+
170
+ { .id = "912", .data = &gt967_chip_data },
171
+ { .id = "9147", .data = &gt967_chip_data },
172
+ { .id = "967", .data = &gt967_chip_data },
173
+ { }
115174 };
116175
117176 static const unsigned long goodix_irq_flags[] = {
....@@ -121,45 +180,37 @@
121180 IRQ_TYPE_LEVEL_HIGH,
122181 };
123182
124
-/*
125
- * Those tablets have their coordinates origin at the bottom right
126
- * of the tablet, as if rotated 180 degrees
127
- */
128
-static const struct dmi_system_id rotated_screen[] = {
183
+static const struct dmi_system_id nine_bytes_report[] = {
129184 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
130185 {
131
- .ident = "Teclast X89",
186
+ /* Lenovo Yoga Book X90F / X90L */
132187 .matches = {
133
- /* tPAD is too generic, also match on bios date */
134
- DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
135
- DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
136
- DMI_MATCH(DMI_BIOS_DATE, "12/19/2014"),
137
- },
138
- },
139
- {
140
- .ident = "Teclast X98 Pro",
141
- .matches = {
142
- /*
143
- * Only match BIOS date, because the manufacturers
144
- * BIOS does not report the board name at all
145
- * (sometimes)...
146
- */
147
- DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
148
- DMI_MATCH(DMI_BIOS_DATE, "10/28/2015"),
149
- },
150
- },
151
- {
152
- .ident = "WinBook TW100",
153
- .matches = {
154
- DMI_MATCH(DMI_SYS_VENDOR, "WinBook"),
155
- DMI_MATCH(DMI_PRODUCT_NAME, "TW100")
188
+ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
189
+ DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
190
+ DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
156191 }
157192 },
158193 {
159
- .ident = "WinBook TW700",
194
+ /* Lenovo Yoga Book X91F / X91L */
160195 .matches = {
161
- DMI_MATCH(DMI_SYS_VENDOR, "WinBook"),
162
- DMI_MATCH(DMI_PRODUCT_NAME, "TW700")
196
+ /* Non exact match to match F + L versions */
197
+ DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X91"),
198
+ }
199
+ },
200
+#endif
201
+ {}
202
+};
203
+
204
+/*
205
+ * Those tablets have their x coordinate inverted
206
+ */
207
+static const struct dmi_system_id inverted_x_screen[] = {
208
+#if defined(CONFIG_DMI) && defined(CONFIG_X86)
209
+ {
210
+ .ident = "Cube I15-TC",
211
+ .matches = {
212
+ DMI_MATCH(DMI_SYS_VENDOR, "Cube"),
213
+ DMI_MATCH(DMI_PRODUCT_NAME, "I15-TC")
163214 },
164215 },
165216 #endif
....@@ -233,26 +284,16 @@
233284 return goodix_i2c_write(client, reg, &value, sizeof(value));
234285 }
235286
236
-static const struct goodix_chip_data *goodix_get_chip_data(u16 id)
287
+static const struct goodix_chip_data *goodix_get_chip_data(const char *id)
237288 {
238
- switch (id) {
239
- case 1151:
240
- return &gt1x_chip_data;
289
+ unsigned int i;
241290
242
- case 911:
243
- case 9271:
244
- case 9110:
245
- case 927:
246
- case 928:
247
- return &gt911_chip_data;
248
-
249
- case 912:
250
- case 967:
251
- return &gt967_chip_data;
252
-
253
- default:
254
- return &gt9x_chip_data;
291
+ for (i = 0; goodix_chip_ids[i].id; i++) {
292
+ if (!strcmp(goodix_chip_ids[i].id, id))
293
+ return goodix_chip_ids[i].data;
255294 }
295
+
296
+ return &gt9x_chip_data;
256297 }
257298
258299 static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
....@@ -260,6 +301,13 @@
260301 unsigned long max_timeout;
261302 int touch_num;
262303 int error;
304
+ u16 addr = GOODIX_READ_COOR_ADDR;
305
+ /*
306
+ * We are going to read 1-byte header,
307
+ * ts->contact_size * max(1, touch_num) bytes of coordinates
308
+ * and 1-byte footer which contains the touch-key code.
309
+ */
310
+ const int header_contact_keycode_size = 1 + ts->contact_size + 1;
263311
264312 /*
265313 * The 'buffer status' bit, which indicates that the data is valid, is
....@@ -268,8 +316,8 @@
268316 */
269317 max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
270318 do {
271
- error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR,
272
- data, GOODIX_CONTACT_SIZE + 1);
319
+ error = goodix_i2c_read(ts->client, addr, data,
320
+ header_contact_keycode_size);
273321 if (error) {
274322 dev_err(&ts->client->dev, "I2C transfer error: %d\n",
275323 error);
....@@ -282,12 +330,11 @@
282330 return -EPROTO;
283331
284332 if (touch_num > 1) {
285
- data += 1 + GOODIX_CONTACT_SIZE;
333
+ addr += header_contact_keycode_size;
334
+ data += header_contact_keycode_size;
286335 error = goodix_i2c_read(ts->client,
287
- GOODIX_READ_COOR_ADDR +
288
- 1 + GOODIX_CONTACT_SIZE,
289
- data,
290
- GOODIX_CONTACT_SIZE *
336
+ addr, data,
337
+ ts->contact_size *
291338 (touch_num - 1));
292339 if (error)
293340 return error;
....@@ -303,10 +350,10 @@
303350 * The Goodix panel will send spurious interrupts after a
304351 * 'finger up' event, which will always cause a timeout.
305352 */
306
- return 0;
353
+ return -ENOMSG;
307354 }
308355
309
-static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
356
+static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data)
310357 {
311358 int id = coor_data[0] & 0x0F;
312359 int input_x = get_unaligned_le16(&coor_data[1]);
....@@ -321,6 +368,40 @@
321368 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
322369 }
323370
371
+static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data)
372
+{
373
+ int id = coor_data[1] & 0x0F;
374
+ int input_x = get_unaligned_le16(&coor_data[3]);
375
+ int input_y = get_unaligned_le16(&coor_data[5]);
376
+ int input_w = get_unaligned_le16(&coor_data[7]);
377
+
378
+ input_mt_slot(ts->input_dev, id);
379
+ input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
380
+ touchscreen_report_pos(ts->input_dev, &ts->prop,
381
+ input_x, input_y, true);
382
+ input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
383
+ input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
384
+}
385
+
386
+static void goodix_ts_report_key(struct goodix_ts_data *ts, u8 *data)
387
+{
388
+ int touch_num;
389
+ u8 key_value;
390
+ int i;
391
+
392
+ if (data[0] & GOODIX_HAVE_KEY) {
393
+ touch_num = data[0] & 0x0f;
394
+ key_value = data[1 + ts->contact_size * touch_num];
395
+ for (i = 0; i < GOODIX_MAX_KEYS; i++)
396
+ if (key_value & BIT(i))
397
+ input_report_key(ts->input_dev,
398
+ ts->keymap[i], 1);
399
+ } else {
400
+ for (i = 0; i < GOODIX_MAX_KEYS; i++)
401
+ input_report_key(ts->input_dev, ts->keymap[i], 0);
402
+ }
403
+}
404
+
324405 /**
325406 * goodix_process_events - Process incoming events
326407 *
....@@ -331,7 +412,7 @@
331412 */
332413 static void goodix_process_events(struct goodix_ts_data *ts)
333414 {
334
- u8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
415
+ u8 point_data[2 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
335416 int touch_num;
336417 int i;
337418
....@@ -339,15 +420,15 @@
339420 if (touch_num < 0)
340421 return;
341422
342
- /*
343
- * Bit 4 of the first byte reports the status of the capacitive
344
- * Windows/Home button.
345
- */
346
- input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4));
423
+ goodix_ts_report_key(ts, point_data);
347424
348425 for (i = 0; i < touch_num; i++)
349
- goodix_ts_report_touch(ts,
350
- &point_data[1 + GOODIX_CONTACT_SIZE * i]);
426
+ if (ts->contact_size == 9)
427
+ goodix_ts_report_touch_9b(ts,
428
+ &point_data[1 + ts->contact_size * i]);
429
+ else
430
+ goodix_ts_report_touch_8b(ts,
431
+ &point_data[1 + ts->contact_size * i]);
351432
352433 input_mt_sync_frame(ts->input_dev);
353434 input_sync(ts->input_dev);
....@@ -383,22 +464,21 @@
383464 ts->irq_flags, ts->client->name, ts);
384465 }
385466
386
-static int goodix_check_cfg_8(struct goodix_ts_data *ts,
387
- const struct firmware *cfg)
467
+static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
388468 {
389
- int i, raw_cfg_len = cfg->size - 2;
469
+ int i, raw_cfg_len = len - 2;
390470 u8 check_sum = 0;
391471
392472 for (i = 0; i < raw_cfg_len; i++)
393
- check_sum += cfg->data[i];
473
+ check_sum += cfg[i];
394474 check_sum = (~check_sum) + 1;
395
- if (check_sum != cfg->data[raw_cfg_len]) {
475
+ if (check_sum != cfg[raw_cfg_len]) {
396476 dev_err(&ts->client->dev,
397477 "The checksum of the config fw is not correct");
398478 return -EINVAL;
399479 }
400480
401
- if (cfg->data[raw_cfg_len + 1] != 1) {
481
+ if (cfg[raw_cfg_len + 1] != 1) {
402482 dev_err(&ts->client->dev,
403483 "Config fw must have Config_Fresh register set");
404484 return -EINVAL;
....@@ -407,28 +487,54 @@
407487 return 0;
408488 }
409489
410
-static int goodix_check_cfg_16(struct goodix_ts_data *ts,
411
- const struct firmware *cfg)
490
+static void goodix_calc_cfg_checksum_8(struct goodix_ts_data *ts)
412491 {
413
- int i, raw_cfg_len = cfg->size - 3;
492
+ int i, raw_cfg_len = ts->chip->config_len - 2;
493
+ u8 check_sum = 0;
494
+
495
+ for (i = 0; i < raw_cfg_len; i++)
496
+ check_sum += ts->config[i];
497
+ check_sum = (~check_sum) + 1;
498
+
499
+ ts->config[raw_cfg_len] = check_sum;
500
+ ts->config[raw_cfg_len + 1] = 1; /* Set "config_fresh" bit */
501
+}
502
+
503
+static int goodix_check_cfg_16(struct goodix_ts_data *ts, const u8 *cfg,
504
+ int len)
505
+{
506
+ int i, raw_cfg_len = len - 3;
414507 u16 check_sum = 0;
415508
416509 for (i = 0; i < raw_cfg_len; i += 2)
417
- check_sum += get_unaligned_be16(&cfg->data[i]);
510
+ check_sum += get_unaligned_be16(&cfg[i]);
418511 check_sum = (~check_sum) + 1;
419
- if (check_sum != get_unaligned_be16(&cfg->data[raw_cfg_len])) {
512
+ if (check_sum != get_unaligned_be16(&cfg[raw_cfg_len])) {
420513 dev_err(&ts->client->dev,
421514 "The checksum of the config fw is not correct");
422515 return -EINVAL;
423516 }
424517
425
- if (cfg->data[raw_cfg_len + 2] != 1) {
518
+ if (cfg[raw_cfg_len + 2] != 1) {
426519 dev_err(&ts->client->dev,
427520 "Config fw must have Config_Fresh register set");
428521 return -EINVAL;
429522 }
430523
431524 return 0;
525
+}
526
+
527
+static void goodix_calc_cfg_checksum_16(struct goodix_ts_data *ts)
528
+{
529
+ int i, raw_cfg_len = ts->chip->config_len - 3;
530
+ u16 check_sum = 0;
531
+
532
+ for (i = 0; i < raw_cfg_len; i += 2)
533
+ check_sum += get_unaligned_be16(&ts->config[i]);
534
+ check_sum = (~check_sum) + 1;
535
+
536
+ put_unaligned_be16(check_sum, &ts->config[raw_cfg_len]);
537
+ ts->config[raw_cfg_len + 2] = 1; /* Set "config_fresh" bit */
432538 }
433539
434540 /**
....@@ -437,16 +543,16 @@
437543 * @ts: goodix_ts_data pointer
438544 * @cfg: firmware config data
439545 */
440
-static int goodix_check_cfg(struct goodix_ts_data *ts,
441
- const struct firmware *cfg)
546
+static int goodix_check_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
442547 {
443
- if (cfg->size > GOODIX_CONFIG_MAX_LENGTH) {
548
+ if (len < GOODIX_CONFIG_MIN_LENGTH ||
549
+ len > GOODIX_CONFIG_MAX_LENGTH) {
444550 dev_err(&ts->client->dev,
445551 "The length of the config fw is not correct");
446552 return -EINVAL;
447553 }
448554
449
- return ts->chip->check_config(ts, cfg);
555
+ return ts->chip->check_config(ts, cfg, len);
450556 }
451557
452558 /**
....@@ -455,17 +561,15 @@
455561 * @ts: goodix_ts_data pointer
456562 * @cfg: config firmware to write to device
457563 */
458
-static int goodix_send_cfg(struct goodix_ts_data *ts,
459
- const struct firmware *cfg)
564
+static int goodix_send_cfg(struct goodix_ts_data *ts, const u8 *cfg, int len)
460565 {
461566 int error;
462567
463
- error = goodix_check_cfg(ts, cfg);
568
+ error = goodix_check_cfg(ts, cfg, len);
464569 if (error)
465570 return error;
466571
467
- error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg->data,
468
- cfg->size);
572
+ error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg, len);
469573 if (error) {
470574 dev_err(&ts->client->dev, "Failed to write config data: %d",
471575 error);
....@@ -479,17 +583,93 @@
479583 return 0;
480584 }
481585
586
+#ifdef ACPI_GPIO_SUPPORT
587
+static int goodix_pin_acpi_direction_input(struct goodix_ts_data *ts)
588
+{
589
+ acpi_handle handle = ACPI_HANDLE(&ts->client->dev);
590
+ acpi_status status;
591
+
592
+ status = acpi_evaluate_object(handle, "INTI", NULL, NULL);
593
+ return ACPI_SUCCESS(status) ? 0 : -EIO;
594
+}
595
+
596
+static int goodix_pin_acpi_output_method(struct goodix_ts_data *ts, int value)
597
+{
598
+ acpi_handle handle = ACPI_HANDLE(&ts->client->dev);
599
+ acpi_status status;
600
+
601
+ status = acpi_execute_simple_method(handle, "INTO", value);
602
+ return ACPI_SUCCESS(status) ? 0 : -EIO;
603
+}
604
+#else
605
+static int goodix_pin_acpi_direction_input(struct goodix_ts_data *ts)
606
+{
607
+ dev_err(&ts->client->dev,
608
+ "%s called on device without ACPI support\n", __func__);
609
+ return -EINVAL;
610
+}
611
+
612
+static int goodix_pin_acpi_output_method(struct goodix_ts_data *ts, int value)
613
+{
614
+ dev_err(&ts->client->dev,
615
+ "%s called on device without ACPI support\n", __func__);
616
+ return -EINVAL;
617
+}
618
+#endif
619
+
620
+static int goodix_irq_direction_output(struct goodix_ts_data *ts, int value)
621
+{
622
+ switch (ts->irq_pin_access_method) {
623
+ case IRQ_PIN_ACCESS_NONE:
624
+ dev_err(&ts->client->dev,
625
+ "%s called without an irq_pin_access_method set\n",
626
+ __func__);
627
+ return -EINVAL;
628
+ case IRQ_PIN_ACCESS_GPIO:
629
+ return gpiod_direction_output(ts->gpiod_int, value);
630
+ case IRQ_PIN_ACCESS_ACPI_GPIO:
631
+ /*
632
+ * The IRQ pin triggers on a falling edge, so its gets marked
633
+ * as active-low, use output_raw to avoid the value inversion.
634
+ */
635
+ return gpiod_direction_output_raw(ts->gpiod_int, value);
636
+ case IRQ_PIN_ACCESS_ACPI_METHOD:
637
+ return goodix_pin_acpi_output_method(ts, value);
638
+ }
639
+
640
+ return -EINVAL; /* Never reached */
641
+}
642
+
643
+static int goodix_irq_direction_input(struct goodix_ts_data *ts)
644
+{
645
+ switch (ts->irq_pin_access_method) {
646
+ case IRQ_PIN_ACCESS_NONE:
647
+ dev_err(&ts->client->dev,
648
+ "%s called without an irq_pin_access_method set\n",
649
+ __func__);
650
+ return -EINVAL;
651
+ case IRQ_PIN_ACCESS_GPIO:
652
+ return gpiod_direction_input(ts->gpiod_int);
653
+ case IRQ_PIN_ACCESS_ACPI_GPIO:
654
+ return gpiod_direction_input(ts->gpiod_int);
655
+ case IRQ_PIN_ACCESS_ACPI_METHOD:
656
+ return goodix_pin_acpi_direction_input(ts);
657
+ }
658
+
659
+ return -EINVAL; /* Never reached */
660
+}
661
+
482662 static int goodix_int_sync(struct goodix_ts_data *ts)
483663 {
484664 int error;
485665
486
- error = gpiod_direction_output(ts->gpiod_int, 0);
666
+ error = goodix_irq_direction_output(ts, 0);
487667 if (error)
488668 return error;
489669
490670 msleep(50); /* T5: 50ms */
491671
492
- error = gpiod_direction_input(ts->gpiod_int);
672
+ error = goodix_irq_direction_input(ts);
493673 if (error)
494674 return error;
495675
....@@ -513,7 +693,7 @@
513693 msleep(20); /* T2: > 10ms */
514694
515695 /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */
516
- error = gpiod_direction_output(ts->gpiod_int, ts->client->addr == 0x14);
696
+ error = goodix_irq_direction_output(ts, ts->client->addr == 0x14);
517697 if (error)
518698 return error;
519699
....@@ -537,6 +717,124 @@
537717 return 0;
538718 }
539719
720
+#ifdef ACPI_GPIO_SUPPORT
721
+#include <asm/cpu_device_id.h>
722
+#include <asm/intel-family.h>
723
+
724
+static const struct x86_cpu_id baytrail_cpu_ids[] = {
725
+ { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, X86_FEATURE_ANY, },
726
+ {}
727
+};
728
+
729
+static inline bool is_byt(void)
730
+{
731
+ const struct x86_cpu_id *id = x86_match_cpu(baytrail_cpu_ids);
732
+
733
+ return !!id;
734
+}
735
+
736
+static const struct acpi_gpio_params first_gpio = { 0, 0, false };
737
+static const struct acpi_gpio_params second_gpio = { 1, 0, false };
738
+
739
+static const struct acpi_gpio_mapping acpi_goodix_int_first_gpios[] = {
740
+ { GOODIX_GPIO_INT_NAME "-gpios", &first_gpio, 1 },
741
+ { GOODIX_GPIO_RST_NAME "-gpios", &second_gpio, 1 },
742
+ { },
743
+};
744
+
745
+static const struct acpi_gpio_mapping acpi_goodix_int_last_gpios[] = {
746
+ { GOODIX_GPIO_RST_NAME "-gpios", &first_gpio, 1 },
747
+ { GOODIX_GPIO_INT_NAME "-gpios", &second_gpio, 1 },
748
+ { },
749
+};
750
+
751
+static const struct acpi_gpio_mapping acpi_goodix_reset_only_gpios[] = {
752
+ { GOODIX_GPIO_RST_NAME "-gpios", &first_gpio, 1 },
753
+ { },
754
+};
755
+
756
+static int goodix_resource(struct acpi_resource *ares, void *data)
757
+{
758
+ struct goodix_ts_data *ts = data;
759
+ struct device *dev = &ts->client->dev;
760
+ struct acpi_resource_gpio *gpio;
761
+
762
+ switch (ares->type) {
763
+ case ACPI_RESOURCE_TYPE_GPIO:
764
+ gpio = &ares->data.gpio;
765
+ if (gpio->connection_type == ACPI_RESOURCE_GPIO_TYPE_INT) {
766
+ if (ts->gpio_int_idx == -1) {
767
+ ts->gpio_int_idx = ts->gpio_count;
768
+ } else {
769
+ dev_err(dev, "More then one GpioInt resource, ignoring ACPI GPIO resources\n");
770
+ ts->gpio_int_idx = -2;
771
+ }
772
+ }
773
+ ts->gpio_count++;
774
+ break;
775
+ default:
776
+ break;
777
+ }
778
+
779
+ return 0;
780
+}
781
+
782
+/*
783
+ * This function gets called in case we fail to get the irq GPIO directly
784
+ * because the ACPI tables lack GPIO-name to APCI _CRS index mappings
785
+ * (no _DSD UUID daffd814-6eba-4d8c-8a91-bc9bbf4aa301 data).
786
+ * In that case we add our own mapping and then goodix_get_gpio_config()
787
+ * retries to get the GPIOs based on the added mapping.
788
+ */
789
+static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
790
+{
791
+ const struct acpi_gpio_mapping *gpio_mapping = NULL;
792
+ struct device *dev = &ts->client->dev;
793
+ LIST_HEAD(resources);
794
+ int ret;
795
+
796
+ ts->gpio_count = 0;
797
+ ts->gpio_int_idx = -1;
798
+ ret = acpi_dev_get_resources(ACPI_COMPANION(dev), &resources,
799
+ goodix_resource, ts);
800
+ if (ret < 0) {
801
+ dev_err(dev, "Error getting ACPI resources: %d\n", ret);
802
+ return ret;
803
+ }
804
+
805
+ acpi_dev_free_resource_list(&resources);
806
+
807
+ if (ts->gpio_count == 2 && ts->gpio_int_idx == 0) {
808
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
809
+ gpio_mapping = acpi_goodix_int_first_gpios;
810
+ } else if (ts->gpio_count == 2 && ts->gpio_int_idx == 1) {
811
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
812
+ gpio_mapping = acpi_goodix_int_last_gpios;
813
+ } else if (ts->gpio_count == 1 && ts->gpio_int_idx == -1 &&
814
+ acpi_has_method(ACPI_HANDLE(dev), "INTI") &&
815
+ acpi_has_method(ACPI_HANDLE(dev), "INTO")) {
816
+ dev_info(dev, "Using ACPI INTI and INTO methods for IRQ pin access\n");
817
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_METHOD;
818
+ gpio_mapping = acpi_goodix_reset_only_gpios;
819
+ } else if (is_byt() && ts->gpio_count == 2 && ts->gpio_int_idx == -1) {
820
+ dev_info(dev, "No ACPI GpioInt resource, assuming that the GPIO order is reset, int\n");
821
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_ACPI_GPIO;
822
+ gpio_mapping = acpi_goodix_int_last_gpios;
823
+ } else {
824
+ dev_warn(dev, "Unexpected ACPI resources: gpio_count %d, gpio_int_idx %d\n",
825
+ ts->gpio_count, ts->gpio_int_idx);
826
+ return -EINVAL;
827
+ }
828
+
829
+ return devm_acpi_dev_add_driver_gpios(dev, gpio_mapping);
830
+}
831
+#else
832
+static int goodix_add_acpi_gpio_mappings(struct goodix_ts_data *ts)
833
+{
834
+ return -EINVAL;
835
+}
836
+#endif /* CONFIG_X86 && CONFIG_ACPI */
837
+
540838 /**
541839 * goodix_get_gpio_config - Get GPIO config from ACPI/DT
542840 *
....@@ -547,11 +845,31 @@
547845 int error;
548846 struct device *dev;
549847 struct gpio_desc *gpiod;
848
+ bool added_acpi_mappings = false;
550849
551850 if (!ts->client)
552851 return -EINVAL;
553852 dev = &ts->client->dev;
554853
854
+ ts->avdd28 = devm_regulator_get(dev, "AVDD28");
855
+ if (IS_ERR(ts->avdd28)) {
856
+ error = PTR_ERR(ts->avdd28);
857
+ if (error != -EPROBE_DEFER)
858
+ dev_err(dev,
859
+ "Failed to get AVDD28 regulator: %d\n", error);
860
+ return error;
861
+ }
862
+
863
+ ts->vddio = devm_regulator_get(dev, "VDDIO");
864
+ if (IS_ERR(ts->vddio)) {
865
+ error = PTR_ERR(ts->vddio);
866
+ if (error != -EPROBE_DEFER)
867
+ dev_err(dev,
868
+ "Failed to get VDDIO regulator: %d\n", error);
869
+ return error;
870
+ }
871
+
872
+retry_get_irq_gpio:
555873 /* Get the interrupt GPIO pin number */
556874 gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME, GPIOD_IN);
557875 if (IS_ERR(gpiod)) {
....@@ -560,6 +878,11 @@
560878 dev_dbg(dev, "Failed to get %s GPIO: %d\n",
561879 GOODIX_GPIO_INT_NAME, error);
562880 return error;
881
+ }
882
+ if (!gpiod && has_acpi_companion(dev) && !added_acpi_mappings) {
883
+ added_acpi_mappings = true;
884
+ if (goodix_add_acpi_gpio_mappings(ts) == 0)
885
+ goto retry_get_irq_gpio;
563886 }
564887
565888 ts->gpiod_int = gpiod;
....@@ -576,6 +899,31 @@
576899
577900 ts->gpiod_rst = gpiod;
578901
902
+ switch (ts->irq_pin_access_method) {
903
+ case IRQ_PIN_ACCESS_ACPI_GPIO:
904
+ /*
905
+ * We end up here if goodix_add_acpi_gpio_mappings() has
906
+ * called devm_acpi_dev_add_driver_gpios() because the ACPI
907
+ * tables did not contain name to index mappings.
908
+ * Check that we successfully got both GPIOs after we've
909
+ * added our own acpi_gpio_mapping and if we did not get both
910
+ * GPIOs reset irq_pin_access_method to IRQ_PIN_ACCESS_NONE.
911
+ */
912
+ if (!ts->gpiod_int || !ts->gpiod_rst)
913
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_NONE;
914
+ break;
915
+ case IRQ_PIN_ACCESS_ACPI_METHOD:
916
+ if (!ts->gpiod_rst)
917
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_NONE;
918
+ break;
919
+ default:
920
+ if (ts->gpiod_int && ts->gpiod_rst) {
921
+ ts->reset_controller_at_probe = true;
922
+ ts->load_cfg_from_disk = true;
923
+ ts->irq_pin_access_method = IRQ_PIN_ACCESS_GPIO;
924
+ }
925
+ }
926
+
579927 return 0;
580928 }
581929
....@@ -588,12 +936,11 @@
588936 */
589937 static void goodix_read_config(struct goodix_ts_data *ts)
590938 {
591
- u8 config[GOODIX_CONFIG_MAX_LENGTH];
592939 int x_max, y_max;
593940 int error;
594941
595942 error = goodix_i2c_read(ts->client, ts->chip->config_addr,
596
- config, ts->chip->config_len);
943
+ ts->config, ts->chip->config_len);
597944 if (error) {
598945 dev_warn(&ts->client->dev, "Error reading config: %d\n",
599946 error);
....@@ -602,15 +949,17 @@
602949 return;
603950 }
604951
605
- ts->int_trigger_type = config[TRIGGER_LOC] & 0x03;
606
- ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f;
952
+ ts->int_trigger_type = ts->config[TRIGGER_LOC] & 0x03;
953
+ ts->max_touch_num = ts->config[MAX_CONTACTS_LOC] & 0x0f;
607954
608
- x_max = get_unaligned_le16(&config[RESOLUTION_LOC]);
609
- y_max = get_unaligned_le16(&config[RESOLUTION_LOC + 2]);
955
+ x_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC]);
956
+ y_max = get_unaligned_le16(&ts->config[RESOLUTION_LOC + 2]);
610957 if (x_max && y_max) {
611958 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1);
612959 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1);
613960 }
961
+
962
+ ts->chip->calc_config_checksum(ts);
614963 }
615964
616965 /**
....@@ -622,7 +971,7 @@
622971 {
623972 int error;
624973 u8 buf[6];
625
- char id_str[5];
974
+ char id_str[GOODIX_ID_MAX_LEN + 1];
626975
627976 error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf));
628977 if (error) {
....@@ -630,14 +979,13 @@
630979 return error;
631980 }
632981
633
- memcpy(id_str, buf, 4);
634
- id_str[4] = 0;
635
- if (kstrtou16(id_str, 10, &ts->id))
636
- ts->id = 0x1001;
982
+ memcpy(id_str, buf, GOODIX_ID_MAX_LEN);
983
+ id_str[GOODIX_ID_MAX_LEN] = 0;
984
+ strscpy(ts->id, id_str, GOODIX_ID_MAX_LEN + 1);
637985
638986 ts->version = get_unaligned_le16(&buf[4]);
639987
640
- dev_info(&ts->client->dev, "ID %d, version: %04x\n", ts->id,
988
+ dev_info(&ts->client->dev, "ID %s, version: %04x\n", ts->id,
641989 ts->version);
642990
643991 return 0;
....@@ -681,6 +1029,7 @@
6811029 static int goodix_configure_dev(struct goodix_ts_data *ts)
6821030 {
6831031 int error;
1032
+ int i;
6841033
6851034 ts->int_trigger_type = GOODIX_INT_TRIGGER;
6861035 ts->max_touch_num = GOODIX_MAX_CONTACTS;
....@@ -695,17 +1044,30 @@
6951044 ts->input_dev->phys = "input/ts";
6961045 ts->input_dev->id.bustype = BUS_I2C;
6971046 ts->input_dev->id.vendor = 0x0416;
698
- ts->input_dev->id.product = ts->id;
1047
+ if (kstrtou16(ts->id, 10, &ts->input_dev->id.product))
1048
+ ts->input_dev->id.product = 0x1001;
6991049 ts->input_dev->id.version = ts->version;
7001050
1051
+ ts->input_dev->keycode = ts->keymap;
1052
+ ts->input_dev->keycodesize = sizeof(ts->keymap[0]);
1053
+ ts->input_dev->keycodemax = GOODIX_MAX_KEYS;
1054
+
7011055 /* Capacitive Windows/Home button on some devices */
702
- input_set_capability(ts->input_dev, EV_KEY, KEY_LEFTMETA);
1056
+ for (i = 0; i < GOODIX_MAX_KEYS; ++i) {
1057
+ if (i == 0)
1058
+ ts->keymap[i] = KEY_LEFTMETA;
1059
+ else
1060
+ ts->keymap[i] = KEY_F1 + (i - 1);
1061
+
1062
+ input_set_capability(ts->input_dev, EV_KEY, ts->keymap[i]);
1063
+ }
7031064
7041065 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X);
7051066 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y);
7061067 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
7071068 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
7081069
1070
+retry_read_config:
7091071 /* Read configuration and apply touchscreen parameters */
7101072 goodix_read_config(ts);
7111073
....@@ -713,7 +1075,19 @@
7131075 touchscreen_parse_properties(ts->input_dev, true, &ts->prop);
7141076
7151077 if (!ts->prop.max_x || !ts->prop.max_y || !ts->max_touch_num) {
716
- dev_err(&ts->client->dev, "Invalid config, using defaults\n");
1078
+ if (!ts->reset_controller_at_probe &&
1079
+ ts->irq_pin_access_method != IRQ_PIN_ACCESS_NONE) {
1080
+ dev_info(&ts->client->dev, "Config not set, resetting controller\n");
1081
+ /* Retry after a controller reset */
1082
+ ts->reset_controller_at_probe = true;
1083
+ error = goodix_reset(ts);
1084
+ if (error)
1085
+ return error;
1086
+ goto retry_read_config;
1087
+ }
1088
+ dev_err(&ts->client->dev,
1089
+ "Invalid config (%d, %d, %d), using defaults\n",
1090
+ ts->prop.max_x, ts->prop.max_y, ts->max_touch_num);
7171091 ts->prop.max_x = GOODIX_MAX_WIDTH - 1;
7181092 ts->prop.max_y = GOODIX_MAX_HEIGHT - 1;
7191093 ts->max_touch_num = GOODIX_MAX_CONTACTS;
....@@ -723,11 +1097,17 @@
7231097 ABS_MT_POSITION_Y, ts->prop.max_y);
7241098 }
7251099
726
- if (dmi_check_system(rotated_screen)) {
727
- ts->prop.invert_x = true;
728
- ts->prop.invert_y = true;
1100
+ if (dmi_check_system(nine_bytes_report)) {
1101
+ ts->contact_size = 9;
1102
+
7291103 dev_dbg(&ts->client->dev,
730
- "Applying '180 degrees rotated screen' quirk\n");
1104
+ "Non-standard 9-bytes report format quirk\n");
1105
+ }
1106
+
1107
+ if (dmi_check_system(inverted_x_screen)) {
1108
+ ts->prop.invert_x = true;
1109
+ dev_dbg(&ts->client->dev,
1110
+ "Applying 'inverted x screen' quirk\n");
7311111 }
7321112
7331113 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num,
....@@ -770,7 +1150,7 @@
7701150
7711151 if (cfg) {
7721152 /* send device configuration to the firmware */
773
- error = goodix_send_cfg(ts, cfg);
1153
+ error = goodix_send_cfg(ts, cfg->data, cfg->size);
7741154 if (error)
7751155 goto err_release_cfg;
7761156 }
....@@ -780,6 +1160,14 @@
7801160 err_release_cfg:
7811161 release_firmware(cfg);
7821162 complete_all(&ts->firmware_loading_complete);
1163
+}
1164
+
1165
+static void goodix_disable_regulators(void *arg)
1166
+{
1167
+ struct goodix_ts_data *ts = arg;
1168
+
1169
+ regulator_disable(ts->vddio);
1170
+ regulator_disable(ts->avdd28);
7831171 }
7841172
7851173 static int goodix_ts_probe(struct i2c_client *client,
....@@ -802,12 +1190,37 @@
8021190 ts->client = client;
8031191 i2c_set_clientdata(client, ts);
8041192 init_completion(&ts->firmware_loading_complete);
1193
+ ts->contact_size = GOODIX_CONTACT_SIZE;
8051194
8061195 error = goodix_get_gpio_config(ts);
8071196 if (error)
8081197 return error;
8091198
810
- if (ts->gpiod_int && ts->gpiod_rst) {
1199
+ /* power up the controller */
1200
+ error = regulator_enable(ts->avdd28);
1201
+ if (error) {
1202
+ dev_err(&client->dev,
1203
+ "Failed to enable AVDD28 regulator: %d\n",
1204
+ error);
1205
+ return error;
1206
+ }
1207
+
1208
+ error = regulator_enable(ts->vddio);
1209
+ if (error) {
1210
+ dev_err(&client->dev,
1211
+ "Failed to enable VDDIO regulator: %d\n",
1212
+ error);
1213
+ regulator_disable(ts->avdd28);
1214
+ return error;
1215
+ }
1216
+
1217
+ error = devm_add_action_or_reset(&client->dev,
1218
+ goodix_disable_regulators, ts);
1219
+ if (error)
1220
+ return error;
1221
+
1222
+reset:
1223
+ if (ts->reset_controller_at_probe) {
8111224 /* reset the controller */
8121225 error = goodix_reset(ts);
8131226 if (error) {
....@@ -818,6 +1231,12 @@
8181231
8191232 error = goodix_i2c_test(client);
8201233 if (error) {
1234
+ if (!ts->reset_controller_at_probe &&
1235
+ ts->irq_pin_access_method != IRQ_PIN_ACCESS_NONE) {
1236
+ /* Retry after a controller reset */
1237
+ ts->reset_controller_at_probe = true;
1238
+ goto reset;
1239
+ }
8211240 dev_err(&client->dev, "I2C communication failure: %d\n", error);
8221241 return error;
8231242 }
....@@ -830,10 +1249,10 @@
8301249
8311250 ts->chip = goodix_get_chip_data(ts->id);
8321251
833
- if (ts->gpiod_int && ts->gpiod_rst) {
1252
+ if (ts->load_cfg_from_disk) {
8341253 /* update device config */
8351254 ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,
836
- "goodix_%d_cfg.bin", ts->id);
1255
+ "goodix_%s_cfg.bin", ts->id);
8371256 if (!ts->cfg_name)
8381257 return -ENOMEM;
8391258
....@@ -861,7 +1280,7 @@
8611280 {
8621281 struct goodix_ts_data *ts = i2c_get_clientdata(client);
8631282
864
- if (ts->gpiod_int && ts->gpiod_rst)
1283
+ if (ts->load_cfg_from_disk)
8651284 wait_for_completion(&ts->firmware_loading_complete);
8661285
8671286 return 0;
....@@ -873,19 +1292,20 @@
8731292 struct goodix_ts_data *ts = i2c_get_clientdata(client);
8741293 int error;
8751294
1295
+ if (ts->load_cfg_from_disk)
1296
+ wait_for_completion(&ts->firmware_loading_complete);
1297
+
8761298 /* We need gpio pins to suspend/resume */
877
- if (!ts->gpiod_int || !ts->gpiod_rst) {
1299
+ if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
8781300 disable_irq(client->irq);
8791301 return 0;
8801302 }
881
-
882
- wait_for_completion(&ts->firmware_loading_complete);
8831303
8841304 /* Free IRQ as IRQ pin is used as output in the suspend sequence */
8851305 goodix_free_irq(ts);
8861306
8871307 /* Output LOW on the INT pin for 5 ms */
888
- error = gpiod_direction_output(ts->gpiod_int, 0);
1308
+ error = goodix_irq_direction_output(ts, 0);
8891309 if (error) {
8901310 goodix_request_irq(ts);
8911311 return error;
....@@ -897,7 +1317,7 @@
8971317 GOODIX_CMD_SCREEN_OFF);
8981318 if (error) {
8991319 dev_err(&ts->client->dev, "Screen off command failed\n");
900
- gpiod_direction_input(ts->gpiod_int);
1320
+ goodix_irq_direction_input(ts);
9011321 goodix_request_irq(ts);
9021322 return -EAGAIN;
9031323 }
....@@ -915,9 +1335,10 @@
9151335 {
9161336 struct i2c_client *client = to_i2c_client(dev);
9171337 struct goodix_ts_data *ts = i2c_get_clientdata(client);
1338
+ u8 config_ver;
9181339 int error;
9191340
920
- if (!ts->gpiod_int || !ts->gpiod_rst) {
1341
+ if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
9211342 enable_irq(client->irq);
9221343 return 0;
9231344 }
....@@ -926,7 +1347,7 @@
9261347 * Exit sleep mode by outputting HIGH level to INT pin
9271348 * for 2ms~5ms.
9281349 */
929
- error = gpiod_direction_output(ts->gpiod_int, 1);
1350
+ error = goodix_irq_direction_output(ts, 1);
9301351 if (error)
9311352 return error;
9321353
....@@ -935,6 +1356,27 @@
9351356 error = goodix_int_sync(ts);
9361357 if (error)
9371358 return error;
1359
+
1360
+ error = goodix_i2c_read(ts->client, ts->chip->config_addr,
1361
+ &config_ver, 1);
1362
+ if (error)
1363
+ dev_warn(dev, "Error reading config version: %d, resetting controller\n",
1364
+ error);
1365
+ else if (config_ver != ts->config[0])
1366
+ dev_info(dev, "Config version mismatch %d != %d, resetting controller\n",
1367
+ config_ver, ts->config[0]);
1368
+
1369
+ if (error != 0 || config_ver != ts->config[0]) {
1370
+ error = goodix_reset(ts);
1371
+ if (error) {
1372
+ dev_err(dev, "Controller reset failed.\n");
1373
+ return error;
1374
+ }
1375
+
1376
+ error = goodix_send_cfg(ts, ts->config, ts->chip->config_len);
1377
+ if (error)
1378
+ return error;
1379
+ }
9381380
9391381 error = goodix_request_irq(ts);
9401382 if (error)
....@@ -963,12 +1405,18 @@
9631405 #ifdef CONFIG_OF
9641406 static const struct of_device_id goodix_of_match[] = {
9651407 { .compatible = "goodix,gt1151" },
1408
+ { .compatible = "goodix,gt1158" },
1409
+ { .compatible = "goodix,gt5663" },
1410
+ { .compatible = "goodix,gt5688" },
9661411 { .compatible = "goodix,gt911" },
9671412 { .compatible = "goodix,gt9110" },
9681413 { .compatible = "goodix,gt912" },
1414
+ { .compatible = "goodix,gt9147" },
1415
+ { .compatible = "goodix,gt917s" },
9691416 { .compatible = "goodix,gt927" },
9701417 { .compatible = "goodix,gt9271" },
9711418 { .compatible = "goodix,gt928" },
1419
+ { .compatible = "goodix,gt9286" },
9721420 { .compatible = "goodix,gt967" },
9731421 { }
9741422 };