From patchwork Mon Jan 19 14:44:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5659081 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 22A129F358 for ; Mon, 19 Jan 2015 14:44:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 54830202F8 for ; Mon, 19 Jan 2015 14:44:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC8622024F for ; Mon, 19 Jan 2015 14:44:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751357AbbASOou (ORCPT ); Mon, 19 Jan 2015 09:44:50 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:58581 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbbASOot (ORCPT ); Mon, 19 Jan 2015 09:44:49 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NIF00K3CIHFWU00@mailout3.w1.samsung.com>; Mon, 19 Jan 2015 14:48:51 +0000 (GMT) X-AuditID: cbfec7f4-b7f126d000001e9a-e1-54bd185e05b5 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 10.E8.07834.E581DB45; Mon, 19 Jan 2015 14:44:46 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NIF00ICVIAIYW40@eusync4.samsung.com>; Mon, 19 Jan 2015 14:44:46 +0000 (GMT) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Kyungmin Park , Robert Baldyga , Paul Zimmerman , Felipe Balbi , John Youn Subject: [PATCH] usb: dwc2: rework initialization of host and gadget in dual-role mode Date: Mon, 19 Jan 2015 15:44:36 +0100 Message-id: <1421678676-31266-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDJMWRmVeSWpSXmKPExsVy+t/xa7pxEntDDC4cVLM4eL/eYvfpS4wW Z5vesFvMOL+PyWLRslZmi7VH7rJbbJ8yncniweGd7A4cHn1bVjF6bNn/mdHj+I3tTB6fN8kF sERx2aSk5mSWpRbp2yVwZbReaGIquCBQ8a9xDlsD4z3eLkZODgkBE4lDu48wQthiEhfurWfr YuTiEBJYyigx4dcsdpCEkEAfk8Sr4zEgNpuAoUTX2y42EFtEwEFiydI7YA3MAm8ZJXY3b2QF SQgLREgcevCVuYuRg4NFQFVixb40kDCvgIfEwo8P2SGWyUn8f7mCaQIj9wJGhlWMoqmlyQXF Sem5hnrFibnFpXnpesn5uZsYISHyZQfj4mNWhxgFOBiVeHg1cvaECLEmlhVX5h5ilOBgVhLh DfgCFOJNSaysSi3Kjy8qzUktPsTIxMEp1cC44c2cd98UpC+mvQh2DZa2Wlj541qM39rGDczn w41Z1TWeHeK+b3WkZI6LyKxHV9pSAhf6fJsvlKQesHGqW9kqlT315ztU1klvPKtzUDrpkp+H 6+fNRoFurmqzpndNWrT1jc7zjwsOT73zbc4l4aY9VxXqw5/dvNxeLcxwXtB350oGi+Ydb7Wz lViKMxINtZiLihMBiCDUZe8BAAA= 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 --- 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);