Skip to contentSkip to conversation

HID: add initial support for Goodix HID-over-SPI touchscreen

PATCH Superseded Charles Wang 4 participants 11 messages Jun 18, 2024 – Aug 13, 2024

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover HID: add initial support for Goodix HID-over-SPI touchscreen

This patch introduces a new driver to support the Goodix GT7986U touch controller. This device is not compatible with Microsoft's HID-over-SPI protocol and therefore needs to implement its own flavor. The data reported is packaged according to the HID protocol but uses SPI for communication to improve speed. This enables the device to transmit not only coordinate data but also corresponding raw data that can be accessed by user-space programs through the hidraw interface. The raw data can be utilized for functions like palm rejection, thereby improving the touch experience.

Key features:
- Device connection confirmation and initialization
- IRQ-based event reporting to the input subsystem
- Support for HIDRAW operations (GET_REPORT and SET_REPORT)

---
Changes in v5:
- Add additional descriptive information to the dt-binding file.
- Fixed build warnings reported by kernel test robot.

Changes in v4:
- Allocate memory based on the report information.
- Added a new function goodix_get_event_report() to retrieve report data, reducing memory copy operations and avoiding the use of reg_rw_lock.
- Add low power control operations.
- Implemented power management operations.
- Introduced GOODIX_HID_STARTED to record the current device operating state.
- Add OF match table.

Changes in v3:
- Renamed the driver file to hid-goodix-spi.c.
- Mentioned in the commit message that this implementation is not compatible with Microsoft's HID-over-SPI protocol.
- Modified the driver to fetch the GOODIX_HID_REPORT_ADDR from device properties.
- Add a lock to prevent concurrent hid feature request operations.
- Optimized the SPI read/write functions by reducing the number of malloc calls.

Changes in v2:
- Fixed build warnings reported by kernel test robot

---
Charles Wang (2):
HID: hid-goodix: Add Goodix HID-over-SPI driver
dt-bindings: input: Goodix SPI HID Touchscreen

 .../bindings/input/goodix,gt7986u.yaml        |  72 ++
 drivers/hid/Kconfig                           |   6 +
 drivers/hid/Makefile                          |   1 +
 drivers/hid/hid-goodix-spi.c                  | 811 ++++++++++++++++++
 4 files changed, 890 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/goodix,gt7986u.yaml
 create mode 100644 drivers/hid/hid-goodix-spi.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v5 1/2 HID: hid-goodix: Add Goodix HID-over-SPI driver

This patch introduces a new driver to support the Goodix GT7986U touch controller. This device is not compatible with Microsoft's HID-over-SPI protocol and therefore needs to implement its own flavor. The data reported is packaged according to the HID protocol but uses SPI for communication to improve speed. This enables the device to transmit not only coordinate data but also corresponding raw data that can be accessed by user-space programs through the hidraw interface. The raw data can be utilized for functions like palm rejection, thereby improving the touch experience.

Key features:
- Device connection confirmation and initialization
- IRQ-based event reporting to the input subsystem
- Support for HIDRAW operations (GET_REPORT and SET_REPORT)

---
 drivers/hid/Kconfig          |   6 +
 drivers/hid/Makefile         |   1 +
 drivers/hid/hid-goodix-spi.c | 811 +++++++++++++++++++++++++++++++++++
 3 files changed, 818 insertions(+)
 create mode 100644 drivers/hid/hid-goodix-spi.c
drivers/hid/Kconfig +6 -0
index 4c682c650..03e750e04 100644
@@ -404,6 +404,12 @@ config HID_VIVALDI_COMMON
 	  option so that drivers can use common code to parse the HID
 	  descriptors for vivaldi function row keymap.
 
+config HID_GOODIX_SPI
+	tristate "Goodix GT7986U SPI HID touchscreen"
+	depends on SPI_MASTER
+	help
+	  Support for Goodix GT7986U SPI HID touchscreen device.
+
 config HID_GOOGLE_HAMMER
 	tristate "Google Hammer Keyboard"
 	select HID_VIVALDI_COMMON
drivers/hid/Makefile +1 -0
index 082a728ea..56e3ed4c1 100644
@@ -54,6 +54,7 @@ obj-$(CONFIG_HID_GEMBIRD)	+= hid-gembird.o
 obj-$(CONFIG_HID_GFRM)		+= hid-gfrm.o
 obj-$(CONFIG_HID_GLORIOUS)  += hid-glorious.o
 obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o
