linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: i2c-hid: Add API to wait for device reset completion
@ 2025-11-14 11:24 LI Qingwu
  2025-11-14 16:13 ` Mario Limonciello (AMD) (kernel.org)
  0 siblings, 1 reply; 2+ messages in thread
From: LI Qingwu @ 2025-11-14 11:24 UTC (permalink / raw)
  To: jikos, bentiss, dianders, treapking, alex.vinarskis,
	dan.carpenter, superm1, guanwentao, kl, Qing-wu.Li, linux-input,
	linux-kernel

Some HID over I2C devices need to signal reset completion to the host
after firmware updates or device resets. Per the HID over I2C spec,
devices signal completion by sending an empty input report (0x0000).

Add i2c_hid_wait_reset_complete() to allow drivers to synchronize
with device reset operations. The function sets I2C_HID_RESET_PENDING
and waits for the device's completion signal.

Returns: 0 on success, -ETIMEDOUT on timeout, -ENODEV if invalid device.

Upstream-Status: Pending
Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
---
 drivers/hid/i2c-hid/i2c-hid-core.c | 24 ++++++++++++++++++++++++
 drivers/hid/i2c-hid/i2c-hid.h      |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index d3912e3f2f13a..4feab2327e92d 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -1365,6 +1365,30 @@ const struct dev_pm_ops i2c_hid_core_pm = {
 };
 EXPORT_SYMBOL_GPL(i2c_hid_core_pm);
 
+int i2c_hid_wait_reset_complete(struct device *dev, unsigned long timeout_ms)
+{
+	struct i2c_client *client;
+	struct i2c_hid *ihid;
+	long ret;
+
+	if (!dev)
+		return -ENODEV;
+
+	client = to_i2c_client(dev);
+	ihid = i2c_get_clientdata(client);
+	if (!ihid)
+		return -ENODEV;
+	set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+	ret = wait_event_timeout(ihid->wait,
+				 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
+				 msecs_to_jiffies(timeout_ms));
+	if (ret == 0) {
+		clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
+	}
+	return ret ? 0 : -ETIMEDOUT;
+}
+EXPORT_SYMBOL_GPL(i2c_hid_wait_reset_complete);
+
 MODULE_DESCRIPTION("HID over I2C core driver");
 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
 MODULE_LICENSE("GPL");
diff --git a/drivers/hid/i2c-hid/i2c-hid.h b/drivers/hid/i2c-hid/i2c-hid.h
index 2c7b66d5caa0f..1c6d959716858 100644
--- a/drivers/hid/i2c-hid/i2c-hid.h
+++ b/drivers/hid/i2c-hid/i2c-hid.h
@@ -40,6 +40,7 @@ void i2c_hid_core_remove(struct i2c_client *client);
 
 void i2c_hid_core_shutdown(struct i2c_client *client);
 
+int i2c_hid_wait_reset_complete(struct device *dev, unsigned long timeout_ms);
 extern const struct dev_pm_ops i2c_hid_core_pm;
 
 #endif
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] HID: i2c-hid: Add API to wait for device reset completion
  2025-11-14 11:24 [PATCH] HID: i2c-hid: Add API to wait for device reset completion LI Qingwu
@ 2025-11-14 16:13 ` Mario Limonciello (AMD) (kernel.org)
  0 siblings, 0 replies; 2+ messages in thread
From: Mario Limonciello (AMD) (kernel.org) @ 2025-11-14 16:13 UTC (permalink / raw)
  To: LI Qingwu, jikos, bentiss, dianders, treapking, alex.vinarskis,
	dan.carpenter, guanwentao, kl, linux-input, linux-kernel



On 11/14/2025 5:24 AM, LI Qingwu wrote:
> Some HID over I2C devices need to signal reset completion to the host
> after firmware updates or device resets. Per the HID over I2C spec,
> devices signal completion by sending an empty input report (0x0000).
> 
> Add i2c_hid_wait_reset_complete() to allow drivers to synchronize
> with device reset operations. The function sets I2C_HID_RESET_PENDING
> and waits for the device's completion signal.
> 
> Returns: 0 on success, -ETIMEDOUT on timeout, -ENODEV if invalid device.
> 
> Upstream-Status: Pending

This tag is probably useful for your downstream tree, but it's not 
useful upstream.  You should strip it when submitting upstream.

> Signed-off-by: LI Qingwu <Qing-wu.Li@leica-geosystems.com.cn>
> ---
>   drivers/hid/i2c-hid/i2c-hid-core.c | 24 ++++++++++++++++++++++++
>   drivers/hid/i2c-hid/i2c-hid.h      |  1 +
>   2 files changed, 25 insertions(+)
> 
> diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
> index d3912e3f2f13a..4feab2327e92d 100644
> --- a/drivers/hid/i2c-hid/i2c-hid-core.c
> +++ b/drivers/hid/i2c-hid/i2c-hid-core.c
> @@ -1365,6 +1365,30 @@ const struct dev_pm_ops i2c_hid_core_pm = {
>   };
>   EXPORT_SYMBOL_GPL(i2c_hid_core_pm);
>   
> +int i2c_hid_wait_reset_complete(struct device *dev, unsigned long timeout_ms)
> +{
> +	struct i2c_client *client;
> +	struct i2c_hid *ihid;
> +	long ret;
> +
> +	if (!dev)
> +		return -ENODEV;
> +
> +	client = to_i2c_client(dev);

Check if client is NULL?

> +	ihid = i2c_get_clientdata(client);
> +	if (!ihid)
> +		return -ENODEV;
> +	set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
> +	ret = wait_event_timeout(ihid->wait,
> +				 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
> +				 msecs_to_jiffies(timeout_ms));
> +	if (ret == 0) {

Shouldn't need curly braces for a one line statement.

> +		clear_bit(I2C_HID_RESET_PENDING, &ihid->flags);
> +	}
> +	return ret ? 0 : -ETIMEDOUT;

Why not just:

return ret;

> +}
> +EXPORT_SYMBOL_GPL(i2c_hid_wait_reset_complete);

Can you please include a second patch in your series demonstrating the 
usage of this in a driver?

> +
>   MODULE_DESCRIPTION("HID over I2C core driver");
>   MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
>   MODULE_LICENSE("GPL");
> diff --git a/drivers/hid/i2c-hid/i2c-hid.h b/drivers/hid/i2c-hid/i2c-hid.h
> index 2c7b66d5caa0f..1c6d959716858 100644
> --- a/drivers/hid/i2c-hid/i2c-hid.h
> +++ b/drivers/hid/i2c-hid/i2c-hid.h
> @@ -40,6 +40,7 @@ void i2c_hid_core_remove(struct i2c_client *client);
>   
>   void i2c_hid_core_shutdown(struct i2c_client *client);
>   
> +int i2c_hid_wait_reset_complete(struct device *dev, unsigned long timeout_ms);
>   extern const struct dev_pm_ops i2c_hid_core_pm;
>   
>   #endif


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-14 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 11:24 [PATCH] HID: i2c-hid: Add API to wait for device reset completion LI Qingwu
2025-11-14 16:13 ` Mario Limonciello (AMD) (kernel.org)

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).