From: Daniel Golle <daniel@makrotopia.org>
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Daniel Golle" <daniel@makrotopia.org>,
"Uwe Kleine-König" <u.kleine-koenig@baylibre.com>,
"Oleh Kuzhylnyi" <kuzhylol@gmail.com>,
linux-input@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Chad Monroe <chad@monroe.io>, John Crispin <john@phrozen.org>
Subject: [PATCH 4/4] Input: hynitron-cst816x: time out gesture key release
Date: Thu, 1 Oct 2026 11:53:11 +0100 [thread overview]
Message-ID: <ea9fa494cfb0a10cee72795a60ed5481fb227de5.1790851590.git.daniel@makrotopia.org> (raw)
In-Reply-To: <cover.1790851590.git.daniel@makrotopia.org>
The controller reports a gesture code once and can then stay quiet
until the next touch, which leaves the gesture key pressed for as long
as the panel is left alone. Release the gesture keys 40 ms after the
last report that carried a gesture code, so that the release comes
from whichever happens first, the timeout or a report without a
gesture code. The 40 ms matches TSC200X_PENUP_TIME_MS, chosen there
for the same want of a lift event from the controller, and has to stay
above the interval between consecutive reports of a held gesture.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/input/touchscreen/hynitron-cst816x.c | 51 ++++++++++++++++++--
1 file changed, 48 insertions(+), 3 deletions(-)
diff --git a/drivers/input/touchscreen/hynitron-cst816x.c b/drivers/input/touchscreen/hynitron-cst816x.c
index e2093518e8af1..30f8ea314ed2c 100644
--- a/drivers/input/touchscreen/hynitron-cst816x.c
+++ b/drivers/input/touchscreen/hynitron-cst816x.c
@@ -15,9 +15,12 @@
#include <linux/unaligned.h>
#include <linux/interrupt.h>
#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <linux/timer.h>
#define CST816X_RD_REG 0x01
#define CST816X_NUM_KEYS 5
+#define CST816X_GEST_HOLD_MS 40
struct cst816x_touch {
u8 gest;
@@ -32,6 +35,9 @@ struct cst816x_priv {
struct input_dev *input;
unsigned int keycode[CST816X_NUM_KEYS];
unsigned int keycodemax;
+ struct timer_list release_timer;
+ /* lock keeps the timeout out of the middle of a report */
+ spinlock_t lock;
struct touchscreen_properties prop;
};
@@ -168,8 +174,9 @@ static void cst816x_reset(struct cst816x_priv *priv)
msleep(100);
}
-static void cst816x_release_keys(struct cst816x_priv *priv)
+static bool cst816x_release_keys(struct cst816x_priv *priv)
{
+ bool released = false;
unsigned int i;
for (i = 0; i < priv->keycodemax; i++) {
@@ -177,33 +184,65 @@ static void cst816x_release_keys(struct cst816x_priv *priv)
continue;
input_report_key(priv->input, priv->keycode[i], 0);
+ released = true;
}
+
+ return released;
+}
+
+static void cst816x_release_timeout(struct timer_list *t)
+{
+ struct cst816x_priv *priv = timer_container_of(priv, t, release_timer);
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->lock, flags);
+
+ if (cst816x_release_keys(priv))
+ input_sync(priv->input);
+
+ spin_unlock_irqrestore(&priv->lock, flags);
}
static irqreturn_t cst816x_irq_cb(int irq, void *cookie)
{
struct cst816x_priv *priv = cookie;
struct cst816x_touch tch;
+ unsigned long flags;
if (!cst816x_process_touch(priv, &tch))
return IRQ_HANDLED;
+ spin_lock_irqsave(&priv->lock, flags);
+
touchscreen_report_pos(priv->input, &priv->prop,
tch.abs_x, tch.abs_y, false);
- if (tch.gest)
+ if (tch.gest) {
input_report_key(priv->input,
priv->keycode[cst816x_gest_idx(tch.gest)], 1);
- else
+ mod_timer(&priv->release_timer,
+ jiffies + msecs_to_jiffies(CST816X_GEST_HOLD_MS));
+ } else {
+ timer_delete(&priv->release_timer);
cst816x_release_keys(priv);
+ }
input_report_key(priv->input, BTN_TOUCH, tch.active);
input_sync(priv->input);
+ spin_unlock_irqrestore(&priv->lock, flags);
+
return IRQ_HANDLED;
}
+static void cst816x_timer_stop(void *data)
+{
+ struct cst816x_priv *priv = data;
+
+ timer_delete_sync(&priv->release_timer);
+}
+
static int cst816x_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
@@ -215,6 +254,8 @@ static int cst816x_probe(struct i2c_client *client)
return -ENOMEM;
priv->client = client;
+ spin_lock_init(&priv->lock);
+ timer_setup(&priv->release_timer, cst816x_release_timeout, 0);
priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(priv->reset))
@@ -232,6 +273,10 @@ static int cst816x_probe(struct i2c_client *client)
if (error)
return dev_err_probe(dev, error, "input register failed\n");
+ error = devm_add_action_or_reset(dev, cst816x_timer_stop, priv);
+ if (error)
+ return error;
+
error = devm_request_threaded_irq(dev, client->irq,
NULL, cst816x_irq_cb, IRQF_ONESHOT,
dev_driver_string(dev), priv);
--
2.55.0
prev parent reply other threads:[~2026-10-01 10:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 10:52 [PATCH 0/4] Input: hynitron-cst816x: axis properties and gesture keys Daniel Golle
2026-10-01 10:52 ` [PATCH 1/4] dt-bindings: input: touchscreen: hynitron,cst816x: configure axes Daniel Golle
2026-10-01 19:01 ` Conor Dooley
2026-10-01 10:52 ` [PATCH 2/4] Input: hynitron-cst816x: respect touchscreen DT properties Daniel Golle
2026-10-01 10:53 ` [PATCH 3/4] Input: hynitron-cst816x: release gesture keys Daniel Golle
2026-10-01 10:53 ` Daniel Golle [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ea9fa494cfb0a10cee72795a60ed5481fb227de5.1790851590.git.daniel@makrotopia.org \
--to=daniel@makrotopia.org \
--cc=chad@monroe.io \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=john@phrozen.org \
--cc=krzk+dt@kernel.org \
--cc=kuzhylol@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=u.kleine-koenig@baylibre.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®