Skip to contentSkip to conversation

Add spi-hid, transport for HID over SPI bus

PATCH In review Jarrett Schultz 6 participants 12 messages Jul 7, 2022 – Feb 25, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v5 cover Add spi-hid, transport for HID over SPI bus

From: Jarrett Schultz <[email protected]>

Surface Duo devices use a touch digitizer that communicates to the main SoC via SPI and presents itself as a HID device. This patch's goal is to add the spi-hid transport driver to drivers/hid. The driver follows the publically available HID Over SPI Protocol Specification version 1.0.

The specification is available at
https://www.microsoft.com/en-us/download/details.aspx?id=103325.

In the initial commits there are some HID core changes to support a SPI device, a change to HID documentation, HID over SPI Device Tree bindings, and finally the SPI HID transport driver.

Dmitry Antipov (5):
HID: Add BUS_SPI support when printing out device info in
hid_connect()
HID: define HID_SPI_DEVICE macro in hid.h
dt-bindings: input: Document Microsoft G6 Touch Digitizer
Documentation: Correction in HID output_report callback description.
HID: add spi-hid, transport driver for HID over SPI bus

Jarrett Schultz (1):
Enable building drivers/hid/spi-hid as a module

 .../input/microsoft,g6-touch-digitizer.yaml   |  135 ++
 Documentation/hid/hid-transport.rst           |    4 +-
 arch/arm64/configs/defconfig                  |    1 +
 drivers/hid/Kconfig                           |    2 +
 drivers/hid/Makefile                          |    1 +
 drivers/hid/hid-core.c                        |    3 +
 drivers/hid/spi-hid/Kconfig                   |   25 +
 drivers/hid/spi-hid/Makefile                  |   12 +
 drivers/hid/spi-hid/spi-hid-core.c            | 1326 +++++++++++++++++
 drivers/hid/spi-hid/spi-hid-core.h            |  188 +++
 drivers/hid/spi-hid/spi-hid-of.c              |  141 ++
 drivers/hid/spi-hid/spi-hid-of.h              |   30 +
 drivers/hid/spi-hid/spi-hid_trace.h           |  194 +++
 drivers/hid/spi-hid/trace.c                   |    9 +
 include/linux/hid.h                           |    2 +
 15 files changed, 2071 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml
 create mode 100644 drivers/hid/spi-hid/Kconfig
 create mode 100644 drivers/hid/spi-hid/Makefile
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.h
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.h
 create mode 100644 drivers/hid/spi-hid/spi-hid_trace.h
 create mode 100644 drivers/hid/spi-hid/trace.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/6 HID: Add BUS_SPI support when printing out device info in hid_connect()

From: Jarrett Schultz <[email protected]>

If connecting a hid_device with bus field indicating BUS_SPI print out "SPI" in the debug print.

---
 drivers/hid/hid-core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/hid/hid-core.c +3 -0
index 00154a1cd2d8..22f313716a12 100644
@@ -2219,6 +2219,9 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 	case BUS_I2C:
 		bus = "I2C";
 		break;
+	case BUS_SPI:
+		bus = "SPI";
+		break;
 	case BUS_VIRTUAL:
 		bus = "VIRTUAL";
 		break;
Signature · 1 line
2.25.1
#2 lore raw

PATCH v5 2/6 HID: define HID_SPI_DEVICE macro in hid.h

In reply to Jarrett Schultz

From: Jarrett Schultz <[email protected]>

Macro sets the bus field to BUS_SPI and uses arguments to set vendor product fields.

---
 include/linux/hid.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/hid.h +2 -0
