diff mbox series

HID: wacom: Ensure bootloader PID is usable in hidraw mode

Message ID 20221201231141.112916-1-jason.gerecke@wacom.com (mailing list archive)
State Mainlined
Commit 1db1f392591aff13fd643f0ec7c1d5e27391d700
Delegated to: Jiri Kosina
Headers show
Series HID: wacom: Ensure bootloader PID is usable in hidraw mode | expand

Commit Message

Gerecke, Jason Dec. 1, 2022, 11:11 p.m. UTC
From: Jason Gerecke <killertofu@gmail.com>

Some Wacom devices have a special "bootloader" mode that is used for
firmware flashing. When operating in this mode, the device cannot be
used for input, and the HID descriptor is not able to be processed by
the driver. The driver generates an "Unknown device_type" warning and
then returns an error code from wacom_probe(). This is a problem because
userspace still needs to be able to interact with the device via hidraw
to perform the firmware flash.

This commit adds a non-generic device definition for 056a:0094 which
is used when devices are in "bootloader" mode. It marks the devices
with a special BOOTLOADER type that is recognized by wacom_probe() and
wacom_raw_event(). When we see this type we ensure a hidraw device is
created and otherwise keep our hands off so that userspace is in full
control.

Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
Tested-by: Tatsunosuke Tobita <tatsunosuke.tobita@wacom.com>
Cc: <stable@vger.kernel.org>
---
 drivers/hid/wacom_sys.c | 8 ++++++++
 drivers/hid/wacom_wac.c | 4 ++++
 drivers/hid/wacom_wac.h | 1 +
 3 files changed, 13 insertions(+)

Comments

