Skip to contentSkip to conversation

dt-bindings: input: touchscreen: add hynitron cst816x

PATCH Superseded Oleh Kuzhylnyi 3 participants 4 messages Jun 29, 2025 – Jul 1, 2025

Subsystems (3)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v8 1/2 dt-bindings: input: touchscreen: add hynitron cst816x

Add documentation for Hynitron CST816x series touchscreen bindings.

---
Changes in v8:
- Use linux,keycodes to map touch gestures to key events
- Refactore binding properties based on feedback from Jeff LaBundy and Krzysztof Kozlowski to align with official documentation

Changes in v7:
- Introduce the gestures field along with its sub-fields
- Make reset-gpio property optional
- Extend main description
- Remove "touchscreen" reference

Changes in v6:
- Fix minor tweak adviced by Krzysztof:
- Move additionalProperties field after required

Changes in v5:
- No code changes

Changes in v4:
- Add Conor's Dooley "Reviewed-by" tag

Changes in v3:
- Rename filename to hynitron,cst816s.yaml
- Update description with display details

Changes in v2:
- Apply pin definitions and DT headers
- Use generic name for DT node
- Drop status field

 .../input/touchscreen/hynitron,cst816x.yaml   | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +82 -0
new file mode 100644
index 000000000000..0d358463d7f8
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/hynitron,cst816x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Hynitron CST816x Series Capacitive Touch controller
+
+maintainers:
+  - Oleh Kuzhylnyi <[email protected]>
+
+description: |
+  Bindings for CST816x high performance self-capacitance touch chip series
+  with single point gesture and real two-point operation.
+
+properties:
+  compatible:
+    enum:
+      - hynitron,cst816s
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  linux,keycodes:
+    minItems: 1
+    maxItems: 16
+    description: |
+      Specifies the numeric keycodes associated with each available gesture in
+      the following order (enter 0 for unused and reserved gestures):
+      0: Touch
+      1: Swipe up
+      2: Swipe down
+      3: Swipe left
+      4: Swipe right
+      5-11: Reserved
+      12: Long press
+      13-15: Reserved
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+          #address-cells = <1>;
+          #size-cells = <0>;
+          touchscreen@15 {
+              compatible = "hynitron,cst816s";
+              reg = <0x15>;
+              interrupt-parent = <&gpio0>;
+              interrupts = <4 IRQ_TYPE_EDGE_RISING>;
+              reset-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
+              linux,keycodes = <BTN_TOUCH>,
+                               <KEY_UP>,
+                               <KEY_DOWN>,
+                               <KEY_LEFT>,
+                               <KEY_RIGHT>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <KEY_RESERVED>,
+                               <BTN_TOOL_TRIPLETAP>;
+          };
+    };
+
+...
Signature · 1 line
2.34.1
#1 lore raw

PATCH v8 2/2 input: add hynitron cst816x series touchscreen

Introduce support for the Hynitron CST816X series touchscreen controller used for 240×240 1.28-inch Round LCD Display Module manufactured by Waveshare Electronics. The driver is designed based on an Arduino implementation marked as under MIT License. This driver is written for a particular round display based on the CST816S controller, which is not compatiable with existing driver for Hynitron controllers.

---
Changes in v8:
- Add array of Linux input event codes to map gestures in DT bindings
- Reword function names and error messages
- Wrap coordinates reporting between touch press and release
- Minor reword in Kconfig

Changes in v7:
- Update commit based on Jeffs's feedback:
- Move event_map table to Device Tree
- Implement DT parsing functionality
- Use "int" type for iterators
- Get rid of "*dev" entry from private struct
- Use touch_info directly as a buffer for I2C
- Fix coding style tweaks

Changes in v6:
- No code changes

Changes in v5:
- Update commit based on Dmitry's feedback:
- Make GPIO reset optional
- Combine declaration and initialization for i2c_xfer
- Return 0 explicitly where possible
- Rename rc (return code) to error
- Make Touch processing call return boolean
- Improve error handling for i2c_transfer
- Use get_unaligned_be16 for getting coordinates
- Move touch event completeness upper to irq callback

