From patchwork Thu Mar 30 02:16:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9652861 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 5AA7C6034C for ; Thu, 30 Mar 2017 02:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 489FC2856E for ; Thu, 30 Mar 2017 02:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B6D22857B; Thu, 30 Mar 2017 02:18:33 +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 AC7172856E for ; Thu, 30 Mar 2017 02:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753213AbdC3CS3 (ORCPT ); Wed, 29 Mar 2017 22:18:29 -0400 Received: from relmlor1.renesas.com ([210.160.252.171]:46437 "EHLO relmlie4.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753303AbdC3CSZ (ORCPT ); Wed, 29 Mar 2017 22:18:25 -0400 Received: from unknown (HELO relmlir2.idc.renesas.com) ([10.200.68.152]) by relmlie4.idc.renesas.com with ESMTP; 30 Mar 2017 11:18:21 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir2.idc.renesas.com (Postfix) with ESMTP id B01E43FB96; Thu, 30 Mar 2017 11:18:21 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id AA33328076; Thu, 30 Mar 2017 11:18:21 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id A17E428070; Thu, 30 Mar 2017 11:18:21 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac2.idc.renesas.com with ESMTP id MAH04671; Thu, 30 Mar 2017 11:18:21 +0900 X-IronPort-AV: E=Sophos;i="5.36,244,1486393200"; d="scan'208";a="239032494" Received: from mail-sg2apc01lp0246.outbound.protection.outlook.com (HELO APC01-SG2-obe.outbound.protection.outlook.com) ([65.55.88.246]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 30 Mar 2017 11:18:21 +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=GMZkrlbZxo6rvvzdia4Lt+ildXMr79KsjsRgVb6gPjs=; b=MRB9R0a6ZV5V/tZmyRqb05Eld9LGqS01WuBbqoxiEKwAk3TKWWanQVV7m3FV0vsiM+I7fj9L66qJTuziiF8pJFyJZuRuhDwAxzKr6vcw9TtbGD1vlj64grDI2iU0Czqm+ieHlTJ6PHE8saziDtlrMjhiMQlXW39iCk4QvMHP9vc= 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 SG2PR06MB1693.apcprd06.prod.outlook.com (10.167.82.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1005.10; Thu, 30 Mar 2017 02:18:19 +0000 From: Yoshihiro Shimoda To: CC: , , , Yoshihiro Shimoda Subject: [PATCH v3 3/3] usb: gadget: udc: renesas_usb3: add support for usb role swap Date: Thu, 30 Mar 2017 11:16:06 +0900 Message-ID: <1490840166-18449-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490840166-18449-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1490840166-18449-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TY1PR0201CA0042.apcprd02.prod.outlook.com (10.164.90.180) To SG2PR06MB1693.apcprd06.prod.outlook.com (10.167.82.135) X-MS-Office365-Filtering-Correlation-Id: 6b43e613-cd52-4621-dda7-08d4771308a4 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:SG2PR06MB1693; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB1693; 3:GH0Sy/qUW1d3X4u1I8mDc6N4rQ1RoSWsfpp2sCUCKNp/NVoAAhtUjyZTXOerkyKu/fimP9nPZLqT5gG9LtrVvJ85FjTgXCyn3FRI0Rkc1HBlpUA4IKCwIzTBEIWLN0jZ9ueaQUGF6+CKv240Nz7IwKYIn3gfvIxjtw872Wypr0/c63W+t878uWP7zfd7mFbIgvkW16tJfhEX6Z/bhPRWCRV6jSVAQZ90OVEiX/0tcp0Vy5ruhQ+YlHOxfANh7lkBK48+zwPpkTg9mkNAXidhCyPFjuUfyvlvBx6KP8uXZv2n/zyd9jI3Q3tcvKtx4lG6KGFOjKJdeFMYuZm39GXv+zhGDPuRh9qVLlLTqrXGQII=; 25:g3v2fEWGeo0HReJ5tpMHlWnngLSzR/KD/yy8qxjlA/kHb7KkpsvsJecPp16L5Mwz3uygJpMO6pzh5PpzoZ1Y1KCCvYqJ7+WS0NsJDHX+uQrfcNC06a9SI3hpsevZ8CkpE6oxOw7BOJIIDnZKZxGQPCC8o+GYwILn9m+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oUMIVC1Y4CIsth+W+Sgyn3IUbx/saJ+KjDXrT5Yhw7SXuGYtp1w X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6041248)(20161123558025)(201703131423075)(201702281528075)(201703061421075)(201703061750075)(20161123560025)(20161123555025)(20161123562025)(20161123564025)(6072148); SRVR:SG2PR06MB1693; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB1693; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB1693; 4:ulyyNBlcRkGUuFSyUojU9V5S5LPPCYqK1r2/8+WHZXeEhD962Y0mTt9FviaqXpMP1EBF8984/D5HOnu/AsWfMrSO8kojcNlsvNLQd3LFSs4csAvlkFy7GGv5x+mzp03tYf/LTmcZ/8gPtpSnorCbNLPL9G+x8anNuiPw19X9yYhnVyADPiV3pqraM/ImkEBIASXRoBC84bDE1Gqorobq+KjxQbwh5Gzz8aB/Ccog13uaJ690oR68a+K/M6s8YfPBZNVkXyLoFSOa62hy8xbHSE2b7Gpy3nQ3lxp2GtX1yMXJ0kdEXKvGCiRDWn0CKYK2ppZEXfm4TrvoQtEX6s9M48zS5SksZPb13FqVhchPQOay+hI5ksvaYQZws39aL8xpjqpRH3l+F+DFBkB6g8kPiawarK1nOYs16sl2Vdjx6h6Zsb8z5b6KqLRpqO6CwDrF/2OTkxQcr62t1sCzSVLPwJMvM8JA1bKN3Gdgnw63NHtz0RxTcmg/abOsnfj+iP4U3M0L6ITccvPrNvyzzplfoeNuIZTHTva4BAPsQMU2tVFHTsMRESir8E3h8BysCNDXBOGtZMjp4M/JPl1jvB5AdDlMEPBG9ZEUXRsgB6lKIGYnfKyLBGC/tYSyfIq1UngIFkM/p0YLV3EExpl4MFtda50insl5aKG/9Ye3DfF7gOhsiOcuGTyix30jtOGuLj1o3hMFCdwiH56jHi9YGhRrGg+ccqFHNPiYlReUXRWcWv5DIUsnXjyJafoTh9X1XyzdTMHILnK1VuC8kPEcCJYWnh6Wz2+4Q2a4j/JtTEcSZIckAqaxpnxTmSCDWqu3RYXo X-Forefront-PRVS: 02622CEF0A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(39840400002)(39860400002)(39450400003)(39400400002)(39410400002)(39850400002)(50944005)(6486002)(110136004)(107886003)(38730400002)(5003940100001)(25786009)(6506006)(2906002)(6666003)(36756003)(2950100002)(42882006)(6916009)(33646002)(4326008)(6512007)(5660300001)(3846002)(6116002)(78352004)(76176999)(8676002)(81166006)(7736002)(48376002)(50466002)(50226002)(2351001)(50986999)(305945005)(47776003)(53936002)(54906002)(66066001)(189998001)(42186005); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB1693; H:localhost.localdomain; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB1693; 23:NJgkavyfNg3KLnstWYhmFBsAKlufN7im2/hUvXgrM?= =?us-ascii?Q?japvPZ8LWuceUOXhejGtjKP24Zh9ANLkDpi6UaMp38CVbzH7A8g04MECF28a?= =?us-ascii?Q?kh/p2qJPYC7EQkC1+wyW59ym+3YxYFce/TbI6tsqXEoioxHU8ysvkKPFUycn?= =?us-ascii?Q?+Di7TfjWp17NF19aiqt+5tdIMu/EsY/+47w+ZC1/6H8noiI16N8EPCK4kd64?= =?us-ascii?Q?NKW8SSIbiuWmUMSs+tHiy4BQMChNA4iQjfPgW+CDlPflcomQDFy1a6GmCqLj?= =?us-ascii?Q?O3qLPAMNdUmxrxFz5k0og4VQ9F9amh/iJiyfZYP9zl0HCr6lRB/kbfjRrn1o?= =?us-ascii?Q?sXljL3sPKk1et9KmNAvcdTdjqcfSGUqv8KyT7rnutfiFKS2JnL4FM/DhE5R6?= =?us-ascii?Q?0E0OS7inp1Cqee5YQVDAr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kbDyOuRvBqxPw7jyAW7UHK9gm61TecuoMlPYHrkcEaBFVrxyQZ5VORKjwAI/fnEeu1gR2tAPXKHBtC6+MX5LQBuOvXayT2fA9JTod5lqFtvtI+5kCU8mlGj/gcfJoxQFyP+lOjQE= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Mar 2017 02:18:19.3563 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB1693 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 | 15 ++++++ drivers/usb/gadget/udc/renesas_usb3.c | 56 ++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-platform-renesas_usb3 diff --git a/Documentation/ABI/testing/sysfs-platform-renesas_usb3 b/Documentation/ABI/testing/sysfs-platform-renesas_usb3 new file mode 100644 index 0000000..1f63190 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-platform-renesas_usb3 @@ -0,0 +1,15 @@ +What: /sys/devices/platform//role +Date: March 2017 +KernelVersion: 4.13 +Contact: Yoshihiro Shimoda +Description: + This file can be read and write. + 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. + + Read the file, then it shows the following strings: + "host" - The mode is host now. + "peripheral" - The mode is peripheral now. diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index a1e79fc..5a2d845 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -372,6 +372,11 @@ static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) usb3_clear_bit(usb3, USB_INT_2_PIPE(num), USB3_USB_INT_ENA_2); } +static bool usb3_is_host(struct renesas_usb3 *usb3) +{ + return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON); +} + static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) { /* Set AXI_INT */ @@ -576,8 +581,14 @@ static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev) { + unsigned long flags; + + spin_lock_irqsave(&usb3->lock, flags); usb3_set_mode(usb3, host); usb3_vbus_out(usb3, a_dev); + if (!host && a_dev) /* for A-Peripheral */ + usb3_connect(usb3); + spin_unlock_irqrestore(&usb3->lock, flags); } static bool usb3_is_a_device(struct renesas_usb3 *usb3) @@ -1837,11 +1848,49 @@ static int renesas_usb3_set_selfpowered(struct usb_gadget *gadget, int is_self) .set_selfpowered = renesas_usb3_set_selfpowered, }; +static ssize_t role_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); + bool new_mode_is_host; + + if (!usb3->driver) + return -ENODEV; + + 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; + + usb3_mode_config(usb3, new_mode_is_host, usb3_is_a_device(usb3)); + + return count; +} + +static ssize_t role_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct renesas_usb3 *usb3 = dev_get_drvdata(dev); + + if (!usb3->driver) + return -ENODEV; + + return sprintf(buf, "%s\n", usb3_is_host(usb3) ? "host" : "peripheral"); +} +static DEVICE_ATTR_RW(role); + /*------- platform_driver ------------------------------------------------*/ static int renesas_usb3_remove(struct platform_device *pdev) { struct renesas_usb3 *usb3 = platform_get_drvdata(pdev); + device_remove_file(&pdev->dev, &dev_attr_role); + pm_runtime_put(&pdev->dev); pm_runtime_disable(&pdev->dev); @@ -2044,6 +2093,10 @@ static int renesas_usb3_probe(struct platform_device *pdev) if (ret < 0) goto err_add_udc; + ret = device_create_file(&pdev->dev, &dev_attr_role); + if (ret < 0) + goto err_dev_create; + usb3->workaround_for_vbus = priv->workaround_for_vbus; pm_runtime_enable(&pdev->dev); @@ -2053,6 +2106,9 @@ static int renesas_usb3_probe(struct platform_device *pdev) return 0; +err_dev_create: + usb_del_gadget_udc(&usb3->gadget); + err_add_udc: __renesas_usb3_ep_free_request(usb3->ep0_req);