Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp24237pxb; Wed, 20 Jan 2021 23:47:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoGQDn/58eCGSymaMERbtAIzmXjxQ3Wjr7pr4fESyX9S2nsH0j4fJNXwyt4Vm8xZ93PWJi X-Received: by 2002:a50:934a:: with SMTP id n10mr9982202eda.26.1611215238621; Wed, 20 Jan 2021 23:47:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611215238; cv=none; d=google.com; s=arc-20160816; b=oi47BFyBZqrIPmRz55x06nLWZkrbgGBXHNQLgFTlRV68uNfYUZyCFsPTFJVAYAlhAV NwMXLOt8cgVlPQl1F79A67xw5fal80dLvv/jqy1AH0PrCZN3ygWf1Mw2YnFMzJyAHTKd QrCkwoVbWfrWoq8oZE1uic4aQHKQtvfkj+0N2iSrLUqXa1LoVHJvvtjiSTxUOqf6Qhhb kzFCgCcYqoY6HKTm4aPlIkbvpgnZsNeNutsow7ZjRRr7hf7XnEGwRgAKu77+u0xkNFBK cGzzybCpasrom/GbXbI9kIG3aFYTqAceH5ISC1s01EOjgNY4wWXU+DbRR/Fk2dfJJii+ Knvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=45SHXNGLf2GW49IFygSLw/pVD2P3JuS39NiipoEW1UQ=; b=vP54QfAJNb3UT2M2m+fC9lhyoXFn1aUz3z5UpDjSsdVNSfggmYh4w54tgfLg9YCtRU EG/ug2OxIAaJDPmxokyW3ELFeVJPSIRTJFXUH+LvbOspuKriGuqeXXl5nNnyVWhXBVrp g1gBf0OeXKmP6WBMENdKgiTna5PJqk5IYCTf0+ixCoLk3bdo8Ie5LtXNOj1if4tD2ZRZ XJPFko/UPoBF+qH/YuGkC5uep5/UPxaVsui2Y09tYMT1PYG/jVBlIGTpanLoE3xImgYR H8C1q8j3VIUx0zPmPmVvHTvEeGCzpnZzbDIkrSIdQEIxSuLjstWpLoRVwUwESs6fQV1h RVfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=U3bvABjJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si1480109eje.466.2021.01.20.23.46.55; Wed, 20 Jan 2021 23:47:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=U3bvABjJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726110AbhAUHqJ (ORCPT + 99 others); Thu, 21 Jan 2021 02:46:09 -0500 Received: from a1.mail.mailgun.net ([198.61.254.60]:18463 "EHLO a1.mail.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727486AbhAUHpA (ORCPT ); Thu, 21 Jan 2021 02:45:00 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1611215080; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=45SHXNGLf2GW49IFygSLw/pVD2P3JuS39NiipoEW1UQ=; b=U3bvABjJ1Fih3qHbVB/rBq8r+naO4d159jEIKnOHdVLjaB5cdTcdssQ/VkBbHta/lgg3nXgu 3t0vZSO0fHAatxSSbNy7NXARtv7vaN/hdHVd7q0nye1cKI5Fj6yVV2E5xIMPrjPmdzh8/u/o 3Rv6B2yNwiUlnq5IblTPtCBRMHc= X-Mailgun-Sending-Ip: 198.61.254.60 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n05.prod.us-west-2.postgun.com with SMTP id 600930c95677aca7bdbe0b14 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Thu, 21 Jan 2021 07:44:09 GMT Sender: wcheng=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 573DFC43464; Thu, 21 Jan 2021 07:44:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from [10.110.7.112] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: wcheng) by smtp.codeaurora.org (Postfix) with ESMTPSA id 185CCC433CA; Thu, 21 Jan 2021 07:44:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 185CCC433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=wcheng@codeaurora.org Subject: Re: usb: dwc3: gadget: skip pullup and set_speed after suspend To: Jung Daehwan , Thinh Nguyen Cc: Felipe Balbi , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" References: <1611113968-102424-1-git-send-email-dh10.jung@samsung.com> <20210121064956.GA69382@ubuntu> From: Wesley Cheng Message-ID: <6c6429da-5d27-2d6a-9bcf-3606810e71a6@codeaurora.org> Date: Wed, 20 Jan 2021 23:44:05 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210121064956.GA69382@ubuntu> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/20/2021 10:49 PM, Jung Daehwan wrote: > Hi, > > On Thu, Jan 21, 2021 at 01:00:32AM +0000, Thinh Nguyen wrote: >> Hi, >> >> Daehwan Jung wrote: >>> Sometimes dwc3_gadget_pullup and dwc3_gadget_set_speed are called after >>> entering suspend. That's why it needs to check whether suspend >>> >>> 1. dwc3 sends disconnect uevent and turn off. (suspend) >>> 2. Platform side causes pullup or set_speed(e.g., adbd closes ffs node) >>> 3. It causes unexpected behavior like ITMON error. >>> >>> Signed-off-by: Daehwan Jung >>> --- >>> drivers/usb/dwc3/gadget.c | 6 ++++++ >>> 1 file changed, 6 insertions(+) >>> >>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c >>> index ee44321..d7d4202 100644 >>> --- a/drivers/usb/dwc3/gadget.c >>> +++ b/drivers/usb/dwc3/gadget.c >>> @@ -2093,6 +2093,9 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) >>> unsigned long flags; >>> int ret; >>> >>> + if (pm_runtime_suspended(dwc->dev)) >>> + return 0; >>> + >>> is_on = !!is_on; >>> >>> /* >>> @@ -2403,6 +2406,9 @@ static void dwc3_gadget_set_speed(struct usb_gadget *g, >>> unsigned long flags; >>> u32 reg; >>> >>> + if (pm_runtime_suspended(dwc->dev)) >>> + return; >>> + >>> spin_lock_irqsave(&dwc->lock, flags); >>> reg = dwc3_readl(dwc->regs, DWC3_DCFG); >>> reg &= ~(DWC3_DCFG_SPEED_MASK); >> >> This is already addressed in Wesley Cheng's patches. Can you try the >> latest changes of DWC3 in Greg's usb-next branch? >> >> Thanks, >> Thinh > > I checked Wesly Cheng's pathces but it's not same. > What I want to do for this patch is to avoid pullup from platform side. > (android in my case) > > It's possible that platform side tries to pullup by UDC_Store after usb is already disconnected. > It can finally run controller and enable irq. > > I think we have to avoid it and other possible things related to platform side. > > Hi Daehwan, I think what you're trying to do is to avoid the unnecessary runtime resume if the cable is disconnected and userspace attempts to bind/unbind the UDC. I'm not exactly sure what patches you've pulled in, but assuming you didn't pull in any of the recent suspend changes: usb: dwc3: gadget: Allow runtime suspend if UDC unbinded usb: dwc3: gadget: Preserve UDC max speed setting Please consider the following scenario: 1. USB connected 2. UDC unbinded 3. DWC3 will continue to stay in runtime active, since dwc->connected = true In this scenario, we should allow the DWC3 to enter runtime suspend, since runstop has been disabled. If you have pulled in the above changes, and adding your changes on top of it, then consider the following: 1. USB connected 2. UDC unbinded 3. DWC enters runtime suspend (due to the above changes) 4. UDC binded The check for pm_runtime_suspended() will block step#4 from re-enabling the runstop bit even if the USB cable is connected. Thanks Wesley Cheng -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project