Add Nsiway NS2009 touchscreen support
Subsystems (3)
cover Add Nsiway NS2009 touchscreen support
Add polling support for the Nsiway NS2009 I2C resistive touchscreen controller, together with its vendor prefix and DT binding. Coordinates are 12-bit ADC readings; raw Z1 is used only to detect contact. The driver uses a 30 ms polling interval and the common touchscreen transforms.
The implementation derives from Icenowy Zheng's 2017 polling driver [1]. It uses the current input polling API and managed input allocation, with no private copy of the input core's touch-key state. Failed, short or malformed I2C reads release the current contact and discard coordinates; a later valid sample can report a new contact. A transient read error can therefore cause a pen-up rather than retain an indefinitely active contact.
The driver checks the zero padding in the second byte of a 12-bit response, as specified by the read-command format. Responses with nonzero padding are rejected before the decoded value is assigned.
The historical Z1 threshold of 80 remains the default. Boards can override it with touchscreen-min-pressure; the tested UNIHIKER M10 V1.2 uses 150. IRQ, wakeup and calibrated pressure reporting are outside this series. Board DTS changes are also separate.
Validation:
- Latest mainline base: ARM64 driver-object build with W=1, and in-tree dt_binding_check for the unchanged NS2009 binding.
- UNIHIKER M10 V1.2, Linux 6.18: clicks, long presses, directed drags, axis orientation, release, and three held-contact inhibit/uninhibit cycles. A validation module changed only the driver registration name to replace the existing built-in driver; the read/poll/probe code is the same as this series. The boot Image and DTB were retained.
- Two malformed Z1 responses were rejected during the physical run; subsequent contacts were reported normally without stuck key state.
- Controlled read/poll/probe tests with ASan/UBSan cover all 4096 valid ADC values, every nonzero padding nibble on Z1/X/Y, threshold bounds, malformed properties, core key resets, short/failed reads and recovery.
Physical NACK/short-read fault injection and system suspend/resume were not tested. This is a new three-patch series, not a continuation of the board-specific BSP changes.
[1] https://lore.kernel.org/all/[email protected]/
Mizuno Miotsuki (3):
dt-bindings: vendor-prefixes: add Nsiway
dt-bindings: input: touchscreen: add Nsiway NS2009
Input: add Nsiway NS2009 resistive touchscreen driver
.../input/touchscreen/nsiway,ns2009.yaml | 64 +++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 7 + drivers/input/touchscreen/Kconfig | 10 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/ns2009.c | 175 ++++++++++++++++++ 6 files changed, 259 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml create mode 100644 drivers/input/touchscreen/ns2009.c
base-commit: af32da41b0327b9c6a37856ba82b6760d6c8d10e
PATCH 1/3 dt-bindings: vendor-prefixes: add Nsiway
Nsiway manufactures the NS2009 I2C resistive touchscreen controller. Add its vendor prefix for the touchscreen binding.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1214,6 +1214,8 @@ patternProperties: description: Novatek "^novtech,.*": description: NovTech, Inc. + "^nsiway,.*": + description: Shenzhen Nsiway Technology Co., Ltd. "^nuclei,.*": description: Nuclei System Technology "^numonyx,.*":
Re: [PATCH 1/3] dt-bindings: vendor-prefixes: add Nsiway
Quoted 4 lines · Miotsuki Mizuno
Nsiway manufactures the NS2009 I2C resistive touchscreen controller. Add its vendor prefix for the touchscreen binding.
Signed-off-by Mizuno Miotsuki <[email protected]>
Honestly, how mismatch can happen? git commit --signoff
Please run scripts/checkpatch.pl on the patches and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' on the patches and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
Best regards,
Krzysztof
PATCH 2/3 dt-bindings: input: touchscreen: add Nsiway NS2009
In reply to Miotsuki MizunoDescribe the Nsiway NS2009 four-wire resistive touchscreen controller and the properties used by its polling driver.
The controller returns 12-bit ADC coordinates. Use the common touchscreen properties for coordinate ranges and orientation, and allow boards to set the raw Z1 contact threshold through touchscreen-min-pressure. Limit that threshold to 1..4095 because zero cannot distinguish a released contact.
Document the historical default of 80 and a board override of 150 in the example. The Z1 threshold is for contact detection, not calibrated pressure.
--- .../input/touchscreen/nsiway,ns2009.yaml | 64 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +64 -0
@@ -0,0 +1,64 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/nsiway,ns2009.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nsiway NS2009 resistive touchscreen controller + +maintainers: + - Mizuno Miotsuki <[email protected]> + +description: | + The NS2009 is a four-wire resistive touchscreen controller connected over + I2C. This binding describes polling operation without a pen interrupt. + Coordinates are 12-bit ADC readings, not display pixel coordinates. + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + const: nsiway,ns2009 + + reg: + maxItems: 1 + + touchscreen-min-pressure: + minimum: 1 + maximum: 4095 + default: 80 + description: + Minimum raw Z1 reading considered a touch. This is a contact detection + threshold, not a calibrated pressure value. Boards may require a higher + empirically determined threshold than the historical driver default. + + touchscreen-min-x: true + touchscreen-min-y: true + touchscreen-size-x: true + touchscreen-size-y: true + touchscreen-fuzz-x: true + touchscreen-fuzz-y: true + touchscreen-inverted-x: true + touchscreen-inverted-y: true + touchscreen-swapped-x-y: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@48 { + compatible = "nsiway,ns2009"; + reg = <0x48>; + touchscreen-min-pressure = <150>; + touchscreen-inverted-y; + }; + };
MAINTAINERS +6 -0
@@ -19467,6 +19467,12 @@ S: Maintained F: Documentation/core-api/symbol-namespaces.rst F: scripts/nsdeps +NSIWAY NS2009 TOUCHSCREEN CONTROLLER +M: Mizuno Miotsuki <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml + NTB AMD DRIVER M: Basavaraj Natikar <[email protected]> M: Shyam Sundar S K <[email protected]>
Dmitry Torokhov
maintainerRe: [PATCH 2/3] dt-bindings: input: touchscreen: add Nsiway NS2009
Hi Miotsuki,
Quoted 14 lines · Miotsuki Mizuno
Describe the Nsiway NS2009 four-wire resistive touchscreen controller and the properties used by its polling driver.
The controller returns 12-bit ADC coordinates. Use the common touchscreen properties for coordinate ranges and orientation, and allow boards to set the raw Z1 contact threshold through touchscreen-min-pressure. Limit that threshold to 1..4095 because zero cannot distinguish a released contact.
Document the historical default of 80 and a board override of 150 in the example. The Z1 threshold is for contact detection, not calibrated pressure.
Signed-off-by Mizuno Miotsuki <[email protected]>---
...
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml line 15
Quoted 4 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +4
-0+description: | + The NS2009 is a four-wire resistive touchscreen controller connected over + I2C. This binding describes polling operation without a pen interrupt. + Coordinates are 12-bit ADC readings, not display pixel coordinates.
Devicetree bindings should describe the hardware itself rather than the subset of features currently used by the Linux driver. According to the NS2009 datasheet, the controller has several hardware signals and capabilities that should be covered in the binding from the start (even if the initial driver operates in polling mode):
- interrupts (maxItems: 1) and wakeup-source: the controller provides an active-low pen interrupt output, which can remain optional for boards where the line is left unconnected.
- vdd-supply and vref-supply: main power supply and external reference voltage regulators.
- touchscreen-x-plate-ohms (along with touchscreen-max-pressure and touchscreen-fuzz-pressure): the NS2009 supports touch resistance calculation from Z1/Z2 and X-plate resistance.
Could you expand the binding description and properties (and show an interrupt/supply example as well) so we do not have to revisit the binding when IRQ or pressure support is added later?
Thanks.
Signature · 1 line
Dmitry
PATCH 3/3 Input: add Nsiway NS2009 resistive touchscreen driver
In reply to Miotsuki MizunoAdd polling support for the Nsiway NS2009 I2C touchscreen controller using the input polling API and managed input allocation. Read 12-bit X/Y ADC values and report BTN_TOUCH from the raw Z1 contact threshold. Apply coordinate transforms through the common touchscreen helpers.
This implementation derives from Icenowy Zheng's 2017 polling driver. Keep its historical threshold default while allowing a firmware override, and retain the original copyright and author attribution.
Report the touch key on every successful sample and let the input core filter repeated values. A private pen-down flag would become stale when the core clears key state during inhibit or reset. On a failed, short or malformed I2C read, discard the coordinates and release the contact so a failed bus cannot leave it stuck down. A later valid sample reports a new contact.
Validate the zero padding in the low nibble of the second byte as specified by the 12-bit read-command format. Reject malformed responses before assigning the decoded value, and rate-limit the diagnostic output.
Tested on UNIHIKER M10 V1.2 with a Linux 6.18 validation module: clicks, long presses, drags, release, axis orientation and three held-contact inhibit/uninhibit cycles. The validation module only changes the driver registration name to replace the existing built-in driver. Physical NACK/short-read fault injection and system suspend/resume have not been exercised.
--- MAINTAINERS | 1 + drivers/input/touchscreen/Kconfig | 10 ++ drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/ns2009.c | 175 +++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/input/touchscreen/ns2009.c
MAINTAINERS +1 -0
@@ -19472,6 +19472,7 @@ M: Mizuno Miotsuki <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml +F: drivers/input/touchscreen/ns2009.c NTB AMD DRIVER M: Basavaraj Natikar <[email protected]>
drivers/input/touchscreen/Kconfig +10 -0
@@ -691,6 +691,16 @@ config TOUCHSCREEN_MTOUCH To compile this driver as a module, choose M here: the module will be called mtouch. +config TOUCHSCREEN_NS2009 + tristate "Nsiway NS2009 touchscreen controller" + depends on I2C + help + Say Y here if you have a resistive touchscreen using the Nsiway + NS2009 controller connected over I2C. + + To compile this driver as a module, choose M here: the module will be + called ns2009. + config TOUCHSCREEN_NOVATEK_NVT_TS tristate "Novatek NT11205 touchscreen support" depends on I2C
drivers/input/touchscreen/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o obj-$(CONFIG_TOUCHSCREEN_MSG2638) += msg2638.o obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o +obj-$(CONFIG_TOUCHSCREEN_NS2009) += ns2009.o obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS) += novatek-nvt-ts.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o
drivers/input/touchscreen/ns2009.c new file +175 -0
175 lines not on this page · raw message
[email protected]
AI reviewRe: [PATCH 3/3] Input: add Nsiway NS2009 resistive touchscreen driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] i2c: missing named initializer in i2c_device_id array --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] i2c: missing named initializer in i2c_device_id array
--
commit 22cbbc5b42325e09804bb86ec6c548c4fefefb81
Author: Miotsuki Mizuno <[email protected]>
Input: add Nsiway NS2009 resistive touchscreen driver
Add polling support for the Nsiway NS2009 I2C touchscreen controller using the input polling API and managed input allocation. Read 12-bit X/Y ADC values and report BTN_TOUCH from the raw Z1 contact threshold.
Quoted 5 lines
drivers/input/touchscreen/ns2009.c new file +0
-0
[ ... ]
drivers/input/touchscreen/ns2009.c line 152
Quoted 2 lines
drivers/input/touchscreen/ns2009.c new file +2
-0+static const struct i2c_device_id ns2009_id[] = { + {"ns2009" },
[Severity: Low]
Should this array element use a named initializer?
The I2C subsystem guidelines specify that initialized arrays of type struct i2c_device_id must be declared const and use named initializers (e.g., { .name = "ns2009" }).
Quoted 6 lines
drivers/input/touchscreen/ns2009.c new file +6
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, ns2009_id); + +static const struct of_device_id ns2009_of_match[] = { + { .compatible ="nsiway,ns2009" },
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
v2 cover Add Nsiway NS2009 touchscreen support
In reply to Miotsuki MizunoAdd the Nsiway vendor prefix, an NS2009 hardware binding and an initial polling driver for the four-wire resistive touchscreen controller.
Changes in v2:
- Address Dmitry Torokhov's review by describing NS2009 hardware capabilities independently of the initial polling implementation.
- Add optional interrupts, wakeup-source, vdd-supply and vref-supply.
- Allow touchscreen-x-plate-ohms, touchscreen-max-pressure and touchscreen-fuzz-pressure via the common touchscreen schema.
- Add a second example showing an active-low pen interrupt and supplies; retain the no-interrupt example.
The driver and vendor-prefix changes are unchanged from v1. IRQ-based operation, wakeup handling and Z1/Z2 touch resistance calculation will be implemented separately. These features are not claimed to work in the current polling driver. The existing raw Z1 minimum contact threshold is unchanged, including the tested M10 value of 150.
Validation:
- dt_binding_check for both NS2009 examples: PASS.
- M10 DTS rebuild and CHECK_DTBS=y: PASS.
- Full-schema direct validation of the rebuilt combined M10 DTB and the existing independent touchscreen DTB: PASS, no diagnostics.
- The combined DTB is byte-identical to the previously hardware-tested DTB. No new runtime IRQ or pressure test was performed.
NS2009 dependencies are imported only in the independent M10 validation branch; no claim that they are merged.
Mizuno Miotsuki (3):
dt-bindings: vendor-prefixes: add Nsiway
dt-bindings: input: touchscreen: add Nsiway NS2009
Input: add Nsiway NS2009 resistive touchscreen driver
.../input/touchscreen/nsiway,ns2009.yaml | 104 +++++++++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 7 + drivers/input/touchscreen/Kconfig | 10 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/ns2009.c | 175 ++++++++++++++++++ 6 files changed, 299 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml create mode 100644 drivers/input/touchscreen/ns2009.c
base-commit: af32da41b0327b9c6a37856ba82b6760d6c8d10e
Signature · 1 line
2.56.0
PATCH v2 1/3 dt-bindings: vendor-prefixes: add Nsiway
Nsiway manufactures the NS2009 I2C resistive touchscreen controller. Add its vendor prefix for the touchscreen binding.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1214,6 +1214,8 @@ patternProperties: description: Novatek "^novtech,.*": description: NovTech, Inc. + "^nsiway,.*": + description: Shenzhen Nsiway Technology Co., Ltd. "^nuclei,.*": description: Nuclei System Technology "^numonyx,.*":
Signature · 1 line
2.56.0
Re: [PATCH v2 1/3] dt-bindings: vendor-prefixes: add Nsiway
Quoted 7 lines · Miotsuki Mizuno
Nsiway manufactures the NS2009 I2C resistive touchscreen controller. Add its vendor prefix for the touchscreen binding.
Signed-off-by Mizuno Miotsuki <[email protected]>--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
And now I see more versions, all threaded in the same spot and repeating same issue.
Please run scripts/checkpatch.pl on the patches and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' on the patches and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
Do not attach (thread) your patchsets to some other threads (unrelated or older versions). This buries them deep in the mailbox and might interfere with applying entire sets. See also:
https://elixir.bootlin.com/linux/v6.16-rc2/source/Documentation/process/submitting-patches.rst#L830
Best regards,
Krzysztof
PATCH v2 2/3 dt-bindings: input: touchscreen: add Nsiway NS2009
In reply to Miotsuki MizunoDescribe the Nsiway NS2009 four-wire resistive touchscreen controller, including its optional active-low pen interrupt, power and external reference supplies, and touch resistance measurement capabilities.
Allow the common X-plate resistance and pressure properties. Include both an interrupt/supply example and a minimal example for a board with an unconnected pen interrupt.
--- .../input/touchscreen/nsiway,ns2009.yaml | 104 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +104 -0
@@ -0,0 +1,104 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/nsiway,ns2009.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nsiway NS2009 resistive touchscreen controller + +maintainers: + - Mizuno Miotsuki <[email protected]> + +description: | + The NS2009 is a four-wire resistive touchscreen controller connected over + I2C, with a 12-bit ADC, an active-low pen interrupt output, and support + for an external ADC reference voltage. Touch resistance can be calculated + from the X coordinate, Z1 and Z2 measurements, and the X-plate resistance. + Coordinates are 12-bit ADC readings, not display pixel coordinates. + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + const: nsiway,ns2009 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: + Active-low pen interrupt output. Optional when the signal is not + connected. + + wakeup-source: true + + vdd-supply: + description: Main power supply. + + vref-supply: + description: External ADC reference voltage supply. + + touchscreen-x-plate-ohms: true + touchscreen-max-pressure: true + touchscreen-fuzz-pressure: true + + touchscreen-min-pressure: + minimum: 1 + maximum: 4095 + default: 80 + description: + Minimum raw Z1 reading considered a touch. This is a contact detection + threshold, not a calibrated pressure value. Boards may require a higher + empirically determined threshold than the historical driver default. + + touchscreen-min-x: true + touchscreen-min-y: true + touchscreen-size-x: true + touchscreen-size-y: true + touchscreen-fuzz-x: true + touchscreen-fuzz-y: true + touchscreen-inverted-x: true + touchscreen-inverted-y: true + touchscreen-swapped-x-y: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@48 { + compatible = "nsiway,ns2009"; + reg = <0x48>; + touchscreen-min-pressure = <150>; + touchscreen-inverted-y; + }; + }; + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@48 { + compatible = "nsiway,ns2009"; + reg = <0x48>; + interrupt-parent = <&gpio1>; + interrupts = <7 IRQ_TYPE_LEVEL_LOW>; + wakeup-source; + vdd-supply = <&vdd>; + vref-supply = <&vref>; + touchscreen-x-plate-ohms = <400>; + touchscreen-max-pressure = <4095>; + touchscreen-fuzz-pressure = <16>; + }; + };
MAINTAINERS +6 -0
@@ -19467,6 +19467,12 @@ S: Maintained F: Documentation/core-api/symbol-namespaces.rst F: scripts/nsdeps +NSIWAY NS2009 TOUCHSCREEN CONTROLLER +M: Mizuno Miotsuki <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml + NTB AMD DRIVER M: Basavaraj Natikar <[email protected]> M: Shyam Sundar S K <[email protected]>
Signature · 1 line
2.56.0
Re: [PATCH v2 2/3] dt-bindings: input: touchscreen: add Nsiway NS2009
Quoted 9 lines · Miotsuki Mizuno
Describe the Nsiway NS2009 four-wire resistive touchscreen controller, including its optional active-low pen interrupt, power and external reference supplies, and touch resistance measurement capabilities.
Allow the common X-plate resistance and pressure properties. Include both an interrupt/supply example and a minimal example for a board with an unconnected pen interrupt.
Suggested-by Dmitry Torokhov <[email protected]>
Hm? How Dmitry could suggest you to write bindings for your device?
Quoted 1 line
Signed-off-by Mizuno Miotsuki <[email protected]>
Same problem as v1.
Quoted 14 lines
--- .../input/touchscreen/nsiway,ns2009.yaml | 104 ++++++++++++++++++ MAINTAINERS | 6 + 2 files changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yamlDocumentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +2
-0@@ -0,0 +1,104 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml line 12
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +10
-0+--- +$id: http://devicetree.org/schemas/input/touchscreen/nsiway,ns2009.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nsiway NS2009 resistive touchscreen controller + +maintainers: + - Mizuno Miotsuki <[email protected]> + +description: |
Do not need '|' unless you need to preserve formatting.
Quoted 48 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +48
-0+ The NS2009 is a four-wire resistive touchscreen controller connected over + I2C, with a 12-bit ADC, an active-low pen interrupt output, and support + for an external ADC reference voltage. Touch resistance can be calculated + from the X coordinate, Z1 and Z2 measurements, and the X-plate resistance. + Coordinates are 12-bit ADC readings, not display pixel coordinates. + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + const: nsiway,ns2009 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + description: + Active-low pen interrupt output. Optional when the signal is not + connected. + + wakeup-source: true + + vdd-supply: + description: Main power supply. + + vref-supply: + description: External ADC reference voltage supply. + + touchscreen-x-plate-ohms: true + touchscreen-max-pressure: true + touchscreen-fuzz-pressure: true + + touchscreen-min-pressure: + minimum: 1 + maximum: 4095 + default: 80 + description: + Minimum raw Z1 reading considered a touch. This is a contact detection + threshold, not a calibrated pressure value. Boards may require a higher + empirically determined threshold than the historical driver default. + + touchscreen-min-x: true + touchscreen-min-y: true + touchscreen-size-x: true + touchscreen-size-y: true + touchscreen-fuzz-x: true
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml line 70
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +10
-0+ touchscreen-fuzz-y: true + touchscreen-inverted-x: true + touchscreen-inverted-y: true + touchscreen-swapped-x-y: true + +required: + - compatible + - reg + +additionalProperties: false
Just make it unevaluatedProperties: false and drop all "true" properties.
Quoted 24 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +24
-0+ +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@48 { + compatible = "nsiway,ns2009"; + reg = <0x48>; + touchscreen-min-pressure = <150>; + touchscreen-inverted-y; + }; + }; + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@48 { + compatible = "nsiway,ns2009"; + reg = <0x48>;
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml line 104
Quoted 10 lines
Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml new file +10
-0+ interrupt-parent = <&gpio1>; + interrupts = <7 IRQ_TYPE_LEVEL_LOW>; + wakeup-source; + vdd-supply = <&vdd>; + vref-supply = <&vref>; + touchscreen-x-plate-ohms = <400>; + touchscreen-max-pressure = <4095>; + touchscreen-fuzz-pressure = <16>; + }; + };
One complete example.
Best regards,
Krzysztof
PATCH v2 3/3 Input: add Nsiway NS2009 resistive touchscreen driver
In reply to Miotsuki MizunoAdd polling support for the Nsiway NS2009 I2C touchscreen controller using the input polling API and managed input allocation. Read 12-bit X/Y ADC values and report BTN_TOUCH from the raw Z1 contact threshold. Apply coordinate transforms through the common touchscreen helpers.
This implementation derives from Icenowy Zheng's 2017 polling driver. Keep its historical threshold default while allowing a firmware override, and retain the original copyright and author attribution.
Report the touch key on every successful sample and let the input core filter repeated values. A private pen-down flag would become stale when the core clears key state during inhibit or reset. On a failed, short or malformed I2C read, discard the coordinates and release the contact so a failed bus cannot leave it stuck down. A later valid sample reports a new contact.
Validate the zero padding in the low nibble of the second byte as specified by the 12-bit read-command format. Reject malformed responses before assigning the decoded value, and rate-limit the diagnostic output.
Tested on UNIHIKER M10 V1.2 with a Linux 6.18 validation module: clicks, long presses, drags, release, axis orientation and three held-contact inhibit/uninhibit cycles. The validation module only changes the driver registration name to replace the existing built-in driver. Physical NACK/short-read fault injection and system suspend/resume have not been exercised.
--- MAINTAINERS | 1 + drivers/input/touchscreen/Kconfig | 10 ++ drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/ns2009.c | 175 +++++++++++++++++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 drivers/input/touchscreen/ns2009.c
MAINTAINERS +1 -0
@@ -19472,6 +19472,7 @@ M: Mizuno Miotsuki <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/input/touchscreen/nsiway,ns2009.yaml +F: drivers/input/touchscreen/ns2009.c NTB AMD DRIVER M: Basavaraj Natikar <[email protected]>
drivers/input/touchscreen/Kconfig +10 -0
@@ -691,6 +691,16 @@ config TOUCHSCREEN_MTOUCH To compile this driver as a module, choose M here: the module will be called mtouch. +config TOUCHSCREEN_NS2009 + tristate "Nsiway NS2009 touchscreen controller" + depends on I2C + help + Say Y here if you have a resistive touchscreen using the Nsiway + NS2009 controller connected over I2C. + + To compile this driver as a module, choose M here: the module will be + called ns2009. + config TOUCHSCREEN_NOVATEK_NVT_TS tristate "Novatek NT11205 touchscreen support" depends on I2C
drivers/input/touchscreen/Makefile +1 -0
@@ -68,6 +68,7 @@ obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o obj-$(CONFIG_TOUCHSCREEN_MMS114) += mms114.o obj-$(CONFIG_TOUCHSCREEN_MSG2638) += msg2638.o obj-$(CONFIG_TOUCHSCREEN_MTOUCH) += mtouch.o +obj-$(CONFIG_TOUCHSCREEN_NS2009) += ns2009.o obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS) += novatek-nvt-ts.o obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) += jornada720_ts.o
drivers/input/touchscreen/ns2009.c new file +175 -0
175 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v2 3/3] Input: add Nsiway NS2009 resistive touchscreen driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] i2c: i2c_device_id array is missing named initializers --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] i2c: i2c_device_id array is missing named initializers
--
commit 0ef31ef1051f1f4d0d958b8c5e57e36de085c191
Author: Miotsuki Mizuno <[email protected]>
Subject: Input: add Nsiway NS2009 resistive touchscreen driver
This commit introduces a new polling driver for the Nsiway NS2009 I2C touchscreen controller. It supports reading 12-bit X/Y ADC values and reports touch events using the raw Z1 contact threshold.
Quoted 5 lines
drivers/input/touchscreen/ns2009.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/input/touchscreen/ns2009.c new file +2
-0+static int ns2009_probe (struct i2c_client *client) +{
[ ... ]
drivers/input/touchscreen/ns2009.c line 152
Quoted 10 lines
drivers/input/touchscreen/ns2009.c new file +10
-0+ error =input_register_device (input); +if (error) +return dev_err_probe (dev, error, +"failed to register input device\n" ); + +return 0 ; +} + +static const struct i2c_device_id ns2009_id[] = { + {"ns2009" },
[Severity: Low]
This isn't a runtime bug, but I2C subsystem guidelines require initialized arrays of type struct i2c_device_id to use named initializers. Should this element be initialized as { .name = "ns2009" } instead of positionally?
Quoted 3 lines
drivers/input/touchscreen/ns2009.c new file +3
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, ns2009_id);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3