From patchwork Mon Mar 20 09:34:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 72054 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1120019wrt; Mon, 20 Mar 2023 02:56:31 -0700 (PDT) X-Google-Smtp-Source: AK7set/OcW1BUSIgNMbehcIuc8vQSMDaOGmTK+JnzeWJjbeONXer1bbXQh9evg2WI41Gx3R3p3f4 X-Received: by 2002:a17:90b:4b4d:b0:23b:3f18:a8fe with SMTP id mi13-20020a17090b4b4d00b0023b3f18a8femr18602545pjb.31.1679306191295; Mon, 20 Mar 2023 02:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679306191; cv=none; d=google.com; s=arc-20160816; b=qkL0Pb5Oul9Pr18Cwzb/6jZ2eakATwLs5HlPfm8msS/dijJzoo/t1vFrKmFKVsjpYJ mK5MhYRRTmkdNbyKMLnnSHMb9IrrfvgXF0uq6q/9H+AUGi+/3ycLU09Q3Kp+LTlpI8Hr DYMlEAFcNGmJlZkb+9UFGuXCsdBpNFbGi+Og6nGs+TOBd8qEn0ej0MQHpIHxn6iW15nN 7W4593P8ezQ8g0qj0GJqMJSqjjt89ljAIYSBmkYcjrOrOHxPRfk8kFAOipLSYDvnL0w2 W4kdpLByJpuM++sByoZx6oUnywI0VokanoElk5EkH5ts7NePN1x7OXrxvorWZCJCtIha yIkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=G4qLjt0iGf1q1R/7efqPZVpjxVSC6vPNIylJvomJDgM=; b=DgalSC14JC5+SeeE4/dKRfz5m8R3huh2oZw6tEbdYQ8kIc9n4sZSbT35WRFvNdwUQM Dp4V5sBCAMzyhMW2Gj3zbhxVjLk0O6q3SRHpbJUpdwGwa0Y3K9sqXewIscKjolocUHWe 1Lag5m7IUaivho40hza4ky7M853CnVVSVeWzTCTK3yN4a8dpaqIvXHo6rwajMz3FEI2S +68Z05UTfb00HkHOdU9lpwRCAbU0ojlwf3F3cFJ9vk6bnmGybjPUQqmZM0kq8gJRT9LK XQvWe48KXpv1chLVnvc6+ta14J9wR0b0NB9SemwpnAwg6C1BSLko5uk1ClcDfvJl2Yky 0Ihw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JRdYEgRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hk2-20020a17090b224200b0023d282930e7si16772401pjb.76.2023.03.20.02.56.19; Mon, 20 Mar 2023 02:56:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JRdYEgRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230417AbjCTJfG (ORCPT + 99 others); Mon, 20 Mar 2023 05:35:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231147AbjCTJfA (ORCPT ); Mon, 20 Mar 2023 05:35:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 750F41B572; Mon, 20 Mar 2023 02:34:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2D868B80DB5; Mon, 20 Mar 2023 09:34:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84F77C433D2; Mon, 20 Mar 2023 09:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679304897; bh=7f7xBrz/th4eNUqDR98uCTdNi7uY7ScAKlNZDYRKTts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRdYEgRjJLA0V9YqyikvA55oBQFK2hrVxrsQHsj9NHQc4KqqqCx9K7g0O1bwcQCa+ XVlHdEAlrhOYpLRo5XK7S6hKCSOJAtReSKoXUDYR8D6PypnlDvX23K7h8u0cfQbq/d +0r5HkWwMVBEKHBFxWuPXqT79fRIl4mdkB8CmwfM71tuEPxJFh+m7mJAhY6I29vV9O +nUNjnwnZMbwKb6Nim+KHmy5lfNjWpPg+CWFO0n+7XH6i4XEJLScYvpMCIZJ0nEhLL jOVjmsM5DtRmHxQoXmtRFxpxscN+ISUx31nvpY8ET89zf3kaf4SOfBxQVPsTtYpfmT aRCR/3WpEypLg== From: Roger Quadros To: Thinh.Nguyen@synopsys.com, stern@rowland.harvard.edu Cc: gregkh@linuxfoundation.org, vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Roger Quadros , devicetree@vger.kernel.org Subject: [RFC PATCH 1/2] dt-bindings: usb: snps,dwc3: Add 'snps,gadget-keep-connect-sys-sleep' Date: Mon, 20 Mar 2023 11:34:46 +0200 Message-Id: <20230320093447.32105-2-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320093447.32105-1-rogerq@kernel.org> References: <20230320093447.32105-1-rogerq@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760880168789534248?= X-GMAIL-MSGID: =?utf-8?q?1760880168789534248?= The current USB gadget driver behaviour is to stop the controller and disconnect from the bus during System sleep. The 'snps,gadget-keep-connect-sys-sleep' property can be used to change this behaviour and keep the controller active and connected to the bus during System sleep. This is useful for applications that want to enter a low power state when USB is suspended but remain connected so they can resume activity on USB resume. This feature introduces a new constraint if Gadget driver is connected to USB host: i.e. the gadget must be in USB suspend state to allow a System sleep as we cannot process any USB transactions when in System sleep. The system hardware is responsible to detect the end of USB suspend and wake up the system so we can begin processing the USB transactions as soon as possible. Cc: devicetree@vger.kernel.org Signed-off-by: Roger Quadros --- Documentation/devicetree/bindings/usb/snps,dwc3.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml index be36956af53b..1ce8008e7fef 100644 --- a/Documentation/devicetree/bindings/usb/snps,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/snps,dwc3.yaml @@ -262,6 +262,11 @@ properties: asserts utmi_sleep_n. type: boolean + snps,gadget-keep-connect-sys-sleep: + description: + If True then gadget driver will not disconnect during system sleep. + System sleep will not be allowed if gadget is not already in USB suspend. + snps,hird-threshold: description: HIRD threshold $ref: /schemas/types.yaml#/definitions/uint8 From patchwork Mon Mar 20 09:34:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 72053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1119813wrt; Mon, 20 Mar 2023 02:55:55 -0700 (PDT) X-Google-Smtp-Source: AK7set89d7vyZ8TvviARJQO0exvYu6FeuPdNJVMSuO9siBclXnxBpzmOht270hsa2lqnyRzRcE5q X-Received: by 2002:a62:19cd:0:b0:623:c7ff:46c8 with SMTP id 196-20020a6219cd000000b00623c7ff46c8mr12901997pfz.1.1679306154508; Mon, 20 Mar 2023 02:55:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679306154; cv=none; d=google.com; s=arc-20160816; b=b8vbSaWyGOTEZfhduPOUcYPvxDGRFctvFtEEMxd/RDzePhkUWzI5P/s8X8n7pjNOpd IcJA7Pg2ebzhu7N9cfc20RU8vjgiGKR4S0iLEpg8FahhcsDTBrp0MOKvprI6F6q2p2s4 7Ld8WPzfOKZJwRpPNFnl1fyY5ueqrwkCteaf+R+yjkzitahqdE0tlUHIj+yNV+5zZbQ/ oZgrPazCoZWggcsCcMp+tnXF/KNidS/vn5L81zTeO/7Ar5vPgr2FfWZXf1hRvkLul+9g MM1gAY+EybXDRoW9HvRg4i6xC4qcJd8BlxO3BNtXrmkQwC4dKpM8p8HrP5g0Ihvpaktz D66Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Doc4NkTuZGqMKJFSqknbFyBJPsRavpL8OBiYjqBQENc=; b=dp0zLZFp0wQVzCu4oDqY2PUEEnehcAHu3zMLgauJJK+NKMN/tO/3IEFOSXfGAkVvOT 6ValRRcdiOzxol8cZYbl28hXWiWEi7mVyTTPPFS7HNShGLJyYcf7Dr4FpedQi4YBsW1E jiQXkGmGscna9xCMMoSO4YK9g3dBLqFEawyBBd9iBgcmkJIIaUWw3EZlJUeSmscuMGQ2 bUcrvkz/MBbvxM0VophLnsuVIfHZjytev9TDjmzVGzwQtsq3GWDxRhp7NWMTFm0OSLl1 UCLM6Te/MATtgt7bbDhRYEzd9Od0Lo+4CSNVyg97rDEnPcEuSiyx51kZoXB9Ee+a/g+p TXQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uMHzvJJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 37-20020a631965000000b004fbd2a5db20si9810518pgz.538.2023.03.20.02.55.42; Mon, 20 Mar 2023 02:55:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uMHzvJJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbjCTJfJ (ORCPT + 99 others); Mon, 20 Mar 2023 05:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231234AbjCTJfE (ORCPT ); Mon, 20 Mar 2023 05:35:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48A231B572; Mon, 20 Mar 2023 02:35:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E781CB80D7D; Mon, 20 Mar 2023 09:35:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75014C4339C; Mon, 20 Mar 2023 09:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679304899; bh=XAeKuwAyy3BpuGbVe2bkXu++daEbNc72qyzyGZsAOMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uMHzvJJSi/yTk8lRtxH05x1dx3ke8t6MxNW0cyJNywTCnCMdZt9UWvBVPDz02Enhx yS8Z9KhUN1bo6gO3p45UqibeRvqik0gILQgUvcv9ScudqdoIlZ/X6sEbpWFU65fbny MOCDlxjtvWt5fF3xmagkzUPJmz3Zn55jBX3ST3oLkYu6INdAillvEunV1Hya0pPDJM P2Tx7dpxzpor6rKmDjAOUZui4hRNMCFDGe6CBXqiDRXnYpdwYHL7zGtUbu3KduMaJ7 MBGdn0kzhCoYzITq0ZGSurYBQQTlsEafcbKg6XrsLhLHd2rn+VOWjZXZFbCPYcyrTM lVcaVlDzjnm8g== From: Roger Quadros To: Thinh.Nguyen@synopsys.com, stern@rowland.harvard.edu Cc: gregkh@linuxfoundation.org, vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Roger Quadros Subject: [RFC PATCH 2/2] usb: dwc3: Support 'snps,gadget-keep-connect-sys-sleep' feature Date: Mon, 20 Mar 2023 11:34:47 +0200 Message-Id: <20230320093447.32105-3-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230320093447.32105-1-rogerq@kernel.org> References: <20230320093447.32105-1-rogerq@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760880129808841029?= X-GMAIL-MSGID: =?utf-8?q?1760880129808841029?= Implement 'snps,gadget-keep-connect-sys-sleep' property. Do not stop the gadget controller and disconnect if this property is present and we are connected to a USB Host. Prevent System sleep if Gadget is not in USB suspend. Signed-off-by: Roger Quadros --- drivers/usb/dwc3/core.c | 25 +++++++++++++++++++------ drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/gadget.c | 25 +++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 476b63618511..a47bbaa27302 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1575,6 +1575,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->dis_split_quirk = device_property_read_bool(dev, "snps,dis-split-quirk"); + dwc->gadget_keep_connect_sys_sleep = device_property_read_bool(dev, + "snps,gadget-keep-connect-sys-sleep"); + dwc->lpm_nyet_threshold = lpm_nyet_threshold; dwc->tx_de_emphasis = tx_de_emphasis; @@ -2027,14 +2030,20 @@ static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg) { unsigned long flags; u32 reg; + int ret; switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: if (pm_runtime_suspended(dwc->dev)) break; - dwc3_gadget_suspend(dwc); + ret = dwc3_gadget_suspend(dwc); + if (ret) { + dev_err(dwc->dev, "gadget not suspended: %d\n", ret); + return ret; + } synchronize_irq(dwc->irq_gadget); - dwc3_core_exit(dwc); + if(!dwc->gadget_keep_connect_sys_sleep) + dwc3_core_exit(dwc); break; case DWC3_GCTL_PRTCAP_HOST: if (!PMSG_IS_AUTO(msg) && !device_may_wakeup(dwc->dev)) { @@ -2088,11 +2097,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: - ret = dwc3_core_init_for_resume(dwc); - if (ret) - return ret; + if (!dwc->gadget_keep_connect_sys_sleep) + { + ret = dwc3_core_init_for_resume(dwc); + if (ret) + return ret; + + dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); + } - dwc3_set_prtcap(dwc, DWC3_GCTL_PRTCAP_DEVICE); dwc3_gadget_resume(dwc); break; case DWC3_GCTL_PRTCAP_HOST: diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 582ebd9cf9c2..f84bac815bed 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1328,6 +1328,8 @@ struct dwc3 { unsigned dis_split_quirk:1; unsigned async_callbacks:1; + unsigned gadget_keep_connect_sys_sleep:1; + u16 imod_interval; int max_cfg_eps; diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 3c63fa97a680..8062e44f63f6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -4572,12 +4572,23 @@ void dwc3_gadget_exit(struct dwc3 *dwc) int dwc3_gadget_suspend(struct dwc3 *dwc) { unsigned long flags; + int link_state; if (!dwc->gadget_driver) return 0; - dwc3_gadget_run_stop(dwc, false, false); + if (dwc->gadget_keep_connect_sys_sleep && dwc->connected) { + link_state = dwc3_gadget_get_link_state(dwc); + /* Prevent PM Sleep if not in U3/L2 */ + if (link_state != DWC3_LINK_STATE_U3) + return -EBUSY; + + /* don't stop/disconnect */ + dwc3_gadget_disable_irq(dwc); + return 0; + } + dwc3_gadget_run_stop(dwc, false, false); spin_lock_irqsave(&dwc->lock, flags); dwc3_disconnect_gadget(dwc); __dwc3_gadget_stop(dwc); @@ -4588,11 +4599,21 @@ int dwc3_gadget_suspend(struct dwc3 *dwc) int dwc3_gadget_resume(struct dwc3 *dwc) { - int ret; + int ret; + irqreturn_t irq_t; if (!dwc->gadget_driver || !dwc->softconnect) return 0; + if (dwc->gadget_keep_connect_sys_sleep && dwc->connected) { + dwc3_gadget_enable_irq(dwc); + /* check pending events */ + irq_t = dwc3_check_event_buf(dwc->ev_buf); + if (irq_t == IRQ_WAKE_THREAD) + dwc3_process_event_buf(dwc->ev_buf); + return 0; + } + ret = __dwc3_gadget_start(dwc); if (ret < 0) goto err0;