Gerecke, Jason Dec. 15, 2022, 3:53 p.m. UTC | #1
On Thu, Dec 1, 2022 at 3:11 PM Jason Gerecke <killertofu@gmail.com> wrote:
>
> From: Jason Gerecke <killertofu@gmail.com>
>
> Some Wacom devices have a special "bootloader" mode that is used for
> firmware flashing. When operating in this mode, the device cannot be
> used for input, and the HID descriptor is not able to be processed by
> the driver. The driver generates an "Unknown device_type" warning and
> then returns an error code from wacom_probe(). This is a problem because
> userspace still needs to be able to interact with the device via hidraw
> to perform the firmware flash.
>
> This commit adds a non-generic device definition for 056a:0094 which
> is used when devices are in "bootloader" mode. It marks the devices
> with a special BOOTLOADER type that is recognized by wacom_probe() and
> wacom_raw_event(). When we see this type we ensure a hidraw device is
> created and otherwise keep our hands off so that userspace is in full
> control.
>
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> Tested-by: Tatsunosuke Tobita <tatsunosuke.tobita@wacom.com>
> Cc: <stable@vger.kernel.org>
> ---
>  drivers/hid/wacom_sys.c | 8 ++++++++
>  drivers/hid/wacom_wac.c | 4 ++++
>  drivers/hid/wacom_wac.h | 1 +
>  3 files changed, 13 insertions(+)
>
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 634263e4556b..fb538a6c4add 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -155,6 +155,9 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
>  {
>         struct wacom *wacom = hid_get_drvdata(hdev);
>
> +       if (wacom->wacom_wac.features.type == BOOTLOADER)
> +               return 0;
> +
>         if (size > WACOM_PKGLEN_MAX)
>                 return 1;
>
> @@ -2785,6 +2788,11 @@ static int wacom_probe(struct hid_device *hdev,
>                 return error;
>         }
>
> +       if (features->type == BOOTLOADER) {
> +               hid_warn(hdev, "Using device in hidraw-only mode");
> +               return hid_hw_start(hdev, HID_CONNECT_HIDRAW);
> +       }
> +
>         error = wacom_parse_and_register(wacom, false);
>         if (error)
>                 return error;
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 0f3d57b42684..9312d611db8e 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -4882,6 +4882,9 @@ static const struct wacom_features wacom_features_0x3dd =
>  static const struct wacom_features wacom_features_HID_ANY_ID =
>         { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
>
> +static const struct wacom_features wacom_features_0x94 =
> +       { "Wacom Bootloader", .type = BOOTLOADER };
> +
>  #define USB_DEVICE_WACOM(prod)                                         \
>         HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
>         .driver_data = (kernel_ulong_t)&wacom_features_##prod
> @@ -4955,6 +4958,7 @@ const struct hid_device_id wacom_ids[] = {
>         { USB_DEVICE_WACOM(0x84) },
>         { USB_DEVICE_WACOM(0x90) },
>         { USB_DEVICE_WACOM(0x93) },
> +       { USB_DEVICE_WACOM(0x94) },
>         { USB_DEVICE_WACOM(0x97) },
>         { USB_DEVICE_WACOM(0x9A) },
>         { USB_DEVICE_WACOM(0x9F) },
> diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
> index 5ca6c06d143b..16f221388563 100644
> --- a/drivers/hid/wacom_wac.h
> +++ b/drivers/hid/wacom_wac.h
> @@ -243,6 +243,7 @@ enum {
>         MTTPC,
>         MTTPC_B,
>         HID_GENERIC,
> +       BOOTLOADER,
>         MAX_TYPE
>  };
>
> --
> 2.38.1
>
Haven't seen any action on this so sending it out again.

Jason
---
Now instead of four in the eights place /
you’ve got three, ‘Cause you added one  /
(That is to say, eight) to the two,     /
But you can’t take seven from three,    /
So you look at the sixty-fours....
Jiri Kosina Dec. 20, 2022, 2:29 p.m. UTC | #2
On Thu, 1 Dec 2022, Jason Gerecke wrote:

> From: Jason Gerecke <killertofu@gmail.com>
> 
> Some Wacom devices have a special "bootloader" mode that is used for
> firmware flashing. When operating in this mode, the device cannot be
> used for input, and the HID descriptor is not able to be processed by
> the driver. The driver generates an "Unknown device_type" warning and
> then returns an error code from wacom_probe(). This is a problem because
> userspace still needs to be able to interact with the device via hidraw
> to perform the firmware flash.
> 
> This commit adds a non-generic device definition for 056a:0094 which
> is used when devices are in "bootloader" mode. It marks the devices
> with a special BOOTLOADER type that is recognized by wacom_probe() and
> wacom_raw_event(). When we see this type we ensure a hidraw device is
> created and otherwise keep our hands off so that userspace is in full
> control.
> 
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> Tested-by: Tatsunosuke Tobita <tatsunosuke.tobita@wacom.com>
> Cc: <stable@vger.kernel.org>

Applied, thanks.
diff mbox series

Patch

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 634263e4556b..fb538a6c4add 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -155,6 +155,9 @@  static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
 {
 	struct wacom *wacom = hid_get_drvdata(hdev);
 
+	if (wacom->wacom_wac.features.type == BOOTLOADER)
+		return 0;
+
 	if (size > WACOM_PKGLEN_MAX)
 		return 1;
 
@@ -2785,6 +2788,11 @@  static int wacom_probe(struct hid_device *hdev,
 		return error;
 	}
 
+	if (features->type == BOOTLOADER) {
+		hid_warn(hdev, "Using device in hidraw-only mode");
+		return hid_hw_start(hdev, HID_CONNECT_HIDRAW);
+	}
+
 	error = wacom_parse_and_register(wacom, false);
 	if (error)
 		return error;
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
index 0f3d57b42684..9312d611db8e 100644
--- a/drivers/hid/wacom_wac.c
+++ b/drivers/hid/wacom_wac.c
@@ -4882,6 +4882,9 @@  static const struct wacom_features wacom_features_0x3dd =
 static const struct wacom_features wacom_features_HID_ANY_ID =
 	{ "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
 
+static const struct wacom_features wacom_features_0x94 =
+	{ "Wacom Bootloader", .type = BOOTLOADER };
+
 #define USB_DEVICE_WACOM(prod)						\
 	HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
 	.driver_data = (kernel_ulong_t)&wacom_features_##prod
@@ -4955,6 +4958,7 @@  const struct hid_device_id wacom_ids[] = {
 	{ USB_DEVICE_WACOM(0x84) },
 	{ USB_DEVICE_WACOM(0x90) },
 	{ USB_DEVICE_WACOM(0x93) },
+	{ USB_DEVICE_WACOM(0x94) },
 	{ USB_DEVICE_WACOM(0x97) },
 	{ USB_DEVICE_WACOM(0x9A) },
 	{ USB_DEVICE_WACOM(0x9F) },
diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
index 5ca6c06d143b..16f221388563 100644
--- a/drivers/hid/wacom_wac.h
+++ b/drivers/hid/wacom_wac.h
@@ -243,6 +243,7 @@  enum {
 	MTTPC,
 	MTTPC_B,
 	HID_GENERIC,
+	BOOTLOADER,
 	MAX_TYPE
 };