From patchwork Fri Oct 31 10:12:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 39876 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B99CD202FE for ; Fri, 31 Oct 2014 10:12:57 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf2579056lbj.8 for ; Fri, 31 Oct 2014 03:12:56 -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=eKQE7KADO6/JeyAlLbz+Ryd+2d1dwGai7wRrFTrsADU=; b=Hwjr14rhVwzRBoxpYEF13sZCgkfKXdxoPIUMr/czwaBvNw3LTAqaw9823C/AsBg6Qn xQt6v9ebyDcG0PrcWs7ZWFEgqTRgrIEtWZhXlW8qkNO9fNwxT8BtMYYbyPCCrGunCMJ+ pt+yzQRgj0G+xT+Y6wixfARiCYI7sfQsP6A6sAqMNIqoMP4WojaZxrylwVLufB3pTbS0 ojiD02n7vzy+box122KoTVvXukLZZZqn5rABdTHGtJnbw0nr/xtzElZqyWu5kICfp2Qg wnuIgL2rvcrKAx2+S5BKTCBXGDKEiH9K8uKMidteG5uSpbESKJr4X+uKbc1zuuJUmC5w dnmw== X-Gm-Message-State: ALoCoQmfLMnySx1e6Jy22n1Vk7e1qq/V+zD8TMpsvzgzNBTfkIfSZnPYaHGkcwA+F0xz4C9hPXfT X-Received: by 10.180.93.35 with SMTP id cr3mr481677wib.2.1414750376619; Fri, 31 Oct 2014 03:12:56 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.106 with SMTP id ln10ls411648lac.103.gmail; Fri, 31 Oct 2014 03:12:56 -0700 (PDT) X-Received: by 10.152.198.204 with SMTP id je12mr25383193lac.61.1414750376443; Fri, 31 Oct 2014 03:12:56 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id rt5si15985022lbb.2.2014.10.31.03.12.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 03:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id ge10so5734027lab.8 for ; Fri, 31 Oct 2014 03:12:56 -0700 (PDT) X-Received: by 10.112.14.69 with SMTP id n5mr24998483lbc.34.1414750376256; Fri, 31 Oct 2014 03:12:56 -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 c5csp176561lbz; Fri, 31 Oct 2014 03:12:55 -0700 (PDT) X-Received: by 10.68.229.193 with SMTP id ss1mr24059797pbc.16.1414750374226; Fri, 31 Oct 2014 03:12:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yw4si8866292pab.178.2014.10.31.03.12.53 for ; Fri, 31 Oct 2014 03:12:54 -0700 (PDT) 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 S1757668AbaJaKMw (ORCPT + 3 others); Fri, 31 Oct 2014 06:12:52 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:48051 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757442AbaJaKMv (ORCPT ); Fri, 31 Oct 2014 06:12:51 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NEB00BV40I6W220@mailout1.w1.samsung.com>; Fri, 31 Oct 2014 10:15:42 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-b3-545360a096ed Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 19.AF.04619.0A063545; Fri, 31 Oct 2014 10:12:48 +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:48 +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 2/2] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Date: Fri, 31 Oct 2014 11:12:34 +0100 Message-id: <1414750354-19571-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1414750354-19571-1-git-send-email-m.szyprowski@samsung.com> References: <54535F82.7020406@samsung.com> <1414750354-19571-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMJMWRmVeSWpSXmKPExsVy+t/xK7oLEoJDDB5tkLY4eL/e4vULQ4uz TW/YLWac38dksWhZK7PF2iN32S22T5nOZPHg8E52Bw6Pvi2rGD227P/M6HH8xnYmj8+b5AJY orhsUlJzMstSi/TtErgyHl9ayVRwVK6i++VC9gbGeZJdjJwcEgImEotnvWWDsMUkLtxbD2Rz cQgJLGWUeHNkAQuE08ckMXtLIzNIFZuAoUTX2y6wDhEBB4klS++A2cwCPxklLv3gA7GFBTIk JvyYClbPIqAqMbmnjx3E5hXwkGhq6GSE2CYn8f/lCqYuRg4OTgFPiYM75UHCQgKZEvef3mGf wMi7gJFhFaNoamlyQXFSeq6hXnFibnFpXrpecn7uJkZIQH3Zwbj4mNUhRgEORiUe3hWSwSFC rIllxZW5hxglOJiVRHhF3IFCvCmJlVWpRfnxRaU5qcWHGJk4OKUaGAMDg6SqZq1d2fr5Wc/6 /5kC1y5XrxH21F/tFVYRumHRzp0qe7Y8NbE++P7AutlefD4HM/dV9v6SajildE2b95X75PWx zV2vP07PYaj4F3PKmtklm+/k05uvLk9t1vxnEtVlw2Q9+X/Lbz6tTxt3SfV578vJe9UkXnCM nTlhYXQpa4R/1LvcuUosxRmJhlrMRcWJAB4pxgsGAgAA 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.215.49 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: , Suspend/resume code assumed that the gadget was always enabled and connected to usb bus. This means that the actual state of the gadget (soft-enabled/disabled or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue. Signed-off-by: Marek Szyprowski --- drivers/usb/dwc2/core.h | 4 +++- drivers/usb/dwc2/gadget.c | 41 +++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 58732a9a0019..a1aa9ecf052e 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -211,7 +211,9 @@ struct s3c_hsotg { u8 ctrl_buff[8]; struct usb_gadget gadget; - unsigned int setup; + unsigned int setup:1; + unsigned int connected:1; + unsigned int enabled:1; unsigned long last_rst; unsigned int address; struct s3c_hsotg_ep *eps; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index a2e4272a904e..e61bb1c4275d 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -2931,6 +2931,8 @@ static int s3c_hsotg_udc_start(struct usb_gadget *gadget, spin_lock_irqsave(&hsotg->lock, flags); s3c_hsotg_init(hsotg); s3c_hsotg_core_init_disconnected(hsotg); + hsotg->enabled = 1; + hsotg->connected = 0; spin_unlock_irqrestore(&hsotg->lock, flags); dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); @@ -2972,6 +2974,8 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget, hsotg->driver = NULL; hsotg->gadget.speed = USB_SPEED_UNKNOWN; + hsotg->enabled = 0; + hsotg->connected = 0; spin_unlock_irqrestore(&hsotg->lock, flags); @@ -3015,9 +3019,11 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) spin_lock_irqsave(&hsotg->lock, flags); if (is_on) { clk_enable(hsotg->clk); + hsotg->connected = 1; s3c_hsotg_core_connect(hsotg); } else { s3c_hsotg_core_disconnect(hsotg); + hsotg->connected = 0; clk_disable(hsotg->clk); } @@ -3670,16 +3676,18 @@ static int s3c_hsotg_suspend(struct platform_device *pdev, pm_message_t state) dev_info(hsotg->dev, "suspending usb gadget %s\n", hsotg->driver->driver.name); - spin_lock_irqsave(&hsotg->lock, flags); - s3c_hsotg_core_disconnect(hsotg); - s3c_hsotg_disconnect(hsotg); - hsotg->gadget.speed = USB_SPEED_UNKNOWN; - spin_unlock_irqrestore(&hsotg->lock, flags); + if (hsotg->enabled) { + int ep; - s3c_hsotg_phy_disable(hsotg); + spin_lock_irqsave(&hsotg->lock, flags); + if (hsotg->connected) + s3c_hsotg_core_disconnect(hsotg); + s3c_hsotg_disconnect(hsotg); + hsotg->gadget.speed = USB_SPEED_UNKNOWN; + spin_unlock_irqrestore(&hsotg->lock, flags); + + s3c_hsotg_phy_disable(hsotg); - if (hsotg->driver) { - int ep; for (ep = 0; ep < hsotg->num_of_eps; ep++) s3c_hsotg_ep_disable(&hsotg->eps[ep].ep); @@ -3705,18 +3713,19 @@ static int s3c_hsotg_resume(struct platform_device *pdev) dev_info(hsotg->dev, "resuming usb gadget %s\n", hsotg->driver->driver.name); + if (hsotg->enabled) { clk_enable(hsotg->clk); ret = regulator_bulk_enable(ARRAY_SIZE(hsotg->supplies), - hsotg->supplies); - } - - s3c_hsotg_phy_enable(hsotg); + hsotg->supplies); - spin_lock_irqsave(&hsotg->lock, flags); - s3c_hsotg_core_init_disconnected(hsotg); - s3c_hsotg_core_connect(hsotg); - spin_unlock_irqrestore(&hsotg->lock, flags); + s3c_hsotg_phy_enable(hsotg); + spin_lock_irqsave(&hsotg->lock, flags); + s3c_hsotg_core_init_disconnected(hsotg); + if (hsotg->connected) + s3c_hsotg_core_connect(hsotg); + spin_unlock_irqrestore(&hsotg->lock, flags); + } mutex_unlock(&hsotg->init_mutex); return ret;