Skip to content

Commit

Permalink
Input: xpad - Poweroff XBOX360W on mode button long press
Browse files Browse the repository at this point in the history
Newer gamepads turn themselves off when the mode button is held down.
For XBOX360W gamepads we must do this this in the driver.
  • Loading branch information
lawl authored and paroj committed Jan 22, 2021
1 parent ac102de commit 5978d10
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions xpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,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
Expand Down Expand Up @@ -759,6 +761,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)
Expand Down

1 comment on commit 5978d10

@k8ieone
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH MY GOD! Thank you so much for this!

Please sign in to comment.