From patchwork Tue May 22 12:01:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10418261 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 0C35C6053B for ; Tue, 22 May 2018 12:02:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF2AF28C49 for ; Tue, 22 May 2018 12:02:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3C8728C55; Tue, 22 May 2018 12:02:01 +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=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 813A628C4E for ; Tue, 22 May 2018 12:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751425AbeEVMB6 (ORCPT ); Tue, 22 May 2018 08:01:58 -0400 Received: from relmlor4.renesas.com ([210.160.252.174]:51633 "EHLO relmlie3.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751339AbeEVMBx (ORCPT ); Tue, 22 May 2018 08:01:53 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie3.idc.renesas.com with ESMTP; 22 May 2018 21:01:52 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id 98FC679F6E; Tue, 22 May 2018 21:01:52 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.49,430,1520866800"; d="scan'208";a="280262388" Received: from mail-ty1jpn01lp0180.outbound.protection.outlook.com (HELO JPN01-TY1-obe.outbound.protection.outlook.com) ([23.103.139.180]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 22 May 2018 21:01:52 +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:X-MS-Exchange-SenderADCheck; bh=kfQjKcEN4hI0ryK3dUcNL2nddoVr1Tm6BVnxb7OsU4w=; b=p+sCOiNUedI+Qqc0rkpQuKVuL376OZ4sV065lBA5W1fPxuWCPsczgRvzrHVZsXn1DfEVFzPw1FMhTHbFjLXBn2XieVAU2Tj0Gw2XRzHvTLx+KLmYyXQH6Wlq4pGFUUnMi9e+LvF8OI102MqeKG4yPgFsU1eno6qmhP7qTmV7jY8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.138) by OSBPR01MB2293.jpnprd01.prod.outlook.com (2603:1096:603:26::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.776.11; Tue, 22 May 2018 12:01:49 +0000 From: Yoshihiro Shimoda To: gregkh@linuxfoundation.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com, andy.shevchenko@gmail.com, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC v4 3/4] usb: gadget: udc: renesas_usb3: use usb role switch API Date: Tue, 22 May 2018 21:01:08 +0900 Message-Id: <1526990469-20739-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526990469-20739-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1526990469-20739-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: TY2PR01CA0016.jpnprd01.prod.outlook.com (2603:1096:404:a::28) To OSBPR01MB2293.jpnprd01.prod.outlook.com (2603:1096:603:26::14) 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:OSBPR01MB2293; X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 3:J1jtVNdTCtnOrx432z5kbGKlOMyaPCj5NY8dAkfJY3UTQ+SDtUG4pYNAYKWsgz9+Wf/tr6ErMDZno8ajaOeXckXUYFnyjCJd3tTwTU+VzTCN8hf7IHRzukwejBHKmgjGi31+m4NgP1z2yCI3yimEGyA9nrl5mMvhaAlAailP2sAcgGpRsceNRSOrRDnFEDrki2slkvOy6Vrti5CJPT6AnxCHV28BZQhncnQABXdbD9yWas+b3ymtShxlSpqOhFp1; 25:bPcl36a0DdrScEgFvntCtytwrgklfnUJF5LEAz2zEPj2hCs5kgCTblXFOHIRGmGYoZaDADQKsGtYSHuRmNsPhjFokF+S0f56gIJUMi6uukbmW+o1DI4bJ1q8ksc7l23rLjrUXm+07UzYBU7CM3on9z2W62DCepyKw2seiN/Lqyb0bmk4/48SYlp0D3T4I8ssruftjm4S58idMBPniJNJsopw03fhuwrfO+N+mm9xoVhsiFYDgSh3VlT0Q+cWHdNRoSlbHfn4lLodNep2jSt4yhMBQOS5MChi3mrkpm8TMTAKWTlh3bxHNLu+0OM9HXz1WdJDw9CuPb7Szag8k7j5kw==; 31:Ey4HLs7B3Z3OIl1FgCbBLEGlFI4Q010LPRdfXH93+6x93+tKkE3gWt8c4kbEoLq4kgCNRjn/UcYMNVormq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S-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231254)(944501410)(52105095)(93006095)(3002001)(6055026)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011)(7699016); SRVR:OSBPR01MB2293; BCL:0; PCL:0; RULEID:; SRVR:OSBPR01MB2293; X-Forefront-PRVS: 0680FADD48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39860400002)(346002)(396003)(39380400002)(366004)(376002)(199004)(189003)(16526019)(97736004)(6116002)(3846002)(8936002)(66066001)(7736002)(81166006)(81156014)(36756003)(8676002)(48376002)(78352004)(305945005)(50466002)(316002)(16586007)(50226002)(51416003)(52116002)(5890100001)(498600001)(76176011)(42882007)(5660300001)(6666003)(956004)(11346002)(446003)(2906002)(2616005)(386003)(39060400002)(6506007)(4326008)(476003)(106356001)(68736007)(486006)(25786009)(47776003)(26005)(53936002)(6512007)(107886003)(6486002)(105586002)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:OSBPR01MB2293; 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: =?us-ascii?Q?1; OSBPR01MB2293; 23:ucy3HYvwWDYK695IJsN7eUJm20ALydmb7saByDNC5?= =?us-ascii?Q?jJaoujuPekT5Wx9lh6tuLDQ8fbdsq4VPdLWn/rXZLofnwtzetpSNocT4Rx4H?= =?us-ascii?Q?6SXWpXsjGlr0Kjnn+0QTmN89LZ1eSzI6TC8eGNdmizv4v6AdY5Jlsh2i0Fuf?= =?us-ascii?Q?YCki4nP/6wRg7j4/ngdibOBav37XFPZMpTRQYaOqBOMgDqbhM/QR868aOiNm?= =?us-ascii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Mhcheds15pcueR6F4ewELs7+?= =?us-ascii?Q?4OOk6JC1lAHrEymImBToYs2Slnl1uIPiVFsvhovxUPTY76XdBvn8EtW9hkWe?= =?us-ascii?Q?+tN4BuxTJ605UF4tQerJ1WGE1bN+WgXFeuNCo8JAKmcniaxlkiv0BvFpZt39?= =?us-ascii?Q?hhv7a98UNa2Eu6HZBVfkd1YocklMvQd6K5ZbFKS+NBYghHc6SWtxyhoRqwGn?= =?us-ascii?B?QT09?= X-Microsoft-Antispam-Message-Info: gRxqxe6BwkkgpkZDxivtOv9ModGYMag//4L3IdDqj+d18lbOu5JiMLWXKrCdPt2PoJkcIAhfkwbS0HfiTnyyTzj8gRJG/wccgRM1aKNs3Vdl8aORe+j4XsFVDH28XM6Ci6nfNWdoTCO7muZIqHqe4CiCoiNqPVE9LJL0VkO/VikIsy584va8A58FwYeWg9Zk X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 6:6WB2O7lw05gCZSlLbNahmo6h0Kn4yhnOHqLNgygSAjx8GOh3dnO3aodYzWUnC51PKhMcG9t4Kc6mwG5fXAw6EDKkIOwyMd+RGFWF9tXTmbRpzJASDAPq53PXPIdDr9apntMyeac0gM/NrlEPSjrkJd1M48DVi9TFQ3Aocvrit8xronRTgRw4Vi1Ywl1aVnf/dF9okvnGqY15A9vC0DhqRMIH6u4LnW2dpjv8npZYsxif1sC1t5+wv/Yxj5z/huz7i/R5kp22P61UOO792aWR8qAA0spIJjyVOnx1ug37nkTxynfumpo1287QwtDa5mVP6jsI7XKRYGgxZSEmESaO3RPXv/e76dMgdU0uGGiXpud3LWH1TBIq28J+DwtqkDQUVr4p8aLyIZJCwSf0hHeQsQSTXpbxPUTeyhyHFjgIq0o5gc6jTJau/PXPPHrdgRaWAQDlwqYC5UJKzCwtXndWLg==; 5:Xn2LTA/TA2hNU3rYhlO03pMnLJhpPSl5ksKLNn0Utf+f3Be7/O04R893hK8rkEwgYIyv2o1InSJTq1scbxqQRofX9K95rMGxX5XutE/GzIQixZ3/dLaOhb9QC5RC9WxZaFMlwINSBRqSJg6OOO6+njdU6T2vhvz0lBe8L7W6uH4=; 24:muMPE81/fAFFHcfaS9LvXYkpS5Q4PR8paFCgZgfR9eVs1py0UEaCZYLzgotCVujn42ygQ+8OwCQlUOQcyhyHz6islV1PVfQvp+2JX0VuGvc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; OSBPR01MB2293; 7:a9aikMCIvh2Utle3J/zKhhiz+O/sbgGUgBvdJRdGFJ7vBMuXEnBYJa9Rr2Zkdll100D3x/X+O/eOfTxG/6bvKwiot81Z2pCBwBj5o8w+ely10sQaLgHa3+hs6alecjAXML75rFeJH2c/6F3dA3L3mT8BLJSCb8lHx9NcqeQG6WPz2chY5MU/FGzu+1miV/PM9hpf9mu/cjhXdzpgyOrR3RjWMWxHJLXP6Mi+iVUW4HsRPHRiaCNaBE1SN/MjFIDE; 20:8gQbFSkFEFv8YlMJ7vDNC14/n/GRBhktz0xL+KSOrhI01MuMEgAa8a8J06lTx5WBUAEX7w1UV9lFjjuQ6sTNjekq6EGvsUpemmG0cjdCJSFFfCSPFrC3z9+7N9tpk+ulDqlSGvss6ATi47vd+EAL4xUiPzBvVcOo3ptendPIIj4= X-MS-Office365-Filtering-Correlation-Id: d4ab41a9-37e4-4180-e071-08d5bfdbccae X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2018 12:01:49.3361 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4ab41a9-37e4-4180-e071-08d5bfdbccae X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: OSBPR01MB2293 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 uses usb role switch APIs if the register suceeeded. Signed-off-by: Yoshihiro Shimoda --- drivers/usb/gadget/udc/renesas_usb3.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c index 9667a5e..d6c11c9 100644 --- a/drivers/usb/gadget/udc/renesas_usb3.c +++ b/drivers/usb/gadget/udc/renesas_usb3.c @@ -338,6 +338,8 @@ struct renesas_usb3 { struct usb_role_switch *role_sw; struct device *host_dev; + struct work_struct role_work; + enum usb_role role; struct renesas_usb3_ep *usb3_ep; int num_usb3_eps; @@ -655,7 +657,15 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3) } } -static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) +static void renesas_usb3_role_work(struct work_struct *work) +{ + struct renesas_usb3 *usb3 = container_of(work, struct renesas_usb3, + role_work); + + usb_role_switch_set_role(usb3->role_sw, usb3->role); +} + +static void _usb3_set_mode(struct renesas_usb3 *usb3, bool host) { if (host) usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); @@ -663,6 +673,16 @@ static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON); } +static void usb3_set_mode(struct renesas_usb3 *usb3, bool host) +{ + if (usb3->role_sw) { + usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; + schedule_work(&usb3->role_work); + } else { + _usb3_set_mode(usb3, host); + } +} + static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable) { if (enable) @@ -2328,10 +2348,10 @@ static int renesas_usb3_role_switch_set(struct device *dev, pm_runtime_get_sync(dev); if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) { device_release_driver(host); - usb3_set_mode(usb3, false); + _usb3_set_mode(usb3, false); } else if (cur_role == USB_ROLE_DEVICE && role == USB_ROLE_HOST) { /* Must set the mode before device_attach of the host */ - usb3_set_mode(usb3, true); + _usb3_set_mode(usb3, true); /* This device_attach() might sleep */ if (device_attach(host) < 0) dev_err(dev, "device_attach(usb3_port) failed\n"); @@ -2726,6 +2746,7 @@ static int renesas_usb3_probe(struct platform_device *pdev) if (ret < 0) goto err_dev_create; + INIT_WORK(&usb3->role_work, renesas_usb3_role_work); usb3->role_sw = usb_role_switch_register(&pdev->dev, &renesas_usb3_role_switch_desc); if (!IS_ERR(usb3->role_sw)) {