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: 5305631 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 D36F49FBB9 for ; Fri, 14 Nov 2014 12:20:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 093B22017D for ; Fri, 14 Nov 2014 12:20:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AD392015D for ; Fri, 14 Nov 2014 12:20:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754706AbaKNMUX (ORCPT ); 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: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 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) {