From patchwork Fri Nov 9 11:44:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10675807 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 0F1A015E9 for ; Fri, 9 Nov 2018 11:47:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00BC52A515 for ; Fri, 9 Nov 2018 11:47:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E96102B24B; Fri, 9 Nov 2018 11:47:03 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 77C972B30D for ; Fri, 9 Nov 2018 11:47:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbeKIV1S (ORCPT ); Fri, 9 Nov 2018 16:27:18 -0500 Received: from mail-os2jpn01on0090.outbound.protection.outlook.com ([104.47.92.90]:2177 "EHLO JPN01-OS2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727656AbeKIV1R (ORCPT ); Fri, 9 Nov 2018 16:27:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=7pXKBDgK3zU66jUzsDY1sLoDhfLJCNYNQ7oIxn8/dvI=; b=VagDBCK8/Y/n00451EF1hEVuGtjDAXD9rxekSEl0Tf22kpUti3vGDrS2GLn30l+Ue0Tnu83pCTxhSLDTL8cx8jX+o/Z4eGnvvdOgCb0vcV0Wllpez+PiaJuW8qD+r1zfs8UKNSYOniDgXWgkdrSHRq7vreUpIzMxyfDj25ASYwA= Received: from localhost.localdomain (211.11.155.144) by TYAPR01MB2301.jpnprd01.prod.outlook.com (2603:1096:404:3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.21; Fri, 9 Nov 2018 11:46:55 +0000 From: Yoshihiro Shimoda To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device Date: Fri, 9 Nov 2018 20:44:36 +0900 Message-Id: <1541763876-19622-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TYAPR01CA0098.jpnprd01.prod.outlook.com (2603:1096:404:2a::14) To TYAPR01MB2301.jpnprd01.prod.outlook.com (2603:1096:404:3::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 593e3908-4c53-4299-6721-08d646390cc6 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(8559020)(8990200)(2017052603328)(7153060)(7193020);SRVR:TYAPR01MB2301; X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2301;3:Wc6opiDFtPQ9eBlkge3uUTK90MzOKtB1P9ljUvLccAasFOyq+faquW7s/GCWKl3vPU5IcMMNG3LLyR7YwhuUxixDHllCUN2Fzqp1vFADeMt+xAZlWyaOoBXb/fHUfL9sPH6NWj0ASkecZ/H2uj7+VV+B8DN1Y4NKadzn+AYPQpxeEfxuM2AWihOs0zFvqAtgb7vkwabsyg7seFk8+8szjk0R8rtRrlV9fJIQi3OtgdidcL4OaIpGlUt43U19q92Y;25:lSdykpQS9P+IZEWSiOkYjIT0C99TxTQzs5y1LfIRlXjDmOGxiwOD7omo/8fdI+WOc0F3h23nr9jQGwLnVcLr6SYXt8doBo9v0dhR7es5mSRcdkwGT+vct2o70PI+WlxH8wK1TTVY6eUwY8QB6fSGn8I1SzdxuZqnx75stFpjZpqpvW2Y013yWc+xnm2nO85cclK+bdDr6nErSIzYjAPCWUTL4MK98utIdFf3BMXr9ZebYWrz4UYxPaVLHElR9Y17RClUy6jFRdsNsjGEikJWGlwIfIwDObQWa+r5hv90gluZGxGXzYi4kaC4qg/2Z3SdfYO5cwgz/GyQFFDs7PqGeQ==;31:JLiwRMOesi1UMQm1866oMggCV8dXQJ/zxx6d+iqMB5FunAaLybHaKD1mZkUiiQ4NkweiuOr9dd/nYWeXUsjqBA18QVUOK0izdIWSNoaygcxgGuW6uKNF3es9ResiifMrilQgYO5RX//TMu+RS99kMulHLIaWD/qzn2Cq2E9gna7HDn1J0Xw2f1vHs2ZZf4eBbLYb7dD66KDPe57yBpOxF74U+lbQ8aZ8ofgz6P316y8= X-MS-TrafficTypeDiagnostic: TYAPR01MB2301: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2301;20:2UdMmWI6Qf0MpbC+xpEKuey9U8Jr1ah/vJhCAcII11yirc6JzS2Maym9LsHJq79DY35eRgzyXznUu9h3/lv05MkBTHlzLO2MV6fSDtLYepKKkFrTAtXShHFZB3aSkFMZ9bxa0DeHMHO/NGfW1dQaTK69I4u/xb5ITBuYGkBdkrbmnGIIiyuAXrdRkY+JiACUkhHpeiEo1CYHTdLjcTnl8GTz2jplwFK7TqjXrISwqLlccEJjeTGZ+VN+9HcH9H1x2QTIvSO9HBLyTP0dlWICx/ytSbJ8DMIf/DLQLDH/XH8Of79eI+gxH7t9LCKLshJj7cwYKcVoIjG8ZjIRS+gTPUdAdfn+5uSdS4w2rT57JX82qIpoor5mV3fCPscXiNkqFOWJRiAcrA3cjCkVN10pKXcyq5lZkPbYa8q1hBILH54EKpKqMavKpRsVrdgFIPvrnFMAw+RYeKuMX1/VBBtkr92aVrmKXNbdkACBzzhntwQpw/fUfAPcdY8R1a2hfVLV;4:4Za0j6NWFO56/XRIwWVqDorhw97kxIVX93bnuzWrCtehwLrDecupxX5oxdSSbcA8Htapsvz02ZKkCP3jKFh9EXDEVzviPUH2os3uIfewz5EKFZuu6bJOyF8qDfk6zERt7haZrykY7xJmpizqA/0naexaynJm7zkPz0oXnLdj/pmuy2o/gHbq03sw/oaUrlcQqVpCrGycQIfMHO3/FfuLq+YmXyd+DK+dnsozT3K7FyAbc0hen9dyv5bBQ89zS2qoSyUQXtuefbcrdmoc1I6MYQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(3002001)(3231382)(944501410)(52105095)(6055026)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123558120)(201708071742011)(7699051)(76991095);SRVR:TYAPR01MB2301;BCL:0;PCL:0;RULEID:;SRVR:TYAPR01MB2301; X-Forefront-PRVS: 08512C5403 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(376002)(346002)(396003)(39860400002)(136003)(366004)(199004)(189003)(16526019)(52116002)(69590400006)(106356001)(53936002)(51416003)(48376002)(97736004)(3846002)(6116002)(6506007)(2616005)(6486002)(26005)(386003)(36756003)(6666004)(25786009)(6512007)(2906002)(2361001)(8676002)(4326008)(486006)(5660300001)(42882007)(47776003)(14444005)(316002)(50466002)(6916009)(107886003)(8936002)(105586002)(16586007)(78352004)(1857600001)(476003)(2351001)(956004)(50226002)(68736007)(81166006)(66066001)(81156014)(7736002)(498600001)(305945005)(3720700003);DIR:OUT;SFP:1102;SCL:1;SRVR:TYAPR01MB2301;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:0;MX:0; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2301;23:cjXtGXLLPN8bEWLWXjHVveWwDXopoHvKX+LB2j1DB1YgThw7nk1cx3Ac9VhWuwEi/u7v7nI0FWJLr5OhJX3lyi9Fx1g2km7KDtJNrA6NhQNKFX82FnuqtwU/fPN9yJFWQn/iLCtnAgSCay2e5Jl7Ls903qXiaI59QXpfEKCFSYqjjACkIonqijG+cZfdQsuh72xh4qfXjQ0N5IxBKISgvqoATwOqlTODEXanoEXc1+Wr5HXkRwG+LDO9oabs32tH2DavGG7yC/tF74H448h4cg//DUoRPBOSQuHafm4pEOSsgQrjEbohGDkuwkGoZdrwnco7ESlc2yvZ/D9Z+2h6L/evmgYSl0RaX9Z233F8ECOPog+qUAWVr4MDZkhfRNuvn1NirqjMkssiZp6Rqql/m5EJPlE+ebq3cvSikVYsgO52zpNEdG5Au8Ot7S7DjwEmDUTw2EkPqWHcuvP+DktiKADg3JKEW2U/QT5QzxBMc65nI/VhGshk8QaAJKQl8nZjcybyLzhx60PNB9qwCrT9IE9jE/l6/k6IC3QMqbR904EqN9RUDuU8D+49pT2BZpS9RirXwahU+idP1CZvur8ZDxgHK0ZwK4+RgpA8lB1iV5VIynFRAY70uBNRbulbRqbJR9NXIiiBhxFzZhK74GlMH8z6qVz84+6eB4sZN6mIW+eS2RBPIkTzlvpkYx8LBbU49WOdFg4Wkek4YmeAi22YCzGmUbbDQ3DbN7eJ4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dsWvkYajbOuIFT4fl/qUoBUaOe4iR15822CvL8ujNM1er8J1u4PS1CMc6hQYEedCnXomLiKmVFlgy7ySp657iZ2nWiYiI+xcNM56E7+CF+6JptkZWB9ikVz6tEY2cEFew/HWdqkAwHMMjcC7xHolA/YyQ1Tkle8oeT/tSCVL4rSttDvjjkUI+uOS5mYO5IXQHT7Wo0LFo1y+29az9BWmqYNdWB9oOIqPfF8OyNVhFG/Rhux/OyjZtobtaQZwetjhfr9JpXreFEHMOgZjez2Cei9EqG5CyvBp3T/f+2KLpwAqMzr1zUpDguOFX4iHOuufs5iIs2mw3uPT+NjPU3m1f87pxa6WMCaPeMoFVBdufo7rtQ==;5:WanaARPt84jPS0KFozB/xK8bEhJ/SP0oAHClkDLuob/m93YpIeDogiTz3Zo2WsyGnNxxIJHw8U/TnD5HVS/PQAa+1CJ3Ym85clZDHZ9denorQTK+GP3fMYIx+Fj8NChd6oFERKLEpxLPmuoljI8yPiPp7vt3yjklrRNYJ9wbijQ=;7:Z25IaticWhM420yLqilL+O0Ko4KcBk+U6K7D4SVZL3APHNYQA4OyAViHIskvQcad5YKANWAlUill7qyvSmkJZyLSlZy75lao+ivEQuC6MOVmhwNcWt3+wqILC5hWAISv48UAWCe6mjjSbPxtd7TkqA== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;TYAPR01MB2301;20:596OXMbwsKjABZAHwPC/AUo2vOmMFCfCoPBeDncDJIyG9U+9JyFdB4wPThiDAHDYt0GupaDIFue373zaL4YOyWISDPV8TboMLgi8sD+Lgtl5msaLm8mSJtbQpGrukMOQbBjTY/D/emRhRAdrIq6pmefijVJrdiSda3pPRgOrQlc= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2018 11:46:55.9975 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 593e3908-4c53-4299-6721-08d646390cc6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYAPR01MB2301 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 This patch adds a safety connection way for "forced_b_device" with "workaround_for_vbus" like below: < Example for R-Car E3 Ebisu > # modprobe # echo 1 > /sys/kernel/debug/ee020000.usb/b_device (connect a usb cable to host side.) # echo 2 > /sys/kernel/debug/ee020000.usb/b_device Previous code should have connected a usb cable before the "b_device" is set to 1 on the Ebisu board. However, if xHCI driver on the board is probed, it causes some troubles: - Conflicts USB VBUS/signals between the board and another host. - "Cannot enable. Maybe the USB cable is bad?" might happen on both the board and another host with a usb hub. - Cannot enumerate a usb gadget correctly because an interruption of VBUS change happens unexpectedly. Reported-by: Kazuya Mizuguchi Signed-off-by: Yoshihiro Shimoda --- drivers/usb/gadget/udc/renesas_usb3.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index cdffbd1..6e34f95 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -358,6 +358,7 @@ struct renesas_usb3 { bool extcon_host; /* check id and set EXTCON_USB_HOST */ bool extcon_usb; /* check vbus and set EXTCON_USB */ bool forced_b_device; + bool start_to_connect; }; #define gadget_to_renesas_usb3(_gadget) \ @@ -476,7 +477,8 @@ static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) static void usb3_init_epc_registers(struct renesas_usb3 *usb3) { usb3_write(usb3, ~0, USB3_USB_INT_STA_1); - usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); + if (!usb3->workaround_for_vbus) + usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG); } static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3) @@ -700,8 +702,7 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) usb3_set_mode_by_role_sw(usb3, host); usb3_vbus_out(usb3, a_dev); /* for A-Peripheral or forced B-device mode */ - if ((!host && a_dev) || - (usb3->workaround_for_vbus && usb3->forced_b_device)) + if ((!host && a_dev) || usb3->start_to_connect) usb3_connect(usb3); spin_unlock_irqrestore(&usb3->lock, flags); } @@ -2432,7 +2433,11 @@ static ssize_t renesas_usb3_b_device_write(struct file *file, if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) return -EFAULT; - if (!strncmp(buf, "1", 1)) + usb3->start_to_connect = false; + if (usb3->workaround_for_vbus && usb3->forced_b_device && + !strncmp(buf, "2", 1)) + usb3->start_to_connect = true; + else if (!strncmp(buf, "1", 1)) usb3->forced_b_device = true; else usb3->forced_b_device = false; @@ -2440,7 +2445,7 @@ static ssize_t renesas_usb3_b_device_write(struct file *file, if (usb3->workaround_for_vbus) usb3_disconnect(usb3); - /* Let this driver call usb3_connect() anyway */ + /* Let this driver call usb3_connect() if needed */ usb3_check_id(usb3); return count;