Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp10133264pxu; Tue, 29 Dec 2020 15:08:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwh7/d0uLLgpqnTjK4D7VZ7Ut27xLbKtK3sEhua9dmo2eS+0FMOXkYKWvjgNMerQTvoBFnX X-Received: by 2002:a17:906:410e:: with SMTP id j14mr47631137ejk.253.1609283299504; Tue, 29 Dec 2020 15:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609283299; cv=none; d=google.com; s=arc-20160816; b=UWfCxhJn6LhJzoQoGdXaey62ATDKjYJYWK00QSLYMBS5hENVz5NL1YoUJM6ceVnw2+ mUzHB/Dlo093BkC0dv6w4UQ4MQXPLX3d6lH29vcV/853Yvhxb1AKAkeHuh706wN6ML/v 1D2lJyRqGfHJEKxU7hKv5gALgVVmiT0XnTRjE3acF9IFE7sQ7nCtCd7WECNQSqVFrmen AeJhPN0GewXt5rZ5ZDc6XN2Rgh3d4rHoigTCz8JRGBLuoln15lHwJXJTnKmuWZPWd59F 62yarxfw8DzrfYJQQjooYpzRznB/t6jZnoj38meChdr2HE10W1KpLeZkeaozCcNCdK31 xwNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:dmarc-filter :sender:dkim-signature; bh=1KAhvuLf/yvnWPBQm8h6VYbwH4+MlaWZaU2ApTgCAck=; b=EPgqGwP1tqlXVbR3eQ2iWHyOl00fwuXmDN8giUgXaNh2PAo4wf5weFkTqRykDlIxUY NmeqpdkIkgqIZMa7VgCTV7+y9tBCzbtqAuT9iPT0lms2TlW+rhgjBIrwf0ZQNlIk3+DQ jgkAXj7PIrpprcfujVFLKng5w++9qXm2KwKmsJ6GXcNHn0iDNYq+teXRskziUH/gpFAJ w5MuO10C5/jF6X+qx313D2BZJwtlhOl4lIlXxAA+X053w9SrpcYcLcjcgwn1lg7MALmQ vOjbrPmhtNULf8SZ2DtebWGLfDP7nEGrZSVUB7Egq5qiYKFWvudQ91pPjFWCUwJKs/Ln By7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=xl+feD0r; 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 x17si24945056edq.181.2020.12.29.15.07.56; Tue, 29 Dec 2020 15:08:19 -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=xl+feD0r; 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 S1726511AbgL2XGb (ORCPT + 99 others); Tue, 29 Dec 2020 18:06:31 -0500 Received: from m43-15.mailgun.net ([69.72.43.15]:31442 "EHLO m43-15.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726274AbgL2XGb (ORCPT ); Tue, 29 Dec 2020 18:06:31 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1609283170; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=1KAhvuLf/yvnWPBQm8h6VYbwH4+MlaWZaU2ApTgCAck=; b=xl+feD0reeLRjy4vyTclE+EWXnlPvRTcBrM5Xqz5ctwssYOc+DkxR3cu/wywpAH19Pk1LyyI muev+pUQRt5dvEIy2eAjKJF8T6EsZmHBVGDHmBNbjUBE+BlegMiIb/qPdVyHU6oASLkJOfO3 mkvALHfPRhtkSy6tWtFn5XZDJNA= X-Mailgun-Sending-Ip: 69.72.43.15 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-n04.prod.us-west-2.postgun.com with SMTP id 5febb644da47198188af06cc (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 29 Dec 2020 23:05:40 GMT Sender: wcheng=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 42157C43462; Tue, 29 Dec 2020 23:05:40 +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,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from wcheng-linux.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: wcheng) by smtp.codeaurora.org (Postfix) with ESMTPSA id 9F556C433C6; Tue, 29 Dec 2020 23:05:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 9F556C433C6 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 From: Wesley Cheng To: balbi@kernel.org, gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Wesley Cheng Subject: [PATCH v2 0/2] Allow DWC3 runtime suspend if UDC is unbinded Date: Tue, 29 Dec 2020 15:05:34 -0800 Message-Id: <1609283136-22140-1-git-send-email-wcheng@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes in v2: - Modified logic for executing the runtime PM resume. Using a sychronous get call to avoid race conditions. During the following scenario, the DWC3 runtime suspend routine is blocked as the connected flag is still true: 1. Enumerate device w/ host. 2. Gadget is unbinded - echo "" > /sys/kernel/config/usb_gadget/g1/UDC 3. Disconnect the USB cable (VBUS low) 4. No dwc3_gadget_disconnect_interrupt() seen (since controller is halted from step#1) 5. Runtime PM autosuspend fails due to "dwc->connected" being true (cleared in dwc3_gadget_disconnect_interrupt()) 6. Gadget binded - echo udc_name > /sys/kernel/config/usb_gadget/g1/UDC 7. No runtime suspend until cable is plugged in and out Technically, for device initiated disconnects, there is no active session/link with the host, so the DWC3 controller should be allowed to go into a low power state. Also, we need to now consider when re-binding the UDC, dwc3_gadget_set_speed() is executed before dwc3_gadget_pullup(), so if the DWC3 controller is suspended/disabled, while accessing the DCFG, that could result in bus timeouts, etc... Change the dwc3_gadget_set_speed() to save the speed being requested, and program it during dwc3_gadget_run_stop(), which is executed during PM runtime resume. If not, previous setting will be overridden as we execute a DWC3 controller reset during PM runtime resume. Wesley Cheng (2): usb: dwc3: gadget: Allow runtime suspend if UDC unbinded usb: dwc3: gadget: Preserve UDC max speed setting drivers/usb/dwc3/core.h | 1 + drivers/usb/dwc3/gadget.c | 121 ++++++++++++++++++++++---------------- 2 files changed, 71 insertions(+), 51 deletions(-) -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project