Changes in v4:
- Update commit based on Dmitry's feedback:
- Move abs_x and abs_y to u16
- Remove __packed qualifier for touch_info struct
- Hide tiny touch irq context to stack
- Extend cst816x_i2c_read_register() with buf and buf_size
- Remove loop from event lookup

Changes in v3:
- Drop timer and delayed work
- Process touch in threaded IRQ context
- Fix chip reset sequence
- Move input_register() before devm_request_threaded_irq()
- Re-arrange and document input reporting
- Set u16 data type for event_code
- Remove double tap event to prevent continuous double side sliding

Changes in v2:
- Apply dev_err_probe() for better error handling
- Remove redundant printing, remove dev_warn() message spamming
- Get rid of PM since the touchscreen goes into sleep mode automatically
- Get rid of IRQ control and IRQF_NO_AUTOEN flag
- Reduce timer timeout up to 10ms to handle touch events faster
- Skip registering of non-gesture CST816X_SWIPE event
- Shift input_register_device() as a final call in probe() callback
- Specify name of i2c_device_id explicitly
- Update module description and fix typo
- Add necessary spaces between lines

 drivers/input/touchscreen/Kconfig            |  12 +
 drivers/input/touchscreen/Makefile           |   1 +
 drivers/input/touchscreen/hynitron-cst816x.c | 227 +++++++++++++++++++
 3 files changed, 240 insertions(+)
 create mode 100644 drivers/input/touchscreen/hynitron-cst816x.c
drivers/input/touchscreen/Kconfig +12 -0
index 91a2b584dab1..c2c115804c92 100644
@@ -466,6 +466,18 @@ config TOUCHSCREEN_HYNITRON_CSTXXX
 	  To compile this driver as a module, choose M here: the
 	  module will be called hynitron-cstxxx.
 
+config TOUCHSCREEN_HYNITRON_CST816X
+	tristate "Hynitron CST816x touchscreen"
+	depends on I2C
+	help
+	  Say Y here if you have a touchscreen using a Hynitron
+	  CST816x series touchscreen controller.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called hynitron-cst816x.
+
 config TOUCHSCREEN_ILI210X
 	tristate "Ilitek ILI210X based touchscreen"
 	depends on I2C
drivers/input/touchscreen/Makefile +1 -0
index 97a025c6a377..6805ab60f016 100644
@@ -50,6 +50,7 @@ obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_I2C)	+= goodix_berlin_i2c.o
 obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_SPI)	+= goodix_berlin_spi.o
 obj-$(CONFIG_TOUCHSCREEN_HIDEEP)	+= hideep.o
 obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX)	+= hynitron_cstxxx.o
+obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CST816X)	+= hynitron-cst816x.o
 obj-$(CONFIG_TOUCHSCREEN_ILI210X)	+= ili210x.o
 obj-$(CONFIG_TOUCHSCREEN_ILITEK)	+= ilitek_ts_i2c.o
 obj-$(CONFIG_TOUCHSCREEN_IMAGIS)	+= imagis.o
drivers/input/touchscreen/hynitron-cst816x.c new file +227 -0

227 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v8 2/2] input: add hynitron cst816x series touchscreen

kernel test robot noticed the following build warnings:

Hi Oleh,

kernel test robot noticed the following build warnings:

