All of lore.kernel.org
 help / color / mirror / Atom feed
* [v4 1/5] HID: core: Export hid_match_id()
@ 2022-08-30 13:25 Bastien Nocera
  2022-08-30 13:25 ` [v4 2/5] HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices Bastien Nocera
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-08-30 13:25 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Export hid_match_id() so it can be used in device-specific drivers to
implement their own matching with open-coding a match function.

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index b7f5566e338d..72f8d8835b34 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2088,6 +2088,7 @@ const struct hid_device_id *hid_match_id(const struct hid_device *hdev,
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(hid_match_id);
 
 static const struct hid_device_id hid_hiddev_list[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
-- 
2.37.2


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

* [v4 2/5] HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices
  2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
@ 2022-08-30 13:25 ` Bastien Nocera
  2022-08-30 13:25 ` [v4 3/5] HID: logitech-hidpp: Remove special-casing of " Bastien Nocera
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-08-30 13:25 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Probe for HID++ support over Bluetooth for all the Logitech Bluetooth
devices. As Logitech doesn't have a list of Bluetooth devices that
support HID++ over Bluetooth, probe every device. The HID++ driver
will fall back to plain HID if the device does not support HID++,
or to a another device-specific driver if it is part of the
unhandled_hidpp_devices array, used in the match function.

Note that this change might cause upower to export 2 batteries for
certain Bluetooth LE devices which export their battery information
through the Bluetooth BATT profile. This particular bug is tracked at:
https://gitlab.freedesktop.org/upower/upower/-/issues/166

Tested with a Logitech Signature M650 mouse, over Bluetooth

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-logitech-hidpp.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 68f9e9d207f4..641c897bf714 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4219,6 +4219,21 @@ static void hidpp_remove(struct hid_device *hdev)
 	mutex_destroy(&hidpp->send_mutex);
 }
 
+static const struct hid_device_id unhandled_hidpp_devices[] = {
+	/* Logitech Harmony Adapter for PS3, handled in hid-sony */
+	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_PS3) },
+	/* Handled in hid-generic */
+	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_DINOVO_EDGE_KBD) },
+	{}
+};
+
+static bool hidpp_match(struct hid_device *hdev,
+			bool ignore_special_driver)
+{
+	/* Refuse to handle devices handled by other HID drivers */
+	return !hid_match_id(hdev, unhandled_hidpp_devices);
+}
+
 #define LDJ_DEVICE(product) \
 	HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE, \
 		   USB_VENDOR_ID_LOGITECH, (product))
@@ -4347,6 +4362,9 @@ static const struct hid_device_id hidpp_devices[] = {
 	{ /* MX Master 3 mouse over Bluetooth */
 	  HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb023),
 	  .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
+
+	{ /* And try to enable HID++ for all the Logitech Bluetooth devices */
+	  HID_DEVICE(BUS_BLUETOOTH, HID_GROUP_ANY, USB_VENDOR_ID_LOGITECH, HID_ANY_ID) },
 	{}
 };
 
@@ -4360,6 +4378,7 @@ static const struct hid_usage_id hidpp_usages[] = {
 static struct hid_driver hidpp_driver = {
 	.name = "logitech-hidpp-device",
 	.id_table = hidpp_devices,
+	.match = hidpp_match,
 	.report_fixup = hidpp_report_fixup,
 	.probe = hidpp_probe,
 	.remove = hidpp_remove,
-- 
2.37.2


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

* [v4 3/5] HID: logitech-hidpp: Remove special-casing of Bluetooth devices
  2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
  2022-08-30 13:25 ` [v4 2/5] HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices Bastien Nocera
