From patchwork Thu Oct 16 12:58:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 38803 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A7FDB20973 for ; Thu, 16 Oct 2014 12:58:38 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id m15sf1878047wgh.3 for ; Thu, 16 Oct 2014 05:58:37 -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=2qiU5Q+M5acZPYgAHBzT+nfGJ+KhubirsgnjUDonqsk=; b=A4f9RmliU/vzqhEovPXF7A5FiI+AcefEpGnrgkwK0hMfWcdqC74s9zwNAuVs1wyE7+ 9D1JCAwHOl8olqTShIXI2cyXeVt3kyoIqjftku2AqaA6IgA4r1A2wrDVhPwHRLXJmzMV XJq0gGINYwDfet58SDhAxO7pOrdu+icpI0uyltPs5y+eMw1uIxnYyX2oyhe9+d/KMG4X z+/TVFEtAeRR9Q3mO/zL6P05A54QXb8dPy22GDb208Me/SkzS4GjhzSh7VELayIApgqr Ln0pNTVH4+kCgGbBcjiN30omRHtMSCU69E3yLLoltLLM4VcM8a8HMiGyNWo4iyamty7/ Ajpg== X-Gm-Message-State: ALoCoQnQ5BfPEJXlBo0Ewxh4Tzo/5oEE/bdPQkwhbQuivS1nGDQxGAjppFUdJhcirBnLasRsIeL7 X-Received: by 10.194.242.36 with SMTP id wn4mr251889wjc.4.1413464317909; Thu, 16 Oct 2014 05:58:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.68 with SMTP id is4ls159189lac.6.gmail; Thu, 16 Oct 2014 05:58:37 -0700 (PDT) X-Received: by 10.112.182.1 with SMTP id ea1mr1553250lbc.16.1413464317743; Thu, 16 Oct 2014 05:58:37 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com [209.85.217.171]) by mx.google.com with ESMTPS id tj1si32960135lbb.73.2014.10.16.05.58.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 Oct 2014 05:58:37 -0700 (PDT) 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 z12so2737877lbi.2 for ; Thu, 16 Oct 2014 05:58:37 -0700 (PDT) X-Received: by 10.112.173.134 with SMTP id bk6mr1499548lbc.66.1413464317617; Thu, 16 Oct 2014 05:58:37 -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 c5csp33455lbz; Thu, 16 Oct 2014 05:58:36 -0700 (PDT) X-Received: by 10.70.90.108 with SMTP id bv12mr1244644pdb.158.1413464316149; Thu, 16 Oct 2014 05:58:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yk7si11920691pab.135.2014.10.16.05.58.35 for ; Thu, 16 Oct 2014 05:58:36 -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 S1752467AbaJPM6d (ORCPT + 3 others); Thu, 16 Oct 2014 08:58:33 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:57455 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751704AbaJPM6c (ORCPT ); Thu, 16 Oct 2014 08:58:32 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) 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 <0NDJ00EVCG6BYC80@mailout1.w1.samsung.com>; Thu, 16 Oct 2014 14:01:23 +0100 (BST) X-AuditID: cbfec7f5-b7f776d000003e54-fd-543fc0f50aa4 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 72.FC.15956.5F0CF345; Thu, 16 Oct 2014 13:58:29 +0100 (BST) 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 <0NDJ00F34G17BB00@eusync2.samsung.com>; Thu, 16 Oct 2014 13:58:28 +0100 (BST) 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 Subject: [PATCH 9/9] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Date: Thu, 16 Oct 2014 14:58:05 +0200 Message-id: <1413464285-24172-10-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1413464285-24172-1-git-send-email-m.szyprowski@samsung.com> References: <1413464285-24172-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrNJMWRmVeSWpSXmKPExsVy+t/xK7pfD9iHGBx8wmvx+oWhxdmmN+wW M87vY7JYtKyV2WLtkbvsFtunTGeyeHB4J7sDu0ffllWMHlv2f2b0+LxJLoA5issmJTUnsyy1 SN8ugSuj4e8ttoL9chV7Vu9jbmBsl+xi5OSQEDCRuPThPDOELSZx4d56NhBbSGApo8SLbo4u Ri4gu49JYuu5nSwgCTYBQ4mut11gRSICDhJLlt5hAyliFrjDKLF+/ycmkISwQKrEpX87GUFs FgFViSUL14HZvAKeEpNvfmOF2CYn8f/lCrB6TqD4rs0rmSE2e0icvzqdcQIj7wJGhlWMoqml yQXFSem5RnrFibnFpXnpesn5uZsYIQH0dQfj0mNWhxgFOBiVeHg1gu1DhFgTy4orcw8xSnAw K4nwLpoEFOJNSaysSi3Kjy8qzUktPsTIxMEp1cB4SshNX6hX/JPVjzYm7QN3LPXvOWRZ3y7o kz6z7Ox9tZUzZOMux3WeNflf0Xcx8bXWybL1K/M+OQj4hSxvW3m7+bZVqNOxxSdD+R4etFDu 1PE2bJ9Sdf9tCI+AvoXTRFuZi3YVBn2XWJz0p+18k1lS2/bJRVBR93+t0L+3cvNLNxgn6Z3i uazEUpyRaKjFXFScCACKKPNt/gEAAA== 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: , 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 | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 29 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 052b1a857291..83fe123ede05 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); @@ -2963,6 +2965,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); @@ -3004,9 +3008,11 @@ static int s3c_hsotg_pullup(struct usb_gadget *gadget, int is_on) 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); } @@ -3655,16 +3661,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); @@ -3682,21 +3690,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; }