1 From 13a9614267e7d8d4075144a7bf4dbebfcc565367 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 30 Jan 2023 14:46:16 +0000
4 Subject: [PATCH] input: goodix: Add option to poll instead of relying
7 The interrupt line from the touch controller is not necessarily
8 connected to the SoC, so add the option to poll for touch info.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/input/touchscreen/goodix.c | 70 +++++++++++++++++++++++++++---
13 drivers/input/touchscreen/goodix.h | 2 +
14 2 files changed, 66 insertions(+), 6 deletions(-)
16 --- a/drivers/input/touchscreen/goodix.c
17 +++ b/drivers/input/touchscreen/goodix.c
19 #define MAX_CONTACTS_LOC 5
22 +#define POLL_INTERVAL_MS 17 /* 17ms = 60fps */
24 /* Our special handling for GPIO accesses through ACPI is x86 specific */
25 #if defined CONFIG_X86 && defined CONFIG_ACPI
26 #define ACPI_GPIO_SUPPORT
27 @@ -513,16 +515,67 @@ static irqreturn_t goodix_ts_irq_handler
31 +static void goodix_ts_irq_poll_timer(struct timer_list *t)
33 + struct goodix_ts_data *ts = from_timer(ts, t, timer);
35 + schedule_work(&ts->work_i2c_poll);
36 + mod_timer(&ts->timer, jiffies + msecs_to_jiffies(POLL_INTERVAL_MS));
39 +static void goodix_ts_work_i2c_poll(struct work_struct *work)
41 + struct goodix_ts_data *ts = container_of(work,
42 + struct goodix_ts_data, work_i2c_poll);
44 + goodix_process_events(ts);
45 + goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0);
48 +static void goodix_enable_irq(struct goodix_ts_data *ts)
50 + if (ts->client->irq) {
51 + enable_irq(ts->client->irq);
53 + ts->timer.expires = jiffies + msecs_to_jiffies(POLL_INTERVAL_MS);
54 + add_timer(&ts->timer);
58 +static void goodix_disable_irq(struct goodix_ts_data *ts)
60 + if (ts->client->irq) {
61 + disable_irq(ts->client->irq);
63 + del_timer(&ts->timer);
64 + cancel_work_sync(&ts->work_i2c_poll);
68 static void goodix_free_irq(struct goodix_ts_data *ts)
70 - devm_free_irq(&ts->client->dev, ts->client->irq, ts);
71 + if (ts->client->irq) {
72 + devm_free_irq(&ts->client->dev, ts->client->irq, ts);
74 + del_timer(&ts->timer);
75 + cancel_work_sync(&ts->work_i2c_poll);
79 static int goodix_request_irq(struct goodix_ts_data *ts)
81 - return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
82 - NULL, goodix_ts_irq_handler,
83 - ts->irq_flags, ts->client->name, ts);
84 + if (ts->client->irq) {
85 + return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
86 + NULL, goodix_ts_irq_handler,
87 + ts->irq_flags, ts->client->name, ts);
89 + INIT_WORK(&ts->work_i2c_poll,
90 + goodix_ts_work_i2c_poll);
91 + timer_setup(&ts->timer, goodix_ts_irq_poll_timer, 0);
92 + if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE)
93 + goodix_enable_irq(ts);
98 static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
99 @@ -1425,6 +1478,11 @@ static void goodix_ts_remove(struct i2c_
101 struct goodix_ts_data *ts = i2c_get_clientdata(client);
103 + if (!client->irq) {
104 + del_timer(&ts->timer);
105 + cancel_work_sync(&ts->work_i2c_poll);
108 if (ts->load_cfg_from_disk)
109 wait_for_completion(&ts->firmware_loading_complete);
111 @@ -1440,7 +1498,7 @@ static int __maybe_unused goodix_suspend
113 /* We need gpio pins to suspend/resume */
114 if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
115 - disable_irq(client->irq);
116 + goodix_disable_irq(ts);
120 @@ -1484,7 +1542,7 @@ static int __maybe_unused goodix_resume(
123 if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
124 - enable_irq(client->irq);
125 + goodix_enable_irq(ts);
129 --- a/drivers/input/touchscreen/goodix.h
130 +++ b/drivers/input/touchscreen/goodix.h
131 @@ -104,6 +104,8 @@ struct goodix_ts_data {
132 u8 main_clk[GOODIX_MAIN_CLK_LEN];
135 + struct timer_list timer;
136 + struct work_struct work_i2c_poll;
139 int goodix_i2c_read(struct i2c_client *client, u16 reg, u8 *buf, int len);