index 4363a63b9775..7923fe1b51bb 100644
@@ -715,6 +715,8 @@ struct hid_descriptor {
 	.bus = BUS_BLUETOOTH, .vendor = (ven), .product = (prod)
 #define HID_I2C_DEVICE(ven, prod)				\
 	.bus = BUS_I2C, .vendor = (ven), .product = (prod)
+#define HID_SPI_DEVICE(ven, prod)				\
+	.bus = BUS_SPI, .vendor = (ven), .product = (prod)
 
 #define HID_REPORT_ID(rep) \
 	.report_type = (rep)
Signature · 1 line
2.25.1
#3 lore raw

PATCH v5 3/6 dt-bindings: input: Document Microsoft G6 Touch Digitizer

In reply to Jarrett Schultz

From: Jarrett Schultz <[email protected]>

Documentation describes the required and optional properties for implementing Device Tree for a Microsoft G6 Touch Digitizer that supports HID over SPI Protocol 1.0 specification.

---
 .../input/microsoft,g6-touch-digitizer.yaml   | 135 ++++++++++++++++++
 1 file changed, 135 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +135 -0
new file mode 100644
index 000000000000..b607bbb32a42
@@ -0,0 +1,135 @@
+# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/microsoft,g6-touch-digitizer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microsoft G6 Touch Digitizer
+
+maintainers:
+  - Dmitry Antipov <[email protected]>
+
+description: |
+  Microsoft G6 touch digitizer is a HID over SPI device supporting HID Over SPI
+  Protocol Specification 1.0, available at
+  https://www.microsoft.com/en-us/download/details.aspx?id=103325.
+
+properties:
+  compatible:
+    items:
+      - const: microsoft,g6-touch-digitizer
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      GPIO specifier for the digitizer's reset pin (active low). The line must
+      be flagged with GPIO_ACTIVE_LOW.
+
+  vdd-supply:
+    description:
+      Regulator for the VDD supply voltage.
+
+  input-report-header-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215
+    description:
+      A value to be included in the Read Approval packet, listing an address of
+      the input report header to be put on the SPI bus. This address has 24
+      bits.
+
+  input-report-body-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215
+    description:
+      A value to be included in the Read Approval packet, listing an address of
+      the input report body to be put on the SPI bus. This address has 24 bits.
+
+  output-report-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215
+    description:
+      A value to be included in the Output Report sent by the host, listing an
+      address where the output report on the SPI bus is to be written to. This
+      address has 24 bits.
+
+  post-power-on-delay-ms:
+    description:
+      Optional time in ms required by the device after enabling its regulators
+      or powering it on, before it is ready for communication.
+
+  minimal-reset-delay-ms:
+    description:
+      Optional minimum amount of time in ms that device needs to be in reset
+      state for the reset to take effect.
+
+  read-opcode:
+    description: 
+      Value to be used in Read Approval packets. 1 byte.
+
+  write-opcode:
+    description:
+      Value to be used in Write Approval packets. 1 byte.
+
+  hid-over-spi-flags:
+    description:
+      16 bits.
+      Bits 0-12 - Reserved (must be 0)
+      Bit 13 - SPI Write Mode. Possible values -
+        * 0b0- Writes are carried out in Single-SPI mode
+        * 0b1- Writes are carried out in the Multi-SPI mode specified by bits
+               14-15
+      Bits 14-15 - Multi-SPI Mode. Possible values - 
+        * 0b00- Single SPI
+        * 0b01- Dual SPI
+        * 0b10- Quad SPI
+
+required:
+  - compatible
+  - interrupts
+  - reset-gpios
+  - vdd-supply
+  - input-report-header-address
+  - input-report-body-address
+  - output-report-address
+  - read-opcode
+  - write-opcode
+  - hid-over-spi-flags
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      hid@0 {
+        compatible = "microsoft,g6-touch-digitizer";
+        reg = <0x0>;
+        interrupts-extended = <&gpio 42 IRQ_TYPE_EDGE_FALLING>;
+        reset-gpios = <&gpio 27 GPIO_ACTIVE_LOW>;
+        vdd-supply = <&pm8350c_l3>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&ts_d6_reset_assert &ts_d6_int_bias>;
+        input-report-header-address = <0x1000>;
+        input-report-body-address = <0x1004>;
+        output-report-address = <0x2000>;
+        read-opcode = <0x0b>;
+        write-opcode = <0x02>;
+        hid-over-spi-flags = <0x00>;
+        post-power-on-delay-ms = <5>;
+        minimal-reset-delay-ms = <5>;
+      };
+    };
Signature · 1 line
2.25.1
maintainer
#4 lore raw

Re: [PATCH v5 3/6] dt-bindings: input: Document Microsoft G6 Touch Digitizer

