* [PATCH v2 0/4] Add output report support for QuickI2C driver
@ 2025-12-09 7:52 Even Xu
2025-12-09 7:52 ` [PATCH v2 1/4] HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables Even Xu
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Even Xu @ 2025-12-09 7:52 UTC (permalink / raw)
To: jikos, bentiss; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu
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(-)
--
2.40.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/4] HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables
2025-12-09 7:52 [PATCH v2 0/4] Add output report support for QuickI2C driver Even Xu
@ 2025-12-09 7:52 ` Even Xu
2025-12-09 7:52 ` [PATCH v2 2/4] HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16 writes Even Xu
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Even Xu @ 2025-12-09 7:52 UTC (permalink / raw)
To: jikos, bentiss; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu
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.
Signed-off-by: Even Xu <even.xu@intel.com>
---
.../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(-)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
index 2cb5471a8133..33a1e3db1cb2 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-dev.h
@@ -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;
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
index a63f8c833252..013cbbb39efd 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
@@ -13,11 +13,11 @@
#include "quicki2c-hid.h"
#include "quicki2c-protocol.h"
-static int quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, int cmd_len,
- bool append_data_reg, u8 *data, int data_len,
- u8 *write_buf, int write_buf_len)
+static ssize_t quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, size_t cmd_len,
+ bool append_data_reg, u8 *data, size_t data_len,
+ u8 *write_buf, size_t write_buf_len)
{
- int buf_len, offset = 0;
+ size_t buf_len, offset = 0;
buf_len = HIDI2C_REG_LEN + cmd_len;
@@ -51,10 +51,10 @@ static int quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, int c
return buf_len;
}
-static int quicki2c_encode_cmd(struct quicki2c_device *qcdev, u32 *cmd_buf,
- u8 opcode, u8 report_type, u8 report_id)
+static size_t quicki2c_encode_cmd(struct quicki2c_device *qcdev, u32 *cmd_buf,
+ u8 opcode, u8 report_type, u8 report_id)
{
- int cmd_len;
+ size_t cmd_len;
*cmd_buf = FIELD_PREP(HIDI2C_CMD_OPCODE, opcode) |
FIELD_PREP(HIDI2C_CMD_REPORT_TYPE, report_type);
@@ -72,22 +72,20 @@ static int quicki2c_encode_cmd(struct quicki2c_device *qcdev, u32 *cmd_buf,
}
static int write_cmd_to_txdma(struct quicki2c_device *qcdev, int opcode,
- int report_type, int report_id, u8 *buf, int buf_len)
+ int report_type, int report_id, u8 *buf, size_t buf_len)
{
- size_t write_buf_len;
- int cmd_len, ret;
+ size_t cmd_len;
+ ssize_t len;
u32 cmd;
cmd_len = quicki2c_encode_cmd(qcdev, &cmd, opcode, report_type, report_id);
- ret = quicki2c_init_write_buf(qcdev, cmd, cmd_len, buf ? true : false, buf,
+ len = quicki2c_init_write_buf(qcdev, cmd, cmd_len, buf ? true : false, buf,
buf_len, qcdev->report_buf, qcdev->report_len);
- if (ret < 0)
- return ret;
-
- write_buf_len = ret;
+ if (len < 0)
+ return len;
- return thc_dma_write(qcdev->thc_hw, qcdev->report_buf, write_buf_len);
+ return thc_dma_write(qcdev->thc_hw, qcdev->report_buf, len);
}
int quicki2c_set_power(struct quicki2c_device *qcdev, enum hidi2c_power_state power_state)
@@ -126,13 +124,13 @@ int quicki2c_get_report_descriptor(struct quicki2c_device *qcdev)
}
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)
{
struct hidi2c_report_packet *rpt;
- size_t write_buf_len, read_len = 0;
- int cmd_len, rep_type;
+ size_t cmd_len, read_len = 0;
+ int rep_type, ret;
+ ssize_t len;
u32 cmd;
- int ret;
if (report_type == HID_INPUT_REPORT) {
rep_type = HIDI2C_INPUT;
@@ -145,25 +143,22 @@ int quicki2c_get_report(struct quicki2c_device *qcdev, u8 report_type,
cmd_len = quicki2c_encode_cmd(qcdev, &cmd, HIDI2C_GET_REPORT, rep_type, reportnum);
- ret = quicki2c_init_write_buf(qcdev, cmd, cmd_len, true, NULL, 0,
+ len = quicki2c_init_write_buf(qcdev, cmd, cmd_len, true, NULL, 0,
qcdev->report_buf, qcdev->report_len);
- if (ret < 0)
- return ret;
-
- write_buf_len = ret;
+ if (len < 0)
+ return len;
rpt = (struct hidi2c_report_packet *)qcdev->input_buf;
- ret = thc_swdma_read(qcdev->thc_hw, qcdev->report_buf, write_buf_len,
- NULL, rpt, &read_len);
+ ret = thc_swdma_read(qcdev->thc_hw, qcdev->report_buf, len, NULL, rpt, &read_len);
if (ret) {
- dev_err_once(qcdev->dev, "Get report failed, ret %d, read len (%zu vs %d)\n",
+ dev_err_once(qcdev->dev, "Get report failed, ret %d, read len (%zu vs %zu)\n",
ret, read_len, buf_len);
return ret;
}
if (HIDI2C_DATA_LEN(le16_to_cpu(rpt->len)) != buf_len || rpt->data[0] != reportnum) {
- dev_err_once(qcdev->dev, "Invalid packet, len (%d vs %d) report id (%d vs %d)\n",
+ dev_err_once(qcdev->dev, "Invalid packet, len (%d vs %zu) report id (%d vs %d)\n",
le16_to_cpu(rpt->len), buf_len, rpt->data[0], reportnum);
return -EINVAL;
}
@@ -174,7 +169,7 @@ int quicki2c_get_report(struct quicki2c_device *qcdev, u8 report_type,
}
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 rep_type;
int ret;
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
index bf4908cce59c..db70e08c8b1c 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
@@ -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);
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/4] HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16 writes
2025-12-09 7:52 [PATCH v2 0/4] Add output report support for QuickI2C driver Even Xu
2025-12-09 7:52 ` [PATCH v2 1/4] HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables Even Xu
@ 2025-12-09 7:52 ` Even Xu
2025-12-09 7:52 ` [PATCH v2 3/4] HID: Intel-thc-hid: Intel-quicki2c: Support writing output report format Even Xu
2025-12-09 7:52 ` [PATCH v2 4/4] HID: Intel-thc-hid: Intel-quicki2c: Add output report support Even Xu
3 siblings, 0 replies; 5+ messages in thread
From: Even Xu @ 2025-12-09 7:52 UTC (permalink / raw)
To: jikos, bentiss; +Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu
Replace 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.
Signed-off-by: Even Xu <even.xu@intel.com>
---
drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
index 013cbbb39efd..ab390ce79c21 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
@@ -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);
}
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/4] HID: Intel-thc-hid: Intel-quicki2c: Support writing output report format
2025-12-09 7:52 [PATCH v2 0/4] Add output report support for QuickI2C driver Even Xu
2025-12-09 7:52 ` [PATCH v2 1/4] HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables Even Xu
2025-12-09 7:52 ` [PATCH v2 2/4] HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16 writes Even Xu
@ 2025-12-09 7:52 ` Even Xu
2025-12-09 7:52 ` [PATCH v2 4/4] HID: Intel-thc-hid: Intel-quicki2c: Add output report support Even Xu
3 siblings, 0 replies; 5+ messages in thread
From: Even Xu @ 2025-12-09 7:52 UTC (permalink / raw)
To: jikos, bentiss
Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu,
Rui Zhang, Ilpo Järvinen
There 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.
Tested-by: Rui Zhang <rui1.zhang@intel.com>
Signed-off-by: Even Xu <even.xu@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
.../intel-quicki2c/quicki2c-protocol.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
index ab390ce79c21..a287d9ee09c3 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
@@ -30,13 +30,18 @@ static ssize_t quicki2c_init_write_buf(struct quicki2c_device *qcdev, u32 cmd, s
if (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;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 4/4] HID: Intel-thc-hid: Intel-quicki2c: Add output report support
2025-12-09 7:52 [PATCH v2 0/4] Add output report support for QuickI2C driver Even Xu
` (2 preceding siblings ...)
2025-12-09 7:52 ` [PATCH v2 3/4] HID: Intel-thc-hid: Intel-quicki2c: Support writing output report format Even Xu
@ 2025-12-09 7:52 ` Even Xu
3 siblings, 0 replies; 5+ messages in thread
From: Even Xu @ 2025-12-09 7:52 UTC (permalink / raw)
To: jikos, bentiss
Cc: srinivas.pandruvada, linux-input, linux-kernel, Even Xu,
Rui Zhang
Add 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.
Tested-by: Rui Zhang <rui1.zhang@intel.com>
Signed-off-by: Even Xu <even.xu@intel.com>
---
.../intel-quicki2c/quicki2c-hid.c | 8 ++++++++
.../intel-quicki2c/quicki2c-protocol.c | 19 +++++++++++++++++++
.../intel-quicki2c/quicki2c-protocol.h | 1 +
3 files changed, 28 insertions(+)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
index 5c3ec95bb3fd..580a760b3ffc 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-hid.c
@@ -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,
};
/**
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
index a287d9ee09c3..41271301215a 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.c
@@ -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 5
int quicki2c_reset(struct quicki2c_device *qcdev)
diff --git a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
index db70e08c8b1c..6642cefb8a67 100644
--- a/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
+++ b/drivers/hid/intel-thc-hid/intel-quicki2c/quicki2c-protocol.h
@@ -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);
--
2.40.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-09 7:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-09 7:52 [PATCH v2 0/4] Add output report support for QuickI2C driver Even Xu
2025-12-09 7:52 ` [PATCH v2 1/4] HID: Intel-thc-hid: Intel-quicki2c: Use size_t for all length variables Even Xu
2025-12-09 7:52 ` [PATCH v2 2/4] HID: Intel-thc-hid: Intel-quicki2c: Use put_unaligned_le16 for __le16 writes Even Xu
2025-12-09 7:52 ` [PATCH v2 3/4] HID: Intel-thc-hid: Intel-quicki2c: Support writing output report format Even Xu
2025-12-09 7:52 ` [PATCH v2 4/4] HID: Intel-thc-hid: Intel-quicki2c: Add output report support Even Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).