.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for Goodix Touchscreens |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * 2010 - 2012 Goodix Technology. |
---|
10 | 11 | */ |
---|
11 | 12 | |
---|
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 | | - */ |
---|
17 | 13 | |
---|
18 | 14 | #include <linux/kernel.h> |
---|
19 | 15 | #include <linux/dmi.h> |
---|
.. | .. |
---|
27 | 23 | #include <linux/delay.h> |
---|
28 | 24 | #include <linux/irq.h> |
---|
29 | 25 | #include <linux/interrupt.h> |
---|
| 26 | +#include <linux/regulator/consumer.h> |
---|
30 | 27 | #include <linux/slab.h> |
---|
31 | 28 | #include <linux/acpi.h> |
---|
32 | 29 | #include <linux/of.h> |
---|
33 | 30 | #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 | | -}; |
---|
58 | 31 | |
---|
59 | 32 | #define GOODIX_GPIO_INT_NAME "irq" |
---|
60 | 33 | #define GOODIX_GPIO_RST_NAME "reset" |
---|
.. | .. |
---|
63 | 36 | #define GOODIX_MAX_WIDTH 4096 |
---|
64 | 37 | #define GOODIX_INT_TRIGGER 1 |
---|
65 | 38 | #define GOODIX_CONTACT_SIZE 8 |
---|
| 39 | +#define GOODIX_MAX_CONTACT_SIZE 9 |
---|
66 | 40 | #define GOODIX_MAX_CONTACTS 10 |
---|
| 41 | +#define GOODIX_MAX_KEYS 7 |
---|
67 | 42 | |
---|
68 | | -#define GOODIX_CONFIG_MAX_LENGTH 240 |
---|
| 43 | +#define GOODIX_CONFIG_MIN_LENGTH 186 |
---|
69 | 44 | #define GOODIX_CONFIG_911_LENGTH 186 |
---|
70 | 45 | #define GOODIX_CONFIG_967_LENGTH 228 |
---|
| 46 | +#define GOODIX_CONFIG_GT9X_LENGTH 240 |
---|
| 47 | +#define GOODIX_CONFIG_MAX_LENGTH 240 |
---|
71 | 48 | |
---|
72 | 49 | /* Register defines */ |
---|
73 | 50 | #define GOODIX_REG_COMMAND 0x8040 |
---|
.. | .. |
---|
79 | 56 | #define GOODIX_REG_ID 0x8140 |
---|
80 | 57 | |
---|
81 | 58 | #define GOODIX_BUFFER_STATUS_READY BIT(7) |
---|
| 59 | +#define GOODIX_HAVE_KEY BIT(4) |
---|
82 | 60 | #define GOODIX_BUFFER_STATUS_TIMEOUT 20 |
---|
83 | 61 | |
---|
84 | 62 | #define RESOLUTION_LOC 1 |
---|
85 | 63 | #define MAX_CONTACTS_LOC 5 |
---|
86 | 64 | #define TRIGGER_LOC 6 |
---|
87 | 65 | |
---|
| 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 | + |
---|
88 | 120 | static int goodix_check_cfg_8(struct goodix_ts_data *ts, |
---|
89 | | - const struct firmware *cfg); |
---|
| 121 | + const u8 *cfg, int len); |
---|
90 | 122 | 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); |
---|
92 | 126 | |
---|
93 | 127 | static const struct goodix_chip_data gt1x_chip_data = { |
---|
94 | 128 | .config_addr = GOODIX_GT1X_REG_CONFIG_DATA, |
---|
95 | | - .config_len = GOODIX_CONFIG_MAX_LENGTH, |
---|
| 129 | + .config_len = GOODIX_CONFIG_GT9X_LENGTH, |
---|
96 | 130 | .check_config = goodix_check_cfg_16, |
---|
| 131 | + .calc_config_checksum = goodix_calc_cfg_checksum_16, |
---|
97 | 132 | }; |
---|
98 | 133 | |
---|
99 | 134 | static const struct goodix_chip_data gt911_chip_data = { |
---|
100 | 135 | .config_addr = GOODIX_GT9X_REG_CONFIG_DATA, |
---|
101 | 136 | .config_len = GOODIX_CONFIG_911_LENGTH, |
---|
102 | 137 | .check_config = goodix_check_cfg_8, |
---|
| 138 | + .calc_config_checksum = goodix_calc_cfg_checksum_8, |
---|
103 | 139 | }; |
---|
104 | 140 | |
---|
105 | 141 | static const struct goodix_chip_data gt967_chip_data = { |
---|
106 | 142 | .config_addr = GOODIX_GT9X_REG_CONFIG_DATA, |
---|
107 | 143 | .config_len = GOODIX_CONFIG_967_LENGTH, |
---|
108 | 144 | .check_config = goodix_check_cfg_8, |
---|
| 145 | + .calc_config_checksum = goodix_calc_cfg_checksum_8, |
---|
109 | 146 | }; |
---|
110 | 147 | |
---|
111 | 148 | static const struct goodix_chip_data gt9x_chip_data = { |
---|
112 | 149 | .config_addr = GOODIX_GT9X_REG_CONFIG_DATA, |
---|
113 | | - .config_len = GOODIX_CONFIG_MAX_LENGTH, |
---|
| 150 | + .config_len = GOODIX_CONFIG_GT9X_LENGTH, |
---|
114 | 151 | .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 = >1x_chip_data }, |
---|
| 157 | + { .id = "1158", .data = >1x_chip_data }, |
---|
| 158 | + { .id = "5663", .data = >1x_chip_data }, |
---|
| 159 | + { .id = "5688", .data = >1x_chip_data }, |
---|
| 160 | + { .id = "917S", .data = >1x_chip_data }, |
---|
| 161 | + { .id = "9286", .data = >1x_chip_data }, |
---|
| 162 | + |
---|
| 163 | + { .id = "911", .data = >911_chip_data }, |
---|
| 164 | + { .id = "9271", .data = >911_chip_data }, |
---|
| 165 | + { .id = "9110", .data = >911_chip_data }, |
---|
| 166 | + { .id = "9111", .data = >911_chip_data }, |
---|
| 167 | + { .id = "927", .data = >911_chip_data }, |
---|
| 168 | + { .id = "928", .data = >911_chip_data }, |
---|
| 169 | + |
---|
| 170 | + { .id = "912", .data = >967_chip_data }, |
---|
| 171 | + { .id = "9147", .data = >967_chip_data }, |
---|
| 172 | + { .id = "967", .data = >967_chip_data }, |
---|
| 173 | + { } |
---|
115 | 174 | }; |
---|
116 | 175 | |
---|
117 | 176 | static const unsigned long goodix_irq_flags[] = { |
---|
.. | .. |
---|
121 | 180 | IRQ_TYPE_LEVEL_HIGH, |
---|
122 | 181 | }; |
---|
123 | 182 | |
---|
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[] = { |
---|
129 | 184 | #if defined(CONFIG_DMI) && defined(CONFIG_X86) |
---|
130 | 185 | { |
---|
131 | | - .ident = "Teclast X89", |
---|
| 186 | + /* Lenovo Yoga Book X90F / X90L */ |
---|
132 | 187 | .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"), |
---|
156 | 191 | } |
---|
157 | 192 | }, |
---|
158 | 193 | { |
---|
159 | | - .ident = "WinBook TW700", |
---|
| 194 | + /* Lenovo Yoga Book X91F / X91L */ |
---|
160 | 195 | .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") |
---|
163 | 214 | }, |
---|
164 | 215 | }, |
---|
165 | 216 | #endif |
---|
.. | .. |
---|
233 | 284 | return goodix_i2c_write(client, reg, &value, sizeof(value)); |
---|
234 | 285 | } |
---|
235 | 286 | |
---|
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) |
---|
237 | 288 | { |
---|
238 | | - switch (id) { |
---|
239 | | - case 1151: |
---|
240 | | - return >1x_chip_data; |
---|
| 289 | + unsigned int i; |
---|
241 | 290 | |
---|
242 | | - case 911: |
---|
243 | | - case 9271: |
---|
244 | | - case 9110: |
---|
245 | | - case 927: |
---|
246 | | - case 928: |
---|
247 | | - return >911_chip_data; |
---|
248 | | - |
---|
249 | | - case 912: |
---|
250 | | - case 967: |
---|
251 | | - return >967_chip_data; |
---|
252 | | - |
---|
253 | | - default: |
---|
254 | | - return >9x_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; |
---|
255 | 294 | } |
---|
| 295 | + |
---|
| 296 | + return >9x_chip_data; |
---|
256 | 297 | } |
---|
257 | 298 | |
---|
258 | 299 | static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) |
---|
.. | .. |
---|
260 | 301 | unsigned long max_timeout; |
---|
261 | 302 | int touch_num; |
---|
262 | 303 | 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; |
---|
263 | 311 | |
---|
264 | 312 | /* |
---|
265 | 313 | * The 'buffer status' bit, which indicates that the data is valid, is |
---|
.. | .. |
---|
268 | 316 | */ |
---|
269 | 317 | max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT); |
---|
270 | 318 | 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); |
---|
273 | 321 | if (error) { |
---|
274 | 322 | dev_err(&ts->client->dev, "I2C transfer error: %d\n", |
---|
275 | 323 | error); |
---|
.. | .. |
---|
282 | 330 | return -EPROTO; |
---|
283 | 331 | |
---|
284 | 332 | if (touch_num > 1) { |
---|
285 | | - data += 1 + GOODIX_CONTACT_SIZE; |
---|
| 333 | + addr += header_contact_keycode_size; |
---|
| 334 | + data += header_contact_keycode_size; |
---|
286 | 335 | 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 * |
---|
291 | 338 | (touch_num - 1)); |
---|
292 | 339 | if (error) |
---|
293 | 340 | return error; |
---|
.. | .. |
---|
303 | 350 | * The Goodix panel will send spurious interrupts after a |
---|
304 | 351 | * 'finger up' event, which will always cause a timeout. |
---|
305 | 352 | */ |
---|
306 | | - return 0; |
---|
| 353 | + return -ENOMSG; |
---|
307 | 354 | } |
---|
308 | 355 | |
---|
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) |
---|
310 | 357 | { |
---|
311 | 358 | int id = coor_data[0] & 0x0F; |
---|
312 | 359 | int input_x = get_unaligned_le16(&coor_data[1]); |
---|
.. | .. |
---|
321 | 368 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); |
---|
322 | 369 | } |
---|
323 | 370 | |
---|
| 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 | + |
---|
324 | 405 | /** |
---|
325 | 406 | * goodix_process_events - Process incoming events |
---|
326 | 407 | * |
---|
.. | .. |
---|
331 | 412 | */ |
---|
332 | 413 | static void goodix_process_events(struct goodix_ts_data *ts) |
---|
333 | 414 | { |
---|
334 | | - u8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; |
---|
| 415 | + u8 point_data[2 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; |
---|
335 | 416 | int touch_num; |
---|
336 | 417 | int i; |
---|
337 | 418 | |
---|
.. | .. |
---|
339 | 420 | if (touch_num < 0) |
---|
340 | 421 | return; |
---|
341 | 422 | |
---|
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); |
---|
347 | 424 | |
---|
348 | 425 | 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]); |
---|
351 | 432 | |
---|
352 | 433 | input_mt_sync_frame(ts->input_dev); |
---|
353 | 434 | input_sync(ts->input_dev); |
---|
.. | .. |
---|
383 | 464 | ts->irq_flags, ts->client->name, ts); |
---|
384 | 465 | } |
---|
385 | 466 | |
---|
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) |
---|
388 | 468 | { |
---|
389 | | - int i, raw_cfg_len = cfg->size - 2; |
---|
| 469 | + int i, raw_cfg_len = len - 2; |
---|
390 | 470 | u8 check_sum = 0; |
---|
391 | 471 | |
---|
392 | 472 | for (i = 0; i < raw_cfg_len; i++) |
---|
393 | | - check_sum += cfg->data[i]; |
---|
| 473 | + check_sum += cfg[i]; |
---|
394 | 474 | check_sum = (~check_sum) + 1; |
---|
395 | | - if (check_sum != cfg->data[raw_cfg_len]) { |
---|
| 475 | + if (check_sum != cfg[raw_cfg_len]) { |
---|
396 | 476 | dev_err(&ts->client->dev, |
---|
397 | 477 | "The checksum of the config fw is not correct"); |
---|
398 | 478 | return -EINVAL; |
---|
399 | 479 | } |
---|
400 | 480 | |
---|
401 | | - if (cfg->data[raw_cfg_len + 1] != 1) { |
---|
| 481 | + if (cfg[raw_cfg_len + 1] != 1) { |
---|
402 | 482 | dev_err(&ts->client->dev, |
---|
403 | 483 | "Config fw must have Config_Fresh register set"); |
---|
404 | 484 | return -EINVAL; |
---|
.. | .. |
---|
407 | 487 | return 0; |
---|
408 | 488 | } |
---|
409 | 489 | |
---|
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) |
---|
412 | 491 | { |
---|
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; |
---|
414 | 507 | u16 check_sum = 0; |
---|
415 | 508 | |
---|
416 | 509 | 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]); |
---|
418 | 511 | 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])) { |
---|
420 | 513 | dev_err(&ts->client->dev, |
---|
421 | 514 | "The checksum of the config fw is not correct"); |
---|
422 | 515 | return -EINVAL; |
---|
423 | 516 | } |
---|
424 | 517 | |
---|
425 | | - if (cfg->data[raw_cfg_len + 2] != 1) { |
---|
| 518 | + if (cfg[raw_cfg_len + 2] != 1) { |
---|
426 | 519 | dev_err(&ts->client->dev, |
---|
427 | 520 | "Config fw must have Config_Fresh register set"); |
---|
428 | 521 | return -EINVAL; |
---|
429 | 522 | } |
---|
430 | 523 | |
---|
431 | 524 | 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 */ |
---|
432 | 538 | } |
---|
433 | 539 | |
---|
434 | 540 | /** |
---|
.. | .. |
---|
437 | 543 | * @ts: goodix_ts_data pointer |
---|
438 | 544 | * @cfg: firmware config data |
---|
439 | 545 | */ |
---|
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) |
---|
442 | 547 | { |
---|
443 | | - if (cfg->size > GOODIX_CONFIG_MAX_LENGTH) { |
---|
| 548 | + if (len < GOODIX_CONFIG_MIN_LENGTH || |
---|
| 549 | + len > GOODIX_CONFIG_MAX_LENGTH) { |
---|
444 | 550 | dev_err(&ts->client->dev, |
---|
445 | 551 | "The length of the config fw is not correct"); |
---|
446 | 552 | return -EINVAL; |
---|
447 | 553 | } |
---|
448 | 554 | |
---|
449 | | - return ts->chip->check_config(ts, cfg); |
---|
| 555 | + return ts->chip->check_config(ts, cfg, len); |
---|
450 | 556 | } |
---|
451 | 557 | |
---|
452 | 558 | /** |
---|
.. | .. |
---|
455 | 561 | * @ts: goodix_ts_data pointer |
---|
456 | 562 | * @cfg: config firmware to write to device |
---|
457 | 563 | */ |
---|
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) |
---|
460 | 565 | { |
---|
461 | 566 | int error; |
---|
462 | 567 | |
---|
463 | | - error = goodix_check_cfg(ts, cfg); |
---|
| 568 | + error = goodix_check_cfg(ts, cfg, len); |
---|
464 | 569 | if (error) |
---|
465 | 570 | return error; |
---|
466 | 571 | |
---|
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); |
---|
469 | 573 | if (error) { |
---|
470 | 574 | dev_err(&ts->client->dev, "Failed to write config data: %d", |
---|
471 | 575 | error); |
---|
.. | .. |
---|
479 | 583 | return 0; |
---|
480 | 584 | } |
---|
481 | 585 | |
---|
| 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 | + |
---|
482 | 662 | static int goodix_int_sync(struct goodix_ts_data *ts) |
---|
483 | 663 | { |
---|
484 | 664 | int error; |
---|
485 | 665 | |
---|
486 | | - error = gpiod_direction_output(ts->gpiod_int, 0); |
---|
| 666 | + error = goodix_irq_direction_output(ts, 0); |
---|
487 | 667 | if (error) |
---|
488 | 668 | return error; |
---|
489 | 669 | |
---|
490 | 670 | msleep(50); /* T5: 50ms */ |
---|
491 | 671 | |
---|
492 | | - error = gpiod_direction_input(ts->gpiod_int); |
---|
| 672 | + error = goodix_irq_direction_input(ts); |
---|
493 | 673 | if (error) |
---|
494 | 674 | return error; |
---|
495 | 675 | |
---|
.. | .. |
---|
513 | 693 | msleep(20); /* T2: > 10ms */ |
---|
514 | 694 | |
---|
515 | 695 | /* 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); |
---|
517 | 697 | if (error) |
---|
518 | 698 | return error; |
---|
519 | 699 | |
---|
.. | .. |
---|
537 | 717 | return 0; |
---|
538 | 718 | } |
---|
539 | 719 | |
---|
| 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 | + |
---|
540 | 838 | /** |
---|
541 | 839 | * goodix_get_gpio_config - Get GPIO config from ACPI/DT |
---|
542 | 840 | * |
---|
.. | .. |
---|
547 | 845 | int error; |
---|
548 | 846 | struct device *dev; |
---|
549 | 847 | struct gpio_desc *gpiod; |
---|
| 848 | + bool added_acpi_mappings = false; |
---|
550 | 849 | |
---|
551 | 850 | if (!ts->client) |
---|
552 | 851 | return -EINVAL; |
---|
553 | 852 | dev = &ts->client->dev; |
---|
554 | 853 | |
---|
| 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: |
---|
555 | 873 | /* Get the interrupt GPIO pin number */ |
---|
556 | 874 | gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME, GPIOD_IN); |
---|
557 | 875 | if (IS_ERR(gpiod)) { |
---|
.. | .. |
---|
560 | 878 | dev_dbg(dev, "Failed to get %s GPIO: %d\n", |
---|
561 | 879 | GOODIX_GPIO_INT_NAME, error); |
---|
562 | 880 | 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; |
---|
563 | 886 | } |
---|
564 | 887 | |
---|
565 | 888 | ts->gpiod_int = gpiod; |
---|
.. | .. |
---|
576 | 899 | |
---|
577 | 900 | ts->gpiod_rst = gpiod; |
---|
578 | 901 | |
---|
| 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 | + |
---|
579 | 927 | return 0; |
---|
580 | 928 | } |
---|
581 | 929 | |
---|
.. | .. |
---|
588 | 936 | */ |
---|
589 | 937 | static void goodix_read_config(struct goodix_ts_data *ts) |
---|
590 | 938 | { |
---|
591 | | - u8 config[GOODIX_CONFIG_MAX_LENGTH]; |
---|
592 | 939 | int x_max, y_max; |
---|
593 | 940 | int error; |
---|
594 | 941 | |
---|
595 | 942 | error = goodix_i2c_read(ts->client, ts->chip->config_addr, |
---|
596 | | - config, ts->chip->config_len); |
---|
| 943 | + ts->config, ts->chip->config_len); |
---|
597 | 944 | if (error) { |
---|
598 | 945 | dev_warn(&ts->client->dev, "Error reading config: %d\n", |
---|
599 | 946 | error); |
---|
.. | .. |
---|
602 | 949 | return; |
---|
603 | 950 | } |
---|
604 | 951 | |
---|
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; |
---|
607 | 954 | |
---|
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]); |
---|
610 | 957 | if (x_max && y_max) { |
---|
611 | 958 | input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1); |
---|
612 | 959 | input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1); |
---|
613 | 960 | } |
---|
| 961 | + |
---|
| 962 | + ts->chip->calc_config_checksum(ts); |
---|
614 | 963 | } |
---|
615 | 964 | |
---|
616 | 965 | /** |
---|
.. | .. |
---|
622 | 971 | { |
---|
623 | 972 | int error; |
---|
624 | 973 | u8 buf[6]; |
---|
625 | | - char id_str[5]; |
---|
| 974 | + char id_str[GOODIX_ID_MAX_LEN + 1]; |
---|
626 | 975 | |
---|
627 | 976 | error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf)); |
---|
628 | 977 | if (error) { |
---|
.. | .. |
---|
630 | 979 | return error; |
---|
631 | 980 | } |
---|
632 | 981 | |
---|
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); |
---|
637 | 985 | |
---|
638 | 986 | ts->version = get_unaligned_le16(&buf[4]); |
---|
639 | 987 | |
---|
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, |
---|
641 | 989 | ts->version); |
---|
642 | 990 | |
---|
643 | 991 | return 0; |
---|
.. | .. |
---|
681 | 1029 | static int goodix_configure_dev(struct goodix_ts_data *ts) |
---|
682 | 1030 | { |
---|
683 | 1031 | int error; |
---|
| 1032 | + int i; |
---|
684 | 1033 | |
---|
685 | 1034 | ts->int_trigger_type = GOODIX_INT_TRIGGER; |
---|
686 | 1035 | ts->max_touch_num = GOODIX_MAX_CONTACTS; |
---|
.. | .. |
---|
695 | 1044 | ts->input_dev->phys = "input/ts"; |
---|
696 | 1045 | ts->input_dev->id.bustype = BUS_I2C; |
---|
697 | 1046 | 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; |
---|
699 | 1049 | ts->input_dev->id.version = ts->version; |
---|
700 | 1050 | |
---|
| 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 | + |
---|
701 | 1055 | /* 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 | + } |
---|
703 | 1064 | |
---|
704 | 1065 | input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X); |
---|
705 | 1066 | input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y); |
---|
706 | 1067 | input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); |
---|
707 | 1068 | input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); |
---|
708 | 1069 | |
---|
| 1070 | +retry_read_config: |
---|
709 | 1071 | /* Read configuration and apply touchscreen parameters */ |
---|
710 | 1072 | goodix_read_config(ts); |
---|
711 | 1073 | |
---|
.. | .. |
---|
713 | 1075 | touchscreen_parse_properties(ts->input_dev, true, &ts->prop); |
---|
714 | 1076 | |
---|
715 | 1077 | 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); |
---|
717 | 1091 | ts->prop.max_x = GOODIX_MAX_WIDTH - 1; |
---|
718 | 1092 | ts->prop.max_y = GOODIX_MAX_HEIGHT - 1; |
---|
719 | 1093 | ts->max_touch_num = GOODIX_MAX_CONTACTS; |
---|
.. | .. |
---|
723 | 1097 | ABS_MT_POSITION_Y, ts->prop.max_y); |
---|
724 | 1098 | } |
---|
725 | 1099 | |
---|
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 | + |
---|
729 | 1103 | 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"); |
---|
731 | 1111 | } |
---|
732 | 1112 | |
---|
733 | 1113 | error = input_mt_init_slots(ts->input_dev, ts->max_touch_num, |
---|
.. | .. |
---|
770 | 1150 | |
---|
771 | 1151 | if (cfg) { |
---|
772 | 1152 | /* send device configuration to the firmware */ |
---|
773 | | - error = goodix_send_cfg(ts, cfg); |
---|
| 1153 | + error = goodix_send_cfg(ts, cfg->data, cfg->size); |
---|
774 | 1154 | if (error) |
---|
775 | 1155 | goto err_release_cfg; |
---|
776 | 1156 | } |
---|
.. | .. |
---|
780 | 1160 | err_release_cfg: |
---|
781 | 1161 | release_firmware(cfg); |
---|
782 | 1162 | 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); |
---|
783 | 1171 | } |
---|
784 | 1172 | |
---|
785 | 1173 | static int goodix_ts_probe(struct i2c_client *client, |
---|
.. | .. |
---|
802 | 1190 | ts->client = client; |
---|
803 | 1191 | i2c_set_clientdata(client, ts); |
---|
804 | 1192 | init_completion(&ts->firmware_loading_complete); |
---|
| 1193 | + ts->contact_size = GOODIX_CONTACT_SIZE; |
---|
805 | 1194 | |
---|
806 | 1195 | error = goodix_get_gpio_config(ts); |
---|
807 | 1196 | if (error) |
---|
808 | 1197 | return error; |
---|
809 | 1198 | |
---|
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) { |
---|
811 | 1224 | /* reset the controller */ |
---|
812 | 1225 | error = goodix_reset(ts); |
---|
813 | 1226 | if (error) { |
---|
.. | .. |
---|
818 | 1231 | |
---|
819 | 1232 | error = goodix_i2c_test(client); |
---|
820 | 1233 | 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 | + } |
---|
821 | 1240 | dev_err(&client->dev, "I2C communication failure: %d\n", error); |
---|
822 | 1241 | return error; |
---|
823 | 1242 | } |
---|
.. | .. |
---|
830 | 1249 | |
---|
831 | 1250 | ts->chip = goodix_get_chip_data(ts->id); |
---|
832 | 1251 | |
---|
833 | | - if (ts->gpiod_int && ts->gpiod_rst) { |
---|
| 1252 | + if (ts->load_cfg_from_disk) { |
---|
834 | 1253 | /* update device config */ |
---|
835 | 1254 | ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL, |
---|
836 | | - "goodix_%d_cfg.bin", ts->id); |
---|
| 1255 | + "goodix_%s_cfg.bin", ts->id); |
---|
837 | 1256 | if (!ts->cfg_name) |
---|
838 | 1257 | return -ENOMEM; |
---|
839 | 1258 | |
---|
.. | .. |
---|
861 | 1280 | { |
---|
862 | 1281 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
---|
863 | 1282 | |
---|
864 | | - if (ts->gpiod_int && ts->gpiod_rst) |
---|
| 1283 | + if (ts->load_cfg_from_disk) |
---|
865 | 1284 | wait_for_completion(&ts->firmware_loading_complete); |
---|
866 | 1285 | |
---|
867 | 1286 | return 0; |
---|
.. | .. |
---|
873 | 1292 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
---|
874 | 1293 | int error; |
---|
875 | 1294 | |
---|
| 1295 | + if (ts->load_cfg_from_disk) |
---|
| 1296 | + wait_for_completion(&ts->firmware_loading_complete); |
---|
| 1297 | + |
---|
876 | 1298 | /* 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) { |
---|
878 | 1300 | disable_irq(client->irq); |
---|
879 | 1301 | return 0; |
---|
880 | 1302 | } |
---|
881 | | - |
---|
882 | | - wait_for_completion(&ts->firmware_loading_complete); |
---|
883 | 1303 | |
---|
884 | 1304 | /* Free IRQ as IRQ pin is used as output in the suspend sequence */ |
---|
885 | 1305 | goodix_free_irq(ts); |
---|
886 | 1306 | |
---|
887 | 1307 | /* 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); |
---|
889 | 1309 | if (error) { |
---|
890 | 1310 | goodix_request_irq(ts); |
---|
891 | 1311 | return error; |
---|
.. | .. |
---|
897 | 1317 | GOODIX_CMD_SCREEN_OFF); |
---|
898 | 1318 | if (error) { |
---|
899 | 1319 | dev_err(&ts->client->dev, "Screen off command failed\n"); |
---|
900 | | - gpiod_direction_input(ts->gpiod_int); |
---|
| 1320 | + goodix_irq_direction_input(ts); |
---|
901 | 1321 | goodix_request_irq(ts); |
---|
902 | 1322 | return -EAGAIN; |
---|
903 | 1323 | } |
---|
.. | .. |
---|
915 | 1335 | { |
---|
916 | 1336 | struct i2c_client *client = to_i2c_client(dev); |
---|
917 | 1337 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
---|
| 1338 | + u8 config_ver; |
---|
918 | 1339 | int error; |
---|
919 | 1340 | |
---|
920 | | - if (!ts->gpiod_int || !ts->gpiod_rst) { |
---|
| 1341 | + if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) { |
---|
921 | 1342 | enable_irq(client->irq); |
---|
922 | 1343 | return 0; |
---|
923 | 1344 | } |
---|
.. | .. |
---|
926 | 1347 | * Exit sleep mode by outputting HIGH level to INT pin |
---|
927 | 1348 | * for 2ms~5ms. |
---|
928 | 1349 | */ |
---|
929 | | - error = gpiod_direction_output(ts->gpiod_int, 1); |
---|
| 1350 | + error = goodix_irq_direction_output(ts, 1); |
---|
930 | 1351 | if (error) |
---|
931 | 1352 | return error; |
---|
932 | 1353 | |
---|
.. | .. |
---|
935 | 1356 | error = goodix_int_sync(ts); |
---|
936 | 1357 | if (error) |
---|
937 | 1358 | 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 | + } |
---|
938 | 1380 | |
---|
939 | 1381 | error = goodix_request_irq(ts); |
---|
940 | 1382 | if (error) |
---|
.. | .. |
---|
963 | 1405 | #ifdef CONFIG_OF |
---|
964 | 1406 | static const struct of_device_id goodix_of_match[] = { |
---|
965 | 1407 | { .compatible = "goodix,gt1151" }, |
---|
| 1408 | + { .compatible = "goodix,gt1158" }, |
---|
| 1409 | + { .compatible = "goodix,gt5663" }, |
---|
| 1410 | + { .compatible = "goodix,gt5688" }, |
---|
966 | 1411 | { .compatible = "goodix,gt911" }, |
---|
967 | 1412 | { .compatible = "goodix,gt9110" }, |
---|
968 | 1413 | { .compatible = "goodix,gt912" }, |
---|
| 1414 | + { .compatible = "goodix,gt9147" }, |
---|
| 1415 | + { .compatible = "goodix,gt917s" }, |
---|
969 | 1416 | { .compatible = "goodix,gt927" }, |
---|
970 | 1417 | { .compatible = "goodix,gt9271" }, |
---|
971 | 1418 | { .compatible = "goodix,gt928" }, |
---|
| 1419 | + { .compatible = "goodix,gt9286" }, |
---|
972 | 1420 | { .compatible = "goodix,gt967" }, |
---|
973 | 1421 | { } |
---|
974 | 1422 | }; |
---|