+obj-$(CONFIG_HID_GOODIX_SPI)	+= hid-goodix-spi.o
 obj-$(CONFIG_HID_GOOGLE_HAMMER)	+= hid-google-hammer.o
 obj-$(CONFIG_HID_GOOGLE_STADIA_FF)	+= hid-google-stadiaff.o
 obj-$(CONFIG_HID_VIVALDI)	+= hid-vivaldi.o
drivers/hid/hid-goodix-spi.c new file +811 -0

811 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v5 2/2 dt-bindings: input: Goodix SPI HID Touchscreen

In reply to Charles Wang

The Goodix GT7986U touch controller report touch data according to the HID protocol through the SPI bus. However, it is incompatible with Microsoft's HID-over-SPI protocol.

---
 .../bindings/input/goodix,gt7986u.yaml        | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/goodix,gt7986u.yaml
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +72 -0
new file mode 100644
index 000000000..25a26b4ce
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/goodix,gt7986u.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GOODIX GT7986U SPI HID Touchscreen
+
+maintainers:
+  - Charles Wang <[email protected]>
+
+description: Supports the Goodix GT7986U touchscreen.
+  This touch controller reports data packaged according to the HID protocol,
+  but is incompatible with Microsoft's HID-over-SPI protocol.
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - goodix,gt7986u
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description: reset gpio the chip is connected to.
+
+  goodix,hid-report-addr:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      The register address for retrieving HID report data.
+      This address is related to the device firmware and may
+      change after a firmware update.
+
+  spi-max-frequency: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - reset-gpios
+  - goodix,hid-report-addr
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      touchscreen@0 {
+        compatible = "goodix,gt7986u";
+        reg = <0>;
+        interrupt-parent = <&gpio>;
+        interrupts = <25 IRQ_TYPE_LEVEL_LOW>;
+        reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
+        spi-max-frequency = <10000000>;
+        goodix,hid-report-addr = <0x22c8c>;
+      };
+    };
+
+...
Signature · 1 line
2.43.0
Reviewed-by on v5 2/2
#5 lore raw

Re: [PATCH v5 2/2] dt-bindings: input: Goodix SPI HID Touchscreen

Quoted 38 lines · Charles Wang

The Goodix GT7986U touch controller report touch data according to the HID protocol through the SPI bus. However, it is incompatible with Microsoft's HID-over-SPI protocol.

---
 .../bindings/input/goodix,gt7986u.yaml        | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/goodix,gt7986u.yaml
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +22 -0
new file mode 100644
index 000000000..25a26b4ce
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/goodix,gt7986u.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GOODIX GT7986U SPI HID Touchscreen
+
+maintainers:
+  - Charles Wang <[email protected]>
+
+description: Supports the Goodix GT7986U touchscreen.
+  This touch controller reports data packaged according to the HID protocol,
+  but is incompatible with Microsoft's HID-over-SPI protocol.
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - goodix,gt7986u

Documentation/devicetree/bindings/input/goodix,gt7986u.yaml line 32

Quoted 10 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +10 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description: reset gpio the chip is connected to.

The description here isn't needed, it's obvious :)

Documentation/devicetree/bindings/input/goodix,gt7986u.yaml line 36

Quoted 3 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +3 -0
+  goodix,hid-report-addr:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

This | is not needed, there's no formatting to preserve.

Those are nits:

Thanks,
Conor.

Quoted 39 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +36 -0
+      The register address for retrieving HID report data.
+      This address is related to the device firmware and may
+      change after a firmware update.
+
+  spi-max-frequency: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - reset-gpios
+  - goodix,hid-report-addr
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      touchscreen@0 {
+        compatible = "goodix,gt7986u";
+        reg = <0>;
+        interrupt-parent = <&gpio>;
+        interrupts = <25 IRQ_TYPE_LEVEL_LOW>;
+        reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
+        spi-max-frequency = <10000000>;
+        goodix,hid-report-addr = <0x22c8c>;
+      };
+    };
+
+...
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v5 2/2] dt-bindings: input: Goodix SPI HID Touchscreen

Hi Conor,

Quoted 43 lines · Conor Dooley
Quoted 42 lines · Charles Wang

