Skip to contentSkip to conversation

hwmon: corsair-cpro: Change to HID driver

PATCH Superseded Marius Zachmann 2 participants 7 messages Jul 15, 2020

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Marius Zachmann

author maintainer
#0 lore raw

PATCH v2 1/1 hwmon: corsair-cpro: Change to HID driver

This changes corsair-cpro to a hid driver using hid reports.

---
Changes from v1
- add comment at the beginning about using hid and hidraw
- use hwmon_device_register_with_info and hwmon_device_unregister
- use a define for timeout

---
 drivers/hid/hid-quirks.c     |   2 -
 drivers/hwmon/Kconfig        |   2 +-
 drivers/hwmon/corsair-cpro.c | 124 ++++++++++++++++++++++++++---------
 3 files changed, 95 insertions(+), 35 deletions(-)
drivers/hid/hid-quirks.c +0 -2
index 7b7bc7737c53..ca8b5c261c7c 100644
@@ -699,8 +699,6 @@ static const struct hid_device_id hid_ignore_list[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_AXENTIA, USB_DEVICE_ID_AXENTIA_FM_RADIO) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x0c10) },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, 0x1d00) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
drivers/hwmon/Kconfig +1 -1
index 8b046a5dfa40..c603d8c8e3d2 100644
@@ -441,7 +441,7 @@ config SENSORS_BT1_PVT_ALARMS
 
 config SENSORS_CORSAIR_CPRO
 	tristate "Corsair Commander Pro controller"
-	depends on USB
+	depends on HID
 	help
 	  If you say yes here you get support for the Corsair Commander Pro
 	  controller.
drivers/hwmon/corsair-cpro.c +93 -31

212 lines not on this page · raw message

--
2.27.0

maintainer
#1 lore raw
Quoted 5 lines · Marius Zachmann

This changes corsair-cpro to a hid driver using hid reports.

---

[ ... ]

Quoted 28 lines
drivers/hwmon/corsair-cpro.c +11 -8
-static const struct usb_device_id ccp_devices[] = {
-	{ USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_PRODUCT_ID_CORSAIR_COMMANDERPRO) },
-	{ USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_PRODUCT_ID_CORSAIR_1000D) },
+static const struct hid_device_id ccp_devices[] = {
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_PRODUCT_ID_CORSAIR_COMMANDERPRO) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CORSAIR, USB_PRODUCT_ID_CORSAIR_1000D) },
 	{ }
 };
 
