All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: add HID device reset callback
@ 2022-04-19 12:26 Angela Czubak
  2022-04-20 20:51 ` Dmitry Torokhov
  0 siblings, 1 reply; 5+ messages in thread
From: Angela Czubak @ 2022-04-19 12:26 UTC (permalink / raw)
  To: linux-input
  Cc: upstream, benjamin.tissoires, jikos, dmitry.torokhov, Angela Czubak

HID-over-I2C devices might reset on their own. Any device configuration
applied before the reset might be brought back to defaults so we need to
reconfigure to make sure the driver state is consistent.

Add a reset callback to the hid driver structure.
Issue it if the driver implements it and the device reset gets observed.

Signed-off-by: Angela Czubak <acz@semihalf.com>
---

Hi guys,

This is a patch introducing callbacks to be issued when device reset gets
noticed. The discussion started in one of the previous linux-input threads [0].

Please let me know if there is anything to fix.

Regards,
Angela

[0] https://lore.kernel.org/linux-input/CAO-hwJ+OgLMkAy+Ms1xgHz3RTYxS+5LCSSP3njju+joTYWZMqA@mail.gmail.com/T/#t

 drivers/hid/i2c-hid/i2c-hid-core.c | 2 ++
 include/linux/hid.h                | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index c078f09a2318..96739d7a4191 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -529,6 +529,8 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)
 		/* host or device initiated RESET completed */
 		if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
 			wake_up(&ihid->wait);
+		if (ihid->hid && ihid->hid->driver && ihid->hid->driver->reset)
+			ihid->hid->driver->reset(ihid->hid);
 		return;
 	}
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 4363a63b9775..50b9dde2c870 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -755,6 +755,7 @@ struct hid_usage_id {
  * @suspend: invoked on suspend (NULL means nop)
  * @resume: invoked on resume if device was not reset (NULL means nop)
  * @reset_resume: invoked on resume if device was reset (NULL means nop)
+ * @reset: invoked if device was reset (NULL means nop)
  *
  * probe should return -errno on error, or 0 on success. During probe,
  * input will not be passed to raw_event unless hid_device_io_start is
@@ -811,6 +812,7 @@ struct hid_driver {
 	int (*resume)(struct hid_device *hdev);
 	int (*reset_resume)(struct hid_device *hdev);
 #endif
+	int (*reset)(struct hid_device *hdev);
 /* private: */
 	struct device_driver driver;
 };
-- 
2.36.0.rc2.479.g8af0fa9b8e-goog


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

end of thread, other threads:[~2022-05-10 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 12:26 [PATCH] HID: add HID device reset callback Angela Czubak
2022-04-20 20:51 ` Dmitry Torokhov
2022-04-21 11:23   ` Angela Czubak
2022-05-06  7:08     ` Benjamin Tissoires
2022-05-10 17:23       ` Angela Czubak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.