From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Daniel Mack <daniel@zonque.org>,
Haojian Zhuang <haojian.zhuang@gmail.com>,
Robert Jarzmik <robert.jarzmik@free.fr>,
Arnd Bergmann <arnd@arndb.de>
Cc: Mark Brown <broonie@kernel.org>,
"H . Nikolaus Schaller" <hns@goldelico.com>,
Kris Bahnsen <kris@embeddedTS.com>,
Mark Featherston <mark@embeddedTS.com>,
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
linux-input@vger.kernel.org, linux-spi@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] Input: ads7846 - simplify sample filtering
Date: Wed, 11 Nov 2026 22:49:54 -0800 [thread overview]
Message-ID: <20261112064957.1796975-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20261112064957.1796975-1-dmitry.torokhov@gmail.com>
The filter and filter_data members of struct ads7846, along with the
generic signature of ads7846_debounce_filter(), are leftovers from
custom filter callbacks that were removed in commit 937f5d5ec642
("Input: ads7846 - remove custom filter handling functions from pdata").
Drop the filter and filter_data function pointers, remove the unused
ads7846_no_filter() stub, simplify ads7846_debounce_filter() to take
struct ads7846 and the sample value directly, and call it without
pointer indirection.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/touchscreen/ads7846.c | 72 ++++++++++++-----------------
1 file changed, 30 insertions(+), 42 deletions(-)
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 9bcb2ef129cd..f1827684c902 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -135,8 +135,6 @@ struct ads7846 {
bool suspended; /* P: lock */
void (*read_state)(struct ads7846 *ts);
- int (*filter)(void *data, int data_idx, int *val);
- void *filter_data;
struct gpio_desc *gpio_pendown;
struct gpio_desc *gpio_hsync;
};
@@ -631,11 +629,12 @@ ATTRIBUTE_GROUPS(ads784x);
/*--------------------------------------------------------------------------*/
-static int ads7846_debounce_filter(void *ads, int data_idx, int *val)
+static enum ads7846_filter ads7846_debounce_filter(struct ads7846 *ts, int val)
{
- struct ads7846 *ts = ads;
+ if (!ts->debounce_max)
+ return ADS7846_FILTER_OK;
- if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) {
+ if (!ts->read_cnt || abs(ts->last_read - val) > ts->debounce_tol) {
/* Start over collecting consistent readings. */
ts->read_rep = 0;
/*
@@ -643,39 +642,34 @@ static int ads7846_debounce_filter(void *ads, int data_idx, int *val)
* wasn't consistent enough.
*/
if (ts->read_cnt < ts->debounce_max) {
- ts->last_read = *val;
- ts->read_cnt++;
- return ADS7846_FILTER_REPEAT;
- } else {
- /*
- * Maximum number of debouncing reached and still
- * not enough number of consistent readings. Abort
- * the whole sample, repeat it in the next sampling
- * period.
- */
- ts->read_cnt = 0;
- return ADS7846_FILTER_IGNORE;
- }
- } else {
- if (++ts->read_rep > ts->debounce_rep) {
- /*
- * Got a good reading for this coordinate,
- * go for the next one.
- */
- ts->read_cnt = 0;
- ts->read_rep = 0;
- return ADS7846_FILTER_OK;
- } else {
- /* Read more values that are consistent. */
+ ts->last_read = val;
ts->read_cnt++;
return ADS7846_FILTER_REPEAT;
}
+
+ /*
+ * Maximum number of debouncing reached and still
+ * not enough number of consistent readings. Abort
+ * the whole sample, repeat it in the next sampling
+ * period.
+ */
+ ts->read_cnt = 0;
+ return ADS7846_FILTER_IGNORE;
}
-}
-static int ads7846_no_filter(void *ads, int data_idx, int *val)
-{
- return ADS7846_FILTER_OK;
+ if (++ts->read_rep > ts->debounce_rep) {
+ /*
+ * Got a good reading for this coordinate,
+ * go for the next one.
+ */
+ ts->read_cnt = 0;
+ ts->read_rep = 0;
+ return ADS7846_FILTER_OK;
+ }
+
+ /* Read more values that are consistent. */
+ ts->read_cnt++;
+ return ADS7846_FILTER_REPEAT;
}
static int ads7846_get_value(struct ads7846_buf *buf)
@@ -759,7 +753,7 @@ static int ads7846_filter_cmd(struct ads7846 *ts, unsigned int cmd_idx)
for (b = l->skip; b < l->count; b++) {
int val = ads7846_get_value(&packet->rx[l->offset + b]);
- switch (ts->filter(ts->filter_data, cmd_idx, &val)) {
+ switch (ads7846_debounce_filter(ts, val)) {
case ADS7846_FILTER_REPEAT:
if (b == l->count - 1)
return -EAGAIN;
@@ -1367,14 +1361,8 @@ static int ads7846_probe(struct spi_device *spi)
device_property_read_u16(dev, "ti,debounce-tol", &ts->debounce_tol);
device_property_read_u16(dev, "ti,debounce-rep", &ts->debounce_rep);
- if (ts->debounce_max) {
- if (ts->debounce_max < 2)
- ts->debounce_max = 2;
- ts->filter = ads7846_debounce_filter;
- ts->filter_data = ts;
- } else {
- ts->filter = ads7846_no_filter;
- }
+ if (ts->debounce_max && ts->debounce_max < 2)
+ ts->debounce_max = 2;
err = ads7846_setup_pendown(ts);
if (err)
--
2.56.0.567.gdb80ae8cd5-goog
next prev parent reply other threads:[~2026-11-12 6:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 6:49 [PATCH 0/5] Input: ads7846 - drop platform data support and cleanups Dmitry Torokhov
2026-11-12 6:49 ` [PATCH 1/5] Input: ads7846 - drop platform data support Dmitry Torokhov
2026-11-21 20:39 ` Linus Walleij
2026-11-12 6:49 ` Dmitry Torokhov [this message]
2026-11-21 20:40 ` [PATCH 2/5] Input: ads7846 - simplify sample filtering Linus Walleij
2026-11-12 6:49 ` [PATCH 3/5] Input: ads7846 - remove unneeded memory barriers Dmitry Torokhov
2026-11-21 20:41 ` Linus Walleij
2026-11-12 6:49 ` [PATCH 4/5] Input: ads7846 - remove unused code Dmitry Torokhov
2026-11-21 20:41 ` Linus Walleij
2026-11-12 6:49 ` [PATCH 5/5] Input: ads7846 - fix minor coding style issues Dmitry Torokhov
2026-11-21 20:42 ` Linus Walleij
2026-11-12 7:28 ` [PATCH 0/5] Input: ads7846 - drop platform data support and cleanups Arnd Bergmann
2026-11-23 4:40 ` Dmitry Torokhov
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=20261112064957.1796975-3-dmitry.torokhov@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=aaro.koskinen@iki.fi \
--cc=arnd@arndb.de \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=broonie@kernel.org \
--cc=daniel@zonque.org \
--cc=haojian.zhuang@gmail.com \
--cc=hns@goldelico.com \
--cc=kris@embeddedTS.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mark@embeddedTS.com \
--cc=robert.jarzmik@free.fr \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.