From patchwork Tue Mar 28 11:53:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9648935 X-Patchwork-Delegate: geert@linux-m68k.org 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 35A65601E9 for ; Tue, 28 Mar 2017 11:55:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3028C28236 for ; Tue, 28 Mar 2017 11:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 249C228334; Tue, 28 Mar 2017 11:55:53 +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,DKIM_SIGNED, DKIM_VALID,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 9CF9028236 for ; Tue, 28 Mar 2017 11:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751563AbdC1Lzw (ORCPT ); Tue, 28 Mar 2017 07:55:52 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:12031 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751446AbdC1Lzu (ORCPT ); Tue, 28 Mar 2017 07:55:50 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 28 Mar 2017 20:55:43 +0900 Received: from relmlac4.idc.renesas.com (relmlac4.idc.renesas.com [10.200.69.24]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id CAED277792; Tue, 28 Mar 2017 20:55:43 +0900 (JST) Received: by relmlac4.idc.renesas.com (Postfix, from userid 0) id ABB3E480A5; Tue, 28 Mar 2017 20:55:43 +0900 (JST) Received: from relmlac4.idc.renesas.com (localhost [127.0.0.1]) by relmlac4.idc.renesas.com (Postfix) with ESMTP id 9FEF448014; Tue, 28 Mar 2017 20:55:43 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac4.idc.renesas.com with ESMTP id WBP02093; Tue, 28 Mar 2017 20:55:43 +0900 X-IronPort-AV: E=Sophos;i="5.36,236,1486393200"; d="scan'208";a="238840606" Received: from mail-sg2apc01lp0240.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.240]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 28 Mar 2017 20:55:42 +0900 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; bh=1CCg09kW0hR5oT1mJnrHDjhiaoBukiv58LqsJ8q5Yos=; b=BHID9OFFxmlmOiPeG2FnvjZIml0+bDrgWzh3iNVQuuziRwI8cWAIuBWdFyo6DN52abGZ6AJ7GkcQReqNlJyGefsp62eiQKhYbeAyXbS2TX0jdicJUFljoacwnr38ehc4MJmVTdjC1BePZiG8soq9/f4Zkk1Kd62kLKyE4HNOwGI= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=none action=none header.from=renesas.com; Received: from localhost.localdomain (211.11.155.144) by PS1PR06MB1691.apcprd06.prod.outlook.com (10.167.53.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14; Tue, 28 Mar 2017 11:55:39 +0000 From: Yoshihiro Shimoda To: CC: , , , Yoshihiro Shimoda Subject: [PATCH 4/4] usb: gadget: udc: renesas_usb3: add support for usb role swap Date: Tue, 28 Mar 2017 20:53:24 +0900 Message-ID: <1490702004-8167-5-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490702004-8167-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1490702004-8167-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR0201CA0036.apcprd02.prod.outlook.com (10.164.90.174) To PS1PR06MB1691.apcprd06.prod.outlook.com (10.167.53.13) X-MS-Office365-Filtering-Correlation-Id: caa85bbc-4b7a-4eb3-0cd4-08d475d15a91 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423060)(201703031133066); SRVR:PS1PR06MB1691; X-Microsoft-Exchange-Diagnostics: 1; PS1PR06MB1691; 3:bhJlEy6czQRaz2cGt/5b60oAhWO0/P3GTXA/vDwVITCyqeaWayDujCmRu+niDj01MCNXAKuSkZ/uG46E+cc+Bxwux+kXforhBa/3zbEZAsrGzyOMgeK1vu+Pb4CoQZ4X4I6LwXZzLs1aKJkLRnI3woxWMYrlYWfEozBomer1kcuWEpCSF+w7fNLwq2VkhowuTOORHfFEv8xvYVlTEcmtKtfyWPzdV21ycEST5gDs7D9s+a7ELmLI/CZXBOvmBQSDeprgifilqStdL/8l7d8akRn5Ub1sL0qFpiRYw/QIXpGEhGkvrYlRdQ4oP6PMuOka07E28Ucn/BtnNoYnVkyhQe3NgVlEvpQhQKvPZxd8XLY=; 25:BZanxRLBbgGNZ0B7c6AnnEh662Du24wJucbT+/0RO1bQ84+dyEjOy0G0uFcSnw7tAsqC1rGSqxSW9JAgbKcTeFfcHXn4nERVGOwzSw7VB+iRyVeYm3uE9detuJppqtbb8CC7nV0wKavIJiNwJOlnimLzPjCWMlxzkZTt7yQltLxW6D1edaiVxoHneMjrgX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2qI X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040435)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123562025)(201703131423059)(201702281528059)(201703061421059)(201703061750059)(20161123564025)(20161123558025)(20161123560025)(6072148); SRVR:PS1PR06MB1691; BCL:0; PCL:0; RULEID:; SRVR:PS1PR06MB1691; X-Microsoft-Exchange-Diagnostics: 1; PS1PR06MB1691; 4:WJJ71NW9IQt2gQlNAYG43tJl+oe3byWmEcEOQIkLkIGyZtGpjwGmuZfgwbd0+awjFrbYIgaR2a7rHzeFjTr8B9Z5h9FsmQMooqjK2cXjEP4htrYrzah8/e6pOd/86zqTt6HHC8MSZ7RlzTHvVp5fdu+zVPN/aigLUVYoXvfOvh/et9CZ1Ab/rUMgZ2i5fu8/3h+nrs87kEP1z8KZZvyX/D+Eyg1Dmez+JxaV2pUtc9W1Z0CpNmwsCmTE10VewtiAyEty9CCFsGIxbJ7//0HAIjq6Ug9DzYj+p638HTRnD2p+a3yDB5LHBUJOjXBAlFskqWEElzRsJtIT55Duuef4rQJOa2P6pKiqA9Cry8ZF58jLv1dhhnr7kd8BrKoRGjLVk19zfmvmpDqxjA+ZwaBu5UuRHj/nocDcyePRikmXk4uxXKfmO5ar1ybu87ITE7+eFSmLHLt2qGCsKy7BaDj/TLwR78C1+jTyMOmnAOBLTDxNGx6JeRflUb0DufaFVh+ZjathXbrulCwZybNFtuqvct40whMa6RtERWduYK+oQ87On+X6LLozwNlkSuipW6i2wGTTmIZ4oiBQd2BiH+IDExiJDlf8U1a5bhFrVtDOS2l+AilJCsQj6qomqL5Z35pBOhbUNYwVXQRo2jzkeU2V5eP1WSl7I/JI7HQE+eeLzP8HK5m/x5053kmKqCXKD5tnbPZgneZO2d4wNJNrcKaiXI2ghfGgtANi9fmBVcRig1zRRI67mLF3SVrxzmn3b8RGJ09MB8zaTLuaugxrgIAsvMEkDt96IJHa0x46s0xAjk52v5TrfLcdIpEkmJIXLCey X-Forefront-PRVS: 0260457E99 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39410400002)(39400400002)(39450400003)(39860400002)(39850400002)(39840400002)(50944005)(81156014)(81166006)(50226002)(25786009)(3846002)(8676002)(4326008)(6116002)(42882006)(110136004)(2950100002)(38730400002)(6666003)(189998001)(107886003)(42186005)(33646002)(97736004)(6916009)(78352004)(2351001)(36756003)(50466002)(48376002)(5660300001)(76176999)(50986999)(7736002)(5003940100001)(6506006)(66066001)(6486002)(6512007)(53936002)(2906002)(47776003)(54906002)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:PS1PR06MB1691; H:localhost.localdomain; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; PS1PR06MB1691; 23:YxSIPzfpdfaAeOBbt3FlxboZ05lM+TuNE/3OwvSNM?= =?us-ascii?Q?xDxq9e07pQX455T8AVsaasniZ63TfTyZX/BuaFSVHn5bSpng3py0SGoYFd5L?= =?us-ascii?Q?hO9xHXCRbOokMH8lyYig2bGZlJGn9GpFmc0fh2Yx7zVS21xyCBGby7FOFxJM?= =?us-ascii?Q?BfA4a4bs03CRvymiCcKayO2q4ueac/4MQ4KiloRHxqmfNGyQBy/YXF7aLND5?= =?us-ascii?Q?bdFkHCq66E3NMG0Q96iqAlsAKJlxM0mbaStZyuWyG8ZG5QZEna8RcnDh/rX3?= =?us-ascii?Q?PkZIfWw+ZCjl3h4kStHHLRvaPB/V5zGL36OQfG5Mv5uqOa0dvuAW4lJxrh4Z?= =?us-ascii?Q?OiJ7RQga7IiBMUgADErmmpZX3kPi2EuB8AOaDcBotWFbHFHDg4h4xVgLCvqw?= =?us-ascii?Q?FXMv/PhhV8dDQyqYMuY+ZWp3K3xciRhnRn5wSal1gVsJXjKk70Vzo+ds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zKPjhTVDAm++jsNP7ypxqB4QJHueZbRoPPiBVWkyiplv0NgkbspIYa+2yrVLwcLl0DKQY9QDNV/brazvN8FvyOTat/krDRBGRrcwgRTtgVq+9ZvOb0= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2017 11:55:39.0689 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: PS1PR06MB1691 Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for usb role swap via sysfs "role". For example: 1) Connect a usb cable using 2 Salvator-X boards. - For A-Device, the cable is connected to CN11 (USB3.0 ch0). - For B-Device, the cable is connected to CN9 (USB2.0 ch0). 2) On A-Device, you input the following command: # echo peripheral > /sys/devices/platform/soc/ee020000.usb/role 3) On B-Device, you input the following command: # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role Then, the A-Device acts as a peripheral and the B-Device acts as a host. Please note that A-Device must input the following command if you want the board to act as a host again. # echo host > /sys/devices/platform/soc/ee020000.usb/role Signed-off-by: Yoshihiro Shimoda --- .../ABI/testing/sysfs-platform-renesas_usb3 | 2 ++ drivers/usb/gadget/udc/renesas_usb3.c | 41 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-platform-renesas_usb3 b/Documentation/ABI/testing/sysfs-platform-renesas_usb3 index f5dace7..1ab919c 100644 --- a/Documentation/ABI/testing/sysfs-platform-renesas_usb3 +++ b/Documentation/ABI/testing/sysfs-platform-renesas_usb3 @@ -7,6 +7,8 @@ Description: The file can show/change the drd mode of usb. Write the following string to change the mode: + "host" - switching mode from peripheral to host. + "peripheral" - switching mode from host to peripheral. "b-device" - switching mode as forced b-device mode. Read the file, then it shows the following strings: diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 34ac03c..b552243 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -570,12 +570,29 @@ static void usb3_mode_a_host(struct renesas_usb3 *usb3) usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); } +static void usb3_mode_a_peri(struct renesas_usb3 *usb3) +{ + unsigned long flags; + + spin_lock_irqsave(&usb3->lock, flags); + usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); + usb3_set_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); + usb3_check_vbus(usb3); + spin_unlock_irqrestore(&usb3->lock, flags); +} + static void usb3_mode_b_peri(struct renesas_usb3 *usb3) { usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); } +static void usb3_mode_b_host(struct renesas_usb3 *usb3) +{ + usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); + usb3_clear_bit(usb3, DRD_CON_VBOUT, USB3_DRD_CON); +} + static bool usb3_is_a_device(struct renesas_usb3 *usb3) { return !(usb3_read(usb3, USB3_USB_OTG_STA) & USB_OTG_IDMON); @@ -1865,8 +1882,30 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr, usb3->forced_b_device = true; renesas_usb3_init_forced_b_device(usb3); } else { + bool new_mode_is_host; + usb3->forced_b_device = false; - return -EINVAL; + if (!strncmp(buf, "host", strlen("host"))) + new_mode_is_host = true; + else if (!strncmp(buf, "peripheral", strlen("peripheral"))) + new_mode_is_host = false; + else + return -EINVAL; + + if (new_mode_is_host == usb3_is_host(usb3)) + return -EINVAL; + + if (new_mode_is_host) { + if (usb3_is_a_device(usb3)) + usb3_mode_a_host(usb3); + else + usb3_mode_b_host(usb3); + } else { + if (usb3_is_a_device(usb3)) + usb3_mode_a_peri(usb3); + else + usb3_mode_b_peri(usb3); + } } return count;