[auto build test WARNING on dtor-input/next]
[also build test WARNING on dtor-input/for-linus robh/for-next krzk-dt/for-next linus/master v6.16-rc4 next-20250630] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Oleh-Kuzhylnyi/input-add-hynitron-cst816x-series-touchscreen/20250630-002723
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
patch link:    https://lore.kernel.org/r/20250629162523.291887-2-kuzhylol%40gmail.com
patch subject: [PATCH v8 2/2] input: add hynitron cst816x series touchscreen
config: microblaze-randconfig-r131-20250701 (https://download.01.org/0day-ci/archive/20250701/[email protected]/config)
compiler: microblaze-linux-gcc (GCC) 15.1.0
reproduce: (https://download.01.org/0day-ci/archive/20250701/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/input/touchscreen/hynitron-cst816x.c:97:21: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] abs_x @@     got unsigned long @@
   drivers/input/touchscreen/hynitron-cst816x.c:97:21: sparse:     expected restricted __be16 [usertype] abs_x
   drivers/input/touchscreen/hynitron-cst816x.c:97:21: sparse:     got unsigned long
>> drivers/input/touchscreen/hynitron-cst816x.c:98:21: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] abs_y @@     got unsigned long @@
   drivers/input/touchscreen/hynitron-cst816x.c:98:21: sparse:     expected restricted __be16 [usertype] abs_y
   drivers/input/touchscreen/hynitron-cst816x.c:98:21: sparse:     got unsigned long
>> drivers/input/touchscreen/hynitron-cst816x.c:148:58: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected int value @@     got restricted __be16 [addressable] [usertype] abs_x @@
   drivers/input/touchscreen/hynitron-cst816x.c:148:58: sparse:     expected int value
   drivers/input/touchscreen/hynitron-cst816x.c:148:58: sparse:     got restricted __be16 [addressable] [usertype] abs_x
>> drivers/input/touchscreen/hynitron-cst816x.c:149:58: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected int value @@     got restricted __be16 [addressable] [usertype] abs_y @@

drivers/input/touchscreen/hynitron-cst816x.c:149:58: sparse: expected int value
drivers/input/touchscreen/hynitron-cst816x.c:149:58: sparse: got restricted __be16 [addressable] [usertype] abs_y

vim +97 drivers/input/touchscreen/hynitron-cst816x.c

    90	
    91	static bool cst816x_process_touch(struct cst816x_priv *priv,
    92					  struct cst816x_touch_desc *desc)
    93	{
    94		if (cst816x_i2c_read_register(priv, CST816X_RD_REG, desc, sizeof(*desc)))
    95			return false;
    96	
  > 97		desc->abs_x = get_unaligned_be16(&desc->abs_x) & GENMASK(11, 0);
  > 98		desc->abs_y = get_unaligned_be16(&desc->abs_y) & GENMASK(11, 0);
    99	
   100		dev_dbg(&priv->client->dev, "x: %u, y: %u, t: %u, g: 0x%x\n",
   101			desc->abs_x, desc->abs_y, desc->touch, desc->gesture);
   102	
   103		return true;
   104	}
   105	
   106	static int cst816x_register_input(struct cst816x_priv *priv)
   107	{
   108		priv->input = devm_input_allocate_device(&priv->client->dev);
   109		if (!priv->input)
   110			return -ENOMEM;
   111	
   112		priv->input->name = "Hynitron CST816x Series Touchscreen";
   113		priv->input->phys = "input/ts";
   114		priv->input->id.bustype = BUS_I2C;
   115		input_set_drvdata(priv->input, priv);
   116	
   117		input_set_abs_params(priv->input, ABS_X, 0, 240, 0, 0);
   118		input_set_abs_params(priv->input, ABS_Y, 0, 240, 0, 0);
   119	
   120		for (int i = 0; i < priv->keycodemax; i++) {
   121			if (priv->keycode[i] == KEY_RESERVED)
   122				continue;
   123	
   124			input_set_capability(priv->input, EV_KEY, priv->keycode[i]);
   125		}
   126	
   127		return input_register_device(priv->input);
   128	}
   129	
   130	static void cst816x_reset(struct cst816x_priv *priv)
   131	{
   132		gpiod_set_value_cansleep(priv->reset, 1);
   133		msleep(50);
   134		gpiod_set_value_cansleep(priv->reset, 0);
   135		msleep(100);
   136	}
   137	
   138	static irqreturn_t cst816x_irq_cb(int irq, void *cookie)
   139	{
   140		struct cst816x_priv *priv = cookie;
   141		struct cst816x_touch_desc desc;
   142	
   143		if (!cst816x_process_touch(priv, &desc))
   144			return IRQ_HANDLED;
   145	
   146		if (desc.touch) {
   147			input_report_key(priv->input, priv->keycode[CST816X_TOUCH], 1);
 > 148			input_report_abs(priv->input, ABS_X, desc.abs_x);
 > 149			input_report_abs(priv->input, ABS_Y, desc.abs_y);

150 }
151
152 if (desc.gesture) {
153 input_report_key(priv->input, priv->keycode[desc.gesture & 0x0F],
154 desc.touch);
155
156 if (!desc.touch)
157 input_report_key(priv->input,
158 priv->keycode[CST816X_TOUCH], 0);
159 }
160
161 input_sync(priv->input);
162
163 return IRQ_HANDLED;
164 }
165

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw
In reply to Oleh Kuzhylnyi
Quoted 8 lines · Oleh Kuzhylnyi

Add documentation for Hynitron CST816x series touchscreen bindings.

---
Changes in v8:
- Use linux,keycodes to map touch gestures to key events
- Refactore binding properties based on feedback from Jeff LaBundy and Krzysztof Kozlowski to align with official documentation

This is vague. Anything can be "refactor". What changed specifically?

b4 diff shows no changes.

Quoted 69 lines

Changes in v7:
- Introduce the gestures field along with its sub-fields
- Make reset-gpio property optional
- Extend main description
- Remove "touchscreen" reference

Changes in v6:
- Fix minor tweak adviced by Krzysztof:
- Move additionalProperties field after required

Changes in v5:
- No code changes

Changes in v4:
- Add Conor's Dooley "Reviewed-by" tag

Changes in v3:
- Rename filename to hynitron,cst816s.yaml
- Update description with display details

Changes in v2:
- Apply pin definitions and DT headers
- Use generic name for DT node
- Drop status field

 .../input/touchscreen/hynitron,cst816x.yaml   | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +33 -0
new file mode 100644
index 000000000000..0d358463d7f8
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/hynitron,cst816x.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Hynitron CST816x Series Capacitive Touch controller
+
+maintainers:
+  - Oleh Kuzhylnyi <[email protected]>
+
+description: |
+  Bindings for CST816x high performance self-capacitance touch chip series
+  with single point gesture and real two-point operation.
+
+properties:
+  compatible:
+    enum:
+      - hynitron,cst816s
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  linux,keycodes:
+    minItems: 1
+    maxItems: 16
+    description: |

Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml line 43

Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +10 -0
+      Specifies the numeric keycodes associated with each available gesture in
+      the following order (enter 0 for unused and reserved gestures):
+      0: Touch
+      1: Swipe up
+      2: Swipe down
+      3: Swipe left
+      4: Swipe right
+      5-11: Reserved
+      12: Long press
+      13-15: Reserved

Fields like "reserved" makes no sense. If this is reserved, why would it be put into the DTS?

No, just list the items with description:
minItems: 1
items:
- description: Touch gesture (although what is a touch gesture? This
is just a touch....)
- description: ...

Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml line 48

Quoted 5 lines
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +5 -0
+
+required:
+  - compatible
+  - reg
+  - interrupts

Where is (or why there is no) the ref to touchscreen.yaml?

Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml line 50

Quoted 2 lines
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +2 -0
+
+additionalProperties: false

And this not unevaluatedProperties then?

Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml line 59

Quoted 9 lines
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +9 -0
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/input/linux-event-codes.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+          #address-cells = <1>;
+          #size-cells = <0>;

Messed indentation.

Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml line 66

Quoted 7 lines
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816x.yaml new file +7 -0
+          touchscreen@15 {
+              compatible = "hynitron,cst816s";
+              reg = <0x15>;
+              interrupt-parent = <&gpio0>;
+              interrupts = <4 IRQ_TYPE_EDGE_RISING>;
+              reset-gpios = <&gpio 17 GPIO_ACTIVE_LOW>;
+              linux,keycodes = <BTN_TOUCH>,

Best regards,
Krzysztof