Quoted 50 lines · Jarrett Schultz

From: Jarrett Schultz <[email protected]>

Documentation describes the required and optional properties for implementing Device Tree for a Microsoft G6 Touch Digitizer that supports HID over SPI Protocol 1.0 specification.

---
 .../input/microsoft,g6-touch-digitizer.yaml   | 135 ++++++++++++++++++
 1 file changed, 135 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +31 -0
new file mode 100644
index 000000000000..b607bbb32a42
@@ -0,0 +1,135 @@
+# SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/microsoft,g6-touch-digitizer.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microsoft G6 Touch Digitizer
+
+maintainers:
+  - Dmitry Antipov <[email protected]>
+
+description: |
+  Microsoft G6 touch digitizer is a HID over SPI device supporting HID Over SPI
+  Protocol Specification 1.0, available at
+  https://www.microsoft.com/en-us/download/details.aspx?id=103325.
+
+properties:
+  compatible:
+    items:
+      - const: microsoft,g6-touch-digitizer
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+    description:
+      GPIO specifier for the digitizer's reset pin (active low). The line must

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 41

Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10 -0
+      be flagged with GPIO_ACTIVE_LOW.
+
+  vdd-supply:
+    description:
+      Regulator for the VDD supply voltage.
+
+  input-report-header-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215

0xffffff would be more readable IMO.

Quoted 11 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +11 -0
+    description:
+      A value to be included in the Read Approval packet, listing an address of
+      the input report header to be put on the SPI bus. This address has 24
+      bits.
+
+  input-report-body-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215
+    description:
+      A value to be included in the Read Approval packet, listing an address of

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 62

Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10 -0
+      the input report body to be put on the SPI bus. This address has 24 bits.
+
+  output-report-address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    minimum: 0
+    maximum: 16777215
+    description:
+      A value to be included in the Output Report sent by the host, listing an
+      address where the output report on the SPI bus is to be written to. This
+      address has 24 bits.

Are all these properties common to HID-over-SPI or all of HID? If so, then they should be in a common, shared schema doc and referenced here.

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 72

Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10 -0
+
+  post-power-on-delay-ms:
+    description:
+      Optional time in ms required by the device after enabling its regulators
+      or powering it on, before it is ready for communication.
+
+  minimal-reset-delay-ms:
+    description:
+      Optional minimum amount of time in ms that device needs to be in reset
+      state for the reset to take effect.

These delays should really be implied by the compatible string.

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 76

Quoted 4 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +4 -0
+
+  read-opcode:
+    description: 
+      Value to be used in Read Approval packets. 1 byte.

Needs a type reference.

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 80

Quoted 4 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +4 -0
+
+  write-opcode:
+    description:
+      Value to be used in Write Approval packets. 1 byte.

ditto

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 93

Quoted 13 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +13 -0
+
+  hid-over-spi-flags:
+    description:
+      16 bits.
+      Bits 0-12 - Reserved (must be 0)
+      Bit 13 - SPI Write Mode. Possible values -
+        * 0b0- Writes are carried out in Single-SPI mode
+        * 0b1- Writes are carried out in the Multi-SPI mode specified by bits
+               14-15
+      Bits 14-15 - Multi-SPI Mode. Possible values - 
+        * 0b00- Single SPI
+        * 0b01- Dual SPI
+        * 0b10- Quad SPI

ditto.

The existing SPI bus width properties wouldn't work here?

Quoted 27 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +27 -0
+
+required:
+  - compatible
+  - interrupts
+  - reset-gpios
+  - vdd-supply
+  - input-report-header-address
+  - input-report-body-address
+  - output-report-address
+  - read-opcode
+  - write-opcode
+  - hid-over-spi-flags
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    spi {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      hid@0 {
+        compatible = "microsoft,g6-touch-digitizer";
+        reg = <0x0>;

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 130

Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10 -0
+        interrupts-extended = <&gpio 42 IRQ_TYPE_EDGE_FALLING>;
+        reset-gpios = <&gpio 27 GPIO_ACTIVE_LOW>;
+        vdd-supply = <&pm8350c_l3>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&ts_d6_reset_assert &ts_d6_int_bias>;
+        input-report-header-address = <0x1000>;
+        input-report-body-address = <0x1004>;
+        output-report-address = <0x2000>;
+        read-opcode = <0x0b>;
+        write-opcode = <0x02>;

Description says 8-bit, but this is 32-bits.

Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 131

Quoted 1 line
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +1 -0
+        hid-over-spi-flags = <0x00>;

Description says 16-bits, but this is 32-bits.

Quoted 8 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +4 -0
+        post-power-on-delay-ms = <5>;
+        minimal-reset-delay-ms = <5>;
+      };
+    };
Signature · 1 line
2.25.1
#5 lore raw

