From patchwork Sun Nov 14 19:23:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Valentin X-Patchwork-Id: 12618079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41E39C433EF for ; Sun, 14 Nov 2021 19:23:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12FF96112E for ; Sun, 14 Nov 2021 19:23:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233136AbhKNT0f (ORCPT ); Sun, 14 Nov 2021 14:26:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236157AbhKNT0a (ORCPT ); Sun, 14 Nov 2021 14:26:30 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0F15C061746 for ; Sun, 14 Nov 2021 11:23:33 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id c8so61617560ede.13 for ; Sun, 14 Nov 2021 11:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=msm4RixDwEFMfe+7jyY/ubZlcJMsRCU7XocB5DrglG4=; b=WGR4HMjvoCm4Krb9bPDEX/EwRdcBGcnBSk3pX0WPbUZvRFLdiXT8JUn65nWp5XMzTl hk4r2zKlvlPBO7csopT4ME2/CHTgeTG7qrc1AKfYpUabe0LeDJ43RTRjp8878SMhOpO0 +S1ktknpZ+kXdJtbgHj33CUEgz40reJ7BQzjBIUZutSCABHzxBrgNsGUE2F8S8PPsUM2 7L+T8XZxPMP9puPV/4SRSB6b7MGgJCFdc09zmG0Cp7y1x+YgTM+e0mrqMoGgUYOc1yBz 0OKavacF2X2Kuj9ni633FaEBpd08gnSwIkSRt3yBhetsx2EtBcQiGS+flFl29QauZ3d/ 8nHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=msm4RixDwEFMfe+7jyY/ubZlcJMsRCU7XocB5DrglG4=; b=V69xgRDMEiJvBh2nSljaKuzjHQ1AlSXAWtv0Rwevmz7NT1l8mD6vQ5m4ImumEcg8QO od42xp8pQ4QlX1bUitZmzuXJZSm1i0J+Oc6u2glYQdYnnceDA9QQKajAfCkw9/29vAvi ynTXzbfhwBEQ73BXQFv663HDa+rS9K3H5GtjX0M9YlFKLD4TMXGZ43PXJqiunoHWLdT4 JRnq04HPJ1NLw8gr6OLGP9STmfAzxva3MPM6HUtnAZ1XICswOFkUThA2t5PGro0TtkBf SIbkmeS6S+hW4kH1I8n3l5Zps2VQoVSx/pdmeePgfAJE+iGE6TIRmHMkWtjwSD79Fbi9 0rIQ== X-Gm-Message-State: AOAM532f+weoP/rfi/yltZLSWt+BJphBCgClD5BUgJ+YI4FgiCHjgUf5 5HDLCWlnJw51lPb/Sn6NmLI= X-Google-Smtp-Source: ABdhPJyiASH7reQvNA4EfR2HjVC0nMHrXbojU2mu/nYpTbCs4b3hrASHqrlpWLCdrMzdH7taH4BSOg== X-Received: by 2002:a17:907:7d94:: with SMTP id oz20mr43970093ejc.410.1636917812192; Sun, 14 Nov 2021 11:23:32 -0800 (PST) Received: from rechenknecht2k11 (200116b8456c370014a1cb2603939609.dip.versatel-1u1.de. [2001:16b8:456c:3700:14a1:cb26:393:9609]) by smtp.googlemail.com with ESMTPSA id u14sm6180078edj.74.2021.11.14.11.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Nov 2021 11:23:32 -0800 (PST) Date: Sun, 14 Nov 2021 20:23:29 +0100 From: Benjamin Valentin To: Cameron Gutman Cc: Dmitry Torokhov , linux-input@vger.kernel.org, Lee Jones , lawl Subject: [PATCH v2] Input: xpad - Poweroff XBOX360W on mode button long press Message-ID: <20211114202329.5745bb26@rechenknecht2k11> In-Reply-To: <3b25f4b1-3ec0-0878-99bc-0da06ce7c2f2@gmail.com> References: <20211113141155.26217b44@rechenknecht2k11> <3b25f4b1-3ec0-0878-99bc-0da06ce7c2f2@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 5s of holding down the button. Signed-off-by: lawl Signed-off-by: Benjamin Valentin --- Changed the timeout back to 5s 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 5s of holding the button */ + && (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) From patchwork Tue Nov 16 16:25:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Valentin X-Patchwork-Id: 12622887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE478C433F5 for ; Tue, 16 Nov 2021 16:25:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD38F61452 for ; Tue, 16 Nov 2021 16:25:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231945AbhKPQ2I (ORCPT ); Tue, 16 Nov 2021 11:28:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231539AbhKPQ2H (ORCPT ); Tue, 16 Nov 2021 11:28:07 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B85EC061570 for ; Tue, 16 Nov 2021 08:25:10 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id az33-20020a05600c602100b00333472fef04so2453935wmb.5 for ; Tue, 16 Nov 2021 08:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Djf41xld+0ekM1PIg4SaeNny1ar0p7PgqRVxFha8Hnk=; b=nH9WnJ3jEso0D4JtEx8L2E1L3tPQG4c//LoAmy0IDOpbJgfdxEPNjxbwakliRIQ2u3 BqFG/Ve/av7T3o1Pw975PqatjEv6TEGQO140H3G3v8Du84Hyja/0uS9CRfbkq/TZEAJz fxjVCtXmaLCDvoI0gg/luWzVSS0221eJIWT3XYZhEis9ocllb31N8ibCpXmY5kbqjAb/ quYbQU+wBOf/GeSwhuaMf4wpntaXrGbr5K255rnaLIgvNkpAPe0d6+YRGjP5TiGWENHN nNVm81PC4rFE1IpW6rYwBGtengfxTF56n1nw26VC1XBU4Qb4mUqxNmI+0CYaY0nsg9iY 2drw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Djf41xld+0ekM1PIg4SaeNny1ar0p7PgqRVxFha8Hnk=; b=BUNfOF0NCAIg1cafgTNGytRe/lp2gu+m8sb7YyjB7Yt47RpopmdK5dtkC5+UM7BOzP YIurhAL5aRnZohTsImQgjct3zGhsB03DNkHMs9ll2muH30MrcuIipRfzqWpEpX/tpqaW yBIq+g4jih/CGFMknQRtrHwMMT9Qk8aepS04WI2Zjhx6w13ZOWC5tuwVH2JXXMI8njZE +L/0+d8q6b4+c8Vp2xqI7yUOGg+EmdpOB83pe8irMxK6XWxgHqsuXSNfD3ge1fOUo+lC P5Yu/9mzPXCLkGE0W4pGK4Vh7M++KSF3x7hofDVC4q3cLR8FlJspkvDyapTiUe5Mkf8f Q90A== X-Gm-Message-State: AOAM532DNobKgFEgv6sUb8Xs4USqLsp6Ly5ORgD8DMyJV9BLo0ZhWtJT TJbWSZGXuU5QUWEZxXHjazY= X-Google-Smtp-Source: ABdhPJz41jku3CpjOZ8o/zPZv3evHUlSOUeD8gOsHlWkIkZiS/Uh5AClfwZOAJQwE8NV6k9mQHd06g== X-Received: by 2002:a7b:c5d8:: with SMTP id n24mr9701870wmk.51.1637079908625; Tue, 16 Nov 2021 08:25:08 -0800 (PST) Received: from rechenknecht2k11 (200116b8459a9b003f00a60854fcf5ee.dip.versatel-1u1.de. [2001:16b8:459a:9b00:3f00:a608:54fc:f5ee]) by smtp.googlemail.com with ESMTPSA id 9sm23419825wry.0.2021.11.16.08.25.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 08:25:08 -0800 (PST) Date: Tue, 16 Nov 2021 17:25:06 +0100 From: Benjamin Valentin To: Cameron Gutman Cc: Dmitry Torokhov , linux-input@vger.kernel.org, Lee Jones Subject: [PATCH 2/2] Input: xpad - drop checks for XTYPE_UNKNOWN Message-ID: <20211116172506.234dbf1d@rechenknecht2k11> In-Reply-To: <3b25f4b1-3ec0-0878-99bc-0da06ce7c2f2@gmail.com> References: <20211113141155.26217b44@rechenknecht2k11> <3b25f4b1-3ec0-0878-99bc-0da06ce7c2f2@gmail.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org If xtype is XTYPE_UNKNOWN, it will *always* be replaced by the real detected type in xpad_probe(). It is therefore not possible to encounter the xtype == XTYPE_UNKNOWN condition anywhere at the run-time of the driver. That means we can drop those checks. Signed-off-by: Benjamin Valentin --- drivers/input/joystick/xpad.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 31a268f43b5b..66a12da58619 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -1110,13 +1110,10 @@ static void xpad_irq_out(struct urb *urb) } static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, - struct usb_endpoint_descriptor *ep_irq_out) + struct usb_endpoint_descriptor *ep_irq_out) { int error; - if (xpad->xtype == XTYPE_UNKNOWN) - return 0; - init_usb_anchor(&xpad->irq_out_anchor); xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, @@ -1148,23 +1145,19 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, static void xpad_stop_output(struct usb_xpad *xpad) { - if (xpad->xtype != XTYPE_UNKNOWN) { - if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, - 5000)) { - dev_warn(&xpad->intf->dev, - "timed out waiting for output URB to complete, killing\n"); - usb_kill_anchored_urbs(&xpad->irq_out_anchor); - } + if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor, + 5000)) { + dev_warn(&xpad->intf->dev, + "timed out waiting for output URB to complete, killing\n"); + usb_kill_anchored_urbs(&xpad->irq_out_anchor); } } static void xpad_deinit_output(struct usb_xpad *xpad) { - if (xpad->xtype != XTYPE_UNKNOWN) { - usb_free_urb(xpad->irq_out); - usb_free_coherent(xpad->udev, XPAD_PKT_LEN, - xpad->odata, xpad->odata_dma); - } + usb_free_urb(xpad->irq_out); + usb_free_coherent(xpad->udev, XPAD_PKT_LEN, + xpad->odata, xpad->odata_dma); } static int xpad_inquiry_pad_presence(struct usb_xpad *xpad) @@ -1339,9 +1332,6 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect static int xpad_init_ff(struct usb_xpad *xpad) { - if (xpad->xtype == XTYPE_UNKNOWN) - return 0; - input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); return input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);