From patchwork Thu Apr 18 00:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10906411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2374E17E0 for ; Thu, 18 Apr 2019 00:15:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000AF28BD4 for ; Thu, 18 Apr 2019 00:15:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E655628BD8; Thu, 18 Apr 2019 00:15:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 545E328BD4 for ; Thu, 18 Apr 2019 00:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XYCC4k4PRqAf46Ny1QCc6Kor06Qdcf7yhk1ly7GIz0g=; b=mqeBo0oxkXBOvT 4Ab6Tw1ZuUGm7h85QePchVceuezDFMbobJuy1j0rD0IpxHQqgEf5Di9WhRuanj83DpJZgo3XPec/l jqXP8nHzZTFGwzmoiPkxCFx0TUVrkCfOSpApUzjuCogTNDRZseU+ZjmGZGoTkhnoSHQs05PL5ePjp zgl83h8aDdo8uKzxeKkOtcXFJL6lnunu3m8ajorcRVZQhWTQRc7OqLWooO/H7a05QdlJgKsYoCx5L ZWzjNFeK3B2EacbiaSwXmYvoAuKX3PTL1TE3eslZ0j5BPs35xXYMg0NdBfJqY1IZdnfK6f4m8aN6i 6szLsEEhBX+JXU47YaZQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhw-0000Ap-SQ; Thu, 18 Apr 2019 00:15:16 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhi-0007Cd-IR for linux-rockchip@lists.infradead.org; Thu, 18 Apr 2019 00:15:06 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so229399pfc.7 for ; Wed, 17 Apr 2019 17:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kqTM4X13zllIwVukxHiG4L+ohv7hFQSZFxL4FXnl0KE=; b=P3yGxpplISbbAjyh5feqp9pmKDDhUZ6n4aB2skbFqXMwReC1ufBQbAsj4sCAj4J8er IR5cdMUZp8M57uV4tT32Slvzzrm3r3dMK4PTHr0+U7lqtR2mCKQ3YBtQAb1PcJMOTjtx ecFK9YRgTFNqcrrg/UnicukR/zopR1waAk/54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kqTM4X13zllIwVukxHiG4L+ohv7hFQSZFxL4FXnl0KE=; b=OVV/liBK9C+9yP/DiPRvmwHw4kwO7i2oLCp3bsx6wh2fbn3om8PzUfQUQhJ/KuadwU 64wVnxPx81NoHDkAieqs5dI96aYhe9TX++Vz95uHYA+o5gg5gCFQmug4gdaOPUSRlp0a ofQLOLYbJIXCYXE2BftSMfvNjm8c30gRSjLHv/eV5MaO4kjMGemAMBAc49DsxsjpQCQd 1sgDXZfq043edx5rWS6huEynDllDOjn/DY/gEd3MtVSu5EtuulE3Q2RK26Vm4pjchy5f eu9qswHcsc8K+VIgruIKIBtoZEJlQfjLNZmdkSRTfHg64reyqC/drUXePshoqvVIUIQs AiNQ== X-Gm-Message-State: APjAAAXqBrAMH7dmUHZclxmJ+mOB0rntWRBGAQQNnDYonZ7v8V2Kb1fd wbMFG0YwTfgHGUM+jWjVa7wM0Q== X-Google-Smtp-Source: APXvYqyivasih9sth0BaBOc1OCWFOlMcvZv0okIVjyRZVEgbD74taE1L9rgCQIevhcQzSJ8LltJoPA== X-Received: by 2002:aa7:884b:: with SMTP id k11mr92680149pfo.49.1555546497634; Wed, 17 Apr 2019 17:14:57 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.14.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:14:57 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Subject: [PATCH v2 1/5] usb: dwc2: bus suspend/resume for hosts with DWC2_POWER_DOWN_PARAM_NONE Date: Wed, 17 Apr 2019 17:13:52 -0700 Message-Id: <20190418001356.124334-2-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_171502_705744_7E5FF263 X-CRM114-Status: GOOD ( 20.09 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Randy Li , amstan@chromium.org, Greg Kroah-Hartman , zyw@rock-chips.com, linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Alan Stern , Elaine Zhang , jwerner@chromium.org, William Wu , ryandcase@chromium.org, dinguyen@opensource.altera.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is an attempt to rehash commit 0cf884e819e0 ("usb: dwc2: add bus suspend/resume for dwc2") on ToT. That commit was reverted in commit b0bb9bb6ce01 ("Revert "usb: dwc2: add bus suspend/resume for dwc2"") because apparently it broke the Altera SOCFPGA. With all the changes that have happened to dwc2 in the meantime, it's possible that the Altera SOCFPGA will just magically work with this change now. ...and it would be good to get bus suspend/resume implemented. This change is a forward port of one that's been living in the Chrome OS 3.14 kernel tree. Signed-off-by: Douglas Anderson --- This patch was last posted at: https://lkml.kernel.org/r/1446237173-15263-1-git-send-email-dianders@chromium.org ...and appears to have died the death of silence. Maybe it could get some bake time in linuxnext if we can't find any proactive testing? I will also freely admit that I don't know tons about the theory behind this patch. I'm mostly just re-hashing the original commit from Kever that was reverted since: * Turning on partial power down on rk3288 doesn't "just work". I don't get hotplug events. This is despite dwc2 auto-detecting that we are power optimized. * If we don't do something like this commit we don't get into as low of a power mode. Changes in v2: None drivers/usb/dwc2/hcd.c | 84 ++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index e272d020012e..978232a9e4a8 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -4482,6 +4482,7 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) unsigned long flags; int ret = 0; u32 hprt0; + u32 pcgctl; spin_lock_irqsave(&hsotg->lock, flags); @@ -4497,7 +4498,7 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) if (hsotg->op_state == OTG_STATE_B_PERIPHERAL) goto unlock; - if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL) + if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) goto skip_power_saving; /* @@ -4506,21 +4507,35 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) */ if (!hsotg->bus_suspended) { hprt0 = dwc2_read_hprt0(hsotg); - hprt0 |= HPRT0_SUSP; - hprt0 &= ~HPRT0_PWR; - dwc2_writel(hsotg, hprt0, HPRT0); - spin_unlock_irqrestore(&hsotg->lock, flags); - dwc2_vbus_supply_exit(hsotg); - spin_lock_irqsave(&hsotg->lock, flags); + if (hprt0 & HPRT0_CONNSTS) { + hprt0 |= HPRT0_SUSP; + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) + hprt0 &= ~HPRT0_PWR; + dwc2_writel(hsotg, hprt0, HPRT0); + } + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { + spin_unlock_irqrestore(&hsotg->lock, flags); + dwc2_vbus_supply_exit(hsotg); + spin_lock_irqsave(&hsotg->lock, flags); + } else { + pcgctl = readl(hsotg->regs + PCGCTL); + pcgctl |= PCGCTL_STOPPCLK; + writel(pcgctl, hsotg->regs + PCGCTL); + } } - /* Enter partial_power_down */ - ret = dwc2_enter_partial_power_down(hsotg); - if (ret) { - if (ret != -ENOTSUPP) - dev_err(hsotg->dev, - "enter partial_power_down failed\n"); - goto skip_power_saving; + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { + /* Enter partial_power_down */ + ret = dwc2_enter_partial_power_down(hsotg); + if (ret) { + if (ret != -ENOTSUPP) + dev_err(hsotg->dev, + "enter partial_power_down failed\n"); + goto skip_power_saving; + } + + /* After entering partial_power_down, hardware is no more accessible */ + clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); } /* Ask phy to be suspended */ @@ -4530,9 +4545,6 @@ static int _dwc2_hcd_suspend(struct usb_hcd *hcd) spin_lock_irqsave(&hsotg->lock, flags); } - /* After entering partial_power_down, hardware is no more accessible */ - clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); - skip_power_saving: hsotg->lx_state = DWC2_L2; unlock: @@ -4545,6 +4557,7 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) { struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd); unsigned long flags; + u32 pcgctl; int ret = 0; spin_lock_irqsave(&hsotg->lock, flags); @@ -4555,17 +4568,11 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) if (hsotg->lx_state != DWC2_L2) goto unlock; - if (hsotg->params.power_down != DWC2_POWER_DOWN_PARAM_PARTIAL) { + if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) { hsotg->lx_state = DWC2_L0; goto unlock; } - /* - * Set HW accessible bit before powering on the controller - * since an interrupt may rise. - */ - set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); - /* * Enable power if not already done. * This must not be spinlocked since duration @@ -4577,10 +4584,23 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) spin_lock_irqsave(&hsotg->lock, flags); } - /* Exit partial_power_down */ - ret = dwc2_exit_partial_power_down(hsotg, true); - if (ret && (ret != -ENOTSUPP)) - dev_err(hsotg->dev, "exit partial_power_down failed\n"); + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { + /* + * Set HW accessible bit before powering on the controller + * since an interrupt may rise. + */ + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); + + + /* Exit partial_power_down */ + ret = dwc2_exit_partial_power_down(hsotg, true); + if (ret && (ret != -ENOTSUPP)) + dev_err(hsotg->dev, "exit partial_power_down failed\n"); + } else { + pcgctl = readl(hsotg->regs + PCGCTL); + pcgctl &= ~PCGCTL_STOPPCLK; + writel(pcgctl, hsotg->regs + PCGCTL); + } hsotg->lx_state = DWC2_L0; @@ -4592,10 +4612,12 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd) spin_unlock_irqrestore(&hsotg->lock, flags); dwc2_port_resume(hsotg); } else { - dwc2_vbus_supply_init(hsotg); + if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) { + dwc2_vbus_supply_init(hsotg); - /* Wait for controller to correctly update D+/D- level */ - usleep_range(3000, 5000); + /* Wait for controller to correctly update D+/D- level */ + usleep_range(3000, 5000); + } /* * Clear Port Enable and Port Status changes. From patchwork Thu Apr 18 00:13:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10906409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67A9114DB for ; Thu, 18 Apr 2019 00:15:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DAA328BD4 for ; Thu, 18 Apr 2019 00:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 419A828BD7; Thu, 18 Apr 2019 00:15:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BE40A28BD4 for ; Thu, 18 Apr 2019 00:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ds8D3xXXd8XjA6MDTGfVUiFDYiQqt5i1smEvEebmEF4=; b=kiUWW8ywNVDQTf vDyLjEZHokOuNml7ZH7AtP5/w2HDFMswk1uBUPi18ePTk6PEAycoWYy/ppmo+weUjVwLe9B0ADijd BLXrLvHIdZbsrZbS9w8m9ALd0TE1fuKzLtmM7mtqhxjAAUn5pWKIeyGzMCLaEU9zGlIuTi9qpmRK3 9BpuUWlBd9gDK0q9+jD95u3hw2VY8EqueCps8fUskZaxCOfWYWE+Bs4WfcDNNQ8oe5th0RsSTcaz1 uL4egfP08VaMuK939IXq3/lHnMLShhn/9M6zCIrGYjoxX3Ym+M3FjvDlUWpUx3M0fSsOnIElXwCRN xTbPUBFyJQOF9ueDI2eg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhv-00008Z-Az; Thu, 18 Apr 2019 00:15:15 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhi-0007Cf-IM for linux-rockchip@lists.infradead.org; Thu, 18 Apr 2019 00:15:06 +0000 Received: by mail-pf1-x441.google.com with SMTP id 8so236882pfr.4 for ; Wed, 17 Apr 2019 17:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FEymG5YLHbrDDzFxo52pdSm6cWs0XYbMN/p1plON6hw=; b=IxvwAG/FD+h3vReXVkO8WN6TgoWmn5hmjEDHCWUqYGymihVRS6a5o1mVUT3QNKxtUS s8WcGVHZle2CbosV4XoPgSRF+m5tBlUbQOt2yAkreM99lgKyKUsc0Fkuy3JlX/HFQ/4d bdAJoUwFWOoAEIZttOkK4YpGJT2cIkcGbSuHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FEymG5YLHbrDDzFxo52pdSm6cWs0XYbMN/p1plON6hw=; b=cCoT1BLaFq1B9q5qbsybBE+8re7L54yUdT2btqlPPjoyhqpLGgAWCT/MkHc2fGRNem vCRH/t+1R2KwtmUJSENQFGrrv3DC92yq//UvNwA9s+nKfOAlfZz0+t6xiTlZ2UnEvRYw J1zgvNcxaHyh2h4XmI9PvRd/TwUBuMK5eZQS3ZdhAUR59BOEc4tmPZqjAh6gGiKBHeq+ qqyw0X9ofZkxoEU1SuUaTTXiFKy7haFt6JYrO19hd7j+QozD2M3Q9pKLz6ZcaeW02FZg yMxTaP8+2GrHmYg6vnZBRDuvtrd/8BYCxLYaCUk7SldYqGjCY8+ZRK94fHaolHHdOvG/ x6pA== X-Gm-Message-State: APjAAAWPI9C/iFawkXmM4KHaw7so98oLgpCg67wZ0cHcL8u4B1Vs3AoK jPlHSDFRBlMo6q9LxUpLv+1tAA== X-Google-Smtp-Source: APXvYqzyMQB6DofPsR3ROmeLa7d3NvmAdljo4RKmr1talzLCVFturW2bHncz7YNf+WhFu2sdhPQ5/g== X-Received: by 2002:a62:aa06:: with SMTP id e6mr2953350pff.254.1555546499283; Wed, 17 Apr 2019 17:14:59 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.14.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:14:58 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Subject: [PATCH v2 2/5] USB: Export usb_wakeup_enabled_descendants() Date: Wed, 17 Apr 2019 17:13:53 -0700 Message-Id: <20190418001356.124334-3-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_171502_685818_24B056D1 X-CRM114-Status: GOOD ( 12.66 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Amelie Delaunay , linux-kernel@vger.kernel.org, Kai-Heng Feng , zyw@rock-chips.com, Stefan Wahren , Nicolas Boichat , linux-rockchip@lists.infradead.org, mka@chromium.org, Alan Stern , Jon Flatley , Artur Petrosyan , Elaine Zhang , amstan@chromium.org, Randy Li , Mathias Nyman , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Douglas Anderson , ryandcase@chromium.org, William Wu , jwerner@chromium.org, dinguyen@opensource.altera.com, Nicolas Saenz Julienne Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In (e583d9d USB: global suspend and remote wakeup don't mix) we introduced wakeup_enabled_descendants() as a static function. We'd like to use this function in USB controller drivers to know if we should keep the controller on during suspend time, since doing so has a power impact. Signed-off-by: Douglas Anderson --- For relevant prior discussion of this idea, see: https://lkml.kernel.org/r/1436207224-21849-4-git-send-email-dianders@chromium.org If I'm reading all the responses correctly folks were of the opinion that this patch is still the right way to go. Changes in v2: None drivers/usb/core/hub.c | 7 ++++--- include/linux/usb/hcd.h | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 8d4631c81b9f..5e8f3fa7ae5a 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -3174,13 +3174,14 @@ static int usb_disable_remote_wakeup(struct usb_device *udev) } /* Count of wakeup-enabled devices at or below udev */ -static unsigned wakeup_enabled_descendants(struct usb_device *udev) +unsigned usb_wakeup_enabled_descendants(struct usb_device *udev) { struct usb_hub *hub = usb_hub_to_struct_hub(udev); return udev->do_remote_wakeup + (hub ? hub->wakeup_enabled_descendants : 0); } +EXPORT_SYMBOL_GPL(usb_wakeup_enabled_descendants); /* * usb_port_suspend - suspend a usb device's upstream port @@ -3282,7 +3283,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) * Therefore we will turn on the suspend feature if udev or any of its * descendants is enabled for remote wakeup. */ - else if (PMSG_IS_AUTO(msg) || wakeup_enabled_descendants(udev) > 0) + else if (PMSG_IS_AUTO(msg) || usb_wakeup_enabled_descendants(udev) > 0) status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); else { @@ -3687,7 +3688,7 @@ static int hub_suspend(struct usb_interface *intf, pm_message_t msg) } if (udev) hub->wakeup_enabled_descendants += - wakeup_enabled_descendants(udev); + usb_wakeup_enabled_descendants(udev); } if (hdev->do_remote_wakeup && hub->quirk_check_port_auto_suspend) { diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 695931b03684..ed4fbbd1b35f 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -652,11 +652,16 @@ extern wait_queue_head_t usb_kill_urb_queue; #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) #ifdef CONFIG_PM +extern unsigned usb_wakeup_enabled_descendants(struct usb_device *udev); extern void usb_root_hub_lost_power(struct usb_device *rhdev); extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); #else +static inline unsigned usb_wakeup_enabled_descendants(struct usb_device *udev) +{ + return 0; +} static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) { return; From patchwork Thu Apr 18 00:13:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10906415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5362914DB for ; Thu, 18 Apr 2019 00:15:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3733428BD4 for ; Thu, 18 Apr 2019 00:15:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2AFE128BD7; Thu, 18 Apr 2019 00:15:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C0C2A28BD4 for ; Thu, 18 Apr 2019 00:15:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0CXWgR5+ljoxwexGrrIoEU5VSilDuNV92K7zwBC7CuE=; b=T50IIyt+PR4eSr NofFZ6yKQz2dm+TxRc9xvim90bbt3CQVF6MDjJ1CgbVhI6MNKHFEzqx+2j1ttf9mne0GkuCRD/PjO tXRqzUKEF9kl71Anyx+fmGk5qwHL5H2g/KYocBncK6SQ4/VpHVw6mpKFr0YzKt2A9z4fkdhKzchGO QJ+ia6treckB+wcnxTmch+bhT1nVQ4B4Un3jDT8+P3O0r99iLK/r4AvB1+cASVPGf9f6FsIUpcSEN F3F7H1M7/wTQzAuB7hGv5n8Q8yzMbXV3glmZgs4ngSr0IXjseKIbNkMLKDfTnS5LPBUpYb1SLa0Y4 2qhfa9OHtcYiz0v2HkDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGui0-0000G1-3M; Thu, 18 Apr 2019 00:15:20 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhj-0007Ch-7t for linux-rockchip@lists.infradead.org; Thu, 18 Apr 2019 00:15:06 +0000 Received: by mail-pg1-x544.google.com with SMTP id l18so169748pgj.6 for ; Wed, 17 Apr 2019 17:15:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8a+BZEe7v/lxE++Jk26DJvDIeRtcgS+edmxjVgSar6E=; b=IVSeUaSONgbK9dI1ta/UwuOc1HRfMQvPSCtcNOmVBdiHzUEh6REoeZBCONmL+PZwSV gdii0s7Vx/s52jH8A1PQYwkkHw9YqXyjHxrrr/jGLWyyR7H1KXSZpkgeusUpVeqsGy6D hURXqfMjL0W5jtLLmOK6G1hVPp3iOLlOrIF3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8a+BZEe7v/lxE++Jk26DJvDIeRtcgS+edmxjVgSar6E=; b=Kkb2WSuYO48ocQAKEs0shJzu1W2rr6wKWAnDrohbrX2LKCR14aMa1u2D6RS12/iO+Q efO/9MXH6yv8ej4/sjQ0Y1d8IrQA339/Otjc+AvaS7vsYOjYRHoCSmSHcGHyanlTFCGC X2UdBfipsWdsWk78LDJfXopcRwVDdwUus+//NWSobUKZtArYh92Xy9hScdjeV7OCEEbw R/5JFqT9/HyPAVyQRrmn6Li139nfk6D3oQP/NbJ41pG4wx1WtL3xgUzBmKU9NJ2G1Khm 4G0XIuZJ7Cy1dvBQZFdJ+p56bL4BNpByjfqZ4mbdKs3DDz2Ezw/VvV4bqgffXfnTyays vjLA== X-Gm-Message-State: APjAAAXdpljKvQHNI5PxQ1l1WwVS4punfEW923kHcQrvTT+bt7Y08BbT F8gba+D89qg45O3R7/tBZ6cZzg== X-Google-Smtp-Source: APXvYqxYqSg78iVNlYmCW86sspNg6ANcr7iduniZLCDqL6dcz9Jy0fjB/9qbeZkfU6namPKEZg5IPQ== X-Received: by 2002:a62:6fc6:: with SMTP id k189mr74302179pfc.154.1555546500578; Wed, 17 Apr 2019 17:15:00 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.14.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:15:00 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Subject: [PATCH v2 3/5] Documentation: dt-bindings: Add snps, need-phy-for-wake for dwc2 USB Date: Wed, 17 Apr 2019 17:13:54 -0700 Message-Id: <20190418001356.124334-4-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_171503_329855_756567A7 X-CRM114-Status: GOOD ( 15.12 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Randy Li , amstan@chromium.org, devicetree@vger.kernel.org, Greg Kroah-Hartman , zyw@rock-chips.com, linux-usb@vger.kernel.org, Douglas Anderson , Rob Herring , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Alan Stern , Mark Rutland , Elaine Zhang , jwerner@chromium.org, William Wu , ryandcase@chromium.org, dinguyen@opensource.altera.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some SoCs with a dwc2 USB controller may need to keep the PHY on to support remote wakeup. Allow specifying this as a device tree property. Signed-off-by: Douglas Anderson --- For relevant prior discussion on this patch, see: https://lkml.kernel.org/r/1435017144-2971-3-git-send-email-dianders@chromium.org I didn't make any changes from the prior version since I never found out what Rob thought of my previous arguments. If folks want a change, perhaps they could choose from these options: 1. Assume that all dwc2 hosts would like to keep their PHY on for suspend if there's a USB wakeup enabled, thus we totally drop this binding. This doesn't seem super great to me since I'd bet that many devices that use dwc2 weren't designed for USB wakeup (they may not keep enough clocks or rails on) so we might be wasting power for nothing. 2. Rename this property to "snps,wakeup-from-suspend-with-phy" to make it more obvious that this property is intended both to document that wakeup from suspend is possible and that we need the PHY for said wakeup. 3. Rename this property to "snps,can-wakeup-from-suspend" and assume it's implicit that if we can wakeup from suspend that we need to keep the PHY on. If/when someone shows that a device exists using dwc2 where we can wakeup from suspend without the PHY they can add a new property. Changes in v2: None Documentation/devicetree/bindings/usb/dwc2.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt b/Documentation/devicetree/bindings/usb/dwc2.txt index f70f3aee4bfc..1c5e29d23c51 100644 --- a/Documentation/devicetree/bindings/usb/dwc2.txt +++ b/Documentation/devicetree/bindings/usb/dwc2.txt @@ -37,6 +37,8 @@ Refer to phy/phy-bindings.txt for generic phy consumer properties - g-rx-fifo-size: size of rx fifo size in gadget mode. - g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode. - g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget mode. +- snps,need-phy-for-wake: If present indicates that the phy needs to be left + on for remote wakeup during suspend. - snps,reset-phy-on-wake: If present indicates that we need to reset the PHY when we detect a wakeup. This is due to a hardware errata. @@ -53,4 +55,5 @@ Example: clock-names = "otg"; phys = <&usbphy>; phy-names = "usb2-phy"; + snps,need-phy-for-wake; }; From patchwork Thu Apr 18 00:13:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10906413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92C0A17E6 for ; Thu, 18 Apr 2019 00:15:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7724D28BD4 for ; Thu, 18 Apr 2019 00:15:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A61328BD7; Thu, 18 Apr 2019 00:15:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E015928BD5 for ; Thu, 18 Apr 2019 00:15:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ic1Q9KIt8g3Vx98aoERirhmskbJKG7DbDWlzb4E3dP0=; b=S2Tvu+OWKzSMvh nNWJeDGZ2hpHZexCoEPa3VgaazzGilxY1ZL/Ffm297opADMC0Pi853J6wSaM3Ya0DOdmGjMEnHIdl d+UoHUuGrWBZKtRHN/xkIf162TorgNFY9EBfu+UkJ8vZhVSZDjyVzgLQt+/AUaVMow4MKU9dRX5e6 X0b99qWH33Nuj8BXde9xs510TESVWdPTAmhoJo3jYnJftmb5Tx1uufNrfxWdVBkDbJUD8ZaC2ww59 iLAoqoy6f/teGPw/GzFZynIuYn+UsMwRiA4Sfemruhf32HnI2obyB6YsHdQF4YqJfpMeJouG9IA0d Rs1GigDG4x1Z7G/Fh1HA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhy-0000DA-6k; Thu, 18 Apr 2019 00:15:18 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhj-0007L0-5f for linux-rockchip@lists.infradead.org; Thu, 18 Apr 2019 00:15:06 +0000 Received: by mail-pg1-x542.google.com with SMTP id k19so315079pgh.0 for ; Wed, 17 Apr 2019 17:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MIQc6nb78x4dX7zZdpFCr2Ou987p1QUJbog7A/7Fv+o=; b=mixCdUtwMK+XLff4ncol1Q/8d97x7uycyS81jNA6X8UeFFCPVEiwfCbVn3fmxHXH2n WZBSKRzGfuOth7RXk3aT2rquxXh4yZsXZOePcLhgUoWHJ4g7sKlwpO34Mo86+wQ3fMkr PUbwgq85Piz5xEcnPXjzHl7xjl5SuE0gnsEnM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MIQc6nb78x4dX7zZdpFCr2Ou987p1QUJbog7A/7Fv+o=; b=El4BPa2CRqxNqo7PO7pzPKjgu1CjycmPNTMkXsfzj9U8greFrUB424YlnRAM91orvC oyO1FKEMaTLT6RVgfznGTIsxHIZfnQOTsfelY3aLPVsD2Vcx5AEG9EygjLgQeKcCZZAX uuuDXClPxKVoe+0NNsOh3C5B8yOevRj7/7BvILAJwUZQz4F2jF2/9cL60f+TWX87QI1T NE1cXvz7/T7+T/qmeWvEqfrHZyo7SnpBBOn5qA0eJiXO+GFXklkuM2u2wWLNjdF+Pazk GDfSdPmY4yQnS0e+5AY9IEJiZH4D1d0lCplNNvaW/hpZbNH+R28CeCZfFLaqnw63zVy2 mQLA== X-Gm-Message-State: APjAAAXuIekwI4QczaiXM31bwenvzN1FHd9NnVV636UJpYFMm7OMRnsI zadqo75BK3Ty7a2ZSP/woVB5Y5prS7k= X-Google-Smtp-Source: APXvYqxx2dZRVxVNGwedp5XviAZdXPDEUKgfhKXZ+ubd9+S7qL/RTyB90fe0SwHbr45tjLTZpZWzKg== X-Received: by 2002:a63:c746:: with SMTP id v6mr84071022pgg.401.1555546501936; Wed, 17 Apr 2019 17:15:01 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.15.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:15:01 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Subject: [PATCH v2 4/5] USB: dwc2: Don't turn off the usbphy in suspend if wakeup is enabled Date: Wed, 17 Apr 2019 17:13:55 -0700 Message-Id: <20190418001356.124334-5-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_171503_264276_F46F90A4 X-CRM114-Status: GOOD ( 22.70 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Randy Li , amstan@chromium.org, Greg Kroah-Hartman , zyw@rock-chips.com, linux-usb@vger.kernel.org, Douglas Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Alan Stern , Elaine Zhang , jwerner@chromium.org, William Wu , ryandcase@chromium.org, dinguyen@opensource.altera.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP If the 'snps,need-phy-for-wake' is set in the device tree then: - We know that we can wakeup, so call device_set_wakeup_capable(). The USB core will use this knowledge to enable wakeup by default. - We know that we should keep the PHY on during suspend if something on our root hub needs remote wakeup. This requires the patch (USB: Export usb_wakeup_enabled_descendants()). Note that we don't keep the PHY on at suspend time if it's not needed because it would be a power draw. If we later find some users of dwc2 that can support wakeup without keeping the PHY on we may want to add a way to call device_set_wakeup_capable() without keeping the PHY on at suspend time. Signed-off-by: Douglas Anderson Signed-off-by: Chris Zhong --- For relevant prior discussion of this idea, see: https://lkml.kernel.org/r/1436207224-21849-4-git-send-email-dianders@chromium.org If I'm reading all the responses correctly folks were of the opinion that this patch is still the right way to go. Changes in v2: - Rebased to mainline atop rk3288 remote wake quirk series. drivers/usb/dwc2/core.h | 5 +++++ drivers/usb/dwc2/platform.c | 43 +++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h index f30748f4fe7e..a99fe7851352 100644 --- a/drivers/usb/dwc2/core.h +++ b/drivers/usb/dwc2/core.h @@ -861,6 +861,9 @@ struct dwc2_hregs_backup { * @hibernated: True if core is hibernated * @reset_phy_on_wake: Quirk saying that we should assert PHY reset on a * remote wakeup. + * @phy_off_for_suspend: Status of whether we turned the PHY off at suspend. + * @need_phy_for_wake: Quirk saying that we should keep the PHY on at + * suspend if we need USB to wake us up. * @frame_number: Frame number read from the core. For both device * and host modes. The value ranges are from 0 * to HFNUM_MAX_FRNUM. @@ -1049,6 +1052,8 @@ struct dwc2_hsotg { unsigned int ll_hw_enabled:1; unsigned int hibernated:1; unsigned int reset_phy_on_wake:1; + unsigned int need_phy_for_wake:1; + unsigned int phy_off_for_suspend:1; u16 frame_number; struct phy *phy; diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c index 9b65b766e0b9..6f0271c5d163 100644 --- a/drivers/usb/dwc2/platform.c +++ b/drivers/usb/dwc2/platform.c @@ -47,7 +47,9 @@ #include #include #include +#include +#include #include #include "core.h" @@ -450,6 +452,10 @@ static int dwc2_driver_probe(struct platform_device *dev) if (retval) goto error; + hsotg->need_phy_for_wake = + of_property_read_bool(dev->dev.of_node, + "snps,need-phy-for-wake"); + /* * Reset before dwc2_get_hwparams() then it could get power-on real * reset value form registers. @@ -481,6 +487,14 @@ static int dwc2_driver_probe(struct platform_device *dev) hsotg->gadget_enabled = 1; } + /* + * If we need PHY for wakeup we must be wakeup capable. + * When we have a device that can wake without the PHY we + * can adjust this condition. + */ + if (hsotg->need_phy_for_wake) + device_set_wakeup_capable(&dev->dev, true); + hsotg->reset_phy_on_wake = of_property_read_bool(dev->dev.of_node, "snps,reset-phy-on-wake"); @@ -516,6 +530,28 @@ static int dwc2_driver_probe(struct platform_device *dev) return retval; } +static bool __maybe_unused dwc2_can_poweroff_phy(struct dwc2_hsotg *dwc2) +{ + struct usb_device *root_hub = dwc2_hsotg_to_hcd(dwc2)->self.root_hub; + + if (!dwc2->ll_hw_enabled) + return false; + + /* If the controller isn't allowed to wakeup then we can power off. */ + if (!device_may_wakeup(dwc2->dev)) + return true; + + /* + * We don't want to power off the PHY if something under the + * root hub has wakeup enabled. + */ + if (usb_wakeup_enabled_descendants(root_hub)) + return false; + + /* No reason to keep the PHY powered, so allow poweroff */ + return true; +} + static int __maybe_unused dwc2_suspend(struct device *dev) { struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); @@ -524,8 +560,10 @@ static int __maybe_unused dwc2_suspend(struct device *dev) if (dwc2_is_device_mode(dwc2)) dwc2_hsotg_suspend(dwc2); - if (dwc2->ll_hw_enabled) + if (dwc2_can_poweroff_phy(dwc2)) { ret = __dwc2_lowlevel_hw_disable(dwc2); + dwc2->phy_off_for_suspend = true; + } return ret; } @@ -535,11 +573,12 @@ static int __maybe_unused dwc2_resume(struct device *dev) struct dwc2_hsotg *dwc2 = dev_get_drvdata(dev); int ret = 0; - if (dwc2->ll_hw_enabled) { + if (dwc2->phy_off_for_suspend && dwc2->ll_hw_enabled) { ret = __dwc2_lowlevel_hw_enable(dwc2); if (ret) return ret; } + dwc2->phy_off_for_suspend = false; if (dwc2_is_device_mode(dwc2)) ret = dwc2_hsotg_resume(dwc2); From patchwork Thu Apr 18 00:13:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10906417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEA0414DB for ; Thu, 18 Apr 2019 00:15:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D65F128BD4 for ; Thu, 18 Apr 2019 00:15:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA08B28BD8; Thu, 18 Apr 2019 00:15:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 74AEF28BD4 for ; Thu, 18 Apr 2019 00:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=43vIlQkICmM5eaf9pxay42gJYeI0v88yQf7toLfePVs=; b=GptoxAREy68IMs 1MnlpDueKX4cW5WgBCbnPY6sss4BMI3kLnkSqn3leuBcxGmNmiXAnJN9RJ4Z2BcpO718pDekykZ8o rfoPkOABZ1zYABJTAot3tEQqwGhEep5MaxPliFTyZwQ/v4l0yugDpMksczEZnrjdfKAUSouu//16m ilUNNof2z5Gkz43JyMUuDxuqBES7mkQYguw9aZUFzZ76mEOo8ex4s7zlRm+mBZUxwOV1Jm8uuOfMZ 4voadHQBQs4Kd/lO3mBSlixfVQw928779dctspZ9ecahS4wvc67Ae98eEpIAEdUOLSil3A+C9l51l iTPoI5/BNJyarRWk00DA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGui2-0000KW-TC; Thu, 18 Apr 2019 00:15:22 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGuhm-0007WG-GY for linux-rockchip@lists.infradead.org; Thu, 18 Apr 2019 00:15:10 +0000 Received: by mail-pl1-x644.google.com with SMTP id w23so270536ply.4 for ; Wed, 17 Apr 2019 17:15:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9dHCbPnlI9BSQxis0+totmB/WamSdFGOvfhVYVfhROQ=; b=g+JqrgM6CtbjdujZ4bhx4uBddKF+4SRVyOciP5srObjxxh8KDMl19YmZbkZRq9D6ro /oQuSYOpqFTsQE5PzmeCMGPnnB5FLYBf00CWcGLWBi2Ml0xUlmRHTB/JAtskaKWlNo5g dQmAwOypdXgrccYfyYUTb/Z2JAOT2ZOBU3IHI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9dHCbPnlI9BSQxis0+totmB/WamSdFGOvfhVYVfhROQ=; b=NLdJ2ycefuHjnSK8TLGX8DFuky9ytF7WeHNepn2RxAI4n5Mgiwvfo1urZe1g3krNFN kW3bk7yPc0Yf1zZVZcAaBD+n9nS1HpFtLQk22g1jubNK4Nf+5LPkEZIWrYb6RuYpZ3ZP zHBp5PNqmYcPSTx65I4Fawrbjtpgk4EpHrDxnz/BbCOZ3h819Mvjho6ydLJTuDJBmjlY R6ulkoDlx+QvH2QetKlxuWYJBA1J6BoQ7FwGfmqYC37ICcL8vF+3CuCF9ApG+hdVbeIZ XOIVtf5w/P7GuE/tFsvcHOwgWFBd4OXElJbZyz1busqt4six6y2pm0YAl5FR6grCMT2v yu0w== X-Gm-Message-State: APjAAAVzOR0huh6XvaJFFAKi++GzWQTMsIZebi/yKah7MLHaLBlq6q9w lHbE99XBqYbEoh7P//n9FkWeJw== X-Google-Smtp-Source: APXvYqxWk5e1kbmfttQMLubOoAO7jJexKAOokKqYIE8CqxPpp93l2fjdF31N53x3ArHo1fS2mksl/Q== X-Received: by 2002:a17:902:2aeb:: with SMTP id j98mr25482240plb.38.1555546503259; Wed, 17 Apr 2019 17:15:03 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id q5sm447668pff.97.2019.04.17.17.15.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Apr 2019 17:15:02 -0700 (PDT) From: Douglas Anderson To: Minas Harutyunyan , Felipe Balbi , heiko@sntech.de Subject: [PATCH v2 5/5] ARM: dts: rockchip: Allow wakeup from rk3288-veyron's dwc2 USB ports Date: Wed, 17 Apr 2019 17:13:56 -0700 Message-Id: <20190418001356.124334-6-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.593.g511ec345e18-goog In-Reply-To: <20190418001356.124334-1-dianders@chromium.org> References: <20190418001356.124334-1-dianders@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190417_171506_741460_2825DEAE X-CRM114-Status: GOOD ( 13.02 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , Artur Petrosyan , Amelie Delaunay , Randy Li , amstan@chromium.org, devicetree@vger.kernel.org, zyw@rock-chips.com, linux-usb@vger.kernel.org, Douglas Anderson , Rob Herring , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, mka@chromium.org, Alan Stern , Mark Rutland , Elaine Zhang , jwerner@chromium.org, William Wu , ryandcase@chromium.org, dinguyen@opensource.altera.com, linux-arm-kernel@lists.infradead.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We want to be able to wake from USB if a device is plugged in that wants remote wakeup. Enable it on both dwc2 controllers. NOTE: this is added specifically to veyron and not to rk3288 in general since it's not known whether all rk3288 boards are designed to support USB wakeup. It is plausible that some boards could shut down important rails in S3. Also note that currently wakeup doesn't seem to happen unless you use the "deep" suspend mode (where SDRAM is turned off). Presumably the shallow suspend mode is gating some sort of clock that's important but I couldn't easily figure out how to get it working. Signed-off-by: Douglas Anderson --- Changes in v2: - rk3288-veyron dts patch new for v2. arch/arm/boot/dts/rk3288-veyron.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/boot/dts/rk3288-veyron.dtsi b/arch/arm/boot/dts/rk3288-veyron.dtsi index 1252522392c7..1d8bfed7830c 100644 --- a/arch/arm/boot/dts/rk3288-veyron.dtsi +++ b/arch/arm/boot/dts/rk3288-veyron.dtsi @@ -424,6 +424,7 @@ &usb_host1 { status = "okay"; + snps,need-phy-for-wake; }; &usb_otg { @@ -432,6 +433,7 @@ assigned-clocks = <&cru SCLK_USBPHY480M_SRC>; assigned-clock-parents = <&usbphy0>; dr_mode = "host"; + snps,need-phy-for-wake; }; &vopb {