Add spi-hid, transport for HID over SPI bus
Subsystems (5)
v4 cover Add spi-hid, transport for HID over SPI bus
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 (6):
HID: Add BUS_SPI support when printing out device info in
hid_connect()
HID: define HID_SPI_DEVICE macro in hid.h
Documentation: DT bindings for Microsoft G6 Touch Digitizer
Documentation: Correction in HID output_report callback description.
HID: add spi-hid, transport driver for HID over SPI bus
Defconfig: add CONFIG_SPI_HID=m
.../input/microsoft,g6-touch-digitizer.yaml | 105 ++ 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, 2041 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
PATCH v4 1/6 HID: Add BUS_SPI support when printing out device info in hid_connect()
From: Dmitry Antipov <[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
@@ -2005,6 +2005,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
PATCH v4 2/6 HID: define HID_SPI_DEVICE macro in hid.h
In reply to Dmitry AntipovFrom: Dmitry Antipov <[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
@@ -684,6 +684,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
PATCH v4 3/6 Documentation: DT bindings for Microsoft G6 Touch Digitizer
In reply to Dmitry AntipovFrom: Dmitry Antipov <[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 | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +105 -0
@@ -0,0 +1,105 @@ +# 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: + oneOf: + - const: microsoft,g6-touch-digitizer + - items: + - const: microsoft,g6-touch-digitizer + - const: hid-over-spi + + 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 + description: + This property and the rest are described in HID Over SPI Protocol Spec 1.0 + + input-report-body-address: + $ref: /schemas/types.yaml#/definitions/uint32 + + output-report-address: + $ref: /schemas/types.yaml#/definitions/uint32 + + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint32 + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint32 + + hid-over-spi-flags: + $ref: /schemas/types.yaml#/definitions/uint32 + + 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. + +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-hid-dev0 { + compatible = "microsoft,g6-touch-digitizer", "hid-over-spi"; + reg = <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>; + hid-over-spi-flags = <0x00>; + post-power-on-delay-ms = <5>; + minimal-reset-delay-ms = <5>; + };
Signature · 1 line
2.25.1
Rob Herring
maintainerRe: [PATCH v4 3/6] Documentation: DT bindings for Microsoft G6 Touch Digitizer
Quoted 6 lines · Dmitry Antipov
From: Dmitry Antipov <[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.
Quoted 6 lines
Signed-off-by Dmitry Antipov <[email protected]>--- .../input/microsoft,g6-touch-digitizer.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:./Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml:22:9: [warning] wrong indentation: expected 10 but found 8 (indentation)
dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dts:23.11-21: Warning (reg_format): /example-0/spi-hid-dev0:reg: property has invalid length (4 bytes) (#address-cells == 1, #size-cells == 1) Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dts:21.22-37.11: Warning (unit_address_vs_reg): /example-0/spi-hid-dev0: node has a reg or ranges property, but no unit name Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dt.yaml: Warning (pci_device_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dt.yaml: Warning (pci_device_bus_num): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dt.yaml: Warning (simple_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dt.yaml: Warning (i2c_bus_reg): Failed prerequisite 'reg_format' Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.example.dt.yaml: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/1597405
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit.
Rob Herring
maintainerRe: [PATCH v4 3/6] Documentation: DT bindings for Microsoft G6 Touch Digitizer
In reply to Dmitry AntipovQuoted 1 line · Dmitry Antipov
From: Dmitry Antipov <[email protected]>
Please follow the conventions of the subsystem for the subject:
dt-bindings: input: ...
Quoted 30 lines
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.
Signed-off-by Dmitry Antipov <[email protected]>--- .../input/microsoft,g6-touch-digitizer.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yamlDocumentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +13
-0@@ -0,0 +1,105 @@ +# 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
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 23
Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10
-0+ Protocol Specification 1.0, available at + https://www.microsoft.com/en-us/download/details.aspx?id=103325. + +properties: + compatible: + oneOf: + - const: microsoft,g6-touch-digitizer + - items: + - const: microsoft,g6-touch-digitizer + - const: hid-over-spi
Why are both cases needed?
Assuming you keep the 2nd case, you will need a custom 'select' to avoid applying this schema to another binding using 'hid-over-spi':
select:
properties:
compatible:
contains:
const: microsoft,g6-touch-digitizer
required:
- compatible
Quoted 11 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +11
-0+ + 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 44
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 + description: + This property and the rest are described in HID Over SPI Protocol Spec 1.0
Each property needs a description and a more specific spec location.
No constraints on the values? 0 - 2^32 is valid?
Quoted 16 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +16
-0+ + input-report-body-address: + $ref: /schemas/types.yaml#/definitions/uint32 + + output-report-address: + $ref: /schemas/types.yaml#/definitions/uint32 + + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint32 + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint32 + + hid-over-spi-flags: + $ref: /schemas/types.yaml#/definitions/uint32 +
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 69
Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +9
-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 should be implied by the compatible string.
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 74
Quoted 5 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +5
-0+ +required: + - compatible + - interrupts + - reset-gpios
It's not allowed to have reset under h/w control?
Quoted 5 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +5
-0+ - vdd-supply + - input-report-header-address + - input-report-body-address + - output-report-address + - read-opcode
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml line 89
Quoted 10 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +10
-0+ - write-opcode + - hid-over-spi-flags + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/gpio/gpio.h> + spi-hid-dev0 {
hid@0
And you'll need to define a spi bus.
Quoted 20 lines
Documentation/devicetree/bindings/input/microsoft,g6-touch-digitizer.yaml new file +16
-0+ compatible = "microsoft,g6-touch-digitizer", "hid-over-spi"; + reg = <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>; + hid-over-spi-flags = <0x00>; + post-power-on-delay-ms = <5>; + minimal-reset-delay-ms = <5>; + };Signature · 1 line
2.25.1
PATCH v4 4/6 Documentation: Correction in HID output_report callback description.
In reply to Dmitry AntipovFrom: Dmitry Antipov <[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
@@ -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
PATCH v4 5/6 HID: add spi-hid, transport driver for HID over SPI bus
In reply to Dmitry AntipovFrom: Dmitry Antipov <[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
@@ -1262,6 +1262,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
@@ -144,6 +144,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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v4 6/6 Defconfig: add CONFIG_SPI_HID=m
In reply to Dmitry AntipovFrom: Dmitry Antipov <[email protected]>
This enables building drivers/hid/spi-hid as module.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -805,6 +805,7 @@ CONFIG_SND_AUDIO_GRAPH_CARD=m CONFIG_HID_MULTITOUCH=m CONFIG_I2C_HID_ACPI=m CONFIG_I2C_HID_OF=m +CONFIG_SPI_HID=m CONFIG_USB_CONN_GPIO=m CONFIG_USB=y CONFIG_USB_OTG=y
Signature · 1 line
2.25.1