PATCH v5 4/6 Documentation: Correction in HID output_report callback description.

In reply to Jarrett Schultz

From: Jarrett Schultz <[email protected]>

Originally output_report callback was described as must-be asynchronous, but that is not the case in some implementations, namely i2c-hid. Correct the documentation to say that it may be asynchronous.

---
 Documentation/hid/hid-transport.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/hid/hid-transport.rst +2 -2
index 6f1692da296c..2008cf432af1 100644
@@ -327,8 +327,8 @@ The available HID callbacks are:
 
    Send raw output report via intr channel. Used by some HID device drivers
    which require high throughput for outgoing requests on the intr channel. This
-   must not cause SET_REPORT calls! This must be implemented as asynchronous
-   output report on the intr channel!
+   must not cause SET_REPORT calls! This call might be asynchronous, so the
+   caller should not expect an immediate response!
 
    ::
 
Signature · 1 line
2.25.1
#6 lore raw

PATCH v5 5/6 HID: add spi-hid, transport driver for HID over SPI bus

In reply to Jarrett Schultz

From: Jarrett Schultz <[email protected]>

This driver follows HID Over SPI Protocol Specification 1.0 available at
https://www.microsoft.com/en-us/download/details.aspx?id=103325. The initial version of the driver does not support: 1) multi-fragment input reports, 2) sending GET_INPUT and COMMAND output report types and processing their respective acknowledge input reports, and 3) device sleep power state.

---
 drivers/hid/Kconfig                 |    2 +
 drivers/hid/Makefile                |    1 +
 drivers/hid/spi-hid/Kconfig         |   25 +
 drivers/hid/spi-hid/Makefile        |   12 +
 drivers/hid/spi-hid/spi-hid-core.c  | 1326 +++++++++++++++++++++++++++
 drivers/hid/spi-hid/spi-hid-core.h  |  188 ++++
 drivers/hid/spi-hid/spi-hid-of.c    |  141 +++
 drivers/hid/spi-hid/spi-hid-of.h    |   30 +
 drivers/hid/spi-hid/spi-hid_trace.h |  194 ++++
 drivers/hid/spi-hid/trace.c         |    9 +
 10 files changed, 1928 insertions(+)
 create mode 100644 drivers/hid/spi-hid/Kconfig
 create mode 100644 drivers/hid/spi-hid/Makefile
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.h
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.h
 create mode 100644 drivers/hid/spi-hid/spi-hid_trace.h
 create mode 100644 drivers/hid/spi-hid/trace.c
drivers/hid/Kconfig +2 -0
index 70da5931082f..a396829c4c0b 100644
@@ -1314,6 +1314,8 @@ source "drivers/hid/usbhid/Kconfig"
 
 source "drivers/hid/i2c-hid/Kconfig"
 
+source "drivers/hid/spi-hid/Kconfig"
+
 source "drivers/hid/intel-ish-hid/Kconfig"
 
 source "drivers/hid/amd-sfh-hid/Kconfig"
drivers/hid/Makefile +1 -0
index cac2cbe26d11..1699863e4021 100644
@@ -149,6 +149,7 @@ obj-$(CONFIG_USB_MOUSE)		+= usbhid/
 obj-$(CONFIG_USB_KBD)		+= usbhid/
 
 obj-$(CONFIG_I2C_HID_CORE)	+= i2c-hid/
+obj-$(CONFIG_SPI_HID)		+= spi-hid/
 
 obj-$(CONFIG_INTEL_ISH_HID)	+= intel-ish-hid/
 obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER)	+= intel-ish-hid/
