From patchwork Fri Nov 14 12:20:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 40815 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 21760244FC for ; Fri, 14 Nov 2014 12:20:28 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id mc6sf10271289lab.7 for ; Fri, 14 Nov 2014 04:20:27 -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=ASap0STaQz23edCEusVqN2yXKNWEJ7DrHlTCc8ufXmo=; b=iZ4KKYrQCYC4NTUANsehvjSPz+DmN/qW8dhrbE68sbHUUoRP1h/DxK5UMvid8TEnzr yY6W7JaO4EpwjuDQrz2osDbElEv3OEe6YLQQB1K8saucqC7NRnlwtJh4EsjvCOcZ1D94 G2uR2CSU5X1ooMBuWgdaR71a9V4MkYGFcA8ZmnEYQOvDZVfmXd1hcIYfdX+CqFZt6RMu +pSyrkrs0HMzdPgHPrRq8Dy3B1KFmKZ/mmVdbaHP2e0jGEacGFgidzhjN+0/niIyU/ls iLa6o9USZ60zstfiVNOoDdgwrRUNJ58/+VcB3e9MQzEeAFYPtcRG4T1Dy0GKf/gfPhnF E1zQ== X-Gm-Message-State: ALoCoQlo03x/4M3mExcBvDEvkfV2fxf+9wSQIIT9+1u0nObaLS1hRyUW274bl8jy1f3XEpYuAZxd X-Received: by 10.152.8.67 with SMTP id p3mr873718laa.4.1415967627094; Fri, 14 Nov 2014 04:20:27 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.132 with SMTP id k4ls445054lak.12.gmail; Fri, 14 Nov 2014 04:20:26 -0800 (PST) X-Received: by 10.112.169.106 with SMTP id ad10mr7936762lbc.13.1415967626848; Fri, 14 Nov 2014 04:20:26 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id lt11si20577164lac.40.2014.11.14.04.20.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 04:20:26 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id hz20so4829596lab.31 for ; Fri, 14 Nov 2014 04:20:26 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr2422042lbr.74.1415967626730; Fri, 14 Nov 2014 04:20:26 -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 ew9csp754196lbc; Fri, 14 Nov 2014 04:20:25 -0800 (PST) X-Received: by 10.70.124.162 with SMTP id mj2mr9560970pdb.33.1415967624567; Fri, 14 Nov 2014 04:20:24 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nj10si28096431pdb.212.2014.11.14.04.20.23 for ; Fri, 14 Nov 2014 04:20:24 -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 S1754706AbaKNMUX (ORCPT + 4 others); Fri, 14 Nov 2014 07:20:23 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:33998 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753981AbaKNMUW (ORCPT ); Fri, 14 Nov 2014 07:20:22 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) 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 <0NF10032D3QP4AB0@mailout1.w1.samsung.com>; Fri, 14 Nov 2014 12:23:13 +0000 (GMT) X-AuditID: cbfec7f4-b7f6c6d00000120b-12-5465f383d889 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id D4.B3.04619.383F5645; Fri, 14 Nov 2014 12:20:19 +0000 (GMT) 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 <0NF1006UC3LR1J00@eusync2.samsung.com>; Fri, 14 Nov 2014 12:20:19 +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 v4] usb: dwc2/gadget: rework disconnect event handling Date: Fri, 14 Nov 2014 13:20:07 +0100 Message-id: <1415967607-6174-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <5465EEF3.7060902@samsung.com> References: <5465EEF3.7060902@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrMJMWRmVeSWpSXmKPExsVy+t/xK7rNn1NDDB5/FLE4eL/e4vULQ4uz TW/YLWac38dksWhZK7PF2iN32S22T5nOZPHg8E52Bw6Pvi2rGD227P/M6HH8xnYmj8+b5AJY orhsUlJzMstSi/TtErgyjvdcZi34KlrR9WU/YwPjXcEuRk4OCQETiafnnjJB2GISF+6tZ+ti 5OIQEljKKPF/6W0mCKePSWIC0DKQKjYBQ4mut11sILaIgIPEkqV3wGxmgZ+MEpd+8IHYwgJu Es9eLGMHsVkEVCX27DrFCGLzCrhLXJu8gwVim5zE/5crgGZycHAKaEs0djmAhIUEtCSuTepm msDIu4CRYRWjaGppckFxUnquoV5xYm5xaV66XnJ+7iZGSEB92cG4+JjVIUYBDkYlHl6DgtQQ IdbEsuLK3EOMEhzMSiK8358DhXhTEiurUovy44tKc1KLDzEycXBKNTAKF1qltWyK6lzRsqH1 QEtXuphQ+tTzFkVOSxd46UtcO6rhKpJyUd85vvFwQkPJGuMzs4WjRKXO6Ij7PLu4d11Pi0aD t4d6vv4tll3nghTlfO+cObBuxeFaFans3f4l/grLVl5iU+MyNVkbf3jzzW9sj030/FQFdgZf uuTReHTf9EvqOY/63yqxFGckGmoxFxUnAgD0D7ISBgIAAA== 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.44 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. Signed-off-by: Marek Szyprowski Acked-by: Paul Zimmerman --- drivers/usb/dwc2/core.h | 1 + drivers/usb/dwc2/gadget.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index 55c90c53f2d6..78b9090ebf71 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 session: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..c7f68dc1cf6b 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->session) + return; + + hsotg->session = 0; for (ep = 0; ep < hsotg->num_of_eps; ep++) kill_all_requests(hsotg, &hsotg->eps[ep], -ESHUTDOWN, true); @@ -2290,11 +2292,18 @@ 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); + s3c_hsotg_disconnect(hsotg); + hsotg->session = 1; } if (gintsts & GINTSTS_ENUMDONE) {