From: Benjamin Valentin <benpicco@googlemail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>, linux-input@vger.kernel.org
Cc: Lee Jones <lee.jones@linaro.org>, lawl <github@dumbinter.net>
Subject: [PATCH] Input: xpad - Poweroff XBOX360W on mode button long press
Date: Sat, 13 Nov 2021 14:11:55 +0100 [thread overview]
Message-ID: <20211113141155.26217b44@rechenknecht2k11> (raw)
Newer gamepads turn themselves off when the mode button is held down.
For XBOX360W gamepads we must do this in the driver.
Power off the gamepad after 2s of holding down the button.
Signed-off-by: lawl <github@dumbinter.net>
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
---
drivers/input/joystick/xpad.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 18caaf436ed4..e36c4b0abd4b 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -619,11 +619,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; /* timestamp when mode button was pressed */
};
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
@@ -775,6 +777,24 @@ 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
+ /* send power off after 2s of holding the button */
+ && (ktime_get_seconds() - xpad->mode_btn_down_ts) >= 2) {
+ 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)
--
2.32.0
next reply other threads:[~2021-11-13 13:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-13 13:11 Benjamin Valentin [this message]
2021-11-14 1:52 ` [PATCH] Input: xpad - Poweroff XBOX360W on mode button long press Cameron Gutman
2021-11-14 19:23 ` [PATCH v2] " Benjamin Valentin
2021-11-16 16:23 ` [PATCH 1/2] Input: xpad - name unknown gamepads according to device type Benjamin Valentin
2021-11-16 16:25 ` [PATCH 2/2] Input: xpad - drop checks for XTYPE_UNKNOWN Benjamin Valentin
2022-01-05 11:53 ` [RESEND][PATCH v2] Input: xpad - Poweroff XBOX360W on mode button long press Benjamin Valentin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211113141155.26217b44@rechenknecht2k11 \
--to=benpicco@googlemail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=github@dumbinter.net \
--cc=lee.jones@linaro.org \
--cc=linux-input@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).