dt-bindings: input: touchscreen: add Hynitron CST816X
Subsystems (3)
PATCH v3 1/2 dt-bindings: input: touchscreen: add Hynitron CST816X
Add documentation for the Hynitron CST816X touchscreen bindings.
---
Changes in v3:
- Rename filename to hynitron,cst816s.yaml
- Update description with display details
.../input/touchscreen/hynitron,cst816s.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816s.yaml
Documentation/devicetree/bindings/input/touchscreen/hynitron,cst816s.yaml new file +57 -0
@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/hynitron,cst816s.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hynitron CST816S Touchscreen controller + +description: + Hynitron CST816S Touchscreen controller for 1.28-inch 240x240 Resolution + Touch LCD Display Module + +maintainers: + - Oleh Kuzhylnyi <[email protected]> + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + enum: + - hynitron,cst816s + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + +additionalProperties: false + +required: + - compatible + - reg + - interrupts + - reset-gpios + +examples: + - | + #include <dt-bindings/gpio/gpio.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>; + }; + }; + +...
Signature · 1 line
2.34.1
PATCH v3 2/2 input: add driver for Hynitron CST816X touchscreen
Introduce support for the Hynitron CST816X 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 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
drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/hynitron-cst816x.c | 257 +++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 drivers/input/touchscreen/hynitron-cst816x.c
drivers/input/touchscreen/Kconfig +12 -0
@@ -481,6 +481,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 support" + depends on I2C + help + Say Y here if you have a touchscreen using a Hynitron + CST816X 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
@@ -51,6 +51,7 @@ obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE) += goodix_berlin_core.o 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_CST816X) += hynitron-cst816x.o obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o obj-$(CONFIG_TOUCHSCREEN_ILITEK) += ilitek_ts_i2c.o
drivers/input/touchscreen/hynitron-cst816x.c new file +257 -0
257 lines not on this page · raw message
Signature · 1 line
2.34.1
Dmitry Torokhov
maintainerRe: [PATCH v3 2/2] input: add driver for Hynitron CST816X touchscreen
Hi Oleh,
Quoted 88 lines · Oleh Kuzhylnyi
Introduce support for the Hynitron CST816X 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.
Signed-off-by Oleh Kuzhylnyi <[email protected]>---
Changes in v3:
- Drop timer and delayed work
- Process touch in threaded IRQ context
- Fix chip reset sequence
- Moveinput_register()beforedevm_request_threaded_irq()
- Re-arrange and document input reporting
- Set u16 data type forevent_code
- Remove double tap event to prevent continuous double side slidingdrivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/hynitron-cst816x.c | 257 +++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 drivers/input/touchscreen/hynitron-cst816x.cdrivers/input/touchscreen/Kconfig +12
-0@@ -481,6 +481,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 support" + depends on I2C + help + Say Y here if you have a touchscreen using a Hynitron + CST816X 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 I2Cdrivers/input/touchscreen/Makefile +1
-0@@ -51,6 +51,7 @@ obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE) += goodix_berlin_core.o 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_CST816X) += hynitron-cst816x.o obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o obj-$(CONFIG_TOUCHSCREEN_ILITEK) += ilitek_ts_i2c.odrivers/input/touchscreen/hynitron-cst816x.c new file +22
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Driver for I2C connected Hynitron CST816X Touchscreen +* +* Copyright (C) 2024 Oleh Kuzhylnyi <[email protected]> +*/ +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/gpio/consumer.h> +#include <linux/i2c.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/module.h> + +enum cst816x_registers { +CST816X_FRAME =0x01 , +CST816X_MOTION =0xEC , +}; + +enum cst816x_gestures { +CST816X_SWIPE_UP =0x01 , +CST816X_SWIPE_DOWN =0x02 ,
drivers/input/touchscreen/hynitron-cst816x.c line 32
Quoted 10 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +10
-0+CST816X_SWIPE_LEFT =0x03 , +CST816X_SWIPE_RIGHT =0x04 , +CST816X_SINGLE_TAP =0x05 , + CST816X_LONG_PRESS = 0x0C, +}; + +struct cst816x_touch_info { +u8 gesture; +u8 touch; +u8 abs_x;
Is this the right size? You are doing:
priv->info.abs_x = ((raw[2] & 0x0F) << 8) | raw[3];
Which suggests it should be u16?
drivers/input/touchscreen/hynitron-cst816x.c line 34
Quoted 2 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +2
-0+u8 abs_y; +} __packed;
Why does this need to be __packed?
drivers/input/touchscreen/hynitron-cst816x.c line 41
Quoted 7 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +7
-0+ +struct cst816x_priv { +struct device *dev; +struct i2c_client *client; +struct gpio_desc *reset; +struct input_dev *input; +struct cst816x_touch_info info;
Why do you need to have this here? It is tiny and does not need to be kept around, just use on stack variable.
Quoted 9 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +9
-0+ +u8 rxtx[8 ]; +}; + +struct cst816x_event_mapping { +enum cst816x_gestures gesture; +u16 event_code; +}; +
drivers/input/touchscreen/hynitron-cst816x.c line 60
Quoted 10 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +10
-0+static const struct cst816x_event_mapping cst816x_event_map[] = { + {CST816X_SWIPE_UP ,BTN_FORWARD }, + {CST816X_SWIPE_DOWN ,BTN_BACK }, + {CST816X_SWIPE_LEFT ,BTN_LEFT }, + {CST816X_SWIPE_RIGHT ,BTN_RIGHT }, + {CST816X_SINGLE_TAP ,BTN_TOUCH }, + {CST816X_LONG_PRESS ,BTN_TOOL_TRIPLETAP } +}; + +static int cst816x_i2c_read_register (struct cst816x_priv *priv,u8 reg)
Maybe supply buffer and size as arguments?
Quoted 9 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +9
-0+{ +struct i2c_client *client; +struct i2c_msg xfer[2 ]; +int rc; + + client = priv->client; + + xfer[0 ].addr = client->addr; + xfer[0 ].flags =0 ;
drivers/input/touchscreen/hynitron-cst816x.c line 79
Quoted 10 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +10
-0+ xfer[0 ].len =sizeof (reg); + xfer[0 ].buf = ® + + xfer[1 ].addr = client->addr; + xfer[1 ].flags =I2C_M_RD ; + xfer[1 ].len =sizeof (priv->rxtx); + xfer[1 ].buf = priv->rxtx; + + rc =i2c_transfer (client->adapter, xfer,ARRAY_SIZE (xfer)); +if (rc !=ARRAY_SIZE (xfer)) {
error = rc >= 0 ? -EIO : rc; dev_err(...); return error; } return 0;
Quoted 62 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +62
-0+if (rc >=0 ) + rc = -EIO ; + }else { + rc =0 ; + } + +if (rc <0 ) +dev_err (&client->dev,"i2c rx err: %d\n" , rc); + +return rc; +} + +static int cst816x_process_touch (struct cst816x_priv *priv) +{ +u8 *raw; +int rc; + + rc =cst816x_i2c_read_register (priv,CST816X_FRAME ); +if (!rc) { + raw = priv->rxtx; + + priv->info.gesture = raw[0 ]; + priv->info.touch = raw[1 ]; + priv->info.abs_x = ((raw[2 ] &0x0F ) <<8 ) | raw[3 ]; + priv->info.abs_y = ((raw[4 ] &0x0F ) <<8 ) | raw[5 ]; + +dev_dbg (priv->dev,"x: %d, y: %d, t: %d, g: 0x%x\n" , + priv->info.abs_x, priv->info.abs_y, priv->info.touch, + priv->info.gesture); + } + +return rc; +} + +static int cst816x_register_input (struct cst816x_priv *priv) +{ + priv->input =devm_input_allocate_device (priv->dev); +if (!priv->input) +return -ENOMEM ; + + priv->input->name ="Hynitron CST816X Touchscreen" ; + priv->input->phys ="input/ts" ; + priv->input->id.bustype =BUS_I2C ; +input_set_drvdata (priv->input, priv); + +for (unsigned int i =0 ; i <ARRAY_SIZE (cst816x_event_map); i++) { +input_set_capability (priv->input,EV_KEY , + cst816x_event_map[i].event_code); + } + +input_set_abs_params (priv->input,ABS_X ,0 ,240 ,0 ,0 ); +input_set_abs_params (priv->input,ABS_Y ,0 ,240 ,0 ,0 ); + +return input_register_device (priv->input); +} + +static void cst816x_reset (struct cst816x_priv *priv) +{ +gpiod_set_value_cansleep (priv->reset,1 ); +msleep (50 ); +gpiod_set_value_cansleep (priv->reset,0 ); +msleep (100 );
drivers/input/touchscreen/hynitron-cst816x.c line 151
Quoted 10 lines
drivers/input/touchscreen/hynitron-cst816x.c new file +10
-0+} + +static void report_gesture_event (const struct cst816x_priv *priv, +enum cst816x_gestures gesture,bool touch) +{ +for (unsigned int i =0 ; i <ARRAY_SIZE (cst816x_event_map); i++) { +if (cst816x_event_map[i].gesture == gesture) { +input_report_key (priv->input, + cst816x_event_map[i].event_code, + touch);
If you make cst816x_event_map an array of 16 entries with unised positions mapped to KEY_RESERVED you can do:
key = cst816x_event_map[raw[0] & 0x0f]; if (key != KEY_RESERVED) input_report_key(priv->input, key, touch);
and you do not need to loop.
Thanks.
Signature · 1 line
Dmitry
Quoted 4 lines · Oleh Kuzhylnyi
Add documentation for the Hynitron CST816X touchscreen bindings.
Signed-off-by Oleh Kuzhylnyi <[email protected]>---
This is a friendly reminder during the review process.
It looks like you received a tag and forgot to add it.
If you do not know the process, here is a short explanation:
Please add Acked-by/Reviewed-by/Tested-by tags when posting new versions, under or above your Signed-off-by tag. Tag is "received", when provided in a message replied to you on the mailing list. Tools like b4 can help here. However, there's no need to repost patches *only* to add the tags. The upstream maintainer will do that for tags received on the version they apply.
https://elixir.bootlin.com/linux/v6.5-rc3/source/Documentation/process/submitting-patches.rst#L577
If a tag was not added on purpose, please state why and what changed.
Best regards,
Krzysztof