Skip to content

Commit 8639e04

Browse files
Marek Vasutdtor
authored andcommitted
Input: ili210x - improve polled sample spacing
Currently the ili210x driver implements a threaded interrupt handler which starts upon edge on the interrupt line, and then polls the touch controller for samples. Every time a sample is obtained from the controller, the thread function checks whether further polling is required, and if so, waits fixed amount of time before polling for next sample. The delay between consecutive samples can thus vary greatly, because the I2C transfer required to retrieve the sample from the controller takes different amount of time on different platforms. Furthermore, different models of the touch controllers supported by this driver require different delays during retrieval of samples too. Instead of waiting fixed amount of time before polling for next sample, determine how much time passed since the beginning of sampling cycle and then wait only the remaining amount of time within the sampling cycle. This makes the driver deliver samples with equal spacing between them. Signed-off-by: Marek Vasut <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent de88910 commit 8639e04

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/input/touchscreen/ili210x.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,13 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data)
334334
const struct ili2xxx_chip *chip = priv->chip;
335335
u8 touchdata[ILI210X_DATA_SIZE] = { 0 };
336336
bool keep_polling;
337+
ktime_t time_next;
338+
s64 time_delta;
337339
bool touch;
338340
int error;
339341

340342
do {
343+
time_next = ktime_add_ms(ktime_get(), ILI2XXX_POLL_PERIOD);
341344
error = chip->get_touch_data(client, touchdata);
342345
if (error) {
343346
dev_err(&client->dev,
@@ -347,8 +350,11 @@ static irqreturn_t ili210x_irq(int irq, void *irq_data)
347350

348351
touch = ili210x_report_events(priv, touchdata);
349352
keep_polling = chip->continue_polling(touchdata, touch);
350-
if (keep_polling)
351-
msleep(ILI2XXX_POLL_PERIOD);
353+
if (keep_polling) {
354+
time_delta = ktime_us_delta(time_next, ktime_get());
355+
if (time_delta > 0)
356+
usleep_range(time_delta, time_delta + 1000);
357+
}
352358
} while (!priv->stop && keep_polling);
353359

354360
return IRQ_HANDLED;

0 commit comments

Comments
 (0)