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: 41319 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CF2AA244B0 for ; Fri, 21 Nov 2014 14:15:08 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf3069316wgh.1 for ; Fri, 21 Nov 2014 06:15:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=Aj3LtH3VL6Tg9UF5Y82RAwkrwKOcdtwoPT5PiAh+C0w=; b=FSVwM+75LUSNwzGtCiREPgidSSv0z3ejvxBs1jBIu3KMgklq+JSMBSswwWqk3Vr5S2 raP1IJ3OlV5ypdSG1As2GDgKvCHIsdOngzz69z8xzIFQPhaDJLSCmDZ3c8rGgcbdqhhd VmX7mmItiOl6eUWyWR/X7GfbD/bnsgvI0UQ9WHGxVXO64QDyuiAnGTHkhkVRmt5YRfOx AsJu69+OdCWVTbwbkUBGjmCStGtGvkXPOqRWqH6x5a9OVZZ+/G5/x5Ppde6xGKBH9Rap 7c5Hl1cj/UG5MxD19r9dT4i2uxS0b6R8XPiqM4IQyA7Bj/YbRx4PgEATrl013STmM9D3 v+Hg== X-Gm-Message-State: ALoCoQkDJP4Vk0bxAl4aT4XIL0XMBZYnlGxePcKJGcHlami+13ZVcAuIUQdioDb04c+8d/iDAOvO X-Received: by 10.112.72.106 with SMTP id c10mr952671lbv.15.1416579308111; Fri, 21 Nov 2014 06:15:08 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.227 with SMTP id ap3ls197746lac.60.gmail; Fri, 21 Nov 2014 06:15:07 -0800 (PST) X-Received: by 10.112.170.7 with SMTP id ai7mr4935352lbc.67.1416579307947; Fri, 21 Nov 2014 06:15:07 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id b2si5515391lbm.104.2014.11.21.06.15.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 06:15:07 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id b6so4153466lbj.30 for ; Fri, 21 Nov 2014 06:15:07 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr4962977lbc.34.1416579307407; Fri, 21 Nov 2014 06:15:07 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp97783lbc; Fri, 21 Nov 2014 06:15:06 -0800 (PST) X-Received: by 10.70.98.141 with SMTP id ei13mr7458329pdb.65.1416579305307; Fri, 21 Nov 2014 06:15:05 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ry1si8612684pab.172.2014.11.21.06.15.04 for ; Fri, 21 Nov 2014 06:15:05 -0800 (PST) Received-SPF: none (google.com: linux-usb-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755320AbaKUOPA (ORCPT + 3 others); Fri, 21 Nov 2014 09:15:00 -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-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: m.szyprowski@samsung.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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;