diff mbox series

HID: Add 044f:b320 ThrustMaster, Inc. 2 in 1 DT

Message ID 20190624152816.xbo2oqyviqbrpkur@lahvuun.homenetwork (mailing list archive)
State Superseded
Delegated to: Jiri Kosina
Headers show
Series HID: Add 044f:b320 ThrustMaster, Inc. 2 in 1 DT | expand

Commit Message

Ilya Trukhanov June 24, 2019, 3:28 p.m. UTC
Enable force feedback for the Thrustmaster Dual Trigger 2 in 1 Rumble Force
gamepad. Compared to other Thrustmaster devices, left and right rumble
motors here are swapped.

Signed-off-by: Ilya Trukhanov <lahvuun@protonmail.com>
---
 drivers/hid/hid-quirks.c |  1 +
 drivers/hid/hid-tmff.c   | 10 ++++++++++
 2 files changed, 11 insertions(+)

Comments

Benjamin Tissoires July 2, 2019, 8:24 a.m. UTC | #1
Hi Ilya,

On Mon, Jun 24, 2019 at 5:28 PM Ilya Trukhanov <lahvuun@gmail.com> wrote:
>
> Enable force feedback for the Thrustmaster Dual Trigger 2 in 1 Rumble Force
> gamepad. Compared to other Thrustmaster devices, left and right rumble
> motors here are swapped.
>
> Signed-off-by: Ilya Trukhanov <lahvuun@protonmail.com>
> ---
>  drivers/hid/hid-quirks.c |  1 +
>  drivers/hid/hid-tmff.c   | 10 ++++++++++
>  2 files changed, 11 insertions(+)
>
> diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
> index e5ca6fe2ca57..7408a4759b35 100644
> --- a/drivers/hid/hid-quirks.c
> +++ b/drivers/hid/hid-quirks.c
> @@ -638,6 +638,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
>  #if IS_ENABLED(CONFIG_HID_THRUSTMASTER)
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320) },

You should be able to drop this hunk from the patch.

>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605) },
> diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
> index e12f2588ddeb..78b931d8617f 100644
> --- a/drivers/hid/hid-tmff.c
> +++ b/drivers/hid/hid-tmff.c
> @@ -76,6 +76,7 @@ static int tmff_play(struct input_dev *dev, void *data,
>         struct hid_field *ff_field = tmff->ff_field;
>         int x, y;
>         int left, right;        /* Rumbling */
> +       int motor_swap;
>
>         switch (effect->type) {
>         case FF_CONSTANT:
> @@ -100,6 +101,13 @@ static int tmff_play(struct input_dev *dev, void *data,
>                                         ff_field->logical_minimum,
>                                         ff_field->logical_maximum);
>
> +               /* 2-in-1 strong motor is left */
> +               if (hid->product == 0xb320) {

I think we better have a (local) #define for the PID here. You are
reusing it below.

Cheers,
Benjamin

> +                       motor_swap = left;
> +                       left = right;
> +                       right = motor_swap;
> +               }
> +
>                 dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
>                 ff_field->value[0] = left;
>                 ff_field->value[1] = right;
> @@ -226,6 +234,8 @@ static const struct hid_device_id tm_devices[] = {
>                 .driver_data = (unsigned long)ff_rumble },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),   /* FireStorm Dual Power 2 (and 3) */
>                 .driver_data = (unsigned long)ff_rumble },
> +       { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320),   /* Dual Trigger 2-in-1 */
> +               .driver_data = (unsigned long)ff_rumble },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323),   /* Dual Trigger 3-in-1 (PC Mode) */
>                 .driver_data = (unsigned long)ff_rumble },
>         { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324),   /* Dual Trigger 3-in-1 (PS3 Mode) */
> --
> 2.22.0
>
Ilya Trukhanov July 2, 2019, 10:45 a.m. UTC | #2
Hello Benjamin,

Thank you for taking the time to reply.

I've sent the v2 patch with the following changes:

diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index 7408a4759b35..e5ca6fe2ca57 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -638,7 +638,6 @@ static const struct hid_device_id hid_have_special_driver[] = {
 #if IS_ENABLED(CONFIG_HID_THRUSTMASTER)
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605) },
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
index 78b931d8617f..bdfc5ff3b2c5 100644
--- a/drivers/hid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -22,6 +22,8 @@
 
 #include "hid-ids.h"
 
+#define THRUSTMASTER_DEVICE_ID_2_IN_1_DT	0xb320
+
 static const signed short ff_rumble[] = {
 	FF_RUMBLE,
 	-1
@@ -102,7 +104,7 @@ static int tmff_play(struct input_dev *dev, void *data,
 					ff_field->logical_maximum);
 
 		/* 2-in-1 strong motor is left */
-		if (hid->product == 0xb320) {
+		if (hid->product == THRUSTMASTER_DEVICE_ID_2_IN_1_DT) {
 			motor_swap = left;
 			left = right;
 			right = motor_swap;
@@ -234,7 +236,7 @@ static const struct hid_device_id tm_devices[] = {
 		.driver_data = (unsigned long)ff_rumble },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),   /* FireStorm Dual Power 2 (and 3) */
 		.driver_data = (unsigned long)ff_rumble },
-	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320),   /* Dual Trigger 2-in-1 */
+	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, THRUSTMASTER_DEVICE_ID_2_IN_1_DT),   /* Dual Trigger 2-in-1 */
 		.driver_data = (unsigned long)ff_rumble },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323),   /* Dual Trigger 3-in-1 (PC Mode) */
 		.driver_data = (unsigned long)ff_rumble },
diff mbox series

Patch

diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
index e5ca6fe2ca57..7408a4759b35 100644
--- a/drivers/hid/hid-quirks.c
+++ b/drivers/hid/hid-quirks.c
@@ -638,6 +638,7 @@  static const struct hid_device_id hid_have_special_driver[] = {
 #if IS_ENABLED(CONFIG_HID_THRUSTMASTER)
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb605) },
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
index e12f2588ddeb..78b931d8617f 100644
--- a/drivers/hid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -76,6 +76,7 @@  static int tmff_play(struct input_dev *dev, void *data,
 	struct hid_field *ff_field = tmff->ff_field;
 	int x, y;
 	int left, right;	/* Rumbling */
+	int motor_swap;
 
 	switch (effect->type) {
 	case FF_CONSTANT:
@@ -100,6 +101,13 @@  static int tmff_play(struct input_dev *dev, void *data,
 					ff_field->logical_minimum,
 					ff_field->logical_maximum);
 
+		/* 2-in-1 strong motor is left */
+		if (hid->product == 0xb320) {
+			motor_swap = left;
+			left = right;
+			right = motor_swap;
+		}
+
 		dbg_hid("(left,right)=(%08x, %08x)\n", left, right);
 		ff_field->value[0] = left;
 		ff_field->value[1] = right;
@@ -226,6 +234,8 @@  static const struct hid_device_id tm_devices[] = {
 		.driver_data = (unsigned long)ff_rumble },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),   /* FireStorm Dual Power 2 (and 3) */
 		.driver_data = (unsigned long)ff_rumble },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb320),   /* Dual Trigger 2-in-1 */
+		.driver_data = (unsigned long)ff_rumble },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb323),   /* Dual Trigger 3-in-1 (PC Mode) */
 		.driver_data = (unsigned long)ff_rumble },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb324),   /* Dual Trigger 3-in-1 (PS3 Mode) */