From patchwork Mon Oct 20 10:45:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 39040 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 89CE0203C5 for ; Mon, 20 Oct 2014 10:46:15 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id ge10sf2318897lab.9 for ; Mon, 20 Oct 2014 03:46:14 -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=BDDl0pV0M+Rj6vVDfiyQr3n97n5Hpg56hjm33Xmgbb4=; b=mBt4L5kiNO4MvZI3mMTnwVWqxYIE48MWBxgNIeebRMzv+oYcwTdTaQ3A8ksiY3ZmTc mzoJMxY9aaRNxHw2ybm9EYN8Zm0TUFlyc4Wq06iiZ/WvhP0P7rK+9mvkJzzinr2k9RjZ /COhhZ43h8HwWDbxcVsgLx4cxBWden6iv0dgLR7Ixu4tki4/K4Qcu92IrOsYklH81Ll+ IaItEXL/Hm3LjW/Vx/p5d8MOgXYZ5lJuw+w6Bla07kdNzIa2vSiRalfOfPPKiuR+JxDf hrylkued4OSLQCBmwkxQS2ec1TzaomA79GAXqmQf4tgcBAkM2B54O+o8D2a0uaSupcWj 2lVA== X-Gm-Message-State: ALoCoQl45sOJNZ60sjcgj8bned9lPKShbtS7nzGKwHdWrYnnAAZsNpBB2OmCS+Wa5jl+jSRP9ruc X-Received: by 10.112.217.102 with SMTP id ox6mr178965lbc.19.1413801974365; Mon, 20 Oct 2014 03:46:14 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.170.133 with SMTP id am5ls462787lac.54.gmail; Mon, 20 Oct 2014 03:46:14 -0700 (PDT) X-Received: by 10.112.63.70 with SMTP id e6mr2146784lbs.93.1413801974217; Mon, 20 Oct 2014 03:46:14 -0700 (PDT) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id m8si13669979lah.97.2014.10.20.03.46.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 20 Oct 2014 03:46:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id pn19so3647253lab.14 for ; Mon, 20 Oct 2014 03:46:14 -0700 (PDT) X-Received: by 10.152.116.102 with SMTP id jv6mr15216479lab.40.1413801974125; Mon, 20 Oct 2014 03:46:14 -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 c5csp278589lbz; Mon, 20 Oct 2014 03:46:13 -0700 (PDT) X-Received: by 10.68.231.69 with SMTP id te5mr27104963pbc.9.1413801972547; Mon, 20 Oct 2014 03:46:12 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5si7471476pdl.134.2014.10.20.03.46.11 for ; Mon, 20 Oct 2014 03:46:12 -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 S1753632AbaJTKqI (ORCPT + 3 others); Mon, 20 Oct 2014 06:46:08 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:16271 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753541AbaJTKpy (ORCPT ); Mon, 20 Oct 2014 06:45:54 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NDQ00MYAOP5PZ10@mailout2.w1.samsung.com>; Mon, 20 Oct 2014 11:48:41 +0100 (BST) X-AuditID: cbfec7f5-b7f956d000005ed7-54-5444e7e01184 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 14.92.24279.0E7E4445; Mon, 20 Oct 2014 11:45:52 +0100 (BST) 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 <0NDQ009U7OK7MS20@eusync4.samsung.com>; Mon, 20 Oct 2014 11:45:52 +0100 (BST) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Felipe Balbi , Kyungmin Park , Robert Baldyga , Paul Zimmerman , Krzysztof Kozlowski Subject: [PATCH v2 10/10] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Date: Mon, 20 Oct 2014 12:45:40 +0200 Message-id: <1413801940-31086-11-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1413801940-31086-1-git-send-email-m.szyprowski@samsung.com> References: <1413801940-31086-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCJMWRmVeSWpSXmKPExsVy+t/xa7oPnruEGMz5rW9x8H69xesXhhZn m96wW8w4v4/JYtGyVmaLtUfusltsnzKdyeLB4Z3sDhwefVtWMXps2f+Z0eP4je1MHp83yQWw RHHZpKTmZJalFunbJXBl/Dz7hL1glXzF6Z33mRoYH0t2MXJySAiYSMy79JIdwhaTuHBvPVsX IxeHkMBSRomWjetZIJw+Jom2ZzOYQarYBAwlut52sYHYIgIOEkuW3gGzmQV+MkpMnmoDYgsL ZEls/TOTFcRmEVCV6Nm9GKyXV8BTYuKGg2wQ2+Qk/r9cwQRicwLF37yYxghiCwl4SGxa/pJl AiPvAkaGVYyiqaXJBcVJ6blGesWJucWleel6yfm5mxghIfV1B+PSY1aHGAU4GJV4eHeYuYQI sSaWFVfmHmKU4GBWEuHtvg0U4k1JrKxKLcqPLyrNSS0+xMjEwSnVwGiRkvx1012ldtltDwO9 FsvNP69h6Lx607YLvryPLx4+Yvv0tfQXx5miBY4iSZtORZT3m0c9Tf8n8e7B4a/Po40dHwaI PZtftZ/NIEVdvla4a9JH10qdeK0jiRo77p173fUvefLd9XN/nHBMk/b70thhL8H2osg1WMB5 TX+e1Lpk+9ytqydlSimxFGckGmoxFxUnAgASejMyBwIAAA== 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.41 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 | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index bf015ab3b44c..3648b76a18b4 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -210,7 +210,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; struct s3c_hsotg_ep *eps; }; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 0d34cfc71bfb..c6c6cf982c90 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -2925,6 +2925,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); @@ -2961,6 +2963,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); @@ -2999,11 +3003,14 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) dev_dbg(hsotg->dev, "%s: is_on: %d\n", __func__, 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); } @@ -3652,16 +3659,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); @@ -3679,21 +3688,23 @@ static int s3c_hsotg_resume(struct platform_device *pdev) unsigned long flags; int ret = 0; - if (hsotg->driver) { + if (hsotg->driver) 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); - } + hsotg->supplies); - s3c_hsotg_phy_enable(hsotg); + s3c_hsotg_phy_enable(hsotg); - spin_lock_irqsave(&hsotg->lock, flags); - s3c_hsotg_core_init_disconnected(hsotg); - s3c_hsotg_core_connect(hsotg); - spin_unlock_irqrestore(&hsotg->lock, flags); + 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); + } return ret; }