Skip to content

Commit 0df28e7

Browse files
passgatdtor
authored andcommitted
Input: edt-ft5x06 - calculate points data length only once
It is pointless and expensive to calculate data in the interrupt that depends on the type of touchscreen, which is detected on the driver probe and cannot then be changed. So calculate the size of the data buffer on the driver probe, as well as the data retrieval command, and then use them in the ISR. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com> Link: https://lore.kernel.org/r/20230402200951.1032513-10-dario.binacchi@amarulasolutions.com Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 079e60a commit 0df28e7

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

drivers/input/touchscreen/edt-ft5x06.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ struct edt_ft5x06_ts_data {
135135
int offset_y;
136136
int report_rate;
137137
int max_support_points;
138+
int point_len;
139+
u8 tdata_cmd;
140+
int tdata_len;
141+
int tdata_offset;
138142

139143
char name[EDT_NAME_LEN];
140144
char fw_version[EDT_NAME_LEN];
@@ -296,46 +300,21 @@ static irqreturn_t edt_ft5x06_ts_isr(int irq, void *dev_id)
296300
{
297301
struct edt_ft5x06_ts_data *tsdata = dev_id;
298302
struct device *dev = &tsdata->client->dev;
299-
u8 cmd;
300303
u8 rdbuf[63];
301304
int i, type, x, y, id;
302-
int offset, tplen, datalen, crclen;
303305
int error;
304306

305-
switch (tsdata->version) {
306-
case EDT_M06:
307-
cmd = 0xf9; /* tell the controller to send touch data */
308-
offset = 5; /* where the actual touch data starts */
309-
tplen = 4; /* data comes in so called frames */
310-
crclen = 1; /* length of the crc data */
311-
break;
312-
313-
case EDT_M09:
314-
case EDT_M12:
315-
case EV_FT:
316-
case GENERIC_FT:
317-
cmd = 0x0;
318-
offset = 3;
319-
tplen = 6;
320-
crclen = 0;
321-
break;
322-
323-
default:
324-
goto out;
325-
}
326-
327307
memset(rdbuf, 0, sizeof(rdbuf));
328-
datalen = tplen * tsdata->max_support_points + offset + crclen;
329-
330-
error = regmap_bulk_read(tsdata->regmap, cmd, rdbuf, datalen);
308+
error = regmap_bulk_read(tsdata->regmap, tsdata->tdata_cmd, rdbuf,
309+
tsdata->tdata_len);
331310
if (error) {
332311
dev_err_ratelimited(dev, "Unable to fetch data, error: %d\n",
333312
error);
334313
goto out;
335314
}
336315

337316
for (i = 0; i < tsdata->max_support_points; i++) {
338-
u8 *buf = &rdbuf[i * tplen + offset];
317+
u8 *buf = &rdbuf[i * tsdata->point_len + tsdata->tdata_offset];
339318

340319
type = buf[0] >> 6;
341320
/* ignore Reserved events */
@@ -1071,6 +1050,26 @@ static void edt_ft5x06_ts_get_parameters(struct edt_ft5x06_ts_data *tsdata)
10711050
}
10721051
}
10731052

1053+
static void edt_ft5x06_ts_set_tdata_parameters(struct edt_ft5x06_ts_data *tsdata)
1054+
{
1055+
int crclen;
1056+
1057+
if (tsdata->version == EDT_M06) {
1058+
tsdata->tdata_cmd = 0xf9;
1059+
tsdata->tdata_offset = 5;
1060+
tsdata->point_len = 4;
1061+
crclen = 1;
1062+
} else {
1063+
tsdata->tdata_cmd = 0x0;
1064+
tsdata->tdata_offset = 3;
1065+
tsdata->point_len = 6;
1066+
crclen = 0;
1067+
}
1068+
1069+
tsdata->tdata_len = tsdata->point_len * tsdata->max_support_points +
1070+
tsdata->tdata_offset + crclen;
1071+
}
1072+
10741073
static void edt_ft5x06_ts_set_regs(struct edt_ft5x06_ts_data *tsdata)
10751074
{
10761075
struct edt_reg_addr *reg_addr = &tsdata->reg_addr;
@@ -1274,6 +1273,7 @@ static int edt_ft5x06_ts_probe(struct i2c_client *client)
12741273
*/
12751274
regmap_read(tsdata->regmap, 0x00, &val);
12761275

1276+
edt_ft5x06_ts_set_tdata_parameters(tsdata);
12771277
edt_ft5x06_ts_set_regs(tsdata);
12781278
edt_ft5x06_ts_get_defaults(&client->dev, tsdata);
12791279
edt_ft5x06_ts_get_parameters(tsdata);

0 commit comments

Comments
 (0)