From patchwork Thu Mar 16 13:12:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 70780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp478205wrt; Thu, 16 Mar 2023 06:20:20 -0700 (PDT) X-Google-Smtp-Source: AK7set/3q7ILacXFKUI6mTata1tmRomRtxt/r+xaU0Qr3ZDP7/JFwK6q8zRcBd3caQSg5yeirw05 X-Received: by 2002:a17:90b:33d1:b0:23d:bbcb:c97f with SMTP id lk17-20020a17090b33d100b0023dbbcbc97fmr4146808pjb.1.1678972820339; Thu, 16 Mar 2023 06:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678972820; cv=none; d=google.com; s=arc-20160816; b=JcPkQlt6bV5bpe0T9cW5xP+U1vwu09kkEx4/WM1TIuVg8Arc8eyVI6V8xLWmujLmZN qbP5gY3h9lmOmXK3NDvZeVRxLropHUZPL8SeTXA4ARbulf8Jak/NXr8RTX7fbmlNYfmn wYgFv/0PgIkEbSNV1stU/hitSXT4HDaHDsIxrrvJDUfWXMf/k3lK1Mj6PCz8PjoFsmFt baGA1qxM4iN5XBfEZYZbXuIIh/3YTeHHpayzY9QccQ2sMJPIqXQR5DC6bcrC8HFY2FEE W3qvgm4haInXq5wnYqaEZ2qfwmsPaa24A1y8AnkFmM0jXwq19EsjxZuIPfEyMYKHmUZx 8mwg== 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=koy4ydadBWt3Jb+aycWI1IW/IvlslpYHi/jywWC3IXs=; b=H9jL0SAiT2ImMn07TB3KCQReR/ixo1kzofWW/vmdzsfvJYez5yRdSzwtGB9l5PlZ3l pYbZJuftiDHPQPBJYJ7+U7tNilCVPtTf051bg41Jb9wYNMmQoI04oR8GBM8+guLqE1qH xcKbIOu4YisW7bmLJXqpFFoozQPkq0m0WKmIc7/IIQmthQ+2rcPC6ukCvOCrHRUZX+5b 8jFQdhKOteFaqbj+/GhTXf8Pv9I26HtjkM6nEeGQKFSDGsA7VkHelgqBPUhLs4PLXE43 U+DWYiQEo+f6qMa2YA8HQh6FWSHjG6bJVqUXEksffs5oUw+d2FpofAeLkfFA5O0WmKyV AHVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jomVkmsc; 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 t19-20020a17090a449300b0023414093852si4397031pjg.25.2023.03.16.06.20.06; Thu, 16 Mar 2023 06:20:20 -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=jomVkmsc; 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 S229932AbjCPNMm (ORCPT + 99 others); Thu, 16 Mar 2023 09:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229913AbjCPNMk (ORCPT ); Thu, 16 Mar 2023 09:12:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC08DC8892; Thu, 16 Mar 2023 06:12:36 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 6E75762013; Thu, 16 Mar 2023 13:12:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79822C4339E; Thu, 16 Mar 2023 13:12:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678972355; bh=7E1F1HujeKXETEZ4kPVIQu6ehkDfj+ztaIBRYcJcu18=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jomVkmsc2gTsM46uTbphUsj1cw/S/gkHSKxZG1YC6g0ElVmzkoZNTUxyyEs6cIDsA mGoT2AGrMM6isbR9jU12g0dDwWosDKVU4aFd0ZgOHlhpO7woOrQcQKY4kFkDzyoxau ZBQmf84N37idtAV2Idui76kdC9iSOX1LobYzBgZyRII2Mz336k/S/zYDTurboxfc9x AGzX/kuzrPSURDXwlS3Jj1CB18hG4Eymg6l1RMjGhLRFkB2YE31Dq5506t0Kl4RLJ1 0k1+1NgAJJESQ6kD4cBvzJwAfLRClbpvf9TcU5wbhJIEpZeBZ3Jf5CIuzw46lMxeFx aIf8uDOnvcayg== From: Roger Quadros To: Thinh.Nguyen@synopsys.com Cc: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Aswath Govindraju , Roger Quadros Subject: [PATCH 1/3] usb: dwc3-am62: Add support for system wakeup based on USB events Date: Thu, 16 Mar 2023 15:12:24 +0200 Message-Id: <20230316131226.89540-2-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316131226.89540-1-rogerq@kernel.org> References: <20230316131226.89540-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?1760530603753979585?= X-GMAIL-MSGID: =?utf-8?q?1760530603753979585?= From: Aswath Govindraju The USB2SS IP in TI's AM62 SoC is capable of supporting wakeup from deep sleep based on the following events, 1) VBUS state change 2) Overcurrent detection 3) Line state change Wakeup from these events can enabled by setting their corresponding bits in the WAKEUP_CONFIG register. The events to be enabled are decided based on the current role of the controller. When the role of the controller is host, the comparators for detecting VBUS state change are disabled while entering low power mode. This is done as VBUS state is not used in host mode and disabling the comparators helps in reducing the power consumption. So, wakeup from VBUS state change should be disabled in host mode. While operating in peripheral mode all the wakeup events can be enabled. Therefore, add support for the same in the suspend/resume hooks. Signed-off-by: Aswath Govindraju Signed-off-by: Roger Quadros --- drivers/usb/dwc3/dwc3-am62.c | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c index 173cf3579c55..867bfa1252b8 100644 --- a/drivers/usb/dwc3/dwc3-am62.c +++ b/drivers/usb/dwc3/dwc3-am62.c @@ -17,6 +17,8 @@ #include #include +#include "core.h" + /* USB WRAPPER register offsets */ #define USBSS_PID 0x0 #define USBSS_OVERCURRENT_CTRL 0x4 @@ -45,6 +47,10 @@ #define USBSS_PHY_VBUS_SEL_SHIFT 1 #define USBSS_PHY_LANE_REVERSE BIT(0) +/* CORE STAT register bits */ +#define USBSS_CORE_OPERATIONAL_MODE_MASK GENMASK(13, 12) +#define USBSS_CORE_OPERATIONAL_MODE_SHIFT 12 + /* MODE CONTROL register bits */ #define USBSS_MODE_VALID BIT(0) @@ -233,6 +239,9 @@ static int dwc3_ti_probe(struct platform_device *pdev) reg |= USBSS_MODE_VALID; dwc3_ti_writel(data, USBSS_MODE_CONTROL, reg); + /* Device has capability to wakeup system from sleep */ + device_set_wakeup_capable(dev, true); + /* Setting up autosuspend */ pm_runtime_set_autosuspend_delay(dev, DWC3_AM62_AUTOSUSPEND_DELAY); pm_runtime_use_autosuspend(dev); @@ -281,6 +290,22 @@ static int dwc3_ti_remove(struct platform_device *pdev) static int dwc3_ti_suspend_common(struct device *dev) { struct dwc3_data *data = dev_get_drvdata(dev); + u32 reg, current_prtcap_dir; + + if (device_may_wakeup(dev)) { + reg = dwc3_ti_readl(data, USBSS_CORE_STAT); + current_prtcap_dir = (reg & USBSS_CORE_OPERATIONAL_MODE_MASK) + >> USBSS_CORE_OPERATIONAL_MODE_SHIFT; + /* Set wakeup config enable bits */ + reg = dwc3_ti_readl(data, USBSS_WAKEUP_CONFIG); + if (current_prtcap_dir == DWC3_GCTL_PRTCAP_HOST) { + reg |= USBSS_WAKEUP_CFG_LINESTATE_EN | USBSS_WAKEUP_CFG_OVERCURRENT_EN; + } else { + reg |= USBSS_WAKEUP_CFG_OVERCURRENT_EN | USBSS_WAKEUP_CFG_LINESTATE_EN | + USBSS_WAKEUP_CFG_VBUSVALID_EN; + } + dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, reg); + } clk_disable_unprepare(data->usb2_refclk); @@ -290,9 +315,23 @@ static int dwc3_ti_suspend_common(struct device *dev) static int dwc3_ti_resume_common(struct device *dev) { struct dwc3_data *data = dev_get_drvdata(dev); + u32 reg; clk_prepare_enable(data->usb2_refclk); + if (device_may_wakeup(dev)) { + /* Clear wakeup config enable bits */ + reg = dwc3_ti_readl(data, USBSS_WAKEUP_CONFIG); + reg &= ~(USBSS_WAKEUP_CFG_OVERCURRENT_EN | USBSS_WAKEUP_CFG_LINESTATE_EN | + USBSS_WAKEUP_CFG_VBUSVALID_EN); + dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, reg); + } + + reg = dwc3_ti_readl(data, USBSS_WAKEUP_STAT); + /* Clear the wakeup status with wakeup clear bit */ + reg |= USBSS_WAKEUP_STAT_CLR; + dwc3_ti_writel(data, USBSS_WAKEUP_STAT, reg); + return 0; } From patchwork Thu Mar 16 13:12:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 70786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp481157wrt; Thu, 16 Mar 2023 06:26:24 -0700 (PDT) X-Google-Smtp-Source: AK7set+DzjA2dEdT/ndS5SlHCU9b9sqlIewTDwDitI44qD8PVEnsmHCBZRD9sL5eZfoVMvAxVwH+ X-Received: by 2002:aa7:97a2:0:b0:625:d5b5:1e9d with SMTP id d2-20020aa797a2000000b00625d5b51e9dmr3144548pfq.1.1678973184412; Thu, 16 Mar 2023 06:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678973184; cv=none; d=google.com; s=arc-20160816; b=xZPbRGpPo8yS6jOBbaOmkKmpdxNTgRPoeh/cNWt6cOlRxCJXw/vaYQc4mUNhHiTtRE mFIOl9/jLrM8W8p+olFqtcZ84O+Xnq8l+Oy5+HPxn0LTnp9t8OTCYueXhxz759SU9jbO K0nxvCF7JOaSMT0/s3XXRIls1MgD8B9bekSyUT5p8a/mN9849DRKH/vfvEHDn9yn4Nha KuSVg7dkN825AgvN/icZm6uhNpyZjDXtqKFkkM3asD3NY0YJWtt/QdxZmW1RvXNbBhRh o70qS8Q7pt46FCCy2MJ//XZIkVjNvwuJdYwwt9O0hxqnpTrxMU+KoVRywrC3hILpdArL eddA== 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=aSCNFPlD5vlrPxktzQKL9ovmSod+XcXImGuOTtOoIs8=; b=RP7txOyGGEGkiQrnBFIumfrIBNfIcgg3w3xML+Awyo9PfJpPqNAEgXU7aETrrPQEgg iNQpOWuj5QSZ6m3LV0QaVJ4dTDDWdxYFNt9YDYi9y8lcZt8vidclZ2hQpp/kEvxpcsr8 zc1WDOZam0wHVslFCoZN27ecnEq9a3aexvJ590CTAHaBm9u/7Y0vzJEcc+cZBJmnyJPh vKVIOnRCqnPdkC0+U8lgFgfubwsjfaCpKbtJbj+g5JnRDZ9hhdS+WiCar7ctIK2XNFNs zii8GnV3/i7ogP6eWiKVnfkmBmiygAtvkf3BwTmsALo5GsZj+YVwkApE6d7u4bg39ajF cHqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WTXdqjQo; 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 x24-20020a63db58000000b005034a5a0a58si7915066pgi.434.2023.03.16.06.26.09; Thu, 16 Mar 2023 06:26:24 -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=WTXdqjQo; 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 S229974AbjCPNMo (ORCPT + 99 others); Thu, 16 Mar 2023 09:12:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbjCPNMn (ORCPT ); Thu, 16 Mar 2023 09:12:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34891C8892; Thu, 16 Mar 2023 06:12:41 -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 B75A9B82165; Thu, 16 Mar 2023 13:12:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 566E5C4339B; Thu, 16 Mar 2023 13:12:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678972358; bh=HL5dP7MWYjnhj6/1lI+kn8CzDcAzNvbbqdPcXur2MCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WTXdqjQoiuRzU9sGCrP5pIDwZbI36MUvIl2syt78U8Q1x2dITlM6k6lIpq//C1r7L 8Ax+afySJ4xU4jESkys0RreCRvk0hrRP2u7x7r6Y+znMTughoGvEAnElXfaTieSg8d mtX8OTTQJUHN7L3oskDeXqp9zMbW4R7AaTwAc6BUDeqTYQLi6782iUp92Z3ESQlqWC 1xDhXj+bafQcZqfJAkwLEZ3dq42rtDOcQPWoMXDfx+AbR/kGE+zMujU9Ud7jm4N4lp O2Tcx6SLe9aTEWwPWt3RtcvJQgPPOUEhrd8QGjhzI50beb/I9Qd+F5ocTLTRpVsn/w JXyVJ5bneti/g== From: Roger Quadros To: Thinh.Nguyen@synopsys.com Cc: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Roger Quadros Subject: [PATCH 2/3] usb: dwc3-am62: Enable as a wakeup source by default Date: Thu, 16 Mar 2023 15:12:25 +0200 Message-Id: <20230316131226.89540-3-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316131226.89540-1-rogerq@kernel.org> References: <20230316131226.89540-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?1760530985663641530?= X-GMAIL-MSGID: =?utf-8?q?1760530985663641530?= USB module can wakeup system. Enable it as a wakeup source by default. Finer grain wakeup enable/disable can be done from the power/wakeup system control file of the respective USB device. Signed-off-by: Roger Quadros --- drivers/usb/dwc3/dwc3-am62.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c index 867bfa1252b8..859b48279658 100644 --- a/drivers/usb/dwc3/dwc3-am62.c +++ b/drivers/usb/dwc3/dwc3-am62.c @@ -241,6 +241,9 @@ static int dwc3_ti_probe(struct platform_device *pdev) /* Device has capability to wakeup system from sleep */ device_set_wakeup_capable(dev, true); + ret = device_wakeup_enable(dev); + if (ret) + dev_err(dev, "couldn't enable device as a wakeup source: %d\n", ret); /* Setting up autosuspend */ pm_runtime_set_autosuspend_delay(dev, DWC3_AM62_AUTOSUSPEND_DELAY); From patchwork Thu Mar 16 13:12:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 70779 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp475292wrt; Thu, 16 Mar 2023 06:15:03 -0700 (PDT) X-Google-Smtp-Source: AK7set+oCoJl6SAsUXx3L9g/zDAkqFdJK3fcZ72L8MhOODM0Q/uiNh8BpM+8aCdbfoqOQnFp/caS X-Received: by 2002:a62:7b4c:0:b0:625:cc03:df33 with SMTP id w73-20020a627b4c000000b00625cc03df33mr3129494pfc.31.1678972503094; Thu, 16 Mar 2023 06:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678972503; cv=none; d=google.com; s=arc-20160816; b=oPSyl9LcBpfOb229833jCeP4SE54jFCIgaVA5ZqyegX66/iooq2ZdwTULewWNtLebZ 5E7u5DB2j18Y/OINBTe2jsONEbf4fflOdi0ux1e1BEpSnAK2vctdA8XoxnJnGCDoEQI2 ksyTPHGAXRS7fFUirHTA5Uym9Wvr5jwxylMbshJJBmxpNU9Kw7zU3C/VRz0fIhLjNOJr cp17l7bm229HrDv6QRh2C3ZS66fKeEKAry/AcJ9sCaA86t/b7GQ0LUouZbzU3pOUSukY zFZcB5CHk3qLbGbptZ3GhQgPymHe42zvZ7n6NtIS05vsBS3krzn/Q7X0fHqjz8pgFU60 CUGQ== 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=VmjHBnQJh7OCwhZe8tvqLkIXYqNjASZIfU+B4Rece0A=; b=hKX8lThwZ0Y7qcFoOQXgt0YR+0cpBIggPETsycySsn5miiQXfpZPY2VewXxBUlcFI4 b3tGakZTcXCxt6oyl+/xAs9CTifCxjM638JSGCKsE8RO18TUV3/0VSVHrqtMDxH/Ziu0 YB8L6h6DUQPuXU6VJImw0IwsDxo3WgcI+SjQCCIAvQwEQ5Lx4MZDsb/nUza9vzJHTATM QWpUDLmjWj+i9I0/mnLsuZ6qZ7fJ3mldd6BWlfoU4gFXc4zp0c3nkI+p8rbdJoMlxiJF 1D8nIa6QMwIiOwybJOvLepFvWOn630dlZSeLd6AMLtsXMSKKoGWPIaXp/l1RQVSBrwFm MY0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HCGMki6y; 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 m3-20020a056a00080300b0062607a24e9bsi600583pfk.68.2023.03.16.06.14.45; Thu, 16 Mar 2023 06:15:03 -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=HCGMki6y; 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 S230041AbjCPNMw (ORCPT + 99 others); Thu, 16 Mar 2023 09:12:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229978AbjCPNMq (ORCPT ); Thu, 16 Mar 2023 09:12:46 -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 DF9CDC97C6; Thu, 16 Mar 2023 06:12:43 -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 56DC2B82160; Thu, 16 Mar 2023 13:12:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2896C4339E; Thu, 16 Mar 2023 13:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678972361; bh=1MM/XIDj4+n74RjajngtGaU+RhN1OSYKdhL9n+Ln1Rw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HCGMki6yauCY/bU/C7p+E5QrS3+kX//JJukwCGHCjztJhZjmw6HpXRqWhlvmUBn/z wd2aPr1mcNQ1a+DXlpuMK8/pvFrZRvpU1VaRjXpFcis548zOD+Dn24iuDar51AAN1F JzOxjFQG5xajIvqItvD4D43dU+RMTODLq4nxwNEmfhYjpybIQ4RcoZosvYh8nLhGEP CqWfoREVQlZiSyuoa+MWgnzFVWjt53owt0OESgI2vfLeNb6BpJOTmmir7rC1lQVEBP Zv95fTPZFHYobZWFFPvrIY7HOp/CS/VLaXEJyQY02P46x41KcLBfnq/6ipuMSgEDNw 7pxeldRsirz4w== From: Roger Quadros To: Thinh.Nguyen@synopsys.com Cc: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, vigneshr@ti.com, srk@ti.com, r-gunasekaran@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Roger Quadros Subject: [PATCH 3/3] usb: dwc3-am62: Fix up wake-up configuration and spurious wake up Date: Thu, 16 Mar 2023 15:12:26 +0200 Message-Id: <20230316131226.89540-4-rogerq@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230316131226.89540-1-rogerq@kernel.org> References: <20230316131226.89540-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?1760530271796411442?= X-GMAIL-MSGID: =?utf-8?q?1760530271796411442?= Explicitly set and clear wakeup config so we don't leave anything to chance. Clear wakeup status on suspend so we know what caused wake up. The LINESTATE wake up should not be enabled in device mode if we are not connected to a USB host else it will cause spurious wake up. Signed-off-by: Roger Quadros --- drivers/usb/dwc3/dwc3-am62.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c index 859b48279658..af0524e2f1e1 100644 --- a/drivers/usb/dwc3/dwc3-am62.c +++ b/drivers/usb/dwc3/dwc3-am62.c @@ -60,6 +60,13 @@ #define USBSS_WAKEUP_CFG_SESSVALID_EN BIT(1) #define USBSS_WAKEUP_CFG_VBUSVALID_EN BIT(0) +#define USBSS_WAKEUP_CFG_ALL (USBSS_WAKEUP_CFG_VBUSVALID_EN | \ + USBSS_WAKEUP_CFG_SESSVALID_EN | \ + USBSS_WAKEUP_CFG_LINESTATE_EN | \ + USBSS_WAKEUP_CFG_OVERCURRENT_EN) + +#define USBSS_WAKEUP_CFG_NONE 0 + /* WAKEUP STAT register bits */ #define USBSS_WAKEUP_STAT_OVERCURRENT BIT(4) #define USBSS_WAKEUP_STAT_LINESTATE BIT(3) @@ -103,6 +110,7 @@ struct dwc3_data { struct regmap *syscon; unsigned int offset; unsigned int vbus_divider; + u32 wakeup_stat; }; static const int dwc3_ti_rate_table[] = { /* in KHZ */ @@ -294,6 +302,7 @@ static int dwc3_ti_suspend_common(struct device *dev) { struct dwc3_data *data = dev_get_drvdata(dev); u32 reg, current_prtcap_dir; + u32 vbus_stat; if (device_may_wakeup(dev)) { reg = dwc3_ti_readl(data, USBSS_CORE_STAT); @@ -302,12 +311,20 @@ static int dwc3_ti_suspend_common(struct device *dev) /* Set wakeup config enable bits */ reg = dwc3_ti_readl(data, USBSS_WAKEUP_CONFIG); if (current_prtcap_dir == DWC3_GCTL_PRTCAP_HOST) { - reg |= USBSS_WAKEUP_CFG_LINESTATE_EN | USBSS_WAKEUP_CFG_OVERCURRENT_EN; + reg = USBSS_WAKEUP_CFG_LINESTATE_EN | USBSS_WAKEUP_CFG_OVERCURRENT_EN; } else { - reg |= USBSS_WAKEUP_CFG_OVERCURRENT_EN | USBSS_WAKEUP_CFG_LINESTATE_EN | - USBSS_WAKEUP_CFG_VBUSVALID_EN; + reg = USBSS_WAKEUP_CFG_VBUSVALID_EN | USBSS_WAKEUP_CFG_SESSVALID_EN; + /* + * Enable LINESTATE wake up only if connected to bus else + * it causes spurious wake-up. + */ + vbus_stat = dwc3_ti_readl(data, USBSS_VBUS_STAT); + if (vbus_stat & (USBSS_VBUS_STAT_SESSVALID | USBSS_VBUS_STAT_VBUSVALID)) + reg |= USBSS_WAKEUP_CFG_LINESTATE_EN; } dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, reg); + /* clear wakeup status so we know what caused the wake up */ + dwc3_ti_writel(data, USBSS_WAKEUP_STAT, USBSS_WAKEUP_STAT_CLR); } clk_disable_unprepare(data->usb2_refclk); @@ -324,16 +341,11 @@ static int dwc3_ti_resume_common(struct device *dev) if (device_may_wakeup(dev)) { /* Clear wakeup config enable bits */ - reg = dwc3_ti_readl(data, USBSS_WAKEUP_CONFIG); - reg &= ~(USBSS_WAKEUP_CFG_OVERCURRENT_EN | USBSS_WAKEUP_CFG_LINESTATE_EN | - USBSS_WAKEUP_CFG_VBUSVALID_EN); - dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, reg); + dwc3_ti_writel(data, USBSS_WAKEUP_CONFIG, USBSS_WAKEUP_CFG_NONE); } reg = dwc3_ti_readl(data, USBSS_WAKEUP_STAT); - /* Clear the wakeup status with wakeup clear bit */ - reg |= USBSS_WAKEUP_STAT_CLR; - dwc3_ti_writel(data, USBSS_WAKEUP_STAT, reg); + data->wakeup_stat = reg; return 0; }