The Goodix GT7986U touch controller report touch data according to the HID protocol through the SPI bus. However, it is incompatible with Microsoft's HID-over-SPI protocol.

---
 .../bindings/input/goodix,gt7986u.yaml        | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/goodix,gt7986u.yaml
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +26 -0
new file mode 100644
index 000000000..25a26b4ce
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/goodix,gt7986u.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: GOODIX GT7986U SPI HID Touchscreen
+
+maintainers:
+  - Charles Wang <[email protected]>
+
+description: Supports the Goodix GT7986U touchscreen.
+  This touch controller reports data packaged according to the HID protocol,
+  but is incompatible with Microsoft's HID-over-SPI protocol.
+
+allOf:
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+
+properties:
+  compatible:
+    enum:
+      - goodix,gt7986u
+
+  reg:
+    maxItems: 1
+
Quoted 9 lines

Documentation/devicetree/bindings/input/goodix,gt7986u.yaml line 32

Quoted 6 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +6 -0
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description: reset gpio the chip is connected to.

The description here isn't needed, it's obvious :)

Ack.

Quoted 9 lines

Documentation/devicetree/bindings/input/goodix,gt7986u.yaml line 36

Quoted 3 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +3 -0
+  goodix,hid-report-addr:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |

This | is not needed, there's no formatting to preserve.

Those are nits:

Thank you. If there is a next version, I will fix these.

Charles,

Quoted 40 lines
Quoted 40 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +36 -0
+      The register address for retrieving HID report data.
+      This address is related to the device firmware and may
+      change after a firmware update.
+
+  spi-max-frequency: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - reset-gpios
+  - goodix,hid-report-addr
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      touchscreen@0 {
+        compatible = "goodix,gt7986u";
+        reg = <0>;
+        interrupt-parent = <&gpio>;
+        interrupts = <25 IRQ_TYPE_LEVEL_LOW>;
+        reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>;
+        spi-max-frequency = <10000000>;
+        goodix,hid-report-addr = <0x22c8c>;
+      };
+    };
+
+...
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v5 2/2] dt-bindings: input: Goodix SPI HID Touchscreen

Quoted 18 lines · Charles Wang

Hi Conor,

Quoted 8 lines · Conor Dooley

Documentation/devicetree/bindings/input/goodix,gt7986u.yaml line 32

Quoted 3 lines · Charles Wang
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +3 -0
+  reset-gpios:
+    maxItems: 1
+    description: reset gpio the chip is connected to.

The description here isn't needed, it's obvious :)

Ack.

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/input/goodix,gt7986u.yaml new file +3 -0
+  goodix,hid-report-addr:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
Quoted 7 lines
Quoted 5 lines

This | is not needed, there's no formatting to preserve.

Those are nits:

Thank you. If there is a next version, I will fix these.

Sounds good, thank you!

#8 lore raw
In reply to Charles Wang

Gentle ping...

Quoted 46 lines · Charles Wang

This patch introduces a new driver to support the Goodix GT7986U touch controller. This device is not compatible with Microsoft's HID-over-SPI protocol and therefore needs to implement its own flavor. The data reported is packaged according to the HID protocol but uses SPI for communication to improve speed. This enables the device to transmit not only coordinate data but also corresponding raw data that can be accessed by user-space programs through the hidraw interface. The raw data can be utilized for functions like palm rejection, thereby improving the touch experience.

Key features:
- Device connection confirmation and initialization
- IRQ-based event reporting to the input subsystem
- Support for HIDRAW operations (GET_REPORT and SET_REPORT)

---
Changes in v5:
- Add additional descriptive information to the dt-binding file.
- Fixed build warnings reported by kernel test robot.

Changes in v4:
- Allocate memory based on the report information.
- Added a new function goodix_get_event_report() to retrieve report data, reducing memory copy operations and avoiding the use of reg_rw_lock.
- Add low power control operations.
- Implemented power management operations.
- Introduced GOODIX_HID_STARTED to record the current device operating state.
- Add OF match table.

Changes in v3:
- Renamed the driver file to hid-goodix-spi.c.
- Mentioned in the commit message that this implementation is not compatible with Microsoft's HID-over-SPI protocol.
- Modified the driver to fetch the GOODIX_HID_REPORT_ADDR from device properties.
- Add a lock to prevent concurrent hid feature request operations.
- Optimized the SPI read/write functions by reducing the number of malloc calls.

