1 From 5e768fe3e14ce0026a297dffd0d3c28ae2f73e72 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 6 Nov 2020 18:45:10 +0000
4 Subject: [PATCH 0262/1085] Input: edt-ft5x06: Poll the device if no interrupt
7 Not all systems have the interrupt line wired up, so switch to
8 polling the touchscreen off a timer if no interrupt line is
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 input: edt-ft5x06: Handle unreliable TOUCH_UP events
15 The ft5x06 is unreliable in sending touch up events, so some
16 touch IDs can become stuck in the detected state.
18 Ensure that IDs that are unreported by the controller are
21 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
23 input: edt-ft5x06: Only look at the number of points reported
25 Register 0x02 in the FT5x06 is TD_STATUS containing the number
26 of valid touch points being reported.
28 Iterate over that number of points rather than all that are
29 supported on the device.
31 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
33 input: edt-ft5x06: Only read data for number of points reported
35 Rather than always reading the maximum number of points supported
36 by the chip (which may be as high as 10), read the number of
37 active points first, and read data for just those.
38 In most cases this will result in less data on the I2C bus,
39 with only the maximum touch points taking more due to a second
40 read that has to configure the start address.
42 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
44 input: edt-ft5x06: Fix patch reading only the number of points reported
46 Fix bad conflict resolution from upstream updates. Need to read
47 from tsdata->tdata_offset bytes, not from tsdata->offset.
48 Also fix logging of i2c read errors to cover both transactions.
50 Fixes: 7216fcfe2e5f ("input: edt-ft5x06: Only read data for number of points reported")
51 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
53 drivers/input/touchscreen/edt-ft5x06.c | 93 ++++++++++++++++++++++----
54 1 file changed, 80 insertions(+), 13 deletions(-)
56 --- a/drivers/input/touchscreen/edt-ft5x06.c
57 +++ b/drivers/input/touchscreen/edt-ft5x06.c
59 #define M06_REG_CMD(factory) ((factory) ? 0xf3 : 0xfc)
60 #define M06_REG_ADDR(factory, addr) ((factory) ? (addr) & 0x7f : (addr) & 0x3f)
62 +#define POLL_INTERVAL_MS 17 /* 17ms = 60fps */
65 EDT_PMODE_NOT_SUPPORTED,
67 @@ -139,6 +141,7 @@ struct edt_ft5x06_ts_data {
71 + unsigned int known_ids;
73 char name[EDT_NAME_LEN];
74 char fw_version[EDT_NAME_LEN];
75 @@ -147,6 +150,9 @@ struct edt_ft5x06_ts_data {
77 unsigned int crc_errors;
78 unsigned int header_errors;
80 + struct timer_list timer;
81 + struct work_struct work_i2c_poll;
84 struct edt_i2c_chip_data {
85 @@ -303,17 +309,34 @@ static irqreturn_t edt_ft5x06_ts_isr(int
87 int i, type, x, y, id;
90 + unsigned int active_ids = 0, known_ids = tsdata->known_ids;
94 memset(rdbuf, 0, sizeof(rdbuf));
95 error = regmap_bulk_read(tsdata->regmap, tsdata->tdata_cmd, rdbuf,
97 + if (tsdata->version == EDT_M06) {
98 + num_points = tsdata->max_support_points;
100 + /* Register 2 is TD_STATUS, containing the number of touch
103 + num_points = min(rdbuf[2] & 0xf, tsdata->max_support_points);
104 + if (!error && num_points)
105 + error = regmap_bulk_read(tsdata->regmap,
106 + tsdata->tdata_offset,
107 + &rdbuf[tsdata->tdata_offset],
108 + tsdata->point_len * num_points);
111 dev_err_ratelimited(dev, "Unable to fetch data, error: %d\n",
116 - for (i = 0; i < tsdata->max_support_points; i++) {
117 + for (i = 0; i < num_points; i++) {
118 u8 *buf = &rdbuf[i * tsdata->point_len + tsdata->tdata_offset];
121 @@ -335,10 +358,25 @@ static irqreturn_t edt_ft5x06_ts_isr(int
123 input_mt_slot(tsdata->input, id);
124 if (input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER,
125 - type != TOUCH_EVENT_UP))
126 + type != TOUCH_EVENT_UP)) {
127 touchscreen_report_pos(tsdata->input, &tsdata->prop,
129 + active_ids |= BIT(id);
131 + known_ids &= ~BIT(id);
135 + /* One issue with the device is the TOUCH_UP message is not always
136 + * returned. Instead track which ids we know about and report when they
137 + * are no longer updated
139 + released_ids = known_ids & ~active_ids;
140 + for_each_set_bit_from(b, &released_ids, tsdata->max_support_points) {
141 + input_mt_slot(tsdata->input, b);
142 + input_mt_report_slot_inactive(tsdata->input);
144 + tsdata->known_ids = active_ids;
146 input_mt_report_pointer_emulation(tsdata->input, true);
147 input_sync(tsdata->input);
148 @@ -347,6 +385,22 @@ out:
152 +static void edt_ft5x06_ts_irq_poll_timer(struct timer_list *t)
154 + struct edt_ft5x06_ts_data *tsdata = from_timer(tsdata, t, timer);
156 + schedule_work(&tsdata->work_i2c_poll);
157 + mod_timer(&tsdata->timer, jiffies + msecs_to_jiffies(POLL_INTERVAL_MS));
160 +static void edt_ft5x06_ts_work_i2c_poll(struct work_struct *work)
162 + struct edt_ft5x06_ts_data *tsdata = container_of(work,
163 + struct edt_ft5x06_ts_data, work_i2c_poll);
165 + edt_ft5x06_ts_isr(0, tsdata);
168 struct edt_ft5x06_attribute {
169 struct device_attribute dattr;
171 @@ -1053,20 +1107,23 @@ static void edt_ft5x06_ts_get_parameters
172 static void edt_ft5x06_ts_set_tdata_parameters(struct edt_ft5x06_ts_data *tsdata)
177 if (tsdata->version == EDT_M06) {
178 tsdata->tdata_cmd = 0xf9;
179 tsdata->tdata_offset = 5;
180 tsdata->point_len = 4;
182 + points = tsdata->max_support_points;
184 tsdata->tdata_cmd = 0x0;
185 tsdata->tdata_offset = 3;
186 tsdata->point_len = 6;
191 - tsdata->tdata_len = tsdata->point_len * tsdata->max_support_points +
192 + tsdata->tdata_len = tsdata->point_len * points +
193 tsdata->tdata_offset + crclen;
196 @@ -1317,17 +1374,27 @@ static int edt_ft5x06_ts_probe(struct i2
200 - irq_flags = irq_get_trigger_type(client->irq);
201 - if (irq_flags == IRQF_TRIGGER_NONE)
202 - irq_flags = IRQF_TRIGGER_FALLING;
203 - irq_flags |= IRQF_ONESHOT;
205 - error = devm_request_threaded_irq(&client->dev, client->irq,
206 - NULL, edt_ft5x06_ts_isr, irq_flags,
207 - client->name, tsdata);
209 - dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
212 + irq_flags = irq_get_trigger_type(client->irq);
213 + if (irq_flags == IRQF_TRIGGER_NONE)
214 + irq_flags = IRQF_TRIGGER_FALLING;
215 + irq_flags |= IRQF_ONESHOT;
217 + error = devm_request_threaded_irq(&client->dev, client->irq,
218 + NULL, edt_ft5x06_ts_isr,
219 + irq_flags, client->name,
222 + dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
226 + INIT_WORK(&tsdata->work_i2c_poll,
227 + edt_ft5x06_ts_work_i2c_poll);
228 + timer_setup(&tsdata->timer, edt_ft5x06_ts_irq_poll_timer, 0);
229 + tsdata->timer.expires = jiffies +
230 + msecs_to_jiffies(POLL_INTERVAL_MS);
231 + add_timer(&tsdata->timer);
234 error = devm_device_add_group(&client->dev, &edt_ft5x06_attr_group);