2 * Driver for Goodix Touchscreens
4 * Copyright (c) 2014 Red Hat Inc.
9 * 2010 - 2012 Goodix Technology.
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.
18 #include <linux/kernel.h>
19 #include <linux/dmi.h>
20 #include <linux/firmware.h>
21 #include <linux/gpio/consumer.h>
22 #include <linux/i2c.h>
23 #include <linux/input.h>
24 #include <linux/input/mt.h>
25 #include <linux/input/touchscreen.h>
26 #include <linux/module.h>
27 #include <linux/delay.h>
28 #include <linux/irq.h>
29 #include <linux/interrupt.h>
30 #include <linux/regulator/consumer.h>
31 #include <linux/slab.h>
32 #include <linux/acpi.h>
34 #include <asm/unaligned.h>
36 struct goodix_ts_data;
38 struct goodix_chip_data {
41 int (*check_config)(struct goodix_ts_data *, const struct firmware *);
44 struct goodix_ts_data {
45 struct i2c_client *client;
46 struct input_dev *input_dev;
47 const struct goodix_chip_data *chip;
48 struct touchscreen_properties prop;
49 unsigned int max_touch_num;
50 unsigned int int_trigger_type;
51 struct regulator *avdd28;
52 struct regulator *vddio;
53 struct gpio_desc *gpiod_int;
54 struct gpio_desc *gpiod_rst;
58 struct completion firmware_loading_complete;
59 unsigned long irq_flags;
62 #define GOODIX_GPIO_INT_NAME "irq"
63 #define GOODIX_GPIO_RST_NAME "reset"
65 #define GOODIX_MAX_HEIGHT 4096
66 #define GOODIX_MAX_WIDTH 4096
67 #define GOODIX_INT_TRIGGER 1
68 #define GOODIX_CONTACT_SIZE 8
69 #define GOODIX_MAX_CONTACTS 10
71 #define GOODIX_CONFIG_MAX_LENGTH 240
72 #define GOODIX_CONFIG_911_LENGTH 186
73 #define GOODIX_CONFIG_967_LENGTH 228
75 /* Register defines */
76 #define GOODIX_REG_COMMAND 0x8040
77 #define GOODIX_CMD_SCREEN_OFF 0x05
79 #define GOODIX_READ_COOR_ADDR 0x814E
80 #define GOODIX_GT1X_REG_CONFIG_DATA 0x8050
81 #define GOODIX_GT9X_REG_CONFIG_DATA 0x8047
82 #define GOODIX_REG_ID 0x8140
84 #define GOODIX_BUFFER_STATUS_READY BIT(7)
85 #define GOODIX_BUFFER_STATUS_TIMEOUT 20
87 #define RESOLUTION_LOC 1
88 #define MAX_CONTACTS_LOC 5
91 static int goodix_check_cfg_8(struct goodix_ts_data *ts,
92 const struct firmware *cfg);
93 static int goodix_check_cfg_16(struct goodix_ts_data *ts,
94 const struct firmware *cfg);
96 static const struct goodix_chip_data gt1x_chip_data = {
97 .config_addr = GOODIX_GT1X_REG_CONFIG_DATA,
98 .config_len = GOODIX_CONFIG_MAX_LENGTH,
99 .check_config = goodix_check_cfg_16,
102 static const struct goodix_chip_data gt911_chip_data = {
103 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
104 .config_len = GOODIX_CONFIG_911_LENGTH,
105 .check_config = goodix_check_cfg_8,
108 static const struct goodix_chip_data gt967_chip_data = {
109 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
110 .config_len = GOODIX_CONFIG_967_LENGTH,
111 .check_config = goodix_check_cfg_8,
114 static const struct goodix_chip_data gt9x_chip_data = {
115 .config_addr = GOODIX_GT9X_REG_CONFIG_DATA,
116 .config_len = GOODIX_CONFIG_MAX_LENGTH,
117 .check_config = goodix_check_cfg_8,
120 static const unsigned long goodix_irq_flags[] = {
121 IRQ_TYPE_EDGE_RISING,
122 IRQ_TYPE_EDGE_FALLING,
128 * Those tablets have their coordinates origin at the bottom right
129 * of the tablet, as if rotated 180 degrees
131 static const struct dmi_system_id rotated_screen[] = {
132 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
134 .ident = "WinBook TW100",
136 DMI_MATCH(DMI_SYS_VENDOR, "WinBook"),
137 DMI_MATCH(DMI_PRODUCT_NAME, "TW100")
141 .ident = "WinBook TW700",
143 DMI_MATCH(DMI_SYS_VENDOR, "WinBook"),
144 DMI_MATCH(DMI_PRODUCT_NAME, "TW700")
152 * goodix_i2c_read - read data from a register of the i2c slave device.
154 * @client: i2c device.
155 * @reg: the register to read from.
156 * @buf: raw write data buffer.
157 * @len: length of the buffer to write
159 static int goodix_i2c_read(struct i2c_client *client,
160 u16 reg, u8 *buf, int len)
162 struct i2c_msg msgs[2];
163 __be16 wbuf = cpu_to_be16(reg);
167 msgs[0].addr = client->addr;
169 msgs[0].buf = (u8 *)&wbuf;
171 msgs[1].flags = I2C_M_RD;
172 msgs[1].addr = client->addr;
176 ret = i2c_transfer(client->adapter, msgs, 2);
177 return ret < 0 ? ret : (ret != ARRAY_SIZE(msgs) ? -EIO : 0);
181 * goodix_i2c_write - write data to a register of the i2c slave device.
183 * @client: i2c device.
184 * @reg: the register to write to.
185 * @buf: raw data buffer to write.
186 * @len: length of the buffer to write
188 static int goodix_i2c_write(struct i2c_client *client, u16 reg, const u8 *buf,
195 addr_buf = kmalloc(len + 2, GFP_KERNEL);
199 addr_buf[0] = reg >> 8;
200 addr_buf[1] = reg & 0xFF;
201 memcpy(&addr_buf[2], buf, len);
204 msg.addr = client->addr;
208 ret = i2c_transfer(client->adapter, &msg, 1);
210 return ret < 0 ? ret : (ret != 1 ? -EIO : 0);
213 static int goodix_i2c_write_u8(struct i2c_client *client, u16 reg, u8 value)
215 return goodix_i2c_write(client, reg, &value, sizeof(value));
218 static const struct goodix_chip_data *goodix_get_chip_data(u16 id)
224 return >1x_chip_data;
231 return >911_chip_data;
235 return >967_chip_data;
238 return >9x_chip_data;
242 static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data)
244 unsigned long max_timeout;
249 * The 'buffer status' bit, which indicates that the data is valid, is
250 * not set as soon as the interrupt is raised, but slightly after.
251 * This takes around 10 ms to happen, so we poll for 20 ms.
253 max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT);
255 error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR,
256 data, GOODIX_CONTACT_SIZE + 1);
258 dev_err(&ts->client->dev, "I2C transfer error: %d\n",
263 if (data[0] & GOODIX_BUFFER_STATUS_READY) {
264 touch_num = data[0] & 0x0f;
265 if (touch_num > ts->max_touch_num)
269 data += 1 + GOODIX_CONTACT_SIZE;
270 error = goodix_i2c_read(ts->client,
271 GOODIX_READ_COOR_ADDR +
272 1 + GOODIX_CONTACT_SIZE,
274 GOODIX_CONTACT_SIZE *
283 usleep_range(1000, 2000); /* Poll every 1 - 2 ms */
284 } while (time_before(jiffies, max_timeout));
287 * The Goodix panel will send spurious interrupts after a
288 * 'finger up' event, which will always cause a timeout.
293 static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data)
295 int id = coor_data[0] & 0x0F;
296 int input_x = get_unaligned_le16(&coor_data[1]);
297 int input_y = get_unaligned_le16(&coor_data[3]);
298 int input_w = get_unaligned_le16(&coor_data[5]);
300 input_mt_slot(ts->input_dev, id);
301 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
302 touchscreen_report_pos(ts->input_dev, &ts->prop,
303 input_x, input_y, true);
304 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);
305 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w);
309 * goodix_process_events - Process incoming events
311 * @ts: our goodix_ts_data pointer
313 * Called when the IRQ is triggered. Read the current device state, and push
314 * the input events to the user space.
316 static void goodix_process_events(struct goodix_ts_data *ts)
318 u8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS];
322 touch_num = goodix_ts_read_input_report(ts, point_data);
327 * Bit 4 of the first byte reports the status of the capacitive
328 * Windows/Home button.
330 input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4));
332 for (i = 0; i < touch_num; i++)
333 goodix_ts_report_touch(ts,
334 &point_data[1 + GOODIX_CONTACT_SIZE * i]);
336 input_mt_sync_frame(ts->input_dev);
337 input_sync(ts->input_dev);
341 * goodix_ts_irq_handler - The IRQ handler
343 * @irq: interrupt number.
344 * @dev_id: private data pointer.
346 static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
348 struct goodix_ts_data *ts = dev_id;
350 goodix_process_events(ts);
352 if (goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0) < 0)
353 dev_err(&ts->client->dev, "I2C write end_cmd error\n");
358 static void goodix_free_irq(struct goodix_ts_data *ts)
360 devm_free_irq(&ts->client->dev, ts->client->irq, ts);
363 static int goodix_request_irq(struct goodix_ts_data *ts)
365 return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
366 NULL, goodix_ts_irq_handler,
367 ts->irq_flags, ts->client->name, ts);
370 static int goodix_check_cfg_8(struct goodix_ts_data *ts,
371 const struct firmware *cfg)
373 int i, raw_cfg_len = cfg->size - 2;
376 for (i = 0; i < raw_cfg_len; i++)
377 check_sum += cfg->data[i];
378 check_sum = (~check_sum) + 1;
379 if (check_sum != cfg->data[raw_cfg_len]) {
380 dev_err(&ts->client->dev,
381 "The checksum of the config fw is not correct");
385 if (cfg->data[raw_cfg_len + 1] != 1) {
386 dev_err(&ts->client->dev,
387 "Config fw must have Config_Fresh register set");
394 static int goodix_check_cfg_16(struct goodix_ts_data *ts,
395 const struct firmware *cfg)
397 int i, raw_cfg_len = cfg->size - 3;
400 for (i = 0; i < raw_cfg_len; i += 2)
401 check_sum += get_unaligned_be16(&cfg->data[i]);
402 check_sum = (~check_sum) + 1;
403 if (check_sum != get_unaligned_be16(&cfg->data[raw_cfg_len])) {
404 dev_err(&ts->client->dev,
405 "The checksum of the config fw is not correct");
409 if (cfg->data[raw_cfg_len + 2] != 1) {
410 dev_err(&ts->client->dev,
411 "Config fw must have Config_Fresh register set");
419 * goodix_check_cfg - Checks if config fw is valid
421 * @ts: goodix_ts_data pointer
422 * @cfg: firmware config data
424 static int goodix_check_cfg(struct goodix_ts_data *ts,
425 const struct firmware *cfg)
427 if (cfg->size > GOODIX_CONFIG_MAX_LENGTH) {
428 dev_err(&ts->client->dev,
429 "The length of the config fw is not correct");
433 return ts->chip->check_config(ts, cfg);
437 * goodix_send_cfg - Write fw config to device
439 * @ts: goodix_ts_data pointer
440 * @cfg: config firmware to write to device
442 static int goodix_send_cfg(struct goodix_ts_data *ts,
443 const struct firmware *cfg)
447 error = goodix_check_cfg(ts, cfg);
451 error = goodix_i2c_write(ts->client, ts->chip->config_addr, cfg->data,
454 dev_err(&ts->client->dev, "Failed to write config data: %d",
458 dev_dbg(&ts->client->dev, "Config sent successfully.");
460 /* Let the firmware reconfigure itself, so sleep for 10ms */
461 usleep_range(10000, 11000);
466 static int goodix_int_sync(struct goodix_ts_data *ts)
470 error = gpiod_direction_output(ts->gpiod_int, 0);
474 msleep(50); /* T5: 50ms */
476 error = gpiod_direction_input(ts->gpiod_int);
484 * goodix_reset - Reset device during power on
486 * @ts: goodix_ts_data pointer
488 static int goodix_reset(struct goodix_ts_data *ts)
492 /* begin select I2C slave addr */
493 error = gpiod_direction_output(ts->gpiod_rst, 0);
497 msleep(20); /* T2: > 10ms */
499 /* HIGH: 0x28/0x29, LOW: 0xBA/0xBB */
500 error = gpiod_direction_output(ts->gpiod_int, ts->client->addr == 0x14);
504 usleep_range(100, 2000); /* T3: > 100us */
506 error = gpiod_direction_output(ts->gpiod_rst, 1);
510 usleep_range(6000, 10000); /* T4: > 5ms */
512 /* end select I2C slave addr */
513 error = gpiod_direction_input(ts->gpiod_rst);
517 error = goodix_int_sync(ts);
525 * goodix_get_gpio_config - Get GPIO config from ACPI/DT
527 * @ts: goodix_ts_data pointer
529 static int goodix_get_gpio_config(struct goodix_ts_data *ts)
533 struct gpio_desc *gpiod;
537 dev = &ts->client->dev;
539 ts->avdd28 = devm_regulator_get(dev, "AVDD28");
540 if (IS_ERR(ts->avdd28)) {
541 error = PTR_ERR(ts->avdd28);
542 if (error != -EPROBE_DEFER)
544 "Failed to get AVDD28 regulator: %d\n", error);
548 ts->vddio = devm_regulator_get(dev, "VDDIO");
549 if (IS_ERR(ts->vddio)) {
550 error = PTR_ERR(ts->vddio);
551 if (error != -EPROBE_DEFER)
553 "Failed to get VDDIO regulator: %d\n", error);
557 /* Get the interrupt GPIO pin number */
558 gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_INT_NAME, GPIOD_IN);
560 error = PTR_ERR(gpiod);
561 if (error != -EPROBE_DEFER)
562 dev_dbg(dev, "Failed to get %s GPIO: %d\n",
563 GOODIX_GPIO_INT_NAME, error);
567 ts->gpiod_int = gpiod;
569 /* Get the reset line GPIO pin number */
570 gpiod = devm_gpiod_get_optional(dev, GOODIX_GPIO_RST_NAME, GPIOD_IN);
572 error = PTR_ERR(gpiod);
573 if (error != -EPROBE_DEFER)
574 dev_dbg(dev, "Failed to get %s GPIO: %d\n",
575 GOODIX_GPIO_RST_NAME, error);
579 ts->gpiod_rst = gpiod;
585 * goodix_read_config - Read the embedded configuration of the panel
587 * @ts: our goodix_ts_data pointer
589 * Must be called during probe
591 static void goodix_read_config(struct goodix_ts_data *ts)
593 u8 config[GOODIX_CONFIG_MAX_LENGTH];
597 error = goodix_i2c_read(ts->client, ts->chip->config_addr,
598 config, ts->chip->config_len);
600 dev_warn(&ts->client->dev, "Error reading config: %d\n",
602 ts->int_trigger_type = GOODIX_INT_TRIGGER;
603 ts->max_touch_num = GOODIX_MAX_CONTACTS;
607 ts->int_trigger_type = config[TRIGGER_LOC] & 0x03;
608 ts->max_touch_num = config[MAX_CONTACTS_LOC] & 0x0f;
610 x_max = get_unaligned_le16(&config[RESOLUTION_LOC]);
611 y_max = get_unaligned_le16(&config[RESOLUTION_LOC + 2]);
612 if (x_max && y_max) {
613 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_X, x_max - 1);
614 input_abs_set_max(ts->input_dev, ABS_MT_POSITION_Y, y_max - 1);
619 * goodix_read_version - Read goodix touchscreen version
621 * @ts: our goodix_ts_data pointer
623 static int goodix_read_version(struct goodix_ts_data *ts)
629 error = goodix_i2c_read(ts->client, GOODIX_REG_ID, buf, sizeof(buf));
631 dev_err(&ts->client->dev, "read version failed: %d\n", error);
635 memcpy(id_str, buf, 4);
637 if (kstrtou16(id_str, 10, &ts->id))
640 ts->version = get_unaligned_le16(&buf[4]);
642 dev_info(&ts->client->dev, "ID %d, version: %04x\n", ts->id,
649 * goodix_i2c_test - I2C test function to check if the device answers.
651 * @client: the i2c client
653 static int goodix_i2c_test(struct i2c_client *client)
659 while (retry++ < 2) {
660 error = goodix_i2c_read(client, GOODIX_REG_ID,
665 dev_err(&client->dev, "i2c test failed attempt %d: %d\n",
674 * goodix_configure_dev - Finish device initialization
676 * @ts: our goodix_ts_data pointer
678 * Must be called from probe to finish initialization of the device.
679 * Contains the common initialization code for both devices that
680 * declare gpio pins and devices that do not. It is either called
681 * directly from probe or from request_firmware_wait callback.
683 static int goodix_configure_dev(struct goodix_ts_data *ts)
687 ts->int_trigger_type = GOODIX_INT_TRIGGER;
688 ts->max_touch_num = GOODIX_MAX_CONTACTS;
690 ts->input_dev = devm_input_allocate_device(&ts->client->dev);
691 if (!ts->input_dev) {
692 dev_err(&ts->client->dev, "Failed to allocate input device.");
696 ts->input_dev->name = "Goodix Capacitive TouchScreen";
697 ts->input_dev->phys = "input/ts";
698 ts->input_dev->id.bustype = BUS_I2C;
699 ts->input_dev->id.vendor = 0x0416;
700 ts->input_dev->id.product = ts->id;
701 ts->input_dev->id.version = ts->version;
703 /* Capacitive Windows/Home button on some devices */
704 input_set_capability(ts->input_dev, EV_KEY, KEY_LEFTMETA);
706 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X);
707 input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y);
708 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
709 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
711 /* Read configuration and apply touchscreen parameters */
712 goodix_read_config(ts);
714 /* Try overriding touchscreen parameters via device properties */
715 touchscreen_parse_properties(ts->input_dev, true, &ts->prop);
717 if (!ts->prop.max_x || !ts->prop.max_y || !ts->max_touch_num) {
718 dev_err(&ts->client->dev,
719 "Invalid config (%d, %d, %d), using defaults\n",
720 ts->prop.max_x, ts->prop.max_y, ts->max_touch_num);
721 ts->prop.max_x = GOODIX_MAX_WIDTH - 1;
722 ts->prop.max_y = GOODIX_MAX_HEIGHT - 1;
723 ts->max_touch_num = GOODIX_MAX_CONTACTS;
724 input_abs_set_max(ts->input_dev,
725 ABS_MT_POSITION_X, ts->prop.max_x);
726 input_abs_set_max(ts->input_dev,
727 ABS_MT_POSITION_Y, ts->prop.max_y);
730 if (dmi_check_system(rotated_screen)) {
731 ts->prop.invert_x = true;
732 ts->prop.invert_y = true;
733 dev_dbg(&ts->client->dev,
734 "Applying '180 degrees rotated screen' quirk\n");
737 error = input_mt_init_slots(ts->input_dev, ts->max_touch_num,
738 INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
740 dev_err(&ts->client->dev,
741 "Failed to initialize MT slots: %d", error);
745 error = input_register_device(ts->input_dev);
747 dev_err(&ts->client->dev,
748 "Failed to register input device: %d", error);
752 ts->irq_flags = goodix_irq_flags[ts->int_trigger_type] | IRQF_ONESHOT;
753 error = goodix_request_irq(ts);
755 dev_err(&ts->client->dev, "request IRQ failed: %d\n", error);
763 * goodix_config_cb - Callback to finish device init
765 * @ts: our goodix_ts_data pointer
767 * request_firmware_wait callback that finishes
768 * initialization of the device.
770 static void goodix_config_cb(const struct firmware *cfg, void *ctx)
772 struct goodix_ts_data *ts = ctx;
776 /* send device configuration to the firmware */
777 error = goodix_send_cfg(ts, cfg);
779 goto err_release_cfg;
782 goodix_configure_dev(ts);
785 release_firmware(cfg);
786 complete_all(&ts->firmware_loading_complete);
789 static void goodix_disable_regulators(void *arg)
791 struct goodix_ts_data *ts = arg;
793 regulator_disable(ts->vddio);
794 regulator_disable(ts->avdd28);
797 static int goodix_ts_probe(struct i2c_client *client,
798 const struct i2c_device_id *id)
800 struct goodix_ts_data *ts;
803 dev_dbg(&client->dev, "I2C Address: 0x%02x\n", client->addr);
805 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
806 dev_err(&client->dev, "I2C check functionality failed.\n");
810 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
815 i2c_set_clientdata(client, ts);
816 init_completion(&ts->firmware_loading_complete);
818 error = goodix_get_gpio_config(ts);
822 /* power up the controller */
823 error = regulator_enable(ts->avdd28);
825 dev_err(&client->dev,
826 "Failed to enable AVDD28 regulator: %d\n",
831 error = regulator_enable(ts->vddio);
833 dev_err(&client->dev,
834 "Failed to enable VDDIO regulator: %d\n",
836 regulator_disable(ts->avdd28);
840 error = devm_add_action_or_reset(&client->dev,
841 goodix_disable_regulators, ts);
845 if (ts->gpiod_int && ts->gpiod_rst) {
846 /* reset the controller */
847 error = goodix_reset(ts);
849 dev_err(&client->dev, "Controller reset failed.\n");
854 error = goodix_i2c_test(client);
856 dev_err(&client->dev, "I2C communication failure: %d\n", error);
860 error = goodix_read_version(ts);
862 dev_err(&client->dev, "Read version failed.\n");
866 ts->chip = goodix_get_chip_data(ts->id);
868 if (ts->gpiod_int && ts->gpiod_rst) {
869 /* update device config */
870 ts->cfg_name = devm_kasprintf(&client->dev, GFP_KERNEL,
871 "goodix_%d_cfg.bin", ts->id);
875 error = request_firmware_nowait(THIS_MODULE, true, ts->cfg_name,
876 &client->dev, GFP_KERNEL, ts,
879 dev_err(&client->dev,
880 "Failed to invoke firmware loader: %d\n",
887 error = goodix_configure_dev(ts);
895 static int goodix_ts_remove(struct i2c_client *client)
897 struct goodix_ts_data *ts = i2c_get_clientdata(client);
899 if (ts->gpiod_int && ts->gpiod_rst)
900 wait_for_completion(&ts->firmware_loading_complete);
905 static int __maybe_unused goodix_suspend(struct device *dev)
907 struct i2c_client *client = to_i2c_client(dev);
908 struct goodix_ts_data *ts = i2c_get_clientdata(client);
911 /* We need gpio pins to suspend/resume */
912 if (!ts->gpiod_int || !ts->gpiod_rst) {
913 disable_irq(client->irq);
917 wait_for_completion(&ts->firmware_loading_complete);
919 /* Free IRQ as IRQ pin is used as output in the suspend sequence */
922 /* Output LOW on the INT pin for 5 ms */
923 error = gpiod_direction_output(ts->gpiod_int, 0);
925 goodix_request_irq(ts);
929 usleep_range(5000, 6000);
931 error = goodix_i2c_write_u8(ts->client, GOODIX_REG_COMMAND,
932 GOODIX_CMD_SCREEN_OFF);
934 dev_err(&ts->client->dev, "Screen off command failed\n");
935 gpiod_direction_input(ts->gpiod_int);
936 goodix_request_irq(ts);
941 * The datasheet specifies that the interval between sending screen-off
942 * command and wake-up should be longer than 58 ms. To avoid waking up
943 * sooner, delay 58ms here.
949 static int __maybe_unused goodix_resume(struct device *dev)
951 struct i2c_client *client = to_i2c_client(dev);
952 struct goodix_ts_data *ts = i2c_get_clientdata(client);
955 if (!ts->gpiod_int || !ts->gpiod_rst) {
956 enable_irq(client->irq);
961 * Exit sleep mode by outputting HIGH level to INT pin
964 error = gpiod_direction_output(ts->gpiod_int, 1);
968 usleep_range(2000, 5000);
970 error = goodix_int_sync(ts);
974 error = goodix_request_irq(ts);
981 static SIMPLE_DEV_PM_OPS(goodix_pm_ops, goodix_suspend, goodix_resume);
983 static const struct i2c_device_id goodix_ts_id[] = {
984 { "GDIX1001:00", 0 },
987 MODULE_DEVICE_TABLE(i2c, goodix_ts_id);
990 static const struct acpi_device_id goodix_acpi_match[] = {
995 MODULE_DEVICE_TABLE(acpi, goodix_acpi_match);
999 static const struct of_device_id goodix_of_match[] = {
1000 { .compatible = "goodix,gt1151" },
1001 { .compatible = "goodix,gt5663" },
1002 { .compatible = "goodix,gt5688" },
1003 { .compatible = "goodix,gt911" },
1004 { .compatible = "goodix,gt9110" },
1005 { .compatible = "goodix,gt912" },
1006 { .compatible = "goodix,gt927" },
1007 { .compatible = "goodix,gt9271" },
1008 { .compatible = "goodix,gt928" },
1009 { .compatible = "goodix,gt967" },
1012 MODULE_DEVICE_TABLE(of, goodix_of_match);
1015 static struct i2c_driver goodix_ts_driver = {
1016 .probe = goodix_ts_probe,
1017 .remove = goodix_ts_remove,
1018 .id_table = goodix_ts_id,
1020 .name = "Goodix-TS",
1021 .acpi_match_table = ACPI_PTR(goodix_acpi_match),
1022 .of_match_table = of_match_ptr(goodix_of_match),
1023 .pm = &goodix_pm_ops,
1026 module_i2c_driver(goodix_ts_driver);
1030 MODULE_DESCRIPTION("Goodix touchscreen driver");
1031 MODULE_LICENSE("GPL v2");