diff mbox series

[v3,1/2] HID: sony: add a quirk for SHANWAN PS3 GamePad.

Message ID 20181230105618.11867-2-outmatch@gmail.com (mailing list archive)
State Mainlined
Commit 69481059c507b3b5a99aaab0d544e6516034defc
Delegated to: Jiri Kosina
Headers show
Series Fix SHANWAN PS3 GamePad rumble on USB again | expand

Commit Message

Hongye Yuan Dec. 30, 2018, 10:56 a.m. UTC
- Add a quirk for SHANWAN PS3 GamePad controller.
- Tiny up SHANWAN controller logic to skip output reports.

Signed-off-by: Hongye Yuan <outmatch@gmail.com>
---
 drivers/hid/hid-sony.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

Comments

Bastien Nocera Jan. 7, 2019, 11:37 a.m. UTC | #1
> HID: sony: add a quirk for SHANWAN PS3 GamePad.

Not period at the end of the commit subjet.

On Sun, 2018-12-30 at 18:56 +0800, Hongye Yuan wrote:
> - Add a quirk for SHANWAN PS3 GamePad controller.

You're not adding a quirk, but converting a one-time check into a
driver quirk. Would also be good to explain why you're doing this.

> - Tiny up SHANWAN controller logic to skip output reports.

It's "tidy". But you're not doing this here.

Try this:
HID: sony: Transform one-time SHANWAN check into quirk

Transform the one-time check for a SHANWAN PS3 clone gamepad into a
quirk, to avoid doing the same string comparison in multiple places.


Looks good otherwise.

> Signed-off-by: Hongye Yuan <outmatch@gmail.com>
> ---
>  drivers/hid/hid-sony.c | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
> index 9671a4bad643..fc82f02bae75 100644
> --- a/drivers/hid/hid-sony.c
> +++ b/drivers/hid/hid-sony.c
> @@ -58,6 +58,7 @@
>  #define FUTUREMAX_DANCE_MAT       BIT(13)
>  #define NSG_MR5U_REMOTE_BT        BIT(14)
>  #define NSG_MR7U_REMOTE_BT        BIT(15)
> +#define SHANWAN_GAMEPAD           BIT(16)
>  
>  #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB |
> SIXAXIS_CONTROLLER_BT)
>  #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB |
> MOTION_CONTROLLER_BT)
> @@ -1490,6 +1491,7 @@ static int sony_register_sensors(struct sony_sc
> *sc)
>   */
>  static int sixaxis_set_operational_usb(struct hid_device *hdev)
>  {
> +	struct sony_sc *sc = hid_get_drvdata(hdev);
>  	const int buf_size =
>  		max(SIXAXIS_REPORT_0xF2_SIZE,
> SIXAXIS_REPORT_0xF5_SIZE);
>  	u8 *buf;
> @@ -1519,14 +1521,15 @@ static int sixaxis_set_operational_usb(struct
> hid_device *hdev)
>  
>  	/*
>  	 * But the USB interrupt would cause SHANWAN controllers to
> -	 * start rumbling non-stop.
> +	 * start rumbling non-stop, so skip step 3 for these
> controllers.
>  	 */
> -	if (strcmp(hdev->name, "SHANWAN PS3 GamePad")) {
> -		ret = hid_hw_output_report(hdev, buf, 1);
> -		if (ret < 0) {
> -			hid_info(hdev, "can't set operational mode:
> step 3, ignoring\n");
> -			ret = 0;
> -		}
> +	if (sc->quirks & SHANWAN_GAMEPAD)
> +		goto out;
> +
> +	ret = hid_hw_output_report(hdev, buf, 1);
> +	if (ret < 0) {
> +		hid_info(hdev, "can't set operational mode: step 3,
> ignoring\n");
> +		ret = 0;
>  	}
>  
>  out:
> @@ -2811,6 +2814,9 @@ static int sony_probe(struct hid_device *hdev,
> const struct hid_device_id *id)
>  	if (!strcmp(hdev->name, "FutureMax Dance Mat"))
>  		quirks |= FUTUREMAX_DANCE_MAT;
>  
> +	if (!strcmp(hdev->name, "SHANWAN PS3 GamePad"))
> +		quirks |= SHANWAN_GAMEPAD;
> +
>  	sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
>  	if (sc == NULL) {
>  		hid_err(hdev, "can't alloc sony descriptor\n");
diff mbox series

Patch

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 9671a4bad643..fc82f02bae75 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -58,6 +58,7 @@ 
 #define FUTUREMAX_DANCE_MAT       BIT(13)
 #define NSG_MR5U_REMOTE_BT        BIT(14)
 #define NSG_MR7U_REMOTE_BT        BIT(15)
+#define SHANWAN_GAMEPAD           BIT(16)
 
 #define SIXAXIS_CONTROLLER (SIXAXIS_CONTROLLER_USB | SIXAXIS_CONTROLLER_BT)
 #define MOTION_CONTROLLER (MOTION_CONTROLLER_USB | MOTION_CONTROLLER_BT)
@@ -1490,6 +1491,7 @@  static int sony_register_sensors(struct sony_sc *sc)
  */
 static int sixaxis_set_operational_usb(struct hid_device *hdev)
 {
+	struct sony_sc *sc = hid_get_drvdata(hdev);
 	const int buf_size =
 		max(SIXAXIS_REPORT_0xF2_SIZE, SIXAXIS_REPORT_0xF5_SIZE);
 	u8 *buf;
@@ -1519,14 +1521,15 @@  static int sixaxis_set_operational_usb(struct hid_device *hdev)
 
 	/*
 	 * But the USB interrupt would cause SHANWAN controllers to
-	 * start rumbling non-stop.
+	 * start rumbling non-stop, so skip step 3 for these controllers.
 	 */
-	if (strcmp(hdev->name, "SHANWAN PS3 GamePad")) {
-		ret = hid_hw_output_report(hdev, buf, 1);
-		if (ret < 0) {
-			hid_info(hdev, "can't set operational mode: step 3, ignoring\n");
-			ret = 0;
-		}
+	if (sc->quirks & SHANWAN_GAMEPAD)
+		goto out;
+
+	ret = hid_hw_output_report(hdev, buf, 1);
+	if (ret < 0) {
+		hid_info(hdev, "can't set operational mode: step 3, ignoring\n");
+		ret = 0;
 	}
 
 out:
@@ -2811,6 +2814,9 @@  static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
 	if (!strcmp(hdev->name, "FutureMax Dance Mat"))
 		quirks |= FUTUREMAX_DANCE_MAT;
 
+	if (!strcmp(hdev->name, "SHANWAN PS3 GamePad"))
+		quirks |= SHANWAN_GAMEPAD;
+
 	sc = devm_kzalloc(&hdev->dev, sizeof(*sc), GFP_KERNEL);
 	if (sc == NULL) {
 		hid_err(hdev, "can't alloc sony descriptor\n");