From patchwork Sun Feb 5 00:29:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Gutman X-Patchwork-Id: 9555809 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 04A7260236 for ; Sun, 5 Feb 2017 00:32:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5AD5269DA for ; Sun, 5 Feb 2017 00:32:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAB4526BE9; Sun, 5 Feb 2017 00:32:19 +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=unavailable 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 8E131269DA for ; Sun, 5 Feb 2017 00:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751890AbdBEAbk (ORCPT ); Sat, 4 Feb 2017 19:31:40 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35455 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751821AbdBEAbe (ORCPT ); Sat, 4 Feb 2017 19:31:34 -0500 Received: by mail-pf0-f195.google.com with SMTP id f144so4187844pfa.2; Sat, 04 Feb 2017 16:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=oL+HyHcAba7MBceQPTLqzQRu+1GnkIRg4CCtKRuP1mU=; b=phQ0v9DFujodnpGoiq/zQEe+/ES8Y6hcvfmKcJLZv/p5r86lJ083t9Zh75it6lgqz2 31pJTsVn/hJ5JW+5sViuC6A1LlDTx3xtiZBBFBl/OKdbKQsEHLq3zCdy85FVMHwoMqu3 pM51oXqzYdxOmXX5gpvyhxq3PGSYKMcdWCWOM+vURs7zTRUXgQ1w3JBcGAuShNgXyTwU ATNSXPGFF6Tipe58m9ZdUs99QAZ3k1Hq3P05wJJMZYMxN/TZTZw3pdM1yC41dHR6bjT1 q0juDLiJmTZLOKHgM6KbzM5CeAunAh3RswlWuT9pPAH9lHxti4WJxuZ6mElVWudvtpiU nMRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oL+HyHcAba7MBceQPTLqzQRu+1GnkIRg4CCtKRuP1mU=; b=sC2Qq9fAFc30dTqf8nQe4l0yQKgtGejhJedljCD/MyDbGEkF2YKB0XwsK7NmS0I4jw LsY6GfciC7yugt6tG5skQnv/cT2JOypfOvv55nG/G4fwzB18zxtXsM5Jz9fNTurafwWy 8ZTgb5QfHLjOhifXPzM4SevxL5BdJcCLuaclDDlW+8WXy74Ycfs+vWokBaEc59Ci7WTC 7JlsJyfYCThgFdUimeNjcpsNviX/h+7tRy3EOK/IQWgHbqpogY10xm5Q9807pz2I2t9V 3IGnnTICZDYKXoK7xCzF4xrauJlE2Xx2+ImlfW+7ywsIZNt0jrWqIqAdtg51DauPn1Op KZeg== X-Gm-Message-State: AIkVDXLQleeg+pQ1v1W2Kr6MPoz7paa3/x5a4S7K5yP4Edvo2S0ED27mcVmwUEsj5xRlxw== X-Received: by 10.99.237.17 with SMTP id d17mr5360225pgi.82.1486254693911; Sat, 04 Feb 2017 16:31:33 -0800 (PST) Received: from localhost.localdomain ([174.127.240.168]) by smtp.gmail.com with ESMTPSA id s8sm77744303pfj.30.2017.02.04.16.31.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Feb 2017 16:31:33 -0800 (PST) From: Cameron Gutman To: dmitry.torokhov@gmail.com, rojtberg@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Cameron Gutman Subject: [PATCH 1/5] Input: xpad - use a packet array to start Xbox One pads Date: Sat, 4 Feb 2017 16:29:58 -0800 Message-Id: <20170205003002.28160-2-aicommander@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170205003002.28160-1-aicommander@gmail.com> References: <20170205003002.28160-1-aicommander@gmail.com> 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 This is preparatory work for supporting some 3rd party pads that need more initialization packets than just one. No initialization behavior change expected. Signed-off-by: Cameron Gutman --- drivers/input/joystick/xpad.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 247fd3a..6f07b5b 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -343,6 +343,15 @@ struct xpad_output_packet { bool pending; }; +/* Sequence numbers will be added before the packets are sent */ +static const struct xpad_output_packet xone_init_pkt[] = { + /* + * This packet is required for all Xbox One pads with 2015 + * or later firmware installed (or present from the factory). + */ + {{0x05, 0x20, 0x00, 0x01, 0x00}, 5, true}, +}; + #define XPAD_OUT_CMD_IDX 0 #define XPAD_OUT_FF_IDX 1 #define XPAD_OUT_LED_IDX (1 + IS_ENABLED(CONFIG_JOYSTICK_XPAD_FF)) @@ -373,6 +382,7 @@ struct usb_xpad { struct xpad_output_packet out_packets[XPAD_NUM_OUT_PACKETS]; int last_out_packet; + int init_seq; #if defined(CONFIG_JOYSTICK_XPAD_LEDS) struct xpad_led *led; @@ -742,8 +752,19 @@ static void xpad_irq_in(struct urb *urb) static bool xpad_prepare_next_out_packet(struct usb_xpad *xpad) { struct xpad_output_packet *pkt, *packet = NULL; + const struct xpad_output_packet *init_packet; int i; + if (xpad->xtype == XTYPE_XBOXONE && xpad->init_seq < ARRAY_SIZE(xone_init_pkt)) { + init_packet = &xone_init_pkt[xpad->init_seq++]; + memcpy(xpad->odata, init_packet->data, init_packet->len); + xpad->irq_out->transfer_buffer_length = init_packet->len; + + /* Update packet with current sequence number */ + xpad->odata[2] = xpad->odata_serial++; + return true; + } + for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) { if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS) xpad->last_out_packet = 0; @@ -929,24 +950,17 @@ static int xpad_inquiry_pad_presence(struct usb_xpad *xpad) static int xpad_start_xbox_one(struct usb_xpad *xpad) { - struct xpad_output_packet *packet = - &xpad->out_packets[XPAD_OUT_CMD_IDX]; unsigned long flags; int retval; spin_lock_irqsave(&xpad->odata_lock, flags); - /* Xbox one controller needs to be initialized. */ - packet->data[0] = 0x05; - packet->data[1] = 0x20; - packet->data[2] = xpad->odata_serial++; /* packet serial */ - packet->data[3] = 0x01; /* rumble bit enable? */ - packet->data[4] = 0x00; - packet->len = 5; - packet->pending = true; - - /* Reset the sequence so we send out start packet first */ - xpad->last_out_packet = -1; + /* + * Begin the init sequence by attempting to send a packet. + * We will cycle through the init packet sequence before + * sending any packets from the output ring. + */ + xpad->init_seq = 0; retval = xpad_try_sending_next_out_packet(xpad); spin_unlock_irqrestore(&xpad->odata_lock, flags);