From patchwork Wed Sep 26 15:23:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10616087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9366C913 for ; Wed, 26 Sep 2018 15:24:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79C612B21C for ; Wed, 26 Sep 2018 15:24:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E1B02B22E; Wed, 26 Sep 2018 15:24:05 +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.9 required=2.0 tests=BAYES_00,FROM_WORDY, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 12BBE2B21C for ; Wed, 26 Sep 2018 15:24:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728317AbeIZVhY (ORCPT ); Wed, 26 Sep 2018 17:37:24 -0400 Received: from mail1.bemta26.messagelabs.com ([85.158.142.113]:49946 "EHLO mail1.bemta26.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727285AbeIZVhW (ORCPT ); Wed, 26 Sep 2018 17:37:22 -0400 Received: from [85.158.142.194] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-2.bemta.az-b.eu-central-1.aws.symcld.net id A2/57-09730-984ABAB5; Wed, 26 Sep 2018 15:23:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOIsWRWlGSWpSXmKPExsUSt3OpsW7HktX RBut79S2aF69ns+havZPF4vKuOWwWi5a1Mls8WXiGyYHVY97JQI/9c9ewe+z83sDu8XmTXABL FGtmXlJ+RQJrxrs3FxgL/vNVPPyym6mBcTdPFyMXh5DAekaJ3jebmbsYOYGcCon79xazgdi8A pkSXb+OAtkcHJwC7hJ79hVDlLhJPJ/bBFbCJmAhMfnEAzCbRUBV4v/+J4wgtrBAkMStG/uYQO aLCPQwSmw8soQdJMEskCSx9m0PM8R8QYmTM5+wQMQlJA6+eAF1g4HE6QWNYHEJAXuJ6e+vMoP cICGgL9F4LBYibCjxfdY3qBJzia7pU5knMArOQjJ1FpKpCxiZVjFaJhVlpmeU5CZm5ugaGhjo Ghoa65roGpkY6iVW6SbppZbqJqfmlRQlAmX1EsuL9Yorc5NzUvTyUks2MQIjIKWQ5eMOxu3t6 YcYJTmYlER5FXxWRwvxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4DVcDJQTLEpNT61Iy8wBxiJMWo KDR0mE1wQkzVtckJhbnJkOkTrFqCglzqsCkhAASWSU5sG1weL/EqOslDAvIwMDgxBPQWpRbmY JqvwrRnEORiVhXi+QKTyZeSVw018BLWYCWjyhZwXI4pJEhJRUA2Pb6erDl7OPZE01c1hzLUpu 8W/t6fzlUnLzDrz4/XyxFWf8zS9/XN/NLD7+hec+6yPZWb/+bxKaKVNWW1Z2p7v5WP/ej8Gvr pye67Qh36g187ZbgKKa9WXLxfZrfk77GBM0V8RduTvlt/lHwdi0oNyAmP9qk/9ITIg4zrn0T2 HCJV2fnscJesuUWIozEg21mIuKEwGyXb3z+gIAAA== X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-25.tower-239.messagelabs.com!1537975432!279113!1 X-Originating-IP: [94.185.165.51] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.14.24; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6890 invoked from network); 26 Sep 2018 15:23:52 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-25.tower-239.messagelabs.com with AES128-SHA encrypted SMTP; 26 Sep 2018 15:23:52 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.382.0; Wed, 26 Sep 2018 16:23:52 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 2F1FA3FAF0; Wed, 26 Sep 2018 16:23:52 +0100 (BST) Message-ID: <383410593681e2fed025a4b538ea0840ff370a9a.1537975081.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Wed, 26 Sep 2018 16:23:52 +0100 Subject: [PATCH 2/2] usb: typec: fusb302: Resolve fixed power role contract setup To: Guenter Roeck , Heikki Krogerus , Greg Kroah-Hartman CC: , , MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 26/09/2018 13:22:00 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the controller is configured for a fixed power role (Source only or Sink only), attach does not proceed within the TCPM state machine as there is no CC event generated by this driver to update the CC line status. To rectify this, when CC is configured as Source or Sink we now make use of the hardware's automatic fixed Source or Sink toggling mechanism, which detects attaches in the same way as for DRP toggling. In this way the result of toggling is handled in the same way by the 'fusb302_handle_togdone()' function, and CC events are generated as expected for TCPM allowing a contract to be established. Signed-off-by: Adam Thomson Reviewed-by: Guenter Roeck Reviewed-by: Heikki Krogerus --- drivers/usb/typec/tcpm/fusb302.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/usb/typec/tcpm/fusb302.c b/drivers/usb/typec/tcpm/fusb302.c index fd851d8..43b64d9 100644 --- a/drivers/usb/typec/tcpm/fusb302.c +++ b/drivers/usb/typec/tcpm/fusb302.c @@ -679,6 +679,7 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) int ret = 0; bool pull_up, pull_down; u8 rd_mda; + enum toggling_mode mode; mutex_lock(&chip->lock); switch (cc) { @@ -764,6 +765,29 @@ static int tcpm_set_cc(struct tcpc_dev *dev, enum typec_cc_status cc) chip->intr_comp_chng = false; } fusb302_log(chip, "cc := %s", typec_cc_status_name[cc]); + + /* Enable detection for fixed SNK or SRC only roles */ + switch (cc) { + case TYPEC_CC_RD: + mode = TOGGLING_MODE_SNK; + break; + case TYPEC_CC_RP_DEF: + case TYPEC_CC_RP_1_5: + case TYPEC_CC_RP_3_0: + mode = TOGGLING_MODE_SRC; + break; + default: + mode = TOGGLING_MODE_OFF; + break; + } + + if (mode != TOGGLING_MODE_OFF) { + ret = fusb302_set_toggling(chip, mode); + if (ret < 0) + fusb302_log(chip, + "cannot set fixed role toggling mode, ret=%d", + ret); + } done: mutex_unlock(&chip->lock);