From patchwork Wed Mar 29 11:42:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 9651401 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 56E7F602BE for ; Wed, 29 Mar 2017 11:45:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4546F281F9 for ; Wed, 29 Mar 2017 11:45:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39EA32846C; Wed, 29 Mar 2017 11:45:40 +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 9D2F2281F9 for ; Wed, 29 Mar 2017 11:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756019AbdC2Lp0 (ORCPT ); Wed, 29 Mar 2017 07:45:26 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:25619 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755945AbdC2LpN (ORCPT ); Wed, 29 Mar 2017 07:45:13 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie2.idc.renesas.com with ESMTP; 29 Mar 2017 20:45:11 +0900 Received: from relmlac2.idc.renesas.com (relmlac2.idc.renesas.com [10.200.69.22]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 18F81717AD; Wed, 29 Mar 2017 20:45:11 +0900 (JST) Received: by relmlac2.idc.renesas.com (Postfix, from userid 0) id 0158D28076; Wed, 29 Mar 2017 20:45:10 +0900 (JST) Received: from relmlac2.idc.renesas.com (localhost [127.0.0.1]) by relmlac2.idc.renesas.com (Postfix) with ESMTP id F15FB28070; Wed, 29 Mar 2017 20:45:10 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac2.idc.renesas.com with ESMTP id WAL05665; Wed, 29 Mar 2017 20:45:10 +0900 X-IronPort-AV: E=Sophos;i="5.36,241,1486393200"; d="scan'208";a="238967672" Received: from mail-pu1apc01lp0020.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.20]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 29 Mar 2017 20:45:10 +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=yU6PR33kJ1lluB8qxzGFJ2ZrTKX784ktADQp4F5QPls=; b=SbT7jQKsZDuGRzuK2W9FPvy1I+zN+jOj1cL3W1bArKKvvgM0Jt/V0qWy4ExyMES+Y1ImOup+N+F7UpGlj8o/DxmAFlIu0d4h0z2SaqyKniI/mT5DhhQEZkgWRLlOjJGTVxP44YNbPYoSJs2J7bKE7g1ZQ6SvDB2o6NCeyFFlT0U= 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 SG2PR06MB1694.apcprd06.prod.outlook.com (10.167.82.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.991.14; Wed, 29 Mar 2017 11:45:07 +0000 From: Yoshihiro Shimoda To: CC: , , , Yoshihiro Shimoda Subject: [PATCH v2 3/3] usb: gadget: udc: renesas_usb3: add support for usb role swap Date: Wed, 29 Mar 2017 20:42:54 +0900 Message-ID: <1490787774-5796-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490787774-5796-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1490787774-5796-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.144] X-ClientProxiedBy: TYXPR01CA0003.jpnprd01.prod.outlook.com (10.168.40.13) To SG2PR06MB1694.apcprd06.prod.outlook.com (10.167.82.136) X-MS-Office365-Filtering-Correlation-Id: 9bf2adf8-d661-4060-c299-08d476990cbf X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:SG2PR06MB1694; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB1694; 3:VYiLl235jzo0rZiETo8Wh0ed+PCGeP5YyeZDYzGyXhyb1xsecmW2Ypn7suRyQpj1GSNqG+Gehef6KCtdtEBn3yQrRIDPB9P5nHJJB8nbLUBmi0zYRDmryz6A+orBpVklQM7Uc/y5XJ5M4oXvpPMuLcQK67NXtHS8qE1cOzdOTOi8uFX1YqGX/+/72bQEAnxHKUbqfGiIhd4c8FwOhRJUzDV1Sy8G6IdlhA7v1DzhNfTevXN9g4EQ2jYylBYfHpuEu5J62KS9YWtQ7Ywkvm8CYFj44M0NmbqONZfQJNE7Eri/R/W0MjO5NXQ7D741UZSkfyER5t5bzM4a97JzlXYIBRmk7MYwcnB9cyfuGyDUtfI=; 25:sNzG1mNswlKvU0n/6PDLSQ3smZ9DsA+vrb44L5jXNmPkUXEadQo+8l12NU0To76cfG7nAkIOYsivQXJxWn4ns/KiGaI/8LZ2CZPWzLugHUbukI9Hlee7S19uGxxH4lqa6LBgxOYLzd4Kf9se1IjXOOXnXcA9dfJTHBhn1+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n6Dl+3afrDoWwXUo8Q2Qtzm1PHJqIhBnauZF 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)(93006041)(6055026)(6041248)(20161123562025)(20161123558025)(201703131423075)(201702281528075)(201703061421075)(201703061750075)(20161123560025)(20161123564025)(20161123555025)(6072148); SRVR:SG2PR06MB1694; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB1694; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB1694; 4:cxHtH3ARZ4jCkos+Mh7yapZ+/OYrZlC85wTz+3jtNd4K9mbRQ8e/9KS5EfaOLZdwErI66xZQGJ6sCRU0K8ZHHBZcotoXH2v7Fbxiva54ghh/9YVrFeLvxnf93xwAmJNiJjsCGTdv8O5gERPtgLX0MAO7k5NvIDi0jf8uKbienryQaEkWB/3CCq1+uAeSY7VkgWQBwhYkGVv7avC5Q97nOBo7Xa9MCdZINhro27P6Y7+n1XrsxmCw3Q2bSuSn7/on53r/j168BtuKyuDBteW/FMwLltIBBlk1r9nFQetRlppEsf+bRxMaJOsJ5zDgLi/YkIRtpkG4LM5LG4QJQObQ2uiAfnos/WUasRS01NDRdkv+412C3Pcr0BqLrEYlX7hYRJohgR8PnLqYkXYenKCYZLlkoVEqJWghg9fg5+SQi0umiC+8N3HDvBVWl6toe0jDFJdm7x0fEmbO7GLWO45lGx3866JBsfTrYRArCgzmjJEUD0UY8EmMxSWhB2bqb9L+svOh9KH3jts6saGdCTUzqZJmM0BJvZX4dTN6GtP/zqiSlUfM8mX/VtVgZsK6MzwE9QMZXbwS/pUFZhOfStOQCT8gqrE8yhMSfNMBdn4X0U/QheDzbQUmHhsSzEE5GkxzXO60Hl5DXv86VwlwKuVeDU/q8wylcOH/uX0/CdJgwaMdVvx8wkyt2zxd6jImAr3sLfoUZME2HLMflLKgjl3AoYF6svMcwt7OdnhEbo2SGeI41KmWHms3rNmxuKZdlDqbqPJaOyFnJ7jgPGzGJow2d6TcGx+DRD7CFc8GVU1shRms9Y3GIRLQMwz8Zg0siGBwOgtKBnOAaXGCBRmhT5FcZQ== X-Forefront-PRVS: 0261CCEEDF X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6069001)(6009001)(39860400002)(39410400002)(39850400002)(39840400002)(39400400002)(39450400003)(50944005)(6506006)(6116002)(3846002)(2906002)(53936002)(6486002)(54906002)(48376002)(2950100002)(2351001)(42882006)(6916009)(5660300001)(7736002)(189998001)(305945005)(50226002)(42186005)(6512007)(6666003)(110136004)(38730400002)(76176999)(107886003)(33646002)(36756003)(47776003)(78352004)(50466002)(66066001)(8676002)(4326008)(81166006)(5003940100001)(25786009)(50986999); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB1694; H:localhost.localdomain; FPR:; SPF:None; MLV:ovrnspm; PTR:InfoNoRecords; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB1694; 23:VZvA4gzk9z0EWExMv0dv9iYEkHTBTmjcO+K9J95QN?= =?us-ascii?Q?GGScbGaU9UA0to0w5xCwa+S8ByLbDhCdElpHj2I+SgxJhFcCJejeSTP1lhXd?= =?us-ascii?Q?7nnQklrnd5HM5TSDy59ulgCN6Y0Nz7CVSemAWJv1sSBtxKpNy56Ye5rWSX5s?= =?us-ascii?Q?uxVNbQl5zAFktnPK2NGno/dEI6v4WVH9E6Myz0Gm546GFBLpOeEe4zK7it6I?= =?us-ascii?Q?h5hKxxqZrwX6Cs2+3ZOaNKJPrWJoWxg2z/rNwbPDHHPasZT40r9LrnLF+8cw?= =?us-ascii?Q?ssTS1U8EqnCLU5G8aMEeDFJLnNtAGxkpYjYonHwQSZmqwIyP20/0vCNFXvQi?= =?us-ascii?Q?ZXuM1zphEg/gJ7JZ5pyxLwTsHBrSJC4OJeEfD9Aux/hZeC0UANF06OLbId0r?= =?us-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ppA/9sMxQUB2JJ/b50dd8ogVqu+KqIXiNFo4V7B4tdnitqdllrGRtMolkHlVxJJGL3SKap1PTINpDBx1KpRAjk/9aox3YXttf76fYqweYxiRVcsF0ExzWyjy03g= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2017 11:45:07.6575 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB1694 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 | 77 ++++++++++++++++++++++ 2 files changed, 92 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 3f04e57..5a4cd85 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 */ @@ -568,12 +573,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_connect(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); @@ -1831,11 +1853,59 @@ 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; + + 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; +} + +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); @@ -2038,6 +2108,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); @@ -2047,6 +2121,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);