From patchwork Fri Nov 21 14:14:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 5355321 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1CC99C11AC for ; Fri, 21 Nov 2014 14:15:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F32A2017E for ; Fri, 21 Nov 2014 14:15:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 315EC20172 for ; Fri, 21 Nov 2014 14:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751175AbaKUOO7 (ORCPT ); Fri, 21 Nov 2014 09:14:59 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:13831 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751596AbaKUOO6 (ORCPT ); Fri, 21 Nov 2014 09:14:58 -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 <0NFE000UR7PNFG30@mailout3.w1.samsung.com>; Fri, 21 Nov 2014 14:17:48 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-bb-546f48df96c2 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id DE.62.04619.FD84F645; Fri, 21 Nov 2014 14:14:55 +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 <0NFE00CB17KQS570@eusync1.samsung.com>; Fri, 21 Nov 2014 14:14:55 +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 , Krzysztof Kozlowski , Felipe Balbi Subject: [PATCH v6 2/3] usb: dwc2/gadget: add mutex to serialize init/deinit calls Date: Fri, 21 Nov 2014 15:14:48 +0100 Message-id: <1416579289-31939-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1416579289-31939-1-git-send-email-m.szyprowski@samsung.com> References: <1416579289-31939-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCJMWRmVeSWpSXmKPExsVy+t/xy7r3PfJDDHqvy1kcvF9v8fqFocXZ pjfsFjPO72OyWLSsldli7ZG77Bbbp0xnsnhweCe7A4dH35ZVjB5b9n9m9Dh+YzuTx+dNcgEs UVw2Kak5mWWpRfp2CVwZjyauYi64rlRxfusVlgbG7zJdjJwcEgImEi/X/GSFsMUkLtxbz9bF yMUhJLCUUeLY603sEE4fk8SdvV+ZQKrYBAwlut52sYHYIgIOEkuW3gGzmQV+Mkpc+sEHYgsL hEhcfL8MrJ5FQFXi2LzX7CA2r4CHRPvPL2wQ2+Qk/r9cAVbDKeApce3zSxYQWwioZs6CSYwT GHkXMDKsYhRNLU0uKE5KzzXUK07MLS7NS9dLzs/dxAgJqS87GBcfszrEKMDBqMTDe8AxN0SI NbGsuDL3EKMEB7OSCG+5cH6IEG9KYmVValF+fFFpTmrxIUYmDk6pBsa5etrpL0uLN3RYXbA2 CvjSdLGyMTz2sRGTppvgN/WEI0/YXmX+kt71b3Ll6zOqOv4tT29+ChF8Y7Ct/P29I2sPnDa9 dOmN27ZjawOaZ/9bcPCFaPZju88zWl7PVJieurZab8l0v+MBGtNiE78uD1gsJXtu2dqVuyzz 5C2L7jIpF3b8nGzp/oxLiaU4I9FQi7moOBEA6JDrBgcCAAA= 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 This patch adds mutex, which protects initialization and deinitialization procedures against suspend/resume methods. This mutex will be needed by the updated suspend/resume calls, which tracks gadget state. Signed-off-by: Marek Szyprowski Acked-by: Paul Zimmerman --- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 19 +++++++++++++++++++ drivers/usb/dwc2/platform.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 2cb0ac31ae86..6b197550c133 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -576,6 +576,7 @@ struct dwc2_hsotg { struct regulator_bulk_data supplies[ARRAY_SIZE(s3c_hsotg_supply_names)]; spinlock_t lock; + struct mutex init_mutex; void *priv; int irq; struct clk *clk; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index c0673ad4c4ad..baba8a862826 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2866,6 +2867,7 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, return -EINVAL; } + mutex_lock(&hsotg->init_mutex); WARN_ON(hsotg->driver); driver->driver.bus = NULL; @@ -2891,9 +2893,12 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); + mutex_unlock(&hsotg->init_mutex); + return 0; err: + mutex_unlock(&hsotg->init_mutex); hsotg->driver = NULL; return ret; } @@ -2914,6 +2919,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) if (!hsotg) return -ENODEV; + mutex_lock(&hsotg->init_mutex); + /* all endpoints should be shutdown */ for (ep = 1; ep < hsotg->num_of_eps; ep++) s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); @@ -2931,6 +2938,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) clk_disable(hsotg->clk); + mutex_unlock(&hsotg->init_mutex); + return 0; } @@ -2959,6 +2968,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, is_on); + mutex_lock(&hsotg->init_mutex); spin_lock_irqsave(&hsotg->lock, flags); if (is_on) { clk_enable(hsotg->clk); @@ -2970,6 +2980,7 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) hsotg->gadget.speed = USB_SPEED_UNKNOWN; spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_unlock(&hsotg->init_mutex); return 0; } @@ -3572,6 +3583,8 @@ int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) unsigned long flags; int ret = 0; + mutex_lock(&hsotg->init_mutex); + if (hsotg->driver) dev_info(hsotg->dev, "suspending usb gadget %s\n", hsotg->driver->driver.name); @@ -3594,6 +3607,8 @@ int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) clk_disable(hsotg->clk); } + mutex_unlock(&hsotg->init_mutex); + return ret; } EXPORT_SYMBOL_GPL(s3c_hsotg_suspend); @@ -3603,6 +3618,8 @@ int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) unsigned long flags; int ret = 0; + mutex_lock(&hsotg->init_mutex); + if (hsotg->driver) { dev_info(hsotg->dev, "resuming usb gadget %s\n", hsotg->driver->driver.name); @@ -3619,6 +3636,8 @@ int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) s3c_hsotg_core_connect(hsotg); spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_unlock(&hsotg->init_mutex); + return ret; } EXPORT_SYMBOL_GPL(s3c_hsotg_resume); diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 57eb8a3e022b..ec5658ac52ba 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -212,6 +213,7 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->dr_mode = of_usb_get_dr_mode(dev->dev.of_node); spin_lock_init(&hsotg->lock); + mutex_init(&hsotg->init_mutex); retval = dwc2_gadget_init(hsotg, irq); if (retval) return retval;