Add spi-hid transport driver
Subsystems (6)
v3 cover Add spi-hid transport driver
This series picks up the spi-hid driver work originally started by Microsoft. The patch breakdown has been modified and the implementation has been refactored to address upstream feedback and testing issues. We are submitting this as a new series while keeping the original sign-off chain to reflect the history.
Same as the original series, there is a change to HID documentation, some HID core changes to support a SPI device, the SPI HID transport driver, and HID over SPI Device Tree binding. We have added the HID over SPI ACPI support, power management, panel follower, and quirks for Ilitek touch controllers.
Original authors: Jarrett Schultz <[email protected]>,
Dmitry Antipov <[email protected]>
---
Changes in v3:
- Add io_lock init
- Relocate tracepoints to drivers/hid/spi-hid/ and fix tracepoint macros
- Add tracepoints for sync, error handling, reset, and report processing
- Clean up internal includes and fix Makefile CFLAGS
- Add more details in v2 changelog
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Clean up DT bindings: fix formatting and remove timing and flags properties
- Update DT binding example: use a device-specific compatible and drop reset_assert
- Simplify ACPI/OF match tables by removing ACPI_PTR/of_match_ptr
- Refactor OF driver to use match data for timing parameters instead
of DT properties
- Switch to fsleep() for delays in ACPI and OF drivers
- Drop patch 12 as it is vendor specific
- Add a lock to fix input/output concurrency race
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Angela Czubak (2):
HID: spi-hid: add transport driver skeleton for HID over SPI bus
HID: spi_hid: add ACPI support for SPI over HID
Jarrett Schultz (3):
Documentation: Correction in HID output_report callback description.
HID: Add BUS_SPI support and define HID_SPI_DEVICE macro
HID: spi_hid: add device tree support for SPI over HID
Jingyuan Liang (6):
HID: spi-hid: add spi-hid driver HID layer
HID: spi-hid: add HID SPI protocol implementation
HID: spi_hid: add spi_hid traces
dt-bindings: input: Document hid-over-spi DT schema
HID: spi-hid: add power management implementation
HID: spi-hid: add panel follower support
.../devicetree/bindings/input/hid-over-spi.yaml | 126 ++ Documentation/hid/hid-transport.rst | 4 +- drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/hid-core.c | 3 + drivers/hid/spi-hid/Kconfig | 45 + drivers/hid/spi-hid/Makefile | 12 + drivers/hid/spi-hid/spi-hid-acpi.c | 254 ++++ drivers/hid/spi-hid/spi-hid-core.c | 1456 ++++++++++++++++++++ drivers/hid/spi-hid/spi-hid-core.h | 98 ++ drivers/hid/spi-hid/spi-hid-of.c | 244 ++++ drivers/hid/spi-hid/spi-hid-trace.h | 169 +++ drivers/hid/spi-hid/spi-hid.h | 46 + include/linux/hid.h | 2 + 14 files changed, 2461 insertions(+), 2 deletions(-)
---
base-commit: 05f7e89ab9731565d8a62e3b5d1ec206485eeb0b
change-id: 20260212-send-upstream-75f6fd9ed92e
Best regards,
Signature · 1 line
Jingyuan Liang <[email protected]>
PATCH v3 1/11 Documentation: Correction in HID output_report callback description.
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
@@ -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.53.0.1185.g05d4b7b318-goog
[email protected]
AI reviewRe: [PATCH v3 01/11] Documentation: Correction in HID output_report callback description.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit modifies `Documentation/hid/hid-transport.rst` to state that the `output_report`…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit modifies Documentation/hid/hid-transport.rst to state that the output_report callback 'might be asynchronous', which directly contradicts the strict HID subsystem architectural rule requiring it to be unconditionally asynchronous. --
--- Patch [1]: [PATCH v3 01/11] Documentation: Correction in HID output_report callback description. --- commit 5b8559748c059ec63c5c810fdf494efbd38be948
Author: Jarrett Schultz <[email protected]>
Documentation: Correction in HID output_report callback description.
This commit modifies the HID transport documentation to indicate that the output_report callback might be asynchronous rather than strictly requiring it to be asynchronous. It notes that some implementations, like i2c-hid, do not implement it asynchronously.
Quoted 4 lines
Documentation/hid/hid-transport.rst +0
-0
[ ... ]
Documentation/hid/hid-transport.rst The available HID callbacks are: · line 331
Quoted 8 lines
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!
[Severity: Medium]
This isn't a bug, but does this documentation change conflict with the subsystem's architectural guidelines?
The official HID subsystem guidelines explicitly state that the output_report callback (used for high-throughput data on the interrupt channel) must be asynchronous and must not trigger synchronous SET_REPORT calls.
Relaxing this language to "might be asynchronous" contradicts the strict architectural rule and might encourage future driver implementations that block or perform synchronous operations. Should the documentation continue to mandate the asynchronous requirement to prevent synchronous blocking on the interrupt channel?
Quoted 3 lines
Documentation/hid/hid-transport.rst +0
-0::
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v3 2/11 HID: Add BUS_SPI support and define HID_SPI_DEVICE macro
In reply to Jingyuan LiangFrom: Jarrett Schultz <[email protected]>
If connecting a hid_device with bus field indicating BUS_SPI print out "SPI" in the debug print.
Macro sets the bus field to BUS_SPI and uses arguments to set vendor product fields.
--- drivers/hid/hid-core.c | 3 +++ include/linux/hid.h | 2 ++ 2 files changed, 5 insertions(+)
drivers/hid/hid-core.c +3 -0
@@ -2316,6 +2316,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_SDW : bus ="SOUNDWIRE" ;break ;
include/linux/hid.h +2 -0
@@ -786,6 +786,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.53.0.1185.g05d4b7b318-goog
PATCH v3 3/11 HID: spi-hid: add transport driver skeleton for HID over SPI bus
In reply to Jingyuan LiangFrom: Angela Czubak <[email protected]>
Create spi-hid folder and add Kconfig and Makefile for spi-hid driver. Add basic device structure, definitions, and probe/remove functions.
--- drivers/hid/Kconfig | 2 + drivers/hid/Makefile | 2 + drivers/hid/spi-hid/Kconfig | 15 +++ drivers/hid/spi-hid/Makefile | 9 ++ drivers/hid/spi-hid/spi-hid-core.c | 213 +++++++++++++++++++++++++++++++++++++ 5 files changed, 241 insertions(+)
drivers/hid/Kconfig +2 -0
@@ -1434,6 +1434,8 @@ source "drivers/hid/bpf/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 +2 -0
@@ -169,6 +169,8 @@ obj-$(CONFIG_USB_KBD) += usbhid/ obj-$(CONFIG_I2C_HID_CORE) += i2c-hid/ +obj-$(CONFIG_SPI_HID_CORE) += spi-hid/ + obj-$(CONFIG_INTEL_ISH_HID) += intel-ish-hid/ obj-$(CONFIG_AMD_SFH_HID) += amd-sfh-hid/
drivers/hid/spi-hid/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (c) 2021 Microsoft Corporation +# + +menuconfig SPI_HID + tristate "SPI HID support" + default y + depends on SPI + +if SPI_HID + +config SPI_HID_CORE + tristate +endif
drivers/hid/spi-hid/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Makefile for the SPI HID input drivers +# +# Copyright (c) 2021 Microsoft Corporation +# + +obj-$(CONFIG_SPI_HID_CORE) += spi-hid.o +spi-hid-objs = spi-hid-core.o
drivers/hid/spi-hid/spi-hid-core.c new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 4/11 HID: spi-hid: add spi-hid driver HID layer
In reply to Jingyuan LiangAdd HID low level driver callbacks to register SPI as a HID driver, and an external touch device as a HID device.
--- drivers/hid/spi-hid/spi-hid-core.c | 519 +++++++++++++++++++++++++++++++++++++ 1 file changed, 519 insertions(+)
drivers/hid/spi-hid/spi-hid-core.c +519 -0
@@ -20,13 +20,69 @@* Copyright (c) 2006-2010 Jiri Kosina */ +#include <linux/completion.h> +#include <linux/crc32.h> #include <linux/device.h> +#include <linux/err.h> #include <linux/hid.h> #include <linux/hid-over-spi.h> #include <linux/interrupt.h> +#include <linux/jiffies.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <linux/spi/spi.h> +#include <linux/string.h> +#include <linux/sysfs.h> +#include <linux/unaligned.h> + +#define SPI_HID_OUTPUT_REPORT_CONTENT_ID_DESC_REQUEST 0x00 + +#define SPI_HID_RESP_TIMEOUT 1000 + +/* Protocol message size constants */ +#define SPI_HID_OUTPUT_HEADER_LEN 8 + +/* flags */ +/* +* ready flag indicates that the FW is ready to accept commands and +* requests. The FW becomes ready after sending the report descriptor. +*/ +#define SPI_HID_READY 0 + +/* Raw input buffer with data from the bus */ +struct spi_hid_input_buf { +u8 header[HIDSPI_INPUT_HEADER_SIZE ]; +u8 body[HIDSPI_INPUT_BODY_HEADER_SIZE ]; +u8 content[]; +}; + +/* Raw output report buffer to be put on the bus */ +struct spi_hid_output_buf { +u8 header[SPI_HID_OUTPUT_HEADER_LEN ]; +u8 content[]; +}; + +/* Data necessary to send an output report */ +struct spi_hid_output_report { +u8 report_type; +u16 content_length; +u8 content_id; +u8 *content; +}; + +/* Processed data from a device descriptor */ +struct spi_hid_device_descriptor { +u16 hid_version; +u16 report_descriptor_length; +u16 max_input_length; +u16 max_output_length; +u16 max_fragment_length; +u16 vendor_id; +u16 product_id; +u16 version_id; +u8 no_output_report_ack; +};/* struct spi_hid_conf - Conf provided to the core */ struct spi_hid_conf {
@@ -61,8 +117,26 @@ struct spi_hid {struct spihid_ops *ops;struct spi_hid_conf *conf; +struct spi_hid_device_descriptor desc;/* HID device descriptor. */ +struct spi_hid_output_buf *output;/* Output buffer. */ +struct spi_hid_input_buf *input;/* Input buffer. */ +struct spi_hid_input_buf *response;/* Response buffer. */ + +u16 response_length; +u16 bufsize; +enum hidspi_power_state power_state; +u8 reset_attempts;/* The number of reset attempts. */ + +unsigned long flags;/* device flags. */ + +/* Control lock to make sure one output transaction at a time. */ +struct mutex output_lock; +struct completion output_done; + +u32 report_descriptor_crc32;/* HID report descriptor crc32 checksum. */ +u32 regulator_error_count;int regulator_last_error;u32 bus_error_count;
@@ -70,6 +144,33 @@ struct spi_hid {u32 dir_count;/* device initiated reset count. */ }; +static struct hid_ll_driver spi_hid_ll_driver; + +static void spi_hid_populate_output_header (u8 *buf, +const struct spi_hid_conf *conf, +const struct spi_hid_output_report *report) +{ + buf[0 ] = conf->write_opcode; +put_unaligned_be24 (conf->output_report_address, &buf[1 ]); + buf[4 ] = report->report_type; +put_unaligned_le16 (report->content_length, &buf[5 ]); + buf[7 ] = report->content_id; +} + +static int spi_hid_output (struct spi_hid *shid,const void *buf,u16 length) +{ +int error; + + error =spi_write (shid->spi, buf, length); + +if (error) { + shid->bus_error_count++; + shid->bus_last_error = error; + } + +return error; +} +static const char *spi_hid_power_mode_string (enum hidspi_power_state power_state) {switch (power_state) {
@@ -84,11 +185,416 @@ static const char *spi_hid_power_mode_string(enum hidspi_power_state power_state } } +static void spi_hid_stop_hid (struct spi_hid *shid) +{ +struct hid_device *hid = shid->hid; + + shid->hid =NULL ; +clear_bit (SPI_HID_READY , &shid->flags); + +if (hid) +hid_destroy_device (hid); +} + +static int spi_hid_send_output_report (struct spi_hid *shid, +struct spi_hid_output_report *report) +{ +struct spi_hid_output_buf *buf = shid->output; +struct device *dev = &shid->spi->dev; +u16 report_length; +u16 padded_length; +u8 padding; +int error; + +guard (mutex)(&shid->output_lock); +if (report->content_length > shid->desc.max_output_length) { +dev_err (dev,"Output report too big, content_length 0x%x." , + report->content_length); +return -E2BIG ; + } + +spi_hid_populate_output_header (buf->header, shid->conf, report); + +if (report->content_length) +memcpy (&buf->content, report->content, report->content_length); + + report_length =sizeof (buf->header) + report->content_length; + padded_length =round_up (report_length,4 ); + padding = padded_length - report_length; +memset (&buf->content[report->content_length],0 , padding); + + error =spi_hid_output (shid, buf, padded_length); +if (error) +dev_err (dev,"Failed output transfer: %d." , error); + +return error; +} + +static int spi_hid_sync_request (struct spi_hid *shid, +struct spi_hid_output_report *report) +{ +struct device *dev = &shid->spi->dev; +int error; + + error =spi_hid_send_output_report (shid, report); +if (error) +return error; + + error =wait_for_completion_interruptible_timeout (&shid->output_done, +msecs_to_jiffies (SPI_HID_RESP_TIMEOUT )); +if (error ==0 ) { +dev_err (dev,"Response timed out." ); +return -ETIMEDOUT ; + } + +return 0 ; +} + +/* +* This function returns the length of the report descriptor, or a negative +* error code if something went wrong. +*/ +static int spi_hid_report_descriptor_request (struct spi_hid *shid) +{ +struct device *dev = &shid->spi->dev; +struct spi_hid_output_report report = { + .report_type =REPORT_DESCRIPTOR , + .content_length =0 , + .content_id =SPI_HID_OUTPUT_REPORT_CONTENT_ID_DESC_REQUEST , + .content =NULL , + }; +int ret; + + ret =spi_hid_sync_request (shid, &report); +if (ret) { +dev_err (dev, +"Expected report descriptor not received: %d." , ret); +return ret; + } + + ret = shid->response_length; +if (ret != shid->desc.report_descriptor_length) { + ret = min_t(unsigned int, ret, shid->desc.report_descriptor_length); +dev_err (dev,"Received report descriptor length doesn't match device descriptor field, using min of the two: %d." , + ret); + } + +return ret; +} + +static int spi_hid_create_device (struct spi_hid *shid) +{ +struct hid_device *hid; +struct device *dev = &shid->spi->dev; +int error; + + hid =hid_allocate_device (); + error =PTR_ERR_OR_ZERO (hid); +if (error) { +dev_err (dev,"Failed to allocate hid device: %d." , error); +return error; + } + + hid->driver_data = shid->spi; + hid->ll_driver = &spi_hid_ll_driver; + hid->dev.parent = &shid->spi->dev; + hid->bus =BUS_SPI ; + hid->version = shid->desc.hid_version; + hid->vendor = shid->desc.vendor_id; + hid->product = shid->desc.product_id; + +snprintf (hid->name,sizeof (hid->name),"spi %04X:%04X" , + hid->vendor, hid->product); +strscpy (hid->phys,dev_name (&shid->spi->dev),sizeof (hid->phys)); + + shid->hid = hid; + + error =hid_add_device (hid); +if (error) { +dev_err (dev,"Failed to add hid device: %d." , error); +/* +* We likely got here because report descriptor request timed +* out. Let's disconnect and destroy the hid_device structure. +*/ +spi_hid_stop_hid (shid); +return error; + } + +return 0 ; +} + +static int spi_hid_get_request (struct spi_hid *shid,u8 content_id) +{ +struct device *dev = &shid->spi->dev; +struct spi_hid_output_report report = { + .report_type =GET_FEATURE , + .content_length =0 , + .content_id = content_id, + .content =NULL , + }; +int error; + + error =spi_hid_sync_request (shid, &report); +if (error) { +dev_err (dev, +"Expected get request response not received! Error %d." , + error); +return error; + } + +return 0 ; +} + +static int spi_hid_set_request (struct spi_hid *shid,u8 *arg_buf,u16 arg_len, +u8 content_id) +{ +struct spi_hid_output_report report = { + .report_type =SET_FEATURE , + .content_length = arg_len, + .content_id = content_id, + .content = arg_buf, + }; + +return spi_hid_sync_request (shid, &report); +} + +/* This is a placeholder. Will be implemented in the next patch. */ static irqreturn_t spi_hid_dev_irq (int irq,void *_shid) {return IRQ_HANDLED ; } +static int spi_hid_alloc_buffers (struct spi_hid *shid,size_t report_size) +{ +struct device *dev = &shid->spi->dev; +int inbufsize =sizeof (shid->input->header) +sizeof (shid->input->body) + report_size; +int outbufsize =sizeof (shid->output->header) + report_size; + +// devm_krealloc with __GFP_ZERO ensures the new memory is initialized + shid->output =devm_krealloc (dev, shid->output, outbufsize,GFP_KERNEL | __GFP_ZERO); + shid->input =devm_krealloc (dev, shid->input, inbufsize,GFP_KERNEL | __GFP_ZERO); + shid->response =devm_krealloc (dev, shid->response, inbufsize,GFP_KERNEL | __GFP_ZERO); + +if (!shid->output || !shid->input || !shid->response) +return -ENOMEM ; + + shid->bufsize = report_size; + +return 0 ; +} + +static int spi_hid_get_report_length (struct hid_report *report) +{ +return ((report->size -1 ) >>3 ) +1 + + report->device->report_enum[report->type].numbered +2 ; +} + +/* +* Traverse the supplied list of reports and find the longest +*/ +static void spi_hid_find_max_report (struct hid_device *hid,u32 type, +u16 *max) +{ +struct hid_report *report; +u16 size; + +/* +* We should not rely on wMaxInputLength, as some devices may set it to +* a wrong length. +*/ +list_for_each_entry (report, &hid->report_enum[type].report_list, list) { + size =spi_hid_get_report_length (report); +if (*max < size) + *max = size; + } +} + +/* hid_ll_driver interface functions */ + +static int spi_hid_ll_start (struct hid_device *hid) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); +int error =0 ; +u16 bufsize =0 ; + +spi_hid_find_max_report (hid,HID_INPUT_REPORT , &bufsize); +spi_hid_find_max_report (hid,HID_OUTPUT_REPORT , &bufsize); +spi_hid_find_max_report (hid,HID_FEATURE_REPORT , &bufsize); + +if (bufsize <HID_MIN_BUFFER_SIZE ) { +dev_err (&spi->dev, +"HID_MIN_BUFFER_SIZE > max_input_length (%d)." , + bufsize); +return -EINVAL ; + } + +if (bufsize > shid->bufsize) { +guard (disable_irq)(&shid->spi->irq); + + error =spi_hid_alloc_buffers (shid, bufsize); +if (error) +return error; + } + +return 0 ; +} + +static void spi_hid_ll_stop (struct hid_device *hid) +{ + hid->claimed =0 ; +} + +static int spi_hid_ll_open (struct hid_device *hid) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); + +set_bit (SPI_HID_READY , &shid->flags); +return 0 ; +} + +static void spi_hid_ll_close (struct hid_device *hid) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); + +clear_bit (SPI_HID_READY , &shid->flags); + shid->reset_attempts =0 ; +} + +static int spi_hid_ll_power (struct hid_device *hid,int level) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); +int error =0 ; + +guard (mutex)(&shid->output_lock); +if (!shid->hid) + error = -ENODEV ; + +return error; +} + +static int spi_hid_ll_parse (struct hid_device *hid) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); +struct device *dev = &spi->dev; +int error, len; + + len =spi_hid_report_descriptor_request (shid); +if (len <0 ) { +dev_err (dev,"Report descriptor request failed, %d." , len); +return len; + } + +/* +* FIXME: below call returning 0 doesn't mean that the report descriptor +* is good. We might be caching a crc32 of a corrupted r. d. or who +* knows what the FW sent. Need to have a feedback loop about r. d. +* being ok and only then cache it. +*/ + error =hid_parse_report (hid, (u8 *)shid->response->content, len); +if (error) { +dev_err (dev,"failed parsing report: %d." , error); +return error; + } + shid->report_descriptor_crc32 =crc32_le (0 , + (unsigned char const *)shid->response->content, + len); + +return 0 ; +} + +static int spi_hid_ll_raw_request (struct hid_device *hid, +unsigned char reportnum,__u8 *buf, +size_t len,unsigned char rtype,int reqtype) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); +struct device *dev = &spi->dev; +int ret; + +switch (reqtype) { +case HID_REQ_SET_REPORT : +if (buf[0 ] != reportnum) { +dev_err (dev,"report id mismatch." ); +return -EINVAL ; + } + + ret =spi_hid_set_request (shid, &buf[1 ], len -1 , + reportnum); +if (ret) { +dev_err (dev,"failed to set report." ); +return ret; + } + + ret = len; +break ; +case HID_REQ_GET_REPORT : + ret =spi_hid_get_request (shid, reportnum); +if (ret) { +dev_err (dev,"failed to get report." ); +return ret; + } + + ret =min_t (size_t, len, + (shid->response->body[1 ] | (shid->response->body[2 ] <<8 )) +1 ); + buf[0 ] = shid->response->body[3 ]; +memcpy (&buf[1 ], &shid->response->content, ret); +break ; +default : +dev_err (dev,"invalid request type." ); +return -EIO ; + } + +return ret; +} + +static int spi_hid_ll_output_report (struct hid_device *hid,__u8 *buf, +size_t len) +{ +struct spi_device *spi = hid->driver_data; +struct spi_hid *shid =spi_get_drvdata (spi); +struct device *dev = &spi->dev; +struct spi_hid_output_report report = { + .report_type =OUTPUT_REPORT , + .content_length = len -1 , + .content_id = buf[0 ], + .content = &buf[1 ], + }; +int error; + +if (!test_bit (SPI_HID_READY , &shid->flags)) { +dev_err (dev,"%s called in unready state" , __func__); +return -ENODEV ; + } + +if (shid->desc.no_output_report_ack) + error =spi_hid_send_output_report (shid, &report); +else + error =spi_hid_sync_request (shid, &report); + +if (error) { +dev_err (dev,"failed to send output report." ); +return error; + } + +return len; +} + +static struct hid_ll_driver spi_hid_ll_driver = { + .start = spi_hid_ll_start, + .stop = spi_hid_ll_stop, + .open = spi_hid_ll_open, + .close = spi_hid_ll_close, + .power = spi_hid_ll_power, + .parse = spi_hid_ll_parse, + .output_report = spi_hid_ll_output_report, + .raw_request = spi_hid_ll_raw_request, +}; +static ssize_t bus_error_count_show (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -159,6 +665,15 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,spi_set_drvdata (spi, shid); +/* +* we need to allocate the buffer without knowing the maximum +* size of the reports. Let's use SZ_2K, then we do the +* real computation later. +*/ + error =spi_hid_alloc_buffers (shid,SZ_2K ); +if (error) +return error; +/* * At the end of probe we initialize the device: * 0) assert reset, bias the interrupt line
@@ -191,6 +706,8 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,dev_dbg (dev,"%s: d3 -> %s." , __func__,spi_hid_power_mode_string (shid->power_state)); +spi_hid_create_device (shid); +return 0 ; }EXPORT_SYMBOL_GPL (spi_hid_core_probe);
@@ -201,6 +718,8 @@ void spi_hid_core_remove(struct spi_device *spi)struct device *dev = &spi->dev;int error; +spi_hid_stop_hid (shid); + shid->ops->assert_reset (shid->ops); error = shid->ops->power_down (shid->ops);if (error)
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 5/11 HID: spi-hid: add HID SPI protocol implementation
In reply to Jingyuan LiangThis 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/spi-hid/spi-hid-core.c | 582 ++++++++++++++++++++++++++++++++++++- 1 file changed, 572 insertions(+), 10 deletions(-)
drivers/hid/spi-hid/spi-hid-core.c +572 -10
@@ -23,11 +23,16 @@#include <linux/completion.h> #include <linux/crc32.h> #include <linux/device.h> +#include <linux/dma-mapping.h> #include <linux/err.h> #include <linux/hid.h> #include <linux/hid-over-spi.h> +#include <linux/input.h> #include <linux/interrupt.h> +#include <linux/irq.h> #include <linux/jiffies.h> +#include <linux/kernel.h> +#include <linux/list.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/slab.h>
@@ -35,12 +40,22 @@#include <linux/string.h> #include <linux/sysfs.h> #include <linux/unaligned.h> +#include <linux/wait.h> +#include <linux/workqueue.h> + +/* Protocol constants */ +#define SPI_HID_READ_APPROVAL_CONSTANT 0xff +#define SPI_HID_INPUT_HEADER_SYNC_BYTE 0x5a +#define SPI_HID_INPUT_HEADER_VERSION 0x03 +#define SPI_HID_SUPPORTED_VERSION 0x0300#define SPI_HID_OUTPUT_REPORT_CONTENT_ID_DESC_REQUEST 0x00 -#define SPI_HID_RESP_TIMEOUT 1000 +#define SPI_HID_MAX_RESET_ATTEMPTS 3 +#define SPI_HID_RESP_TIMEOUT 1000/* Protocol message size constants */ +#define SPI_HID_READ_APPROVAL_LEN 5#define SPI_HID_OUTPUT_HEADER_LEN 8/* flags */
@@ -49,6 +64,22 @@* requests. The FW becomes ready after sending the report descriptor. */ #define SPI_HID_READY 0 +/* +* refresh_in_progress is set to true while the refresh_device worker +* thread is destroying and recreating the hidraw device. When this flag +* is set to true, the ll_close and ll_open functions will not cause +* power state changes. +*/ +#define SPI_HID_REFRESH_IN_PROGRESS 1 +/* +* reset_pending indicates that the device is being reset. When this flag +* is set to true, garbage interrupts triggered during reset will be +* dropped and will not cause error handling. +*/ +#define SPI_HID_RESET_PENDING 2 +#define SPI_HID_RESET_RESPONSE 3 +#define SPI_HID_CREATE_DEVICE 4 +#define SPI_HID_ERROR 5/* Raw input buffer with data from the bus */ struct spi_hid_input_buf {
@@ -57,6 +88,22 @@ struct spi_hid_input_buf {u8 content[]; }; +/* Processed data from input report header */ +struct spi_hid_input_header { +u8 version; +u16 report_length; +u8 last_fragment_flag; +u8 sync_const; +}; + +/* Processed data from an input report */ +struct spi_hid_input_report { +u8 report_type; +u16 content_length; +u8 content_id; +u8 *content; +}; +/* Raw output report buffer to be put on the bus */ struct spi_hid_output_buf {u8 header[SPI_HID_OUTPUT_HEADER_LEN ];
@@ -114,6 +161,9 @@ struct spi_hid {struct spi_device *spi;/* spi device. */ struct hid_device *hid;/* pointer to corresponding HID dev. */ +struct spi_transfer input_transfer[2 ];/* Transfer buffer for read and write. */ +struct spi_message input_message;/* used to execute a sequence of spi transfers. */ +struct spihid_ops *ops;struct spi_hid_conf *conf;
@@ -131,10 +181,20 @@ struct spi_hid {unsigned long flags;/* device flags. */ -/* Control lock to make sure one output transaction at a time. */ +struct work_struct reset_work; + +/* Control lock to ensure complete output transaction. */ struct mutex output_lock; +/* Power lock to make sure one power state change at a time. */ +struct mutex power_lock; +/* I/O lock to prevent concurrent output writes during the input read. */ +struct mutex io_lock; +struct completion output_done; +u8 read_approval_header[SPI_HID_READ_APPROVAL_LEN ]; +u8 read_approval_body[SPI_HID_READ_APPROVAL_LEN ]; +u32 report_descriptor_crc32;/* HID report descriptor crc32 checksum. */ u32 regulator_error_count;
@@ -146,6 +206,66 @@ struct spi_hid {static struct hid_ll_driver spi_hid_ll_driver; +static void spi_hid_populate_read_approvals (const struct spi_hid_conf *conf, +u8 *header_buf,u8 *body_buf) +{ + header_buf[0 ] = conf->read_opcode; +put_unaligned_be24 (conf->input_report_header_address, &header_buf[1 ]); + header_buf[4 ] =SPI_HID_READ_APPROVAL_CONSTANT ; + + body_buf[0 ] = conf->read_opcode; +put_unaligned_be24 (conf->input_report_body_address, &body_buf[1 ]); + body_buf[4 ] =SPI_HID_READ_APPROVAL_CONSTANT ; +} + +static void spi_hid_parse_dev_desc (const struct hidspi_dev_descriptor *raw, +struct spi_hid_device_descriptor *desc) +{ + desc->hid_version =le16_to_cpu (raw->bcd_ver); + desc->report_descriptor_length =le16_to_cpu (raw->rep_desc_len); + desc->max_input_length =le16_to_cpu (raw->max_input_len); + desc->max_output_length =le16_to_cpu (raw->max_output_len); + +/* FIXME: multi-fragment not supported, field below not used */ + desc->max_fragment_length =le16_to_cpu (raw->max_frag_len); + + desc->vendor_id =le16_to_cpu (raw->vendor_id); + desc->product_id =le16_to_cpu (raw->product_id); + desc->version_id =le16_to_cpu (raw->version_id); + desc->no_output_report_ack =le16_to_cpu (raw->flags) &BIT (0 ); +} + +static void spi_hid_populate_input_header (const u8 *buf, +struct spi_hid_input_header *header) +{ + header->version = buf[0 ] &0xf ; + header->report_length = (get_unaligned_le16 (&buf[1 ]) &0x3fff ) *4 ; + header->last_fragment_flag = (buf[2 ] &0x40 ) >>6 ; + header->sync_const = buf[3 ]; +} + +static void spi_hid_populate_input_body (const u8 *buf, +struct input_report_body_header *body) +{ + body->input_report_type = buf[0 ]; + body->content_len =get_unaligned_le16 (&buf[1 ]); + body->content_id = buf[3 ]; +} + +static void spi_hid_input_report_prepare (struct spi_hid_input_buf *buf, +struct spi_hid_input_report *report) +{ +struct spi_hid_input_header header; +struct input_report_body_header body; + +spi_hid_populate_input_header (buf->header, &header); +spi_hid_populate_input_body (buf->body, &body); + report->report_type = body.input_report_type; + report->content_length = body.content_len; + report->content_id = body.content_id; + report->content = buf->content; +} +static void spi_hid_populate_output_header (u8 *buf,const struct spi_hid_conf *conf,const struct spi_hid_output_report *report)
@@ -157,6 +277,33 @@ static void spi_hid_populate_output_header(u8 *buf, buf[7 ] = report->content_id; } +static int spi_hid_input_sync (struct spi_hid *shid,void *buf,u16 length, +bool is_header) +{ +int error; + + shid->input_transfer[0 ].tx_buf = is_header ? + shid->read_approval_header : + shid->read_approval_body; + shid->input_transfer[0 ].len =SPI_HID_READ_APPROVAL_LEN ; + + shid->input_transfer[1 ].rx_buf = buf; + shid->input_transfer[1 ].len = length; + +spi_message_init_with_transfers (&shid->input_message, + shid->input_transfer,2 ); + + error =spi_sync (shid->spi, &shid->input_message); +if (error) { +dev_err (&shid->spi->dev,"Error starting sync transfer: %d." , error); + shid->bus_error_count++; + shid->bus_last_error = error; +return error; + } + +return 0 ; +} +static int spi_hid_output (struct spi_hid *shid,const void *buf,u16 length) {int error;
@@ -196,6 +343,50 @@ static void spi_hid_stop_hid(struct spi_hid *shid)hid_destroy_device (hid); } +static void spi_hid_error (struct spi_hid *shid) +{ +struct device *dev = &shid->spi->dev; +int error; + +guard (mutex)(&shid->power_lock); +if (shid->power_state ==HIDSPI_OFF ) +return ; + +if (shid->reset_attempts++ >=SPI_HID_MAX_RESET_ATTEMPTS ) { +dev_err (dev,"unresponsive device, aborting." ); +spi_hid_stop_hid (shid); + shid->ops->assert_reset (shid->ops); + error = shid->ops->power_down (shid->ops); +if (error) { +dev_err (dev,"failed to disable regulator." ); + shid->regulator_error_count++; + shid->regulator_last_error = error; + } +return ; + } + +clear_bit (SPI_HID_READY , &shid->flags); +set_bit (SPI_HID_RESET_PENDING , &shid->flags); + + shid->ops->assert_reset (shid->ops); + + shid->power_state =HIDSPI_OFF ; + +/* +* We want to cancel pending reset work as the device is being reset +* to recover from an error. cancel_work_sync will put us in a deadlock +* because this function is scheduled in 'reset_work' and we should +* avoid waiting for itself. +*/ +cancel_work (&shid->reset_work); + + shid->ops->sleep_minimal_reset_delay (shid->ops); + + shid->power_state =HIDSPI_ON ; + + shid->ops->deassert_reset (shid->ops); +} +static int spi_hid_send_output_report (struct spi_hid *shid,struct spi_hid_output_report *report) {
@@ -206,13 +397,13 @@ static int spi_hid_send_output_report(struct spi_hid *shid,u8 padding;int error; -guard (mutex)(&shid->output_lock);if (report->content_length > shid->desc.max_output_length) {dev_err (dev,"Output report too big, content_length 0x%x." , report->content_length);return -E2BIG ; } +guard (mutex)(&shid->io_lock);spi_hid_populate_output_header (buf->header, shid->conf, report);if (report->content_length)
@@ -236,6 +427,7 @@ static int spi_hid_sync_request(struct spi_hid *shid,struct device *dev = &shid->spi->dev;int error; +guard (mutex)(&shid->output_lock); error =spi_hid_send_output_report (shid, report);if (error)return error;
@@ -250,6 +442,86 @@ static int spi_hid_sync_request(struct spi_hid *shid,return 0 ; } +/* +* Handle the reset response from the FW by sending a request for the device +* descriptor. +*/ +static void spi_hid_reset_response (struct spi_hid *shid) +{ +struct device *dev = &shid->spi->dev; +struct spi_hid_output_report report = { + .report_type =DEVICE_DESCRIPTOR , + .content_length =0x0 , + .content_id =SPI_HID_OUTPUT_REPORT_CONTENT_ID_DESC_REQUEST , + .content =NULL , + }; +int error; + +if (test_bit (SPI_HID_READY , &shid->flags)) { +dev_err (dev,"Spontaneous FW reset!" ); +clear_bit (SPI_HID_READY , &shid->flags); + shid->dir_count++; + } + +if (shid->power_state ==HIDSPI_OFF ) +return ; + + error =spi_hid_sync_request (shid, &report); +if (error) { +dev_WARN_ONCE (dev, true, +"Failed to send device descriptor request: %d." , error); +set_bit (SPI_HID_ERROR , &shid->flags); +schedule_work (&shid->reset_work); + } +} + +static int spi_hid_input_report_handler (struct spi_hid *shid, +struct spi_hid_input_buf *buf) +{ +struct device *dev = &shid->spi->dev; +struct spi_hid_input_report r; +int error =0 ; + +if (!test_bit (SPI_HID_READY , &shid->flags) || +test_bit (SPI_HID_REFRESH_IN_PROGRESS , &shid->flags) || !shid->hid) { +dev_err (dev,"HID not ready" ); +return 0 ; + } + +spi_hid_input_report_prepare (buf, &r); + + error =hid_input_report (shid->hid,HID_INPUT_REPORT , + r.content -1 , r.content_length +1 ,1 ); + +if (error == -ENODEV || error == -EBUSY ) { +dev_err (dev,"ignoring report --> %d." , error); +return 0 ; + }else if (error) { +dev_err (dev,"Bad input report: %d." , error); + } + +return error; +} + +static void spi_hid_response_handler (struct spi_hid *shid, +struct input_report_body_header *body) +{ + shid->response_length = body->content_len; +/* completion_done returns 0 if there are waiters, otherwise 1 */ +if (completion_done (&shid->output_done)) { +dev_err (&shid->spi->dev,"Unexpected response report." ); + }else { +if (body->input_report_type ==REPORT_DESCRIPTOR_RESPONSE || + body->input_report_type ==GET_FEATURE_RESPONSE ) { +memcpy (shid->response->body, shid->input->body, +sizeof (shid->input->body)); +memcpy (shid->response->content, shid->input->content, + body->content_len); + } +complete (&shid->output_done); + } +} +/* * This function returns the length of the report descriptor, or a negative * error code if something went wrong.
@@ -269,6 +541,8 @@ static int spi_hid_report_descriptor_request(struct spi_hid *shid)if (ret) {dev_err (dev,"Expected report descriptor not received: %d." , ret); +set_bit (SPI_HID_ERROR , &shid->flags); +schedule_work (&shid->reset_work);return ret; }
@@ -323,6 +597,205 @@ static int spi_hid_create_device(struct spi_hid *shid)return 0 ; } +static void spi_hid_refresh_device (struct spi_hid *shid) +{ +struct device *dev = &shid->spi->dev; +u32 new_crc32 =0 ; +int error =0 ; + + error =spi_hid_report_descriptor_request (shid); +if (error <0 ) { +dev_err (dev, +"%s: failed report descriptor request: %d" , + __func__, error); +return ; + } + new_crc32 =crc32_le (0 , (unsigned char const *)shid->response->content, + (size_t )error); + +/* Same report descriptor, so no need to create a new hid device. */ +if (new_crc32 == shid->report_descriptor_crc32) { +set_bit (SPI_HID_READY , &shid->flags); +return ; + } + + shid->report_descriptor_crc32 = new_crc32; + +set_bit (SPI_HID_REFRESH_IN_PROGRESS , &shid->flags); + +spi_hid_stop_hid (shid); + + error =spi_hid_create_device (shid); +if (error) { +dev_err (dev,"%s: Failed to create hid device: %d." , __func__, error); +return ; + } + +clear_bit (SPI_HID_REFRESH_IN_PROGRESS , &shid->flags); +} + +static void spi_hid_reset_work (struct work_struct *work) +{ +struct spi_hid *shid = + container_of(work, struct spi_hid, reset_work); +struct device *dev = &shid->spi->dev; +int error =0 ; + +if (test_and_clear_bit (SPI_HID_RESET_RESPONSE , &shid->flags)) { +spi_hid_reset_response (shid); +return ; + } + +if (test_and_clear_bit (SPI_HID_CREATE_DEVICE , &shid->flags)) { +guard (mutex)(&shid->power_lock); +if (shid->power_state ==HIDSPI_OFF ) { +dev_err (dev,"%s: Powered off, returning" , __func__); +return ; + } + +if (!shid->hid) { + error =spi_hid_create_device (shid); +if (error) { +dev_err (dev,"%s: Failed to create hid device: %d." , + __func__, error); +return ; + } + }else { +spi_hid_refresh_device (shid); + } + +return ; + } + +if (test_and_clear_bit (SPI_HID_ERROR , &shid->flags)) { +spi_hid_error (shid); +return ; + } +} + +static int spi_hid_process_input_report (struct spi_hid *shid, +struct spi_hid_input_buf *buf) +{ +struct spi_hid_input_header header; +struct input_report_body_header body; +struct device *dev = &shid->spi->dev; +struct hidspi_dev_descriptor *raw; + +spi_hid_populate_input_header (buf->header, &header); +spi_hid_populate_input_body (buf->body, &body); + +if (body.content_len > header.report_length) { +dev_err (dev,"Bad body length %d > %d." , body.content_len, + header.report_length); +return -EPROTO ; + } + +switch (body.input_report_type) { +case DATA : +return spi_hid_input_report_handler (shid, buf); +case RESET_RESPONSE : +clear_bit (SPI_HID_RESET_PENDING , &shid->flags); +set_bit (SPI_HID_RESET_RESPONSE , &shid->flags); +schedule_work (&shid->reset_work); +break ; +case DEVICE_DESCRIPTOR_RESPONSE : +/* Mark the completion done to avoid timeout */ +spi_hid_response_handler (shid, &body); + +/* Reset attempts at every device descriptor fetch */ + shid->reset_attempts =0 ; + raw = (struct hidspi_dev_descriptor *)buf->content; + +/* Validate device descriptor length before parsing */ +if (body.content_len !=HIDSPI_DEVICE_DESCRIPTOR_SIZE ) { +dev_err (dev,"Invalid content length %d, expected %lu." , + body.content_len, +HIDSPI_DEVICE_DESCRIPTOR_SIZE ); +return -EPROTO ; + } + +if (le16_to_cpu (raw->dev_desc_len) != +HIDSPI_DEVICE_DESCRIPTOR_SIZE ) { +dev_err (dev, +"Invalid wDeviceDescLength %d, expected %lu." , + raw->dev_desc_len, +HIDSPI_DEVICE_DESCRIPTOR_SIZE ); +return -EPROTO ; + } + +spi_hid_parse_dev_desc (raw, &shid->desc); + +if (shid->desc.hid_version !=SPI_HID_SUPPORTED_VERSION ) { +dev_err (dev, +"Unsupported device descriptor version %4x." , + shid->desc.hid_version); +return -EPROTONOSUPPORT ; + } + +set_bit (SPI_HID_CREATE_DEVICE , &shid->flags); +schedule_work (&shid->reset_work); + +break ; +case OUTPUT_REPORT_RESPONSE : +if (shid->desc.no_output_report_ack) { +dev_err (dev,"Unexpected output report response." ); +break ; + } + fallthrough; +case GET_FEATURE_RESPONSE : +case SET_FEATURE_RESPONSE : +case REPORT_DESCRIPTOR_RESPONSE : +spi_hid_response_handler (shid, &body); +break ; +/* +* FIXME: sending GET_INPUT and COMMAND reports not supported, thus +* throw away responses to those, they should never come. +*/ +case GET_INPUT_REPORT_RESPONSE : +case COMMAND_RESPONSE : +dev_err (dev,"Not a supported report type: 0x%x." , + body.input_report_type); +break ; +default : +dev_err (dev,"Unknown input report: 0x%x." , body.input_report_type); +return -EPROTO ; + } + +return 0 ; +} + +static int spi_hid_bus_validate_header (struct spi_hid *shid, +struct spi_hid_input_header *header) +{ +struct device *dev = &shid->spi->dev; + +if (header->version !=SPI_HID_INPUT_HEADER_VERSION ) { +dev_err (dev,"Unknown input report version (v 0x%x)." , + header->version); +return -EINVAL ; + } + +if (shid->desc.max_input_length !=0 && + header->report_length > shid->desc.max_input_length) { +dev_err (dev,"Input report body size %u > max expected of %u." , + header->report_length, shid->desc.max_input_length); +return -EMSGSIZE ; + } + +if (header->last_fragment_flag !=1 ) { +dev_err (dev,"Multi-fragment reports not supported." ); +return -EOPNOTSUPP ; + } + +if (header->sync_const !=SPI_HID_INPUT_HEADER_SYNC_BYTE ) { +dev_err (dev,"Invalid input report sync constant (0x%x)." , + header->sync_const); +return -EINVAL ; + } + +return 0 ; +} +static int spi_hid_get_request (struct spi_hid *shid,u8 content_id) {struct device *dev = &shid->spi->dev;
@@ -339,6 +812,8 @@ static int spi_hid_get_request(struct spi_hid *shid, u8 content_id)dev_err (dev,"Expected get request response not received! Error %d." , error); +set_bit (SPI_HID_ERROR , &shid->flags); +schedule_work (&shid->reset_work);return error; }
@@ -358,9 +833,83 @@ static int spi_hid_set_request(struct spi_hid *shid, u8 *arg_buf, u16 arg_len,return spi_hid_sync_request (shid, &report); } -/* This is a placeholder. Will be implemented in the next patch. */ static irqreturn_t spi_hid_dev_irq (int irq,void *_shid) { +struct spi_hid *shid = _shid; +struct device *dev = &shid->spi->dev; +struct spi_hid_input_header header; +int error =0 ; + + scoped_guard(mutex, &shid->io_lock) { + error =spi_hid_input_sync (shid, shid->input->header, +sizeof (shid->input->header), true); +if (error) { +dev_err (dev,"Failed to transfer header: %d." , error); + goto err; + } + +if (shid->power_state ==HIDSPI_OFF ) { +dev_warn (dev,"Device is off after header was received." ); + goto out; + } + +if (shid->input_message.status <0 ) { +dev_warn (dev,"Error reading header: %d." , + shid->input_message.status); + shid->bus_error_count++; + shid->bus_last_error = shid->input_message.status; + goto err; + } + +spi_hid_populate_input_header (shid->input->header, &header); + + error =spi_hid_bus_validate_header (shid, &header); +if (error) { +if (!test_bit (SPI_HID_RESET_PENDING , &shid->flags)) { +dev_err (dev,"Failed to validate header: %d." , error); +print_hex_dump (KERN_ERR ,"spi_hid: header buffer: " , +DUMP_PREFIX_NONE ,16 ,1 , shid->input->header, +sizeof (shid->input->header), false); + shid->bus_error_count++; + shid->bus_last_error = error; + goto err; + } + goto out; + } + + error =spi_hid_input_sync (shid, shid->input->body, header.report_length, + false); +if (error) { +dev_err (dev,"Failed to transfer body: %d." , error); + goto err; + } + +if (shid->power_state ==HIDSPI_OFF ) { +dev_warn (dev,"Device is off after body was received." ); + goto out; + } + +if (shid->input_message.status <0 ) { +dev_warn (dev,"Error reading body: %d." , + shid->input_message.status); + shid->bus_error_count++; + shid->bus_last_error = shid->input_message.status; + goto err; + } + } + + error =spi_hid_process_input_report (shid, shid->input); +if (error) { +dev_err (dev,"Failed to process input report: %d." , error); + goto err; + } + +out: +return IRQ_HANDLED ; + +err: +set_bit (SPI_HID_ERROR , &shid->flags); +schedule_work (&shid->reset_work);return IRQ_HANDLED ; }
@@ -571,10 +1120,13 @@ static int spi_hid_ll_output_report(struct hid_device *hid, __u8 *buf,return -ENODEV ; } -if (shid->desc.no_output_report_ack) - error =spi_hid_send_output_report (shid, &report); -else +if (shid->desc.no_output_report_ack) { + scoped_guard(mutex, &shid->output_lock) { + error =spi_hid_send_output_report (shid, &report); + } + }else { error =spi_hid_sync_request (shid, &report); + }if (error) {dev_err (dev,"failed to send output report." );
@@ -662,11 +1214,23 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops, shid->power_state =HIDSPI_ON ; shid->ops = ops; shid->conf = conf; +set_bit (SPI_HID_RESET_PENDING , &shid->flags);spi_set_drvdata (spi, shid); +/* Using now populated conf let's pre-calculate the read approvals */ +spi_hid_populate_read_approvals (shid->conf, shid->read_approval_header, + shid->read_approval_body); + +mutex_init (&shid->output_lock); +mutex_init (&shid->power_lock); +mutex_init (&shid->io_lock); +init_completion (&shid->output_done); + +INIT_WORK (&shid->reset_work, spi_hid_reset_work); +/* -* we need to allocate the buffer without knowing the maximum +* We need to allocate the buffer without knowing the maximum * size of the reports. Let's use SZ_2K, then we do the * real computation later. */
@@ -706,8 +1270,6 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,dev_dbg (dev,"%s: d3 -> %s." , __func__,spi_hid_power_mode_string (shid->power_state)); -spi_hid_create_device (shid); -return 0 ; }EXPORT_SYMBOL_GPL (spi_hid_core_probe);
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 6/11 HID: spi_hid: add spi_hid traces
In reply to Jingyuan LiangAdd traces for purposed of debugging spi_hid driver.
--- drivers/hid/spi-hid/Makefile | 1 + drivers/hid/spi-hid/spi-hid-core.c | 118 +++++++++---------------- drivers/hid/spi-hid/spi-hid-core.h | 91 +++++++++++++++++++ drivers/hid/spi-hid/spi-hid-trace.h | 169 ++++++++++++++++++++++++++++++++++++ 4 files changed, 303 insertions(+), 76 deletions(-)
drivers/hid/spi-hid/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_SPI_HID_CORE) += spi-hid.o spi-hid-objs = spi-hid-core.o +CFLAGS_spi-hid-core.o := -I$(src)
drivers/hid/spi-hid/spi-hid-core.c +42 -76
224 lines not on this page · raw message
drivers/hid/spi-hid/spi-hid-core.h new file +91 -0
91 lines not on this page · raw message
drivers/hid/spi-hid/spi-hid-trace.h new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 7/11 HID: spi_hid: add ACPI support for SPI over HID
In reply to Jingyuan LiangFrom: Angela Czubak <[email protected]>
Detect SPI HID devices described in ACPI.
--- drivers/hid/spi-hid/Kconfig | 15 +++ drivers/hid/spi-hid/Makefile | 1 + drivers/hid/spi-hid/spi-hid-acpi.c | 253 +++++++++++++++++++++++++++++++++++++ drivers/hid/spi-hid/spi-hid-core.c | 26 +--- drivers/hid/spi-hid/spi-hid.h | 45 +++++++ 5 files changed, 315 insertions(+), 25 deletions(-)
drivers/hid/spi-hid/Kconfig +15 -0
@@ -10,6 +10,21 @@ menuconfig SPI_HID if SPI_HID +config SPI_HID_ACPI + tristate "HID over SPI transport layer ACPI driver" + depends on ACPI + select SPI_HID_CORE + help + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any + other HID based devices which are connected to your computer via SPI. + This driver supports ACPI-based systems. + + If unsure, say N. + + This support is also available as a module. If so, the module + will be called spi-hid-acpi. It will also build/depend on the + module spi-hid. + config SPI_HID_CORE tristate endif
drivers/hid/spi-hid/Makefile +1 -0
@@ -8,3 +8,4 @@ obj-$(CONFIG_SPI_HID_CORE) += spi-hid.o spi-hid-objs = spi-hid-core.o CFLAGS_spi-hid-core.o := -I$(src) +obj-$(CONFIG_SPI_HID_ACPI) += spi-hid-acpi.o
drivers/hid/spi-hid/spi-hid-acpi.c new file +253 -0
253 lines not on this page · raw message
drivers/hid/spi-hid/spi-hid-core.c +1 -25
@@ -43,6 +43,7 @@#include <linux/wait.h> #include <linux/workqueue.h> +#include "spi-hid.h" #include "spi-hid-core.h" #define CREATE_TRACE_POINTS
@@ -110,31 +111,6 @@ struct spi_hid_output_report {u8 *content; }; -/* struct spi_hid_conf - Conf provided to the core */ -struct spi_hid_conf { -u32 input_report_header_address; -u32 input_report_body_address; -u32 output_report_address; -u8 read_opcode; -u8 write_opcode; -}; - -/** -* struct spihid_ops - Ops provided to the core -* @power_up: do sequencing to power up the device -* @power_down: do sequencing to power down the device -* @assert_reset: do sequencing to assert the reset line -* @deassert_reset: do sequencing to deassert the reset line -* @sleep_minimal_reset_delay: minimal sleep delay during reset -*/ -struct spihid_ops { -int (*power_up)(struct spihid_ops *ops); -int (*power_down)(struct spihid_ops *ops); -int (*assert_reset)(struct spihid_ops *ops); -int (*deassert_reset)(struct spihid_ops *ops); -void (*sleep_minimal_reset_delay)(struct spihid_ops *ops); -}; -static struct hid_ll_driver spi_hid_ll_driver; static void spi_hid_populate_read_approvals(const struct spi_hid_conf *conf,
drivers/hid/spi-hid/spi-hid.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 8/11 HID: spi_hid: add device tree support for SPI over HID
In reply to Jingyuan LiangFrom: Jarrett Schultz <[email protected]>
--- drivers/hid/spi-hid/Kconfig | 15 +++ drivers/hid/spi-hid/Makefile | 1 + drivers/hid/spi-hid/spi-hid-of.c | 243 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+)
drivers/hid/spi-hid/Kconfig +15 -0
@@ -25,6 +25,21 @@ config SPI_HID_ACPI will be called spi-hid-acpi. It will also build/depend on the module spi-hid. +config SPI_HID_OF + tristate "HID over SPI transport layer Open Firmware driver" + depends on OF + select SPI_HID_CORE + help + Say Y here if you use a keyboard, a touchpad, a touchscreen, or any + other HID based devices which are connected to your computer via SPI. + This driver supports Open Firmware (Device Tree)-based systems. + + If unsure, say N. + + This support is also available as a module. If so, the module + will be called spi-hid-of. It will also build/depend on the + module spi-hid. + config SPI_HID_CORE tristate endif
drivers/hid/spi-hid/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_SPI_HID_CORE) += spi-hid.o spi-hid-objs = spi-hid-core.o CFLAGS_spi-hid-core.o := -I$(src) obj-$(CONFIG_SPI_HID_ACPI) += spi-hid-acpi.o +obj-$(CONFIG_SPI_HID_OF) += spi-hid-of.o
drivers/hid/spi-hid/spi-hid-of.c new file +243 -0
243 lines not on this page · raw message
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 9/11 dt-bindings: input: Document hid-over-spi DT schema
In reply to Jingyuan LiangDocumentation 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.
The properties are common to HID over SPI.
--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +126 -0
@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]> + +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol. + +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + 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 + minimum: 0 + maximum: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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. + + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte. + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte. + +required: + - compatible + - interrupts + - reset-gpios + - vdd-supply + - input-report-header-address + - input-report-body-address + - output-report-address + - read-opcode + - write-opcode + +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", "hid-over-spi"; + 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_int_bias>; + input-report-header-address = <0x1000>; + input-report-body-address = <0x1004>; + output-report-address = <0x2000>; + read-opcode = /bits/ 8 <0x0b>; + write-opcode = /bits/ 8 <0x02>; + }; + };
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
Re: [PATCH v3 09/11] dt-bindings: input: Document hid-over-spi DT schema
Quoted 20 lines · Jingyuan Liang
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.
The properties are common to HID over SPI.
Signed-off-by Dmitry Antipov <[email protected]>Signed-off-by Jarrett Schultz <[email protected]>Signed-off-by Jingyuan Liang <[email protected]>--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +1
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]>
Why them and not you, the developers of the series?
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 23
Quoted 12 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +12
-0+ +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol.
This is not relevant to the binding, please remove it.
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 36
Quoted 13 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +13
-0+ +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + const: hid-over-spi
Why is it allowed but not recommended? Seems to me like we should require device-specific compatibles.
Quoted 42 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +42
-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 + 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: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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.
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 88
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+ + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte. + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte.
Why can none of these things be determined from the device's compatible? On the surface, they like the kinds of things that could/should be.
Cheers,
Conor.
Quoted 42 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +38
-0+ +required: + - compatible + - interrupts + - reset-gpios + - vdd-supply + - input-report-header-address + - input-report-body-address + - output-report-address + - read-opcode + - write-opcode + +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", "hid-over-spi"; + 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_int_bias>; + input-report-header-address = <0x1000>; + input-report-body-address = <0x1004>; + output-report-address = <0x2000>; + read-opcode = /bits/ 8 <0x0b>; + write-opcode = /bits/ 8 <0x02>; + }; + };Signature · 2 lines
-- 2.53.0.1185.g05d4b7b318-goog
Dmitry Torokhov
maintainerRe: [PATCH v3 09/11] dt-bindings: input: Document hid-over-spi DT schema
Quoted 49 lines · Conor Dooley
Quoted 20 lines · Jingyuan Liang
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.
The properties are common to HID over SPI.
Signed-off-by Dmitry Antipov <[email protected]>Signed-off-by Jarrett Schultz <[email protected]>Signed-off-by Jingyuan Liang <[email protected]>--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +1
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)Documentation/devicetree/bindings/input/hid-over-spi.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]>Why them and not you, the developers of the series?
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 23
Quoted 12 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +12
-0+ +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol.This is not relevant to the binding, please remove it.
Quoted 16 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 36
Quoted 13 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +13
-0+ +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + const: hid-over-spiWhy is it allowed but not recommended? Seems to me like we should require device-specific compatibles.
Why would we want to change the driver code to add a new compatible each time a vendor decides to create a chip that is fully hid-spi-protocol compliant? Or is the plan to still allow "hid-over-spi" fallback but require device-specific compatible that will be ignored unless there is device-specific quirk needed?
Quoted 48 lines
Quoted 48 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +47
-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 + 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: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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. + + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte.
Quoted 8 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 88
Quoted 5 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +5
-0+ + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte.Why can none of these things be determined from the device's compatible? On the surface, they like the kinds of things that could/should be.
Why would we want to keep tables of these values in the kernel and again have to update the driver for each new chip? It also probably firmware-dependent.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v3 09/11] dt-bindings: input: Document hid-over-spi DT schema
Quoted 67 lines · Dmitry Torokhov
Quoted 49 lines · Conor Dooley
Quoted 20 lines · Jingyuan Liang
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.
The properties are common to HID over SPI.
Signed-off-by Dmitry Antipov <[email protected]>Signed-off-by Jarrett Schultz <[email protected]>Signed-off-by Jingyuan Liang <[email protected]>--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +1
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)Documentation/devicetree/bindings/input/hid-over-spi.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]>Why them and not you, the developers of the series?
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 23
Quoted 12 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +12
-0+ +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol.This is not relevant to the binding, please remove it.
Quoted 16 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 36
Quoted 13 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +13
-0+ +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + const: hid-over-spiWhy is it allowed but not recommended? Seems to me like we should require device-specific compatibles.
Quoted 5 lines
Why would we want to change the driver code to add a new compatible each time a vendor decides to create a chip that is fully hid-spi-protocol compliant? Or is the plan to still allow "hid-over-spi" fallback but require device-specific compatible that will be ignored unless there is device-specific quirk needed?
This has nothing to do with the driver, just the oddity of having a comment saying that not having a device specific compatible was permitted by not recommended in a binding. Requiring device-specific compatibles is the norm after all and a comment like this makes draws more attention to the fact that this is abnormal. Regardless of what the driver does, device-specific compatibles should be required.
Quoted 56 lines
Quoted 47 lines
Quoted 47 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +47
-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 + 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: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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. + + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte.Quoted 8 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 88
Quoted 5 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +5
-0+ + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte.Why can none of these things be determined from the device's compatible? On the surface, they like the kinds of things that could/should be.
Quoted 2 lines
Why would we want to keep tables of these values in the kernel and again have to update the driver for each new chip?
That's pretty normal though innit? It's what match data does. If someone wants to have properties that communicate data that can be determined from the compatible, they need to provide justification why it is being done.
Quoted 1 line
It also probably firmware-dependent.
Rob Herring
maintainerRe: [PATCH v3 09/11] dt-bindings: input: Document hid-over-spi DT schema
Quoted 68 lines · Conor Dooley
Quoted 67 lines · Dmitry Torokhov
Quoted 65 lines · Conor Dooley
Quoted 20 lines · Jingyuan Liang
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.
The properties are common to HID over SPI.
Signed-off-by Dmitry Antipov <[email protected]>Signed-off-by Jarrett Schultz <[email protected]>Signed-off-by Jingyuan Liang <[email protected]>--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +1
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)Documentation/devicetree/bindings/input/hid-over-spi.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]>Why them and not you, the developers of the series?
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 23
Quoted 12 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +12
-0+ +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol.This is not relevant to the binding, please remove it.
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 36
Quoted 13 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +13
-0+ +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + const: hid-over-spiWhy is it allowed but not recommended? Seems to me like we should require device-specific compatibles.
Quoted 5 lines
Quoted 5 lines
Why would we want to change the driver code to add a new compatible each time a vendor decides to create a chip that is fully hid-spi-protocol compliant? Or is the plan to still allow "hid-over-spi" fallback but require device-specific compatible that will be ignored unless there is device-specific quirk needed?
The plan is the latter case (the 1st entry up above). The comment is remove the 2nd entry (with 'Just "hid-over-spi" alone is allowed, but not recommended.').
Quoted 63 lines
This has nothing to do with the driver, just the oddity of having a comment saying that not having a device specific compatible was permitted by not recommended in a binding. Requiring device-specific compatibles is the norm after all and a comment like this makes draws more attention to the fact that this is abnormal. Regardless of what the driver does, device-specific compatibles should be required.
Quoted 56 lines
Quoted 55 lines
Quoted 42 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +42
-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 + 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: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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.Documentation/devicetree/bindings/input/hid-over-spi.yaml line 88
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+ + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte. + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte.Why can none of these things be determined from the device's compatible? On the surface, they like the kinds of things that could/should be.
Quoted 7 lines
Quoted 2 lines
Why would we want to keep tables of these values in the kernel and again have to update the driver for each new chip?
That's pretty normal though innit? It's what match data does. If someone wants to have properties that communicate data that can be determined from the compatible, they need to provide justification why it is being done.
IIRC, it was explained in prior versions the spec itself says these values vary by device. If we expect variation, then I think these properties are fine. But please capture the reasoning for them in this patch or we will just keep asking the same questions over and over.
Rob
Benjamin Tissoires
maintainerRe: [PATCH v3 09/11] dt-bindings: input: Document hid-over-spi DT schema
Quoted 150 lines · Rob Herring
Quoted 68 lines · Conor Dooley
Quoted 67 lines · Dmitry Torokhov
Quoted 65 lines · Conor Dooley
Quoted 20 lines · Jingyuan Liang
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.
The properties are common to HID over SPI.
Signed-off-by Dmitry Antipov <[email protected]>Signed-off-by Jarrett Schultz <[email protected]>Signed-off-by Jingyuan Liang <[email protected]>--- .../devicetree/bindings/input/hid-over-spi.yaml | 126 +++++++++++++++++++++ 1 file changed, 126 insertions(+)Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +1
-0@@ -0,0 +1,126 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)Documentation/devicetree/bindings/input/hid-over-spi.yaml line 11
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/hid-over-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HID over SPI Devices + +maintainers: + - Benjamin Tissoires <[email protected]> + - Jiri Kosina <[email protected]>Why them and not you, the developers of the series?
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 23
Quoted 12 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +12
-0+ +description: |+ + HID over SPI provides support for various Human Interface Devices over the + SPI bus. These devices can be for example touchpads, keyboards, touch screens + or sensors. + + The specification has been written by Microsoft and is currently available + here: https://www.microsoft.com/en-us/download/details.aspx?id=103325 + + If this binding is used, the kernel module spi-hid will handle the + communication with the device and the generic hid core layer will handle the + protocol.This is not relevant to the binding, please remove it.
Documentation/devicetree/bindings/input/hid-over-spi.yaml line 36
Quoted 13 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +13
-0+ +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + +properties: + compatible: + oneOf: + - items: + - enum: + - microsoft,g6-touch-digitizer + - const: hid-over-spi + - description: Just "hid-over-spi" alone is allowed, but not recommended. + const: hid-over-spiWhy is it allowed but not recommended? Seems to me like we should require device-specific compatibles.
Quoted 5 lines
Quoted 5 lines
Why would we want to change the driver code to add a new compatible each time a vendor decides to create a chip that is fully hid-spi-protocol compliant? Or is the plan to still allow "hid-over-spi" fallback but require device-specific compatible that will be ignored unless there is device-specific quirk needed?
The plan is the latter case (the 1st entry up above). The comment is remove the 2nd entry (with 'Just "hid-over-spi" alone is allowed, but not recommended.').
Quoted 63 lines
This has nothing to do with the driver, just the oddity of having a comment saying that not having a device specific compatible was permitted by not recommended in a binding. Requiring device-specific compatibles is the norm after all and a comment like this makes draws more attention to the fact that this is abnormal. Regardless of what the driver does, device-specific compatibles should be required.
Quoted 56 lines
Quoted 55 lines
Quoted 42 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +42
-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 + 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: 0xffffff + 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: 0xffffff + 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: 0xffffff + 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.Documentation/devicetree/bindings/input/hid-over-spi.yaml line 88
Quoted 10 lines
Documentation/devicetree/bindings/input/hid-over-spi.yaml new file +10
-0+ + read-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Read Approval packets. 1 byte. + + write-opcode: + $ref: /schemas/types.yaml#/definitions/uint8 + description: + Value to be used in Write Approval packets. 1 byte.Why can none of these things be determined from the device's compatible? On the surface, they like the kinds of things that could/should be.
Quoted 7 lines
Quoted 2 lines
Why would we want to keep tables of these values in the kernel and again have to update the driver for each new chip?
That's pretty normal though innit? It's what match data does. If someone wants to have properties that communicate data that can be determined from the compatible, they need to provide justification why it is being done.
Quoted 5 lines
IIRC, it was explained in prior versions the spec itself says these values vary by device. If we expect variation, then I think these properties are fine. But please capture the reasoning for them in this patch or we will just keep asking the same questions over and over.
Dmitry, FWIW, we roughly had the exact same of argument with Rob with i2c-hid :)
It took me a while, but I finally understood the rationale and agreed to it (using the i2c-hid examples):
Most i2c-hid devices are following the spec and rely purely on ACPI and the DT declaration of i2c-hid -> they are working fine and we don't need anything else for them. They declare their compatible and the i2c-hid compatible, and they work great.
But some devices need a reset line. But the i2c-hid spec doesn't mention a reset line at all. And some other devices need a reset line with a different timing. etc... Relying purely on the i2c-hid driver means that the driver needs to now the platform the device is on and the exact device we have in front of us. i2c-hid provide a VID/PID through the protocol, but we are still lacking information: in some cases, the timing of the reset line for the same device differs depending on the platform they run.
Having a device specific compatible means that we can make use of it before we load i2c-hid. This is why we have i2c-hid-core and module specifics on the side. Those extra module can do all the oddities they want, like having 2 or 3 reset lines, but in the end they are using the core i2c-hid once they are set up.
Think of it as a way to quirk the device upfront without polluting the i2c-hid processing.
That allowed us to clean up the i2c-hid code by removing the non standard regulators, reset lines, quirks that are device specific and keep it closer to the spec.
Cheers,
Benjamin
PATCH v3 10/11 HID: spi-hid: add power management implementation
In reply to Jingyuan LiangImplement HID over SPI driver power management callbacks.
--- drivers/hid/spi-hid/spi-hid-acpi.c | 1 + drivers/hid/spi-hid/spi-hid-core.c | 107 +++++++++++++++++++++++++++++++++++++ drivers/hid/spi-hid/spi-hid-of.c | 1 + drivers/hid/spi-hid/spi-hid.h | 1 + 4 files changed, 110 insertions(+)
drivers/hid/spi-hid/spi-hid-acpi.c +1 -0
@@ -238,6 +238,7 @@ static struct spi_driver spi_hid_acpi_driver = { .driver = { .name = "spi_hid_acpi", .owner = THIS_MODULE, + .pm = &spi_hid_core_pm, .acpi_match_table = spi_hid_acpi_match, .probe_type = PROBE_PREFER_ASYNCHRONOUS, .dev_groups = spi_hid_groups,
drivers/hid/spi-hid/spi-hid-core.c +107 -0
131 lines not on this page · raw message
drivers/hid/spi-hid/spi-hid-of.c +1 -0
@@ -227,6 +227,7 @@ static struct spi_driver spi_hid_of_driver = { .driver = { .name = "spi_hid_of", .owner = THIS_MODULE, + .pm = &spi_hid_core_pm, .of_match_table = spi_hid_of_match, .probe_type = PROBE_PREFER_ASYNCHRONOUS, .dev_groups = spi_hid_groups,
drivers/hid/spi-hid/spi-hid.h +1 -0
@@ -41,5 +41,6 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,void spi_hid_core_remove (struct spi_device *spi);extern const struct attribute_group *spi_hid_groups[]; +extern const struct dev_pm_ops spi_hid_core_pm;#endif /* SPI_HID_H */
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog
PATCH v3 11/11 HID: spi-hid: add panel follower support
In reply to Jingyuan LiangAdd support to spi-hid to be a panel follower.
--- drivers/hid/spi-hid/spi-hid-core.c | 199 +++++++++++++++++++++++++++++-------- drivers/hid/spi-hid/spi-hid-core.h | 7 ++ 2 files changed, 163 insertions(+), 43 deletions(-)
drivers/hid/spi-hid/spi-hid-core.c +156 -43
@@ -246,21 +246,21 @@ static const char *spi_hid_power_mode_string(enum hidspi_power_state power_state } } -static void spi_hid_suspend (struct spi_hid *shid) +static int spi_hid_suspend (struct spi_hid *shid) {int error;struct device *dev = &shid->spi->dev;guard (mutex)(&shid->power_lock);if (shid->power_state ==HIDSPI_OFF ) -return ; +return 0 ;if (shid->hid) { error =hid_driver_suspend (shid->hid,PMSG_SUSPEND );if (error) {dev_err (dev,"%s failed to suspend hid driver: %d" , __func__, error); -return ; +return error; } }
@@ -278,21 +278,22 @@ static void spi_hid_suspend(struct spi_hid *shid)dev_err (dev,"%s: could not power down." , __func__); shid->regulator_error_count++; shid->regulator_last_error = error; -return ; +return error; } shid->power_state =HIDSPI_OFF ; } +return 0 ; } -static void spi_hid_resume (struct spi_hid *shid) +static int spi_hid_resume (struct spi_hid *shid) {int error;struct device *dev = &shid->spi->dev;guard (mutex)(&shid->power_lock);if (shid->power_state ==HIDSPI_ON ) -return ; +return 0 ;enable_irq (shid->spi->irq);
@@ -306,7 +307,7 @@ static void spi_hid_resume(struct spi_hid *shid)dev_err (dev,"%s: could not power up." , __func__); shid->regulator_error_count++; shid->regulator_last_error = error; -return ; +return error; } shid->power_state =HIDSPI_ON ;
@@ -315,10 +316,13 @@ static void spi_hid_resume(struct spi_hid *shid)if (shid->hid) { error =hid_driver_reset_resume (shid->hid); -if (error) +if (error) {dev_err (dev,"%s: failed to reset resume hid driver: %d." , __func__, error); +return error; + } } +return 0 ; }static void spi_hid_stop_hid (struct spi_hid *shid)
@@ -1215,6 +1219,132 @@ const struct attribute_group *spi_hid_groups[] = { };EXPORT_SYMBOL_GPL (spi_hid_groups); +/* +* At the end of probe we initialize the device: +* 0) assert reset, bias the interrupt line +* 1) sleep minimal reset delay +* 2) request IRQ +* 3) power up the device +* 4) deassert reset (high) +* After this we expect an IRQ with a reset response. +*/ +static int spi_hid_dev_init (struct spi_hid *shid) +{ +struct spi_device *spi = shid->spi; +struct device *dev = &spi->dev; +int error; + + shid->ops->assert_reset (shid->ops); + + shid->ops->sleep_minimal_reset_delay (shid->ops); + + error =devm_request_threaded_irq (dev, spi->irq,NULL , spi_hid_dev_irq, +IRQF_ONESHOT ,dev_name (&spi->dev), shid); +if (error) { +dev_err (dev,"%s: unable to request threaded IRQ." , __func__); +return error; + } +if (device_may_wakeup (dev)) { + error =dev_pm_set_wake_irq (dev, spi->irq); +if (error) { +dev_err (dev,"%s: failed to set wake IRQ." , __func__); +return error; + } + } + + error = shid->ops->power_up (shid->ops); +if (error) { +dev_err (dev,"%s: could not power up." , __func__); + shid->regulator_error_count++; + shid->regulator_last_error = error; +return error; + } + + shid->ops->deassert_reset (shid->ops); + +return 0 ; +} + +static void spi_hid_panel_follower_work (struct work_struct *work) +{ + struct spi_hid *shid = container_of(work, struct spi_hid, + panel_follower_work); +int error; + +if (!shid->desc.hid_version) + error =spi_hid_dev_init (shid); +else + error =spi_hid_resume (shid); +if (error) +dev_warn (&shid->spi->dev,"Power on failed: %d" , error); +else +WRITE_ONCE (shid->panel_follower_work_finished, true); + +/* +* The work APIs provide a number of memory ordering guarantees +* including one that says that memory writes before schedule_work() +* are always visible to the work function, but they don't appear to +* guarantee that a write that happened in the work is visible after +* cancel_work_sync(). We'll add a write memory barrier here to match +* with spi_hid_panel_unpreparing() to ensure that our write to +* panel_follower_work_finished is visible there. +*/ +smp_wmb (); +} + +static int spi_hid_panel_follower_resume (struct drm_panel_follower *follower) +{ + struct spi_hid *shid = container_of(follower, struct spi_hid, panel_follower); + +/* +* Powering on a touchscreen can be a slow process. Queue the work to +* the system workqueue so we don't block the panel's power up. +*/ +WRITE_ONCE (shid->panel_follower_work_finished, false); +schedule_work (&shid->panel_follower_work); + +return 0 ; +} + +static int spi_hid_panel_follower_suspend (struct drm_panel_follower *follower) +{ + struct spi_hid *shid = container_of(follower, struct spi_hid, panel_follower); + +cancel_work_sync (&shid->panel_follower_work); + +/* Match with shid_core_panel_follower_work() */ +smp_rmb (); +if (!READ_ONCE (shid->panel_follower_work_finished)) +return 0 ; + +return spi_hid_suspend (shid); +} + +static const struct drm_panel_follower_funcs + spi_hid_panel_follower_prepare_funcs = { + .panel_prepared = spi_hid_panel_follower_resume, + .panel_unpreparing = spi_hid_panel_follower_suspend, +}; + +static int spi_hid_register_panel_follower (struct spi_hid *shid) +{ +struct device *dev = &shid->spi->dev; + + shid->panel_follower.funcs = &spi_hid_panel_follower_prepare_funcs; + +/* +* If we're not in control of our own power up/power down then we can't +* do the logic to manage wakeups. Give a warning if a user thought +* that was possible then force the capability off. +*/ +if (device_can_wakeup (dev)) { +dev_warn (dev,"Can't wakeup if following panel\n" ); +device_set_wakeup_capable (dev, false); + } + +return drm_panel_add_follower (dev, &shid->panel_follower); +} +int spi_hid_core_probe (struct spi_device *spi,struct spihid_ops *ops,struct spi_hid_conf *conf) {
@@ -1234,6 +1364,7 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops, shid->ops = ops; shid->conf = conf;set_bit (SPI_HID_RESET_PENDING , &shid->flags); + shid->is_panel_follower =drm_is_panel_follower (&spi->dev);spi_set_drvdata (spi, shid);
@@ -1247,6 +1378,7 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,init_completion (&shid->output_done);INIT_WORK (&shid->reset_work, spi_hid_reset_work); +INIT_WORK (&shid->panel_follower_work, spi_hid_panel_follower_work);/* * We need to allocate the buffer without knowing the maximum
@@ -1257,42 +1389,18 @@ int spi_hid_core_probe(struct spi_device *spi, struct spihid_ops *ops,if (error)return error; -/* -* At the end of probe we initialize the device: -* 0) assert reset, bias the interrupt line -* 1) sleep minimal reset delay -* 2) request IRQ -* 3) power up the device -* 4) deassert reset (high) -* After this we expect an IRQ with a reset response. -*/ - - shid->ops->assert_reset (shid->ops); - - shid->ops->sleep_minimal_reset_delay (shid->ops); - - error =devm_request_threaded_irq (dev, spi->irq,NULL , spi_hid_dev_irq, -IRQF_ONESHOT ,dev_name (&spi->dev), shid); -if (error) { -dev_err (dev,"%s: unable to request threaded IRQ." , __func__); -return error; - } -if (device_may_wakeup (dev)) { - error =dev_pm_set_wake_irq (dev, spi->irq); +if (shid->is_panel_follower) { + error =spi_hid_register_panel_follower (shid);if (error) { -dev_err (dev,"%s: failed to set wake IRQ." , __func__); +dev_err (dev,"%s: could not add panel follower." , __func__);return error; } + }else { + error =spi_hid_dev_init (shid); +if (error) +return error; } - error = shid->ops->power_up (shid->ops); -if (error) { -dev_err (dev,"%s: could not power up." , __func__); -return error; - } - - shid->ops->deassert_reset (shid->ops); -dev_dbg (dev,"%s: d3 -> %s." , __func__,spi_hid_power_mode_string (shid->power_state));
@@ -1306,6 +1414,9 @@ void spi_hid_core_remove(struct spi_device *spi)struct device *dev = &spi->dev;int error; +if (shid->is_panel_follower) +drm_panel_remove_follower (&shid->panel_follower); +spi_hid_stop_hid (shid); shid->ops->assert_reset (shid->ops);
@@ -1319,18 +1430,20 @@ static int spi_hid_core_pm_suspend(struct device *dev) {struct spi_hid *shid =dev_get_drvdata (dev); -spi_hid_suspend (shid); +if (shid->is_panel_follower) +return 0 ; -return 0 ; +return spi_hid_suspend (shid); }static int spi_hid_core_pm_resume (struct device *dev) {struct spi_hid *shid =dev_get_drvdata (dev); -spi_hid_resume (shid); +if (shid->is_panel_follower) +return 0 ; -return 0 ; +return spi_hid_resume (shid); }const struct dev_pm_ops spi_hid_core_pm = {
drivers/hid/spi-hid/spi-hid-core.h +7 -0
@@ -10,6 +10,8 @@#include <linux/hid-over-spi.h> #include <linux/spi/spi.h> +#include <drm/drm_panel.h> +/* Protocol message size constants */ #define SPI_HID_READ_APPROVAL_LEN 5#define SPI_HID_OUTPUT_HEADER_LEN 8
@@ -56,6 +58,10 @@ struct spi_hid {struct spi_hid_input_buf *input;/* Input buffer. */ struct spi_hid_input_buf *response;/* Response buffer. */ +struct drm_panel_follower panel_follower; +bool is_panel_follower; +bool panel_follower_work_finished; +u16 response_length;u16 bufsize;
@@ -66,6 +72,7 @@ struct spi_hid {unsigned long flags;/* device flags. */ struct work_struct reset_work; +struct work_struct panel_follower_work;/* Control lock to ensure complete output transaction. */ struct mutex output_lock;
Signature · 1 line
2.53.0.1185.g05d4b7b318-goog