-static struct usb_driver ccp_driver = {
+static struct hid_driver ccp_driver = {
 	.name = "corsair-cpro",
+	.id_table = ccp_devices,
 	.probe = ccp_probe,
-	.disconnect = ccp_disconnect,
-	.id_table = ccp_devices
+	.remove = ccp_remove,
+	.raw_event = ccp_raw_event,
 };
 
-MODULE_DEVICE_TABLE(usb, ccp_devices);
+MODULE_DEVICE_TABLE(hid, ccp_devices);
 MODULE_LICENSE("GPL");
 
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Thanks,
Guenter

author maintainer
#2 lore raw

On 15.07.20 at 17:35:08 CEST, Guenter Roeck wrote

Quoted 7 lines · Marius Zachmann
Quoted 5 lines

This changes corsair-cpro to a hid driver using hid reports.

---

...

Quoted 18 lines
Quoted 4 lines
drivers/hwmon/corsair-cpro.c +3 -1
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Quoted 3 lines

Thanks,
Guenter

When using module_hid_driver() and compiling the driver as built-in the driver init function will get called before hid and fail registering the driver. late_initcall forces it to be loaded after hid.

Greetings,
Marius

maintainer
#3 lore raw
Quoted 27 lines · Marius Zachmann

On 15.07.20 at 17:35:08 CEST, Guenter Roeck wrote

Quoted 7 lines · Marius Zachmann
Quoted 5 lines

This changes corsair-cpro to a hid driver using hid reports.

---

...

Quoted 18 lines
Quoted 4 lines
drivers/hwmon/corsair-cpro.c +3 -1
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

When using module_hid_driver() and compiling the driver as built-in the driver init function will get called before hid and fail registering the driver. late_initcall forces it to be loaded after hid.

That seems odd. Why does no other hid driver have that problem ? Your argument is pretty much that module_hid_driver() would not work, which seems unlikely.

Thanks,
Guenter

author maintainer
#4 lore raw

On 15.07.20 at 21:49:59 CEST, Guenter Roeck wrote

Quoted 37 lines · Marius Zachmann
Quoted 27 lines

On 15.07.20 at 17:35:08 CEST, Guenter Roeck wrote

Quoted 7 lines · Marius Zachmann
Quoted 5 lines

This changes corsair-cpro to a hid driver using hid reports.

---

...

Quoted 18 lines
Quoted 4 lines
drivers/hwmon/corsair-cpro.c +3 -1
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

When using module_hid_driver() and compiling the driver as built-in the driver init function will get called before hid and fail registering the driver. late_initcall forces it to be loaded after hid.

Quoted 7 lines

That seems odd. Why does no other hid driver have that problem ? Your argument is pretty much that module_hid_driver() would not work, which seems unlikely.

Thanks,
Guenter

The order of initcalls is determined by the build order. Hwmon subsystem gets build before hid subsystem and therefore the initcalls are earlier than hid. But hid_register_driver needs the hid driver to be there.

Greetings
Marius

maintainer
#5 lore raw
Quoted 42 lines · Marius Zachmann

On 15.07.20 at 21:49:59 CEST, Guenter Roeck wrote

Quoted 41 lines · Marius Zachmann
Quoted 27 lines

On 15.07.20 at 17:35:08 CEST, Guenter Roeck wrote

Quoted 7 lines · Marius Zachmann
Quoted 5 lines

This changes corsair-cpro to a hid driver using hid reports.

---

...

Quoted 18 lines
Quoted 4 lines
drivers/hwmon/corsair-cpro.c +3 -1
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

When using module_hid_driver() and compiling the driver as built-in the driver init function will get called before hid and fail registering the driver. late_initcall forces it to be loaded after hid.

That seems odd. Why does no other hid driver have that problem ? Your argument is pretty much that module_hid_driver() would not work, which seems unlikely.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

The order of initcalls is determined by the build order. Hwmon subsystem gets build before hid subsystem and therefore the initcalls are earlier than hid. But hid_register_driver needs the hid driver to be there.

Hmm. I am not happy, but I guess we'll have to live with it.

Can you add the detailed explanation to the comment above ? "make sure it is loaded after hid" doesn't tell the whole story, and I want to avoid having to deal with "cleanup" patches later.

Alternatively, I wonder if it would make sense to force this driver to be built as module. Have you thought about that ?

Thanks,
Guenter

author maintainer
#6 lore raw

On 15.07.20 at 22:11:39 CEST, Guenter Roeck wrote

Quoted 57 lines · Marius Zachmann
Quoted 42 lines

On 15.07.20 at 21:49:59 CEST, Guenter Roeck wrote

Quoted 41 lines · Marius Zachmann
Quoted 27 lines

On 15.07.20 at 17:35:08 CEST, Guenter Roeck wrote

Quoted 7 lines · Marius Zachmann
Quoted 5 lines

This changes corsair-cpro to a hid driver using hid reports.

---

...

Quoted 18 lines
Quoted 4 lines
drivers/hwmon/corsair-cpro.c +3 -1
-module_usb_driver(ccp_driver);
+static int __init ccp_init(void)
+{
+	return hid_register_driver(&ccp_driver);

drivers/hwmon/corsair-cpro.c static int get_temp_cnct(struct ccp_device *ccp) · line 555

Quoted 10 lines
drivers/hwmon/corsair-cpro.c +10 -0
+}
+
+static void __exit ccp_exit(void)
+{
+	hid_unregister_driver(&ccp_driver);
+}
+
+/* make sure it is loaded after hid */
+late_initcall(ccp_init);
+module_exit(ccp_exit);

Sorry for not noticing before, but can you use module_hid_driver() ? That seems to work for other hid drivers.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

When using module_hid_driver() and compiling the driver as built-in the driver init function will get called before hid and fail registering the driver. late_initcall forces it to be loaded after hid.

That seems odd. Why does no other hid driver have that problem ? Your argument is pretty much that module_hid_driver() would not work, which seems unlikely.

Quoted 8 lines
Quoted 3 lines

Thanks,
Guenter

The order of initcalls is determined by the build order. Hwmon subsystem gets build before hid subsystem and therefore the initcalls are earlier than hid. But hid_register_driver needs the hid driver to be there.

Hmm. I am not happy, but I guess we'll have to live with it.

Can you add the detailed explanation to the comment above ? "make sure it is loaded after hid" doesn't tell the whole story, and I want to avoid having to deal with "cleanup" patches later.

Quoted 6 lines

Alternatively, I wonder if it would make sense to force this driver to be built as module. Have you thought about that ?

Thanks,
Guenter

I am also not happy about this and thought about this, but I think late_initcall is the least ugly solution to this. I will add a more detailed explanation.

Greetings
Marius