Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1715110pxp; Thu, 17 Mar 2022 15:17:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjmhK1FJlTG2dE11n8yfjniZxIQEjSWcSHwwWVYJ/rDVRhCBSXq+ilYJXeALUF8EGP1Tti X-Received: by 2002:a50:da8b:0:b0:415:a122:d7ad with SMTP id q11-20020a50da8b000000b00415a122d7admr6708697edj.123.1647555446773; Thu, 17 Mar 2022 15:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647555446; cv=none; d=google.com; s=arc-20160816; b=067yl+RhQXiAsyOpGcNrFFS+epkYmdIwyeMYVrHjnZK7r/qI1VobychVTTXjmL814V Dg3zkt2CMG61MRLhSCGuVIvFnnx1V74fU90t3Ono+fIV4Onug7rGMkKK7zQ+ttialq75 MKOaZ8SDRmPIk3RxxpoZ5tKC1Ko37UF6W2zGgSbvu5i6PsXYKDG4lo9dFW2yV/TnOhvg u/0gMrd9fY244jn9gavVAOQSXy0IXzW9aDjX+y6pU+HHUUGCb5OvDLBBnBaLx+DIC/P6 ubQJh3Otdrd5OM0fj5AK50Gu8ctzEs64wTCbiXyQ+aTMmHTlAuPUbdXhkR18hUcRH+G/ Qjkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:user-agent:from :references:in-reply-to:mime-version:dkim-signature; bh=7a705il38wQNIgcW74B99Zg1pH09khmZyWTP/+DOfM8=; b=Oz+Ryajyx87X+erckCENYAsQ3KMooPtnrLv9cwgdjgLixMcxGuZe4nR5HhbI3NM7/M 4iKQb6ZW55ouloUkKQzgHE3ffe4QJ2vVLz30ykD36K08mZt+A8UKiI+yLMuiZa/zvNx3 AQ6rh23XkCQT/daEN0FpBbLXXfXIYn85LljAwCw+XRAmQ6HIdM7yjff6qjDe0FrqVy+b yjQVzZOrZWBTV/MZPAbvRSiUxxgzgywz9BT4L5aKfP9kBPuRgcp0TmL6nP+DuMXWd4Dx PLB98NicRyC0m5ehrUMCYWBbQZ4i8FzoJtgsVvFj7j8Yv0xZDkTvy9d9YcdGAfAgg8ws OYiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h98yCe7f; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a17090610c400b006df76385ebfsi223506ejv.863.2022.03.17.15.17.01; Thu, 17 Mar 2022 15:17:26 -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=@chromium.org header.s=google header.b=h98yCe7f; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229561AbiCQWJL (ORCPT + 99 others); Thu, 17 Mar 2022 18:09:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbiCQWJJ (ORCPT ); Thu, 17 Mar 2022 18:09:09 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6B881C9B4F for ; Thu, 17 Mar 2022 15:07:50 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id o83so7138988oif.0 for ; Thu, 17 Mar 2022 15:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:user-agent:date:message-id :subject:to:cc; bh=7a705il38wQNIgcW74B99Zg1pH09khmZyWTP/+DOfM8=; b=h98yCe7fgQnBGQkCGLi0Th0UZFhv6CJewtkHxfhJIcJJR+xNQ4UXReJDQWkxfXP1T6 1CdqqeRoZi2c8hKnTWD6RKwM8tV0cnhlOGJu+E3pKLugZctBxNAdUzs6QkKImXJr1zQR EJeq/FgutrCMZxSG0GtafUys5JAOdPHWuOrY8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from :user-agent:date:message-id:subject:to:cc; bh=7a705il38wQNIgcW74B99Zg1pH09khmZyWTP/+DOfM8=; b=YUolQz69D8/61JANYwUJl4f9aZsKC7t7oildMXm8QePuWaH2DeOcxIVecF4KY9akh2 siycd4UXQNt4qmfuRmg1ygBsz/0yHz+o2o7s+CBWxtSFQxS3Amf11B8Uq32InmSL3WRx hmGLzl9/hlJLlX2/1uaDU+jZAuTMpgUkfp5dlRKjQ9IHDj8ZiBY5gZvy3+Zb/VhDqwk+ 81J6Ei9MUwRxmHjwP1U6w6y3NgFWLq7mcA2yZG/noSZpeR91yJn8mmUDD83uMcRSuF03 WySEIsjZqAinWbviZHWEktUnWgrdfHYI7D6WifUeO1ELI/iBCLOyrohp6leAc7iaxwJJ ERbQ== X-Gm-Message-State: AOAM5323MFGg//P9kKJVUqdo4+ufCdJFUGitPn0qwWDkn2kUwOdOa7dG xA7//WfTUXWrW9khTemDaTAUi/r+jdQwlW8EiQgBwg== X-Received: by 2002:aca:bd41:0:b0:2ec:ff42:814f with SMTP id n62-20020acabd41000000b002ecff42814fmr3089735oif.63.1647554870183; Thu, 17 Mar 2022 15:07:50 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 17 Mar 2022 18:07:49 -0400 MIME-Version: 1.0 In-Reply-To: <1646679306-4768-1-git-send-email-quic_pmaliset@quicinc.com> References: <1646679306-4768-1-git-send-email-quic_pmaliset@quicinc.com> From: Stephen Boyd User-Agent: alot/0.10 Date: Thu, 17 Mar 2022 18:07:49 -0400 Message-ID: Subject: Re: [PATCH v4] PCI: qcom: Add system PM support To: Prasad Malisetty , agross@kernel.org, bhelgaas@google.com, bjorn.andersson@linaro.org, kw@linux.com, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, rajatja@google.com, refactormyself@gmail.com, robh@kernel.org Cc: quic_vbadigan@quicinc.com, quic_ramkri@quicinc.com, manivannan.sadhasivam@linaro.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Quoting Prasad Malisetty (2022-03-07 10:55:06) > Add suspend_noirq and resume_noirq callbacks to handle Nitpick: They're no longer noirq so this should say "Add suspend and resume callbacks" > system suspend and resume in dwc PCIe controller driver. > > When system suspends, send PME turnoff message to enter > link into L2 state. Along with powerdown the PHY, disable > pipe clock, switch gcc_pcie_1_pipe_clk_src to XO if mux is > supported and disable the pcie clocks, regulators. I think Bjorn A. and Dmitry are trying to avoid this whole parking thing in another series? Can you take a look at that? > > When system resumes, PCIe link will be re-established and > setup rc settings. > > Signed-off-by: Prasad Malisetty > > --- > Changes since v3: > - Replaced noirq hooks with normal suspend/resume hooks. > - Removed local variable and placed in function itself. > > Changes since v2: > - Removed unnecessary variable initializations and comments. > - Removed platform specific variables declarations. > - Added MACRO names for the BIT shiftings. > > Changes since v1: > - Removed unnecessary logs and modified log level suggested by Manivannan. > - Removed platform specific callbacks as PM support is generic. > --- > drivers/pci/controller/dwc/pcie-qcom.c | 97 ++++++++++++++++++++++++++++++++++ > 1 file changed, 97 insertions(+) > > diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c > index 6ab9089..4d29c80 100644 > --- a/drivers/pci/controller/dwc/pcie-qcom.c > +++ b/drivers/pci/controller/dwc/pcie-qcom.c > @@ -48,6 +48,7 @@ > #define PCIE20_PARF_PHY_REFCLK 0x4C > #define PHY_REFCLK_SSP_EN BIT(16) > #define PHY_REFCLK_USE_PAD BIT(12) > +#define PHY_POWER_DOWN 0x1 > > #define PCIE20_PARF_DBI_BASE_ADDR 0x168 > #define PCIE20_PARF_SLV_ADDR_SPACE_SIZE 0x16C > @@ -62,6 +63,8 @@ > > #define PCIE20_ELBI_SYS_CTRL 0x04 > #define PCIE20_ELBI_SYS_CTRL_LT_ENABLE BIT(0) > +#define PCIE_PME_TURNOFF_MSG BIT(4) > +#define PCIE_PM_LINKST_IN_L2 BIT(5) > > #define PCIE20_AXI_MSTR_RESP_COMP_CTRL0 0x818 > #define CFG_REMOTE_RD_REQ_BRIDGE_SIZE_2K 0x4 > @@ -73,6 +76,8 @@ > > #define PCIE20_PARF_Q2A_FLUSH 0x1AC > > +#define PCIE20_PARF_PM_STTS 0x24 > + > #define PCIE20_MISC_CONTROL_1_REG 0x8BC > #define DBI_RO_WR_EN 1 > > @@ -1645,6 +1650,97 @@ static int qcom_pcie_probe(struct platform_device *pdev) > return ret; > } > > +static int qcom_pcie_send_pme_turnoff_msg(struct qcom_pcie *pcie) > +{ > + int ret; > + u32 val, poll_val; > + struct dw_pcie *pci = pcie->pci; > + struct device *dev = pci->dev; > + > + val = readl(pcie->elbi + PCIE20_ELBI_SYS_CTRL); > + val |= PCIE_PME_TURNOFF_MSG; > + writel(val, pcie->elbi + PCIE20_ELBI_SYS_CTRL); > + > + ret = readl_poll_timeout((pcie->parf + PCIE20_PARF_PM_STTS), poll_val, > + (poll_val & PCIE_PM_LINKST_IN_L2), > + 10000, 100000); > + if (!ret) > + dev_dbg(dev, "Device entered L23_Ready state\n"); > + else > + dev_err(dev, "Device failed to enter L23_Ready. PM_STTS 0x%x\n", > + readl_relaxed(pcie->parf + PCIE20_PARF_PM_STTS)); > + > + return ret; > +} > + > +static void qcom_pcie_host_disable(struct qcom_pcie *pcie) > +{ > + qcom_ep_reset_assert(pcie); > + > + /* Put PHY into POWER DOWN state */ > + phy_power_off(pcie->phy); > + > + writel(PHY_POWER_DOWN, pcie->parf + PCIE20_PARF_PHY_CTRL); > + > + if (pcie->cfg->ops->post_deinit) > + pcie->cfg->ops->post_deinit(pcie); > + > + /* Disable PCIe clocks and regulators */ > + pcie->cfg->ops->deinit(pcie); > +} > + > +static int __maybe_unused qcom_pcie_pm_suspend(struct device *dev) > +{ > + int ret; > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > + struct dw_pcie *pci = pcie->pci; > + > + if (!dw_pcie_link_up(pci)) { > + dev_dbg(dev, "Power has been turned off already\n"); > + return 0; > + } > + > + ret = qcom_pcie_send_pme_turnoff_msg(pcie); > + if (ret) > + return ret; > + > + /* Power down the PHY, disable clock and regulators */ > + qcom_pcie_host_disable(pcie); > + > + return 0; > +} > + > +/* Resume the PCIe link */ > +static int __maybe_unused qcom_pcie_pm_resume(struct device *dev) > +{ > + int ret; > + struct qcom_pcie *pcie = dev_get_drvdata(dev); > + struct dw_pcie *pci = pcie->pci; > + struct pcie_port *pp = &pci->pp; > + > + ret = qcom_pcie_host_init(pp); > + if (ret) { > + dev_err(dev, "cannot initialize host\n"); Capitalize cannot? > + return ret; > + } > + > + dw_pcie_setup_rc(pp); > + > + qcom_pcie_start_link(pci); > + > + ret = dw_pcie_wait_for_link(pci); > + if (ret) { > + dev_err(dev, "Link never came up, Resume failed\n"); > + return ret; Drop return and braces. > + } > + > + return 0; return ret; > +} > + > +static const struct dev_pm_ops qcom_pcie_pm_ops = { > + SET_SYSTEM_SLEEP_PM_OPS(qcom_pcie_pm_suspend, qcom_pcie_pm_resume) > +}; > +