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: 5104241 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 767439F374 for ; Mon, 20 Oct 2014 10:46:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 950AA201D3 for ; Mon, 20 Oct 2014 10:46:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B51E620176 for ; Mon, 20 Oct 2014 10:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753629AbaJTKqI (ORCPT ); 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-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }