From patchwork Fri Nov 21 14:14:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 41321 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8B3A5244B0 for ; Fri, 21 Nov 2014 14:15:17 +0000 (UTC) Received: by mail-la0-f71.google.com with SMTP id s18sf3098913lam.6 for ; Fri, 21 Nov 2014 06:15:12 -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=dRfV1Il8ibCJUuHX8B5fF1TzdzGz3a/Lj5AYX40rjis=; b=M+pIGHHQmQOtfFswyBb5T4P3gm1+Fln3GXhroBmNhcAA6/ZVAETfpKAjekCoPG78+J D137mfvPHR2L1s3r+VHWPJfYrrKYgzlJTN2onwo2dz1TeQT55KsnsKWWsWNV/QMgPWAE cFHsaDF4bh6glnT4TSbWFE3zwKl2eD9oF9TFW+g4n5A9IfXPtVme26X5ocAsoVLhmttJ D+EhotDQS/qdiHxBydz7bLIq269hgceMc9hXCilqVyQsijkOEiNvWze487wxYShtWHIp Lmmptl9EhzMcmxuNtPunYOnsZKwVG+aIjPKo73JTXxIwiTkSGGBzQFKMmvLZHsCe/Z9F dmcw== X-Gm-Message-State: ALoCoQnZYxCIH49pMkUeW5q6iHajmIeMWOuf7C69bx8/dHi7KOvjx3gqOdOZ1GoDid0ZJbIW9+xI X-Received: by 10.112.55.10 with SMTP id n10mr952889lbp.14.1416579311798; Fri, 21 Nov 2014 06:15:11 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.133 with SMTP id ue5ls207054lac.6.gmail; Fri, 21 Nov 2014 06:15:11 -0800 (PST) X-Received: by 10.152.28.227 with SMTP id e3mr5023508lah.54.1416579311426; Fri, 21 Nov 2014 06:15:11 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id jj7si5564673lbc.65.2014.11.21.06.15.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 06:15:11 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id p9so3077495lbv.14 for ; Fri, 21 Nov 2014 06:15:10 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr4871665lbc.66.1416579310208; Fri, 21 Nov 2014 06:15:10 -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 ew9csp97791lbc; Fri, 21 Nov 2014 06:15:08 -0800 (PST) X-Received: by 10.68.246.164 with SMTP id xx4mr7746811pbc.64.1416579307328; Fri, 21 Nov 2014 06:15:07 -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.06 for ; Fri, 21 Nov 2014 06:15:07 -0800 (PST) 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 S1751596AbaKUOPF (ORCPT + 4 others); Fri, 21 Nov 2014 09:15:05 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:15284 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755232AbaKUOO7 (ORCPT ); Fri, 21 Nov 2014 09:14:59 -0500 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 <0NFE006FM7PPK030@mailout1.w1.samsung.com>; Fri, 21 Nov 2014 14:17:49 +0000 (GMT) X-AuditID: cbfec7f5-b7f956d000005ed7-46-546f48dfa5ae Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 9E.FC.24279.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 3/3] usb: dwc2/gadget: rework suspend/resume code to correctly restore gadget state Date: Fri, 21 Nov 2014 15:14:49 +0100 Message-id: <1416579289-31939-3-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+NgFvrMJMWRmVeSWpSXmKPExsVy+t/xy7r3PfJDDJ48t7E4eL/e4vULQ4uz TW/YLWac38dksWhZK7PF2iN32S22T5nOZPHg8E52Bw6Pvi2rGD227P/M6HH8xnYmj8+b5AJY orhsUlJzMstSi/TtErgyGrfZF0xQqGj8s4i1gfG7VBcjJ4eEgInE48Mf2CFsMYkL99azdTFy cQgJLGWUeLRvFwuE08ckcWfvVyaQKjYBQ4mut11sILaIgIPEkqV3wGxmgZ+MEpd+8IHYwgIZ Erse/WYGsVkEVCVOtX8Bq+EV8JA49XcuK8Q2OYn/L1eAzeQU8JS49vklC4gtBFQzZ8EkxgmM vAsYGVYxiqaWJhcUJ6XnGukVJ+YWl+al6yXn525ihATU1x2MS49ZHWIU4GBU4uG9MCs3RIg1 say4MvcQowQHs5IIb7lwfogQb0piZVVqUX58UWlOavEhRiYOTqkGxi19Nlckpt7znlp9tyBQ Viyzt6T60NT4A3XXZyq1XXqfd+WeVuTao7N/RB6+zbWS96Lsbf3aK/5//xSXzOH7Uca3gfmX 4/bYB9ETHApXHmn/Ivr7mm6ztOzS39lyknXu26fsXi/iKKfc6Xt5TozIgYVvJzNMPCLxajd3 T+qnk7nKXMo2W79meiqxFGckGmoxFxUnAgDv/wvyBgIAAA== 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.169 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 started and enabled to connect to usb bus. This means that the actual state of the gadget (started/stopped or connected/disconnected) was not correctly preserved on suspend/resume cycle. This patch fixes this issue. Signed-off-by: Marek Szyprowski --- Since hsotg->driver is always set in udc_start and cleared in udc_stop, it has been also used to track if gadget has been start (in previous version a 'enabled' bool entry was used for this purpose). Because 'connected' bool entry has been used to track usb cable connection state, to aboid confusion, I reused 'enable' bool entry to track soft-disconnect mode. --- drivers/usb/dwc2/core.h | 3 ++- drivers/usb/dwc2/gadget.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 6b197550c133..7a70a1349334 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -688,8 +688,9 @@ struct dwc2_hsotg { u8 ctrl_buff[8]; struct usb_gadget gadget; + unsigned int enabled:1; unsigned int connected:1; - unsigned int setup; + unsigned int setup:1; unsigned long last_rst; struct s3c_hsotg_ep *eps; #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */ diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index baba8a862826..1ecc5ac16244 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -2889,6 +2889,7 @@ 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 = 0; spin_unlock_irqrestore(&hsotg->lock, flags); dev_info(hsotg->dev, "bound driver %s\n", driver->driver.name); @@ -2929,6 +2930,7 @@ static int s3c_hsotg_udc_stop(struct usb_gadget *gadget) hsotg->driver = NULL; hsotg->gadget.speed = USB_SPEED_UNKNOWN; + hsotg->enabled = 0; spin_unlock_irqrestore(&hsotg->lock, flags); @@ -2972,9 +2974,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->enabled = 1; s3c_hsotg_core_connect(hsotg); } else { s3c_hsotg_core_disconnect(hsotg); + hsotg->enabled = 0; clk_disable(hsotg->clk); } @@ -3585,20 +3589,21 @@ int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg) mutex_lock(&hsotg->init_mutex); - if (hsotg->driver) + if (hsotg->driver) { + int ep; + 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); + spin_lock_irqsave(&hsotg->lock, flags); + if (hsotg->enabled) + 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); + 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); @@ -3626,16 +3631,16 @@ int s3c_hsotg_resume(struct dwc2_hsotg *hsotg) 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->enabled) + s3c_hsotg_core_connect(hsotg); + spin_unlock_irqrestore(&hsotg->lock, flags); + } mutex_unlock(&hsotg->init_mutex); return ret;