Changes in v2:
- Fixed build warnings reported by kernel test robot

---
Charles Wang (2):
HID: hid-goodix: Add Goodix HID-over-SPI driver
dt-bindings: input: Goodix SPI HID Touchscreen

Quoted 11 lines
 .../bindings/input/goodix,gt7986u.yaml        |  72 ++
 drivers/hid/Kconfig                           |   6 +
 drivers/hid/Makefile                          |   1 +
 drivers/hid/hid-goodix-spi.c                  | 811 ++++++++++++++++++
 4 files changed, 890 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/goodix,gt7986u.yaml
 create mode 100644 drivers/hid/hid-goodix-spi.c
Signature · 1 line
2.43.0

Thanks
Charles

maintainer Reviewed-by on v5 1/2
#2 lore raw

Re: [PATCH v5 1/2] HID: hid-goodix: Add Goodix HID-over-SPI driver

In reply to Charles Wang

Hi Charles,

Quoted 10 lines · Charles Wang

This patch introduces a new driver to support the Goodix GT7986U touch controller. This device is not compatible with Microsoft's HID-over-SPI protocol and therefore needs to implement its own flavor. The data reported is packaged according to the HID protocol but uses SPI for communication to improve speed. This enables the device to transmit not only coordinate data but also corresponding raw data that can be accessed by user-space programs through the hidraw interface. The raw data can be utilized for functions like palm rejection, thereby improving the touch experience.

Quoted 4 lines

Key features:
- Device connection confirmation and initialization
- IRQ-based event reporting to the input subsystem
- Support for HIDRAW operations (GET_REPORT and SET_REPORT)

This looks reasonable good, so:

A couple of suggestions/nits below:

