From patchwork Mon Nov 17 08:59:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 40880 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCC6E21F5F for ; Mon, 17 Nov 2014 08:59:48 +0000 (UTC) Received: by mail-la0-f69.google.com with SMTP id gq15sf484730lab.0 for ; Mon, 17 Nov 2014 00:59:47 -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=GGX+kGHr66HrRdsglao4kofdcnmlsUHzR2xXhdV9uCc=; b=CnDzkzlSNtsnUYPGm8EL4Nvl7+e3GMpomSYniuB4+w3QPK7A+3C/wg56awGfsX2LmY 7DXlGRgB+EkJ/rJL0DZgB93BF8Jak9QosbWtIwi285qBsFG4JqOn36WWPnvvx9qVX+MR afdiYa3zSKokUpn1pS0KdeVwPzfJ/4jHQrzeHfCgzA/KGIMlc75Fn27neIpXddZ2eQWh JBzKk6uacP0zIbFgnvIPL7RSRor2Xgty7r4a3uZrzW7T4Q8myBUe/8XGTuP+eWp4P0+P RcQ5Er4LWo1aPfb67wPsMd/AwkZetqKtVNPKdzr9IUSrh6Pn1GQE+L8OGWQa52iI0CgX ZW0Q== X-Gm-Message-State: ALoCoQnYZt+Pnbi+/hH4duYSk4E3vrpCsGa1mJx/55INiy1TnqVbWTt7Nznvl2Oeh9Gpbxe0PzFQ X-Received: by 10.112.147.131 with SMTP id tk3mr7400436lbb.2.1416214787755; Mon, 17 Nov 2014 00:59:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.115.135 with SMTP id jo7ls1178056lab.108.gmail; Mon, 17 Nov 2014 00:59:47 -0800 (PST) X-Received: by 10.112.16.168 with SMTP id h8mr12484879lbd.41.1416214787607; Mon, 17 Nov 2014 00:59:47 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id a3si9512819lbv.43.2014.11.17.00.59.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 00:59:47 -0800 (PST) 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 ge10so18037157lab.36 for ; Mon, 17 Nov 2014 00:59:47 -0800 (PST) X-Received: by 10.152.116.102 with SMTP id jv6mr12191960lab.40.1416214787481; Mon, 17 Nov 2014 00:59:47 -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 ew9csp1123448lbc; Mon, 17 Nov 2014 00:59:46 -0800 (PST) X-Received: by 10.70.64.134 with SMTP id o6mr2073270pds.153.1416214785631; Mon, 17 Nov 2014 00:59:45 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id py3si34575424pac.210.2014.11.17.00.59.45 for ; Mon, 17 Nov 2014 00:59:45 -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 S1751607AbaKQI7o (ORCPT + 4 others); Mon, 17 Nov 2014 03:59:44 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:34397 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbaKQI7n (ORCPT ); Mon, 17 Nov 2014 03:59:43 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NF600BU1EGAWD40@mailout3.w1.samsung.com>; Mon, 17 Nov 2014 09:02:34 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-53-5469b8fd7e88 Received: from eusync4.samsung.com ( [203.254.199.214]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id FB.CC.04619.DF8B9645; Mon, 17 Nov 2014 08:59:41 +0000 (GMT) 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 <0NF600IEJEBC0A50@eusync4.samsung.com>; Mon, 17 Nov 2014 08:59:41 +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 v5] usb: dwc2/gadget: rework disconnect event handling Date: Mon, 17 Nov 2014 09:59:42 +0100 Message-id: <1416214782-13911-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <54699561.5040303@samsung.com> References: <54699561.5040303@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrEJMWRmVeSWpSXmKPExsVy+t/xa7p/d2SGGLTfV7Q4eL/e4vULQ4uz TW/YLWac38dksWhZK7PF2iN32S22T5nOZPHg8E52Bw6Pvi2rGD227P/M6HH8xnYmj8+b5AJY orhsUlJzMstSi/TtErgyGi6vZi+4JFHROzmsgfGTcBcjJ4eEgInEnSNPWSBsMYkL99azdTFy cQgJLGWU2LdyBjuE08ck8fbZNmaQKjYBQ4mut11sILaIgIPEkqV3wGxmgZ+MEpd+8HUxcnAI C7hJXLoSCRJmEVCVuL3xPiuIzSvgIbF26SNWiGVyEv9frmACsTkFtCWmHT4MNkZIQEvi64E1 bBMYeRcwMqxiFE0tTS4oTkrPNdQrTswtLs1L10vOz93ECAmnLzsYFx+zOsQowMGoxMP7oC8z RIg1say4MvcQowQHs5IIr/I2oBBvSmJlVWpRfnxRaU5q8SFGJg5OqQbGlaFH5GtnZrxkMTHP OnCBbbrl98CmC4FVyTsOr9f7Nf/OSyvJ1yrmE1pyGeSXtrFr6xS2zXD++FVnxqLas9wlW1dE nOYumCYxMy4tVye59FpxU1NvkeLyU7WyHGtT1ixL+zK36eyBRxlqAZHzaje/atvyJqjnrq6q PJtwe4mO9O/oTcVr/95TYinOSDTUYi4qTgQAqUBjjAUCAAA= 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.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: , This patch adds a call to s3c_hsotg_disconnect() from 'end session' interrupt (GOTGINT_SES_END_DET) to correctly notify gadget subsystem about unplugged usb cable. DISCONNINT interrupt cannot be used for this purpose, because it is asserted only in host mode. To avoid reporting disconnect event more than once, a disconnect call has been moved from USB_REQ_SET_ADDRESS handling function to SESSREQINT interrupt. This way driver ensures that disconnect event is reported either when usb cable is unplugged or every time the host starts a new session. To handle devices which has been synthesized without SRP support, connected state is set in ENUMDONE interrupt. Signed-off-by: Marek Szyprowski Acked-by: Paul Zimmerman --- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 55c90c53f2d6..e54c3c50cd48 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -210,6 +210,7 @@ struct s3c_hsotg { u8 ctrl_buff[8]; struct usb_gadget gadget; + unsigned int connected:1; unsigned int setup; unsigned long last_rst; struct s3c_hsotg_ep *eps; diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index fcd2bb55ccca..89b1bea50ee3 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -1029,7 +1029,6 @@ static int s3c_hsotg_process_req_feature(struct s3c_hsotg *hsotg, } static void s3c_hsotg_enqueue_setup(struct s3c_hsotg *hsotg); -static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg); /** * s3c_hsotg_stall_ep0 - stall ep0 @@ -1107,7 +1106,6 @@ static void s3c_hsotg_process_control(struct s3c_hsotg *hsotg, if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { switch (ctrl->bRequest) { case USB_REQ_SET_ADDRESS: - s3c_hsotg_disconnect(hsotg); dcfg = readl(hsotg->regs + DCFG); dcfg &= ~DCFG_DEVADDR_MASK; dcfg |= (le16_to_cpu(ctrl->wValue) << @@ -2031,6 +2029,10 @@ static void s3c_hsotg_disconnect(struct s3c_hsotg *hsotg) { unsigned ep; + if (!hsotg->connected) + return; + + hsotg->connected = 0; for (ep = 0; ep < hsotg->num_of_eps; ep++) kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); @@ -2290,17 +2292,27 @@ irq_retry: dev_info(hsotg->dev, "OTGInt: %08x\n", otgint); writel(otgint, hsotg->regs + GOTGINT); + + if (otgint & GOTGINT_SES_END_DET) { + s3c_hsotg_disconnect(hsotg); + hsotg->gadget.speed = USB_SPEED_UNKNOWN; + } } if (gintsts & GINTSTS_SESSREQINT) { dev_dbg(hsotg->dev, "%s: SessReqInt\n", __func__); writel(GINTSTS_SESSREQINT, hsotg->regs + GINTSTS); + /* + * Report disconnect if there is any previous session established + */ + s3c_hsotg_disconnect(hsotg); } if (gintsts & GINTSTS_ENUMDONE) { writel(GINTSTS_ENUMDONE, hsotg->regs + GINTSTS); s3c_hsotg_irq_enumdone(hsotg); + hsotg->connected = 1; } if (gintsts & GINTSTS_CONIDSTSCHNG) {