From patchwork Wed May 18 13:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 573930 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A137EC433F5 for ; Wed, 18 May 2022 13:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237666AbiERNTp (ORCPT ); Wed, 18 May 2022 09:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237658AbiERNTo (ORCPT ); Wed, 18 May 2022 09:19:44 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF36D1312AC for ; Wed, 18 May 2022 06:19:41 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o13-20020a17090a9f8d00b001df3fc52ea7so5576364pjp.3 for ; Wed, 18 May 2022 06:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o0m2cct6gQ1hTU8zWjrJlY1/CzYGMV6aIaj43pzMyHQ=; b=umKomzNTnxFS6bZsoFa6ppQZeJt+zfPQytLmumJLs/djqxC49M3mmhYlkyQQngnwyn f1UHtTKAviySFJOH931vQd8f+sqmaiLm8zbbFf1ZLLmttwg3ObFbmIqJ7HIMqJjFGz4f 3rOvpAe0Ronm9jj6M3flcWOBpwZEADpP0FEqTM+Y0t6KPDDOOBOdv+j+ws6PZ90SqxIm DhxCFoOvjQgLF0ogB25DjAAQFJqKKnMGUpP8YOfNT5CTYvpH1Rf0StUfMOv68SLfNdEa i+1skS1vRbokch1jy3ZPMODZR39KIkDj2C8+cwijleR7EaNKoNQehKCijXPLBkgmKI1h vENA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o0m2cct6gQ1hTU8zWjrJlY1/CzYGMV6aIaj43pzMyHQ=; b=IRxyl9FNV8HM0hFCmz1OkmnjgQ1m7cUSm7bFh14vpGcKdxQLalyE1VXrP2qtZ7VlJo WIh+93I+sQ0933a8N4huAUfQ6vLp999cfYbZR57GVzZUqRS0znSYkMZq2IqietTFG5WU RyiyhA/SPLNFy3hz5hzrlb2LHnWs0JZb8fISQf16txMrxKiFz2WZobfSfQsxq9Iz14l0 ut7AuLSSemrVDOeAMuGx1F38VfQAxZrxSdhnOlilV7TITvPg71ULnnzvLzvuh4ABLwJc 7X2nOjOTSeF6a//WZCMhCXp078+ktCuNTRQHvkh6rtx8RXwFXyPK6Ea9o/ge6qu5iYya BQNw== X-Gm-Message-State: AOAM531Squ8EMaI58yH3T1uy4pLYzx7AjfIQlBMFuZ8GElT6c8+ta9B2 g7A5WFuQt4qF7G4/1j6fs7KT X-Google-Smtp-Source: ABdhPJyHDXnFThSQ2XZkBGm0ehgt4AjaSs5P8n90+AxqDFvzx/b9+gdrukWw65K8iRuiJeeg7pXjng== X-Received: by 2002:a17:902:cec9:b0:161:a107:d30a with SMTP id d9-20020a170902cec900b00161a107d30amr9115101plg.105.1652879981149; Wed, 18 May 2022 06:19:41 -0700 (PDT) Received: from localhost.localdomain ([117.217.181.192]) by smtp.gmail.com with ESMTPSA id b5-20020a170903228500b0015e8d4eb27esm1663908plh.200.2022.05.18.06.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:19:40 -0700 (PDT) From: Manivannan Sadhasivam To: bhelgaas@google.com, lorenzo.pieralisi@arm.com, kbusch@kernel.org, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, svarbanov@mm-sol.com, bjorn.andersson@linaro.org, axboe@fb.com, quic_vbadigan@quicinc.com, quic_krichai@quicinc.com, quic_nitirawa@quicinc.com, vidyas@nvidia.com, sagi@grimberg.me, linux-pm@vger.kernel.org, rafael@kernel.org, Manivannan Sadhasivam Subject: [PATCH v2 1/3] PCI: Add a flag to notify PCI drivers about powerdown during suspend Date: Wed, 18 May 2022 18:49:11 +0530 Message-Id: <20220518131913.26974-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> References: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On some systems like Chromebooks based on Qcom SC7280, the PCIe RC driver or a hardware entity like RPMh may powerdown all PCIe devices during system suspend for aggressive powersaving. In that case, the PCI host controller drivers need to notify the PCI device drivers that the power will be taken off during system suspend so that the drivers can prepare the devices accordingly. One prime example is the PCI NVMe driver. This flag can be used by the driver to shutdown the NVMe device during suspend and recover it during resume. Signed-off-by: Manivannan Sadhasivam --- Changes in v2: * Changed the comment for the flag to mention the usecase. * Reworded the commit message to convey how the poweroff happens include/linux/pci.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/pci.h b/include/linux/pci.h index 60adf42460ab..3e3a1c4f4559 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -578,6 +578,8 @@ struct pci_host_bridge { unsigned int preserve_config:1; /* Preserve FW resource setup */ unsigned int size_windows:1; /* Enable root bus sizing */ unsigned int msi_domain:1; /* Bridge wants MSI domain */ + unsigned int suspend_poweroff:1; /* Some platforms like Qcom SC7280 may poweroff + devices during system suspend for power saving */ /* Resource alignment requirements */ resource_size_t (*align_resource)(struct pci_dev *dev, From patchwork Wed May 18 13:19:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 574348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 601A8C433EF for ; Wed, 18 May 2022 13:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237671AbiERNTz (ORCPT ); Wed, 18 May 2022 09:19:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237650AbiERNTy (ORCPT ); Wed, 18 May 2022 09:19:54 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8477713F911 for ; Wed, 18 May 2022 06:19:51 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id w17-20020a17090a529100b001db302efed6so2013313pjh.4 for ; Wed, 18 May 2022 06:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MnDyHs2MuOBTYTZqMG6fv0gi5HnIJHFVYwZNehBynVo=; b=Gb7hlyWGSwEGvXPHTyrg47FBM/6vom5xkAKFHXURmg6UVnev5DicIGpI22deIiwRYe 1vwNPVnl79uHsq2vfp+Zq+7YvnIMJz0lN1dbMOjQE56/Y0ZnghlxZ9FitoV0pbqCrSvK FFylVwCsKOTkWRJn0dVrNJml8UIkoXKFC3OCC/zdqorcZ5w76yWNSV7usc1Y6vunc6zF zL8e5wj0fQMpyd1qT9xC+ZwB/OkoFqs5qW0psjmBflEn4AuMyYyE2Apt+a4lFil+Z51W 8p96EYZz/SXrqGueOtntDzUzxnXdpHt2oaK5/U1REC+dvLmHgk9cbreImvwT1EFx+/qK AynQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MnDyHs2MuOBTYTZqMG6fv0gi5HnIJHFVYwZNehBynVo=; b=VboYO42jgu+sYiQMb/dZgCjuo8ZLRd32xjrasPw1CPuud+/ME/vVFbCBX+i5G9BsF7 tCREEedsWPIwf4LhmfT1nGgecm2Jf4G3Tw2BRQwous75fxtKJW1AzNfmmllMKoyKURO4 /WHqxfNbG8fo1yW7TnxkILy+HHvlyrKYtHjtSijymrtjgW9Dm1v7hlcmruSaen2itb1W U9fELL/Un9zDjMNOk8VYJoQZ1QBi3RSk20OjckyB1Vhu9fI0S7eDOr+YP14UVlIHhtr3 8eg+jtd4qX5SapDQbAhCJEmUtKeZQQ96rNFiYthlu7tGtGpOlwfthj/lETgmMv0adjUv bUlw== X-Gm-Message-State: AOAM531EkeOEHknBwdAIwJvlFEzV+kvFFMLrMiy6+/9VIvbPkeqtP9iA o8TJabemFybyBEb5uxk/JVjT X-Google-Smtp-Source: ABdhPJxTyC9sMCUpQo22UY5IOj1tKIEFt5bK4JNQ+ltl3bxoy1ym3mVWnjrTKA7ZEwahtkVXeCDyvw== X-Received: by 2002:a17:902:e882:b0:15e:b9e8:ba1b with SMTP id w2-20020a170902e88200b0015eb9e8ba1bmr26942176plg.71.1652879990995; Wed, 18 May 2022 06:19:50 -0700 (PDT) Received: from localhost.localdomain ([117.217.181.192]) by smtp.gmail.com with ESMTPSA id b5-20020a170903228500b0015e8d4eb27esm1663908plh.200.2022.05.18.06.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:19:50 -0700 (PDT) From: Manivannan Sadhasivam To: bhelgaas@google.com, lorenzo.pieralisi@arm.com, kbusch@kernel.org, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, svarbanov@mm-sol.com, bjorn.andersson@linaro.org, axboe@fb.com, quic_vbadigan@quicinc.com, quic_krichai@quicinc.com, quic_nitirawa@quicinc.com, vidyas@nvidia.com, sagi@grimberg.me, linux-pm@vger.kernel.org, rafael@kernel.org, Manivannan Sadhasivam Subject: [PATCH v2 2/3] nvme-pci: Make use of "suspend_poweroff" flag during system suspend Date: Wed, 18 May 2022 18:49:12 +0530 Message-Id: <20220518131913.26974-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> References: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On some platforms like Chromebooks based on Qcom SC7280, the power to the PCI devices will be taken off during system suspend. For these platforms, the PCI RC will set the "system_poweroff" flag to notify the PCI device drivers of the poweroff scenario. Hence, make use of the flag in the system suspend path and if set, properly shutdown the device. Acked-by: Christoph Hellwig Signed-off-by: Manivannan Sadhasivam --- Changes in v2: * Added Ack from Christoph * Reworded the commit message to include SC7280 drivers/nvme/host/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index d817ca17463e..381bf0c7cf8d 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -3238,6 +3238,7 @@ static int nvme_suspend(struct device *dev) { struct pci_dev *pdev = to_pci_dev(dev); struct nvme_dev *ndev = pci_get_drvdata(pdev); + struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus); struct nvme_ctrl *ctrl = &ndev->ctrl; int ret = -EBUSY; @@ -3257,7 +3258,7 @@ static int nvme_suspend(struct device *dev) * state (which may not be possible if the link is up). */ if (pm_suspend_via_firmware() || !ctrl->npss || - !pcie_aspm_enabled(pdev) || + !pcie_aspm_enabled(pdev) || bridge->suspend_poweroff || (ndev->ctrl.quirks & NVME_QUIRK_SIMPLE_SUSPEND)) return nvme_disable_prepare_reset(ndev, true); From patchwork Wed May 18 13:19:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 573929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F127C433FE for ; Wed, 18 May 2022 13:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237669AbiERNUB (ORCPT ); Wed, 18 May 2022 09:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237631AbiERNUA (ORCPT ); Wed, 18 May 2022 09:20:00 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E2D179959 for ; Wed, 18 May 2022 06:19:58 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id k16so2123928pff.5 for ; Wed, 18 May 2022 06:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=txATEk4JZM2jQy2RKz/BeGooaFu5CSNU01MtDQRxfaQ=; b=nIQmnqo4Rz4+1DLw5lorzvCXpRFs2B3NZa0m8W4N/JxNEqItRgCCf/nxhj64sR4iow gt5jEf6JgZMcDab7hEsHWwC21YW1x3iDNzVYn4nHHzuOPcSKkn724F6nRKkpzFgvc28z 3ttes+LANUdhqegEed37V7LvT9+d5wX5gC+zf4NUqykgFeIxMVbnh5Y2VRrpZsJ1O/ni jFpkbQ9/k9wbZ+XUYZWNob5F41LhL6QtFqJ5UYaM1y96nHrKig0NvC9RsCQDWooxywAi 5MbA0HYb1Rygrh/XHNPk/L1nD6chMinbu3FaJzb/3E76iiKuL5SlUQb1XA94njVrb9Bi qExw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=txATEk4JZM2jQy2RKz/BeGooaFu5CSNU01MtDQRxfaQ=; b=8PoEZ3iw0nUNES9HsSbbNUl5Egm+Hbc1FGDFDjfRK1QNvzH8nJ47f4wZROgEHUyA1e t5ffgrKw0J/UjJRrLcKH6lScX0TbxOc6/T23lwezcI2Vb5Y0/UXrLgBvTDjM8ZrTvijw pT0SBdbAo2Iiqf/tY+RLzUzMu3OWL0DPE/TV9j/oqnhYmKuEUVsLDq7HccMKAWTS7NJD lHPAbOatQcZxiM30Y4YTLJ0HuJl/k5fIH80IaBOWpLTeMKLUn2mBYj45rZ09junC4Roo ZBxovOgXgG3du8WyGiMzX2kxrPWX0v9oXxRN/AE0FREfLFkQgaegjm3YsD7ev2/rXCo5 ABQw== X-Gm-Message-State: AOAM531sWw6o+MPZwBj7SKhYIcuvTmQrtVQjpliF3KJdtg7euVcgeajP tGp+2Sih8EMOxkcuV20dhWbl X-Google-Smtp-Source: ABdhPJwza2H4RAuSmX+mr9/p1a18xwE96l79O/kDfY2T0ZDpQBEOEo+0ehBH5TXhTMNBUg/E65fAmQ== X-Received: by 2002:a63:1b49:0:b0:3f2:cf90:5ad4 with SMTP id b9-20020a631b49000000b003f2cf905ad4mr8023542pgm.450.1652879997896; Wed, 18 May 2022 06:19:57 -0700 (PDT) Received: from localhost.localdomain ([117.217.181.192]) by smtp.gmail.com with ESMTPSA id b5-20020a170903228500b0015e8d4eb27esm1663908plh.200.2022.05.18.06.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 06:19:57 -0700 (PDT) From: Manivannan Sadhasivam To: bhelgaas@google.com, lorenzo.pieralisi@arm.com, kbusch@kernel.org, hch@lst.de Cc: linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, svarbanov@mm-sol.com, bjorn.andersson@linaro.org, axboe@fb.com, quic_vbadigan@quicinc.com, quic_krichai@quicinc.com, quic_nitirawa@quicinc.com, vidyas@nvidia.com, sagi@grimberg.me, linux-pm@vger.kernel.org, rafael@kernel.org, Prasad Malisetty , Manivannan Sadhasivam Subject: [PATCH v2 3/3] PCI: qcom: Add system PM support Date: Wed, 18 May 2022 18:49:13 +0530 Message-Id: <20220518131913.26974-4-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> References: <20220518131913.26974-1-manivannan.sadhasivam@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org From: Prasad Malisetty Add suspend and resume callbacks to handle system suspend and resume in the Qcom PCIe controller driver. When the system suspends, PME turnoff message will be sent to the device and the RC driver will wait for the device to enter L23 Ready state. After that, the PHY will be powered down and clocks/regulators will be disabled. When the system resumes, RC driver gets initialized and re-establishes the link. The system suspend and resume are only handled when the underlying platform supports the "suspend_poweroff" flag that notifies the PCI drivers about powerdown during suspend. Otherwise, these callbacks are NO-OPs. Currently, this flag is only enabled for SC7280 SoC, where aggressive powersaving is required during system suspend. It should be noted that on this platform, RPMh will also cutoff the power to PCIe domain during suspend, independent of the RC driver as rest of the RPMh clients de-vote for the resources. But ideally, the PCIe devices should be put into D3cold state during suspend by the PCIe RC driver and that's what this commit also does. Signed-off-by: Prasad Malisetty [mani: Reworded commit message, removed pipe_clk & added "suspend_poweroff" flag] Signed-off-by: Manivannan Sadhasivam --- Changes in v2: * Picked the suspend/resume patch from Prasad and squashed the suspend_poweroff patch * Rebased on top of pipe_clk handling series from Dmitry https://lore.kernel.org/all/20220513175339.2981959-1-dmitry.baryshkov@linaro.org/ drivers/pci/controller/dwc/pcie-qcom.c | 108 +++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index b48c899bcc97..bfcc79058b3f 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 @@ -193,6 +198,7 @@ struct qcom_pcie_cfg { unsigned int has_ddrss_sf_tbu_clk:1; unsigned int has_aggre0_clk:1; unsigned int has_aggre1_clk:1; + unsigned int suspend_poweroff:1; }; struct qcom_pcie { @@ -1171,6 +1177,10 @@ static int qcom_pcie_init_2_7_0(struct qcom_pcie *pcie) return ret; } + /* Indicate PCI device drivers that the power will be taken off during system suspend */ + if (pcie->cfg->suspend_poweroff) + pci->pp.bridge->suspend_poweroff = true; + ret = clk_bulk_prepare_enable(res->num_clks, res->clks); if (ret < 0) goto err_disable_regulators; @@ -1467,6 +1477,7 @@ static const struct qcom_pcie_cfg sm8450_pcie1_cfg = { static const struct qcom_pcie_cfg sc7280_cfg = { .ops = &ops_1_9_0, .has_tbu_clk = true, + .suspend_poweroff = true, }; static const struct dw_pcie_ops dw_pcie_ops = { @@ -1564,6 +1575,102 @@ 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); + + /* Disable PCIe clocks and regulators */ + pcie->cfg->ops->deinit(pcie); +} + +static int qcom_pcie_pm_suspend(struct device *dev) +{ + int ret; + struct qcom_pcie *pcie = dev_get_drvdata(dev); + struct dw_pcie *pci = pcie->pci; + + /* If the platform doesn't support powerdown during suspend, just return */ + if (!pcie->cfg->suspend_poweroff) + return 0; + + 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 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; + + /* If the platform doesn't support powerdown during suspend, just return */ + if (!pcie->cfg->suspend_poweroff) + return 0; + + ret = qcom_pcie_host_init(pp); + if (ret) { + dev_err(dev, "cannot initialize host\n"); + 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; + } + + return 0; +} + +static const struct dev_pm_ops qcom_pcie_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(qcom_pcie_pm_suspend, qcom_pcie_pm_resume) +}; + static const struct of_device_id qcom_pcie_match[] = { { .compatible = "qcom,pcie-apq8084", .data = &apq8084_cfg }, { .compatible = "qcom,pcie-ipq8064", .data = &ipq8064_cfg }, @@ -1600,6 +1707,7 @@ static struct platform_driver qcom_pcie_driver = { .name = "qcom-pcie", .suppress_bind_attrs = true, .of_match_table = qcom_pcie_match, + .pm = pm_sleep_ptr(&qcom_pcie_pm_ops), }, }; builtin_platform_driver(qcom_pcie_driver);