Quoted 7 lines
drivers/hid/hid-goodix-spi.c new file +7 -0
+static int goodix_spi_probe(struct spi_device *spi)
+{
+	struct device *dev = &spi->dev;
+	struct goodix_ts_data *ts;
+	int error;
+
+	/* init spi_device */

drivers/hid/hid-goodix-spi.c line 670

Quoted 10 lines
drivers/hid/hid-goodix-spi.c new file +10 -0
+	spi->mode            = SPI_MODE_0;
+	spi->bits_per_word   = 8;
+	error = spi_setup(spi);
+	if (error)
+		return error;
+
+	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
+	if (!ts)
+		return -ENOMEM;
+

If you do:

	ts->event_buf = devm_kmalloc(dev, <some nominal size>, GFP_KERNEL);

here and use devm_krealloc() once you figure the true size of event buffer you can stop calling kfree() by hand on remove.

Quoted 49 lines
drivers/hid/hid-goodix-spi.c new file +49 -0
+	mutex_init(&ts->hid_request_lock);
+	spi_set_drvdata(spi, ts);
+	ts->spi = spi;
+	ts->dev = dev;
+	ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(ts->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(ts->reset_gpio),
+				     "failed to request reset gpio\n");
+
+	error = device_property_read_u32(dev, "goodix,hid-report-addr",
+					 &ts->hid_report_addr);
+	if (error)
+		return dev_err_probe(dev, error,
+				     "failed get hid report addr\n");
+
+	error = goodix_dev_confirm(ts);
+	if (error)
+		return error;
+
+	/* Waits 150ms for firmware to fully boot */
+	msleep(GOODIX_NORMAL_RESET_DELAY_MS);
+
+	error = goodix_hid_init(ts);
+	if (error) {
+		dev_err(dev, "failed init hid device");
+		return error;
+	}
+
+	error = devm_request_threaded_irq(&ts->spi->dev, ts->spi->irq,
+					  NULL, goodix_hid_irq, IRQF_ONESHOT,
+					  "goodix_spi_hid", ts);
+	if (error) {
+		dev_err(ts->dev, "could not register interrupt, irq = %d, %d",
+			ts->spi->irq, error);
+		goto err_destroy_hid;
+	}
+
+	return 0;
+
+err_destroy_hid:
+	hid_destroy_device(ts->hid);
+	return error;
+}
+
+static void goodix_spi_remove(struct spi_device *spi)
+{
+	struct goodix_ts_data *ts = spi_get_drvdata(spi);
+
+	disable_irq(spi->irq);

drivers/hid/hid-goodix-spi.c line 729

Quoted 10 lines
drivers/hid/hid-goodix-spi.c new file +10 -0
+	hid_destroy_device(ts->hid);
+	kfree(ts->event_buf);
+}
+
+static void goodix_spi_shutdown(struct spi_device *spi)
+{
+	struct goodix_ts_data *ts = spi_get_drvdata(spi);
+
+	disable_irq(spi->irq);
+	hid_destroy_device(ts->hid);

Do we really need shutdown() method? It is very rarely that it is needed.

Quoted 18 lines
drivers/hid/hid-goodix-spi.c new file +18 -0
+}
+
+static int goodix_spi_set_power(struct goodix_ts_data *ts, int power_state)
+{
+	u8 power_control_cmd[] = {0x00, 0x00, 0x00, 0x87, 0x02, 0x00, 0x08};
+	int error;
+
+	/* value 0 for power on, 1 for power sleep */
+	power_control_cmd[5] = power_state;
+
+	guard(mutex)(&ts->hid_request_lock);
+	error = goodix_spi_write(ts, ts->hid_report_addr, power_control_cmd,
+				 sizeof(power_control_cmd));
+	if (error) {
+		dev_err(ts->dev, "failed set power mode: %s",
+			power_state == GOODIX_SPI_POWER_ON ? "on" : "sleep");
+		return error;
+	}

drivers/hid/hid-goodix-spi.c line 757

Quoted 10 lines
drivers/hid/hid-goodix-spi.c new file +10 -0
+	return 0;
+}
+
+static int goodix_spi_suspend(struct device *dev)
+{
+	struct goodix_ts_data *ts = dev_get_drvdata(dev);
+	int error;
+
+	error = goodix_spi_set_power(ts, GOODIX_SPI_POWER_SLEEP);
+	disable_irq(ts->spi->irq);

Can disable_irq() be called first?

Thanks.

Signature · 1 line
Dmitry
#9 lore raw
In reply to Charles Wang

Hi,

Quoted 2 lines · Charles Wang

Gentle ping...

Looks like Dmitry had some small nits on patch #1. Maybe folks are assuming that you'll send a v6 or at least respond to him about the nits?

-Doug

#3 lore raw

Re: [PATCH v5 1/2] HID: hid-goodix: Add Goodix HID-over-SPI driver

In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 44 lines · Dmitry Torokhov

Hi Charles,

Quoted 10 lines · Charles Wang

This patch introduces a new driver to support the Goodix GT7986U touch controller. This device is not compatible with Microsoft's HID-over-SPI protocol and therefore needs to implement its own flavor. The data reported is packaged according to the HID protocol but uses SPI for communication to improve speed. This enables the device to transmit not only coordinate data but also corresponding raw data that can be accessed by user-space programs through the hidraw interface. The raw data can be utilized for functions like palm rejection, thereby improving the touch experience.

Quoted 4 lines

Key features:
- Device connection confirmation and initialization
- IRQ-based event reporting to the input subsystem
- Support for HIDRAW operations (GET_REPORT and SET_REPORT)

This looks reasonable good, so:

A couple of suggestions/nits below:

Quoted 7 lines
drivers/hid/hid-goodix-spi.c new file +7 -0
+static int goodix_spi_probe(struct spi_device *spi)
+{
+	struct device *dev = &spi->dev;
+	struct goodix_ts_data *ts;
+	int error;
+
+	/* init spi_device */

drivers/hid/hid-goodix-spi.c line 670

Quoted 10 lines
drivers/hid/hid-goodix-spi.c new file +10 -0
+	spi->mode            = SPI_MODE_0;
+	spi->bits_per_word   = 8;
+	error = spi_setup(spi);
+	if (error)
+		return error;
+
+	ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
+	if (!ts)
+		return -ENOMEM;
+

If you do:

Quoted 5 lines
	ts->event_buf = devm_kmalloc(dev, <some nominal size>, GFP_KERNEL);

here and use devm_krealloc() once you figure the true size of event buffer you can stop calling kfree() by hand on remove.

Ack,

Quoted 54 lines
Quoted 54 lines
drivers/hid/hid-goodix-spi.c new file +54 -0
+	mutex_init(&ts->hid_request_lock);
+	spi_set_drvdata(spi, ts);
+	ts->spi = spi;
+	ts->dev = dev;
+	ts->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+	if (IS_ERR(ts->reset_gpio))
+		return dev_err_probe(dev, PTR_ERR(ts->reset_gpio),
+				     "failed to request reset gpio\n");
+
+	error = device_property_read_u32(dev, "goodix,hid-report-addr",
+					 &ts->hid_report_addr);
+	if (error)
+		return dev_err_probe(dev, error,
+				     "failed get hid report addr\n");
+
+	error = goodix_dev_confirm(ts);
+	if (error)
+		return error;
+
+	/* Waits 150ms for firmware to fully boot */
+	msleep(GOODIX_NORMAL_RESET_DELAY_MS);
+
+	error = goodix_hid_init(ts);
+	if (error) {
+		dev_err(dev, "failed init hid device");
+		return error;
+	}
+
+	error = devm_request_threaded_irq(&ts->spi->dev, ts->spi->irq,
+					  NULL, goodix_hid_irq, IRQF_ONESHOT,
+					  "goodix_spi_hid", ts);
+	if (error) {
+		dev_err(ts->dev, "could not register interrupt, irq = %d, %d",
+			ts->spi->irq, error);
+		goto err_destroy_hid;
+	}
+
+	return 0;
+
+err_destroy_hid:
+	hid_destroy_device(ts->hid);
+	return error;
+}
+
+static void goodix_spi_remove(struct spi_device *spi)
+{
+	struct goodix_ts_data *ts = spi_get_drvdata(spi);
+
+	disable_irq(spi->irq);
+	hid_destroy_device(ts->hid);
+	kfree(ts->event_buf);
+}
+
+static void goodix_spi_shutdown(struct spi_device *spi)
Quoted 9 lines

drivers/hid/hid-goodix-spi.c line 720

Quoted 5 lines
drivers/hid/hid-goodix-spi.c new file +5 -0
+{
+	struct goodix_ts_data *ts = spi_get_drvdata(spi);
+
+	disable_irq(spi->irq);
+	hid_destroy_device(ts->hid);

Do we really need shutdown() method? It is very rarely that it is needed.

After testing on the machine, we found that this method is only invoked during system shutdown. Since the device doesn't require any special operations at shutdown, so I think it can be removed.

Quoted 22 lines
Quoted 22 lines
drivers/hid/hid-goodix-spi.c new file +22 -0
+}
+
+static int goodix_spi_set_power(struct goodix_ts_data *ts, int power_state)
+{
+	u8 power_control_cmd[] = {0x00, 0x00, 0x00, 0x87, 0x02, 0x00, 0x08};
+	int error;
+
+	/* value 0 for power on, 1 for power sleep */
+	power_control_cmd[5] = power_state;
+
+	guard(mutex)(&ts->hid_request_lock);
+	error = goodix_spi_write(ts, ts->hid_report_addr, power_control_cmd,
+				 sizeof(power_control_cmd));
+	if (error) {
+		dev_err(ts->dev, "failed set power mode: %s",
+			power_state == GOODIX_SPI_POWER_ON ? "on" : "sleep");
+		return error;
+	}
+	return 0;
+}
+
+static int goodix_spi_suspend(struct device *dev)
Quoted 9 lines

drivers/hid/hid-goodix-spi.c line 757

Quoted 6 lines
drivers/hid/hid-goodix-spi.c new file +6 -0
+{
+	struct goodix_ts_data *ts = dev_get_drvdata(dev);
+	int error;
+
+	error = goodix_spi_set_power(ts, GOODIX_SPI_POWER_SLEEP);
+	disable_irq(ts->spi->irq);

Can disable_irq() be called first?

Ack, calling this first seems better.

Thanks,

Charles

#10 lore raw
In reply to Doug Anderson

Hi Doug,

Thank you for the reminder, and I apologize for overlooking Dmitry's review comments. I will address his feedback and submit a v6.

Quoted 11 lines · Doug Anderson

Hi,

Quoted 2 lines · Charles Wang

Gentle ping...

Looks like Dmitry had some small nits on patch #1. Maybe folks are assuming that you'll send a v6 or at least respond to him about the nits?

-Doug

Thanks again,

Charles