Input: support overlay objects on touchscreens
Subsystems (4)
Javier Carrasco
maintainerv4 cover Input: support overlay objects on touchscreens
Some touchscreens are shipped with a physical layer on top of them where a number of buttons and a resized touchscreen surface might be available.
In order to generate proper key events by overlay buttons and adjust the touch events to a clipped surface, these patches offer a documented, device-tree-based solution by means of helper functions.
An implementation for a specific touchscreen driver is also included.
The functions in ts-overlay provide a simple workflow to acquire physical objects from the device tree, map them into the device driver structures as overlay objects and generate events according to the object descriptions.
This feature has been tested with a JT240MHQS-E3 display, which consists of an st1624 as the base touchscreen and an overlay with two buttons and a frame that clips its effective surface mounted on it.
---
Changes in v4:
- General: rename "touchscreen" to "touch" to include other consumers.
- PATCH 1/4: move touch-overlay feature to input core.
- PATCH 1/4, 3/4: set key caps and report key events without consumer's
intervention.
- PATCH 2/4: add missing 'required' field with the required properties.
- Link to v3: https://lore.kernel.org/r/20230510-feature-ts_virtobj_patch-v3-0-b4fb7fc4bab7@wolfvision.net
Changes in v3:
- General: rename "virtobj" and "virtual" to "overlay"
- PATCH 1/4: Make feature bool instead of tristate (selected by
supported touchscreens)
- Link to v2: https://lore.kernel.org/r/20230510-feature-ts_virtobj_patch-v2-0-f68a6bfe7a0f@wolfvision.net
Changes in v2:
- PATCH 1/4: remove preprocessor directives (the module is selected by
the drivers that support the feature). Typo in the commit message.
- PATCH 2/4: more detailed documentation. Images and examples were added.
- PATCH 3/4: select ts-virtobj automatically.
- Link to v1: https://lore.kernel.org/r/20230510-feature-ts_virtobj_patch-v1-0-5ae5e81bc264@wolfvision.net
---
Javier Carrasco (4):
Input: touch-overlay - Add touchscreen overlay object handling
dt-bindings: touchscreen: add overlay-touchscreen and overlay-buttons properties
Input: st1232 - add touch overlays handling
dt-bindings: input: touchscreen: st1232: add example with touch-overlay
.../input/touchscreen/sitronix,st1232.yaml | 40 +++ .../bindings/input/touchscreen/touchscreen.yaml | 152 ++++++++ MAINTAINERS | 7 + drivers/input/Makefile | 2 +- drivers/input/touch-overlay.c | 399 +++++++++++++++++++++ drivers/input/touchscreen/st1232.c | 70 +++- include/linux/input/touch-overlay.h | 34 ++ 7 files changed, 689 insertions(+), 15 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230510-feature-ts_virtobj_patch-e267540aae74
Best regards,
Signature · 1 line
Javier Carrasco <[email protected]>
Javier Carrasco
maintainerPATCH v4 1/4 Input: touch-overlay - Add touchscreen overlay object handling
Some touch devices provide mechanical overlays with different objects like buttons or clipped touchscreen surfaces.
In order to support these objects, add a series of helper functions to the input subsystem to transform them into overlay objects via device tree nodes.
These overlay objects consume the raw touch events and report the expected input events depending on the object properties.
--- MAINTAINERS | 7 + drivers/input/Makefile | 2 +- drivers/input/touch-overlay.c | 399 ++++++++++++++++++++++++++++++++++++ include/linux/input/touch-overlay.h | 34 +++ 4 files changed, 441 insertions(+), 1 deletion(-)
MAINTAINERS +7 -0
@@ -21625,6 +21625,13 @@ W: https://github.com/srcres258/linux-doc T: git git://github.com/srcres258/linux-doc.git doc-zh-tw F: Documentation/translations/zh_TW/ +TOUCH OVERLAY OBJECTS +M: Javier Carrasco <[email protected]> +L: [email protected] +S: Maintained +F: drivers/input/touch-overlay.c +F: include/linux/input/touch-overlay.h + TTY LAYER M: Greg Kroah-Hartman <[email protected]> M: Jiri Slaby <[email protected]>
drivers/input/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_INPUT) += input-core.o input-core-y := input.o input-compat.o input-mt.o input-poller.o ff-core.o -input-core-y += touchscreen.o +input-core-y += touchscreen.o touch-overlay.o obj-$(CONFIG_INPUT_FF_MEMLESS) += ff-memless.o obj-$(CONFIG_INPUT_SPARSEKMAP) += sparse-keymap.o
drivers/input/touch-overlay.c new file +399 -0
399 lines not on this page · raw message
include/linux/input/touch-overlay.h new file +34 -0
@@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright (c) 2023 Javier Carrasco <[email protected]> +*/ + +#ifndef _TOUCH_OVERLAY +#define _TOUCH_OVERLAY + +#include <linux/types.h> + +struct input_dev ; +struct device ; + +struct touch_overlay_map { +struct touch_overlay_segment *touchscreen; +bool overlay_touchscreen; +struct touch_overlay_button *buttons; +u32 button_count; +}; + +struct touch_overlay_map *touch_overlay_map_overlay (struct input_dev *keypad); + +void touch_overlay_get_touchscreen_abs (struct touch_overlay_map *map, +u16 *x,u16 *y); + +bool touch_overlay_mapped_touchscreen (struct touch_overlay_map *map); + +bool touch_overlay_mapped_buttons (struct touch_overlay_map *map); + +bool touch_overlay_process_event (struct touch_overlay_map *map, +struct input_dev *input, +u32 *x,u32 *y,u32 slot); + +#endif
Signature · 1 line
2.39.2
Javier Carrasco
maintainerPATCH v4 2/4 dt-bindings: touchscreen: add overlay-touchscreen and overlay-buttons properties
In reply to Javier CarrascoThe overlay-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the overlay origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the overlay-buttons object contains a node for every button and the key event that should be reported when pressed.
--- .../bindings/input/touchscreen/touchscreen.yaml | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +152 -0
@@ -80,6 +80,158 @@ properties: touchscreen-y-plate-ohms: description: Resistance of the Y-plate in Ohms + overlay-touchscreen: + description: Clipped touchscreen area + + This object can be used to describe a frame that restricts the area + within touch events are reported, ignoring the events that occur outside + this area. This is of special interest if the touchscreen is shipped + with a physical overlay on top of it with a frame that hides some part + of the original touchscreen area. + + The x-origin and y-origin properties of this object define the offset of + a new origin from where the touchscreen events are referenced. + This offset is applied to the events accordingly. The x-size and y-size + properties define the size of the overlay-touchscreen (effective area). + + The following example shows the new touchscreen area and the new origin + (0',0') for the touch events generated by the device. + + Touchscreen (full area) + ┌────────────────────────────────────────┐ + │ ┌───────────────────────────────┐ │ + │ │ │ │ + │ ├ y-size │ │ + │ │ │ │ + │ │ overlay-touchscreen │ │ + │ │ │ │ + │ │ │ │ + │ │ x-size │ │ + │ ┌└──────────────┴────────────────┘ │ + │(0',0') │ + ┌└────────────────────────────────────────┘ + (0,0) + + where (0',0') = (0+x-origin,0+y-origin) + + type: object + + properties: + x-origin: + description: horizontal origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - x-origin + - y-origin + - x-size + - y-size + + overlay-buttons: + description: list of nodes defining the buttons on the touchscreen + + This object can be used to describe buttons on the touchscreen area, + reporting the touch events on their surface as key events instead of + the original touch events. + + This is of special interest if the touchscreen is shipped with a + physical overlay on top of it where a number of buttons with some + predefined functionality are printed. In that case a specific behavior + is expected from those buttons instead of raw touch events. + + The overlay-buttons properties define a per-button area as well as an + origin relative to the real touchscreen origin. Touch events within the + button area are reported as the key event defined in the linux,code + property. Given that the key events do not provide coordinates, the + button origin is only used to place the button area on the touchscreen + surface. Any event outside the overlay-buttons object is reported as a + touch event with no coordinate transformation. + + The following example shows a touchscreen with a single button on it + + Touchscreen (full area) + ┌───────────────────────────────────┐ + │ │ + │ │ + │ ┌─────────┐ │ + │ │button 0 │ │ + │ │KEY_POWER│ │ + │ └─────────┘ │ + │ │ + │ │ + ┌└───────────────────────────────────┘ + (0,0) + + The overlay-buttons object can be combined with the overlay-touchscreen + object as shown in the following example. In that case only the events + within the overlay-touchscreen object are reported as touch events. + + Touchscreen (full area) + ┌─────────┬──────────────────────────────┐ + │ │ │ + │ │ ┌───────────────────────┐ │ + │ button 0│ │ │ │ + │KEY_POWER│ │ │ │ + │ │ │ │ │ + ├─────────┤ │ overlay-touchscreen │ │ + │ │ │ │ │ + │ │ │ │ │ + │ button 1│ │ │ │ + │ KEY_INFO│ ┌└───────────────────────┘ │ + │ │(0',0') │ + ┌└─────────┴──────────────────────────────┘ + (0,0) + + type: object + + patternProperties: + '^button-': + type: object + description: + Each button (key) is represented as a sub-node. + + properties: + label: + $ref: /schemas/types.yaml#/definitions/string + description: descriptive name of the button + + linux,code: true + + x-origin: + description: horizontal origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - linux,code + - x-origin + - y-origin + - x-size + - y-size + dependencies: touchscreen-size-x: [ touchscreen-size-y ] touchscreen-size-y: [ touchscreen-size-x ]
Signature · 1 line
2.39.2
Rob Herring
maintainerRe: [PATCH v4 2/4] dt-bindings: touchscreen: add overlay-touchscreen and overlay-buttons properties
Quoted 45 lines · Javier Carrasco
The overlay-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the overlay origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the overlay-buttons object contains a node for every button and the key event that should be reported when pressed.
Signed-off-by Javier Carrasco <[email protected]>--- .../bindings/input/touchscreen/touchscreen.yaml | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+)Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +23
-0@@ -80,6 +80,158 @@ properties: touchscreen-y-plate-ohms: description: Resistance of the Y-plate in Ohms + overlay-touchscreen: + description: Clipped touchscreen area + + This object can be used to describe a frame that restricts the area + within touch events are reported, ignoring the events that occur outside + this area. This is of special interest if the touchscreen is shipped + with a physical overlay on top of it with a frame that hides some part + of the original touchscreen area. + + The x-origin and y-origin properties of this object define the offset of + a new origin from where the touchscreen events are referenced. + This offset is applied to the events accordingly. The x-size and y-size + properties define the size of the overlay-touchscreen (effective area). + + The following example shows the new touchscreen area and the new origin + (0',0') for the touch events generated by the device. + + Touchscreen (full area) + ┌────────────────────────────────────────┐ + │ ┌───────────────────────────────┐ │ + │ │ │ │ + │ ├ y-size │ │ + │ │ │ │
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml properties: · line 115
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +10
-0+ │ │ overlay-touchscreen │ │ + │ │ │ │ + │ │ │ │ + │ │ x-size │ │ + │ ┌└──────────────┴────────────────┘ │ + │(0',0') │ + ┌└────────────────────────────────────────┘ + (0,0) + + where (0',0') = (0+x-origin,0+y-origin)
What happens if touchscreen-inverted-x/y are set?
Though the existing binding never defines what the non-inverted orientation is.
Quoted 108 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +108
-0+ + type: object + + properties: + x-origin: + description: horizontal origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - x-origin + - y-origin + - x-size + - y-size + + overlay-buttons: + description: list of nodes defining the buttons on the touchscreen + + This object can be used to describe buttons on the touchscreen area, + reporting the touch events on their surface as key events instead of + the original touch events. + + This is of special interest if the touchscreen is shipped with a + physical overlay on top of it where a number of buttons with some + predefined functionality are printed. In that case a specific behavior + is expected from those buttons instead of raw touch events. + + The overlay-buttons properties define a per-button area as well as an + origin relative to the real touchscreen origin. Touch events within the + button area are reported as the key event defined in the linux,code + property. Given that the key events do not provide coordinates, the + button origin is only used to place the button area on the touchscreen + surface. Any event outside the overlay-buttons object is reported as a + touch event with no coordinate transformation. + + The following example shows a touchscreen with a single button on it + + Touchscreen (full area) + ┌───────────────────────────────────┐ + │ │ + │ │ + │ ┌─────────┐ │ + │ │button 0 │ │ + │ │KEY_POWER│ │ + │ └─────────┘ │ + │ │ + │ │ + ┌└───────────────────────────────────┘ + (0,0) + + The overlay-buttons object can be combined with the overlay-touchscreen + object as shown in the following example. In that case only the events + within the overlay-touchscreen object are reported as touch events. + + Touchscreen (full area) + ┌─────────┬──────────────────────────────┐ + │ │ │ + │ │ ┌───────────────────────┐ │ + │ button 0│ │ │ │ + │KEY_POWER│ │ │ │ + │ │ │ │ │ + ├─────────┤ │ overlay-touchscreen │ │ + │ │ │ │ │ + │ │ │ │ │ + │ button 1│ │ │ │ + │ KEY_INFO│ ┌└───────────────────────┘ │ + │ │(0',0') │ + ┌└─────────┴──────────────────────────────┘ + (0,0) + + type: object + + patternProperties: + '^button-': + type: object + description: + Each button (key) is represented as a sub-node. + + properties: + label: + $ref: /schemas/types.yaml#/definitions/string + description: descriptive name of the button + + linux,code: true + + x-origin: + description: horizontal origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 +
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml properties: · line 233
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +10
-0+ y-size: + description: vertical resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - linux,code + - x-origin + - y-origin + - x-size + - y-size
We have the same properties defined twice. Move all the common ones to a $def entry and then reference it here and in overlay-touchscreen.
$defs:
overlay-node:
type: object
properties:
x-origin:
...And then here:
'^button-':
$ref: '#/$defs/overlay-node
unevaluatedProperties: false
properties:
label:
...Rob
Javier Carrasco
maintainerRe: [PATCH v4 2/4] dt-bindings: touchscreen: add overlay-touchscreen and overlay-buttons properties
Hi Rob,
Quoted 59 lines · Rob Herring
Quoted 45 lines · Javier Carrasco
The overlay-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the overlay origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the overlay-buttons object contains a node for every button and the key event that should be reported when pressed.
Signed-off-by Javier Carrasco <[email protected]>--- .../bindings/input/touchscreen/touchscreen.yaml | 152 +++++++++++++++++++++ 1 file changed, 152 insertions(+)Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +23
-0@@ -80,6 +80,158 @@ properties: touchscreen-y-plate-ohms: description: Resistance of the Y-plate in Ohms + overlay-touchscreen: + description: Clipped touchscreen area + + This object can be used to describe a frame that restricts the area + within touch events are reported, ignoring the events that occur outside + this area. This is of special interest if the touchscreen is shipped + with a physical overlay on top of it with a frame that hides some part + of the original touchscreen area. + + The x-origin and y-origin properties of this object define the offset of + a new origin from where the touchscreen events are referenced. + This offset is applied to the events accordingly. The x-size and y-size + properties define the size of the overlay-touchscreen (effective area). + + The following example shows the new touchscreen area and the new origin + (0',0') for the touch events generated by the device. + + Touchscreen (full area) + ┌────────────────────────────────────────┐ + │ ┌───────────────────────────────┐ │ + │ │ │ │ + │ ├ y-size │ │ + │ │ │ │Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml properties: · line 115
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +10
-0+ │ │ overlay-touchscreen │ │ + │ │ │ │ + │ │ │ │ + │ │ x-size │ │ + │ ┌└──────────────┴────────────────┘ │ + │(0',0') │ + ┌└────────────────────────────────────────┘ + (0,0) + + where (0',0') = (0+x-origin,0+y-origin)What happens if touchscreen-inverted-x/y are set?
Quoted 3 lines
Though the existing binding never defines what the non-inverted orientation is.
This feature acts on the raw input values and the inversion is carried out afterwards.The events will be inverted within the defined frame, which is probably the expected behavior.
Quoted 135 lines
Quoted 108 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +108
-0+ + type: object + + properties: + x-origin: + description: horizontal origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - x-origin + - y-origin + - x-size + - y-size + + overlay-buttons: + description: list of nodes defining the buttons on the touchscreen + + This object can be used to describe buttons on the touchscreen area, + reporting the touch events on their surface as key events instead of + the original touch events. + + This is of special interest if the touchscreen is shipped with a + physical overlay on top of it where a number of buttons with some + predefined functionality are printed. In that case a specific behavior + is expected from those buttons instead of raw touch events. + + The overlay-buttons properties define a per-button area as well as an + origin relative to the real touchscreen origin. Touch events within the + button area are reported as the key event defined in the linux,code + property. Given that the key events do not provide coordinates, the + button origin is only used to place the button area on the touchscreen + surface. Any event outside the overlay-buttons object is reported as a + touch event with no coordinate transformation. + + The following example shows a touchscreen with a single button on it + + Touchscreen (full area) + ┌───────────────────────────────────┐ + │ │ + │ │ + │ ┌─────────┐ │ + │ │button 0 │ │ + │ │KEY_POWER│ │ + │ └─────────┘ │ + │ │ + │ │ + ┌└───────────────────────────────────┘ + (0,0) + + The overlay-buttons object can be combined with the overlay-touchscreen + object as shown in the following example. In that case only the events + within the overlay-touchscreen object are reported as touch events. + + Touchscreen (full area) + ┌─────────┬──────────────────────────────┐ + │ │ │ + │ │ ┌───────────────────────┐ │ + │ button 0│ │ │ │ + │KEY_POWER│ │ │ │ + │ │ │ │ │ + ├─────────┤ │ overlay-touchscreen │ │ + │ │ │ │ │ + │ │ │ │ │ + │ button 1│ │ │ │ + │ KEY_INFO│ ┌└───────────────────────┘ │ + │ │(0',0') │ + ┌└─────────┴──────────────────────────────┘ + (0,0) + + type: object + + patternProperties: + '^button-': + type: object + description: + Each button (key) is represented as a sub-node. + + properties: + label: + $ref: /schemas/types.yaml#/definitions/string + description: descriptive name of the button + + linux,code: true + + x-origin: + description: horizontal origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 +Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml properties: · line 233
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +10
-0+ y-size: + description: vertical resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - linux,code + - x-origin + - y-origin + - x-size + - y-sizeWe have the same properties defined twice. Move all the common ones to a $def entry and then reference it here and in overlay-touchscreen.
$defs:
overlay-node:type: object properties: x-origin: ...And then here:
'^button-':
$ref: '#/$defs/overlay-node
unevaluatedProperties: false
Quoted 6 lines
properties:
label: ...Rob
Thank your for your feedback, I will send a next version with this modification in it.
Best regards,
Javier Carrasco
Javier Carrasco
maintainerPATCH v4 3/4 Input: st1232 - add touch overlays handling
In reply to Javier CarrascoUse touch-overlay to support overlay objects such as buttons and resized frames defined in the device tree.
If an 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.
--- drivers/input/touchscreen/st1232.c | 70 ++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 14 deletions(-)
drivers/input/touchscreen/st1232.c +56 -14
@@ -22,6 +22,7 @@#include <linux/pm_qos.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/input/touch-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 touch_overlay_map *overlay_map;const struct st_chip_info *chip_info;int read_buf_len;u8 *read_buf;
@@ -130,6 +133,7 @@ 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 *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 ];
@@ -138,14 +142,20 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts)for (i =0 ; i < ts->chip_info->max_fingers; i++) {u8 *buf = &ts->read_buf[i *4 ]; +bool contact = buf[0 ] &BIT (7 ); +unsigned int x, y; -if (buf[0 ] &BIT (7 )) { -unsigned int x = ((buf[0 ] &0x70 ) <<4 ) | buf[1 ]; -unsigned int y = ((buf[0 ] &0x07 ) <<8 ) | buf[2 ]; - -touchscreen_set_mt_pos (&pos[n_contacts], - &ts->prop, x, y); +if (contact) { + x = ((buf[0 ] &0x70 ) <<4 ) | buf[1 ]; + y = ((buf[0 ] &0x07 ) <<8 ) | buf[2 ]; + } +if (touch_overlay_process_event (ts->overlay_map, keypad, + contact ? &x :NULL , + contact ? &y :NULL , i)) +continue ; +if (contact) { +touchscreen_set_mt_pos (&pos[n_contacts], &ts->prop, x, y);/* st1232 includes a z-axis / touch strength */ if (ts->chip_info->have_z) z[n_contacts] = ts->read_buf[i +6 ];
@@ -226,6 +236,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 *overlay_keypad;u16 max_x, max_y;int error;
@@ -263,8 +274,13 @@ static int st1232_ts_probe(struct i2c_client *client)if (!input_dev)return -ENOMEM ; + overlay_keypad =devm_input_allocate_device (&client->dev); +if (!overlay_keypad) +return -ENOMEM ; + ts->client = client; ts->input_dev = input_dev; + ts->overlay_keypad = overlay_keypad; ts->reset_gpio =devm_gpiod_get_optional (&client->dev,NULL ,GPIOD_OUT_HIGH );
@@ -286,24 +302,37 @@ static int st1232_ts_probe(struct i2c_client *client) input_dev->name ="st1232-touchscreen" ; input_dev->id.bustype =BUS_I2C ; + overlay_keypad->name ="st1232-keypad" ; + overlay_keypad->id.bustype =BUS_I2C ;/* Wait until device is ready */ error =st1232_ts_wait_ready (ts);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->overlay_map =touch_overlay_map_overlay (ts->overlay_keypad); +if (IS_ERR (ts->overlay_map)) +return PTR_ERR (ts->overlay_map); + +if (touch_overlay_mapped_touchscreen (ts->overlay_map)) { +/* Read resolution from the overlay touchscreen if defined */ +touch_overlay_get_touchscreen_abs (ts->overlay_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 +364,19 @@ static int st1232_ts_probe(struct i2c_client *client)return error; } +/* Register keypad input device if overlay buttons were defined */ +if (touch_overlay_mapped_buttons (ts->overlay_map)) { + 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; + } + }else { +input_free_device (ts->overlay_keypad); + } +i2c_set_clientdata (client, ts);return 0 ;
Signature · 1 line
2.39.2
Javier Carrasco
maintainerPATCH v4 4/4 dt-bindings: input: touchscreen: st1232: add example with touch-overlay
In reply to Javier CarrascoThe st1232 driver supports the overlay-touchscreen and overlay-buttons objects defined in the generic touchscreen bindings and implemented in the touch-overlay module. Add an example where nodes for an overlay touchscreen and overlay buttons are defined.
--- .../input/touchscreen/sitronix,st1232.yaml | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +40 -0
@@ -48,3 +48,43 @@ examples: gpios = <&gpio1 166 0>; }; }; + - | + #include <dt-bindings/input/linux-event-codes.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@55 { + compatible = "sitronix,st1232"; + reg = <0x55>; + interrupts = <2 0>; + gpios = <&gpio1 166 0>; + + overlay-touchscreen { + x-origin = <0>; + x-size = <240>; + y-origin = <40>; + y-size = <280>; + }; + + overlay-buttons { + button-light { + label = "Camera light"; + linux,code = <KEY_LIGHTS_TOGGLE>; + x-origin = <40>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + + button-power { + label = "Power"; + linux,code = <KEY_POWER>; + x-origin = <160>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + }; + }; + };
Signature · 1 line
2.39.2
Rob Herring
maintainerRe: [PATCH v4 4/4] dt-bindings: input: touchscreen: st1232: add example with touch-overlay
Quoted 19 lines · Javier Carrasco
The st1232 driver supports the overlay-touchscreen and overlay-buttons objects defined in the generic touchscreen bindings and implemented in the touch-overlay module. Add an example where nodes for an overlay touchscreen and overlay buttons are defined.
Signed-off-by Javier Carrasco <[email protected]>--- .../input/touchscreen/sitronix,st1232.yaml | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+)Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +1
-0@@ -48,3 +48,43 @@ examples: gpios = <&gpio1 166 0>; }; }; + - |
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml examples: · line 61
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +10
-0+ #include <dt-bindings/input/linux-event-codes.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@55 { + compatible = "sitronix,st1232"; + reg = <0x55>; + interrupts = <2 0>; + gpios = <&gpio1 166 0>;
Just add this to the existing example. No value in 2 examples.
Quoted 33 lines
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +29
-0+ + overlay-touchscreen { + x-origin = <0>; + x-size = <240>; + y-origin = <40>; + y-size = <280>; + }; + + overlay-buttons { + button-light { + label = "Camera light"; + linux,code = <KEY_LIGHTS_TOGGLE>; + x-origin = <40>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + + button-power { + label = "Power"; + linux,code = <KEY_POWER>; + x-origin = <160>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + }; + }; + };Signature · 2 lines
-- 2.39.2