From patchwork Tue Mar 10 12:41:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5977631 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DBBA1BF440 for ; Tue, 10 Mar 2015 12:41:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1A6D720225 for ; Tue, 10 Mar 2015 12:41:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CB8320219 for ; Tue, 10 Mar 2015 12:41:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752224AbbCJMlW (ORCPT ); Tue, 10 Mar 2015 08:41:22 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:52296 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751391AbbCJMlV (ORCPT ); Tue, 10 Mar 2015 08:41:21 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NKZ008QAY3J1N70@mailout2.w1.samsung.com>; Tue, 10 Mar 2015 12:45:19 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-45-54fee5de0628 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 3D.8F.07834.ED5EEF45; Tue, 10 Mar 2015 12:38:54 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NKZ00DM1XWR8650@eusync1.samsung.com>; Tue, 10 Mar 2015 12:41:19 +0000 (GMT) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Robert Baldyga , Paul Zimmerman , Felipe Balbi , John Youn Subject: [PATCH RESEND] usb: dwc2: rework initialization of host and gadget in dual-role mode Date: Tue, 10 Mar 2015 13:41:10 +0100 Message-id: <1425991270-30629-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBJMWRmVeSWpSXmKPExsVy+t/xy7r3nv4LMZjZKWZx8H69xe7Tlxgt Zpzfx2SxaFkrs8XaI3fZLbZPmc5k8eDwTnYHdo++LasYPbbs/8zocfzGdiaPz5vkAliiuGxS UnMyy1KL9O0SuDJaLzQxFVwQqPjXOIetgfEebxcjJ4eEgInE768trBC2mMSFe+vZuhi5OIQE ljJKfF7YwwLh9DFJXG7uZQKpYhMwlOh628UGYosIOEgsWXoHrINZ4ACjxPSdM4A6ODiEBeIl tt6xBKlhEVCVaF99mgXE5hXwkPi0cCLUNjmJ/y9XME1g5F7AyLCKUTS1NLmgOCk911CvODG3 uDQvXS85P3cTIyQ0vuxgXHzM6hCjAAejEg/vzeh/IUKsiWXFlbmHGCU4mJVEeEuPAoV4UxIr q1KL8uOLSnNSiw8xMnFwSjUwMv9teFXzoVTu2R0X2x06vpprzM7fFb7xu5fL/zbfxCvZlXH/ s4q2vZ1yqpitaufcDId5fCwfr13PsdzyScGoqXM683UpHY5rXcyf7iwtbpVK/XHg07zGdu1l p3gCTZbbLebiUvHTV84o5jfaO7VZu0ijP9FbJ3ryDOPLB571Ju7b9el2yL3LSizFGYmGWsxF xYkA3AHZmesBAAA= Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If device is configured to work only in HOST or DEVICE mode, there is no point in initializing both subdrivers. This patch also fixes resource leakage if host subdriver fails to initialize. Signed-off-by: Marek Szyprowski Acked-by: John Youn --- drivers/usb/dwc2/core.h | 2 ++ drivers/usb/dwc2/platform.c | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 7a70a1349334..f93b06daef97 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -570,6 +570,8 @@ struct dwc2_hsotg { struct dwc2_core_params *core_params; enum usb_otg_state op_state; enum usb_dr_mode dr_mode; + unsigned int hcd_enabled:1; + unsigned int gadget_enabled:1; struct phy *phy; struct usb_phy *uphy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 6a795aa2ff05..ee0b0b06d0fc 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -121,8 +121,10 @@ static int dwc2_driver_remove(struct platform_device *dev) { struct dwc2_hsotg *hsotg = platform_get_drvdata(dev); - dwc2_hcd_remove(hsotg); - s3c_hsotg_remove(hsotg); + if (hsotg->hcd_enabled) + dwc2_hcd_remove(hsotg); + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); return 0; } @@ -214,12 +216,23 @@ static int dwc2_driver_probe(struct platform_device *dev) spin_lock_init(&hsotg->lock); mutex_init(&hsotg->init_mutex); - retval = dwc2_gadget_init(hsotg, irq); - if (retval) - return retval; - retval = dwc2_hcd_init(hsotg, irq, params); - if (retval) - return retval; + + if (hsotg->dr_mode != USB_DR_MODE_HOST) { + retval = dwc2_gadget_init(hsotg, irq); + if (retval) + return retval; + hsotg->gadget_enabled = 1; + } + + if (hsotg->dr_mode != USB_DR_MODE_PERIPHERAL) { + retval = dwc2_hcd_init(hsotg, irq, params); + if (retval) { + if (hsotg->gadget_enabled) + s3c_hsotg_remove(hsotg); + return retval; + } + hsotg->hcd_enabled = 1; + } platform_set_drvdata(dev, hsotg);