From patchwork Tue Jul 26 05:35:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Gutman X-Patchwork-Id: 9247637 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D46C60757 for ; Tue, 26 Jul 2016 05:35:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CC3A26223 for ; Tue, 26 Jul 2016 05:35:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EC0A276AE; Tue, 26 Jul 2016 05:35:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05BED26223 for ; Tue, 26 Jul 2016 05:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753685AbcGZFfM (ORCPT ); Tue, 26 Jul 2016 01:35:12 -0400 Received: from mail-pa0-f68.google.com ([209.85.220.68]:36023 "EHLO mail-pa0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752634AbcGZFfL (ORCPT ); Tue, 26 Jul 2016 01:35:11 -0400 Received: by mail-pa0-f68.google.com with SMTP id ez1so12624392pab.3 for ; Mon, 25 Jul 2016 22:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=RPBrvntfqHdnivQfzvLpd3YWPFjQOzFdVcds92rS0nk=; b=ZHwS4CK8ZJs1UaODbG/M/G7wgIo/cMp6zfftOtZRc4K2WJwTtXjwx01CIb68JOmYI8 E7BrQiJ6XC9hca14r1D6Ffq6CNAcIecwfZt/+g9DV8Hr4XJifRA6uohjvBwLt5XbeMDN CdwDTJbJ6ZATMrlbCG3w8C+TNy3e5639fhG85ah7FxMk68tkFXup4W2oHPlMQc2fscXe NKnuflBgJau7VxV/KvFbMH/sL2RHfZz/PqS66MlsGHKfmK4Snxa3uU5Cjo7S9tzFpVvW oGTNJNdGLRRTOhnIiU6pXtrsSpdE2vlvcdi/3eY/hjAiS9bl8cdf2eQ5U3miijnYlNbR fJ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=RPBrvntfqHdnivQfzvLpd3YWPFjQOzFdVcds92rS0nk=; b=JzXusySs25dWEXuD2Pqv+Ti/KsN1FNETWN8q2yTLstLi4JYW63qsaHZq1ukhZwdR/j nmHkzAyFEnzLekdNfOM0riEOAjt0TYEbRvP42Lwtyi4JQeGZLI31eqm/lCtWMq4hg65l 8Z7uOcmsS7aciddZAU0I56/hhsUd+wD3ltWlkPPfdAITHiBYTsGg0+B7Bd3rcaHEARDL ZJoQzkPFvJDU1shoLfZoq0ZSn0uvL6Lk1MXfZrP2OpNYVcnnTNo3qtlxvWKEg5Rc7ooU NLPF8bkRsMTTtXE1fXvKzFdF6h7l4T7byvoxYXc/t9jEdHGsMpZPn+fbLdN96BC63gA4 zKqQ== X-Gm-Message-State: AEkoouv0kaEKFfN6tmD09fESLaWkdWpEOPRdN7lhCrusUlFBj8np6byeGbbVDsD60ecnSw== X-Received: by 10.66.160.41 with SMTP id xh9mr36506020pab.85.1469511310249; Mon, 25 Jul 2016 22:35:10 -0700 (PDT) Received: from [192.168.1.139] (c-24-16-1-64.hsd1.wa.comcast.net. [24.16.1.64]) by smtp.gmail.com with ESMTPSA id t1sm44071382pfa.86.2016.07.25.22.35.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 22:35:09 -0700 (PDT) From: Cameron Gutman Subject: [PATCH] Input: xpad - power off wireless 360 controllers on suspend To: dmitry.torokhov@gmail.com, rojtberg@gmail.com Cc: linux-input@vger.kernel.org Message-ID: <6203d65c-4e15-c44c-edc9-d47cc78f1c28@gmail.com> Date: Mon, 25 Jul 2016 22:35:08 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the USB wireless adapter is suspended, the controllers lose their connection. This causes them to start flashing their LED rings and searching for the wireless adapter again, wasting the controller's battery power. Instead, we will tell the controllers to power down when we suspend. This mirrors the behavior of the controllers when connected to the console itself and how the official Xbox One wireless adapter behaves on Windows. Signed-off-by: Cameron Gutman --- This patch is independent of the other xpad patch [0] that I submitted (and decided to wait on). It applies against unmodified xpad.c in master. [0] http://www.spinics.net/lists/linux-input/msg46062.html --- drivers/input/joystick/xpad.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index a529a45..3408019 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -115,6 +115,10 @@ static bool sticks_to_null; module_param(sticks_to_null, bool, S_IRUGO); MODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads"); +static bool disable_auto_poweroff; +module_param(disable_auto_poweroff, bool, S_IRUGO); +MODULE_PARM_DESC(disable_auto_poweroff, "Do not power off wireless controllers on suspend"); + static const struct xpad_device { u16 idVendor; u16 idProduct; @@ -1248,6 +1252,36 @@ static void xpad_stop_input(struct usb_xpad *xpad) usb_kill_urb(xpad->irq_in); } +static void xpad360w_poweroff_controller(struct usb_xpad *xpad) +{ + unsigned long flags; + struct xpad_output_packet *packet = + &xpad->out_packets[XPAD_OUT_CMD_IDX]; + + spin_lock_irqsave(&xpad->odata_lock, flags); + + packet->data[0] = 0x00; + packet->data[1] = 0x00; + packet->data[2] = 0x08; + packet->data[3] = 0xC0; + packet->data[4] = 0x00; + packet->data[5] = 0x00; + packet->data[6] = 0x00; + packet->data[7] = 0x00; + packet->data[8] = 0x00; + packet->data[9] = 0x00; + packet->data[10] = 0x00; + packet->data[11] = 0x00; + packet->len = 12; + packet->pending = true; + + /* Reset the sequence so we send out poweroff now */ + xpad->last_out_packet = -1; + xpad_try_sending_next_out_packet(xpad); + + spin_unlock_irqrestore(&xpad->odata_lock, flags); +} + static int xpad360w_start_input(struct usb_xpad *xpad) { int error; @@ -1590,6 +1624,15 @@ static int xpad_suspend(struct usb_interface *intf, pm_message_t message) * or goes away. */ xpad360w_stop_input(xpad); + + /* + * The wireless adapter is going off now, so the + * gamepads are going to become disconnected. + * Unless explicitly disabled, power them down + * so they don't just sit there flashing. + */ + if (!disable_auto_poweroff && xpad->pad_present) + xpad360w_poweroff_controller(xpad); } else { mutex_lock(&input->mutex); if (input->users)