drivers/hid/spi-hid/Kconfig new file +25 -0
new file mode 100644
index 000000000000..37302d658162
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2021 Microsoft Corporation
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+menu "SPI HID support"
+	depends on SPI
+
+config SPI_HID
+	tristate "HID over SPI transport layer"
+	default n
+	depends on SPI && INPUT && OF
+	select HID
+	help
+	  Say Y here if you use a keyboard, a touchpad, a touchscreen, or any
+	  other HID based devices which is connected to your computer via SPI.
+
+	  If unsure, say N.
+
+	  This support is also available as a module.  If so, the module
+	  will be called spi-hid.
+
+endmenu
drivers/hid/spi-hid/Makefile new file +12 -0
new file mode 100644
index 000000000000..b9f73982b956
@@ -0,0 +1,12 @@
+#
+# Copyright (c) 2021 Microsoft Corporation
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#
+# Makefile for the HID over SPI transport driver
+#
+CFLAGS_trace.o = -I$(src)
+obj-$(CONFIG_SPI_HID)	+= spi-hid.o
+spi-hid-objs := spi-hid-core.o spi-hid-of.o trace.o
drivers/hid/spi-hid/spi-hid-core.c new file +1326 -0

1,326 lines not on this page · raw message

drivers/hid/spi-hid/spi-hid-core.h new file +188 -0

188 lines not on this page · raw message

drivers/hid/spi-hid/spi-hid-of.c new file +141 -0

141 lines not on this page · raw message

drivers/hid/spi-hid/spi-hid-of.h new file +30 -0
new file mode 100644
index 000000000000..48d9dfe44e95
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2021 Microsoft Corporation
+ */
+
+#ifndef SPI_HID_OF_H
+#define SPI_HID_OF_H
+
+/* Config structure is filled with data from Device Tree */
+struct spi_hid_of_config {
+	u32 input_report_header_address;
+	u32 input_report_body_address;
+	u32 output_report_address;
+	u8 read_opcode;
+	u8 write_opcode;
+	u32 post_power_on_delay_ms;
+	u32 minimal_reset_delay_ms;
+	struct gpio_desc *reset_gpio;
+	struct regulator *supply;
+};
+
+int spi_hid_of_populate_config(struct spi_hid_of_config *conf,
+				struct device *dev);
+int spi_hid_of_power_down(struct spi_hid_of_config *conf);
+int spi_hid_of_power_up(struct spi_hid_of_config *conf);
+void spi_hid_of_assert_reset(struct spi_hid_of_config *conf);
+void spi_hid_of_deassert_reset(struct spi_hid_of_config *conf);
+void spi_hid_of_sleep_minimal_reset_delay(struct spi_hid_of_config *conf);
+
+#endif
drivers/hid/spi-hid/spi-hid_trace.h new file +194 -0

194 lines not on this page · raw message

drivers/hid/spi-hid/trace.c new file +9 -0
new file mode 100644
index 000000000000..6cd686c9493e
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 Microsoft Corporation
+ *
+ * Author: Felipe Balbi <[email protected]>
+ */
+
+#define CREATE_TRACE_POINTS
+#include "spi-hid_trace.h"
Signature · 1 line
2.25.1
reviewer
#7 lore raw

Re: [PATCH v5 5/6] HID: add spi-hid, transport driver for HID over SPI bus

Hi--

Quoted 10 lines · Jarrett Schultz

From: Jarrett Schultz <[email protected]>

This driver follows HID Over SPI Protocol Specification 1.0 available at
https://www.microsoft.com/en-us/download/details.aspx?id=103325. The initial version of the driver does not support: 1) multi-fragment input reports, 2) sending GET_INPUT and COMMAND output report types and processing their respective acknowledge input reports, and 3) device sleep power state.