@ 2022-08-30 13:25 ` Bastien Nocera
  2022-08-30 13:25 ` [v4 4/5] HID: logitech-hidpp: Fix "Sw. Id." for HID++ 2.0 commands Bastien Nocera
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-08-30 13:25 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Now that all the Logitech Bluetooth devices are probed for HID++
support, remove the handling of those 2 devices without any quirks, as
they're duplicates.

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-logitech-hidpp.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 641c897bf714..98ebedb73d98 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -4350,13 +4350,9 @@ static const struct hid_device_id hidpp_devices[] = {
 	{ /* MX5500 keyboard over Bluetooth */
 	  HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb30b),
 	  .driver_data = HIDPP_QUIRK_HIDPP_CONSUMER_VENDOR_KEYS },
-	{ /* M-RCQ142 V470 Cordless Laser Mouse over Bluetooth */
-	  HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb008) },
 	{ /* MX Master mouse over Bluetooth */
 	  HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb012),
 	  .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
-	{ /* MX Ergo trackball over Bluetooth */
-	  HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01d) },
 	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH, 0xb01e),
 	  .driver_data = HIDPP_QUIRK_HI_RES_SCROLL_X2121 },
 	{ /* MX Master 3 mouse over Bluetooth */
-- 
2.37.2


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

* [v4 4/5] HID: logitech-hidpp: Fix "Sw. Id." for HID++ 2.0 commands
  2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
  2022-08-30 13:25 ` [v4 2/5] HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices Bastien Nocera
  2022-08-30 13:25 ` [v4 3/5] HID: logitech-hidpp: Remove special-casing of " Bastien Nocera
@ 2022-08-30 13:25 ` Bastien Nocera
  2022-08-30 13:25 ` [v4 5/5] HID: logitech-hidpp: Remove hard-coded " Bastien Nocera
  2022-09-07 15:39 ` [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
  4 siblings, 0 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-08-30 13:25 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Always set a non-zero "Sw. Id." in the lower nibble of the Function/ASE
and Software Identifier byte in HID++ 2.0 commands.

As per the "Protocol HID++2.0 essential features" section in
https://lekensteyn.nl/files/logitech/logitech_hidpp_2.0_specification_draft_2012-06-04.pdf
"
Software identifier (4 bits, unsigned)

A number uniquely defining the software that sends a request. The
firmware must copy the software identifier in the response but does
not use it in any other ways.

0 Do not use (allows to distinguish a notification from a response).
"

Link: https://bugzilla.kernel.org/show_bug.cgi?id=215699
Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-logitech-hidpp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 98ebedb73d98..e51ccf2c04e3 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -41,6 +41,9 @@ module_param(disable_tap_to_click, bool, 0644);
 MODULE_PARM_DESC(disable_tap_to_click,
 	"Disable Tap-To-Click mode reporting for touchpads (only on the K400 currently).");
 
+/* Define a non-zero software ID to identify our own requests */
+#define LINUX_KERNEL_SW_ID			0x01
+
 #define REPORT_ID_HIDPP_SHORT			0x10
 #define REPORT_ID_HIDPP_LONG			0x11
 #define REPORT_ID_HIDPP_VERY_LONG		0x12
@@ -343,7 +346,7 @@ static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
 	else
 		message->report_id = REPORT_ID_HIDPP_LONG;
 	message->fap.feature_index = feat_index;
-	message->fap.funcindex_clientid = funcindex_clientid;
+	message->fap.funcindex_clientid = funcindex_clientid | LINUX_KERNEL_SW_ID;
 	memcpy(&message->fap.params, params, param_count);
 
 	ret = hidpp_send_message_sync(hidpp, message, response);
-- 
2.37.2


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

* [v4 5/5] HID: logitech-hidpp: Remove hard-coded "Sw. Id." for HID++ 2.0 commands
  2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
                   ` (2 preceding siblings ...)
  2022-08-30 13:25 ` [v4 4/5] HID: logitech-hidpp: Fix "Sw. Id." for HID++ 2.0 commands Bastien Nocera
@ 2022-08-30 13:25 ` Bastien Nocera
  2022-09-07 15:39 ` [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
  4 siblings, 0 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-08-30 13:25 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Some HID++ 2.0 commands had correctly set a non-zero software identifier
directly as part of their function identifiers, but it's more correct to
define the function identifier and the software identifier separately
before combined them when the command is sent.

As this is now done in the previous commit, remove the hard-coded 0x1
software identifiers in the function definitions.

Signed-off-by: Bastien Nocera <hadess@hadess.net>
---
 drivers/hid/hid-logitech-hidpp.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index e51ccf2c04e3..74013d0e0a24 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -859,8 +859,8 @@ static int hidpp_unifying_init(struct hidpp_device *hidpp)
 #define HIDPP_PAGE_ROOT					0x0000
 #define HIDPP_PAGE_ROOT_IDX				0x00
 
-#define CMD_ROOT_GET_FEATURE				0x01
-#define CMD_ROOT_GET_PROTOCOL_VERSION			0x11
+#define CMD_ROOT_GET_FEATURE				0x00
+#define CMD_ROOT_GET_PROTOCOL_VERSION			0x10
 
 static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
 	u8 *feature_index, u8 *feature_type)
@@ -937,9 +937,9 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
 
 #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE			0x0005
 
-#define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT		0x01
-#define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME	0x11
-#define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE		0x21
+#define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT		0x00
+#define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME	0x10
+#define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE		0x20
 
 static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
 	u8 feature_index, u8 *nameLength)
@@ -1969,8 +1969,8 @@ static int hidpp_touchpad_fw_items_set(struct hidpp_device *hidpp,
 
 #define HIDPP_PAGE_TOUCHPAD_RAW_XY			0x6100
 
-#define CMD_TOUCHPAD_GET_RAW_INFO			0x01
-#define CMD_TOUCHPAD_SET_RAW_REPORT_STATE		0x21
+#define CMD_TOUCHPAD_GET_RAW_INFO			0x00
+#define CMD_TOUCHPAD_SET_RAW_REPORT_STATE		0x20
 
 #define EVENT_TOUCHPAD_RAW_XY				0x00
 
-- 
2.37.2


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

* Re: [v4 1/5] HID: core: Export hid_match_id()
  2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
                   ` (3 preceding siblings ...)
  2022-08-30 13:25 ` [v4 5/5] HID: logitech-hidpp: Remove hard-coded " Bastien Nocera
@ 2022-09-07 15:39 ` Bastien Nocera
  2022-09-07 20:09   ` Jiri Kosina
  4 siblings, 1 reply; 8+ messages in thread
From: Bastien Nocera @ 2022-09-07 15:39 UTC (permalink / raw)
  To: linux-input
  Cc: linux-kernel, Jiri Kosina, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

Jiri,

If those patches look good to you, would be great to get merged.
Benjamin doesn't have the bandwidth to test the patches on his own test
hardware right now, but I've been using them daily for a week now.

Cheers

On Tue, 2022-08-30 at 15:25 +0200, Bastien Nocera wrote:
> Export hid_match_id() so it can be used in device-specific drivers to
> implement their own matching with open-coding a match function.
> 
> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> ---
>  drivers/hid/hid-core.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index b7f5566e338d..72f8d8835b34 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
> @@ -2088,6 +2088,7 @@ const struct hid_device_id *hid_match_id(const
> struct hid_device *hdev,
>  
>         return NULL;
>  }
> +EXPORT_SYMBOL_GPL(hid_match_id);
>  
>  static const struct hid_device_id hid_hiddev_list[] = {
>         { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },


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

* Re: [v4 1/5] HID: core: Export hid_match_id()
  2022-09-07 15:39 ` [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
@ 2022-09-07 20:09   ` Jiri Kosina
  2022-09-08  8:03     ` Bastien Nocera
  0 siblings, 1 reply; 8+ messages in thread
From: Jiri Kosina @ 2022-09-07 20:09 UTC (permalink / raw)
  To: Bastien Nocera
  Cc: linux-input, linux-kernel, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

On Wed, 7 Sep 2022, Bastien Nocera wrote:

> > Export hid_match_id() so it can be used in device-specific drivers to
> > implement their own matching with open-coding a match function.
> > 
> > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > ---
> >  drivers/hid/hid-core.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> > index b7f5566e338d..72f8d8835b34 100644
> > --- a/drivers/hid/hid-core.c
> > +++ b/drivers/hid/hid-core.c
> > @@ -2088,6 +2088,7 @@ const struct hid_device_id *hid_match_id(const
> > struct hid_device *hdev,
> >  
> >         return NULL;
> >  }
> > +EXPORT_SYMBOL_GPL(hid_match_id);
> >  
> >  static const struct hid_device_id hid_hiddev_list[] = {
> >         { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
> 
> If those patches look good to you, would be great to get merged.
> Benjamin doesn't have the bandwidth to test the patches on his own test
> hardware right now, but I've been using them daily for a week now.

Alright, I was waiting for Ack from Benjamin, but based on this, and due 
to the fact that I don't see any issue with it myself, I've now applied 
the series to for-6.1/logitech branch so that it gets as much linux-next 
exposure as possible.

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

* Re: [v4 1/5] HID: core: Export hid_match_id()
  2022-09-07 20:09   ` Jiri Kosina
@ 2022-09-08  8:03     ` Bastien Nocera
  0 siblings, 0 replies; 8+ messages in thread
From: Bastien Nocera @ 2022-09-08  8:03 UTC (permalink / raw)
  To: Jiri Kosina
  Cc: linux-input, linux-kernel, Benjamin Tissoires,
	Peter F . Patel-Schneider, Filipe Laíns,
	Nestor Lopez Casado

On Wed, 2022-09-07 at 22:09 +0200, Jiri Kosina wrote:
> On Wed, 7 Sep 2022, Bastien Nocera wrote:
> 
> > > Export hid_match_id() so it can be used in device-specific
> > > drivers to
> > > implement their own matching with open-coding a match function.
> > > 
> > > Signed-off-by: Bastien Nocera <hadess@hadess.net>
> > > ---
> > >  drivers/hid/hid-core.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> > > index b7f5566e338d..72f8d8835b34 100644
> > > --- a/drivers/hid/hid-core.c
> > > +++ b/drivers/hid/hid-core.c
> > > @@ -2088,6 +2088,7 @@ const struct hid_device_id
> > > *hid_match_id(const
> > > struct hid_device *hdev,
> > >  
> > >         return NULL;
> > >  }
> > > +EXPORT_SYMBOL_GPL(hid_match_id);
> > >  
> > >  static const struct hid_device_id hid_hiddev_list[] = {
> > >         { HID_USB_DEVICE(USB_VENDOR_ID_MGE,
> > > USB_DEVICE_ID_MGE_UPS) },
> > 
> > If those patches look good to you, would be great to get merged.
> > Benjamin doesn't have the bandwidth to test the patches on his own
> > test
> > hardware right now, but I've been using them daily for a week now.
> 
> Alright, I was waiting for Ack from Benjamin, but based on this, and
> due 
> to the fact that I don't see any issue with it myself, I've now
> applied 
> the series to for-6.1/logitech branch so that it gets as much linux-
> next 
> exposure as possible.

Great, thanks!

Peter, if there were any other bugs in the hid-logitech-hidpp
implementation that needed handling, please file them at
bugzilla.kernel.org so they don't get lost.

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

end of thread, other threads:[~2022-09-08  8:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 13:25 [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
2022-08-30 13:25 ` [v4 2/5] HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices Bastien Nocera
2022-08-30 13:25 ` [v4 3/5] HID: logitech-hidpp: Remove special-casing of " Bastien Nocera
2022-08-30 13:25 ` [v4 4/5] HID: logitech-hidpp: Fix "Sw. Id." for HID++ 2.0 commands Bastien Nocera
2022-08-30 13:25 ` [v4 5/5] HID: logitech-hidpp: Remove hard-coded " Bastien Nocera
2022-09-07 15:39 ` [v4 1/5] HID: core: Export hid_match_id() Bastien Nocera
2022-09-07 20:09   ` Jiri Kosina
2022-09-08  8:03     ` Bastien Nocera

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.