diff mbox series

[3/3] Input: xpad - Poweroff XBOX360W on mode button long press

Message ID 20220417161526.138019-4-rojtberg@gmail.com (mailing list archive)
State Superseded
Headers show
Series Input: xpad - sync with github fork | expand

Commit Message

Pavel Rojtberg April 17, 2022, 4:15 p.m. UTC
From: Pavel Rojtberg <rojtberg@gmail.com>

Newer gamepads turn themselves off when the mode button is held down.
For XBOX360W gamepads we must do this this in the driver.

Signed-off-by: lawl <github@dumbinter.net>
Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
---
 drivers/input/joystick/xpad.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Greg Kroah-Hartman April 18, 2022, 6:18 a.m. UTC | #1
On Sun, Apr 17, 2022 at 06:15:26PM +0200, Pavel Rojtberg wrote:
> From: Pavel Rojtberg <rojtberg@gmail.com>

Wait, who wrote this, "lawl" or you?


> Newer gamepads turn themselves off when the mode button is held down.
> For XBOX360W gamepads we must do this this in the driver.
> 
> Signed-off-by: lawl <github@dumbinter.net>

We need a real name here please.

> Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
> ---
>  drivers/input/joystick/xpad.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
> index 7640cbb..a9894a6 100644
> --- a/drivers/input/joystick/xpad.c
> +++ b/drivers/input/joystick/xpad.c
> @@ -620,11 +620,13 @@ struct usb_xpad {
>  	int pad_nr;			/* the order x360 pads were attached */
>  	const char *name;		/* name of the device */
>  	struct work_struct work;	/* init/remove device from callback */
> +	time64_t mode_btn_down_ts;
>  };
>  
>  static int xpad_init_input(struct usb_xpad *xpad);
>  static void xpad_deinit_input(struct usb_xpad *xpad);
>  static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
> +static void xpad360w_poweroff_controller(struct usb_xpad *xpad);
>  
>  /*
>   *	xpad_process_packet
> @@ -776,6 +778,23 @@ static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
>  	}
>  
>  	input_sync(dev);
> +
> +	/* XBOX360W controllers can't be turned off without driver assistance */
> +	if (xpad->xtype == XTYPE_XBOX360W) {
> +		if (xpad->mode_btn_down_ts > 0
> +		&& xpad->pad_present
> +		&& (ktime_get_seconds() - xpad->mode_btn_down_ts) >= 5) {

Did you run this through checkpatch?  Please indent properly and put the
"&&" on the end of the lines.

And what does "5" mean here?

> +			xpad360w_poweroff_controller(xpad);
> +			xpad->mode_btn_down_ts = 0;
> +			return;
> +		}
> +
> +		/* mode button down/up */
> +		if (data[3] & 0x04)

BIT(2)?

thanks,

greg k-h
Santosh De Massari April 18, 2022, 6:45 a.m. UTC | #2
On Mon, Apr 18, 2022 at 08:18, Greg KH <gregkh@linuxfoundation.org> 
wrote:
> On Sun, Apr 17, 2022 at 06:15:26PM +0200, Pavel Rojtberg wrote:
>>  From: Pavel Rojtberg <rojtberg@gmail.com>
> 
> Wait, who wrote this, "lawl" or you?

I wrote this. Santosh De Massari. But I never submitted it to LKML
because e-mail sounded too hard and the LKML too scary. Apologies
in advance for any misconfigured mail client etc. on my side.

If Pavel or anyone else wants to get this patch merged, they're
more than welcome to from my side.


> 
>>  Newer gamepads turn themselves off when the mode button is held 
>> down.
>>  For XBOX360W gamepads we must do this this in the driver.
>> 
>>  Signed-off-by: lawl <github@dumbinter.net>
> 
> We need a real name here please.

You can use Santosh De Massari <s.demassari@gmail.com>

> 
>>  Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
>>  ---
>>   drivers/input/joystick/xpad.c | 19 +++++++++++++++++++
>>   1 file changed, 19 insertions(+)
>> 
>>  diff --git a/drivers/input/joystick/xpad.c 
>> b/drivers/input/joystick/xpad.c
>>  index 7640cbb..a9894a6 100644
>>  --- a/drivers/input/joystick/xpad.c
>>  +++ b/drivers/input/joystick/xpad.c
>>  @@ -620,11 +620,13 @@ struct usb_xpad {
>>   	int pad_nr;			/* the order x360 pads were attached */
>>   	const char *name;		/* name of the device */
>>   	struct work_struct work;	/* init/remove device from callback */
>>  +	time64_t mode_btn_down_ts;
>>   };
>> 
>>   static int xpad_init_input(struct usb_xpad *xpad);
>>   static void xpad_deinit_input(struct usb_xpad *xpad);
>>   static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 
>> seq_num);
>>  +static void xpad360w_poweroff_controller(struct usb_xpad *xpad);
>> 
>>   /*
>>    *	xpad_process_packet
>>  @@ -776,6 +778,23 @@ static void xpad360_process_packet(struct 
>> usb_xpad *xpad, struct input_dev *dev,
>>   	}
>> 
>>   	input_sync(dev);
>>  +
>>  +	/* XBOX360W controllers can't be turned off without driver 
>> assistance */
>>  +	if (xpad->xtype == XTYPE_XBOX360W) {
>>  +		if (xpad->mode_btn_down_ts > 0
>>  +		&& xpad->pad_present
>>  +		&& (ktime_get_seconds() - xpad->mode_btn_down_ts) >= 5) {
> 
> Did you run this through checkpatch?  Please indent properly and put 
> the
> "&&" on the end of the lines.
> 
> And what does "5" mean here?

Assuming Pavel will take care of this, but since I'm replying anyways. 
Seconds.
Chosen arbitrarily.

> 
>>  +			xpad360w_poweroff_controller(xpad);
>>  +			xpad->mode_btn_down_ts = 0;
>>  +			return;
>>  +		}
>>  +
>>  +		/* mode button down/up */
>>  +		if (data[3] & 0x04)
> 
> BIT(2)?
> 
> thanks,
> 
> greg k-h
Greg Kroah-Hartman April 18, 2022, 6:58 a.m. UTC | #3
On Mon, Apr 18, 2022 at 08:45:53AM +0200, Santosh De Massari wrote:
> 
> 
> On Mon, Apr 18, 2022 at 08:18, Greg KH <gregkh@linuxfoundation.org> wrote:
> > On Sun, Apr 17, 2022 at 06:15:26PM +0200, Pavel Rojtberg wrote:
> > >  From: Pavel Rojtberg <rojtberg@gmail.com>
> > 
> > Wait, who wrote this, "lawl" or you?
> 
> I wrote this. Santosh De Massari. But I never submitted it to LKML
> because e-mail sounded too hard and the LKML too scary. Apologies
> in advance for any misconfigured mail client etc. on my side.
> 
> If Pavel or anyone else wants to get this patch merged, they're
> more than welcome to from my side.
> 
> 
> > 
> > >  Newer gamepads turn themselves off when the mode button is held
> > > down.
> > >  For XBOX360W gamepads we must do this this in the driver.
> > > 
> > >  Signed-off-by: lawl <github@dumbinter.net>
> > 
> > We need a real name here please.
> 
> You can use Santosh De Massari <s.demassari@gmail.com>

Wonderful, thanks!

> > >  Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
> > >  ---
> > >   drivers/input/joystick/xpad.c | 19 +++++++++++++++++++
> > >   1 file changed, 19 insertions(+)
> > > 
> > >  diff --git a/drivers/input/joystick/xpad.c
> > > b/drivers/input/joystick/xpad.c
> > >  index 7640cbb..a9894a6 100644
> > >  --- a/drivers/input/joystick/xpad.c
> > >  +++ b/drivers/input/joystick/xpad.c
> > >  @@ -620,11 +620,13 @@ struct usb_xpad {
> > >   	int pad_nr;			/* the order x360 pads were attached */
> > >   	const char *name;		/* name of the device */
> > >   	struct work_struct work;	/* init/remove device from callback */
> > >  +	time64_t mode_btn_down_ts;
> > >   };
> > > 
> > >   static int xpad_init_input(struct usb_xpad *xpad);
> > >   static void xpad_deinit_input(struct usb_xpad *xpad);
> > >   static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8
> > > seq_num);
> > >  +static void xpad360w_poweroff_controller(struct usb_xpad *xpad);
> > > 
> > >   /*
> > >    *	xpad_process_packet
> > >  @@ -776,6 +778,23 @@ static void xpad360_process_packet(struct
> > > usb_xpad *xpad, struct input_dev *dev,
> > >   	}
> > > 
> > >   	input_sync(dev);
> > >  +
> > >  +	/* XBOX360W controllers can't be turned off without driver
> > > assistance */
> > >  +	if (xpad->xtype == XTYPE_XBOX360W) {
> > >  +		if (xpad->mode_btn_down_ts > 0
> > >  +		&& xpad->pad_present
> > >  +		&& (ktime_get_seconds() - xpad->mode_btn_down_ts) >= 5) {
> > 
> > Did you run this through checkpatch?  Please indent properly and put the
> > "&&" on the end of the lines.
> > 
> > And what does "5" mean here?
> 
> Assuming Pavel will take care of this, but since I'm replying anyways.
> Seconds.
> Chosen arbitrarily.

Then perhaps a #define somewhere saying this would be good for when in
the future it has to be changed :)

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 7640cbb..a9894a6 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -620,11 +620,13 @@  struct usb_xpad {
 	int pad_nr;			/* the order x360 pads were attached */
 	const char *name;		/* name of the device */
 	struct work_struct work;	/* init/remove device from callback */
+	time64_t mode_btn_down_ts;
 };
 
 static int xpad_init_input(struct usb_xpad *xpad);
 static void xpad_deinit_input(struct usb_xpad *xpad);
 static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
+static void xpad360w_poweroff_controller(struct usb_xpad *xpad);
 
 /*
  *	xpad_process_packet
@@ -776,6 +778,23 @@  static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
 	}
 
 	input_sync(dev);
+
+	/* XBOX360W controllers can't be turned off without driver assistance */
+	if (xpad->xtype == XTYPE_XBOX360W) {
+		if (xpad->mode_btn_down_ts > 0
+		&& xpad->pad_present
+		&& (ktime_get_seconds() - xpad->mode_btn_down_ts) >= 5) {
+			xpad360w_poweroff_controller(xpad);
+			xpad->mode_btn_down_ts = 0;
+			return;
+		}
+
+		/* mode button down/up */
+		if (data[3] & 0x04)
+			xpad->mode_btn_down_ts = ktime_get_seconds();
+		else
+			xpad->mode_btn_down_ts = 0;
+	}
 }
 
 static void xpad_presence_work(struct work_struct *work)