Missing your (Jarrett's) Signed-off-by: here.

More below...

Quoted 28 lines
---
 drivers/hid/Kconfig                 |    2 +
 drivers/hid/Makefile                |    1 +
 drivers/hid/spi-hid/Kconfig         |   25 +
 drivers/hid/spi-hid/Makefile        |   12 +
 drivers/hid/spi-hid/spi-hid-core.c  | 1326 +++++++++++++++++++++++++++
 drivers/hid/spi-hid/spi-hid-core.h  |  188 ++++
 drivers/hid/spi-hid/spi-hid-of.c    |  141 +++
 drivers/hid/spi-hid/spi-hid-of.h    |   30 +
 drivers/hid/spi-hid/spi-hid_trace.h |  194 ++++
 drivers/hid/spi-hid/trace.c         |    9 +
 10 files changed, 1928 insertions(+)
 create mode 100644 drivers/hid/spi-hid/Kconfig
 create mode 100644 drivers/hid/spi-hid/Makefile
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-core.h
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.c
 create mode 100644 drivers/hid/spi-hid/spi-hid-of.h
 create mode 100644 drivers/hid/spi-hid/spi-hid_trace.h
 create mode 100644 drivers/hid/spi-hid/trace.c
drivers/hid/spi-hid/Kconfig new file +0 -0
new file mode 100644
index 000000000000..37302d658162

drivers/hid/spi-hid/Kconfig line 7

Quoted 7 lines
drivers/hid/spi-hid/Kconfig new file +7 -0
@@ -0,0 +1,25 @@
+#
+# Copyright (c) 2021 Microsoft Corporation
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published by
+# the Free Software Foundation.
+#

Please just use SPDX tags instead of all of that.
See other hid/Kconfig files for examples.

drivers/hid/spi-hid/Kconfig line 18

Quoted 11 lines
drivers/hid/spi-hid/Kconfig new file +11 -0
+menu "SPI HID support"
+	depends on SPI
+
+config SPI_HID
+	tristate "HID over SPI transport layer"
+	default n
+	depends on SPI && INPUT && OF
+	select HID
+	help
+	  Say Y here if you use a keyboard, a touchpad, a touchscreen, or any
+	  other HID based devices which is connected to your computer via SPI.

HID-based devices which are connected
(or)
HID-based device which is connected

Quoted 7 lines
drivers/hid/spi-hid/Kconfig new file +7 -0
+
+	  If unsure, say N.
+
+	  This support is also available as a module.  If so, the module
+	  will be called spi-hid.
+
+endmenu
Signature · 1 line
~Randy
#8 lore raw

Re: [PATCH v5 5/6] HID: add spi-hid, transport driver for HID over SPI bus

In reply to Jarrett Schultz
Thank you for the patch! Perhaps something to improve:

Hi Jarrett,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on hid/for-next]
[also build test WARNING on dtor-input/next robh/for-next linus/master v5.19-rc6 next-20220711] [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/Jarrett-Schultz/Add-spi-hid-transport-for-HID-over-SPI-bus/20220708-010203
base:   https://git.kernel.org/pub/scm/linux/kernel/git/hid/hid.git for-next
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20220712/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 77a38f6839980bfac61babb40d83772c51427011)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/d0121c2f2d1bb21824555c34c233dd3fbc6aee96
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Jarrett-Schultz/Add-spi-hid-transport-for-HID-over-SPI-bus/20220708-010203
git checkout d0121c2f2d1bb21824555c34c233dd3fbc6aee96
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/hid/spi-hid/ drivers/md/ drivers/net/ethernet/marvell/prestera/ drivers/vfio/pci/mlx5/

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

>> drivers/hid/spi-hid/spi-hid-core.c:193:20: warning: 'const' type qualifier on return type has no effect [-Wignored-qualifiers]
   static const char *const spi_hid_power_mode_string(u8 power_state)
                      ^~~~~~
>> drivers/hid/spi-hid/spi-hid-core.c:691:4: warning: format specifies type 'unsigned short' but the argument has type '__u32' (aka 'unsigned int') [-Wformat]
                           hid->vendor, hid->product);
                           ^~~~~~~~~~~
   drivers/hid/spi-hid/spi-hid-core.c:691:17: warning: format specifies type 'unsigned short' but the argument has type '__u32' (aka 'unsigned int') [-Wformat]
                           hid->vendor, hid->product);
                                        ^~~~~~~~~~~~

