Add output report support for QuickI2C driver
Subsystems (2)
Even Xu
maintainerv2 cover Add output report support for QuickI2C driver
This patch serial adds support for HID output reports in the Quicki2c driver by implementing the output_report callback in the HID low-level driver interface.
This change introduces:
- Refine QuickI2C driver to use size_t for all length-related variables
- Enhance the quicki2c_init_write_buf() function by adding support for writing to the output register based on the content being written
- Add quicki2c_hid_output_report() and quicki2c_output_report() function that processe the HID output reports request
This enables proper communication with HID devices that require output report functionality, such as setting device configuration or updating device firmware.
Change log:
v2:
- Fix a return error code check bug in [patch 4/4]
Even Xu (4):
HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length
variables
HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16
writes
HID: Intel-thc-hid: Intel-quicki2c: Support writing output report
format
HID: Intel-thc-hid: Intel-quicki2c: Add output report support
.../intel-quicki2c/quicki2c-dev.h | 2 +- .../intel-quicki2c/quicki2c-hid.c | 8 ++ .../intel-quicki2c/quicki2c-protocol.c | 95 +++++++++++-------- .../intel-quicki2c/quicki2c-protocol.h | 5 +- 4 files changed, 68 insertions(+), 42 deletions(-)
Signature · 1 line
2.40.1
Even Xu
maintainerPATCH v2 1/4 HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables
Convert all length-related variables in the QuickI2C protocol layer to use size_t type to follow kernel coding conventions.
This includes:
- All buffer length parameters and variables
- Return values of quicki2c_encode_cmd() function which represents encoded command buffer size.
- Return values of quicki2c_init_write_buf() function which represents process result: either prepared output buffer size or error code.
This change improves type consistency and aligns with standard kernel practices for memory size representation, reducing potential issues with size calculations and comparisons.
--- .../intel-quicki2c/quicki2c-dev.h | 2 +- .../intel-quicki2c/quicki2c-protocol.c | 55 +++++++++---------- .../intel-quicki2c/quicki2c-protocol.h | 4 +- 3 files changed, 28 insertions(+), 33 deletions(-)
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h +1 -1
@@ -213,7 +213,7 @@ struct quicki2c_device {u8 *report_descriptor;u8 *input_buf;u8 *report_buf; -u32 report_len; +size_t report_len;wait_queue_head_t reset_ack_wq;bool reset_ack;
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c +25 -30
113 lines not on this page · raw message
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h +2 -2
@@ -10,9 +10,9 @@ struct quicki2c_device;int quicki2c_set_power (struct quicki2c_device *qcdev,enum hidi2c_power_state power_state);int quicki2c_get_report (struct quicki2c_device *qcdev,u8 report_type, -unsigned int reportnum,void *buf,u32 buf_len); +unsigned int reportnum,void *buf,size_t buf_len);int quicki2c_set_report (struct quicki2c_device *qcdev,u8 report_type, -unsigned int reportnum,void *buf,u32 buf_len); +unsigned int reportnum,void *buf,size_t buf_len);int quicki2c_get_device_descriptor (struct quicki2c_device *qcdev);int quicki2c_get_report_descriptor (struct quicki2c_device *qcdev);int quicki2c_reset (struct quicki2c_device *qcdev);
Signature · 1 line
2.40.1
Even Xu
maintainerPATCH v2 2/4 HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16 writes
In reply to Even XuReplace memcpy operations with put_unaligned_le16() when writing 16-bit little-endian values to the write buffer.
This change improves code clarity and ensures proper handling of unaligned memory access.
--- drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c +1 -3
@@ -41,9 +41,7 @@ static ssize_t quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, s }if (data && data_len) { -__le16 len =cpu_to_le16 (data_len +HIDI2C_LENGTH_LEN ); - -memcpy (write_buf + offset, &len,HIDI2C_LENGTH_LEN ); +put_unaligned_le16 (data_len +HIDI2C_LENGTH_LEN , write_buf + offset); offset +=HIDI2C_LENGTH_LEN ;memcpy (write_buf + offset, data, data_len); }
Signature · 1 line
2.40.1
Even Xu
maintainerPATCH v2 3/4 HID: Intel-thc-hid: Intel-quicki2c: Support writing output report format
In reply to Even XuThere are two output formats requested in the HID-over-I2C specification:
- Command format (set feature/set report): encoded command written to command register, followed by data written to data register
- Output report format: all data written directly to output register
Current quicki2c_init_write_buf() implementation only supports the command format.
Extend quicki2c_init_write_buf() to automatically detect the output format based on the presence of command parameters and prepare the appropriate output buffer accordingly.
--- .../intel-quicki2c/quicki2c-protocol.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c +11 -6
@@ -30,13 +30,18 @@ static ssize_t quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, sif (buf_len > write_buf_len)return -EINVAL ; -memcpy (write_buf, &qcdev->dev_desc.cmd_reg,HIDI2C_REG_LEN ); - offset +=HIDI2C_REG_LEN ; -memcpy (write_buf + offset, &cmd, cmd_len); - offset += cmd_len; +if (cmd_len) { +memcpy (write_buf, &qcdev->dev_desc.cmd_reg,HIDI2C_REG_LEN ); + offset +=HIDI2C_REG_LEN ; +memcpy (write_buf + offset, &cmd, cmd_len); + offset += cmd_len; -if (append_data_reg) { -memcpy (write_buf + offset, &qcdev->dev_desc.data_reg,HIDI2C_REG_LEN ); +if (append_data_reg) { +memcpy (write_buf + offset, &qcdev->dev_desc.data_reg,HIDI2C_REG_LEN ); + offset +=HIDI2C_REG_LEN ; + } + }else { +memcpy (write_buf, &qcdev->dev_desc.output_reg,HIDI2C_REG_LEN ); offset +=HIDI2C_REG_LEN ; }
Signature · 1 line
2.40.1
Even Xu
maintainerPATCH v2 4/4 HID: Intel-thc-hid: Intel-quicki2c: Add output report support
In reply to Even XuAdd support for HID output reports in the intel-quicki2c driver by implementing the output_report callback in the HID low-level driver interface.
This enables proper communication with HID devices that require output report functionality, such as setting device configuration or updating device firmware.
--- .../intel-quicki2c/quicki2c-hid.c | 8 ++++++++ .../intel-quicki2c/quicki2c-protocol.c | 19 +++++++++++++++++++ .../intel-quicki2c/quicki2c-protocol.h | 1 + 3 files changed, 28 insertions(+)
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c +8 -0
@@ -83,6 +83,13 @@ static int quicki2c_hid_power(struct hid_device *hid, int lvl)return 0 ; } +static int quicki2c_hid_output_report (struct hid_device *hid,u8 *buf,size_t count) +{ +struct quicki2c_device *qcdev = hid->driver_data; + +return quicki2c_output_report (qcdev, buf, count); +} +static struct hid_ll_driver quicki2c_hid_ll_driver = { .parse = quicki2c_hid_parse, .start = quicki2c_hid_start,
@@ -91,6 +98,7 @@ static struct hid_ll_driver quicki2c_hid_ll_driver = { .close = quicki2c_hid_close, .power = quicki2c_hid_power, .raw_request = quicki2c_hid_raw_request, + .output_report = quicki2c_hid_output_report, };/**
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c +19 -0
@@ -195,6 +195,25 @@ int quicki2c_set_report(struct quicki2c_device *qcdev, u8 report_type,return buf_len; } +int quicki2c_output_report (struct quicki2c_device *qcdev,void *buf,size_t buf_len) +{ +ssize_t len; +int ret; + + len =quicki2c_init_write_buf (qcdev,0 ,0 , false, buf, buf_len, + qcdev->report_buf, qcdev->report_len); +if (len <0 ) +return -EINVAL ; + + ret =thc_dma_write (qcdev->thc_hw, qcdev->report_buf, len); +if (ret) { +dev_err (qcdev->dev,"Output Report failed, ret %d\n" , ret); +return ret; + } + +return buf_len; +} +#define HIDI2C_RESET_TIMEOUT 5int quicki2c_reset (struct quicki2c_device *qcdev)
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h +1 -0
@@ -13,6 +13,7 @@ int quicki2c_get_report(struct quicki2c_device *qcdev, u8 report_type, unsigned int reportnum, void *buf, size_t buf_len);int quicki2c_set_report (struct quicki2c_device *qcdev,u8 report_type,unsigned int reportnum,void *buf,size_t buf_len); +int quicki2c_output_report (struct quicki2c_device *qcdev,void *buf,size_t buf_len);int quicki2c_get_device_descriptor (struct quicki2c_device *qcdev);int quicki2c_get_report_descriptor (struct quicki2c_device *qcdev);int quicki2c_reset (struct quicki2c_device *qcdev);
Signature · 1 line
2.40.1
Jiri Kosina
maintainerQuoted 11 lines · Even Xu
This patch serial adds support for HID output reports in the Quicki2c driver by implementing the
output_reportcallback in the HID low-level driver interface.This change introduces:
- Refine QuickI2C driver to usesize_tfor all length-related variables
- Enhance thequicki2c_init_write_buf()function by adding support for writing to the output register based on the content being written
- Addquicki2c_hid_output_report()andquicki2c_output_report()function that processe the HID output reports request
Quoted 3 lines
This enables proper communication with HID devices that require output report functionality, such as setting device configuration or updating device firmware.
Now queued in hid.git#for-6.20/intel-thc, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs