From: Javier Carrasco <javier.carrasco@wolfvision.net>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Henrik Rydberg <rydberg@bitmath.org>,
Bastian Hecht <hechtb@gmail.com>,
Michael Riesch <michael.riesch@wolfvision.net>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
devicetree@vger.kernel.org,
Javier Carrasco <javier.carrasco@wolfvision.net>
Subject: [PATCH v3 3/4] Input: st1232 - add overlay touchscreen and buttons handling
Date: Fri, 16 Jun 2023 09:28:53 +0200 [thread overview]
Message-ID: <20230510-feature-ts_virtobj_patch-v3-3-b4fb7fc4bab7@wolfvision.net> (raw)
In-Reply-To: <20230510-feature-ts_virtobj_patch-v3-0-b4fb7fc4bab7@wolfvision.net>
Use ts-overlay to support overlay objects such as buttons and resized
frames defined in the device tree.
If a overlay-touchscreen is provided, ignore touch events outside of
the area defined by its properties. Otherwise, transform the event
coordinates to the overlay-touchscreen x and y-axis if required.
If buttons are provided, register an additional device to report key
events separately. A key event will be generated if the coordinates
of a touch event are within the area defined by the button properties.
Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net>
---
drivers/input/touchscreen/Kconfig | 1 +
drivers/input/touchscreen/st1232.c | 87 ++++++++++++++++++++++++++++++--------
2 files changed, 70 insertions(+), 18 deletions(-)
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 8382a4d68326..202e559371e8 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -1215,6 +1215,7 @@ config TOUCHSCREEN_SIS_I2C
config TOUCHSCREEN_ST1232
tristate "Sitronix ST1232 or ST1633 touchscreen controllers"
depends on I2C
+ select TOUCHSCREEN_TS_OVERLAY
help
Say Y here if you want to support the Sitronix ST1232
or ST1633 touchscreen controller.
diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index f49566dc96f8..7d8a69e4831b 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -22,6 +22,7 @@
#include <linux/pm_qos.h>
#include <linux/slab.h>
#include <linux/types.h>
+#include <linux/input/ts-overlay.h>
#define ST1232_TS_NAME "st1232-ts"
#define ST1633_TS_NAME "st1633-ts"
@@ -56,6 +57,8 @@ struct st1232_ts_data {
struct touchscreen_properties prop;
struct dev_pm_qos_request low_latency_req;
struct gpio_desc *reset_gpio;
+ struct input_dev *overlay_keypad;
+ struct ts_overlay_map *map;
const struct st_chip_info *chip_info;
int read_buf_len;
u8 *read_buf;
@@ -129,10 +132,12 @@ static int st1232_ts_read_resolution(struct st1232_ts_data *ts, u16 *max_x,
static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
{
- struct input_dev *input = ts->input_dev;
+ struct input_dev *tscreen = ts->input_dev;
+ __maybe_unused struct input_dev *keypad = ts->overlay_keypad;
struct input_mt_pos pos[ST_TS_MAX_FINGERS];
u8 z[ST_TS_MAX_FINGERS];
int slots[ST_TS_MAX_FINGERS];
+ __maybe_unused bool button_pressed[ST_TS_MAX_FINGERS];
int n_contacts = 0;
int i;
@@ -143,6 +148,15 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
unsigned int x = ((buf[0] & 0x70) << 4) | buf[1];
unsigned int y = ((buf[0] & 0x07) << 8) | buf[2];
+ /* forward button presses to the keypad input device */
+ if (ts_overlay_is_button_slot(ts->map, i) ||
+ ts_overlay_button_press(ts->map, keypad, x, y, i)) {
+ button_pressed[i] = true;
+ continue;
+ }
+ /* Ignore events out of the overlay screen if defined */
+ if (!ts_overlay_mt_on_touchscreen(ts->map, &x, &y))
+ continue;
touchscreen_set_mt_pos(&pos[n_contacts],
&ts->prop, x, y);
@@ -154,18 +168,25 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)
}
}
- input_mt_assign_slots(input, slots, pos, n_contacts, 0);
+ input_mt_assign_slots(tscreen, slots, pos, n_contacts, 0);
for (i = 0; i < n_contacts; i++) {
- input_mt_slot(input, slots[i]);
- input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
- input_report_abs(input, ABS_MT_POSITION_X, pos[i].x);
- input_report_abs(input, ABS_MT_POSITION_Y, pos[i].y);
+ input_mt_slot(tscreen, slots[i]);
+ input_mt_report_slot_state(tscreen, MT_TOOL_FINGER, true);
+ input_report_abs(tscreen, ABS_MT_POSITION_X, pos[i].x);
+ input_report_abs(tscreen, ABS_MT_POSITION_Y, pos[i].y);
if (ts->chip_info->have_z)
- input_report_abs(input, ABS_MT_TOUCH_MAJOR, z[i]);
+ input_report_abs(tscreen, ABS_MT_TOUCH_MAJOR, z[i]);
+ }
+ input_mt_sync_frame(tscreen);
+ input_sync(tscreen);
+
+ if (ts_overlay_mapped_buttons(ts->map)) {
+ for (i = 0; i < ts->chip_info->max_fingers; i++)
+ if (ts_overlay_is_button_slot(ts->map, i) &&
+ !button_pressed[i])
+ ts_overlay_button_release(ts->map, keypad, i);
+ input_sync(keypad);
}
-
- input_mt_sync_frame(input);
- input_sync(input);
return n_contacts;
}
@@ -226,6 +247,7 @@ static int st1232_ts_probe(struct i2c_client *client)
const struct st_chip_info *match;
struct st1232_ts_data *ts;
struct input_dev *input_dev;
+ struct input_dev __maybe_unused *overlay_keypad;
u16 max_x, max_y;
int error;
@@ -292,18 +314,28 @@ static int st1232_ts_probe(struct i2c_client *client)
if (error)
return error;
- /* Read resolution from the chip */
- error = st1232_ts_read_resolution(ts, &max_x, &max_y);
- if (error) {
- dev_err(&client->dev,
- "Failed to read resolution: %d\n", error);
- return error;
- }
-
if (ts->chip_info->have_z)
input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0,
ts->chip_info->max_area, 0, 0);
+ /* map overlay objects if defined in the device tree */
+ ts->map = ts_overlay_map_objects(&ts->client->dev, ts->input_dev);
+ if (IS_ERR(ts->map))
+ return PTR_ERR(ts->map);
+
+ if (ts_overlay_mapped_touchscreen(ts->map)) {
+ /* Read resolution from the overlay touchscreen if defined*/
+ ts_overlay_get_touchscreen_abs(ts->map, &max_x, &max_y);
+ } else {
+ /* Read resolution from the chip */
+ error = st1232_ts_read_resolution(ts, &max_x, &max_y);
+ if (error) {
+ dev_err(&client->dev,
+ "Failed to read resolution: %d\n", error);
+ return error;
+ }
+ }
+
input_set_abs_params(input_dev, ABS_MT_POSITION_X,
0, max_x, 0, 0);
input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
@@ -335,6 +367,25 @@ static int st1232_ts_probe(struct i2c_client *client)
return error;
}
+ /* Register keypad input device if overlay buttons were defined */
+ if (ts_overlay_mapped_buttons(ts->map)) {
+ overlay_keypad = devm_input_allocate_device(&client->dev);
+ if (!overlay_keypad)
+ return -ENOMEM;
+
+ ts->overlay_keypad = overlay_keypad;
+ overlay_keypad->name = "st1232-keypad";
+ overlay_keypad->id.bustype = BUS_I2C;
+ ts_overlay_set_button_caps(ts->map, overlay_keypad);
+ error = input_register_device(ts->overlay_keypad);
+ if (error) {
+ dev_err(&client->dev,
+ "Unable to register %s input device\n",
+ overlay_keypad->name);
+ return error;
+ }
+ }
+
i2c_set_clientdata(client, ts);
return 0;
--
2.39.2
next prev parent reply other threads:[~2023-06-16 7:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 7:28 [PATCH v3 0/4] Input: support overlay objects on touchscreens Javier Carrasco
2023-06-16 7:28 ` [PATCH v3 1/4] Input: ts-overlay - Add touchscreen overlay object handling Javier Carrasco
2023-06-26 2:35 ` Jeff LaBundy
2023-06-26 10:31 ` Javier Carrasco
2023-06-26 13:47 ` Jeff LaBundy
2023-06-28 6:44 ` Javier Carrasco
2023-06-29 3:29 ` Jeff LaBundy
2023-06-29 7:53 ` Javier Carrasco
2023-06-30 17:30 ` Jeff LaBundy
2023-07-01 20:58 ` Javier Carrasco
2023-07-06 2:26 ` Jeff LaBundy
2023-06-16 7:28 ` [PATCH v3 2/4] dt-bindings: touchscreen: add overlay-touchscreen and overlay-buttons properties Javier Carrasco
2023-06-16 7:28 ` Javier Carrasco [this message]
2023-06-27 9:25 ` [PATCH v3 3/4] Input: st1232 - add overlay touchscreen and buttons handling kernel test robot
2023-06-16 7:28 ` [PATCH v3 4/4] dt-bindings: input: touchscreen: st1232: add example with ts-overlay Javier Carrasco
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=20230510-feature-ts_virtobj_patch-v3-3-b4fb7fc4bab7@wolfvision.net \
--to=javier.carrasco@wolfvision.net \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=hechtb@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.riesch@wolfvision.net \
--cc=robh+dt@kernel.org \
--cc=rydberg@bitmath.org \
/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;
as well as URLs for NNTP newsgroup(s).