drivers/hid/spi-hid/spi-hid-core.c:1318:13: error: incompatible function pointer types initializing 'void (*)(struct spi_device *)' with an expression of type 'int (struct spi_device *)' [-Werror,-Wincompatible-function-pointer-types]
.remove = spi_hid_remove,
^~~~~~~~~~~~~~
3 warnings and 1 error generated.
--
In file included from drivers/hid/spi-hid/trace.c:9:
In file included from drivers/hid/spi-hid/./spi-hid_trace.h:194:
In file included from include/trace/define_trace.h:102:
In file included from include/trace/trace_events.h:237:

>> drivers/hid/spi-hid/./spi-hid_trace.h:140:92: warning: more '%' conversions than data arguments [-Wformat-insufficient-args]
           TP_printk("spi%d.%d: (%04x:%04x v%d) HID v%d.%d state i:%d p:%d len i:%d o:%d r:%d flags %c",
                                                                                                    ~^
   include/trace/stages/stage3_trace_output.h:9:33: note: expanded from macro 'TP_printk'
   #define TP_printk(fmt, args...) fmt "\n", args
                                   ^~~
   include/trace/trace_events.h:203:27: note: expanded from macro 'DECLARE_EVENT_CLASS'
           trace_event_printf(iter, print);                                \
                                    ^~~~~

1 warning generated.

vim +/const +193 drivers/hid/spi-hid/spi-hid-core.c

192

 > 193	static const char *const spi_hid_power_mode_string(u8 power_state)

194 {
195 switch (power_state) {
196 case SPI_HID_POWER_MODE_ON:
197 return "d0";
198 case SPI_HID_POWER_MODE_SLEEP:
199 return "d2";
200 case SPI_HID_POWER_MODE_OFF:
201 return "d3";
202 case SPI_HID_POWER_MODE_WAKING_SLEEP:
203 return "d3*";
204 default:
205 return "unknown";
206 }
207 }
208

Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#9 lore raw

PATCH v5 6/6 Enable building drivers/hid/spi-hid as a module

In reply to Jarrett Schultz

From: Jarrett Schultz <[email protected]>

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 7d1105343bc2..731fc6e67f31 100644
@@ -848,6 +848,7 @@ CONFIG_SND_AUDIO_GRAPH_CARD2=m
 CONFIG_HID_MULTITOUCH=m
 CONFIG_I2C_HID_ACPI=m
 CONFIG_I2C_HID_OF=m
+CONFIG_SPI_HID=m
 CONFIG_USB=y
 CONFIG_USB_OTG=y
 CONFIG_USB_XHCI_HCD=y
Signature · 1 line
2.25.1
#10 lore raw
In reply to Jarrett Schultz
Quoted 4 lines · Jarrett Schultz

Surface Duo devices use a touch digitizer that communicates to the main SoC via SPI and presents itself as a HID device. This patch's goal is to add the spi-hid transport driver to drivers/hid. The driver follows the publically available HID Over SPI Protocol Specification version 1.0.

As far as I can tell based on the downstream code you provide in [1], your proposed driver (and v1.0 spec) is incompatible with the version used on current Surface devices (Surface Duo 1 and 2, Surface Pro X, and I assume some AMD/x86 based devices on which you also use spi-hid for the digitizer). On those, SPI_HID_SUPPORTED_VERSION is 0x0100 whereas it is 0x0300 for the driver proposed here, along with at least some protocol struct changes.

Do you have any plans on supporting those devices (i.e. protocol version 0x0100) at some point?

Regards,
Max

[1]: https://github.com/microsoft/surface-duo-oss-kernel.msm-5..4/tree/surfaceduo2/11/2022.108.8/drivers/hid/spi-hid

#11 lore raw
In reply to Jarrett Schultz
Quoted 9 lines · Jarrett Schultz

From: Jarrett Schultz <[email protected]>

Surface Duo devices use a touch digitizer that communicates to the main SoC via SPI and presents itself as a HID device. This patch's goal is to add the spi-hid transport driver to drivers/hid. The driver follows the publically available HID Over SPI Protocol Specification version 1.0.

The specification is available at
https://www.microsoft.com/en-us/download/details.aspx?id=103325.

Hi, I know this is a bit of an old thread..

The spec mentions some oddities around dual or quad SPI - do you perhaps have some version of this patchset that implements those?

Konrad