From patchwork Fri Oct 31 10:12:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 39875 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 59EFB202FE for ; Fri, 31 Oct 2014 10:12:51 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id l18sf412100wgh.8 for ; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) 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=ZPGhVcmrp6FV8liJzcIC+NLhrKVmZVcUp1fgnBbAkYk=; b=GJqltWtUgSHlAQpAxNpv4iHhNbTIx0Xjhs8sOvZsvCrk/a8AzRnCsr//z62+j/XTJM PtdvayXt7BAGmr3H+YS96upFgOSuSbRoW3WGof6Ur7yvF7a6rE5rxNe2g+SJxPUwc/a8 tiSZzBwdwAe4Nas2avv1yt8E2XZv6KAe2HiR8gAoedSwfurU91LbE3uf4sVK5Sl/8i8U qyJPtv4rfNightEVW6Ns9J+gOQj2M6jhMFK1Ux7jUxz6iJr3PL/nPFlokD2QKPjQv3O3 f7neTDYiF8kTWe8by3TionaJOzReOERuNbE4SP9vuSQ3fu2nrS2BjOE71a0IaPuEy9w7 hnwA== X-Gm-Message-State: ALoCoQkRMwn56rsHxjxSw4H3u3QMQxnFemmB+LhMTp0UTpnQArpTjRG54UbcYeisF/NJNUTHfk+F X-Received: by 10.112.32.163 with SMTP id k3mr174228lbi.17.1414750370494; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.72 with SMTP id q8ls358736laq.98.gmail; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) X-Received: by 10.152.42.172 with SMTP id p12mr25124941lal.11.1414750370259; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id ei3si15896295lad.84.2014.10.31.03.12.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 03:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so6493307lbj.9 for ; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) X-Received: by 10.112.97.135 with SMTP id ea7mr25276465lbb.46.1414750370099; Fri, 31 Oct 2014 03:12:50 -0700 (PDT) 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.84.229 with SMTP id c5csp176551lbz; Fri, 31 Oct 2014 03:12:49 -0700 (PDT) X-Received: by 10.70.130.47 with SMTP id ob15mr24030420pdb.112.1414750368206; Fri, 31 Oct 2014 03:12:48 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id uz17si8957518pab.56.2014.10.31.03.12.47 for ; Fri, 31 Oct 2014 03:12:48 -0700 (PDT) Received-SPF: none (google.com: linux-samsung-soc-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 S1756896AbaJaKMq (ORCPT + 3 others); Fri, 31 Oct 2014 06:12:46 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:43953 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756230AbaJaKMq (ORCPT ); Fri, 31 Oct 2014 06:12:46 -0400 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 <0NEB00AWI0HZGR20@mailout3.w1.samsung.com>; Fri, 31 Oct 2014 10:15:35 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-9b-5453609be6a9 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id A2.AF.04619.B9063545; Fri, 31 Oct 2014 10:12:43 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync2.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0NEB007QG0D3LE80@eusync2.samsung.com>; Fri, 31 Oct 2014 10:12:43 +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 v3 1/2] usb: dwc2/gadget: add mutex to serialize init/deinit calls Date: Fri, 31 Oct 2014 11:12:33 +0100 Message-id: <1414750354-19571-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <54535F82.7020406@samsung.com> References: <54535F82.7020406@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMJMWRmVeSWpSXmKPExsVy+t/xK7qzE4JDDPp+MlkcvF9v8fqFocXZ pjfsFjPO72OyWLSsldli7ZG77Bbbp0xnsnhweCe7A4dH35ZVjB5b9n9m9Dh+YzuTx+dNcgEs UVw2Kak5mWWpRfp2CVwZ+47HFuyVrfi09hJzA+M/8S5GTg4JAROJb4unMkPYYhIX7q1n62Lk 4hASWMoo0dywgBnC6WOS+Px1FwtIFZuAoUTX2y42EFtEwEFiydI7YDazwE9GiUs/+EBsYYEQ ie/vH7KD2CwCqhJPf58B28Ar4CHxY9ocqG1yEv9frmACsTkFtCW+9G8FiwsJaEn8fNbPOIGR dwEjwypG0dTS5ILipPRcQ73ixNzi0rx0veT83E2MkID6soNx8TGrQ4wCHIxKPLwrJINDhFgT y4orcw8xSnAwK4nwirgDhXhTEiurUovy44tKc1KLDzEycXBKNTC2F0bt3Wxm8HyS1dfFEVeN 979ZYrjmg77A04+vNLeuf+XYH9Tpv8LZ/e8lwR8X0tJyNBllDxd8KeCefcX3wCOuuXYz6yRq ZXxmBbcxdaU5yWnGzki9k+8n1mb+QNlZ94fcH16Nci3GGRUXpmxarday0ursod99Mc27LNYE XlLZX13w+uw/B3MlluKMREMt5qLiRAA7PMSZBgIAAA== Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-samsung-soc@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.178 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. Signed-off-by: Marek Szyprowski Acked-by: Paul Zimmerman --- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 9f77b4d1c5ff..58732a9a0019 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -187,6 +187,7 @@ struct s3c_hsotg { struct s3c_hsotg_plat *plat; spinlock_t lock; + struct mutex init_mutex; void __iomem *regs; int irq; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index d8dda39c9e16..a2e4272a904e 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -2908,6 +2909,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; @@ -2933,9 +2935,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; } @@ -2957,6 +2962,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); @@ -2974,6 +2981,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, clk_disable(hsotg->clk); + mutex_unlock(&hsotg->init_mutex); + return 0; } @@ -3002,6 +3011,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); @@ -3013,6 +3023,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; } @@ -3507,6 +3518,7 @@ static int s3c_hsotg_probe(struct platform_device *pdev) } spin_lock_init(&hsotg->lock); + mutex_init(&hsotg->init_mutex); hsotg->irq = ret; @@ -3652,6 +3664,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) 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); @@ -3674,6 +3688,8 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) clk_disable(hsotg->clk); } + mutex_unlock(&hsotg->init_mutex); + return ret; } @@ -3683,7 +3699,9 @@ static int s3c_hsotg_resume(struct platform_device *pdev) 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); @@ -3699,6 +3717,8 @@ static int s3c_hsotg_resume(struct platform_device *pdev) s3c_hsotg_core_connect(hsotg); spin_unlock_irqrestore(&hsotg->lock, flags); + mutex_unlock(&hsotg->init_mutex); + return ret; }