From patchwork Wed Apr 18 08:10:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10347531 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 7BFB66031B for ; Wed, 18 Apr 2018 08:11:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71331284CE for ; Wed, 18 Apr 2018 08:11:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 651DF2859A; Wed, 18 Apr 2018 08:11:38 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 B9955284CE for ; Wed, 18 Apr 2018 08:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753541AbeDRILd (ORCPT ); Wed, 18 Apr 2018 04:11:33 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:21424 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753704AbeDRIKw (ORCPT ); Wed, 18 Apr 2018 04:10:52 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie3.idc.renesas.com with ESMTP; 18 Apr 2018 17:10:50 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 463AC94CCE; Wed, 18 Apr 2018 17:10:50 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.48,464,1517842800"; d="scan'208";a="278555618" Received: from mail-pu1apc01lp0019.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.19]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-GCM-SHA384; 18 Apr 2018 17:10:48 +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=jeIj2MKXVJ7yTHCd1vwb5j4hVeL4ZU7Vcbhb8wUTCic=; b=Se1yDPYiJhF5S/HgRDn0tsvOGZMdiiAWYW5NEadQUmj8LZ0PigbKt3VWjQ7PYIUGWmO4wr4FTfaT5YvHSg3r9BSdKUtoCr42fhwZjozpzcP2wriETsrFD41cfa+JPOXPYZok1oZyAwEDgoHtWCe5q0hiCpfD94EJMawxlDflgYM= Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=renesas.com; Received: from localhost.localdomain (211.11.155.138) by SG2PR06MB0982.apcprd06.prod.outlook.com (2a01:111:e400:5213::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.14; Wed, 18 Apr 2018 08:10:42 +0000 From: Yoshihiro Shimoda To: gregkh@linuxfoundation.org, robh+dt@kernel.org, mark.rutland@arm.com, frowand.list@gmail.com Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com, andy.shevchenko@gmail.com, p.zabel@pengutronix.de, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC 09/11] usb: gadget: udc: renesas_usb3: add support for a usb role switch Date: Wed, 18 Apr 2018 17:10:03 +0900 Message-Id: <1524039005-30618-10-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524039005-30618-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1524039005-30618-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: OSAPR01CA0023.jpnprd01.prod.outlook.com (2603:1096:603:2a::35) To SG2PR06MB0982.apcprd06.prod.outlook.com (2a01:111:e400:5213::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(48565401081)(2017052603328)(7153060)(7193020); SRVR:SG2PR06MB0982; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 3:YCKt84rZvLeqBjzG4UBQXnpHnM66xC2NR7mJgOEBC/HsIXcTb0G2kjXVt3qOrwIT+F7dGnOnMNhBJJW0K3BGNBLexHrgSXWnMfwrInKc8AqJUo4hMIwuJjG9ZVmrq9CS8Un3UBdD35Dfv3fcTOj4wzxcNcj9YgSfu/XcjnTh5Osc9d2Y286RmYF3j+3IqQRg/eWplYPLRjmzN8w34PKkGbzzf+QeyishUwyHd05wwyDKqVVfjOfcnfSrqYqsU/6U; 25:YxuexT5oQVSPByT+j2vuJH6wotgtWer53sT+5c64GnEehoVJPiqgKVy1z1hjGmB75oqepfZndJBAlL7PM03B84/+tdsJ/TRsiDGUddMKmzDotTNua6rbz+S2hMMf5vxq1vs1czFtdzhJfmRe10iHNpZQfG+xrTjMbCShQykPhP0LDgqr/5Sh2NihGvKALigdu9modkDMCb865WEaSHi2x27TLL7aCiS+XRbM/WmLVWEnlICMpl6yvQNpnqBxPJMjvnnUPMZBYH0IdA9zb+7nlVcLp7VLWcGli1OLaC8KitiZ4TbtUezPDAjPJ/epdtRJNfx7gGCS7i/VqXqC76vYvQ==; 31:PELTE4tNkwrt0JOjndtzo3UoqOSZGxhKR4VH4gQ2Wuxd2CyAqLVyqad14oG1V0cIpnyvI+0dXs154nctarob+CmDkr20MbJIQg50UKPHpALrkWPymkilw6U+gJt2G4IH+OMSi/bysYEJp6Q7141LZPu+qL1ldzQd8ZlEsbTkAvrBVupUw5KHQRdHrShQa8CvH9tRMDHkqAPfHJbdFoBBi4wHvCo26XRxhJfuHHA60oY= X-MS-TrafficTypeDiagnostic: SG2PR06MB0982: X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 20:a0PMmZQ6NFpYi4jTZvobjpV+WxB6235+gOwv2tWufJ/1OMU6NNsJY7CsrU48bNc4UY3RVpo1SDK4htAa4tydCHVCn/C49nkHWIi6IujMzWOPEQ7cX/9CTpuZwlzTp0jh7QXC813kPek+NxvA7wzh4hlJu6LVrKa3a1SQw0nasFi+53k9giCr0SRUQXnSCyD8nET3yMX3yeunmWvlv/HhU0ML/Dq9yN0Td7I40AfUJtASLGbGUYL5kev5oV9GgurJQVkmyjdsVpB2CyoNgVvMzFFtqTMcecB+z4gt70+RIwip+xwMqLEG5KsykqH8QkhH9rxVk48LUR8vUrqIm2nZRNgejx327u/vryYD8V3hdxpIwj+uNlFXlgxDNZ3gZBhvJdFrizDv7z2z4lk/DDMoJR/35sr5cF8yut+fv4tuwehuVUfj5lDm6pEjjKJU/61oDFCfPll1jJOWYluiq8m85XQdMHxA/3/fc/FCAc/UriW+hWrnK8MNr7PC4dYQoz7v; 4:7UvutV9tfPBIiHz2Zwd60V8QqOoaM/ny3Go+vrgT0vpKYSiInRWPCc0udMoeu4enUjZYxR9SVRGqpytvswiVhCQ8r7aJG9VjUtwtGFSAacqm3IB2Tdnht8+RBKJJZBXN1xqtOfJ2oAXEihQNBsTbtFmEu+rerdDI2tNk22wROs12M68zkvAeNlr85tDHylA7hopEAZLXOM0hXKGywl32WCTEqV9t09Zng13ky3Y8xqybGimns+d3AghQ02ss6A7mtxEa+NkV35kLfu3Dt1DEDA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231232)(944501327)(52105095)(93006095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(6072148)(201708071742011); SRVR:SG2PR06MB0982; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB0982; X-Forefront-PRVS: 06469BCC91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39860400002)(346002)(376002)(396003)(366004)(39380400002)(7416002)(956004)(2616005)(6116002)(446003)(3846002)(47776003)(8936002)(97736004)(66066001)(50466002)(4326008)(2906002)(76176011)(42882007)(53936002)(52116002)(6512007)(476003)(107886003)(386003)(11346002)(6506007)(51416003)(59450400001)(36756003)(25786009)(316002)(6666003)(305945005)(16586007)(5660300001)(7736002)(48376002)(78352004)(8676002)(6486002)(50226002)(16526019)(81166006)(39060400002)(498600001)(26005)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB0982; H:localhost.localdomain; FPR:; SPF:None; LANG:en; MLV:ovr; PTR:InfoNoRecords; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB0982; 23:JjDcNJaZZAC+6i1B/WObRYPddghzZUadR/NvNOMxE?= =?us-ascii?Q?mOcllUAue871G7pJACRj9LMbUeVcUvSir19ulWP+ZX1wvser1a1wWT0nPLKJ?= =?us-ascii?Q?ta/pWd+GOP9jLq+HM5HChD3FGhFhlphVvTafAelt51ydr3Zn+tlbFkE3Sb4M?= =?us-ascii?Q?zop6H90oHvyTwZVj9OILEA19PwebwfAXbJYBb5DHwcwOuByTPOGfGFxLER/b?= =?us-ascii?Q?dzneN6e1ilZV9QnosdHd74hVOBoB6kE1hzE0A2KITLhE9ehPFdBlnZ5oKGko?= =?us-ascii?Q?kTL/j2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GLPOfapg=3D=3D?= X-Microsoft-Antispam-Message-Info: AcENEmHQJoTKaDJ9+0gzzAQL11psY0NjXPZpOW4b8bvONpxk4/FxHPnCBLD5U+LVDvHTmc07vMhVV3FgMhRoZMtprxMCmIgbdxTQr8k5jZJs9eaCQM7TfQJLPq0mYw3QOFJrkNMNy0BRGnE8ZEHJ/nnPxZXF28TRQykb/ab5Szb8F9BBEeHhLtTV3jGOs0yy X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 6:0XQogQZAR2P2P0oR05//LClPLiE5H6U/0RfTxkJkJw3/ZnJwAwObxC/bzBTQaUJho+YZTHgweUcrPYLECpQvEbB8KJUvSxetUekBZWwMtpSCVS7dLeOwnH2drcexqph8sd1OmwDzVut+nykB2UFaVSY3K7Q9Y4tct1LKG7PBlyYm4Yz5C9Gm3eyIby0MNIoWTKUb5n+PHeCbwQYuM0H14Xtn8DDx7BFFye+cRCK3PDaFg5822YItM9jPFoU9HztY6XaGFbG5g8gmG6JJUo+ZouMU3AKbT4MZO5k35pZoNpeXAiI/U165cwcG0Kj6yG8gNSDYc7CgVp9BpEJ9VbdbywTCplyMlKFg4EytriQr4MKAnfGutBuqihNHzpXzV9Pv/ASeapSPZkqb4zMwMAj01kMolh2ZoCbSP9xjfwbmyaRDWrfTwpl7xnnJEX7PYIYURemb6gZikF9qAfeXLg9Tgw==; 5:JckyZhZzXBI0Utg8pskzqZ/x9VVt5ezJrLs5EeKxmDemcuKie8uofnYhxk2l1zXl+PWJ0dJAUo99rDTNRjP3QkRX3M/HZMH0CRAjFel3UnhAaqFBg+qjzb9YgbvSoeiVgcIbRzdNqrxJonHewDQuuBeM4KJsgUToQv3yhKKjVa4=; 24:KuD4molaK5leCLu6XRfK++q9HwM57jGJHBYsYjG7PT52TzVqNNhHZlCdTj2K5GPI/AyMns1A631Dk7C2t//pPwR/nOGx3aDtw3mNSGXtLJA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 7:kE3fUMtQVBAUMj11bVXvIa6KnasLwntqokMwyeO8Lcs12YES4RoEufBaIsC5qLWqtr9D832tXe0Rc0qqLf9J2qbCfNlu7m2pmlNDBTJwPL7MBQU1IZleR3QD1aLBpkkbnc9Nr5/wd0B1qlk/OjH2imc2nJ+/IW5W6tPi565k3OC/jzH0aJebQpWORHVnBvq33eSxYW5bya9FZqS8VcCspEPMTwSEmvSnc4UTXw07s8Df3NEWT1L5KEy7RfzO4VX2; 20:BIS2O04gIq1bpK9c19+WPk9amIpXnaEhW4aafJAOcsUfcmocmy08f3uRjGTINuXJvIDLyZtpv3zPzJknPjpwWVyNYiOAZrkyTSgUusbIIFPxhScQ2u68pluz2680xIm5ixlhQiB0bJUhGqHmccB3YMp259iHd5VF0F2Ek5I5hX4= X-MS-Office365-Filtering-Correlation-Id: b0665795-d744-4a21-5d25-08d5a503e1d2 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2018 08:10:42.2281 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0665795-d744-4a21-5d25-08d5a503e1d2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB0982 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 support for a usb role switch driver. And then, this driver uses the usb role switch APIs instead of hardware access to initialize usb host side at specific timings. Signed-off-by: Yoshihiro Shimoda --- drivers/usb/gadget/udc/Kconfig | 1 + drivers/usb/gadget/udc/renesas_usb3.c | 34 ++++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig index 0875d38..7e4a5dd 100644 --- a/drivers/usb/gadget/udc/Kconfig +++ b/drivers/usb/gadget/udc/Kconfig @@ -193,6 +193,7 @@ config USB_RENESAS_USB3 tristate 'Renesas USB3.0 Peripheral controller' depends on ARCH_RENESAS || COMPILE_TEST depends on EXTCON && HAS_DMA + select USB_ROLE_SWITCH help Renesas USB3.0 Peripheral controller is a USB peripheral controller that supports super, high, and full speed USB 3.0 data transfers. diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 409cde4..38dd759 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -23,6 +23,7 @@ #include #include #include +#include /* register definitions */ #define USB3_AXI_INT_STA 0x008 @@ -330,6 +331,7 @@ struct renesas_usb3 { struct usb_gadget gadget; struct usb_gadget_driver *driver; + struct usb_role_switch *role_sw; /* Optional */ struct extcon_dev *extcon; struct work_struct extcon_work; struct phy *phy; @@ -454,7 +456,11 @@ static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num) static bool usb3_is_host(struct renesas_usb3 *usb3) { - return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON); + if (usb3->role_sw) + return usb_role_switch_get_role(usb3->role_sw) == + USB_ROLE_HOST ? true : false; + else + return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON); } static void usb3_init_axi_bridge(struct renesas_usb3 *usb3) @@ -645,10 +651,16 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3) static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) { - if (host) - usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); - else - usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); + if (usb3->role_sw) { + enum usb_role role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; + + usb_role_switch_set_role(usb3->role_sw, role); + } else { + if (host) + usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); + else + usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); + } } static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) @@ -663,8 +675,8 @@ 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); + spin_lock_irqsave(&usb3->lock, flags); usb3_vbus_out(usb3, a_dev); /* for A-Peripheral or forced B-device mode */ if ((!host && a_dev) || @@ -2238,6 +2250,10 @@ static int renesas_usb3_start(struct usb_gadget *gadget, /* hook up the driver */ usb3->driver = driver; + usb3->role_sw = usb_role_switch_get(usb3_to_dev(usb3)); + if (IS_ERR_OR_NULL(usb3->role_sw)) + usb3->role_sw = NULL; + if (usb3->phy) phy_init(usb3->phy); @@ -2260,6 +2276,8 @@ static int renesas_usb3_stop(struct usb_gadget *gadget) if (usb3->phy) phy_exit(usb3->phy); + usb_role_switch_put(usb3->role_sw); + pm_runtime_put(usb3_to_dev(usb3)); return 0; @@ -2632,6 +2650,10 @@ static int renesas_usb3_probe(struct platform_device *pdev) if (ret < 0) goto err_add_udc; + ret = devm_of_platform_populate(&pdev->dev); + if (ret < 0) + goto err_dev_create; + ret = device_create_file(&pdev->dev, &dev_attr_role); if (ret < 0) goto err_dev_create;