From patchwork Mon Aug 27 11:28:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonard Crestez X-Patchwork-Id: 10577015 X-Patchwork-Delegate: bhelgaas@google.com 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 494B7174C for ; Mon, 27 Aug 2018 11:29:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37E1529591 for ; Mon, 27 Aug 2018 11:29:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B82D29657; Mon, 27 Aug 2018 11:29:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A72729591 for ; Mon, 27 Aug 2018 11:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbeH0PPS (ORCPT ); Mon, 27 Aug 2018 11:15:18 -0400 Received: from mail-eopbgr30069.outbound.protection.outlook.com ([40.107.3.69]:11424 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726931AbeH0PPS (ORCPT ); Mon, 27 Aug 2018 11:15:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FnNxjrhbGg0wNbsallEvFRK62BojjLoThzOBnqWDmhE=; b=lIrIAkCgrgu4dgsfRwyWSvZ/hGYAVt/CAljOrhsO1HM/igo9JwNYoR/2XsOwPJjkXWXvuNJZqDHjSph+ITgoOXdtTYcINj7e/TkCDN2LSHRwvLW3r1MvELW/nQ/bLZn93ae8TjQg1tboMpH9psyENIAKPHcussKYMJmctxIECf0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=leonard.crestez@nxp.com; Received: from localhost.localdomain (95.76.156.53) by AM6PR04MB4296.eurprd04.prod.outlook.com (2603:10a6:209:50::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.13; Mon, 27 Aug 2018 11:28:55 +0000 From: Leonard Crestez To: Lorenzo Pieralisi Cc: Lucas Stach , Andrey Smirnov , Richard Zhu , Anson Huang , Philipp Zabel , Bjorn Helgaas , Jingoo Han , Joao Pinto , Fabio Estevam , Dong Aisheng , linux-imx@nxp.com, kernel@pengutronix.de, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND] PCI: imx: Initial imx7d pm support Date: Mon, 27 Aug 2018 14:28:37 +0300 Message-Id: X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [95.76.156.53] X-ClientProxiedBy: VI1PR0302CA0006.eurprd03.prod.outlook.com (2603:10a6:800:e9::16) To AM6PR04MB4296.eurprd04.prod.outlook.com (2603:10a6:209:50::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 20eeb764-8eb0-441d-49a4-08d60c1046c1 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:AM6PR04MB4296; X-Microsoft-Exchange-Di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2bq125AsBKLh+DsnownDbcF00nqpLUX23F3Bo4ipGZQtjbXc1JPDeOhIDCkVfHwqezoeXmdk4ZsMYgirme+pxAeb3tJKJowpiRq4POosASu9ijD5BOwdE0hKI7FM5ifkxZZSpvKIT2x0+hYlK0U/bQ3laGW0dymZ8ar2DsOXU0dfPf9xvgyeqAmOtpq1OY/D26vBxbYY2366TZjHdilE5BEM1o8AODZRE3gP4BnaML/2jinrWQrhktzHKVJR4MFEblG39SIGF9avURnRc7UKAn3qmsKGRVay3X9cjlG0FjsAzyGDnPLsWhkBS1FIlT+/h7bnnT139PhntO1NublXh34I85BdvzCoTWrYr0R/lg2MieD2V79P;4:J0uP6RK3l2gvQw/iELV3hLJTlT6Tn+7H3WJXj90zk1nD2mVhJ9TSkjQ9NHLW6Q+ZxQm2pO98KjgRFTQm/dB7xYytEHjKwc0rZe9i3aBKh8ZZ/MaVUkkxrT/kfYm3FvRFX+k3TCsP6qSlBRbjWgpWjQYT5n8K2UFAEAUeKBteyO3zGo7doaBhg9t/OKa6L/aT9Pj0n7MtFgdc/+w89QybBhUqlo4bjT6rzxvB59iR9rwo0u9+7aH2U6JFzwY6ndg+JKJsey+KiFCmdrVrqWkMSeLJ9T3GSDxBKUsrEKqiZxVhb6lyB33VBMYc4rCWZ+Zt X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(823301075)(3231311)(944501410)(52105095)(10201501046)(93006095)(93001095)(3002001)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(201708071742011)(7699016);SRVR:AM6PR04MB4296;BCL:0;PCL:0;RULEID:;SRVR:AM6PR04MB4296; X-Forefront-PRVS: 07778E4001 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(346002)(136003)(39860400002)(366004)(376002)(396003)(199004)(189003)(476003)(86362001)(2616005)(956004)(5660300001)(68736007)(54906003)(2906002)(53936002)(14444005)(478600001)(25786009)(8936002)(39060400002)(47776003)(4326008)(7416002)(966005)(66066001)(44832011)(486006)(48376002)(3846002)(6116002)(8676002)(50466002)(50226002)(81156014)(81166006)(51416003)(6916009)(97736004)(52116002)(16526019)(186003)(1857600001)(7736002)(6506007)(105586002)(386003)(36756003)(305945005)(106356001)(16586007)(26005)(6486002)(6512007)(6306002)(316002)(118296001)(6666003)(69590400005);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR04MB4296;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: 1;AM6PR04MB4296;23:rq442ramJnbO84ton5r7t2LDRtPJzpHkxcw4PGLM5bQKg+coGsk5alGfds+NN9+nv4H3cYeMzDWI8mHOxYtr7T4KMmaT0lOxDfF6BwICIJ7jFvqAUsjlwjMRW2qGu7uQ3/dvtWUF2jYoZmawNtyirkwdR9ig12RaFoS9CrptZiIJv2G2hDGtCxXH/0DTi1gqVwuXW1m1nfvq2rg0p4YGcTAITvwpY5t83FDmBkEOEGGyajFi0E43/9sZwnksUOM2I78ap4eb2BNqB2/iabbZXIAPP4W+z9/MC/nAIki/W2xo9QM0BFXbgglwfmOds3sNQlGhgB0fF8WjV0qkNbuVd0Vb8k7eOjrxpB1ks0PVbWek51llG1EysXmAexAPBbPWpqh0OoxfmoXFgMf8KX9Ng1G+j507uu8BI/+ZpU4WI+zWjNqnuQyGt8/8z9vZxwhrIYnPaAbya//cxnLBKcF0Uzw45wMm/l8r6n5WgSktXxk6HzV4G8VwyjnY+EaMkjfCX7oYUqXTpklMY+Ih9HsX8DW455V/XjIXq3REjLyr3XRnuBzFzEYfpKvAvNucgHYqJbOYxvpvAxGOOUZdX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OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2018 11:28:55.5339 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 20eeb764-8eb0-441d-49a4-08d60c1046c1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4296 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On imx7d the pcie-phy power domain is turned off in suspend and this can make the system hang after resume when attempting any read from PCI. Fix this by adding minimal suspend/resume code from the nxp internal tree. This will prepare for powering down on suspend and reset the block on resume. Code is only for imx7d but a very similar sequence can be used for other socs. The original author is mostly Richard Zhu , this patch adjusts the code to the upstream imx7d implemention using reset controls and power domains. Signed-off-by: Leonard Crestez Reviewed-by: Lucas Stach --- drivers/pci/controller/dwc/pci-imx6.c | 97 +++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 5 deletions(-) Resending after RC1 as suggested here: https://lkml.org/lkml/2018/8/8/496 This was initially sent together with a dts fix, that was already accepted by Shawn: https://lkml.org/lkml/2018/8/21/529 Some dependencies in this area are complicated but as far as I know including this patch without others should not break anything that was not already broken. Since this is a patch for something that has never worked before it should be treated as a feature not a bugfix. I have a few other patches for imx pci but it's better to deal with them separately. This initial patch adding suspend support is useful by itself. diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 4a9a673b4777..65b6d1015723 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -540,10 +540,28 @@ static int imx6_pcie_wait_for_speed_change(struct imx6_pcie *imx6_pcie) dev_err(dev, "Speed change timeout\n"); return -EINVAL; } +static void imx6_pcie_ltssm_enable(struct device *dev) +{ + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + + switch (imx6_pcie->variant) { + case IMX6Q: + case IMX6SX: + case IMX6QP: + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, + IMX6Q_GPR12_PCIE_CTL_2, + IMX6Q_GPR12_PCIE_CTL_2); + break; + case IMX7D: + reset_control_deassert(imx6_pcie->apps_reset); + break; + } +} + static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) { struct dw_pcie *pci = imx6_pcie->pci; struct device *dev = pci->dev; u32 tmp; @@ -558,15 +576,11 @@ static int imx6_pcie_establish_link(struct imx6_pcie *imx6_pcie) tmp &= ~PCIE_RC_LCR_MAX_LINK_SPEEDS_MASK; tmp |= PCIE_RC_LCR_MAX_LINK_SPEEDS_GEN1; dw_pcie_writel_dbi(pci, PCIE_RC_LCR, tmp); /* Start LTSSM. */ - if (imx6_pcie->variant == IMX7D) - reset_control_deassert(imx6_pcie->apps_reset); - else - regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, - IMX6Q_GPR12_PCIE_CTL_2, 1 << 10); + imx6_pcie_ltssm_enable(dev); ret = imx6_pcie_wait_for_link(imx6_pcie); if (ret) goto err_reset_phy; @@ -680,10 +694,82 @@ static int imx6_add_pcie_port(struct imx6_pcie *imx6_pcie, static const struct dw_pcie_ops dw_pcie_ops = { .link_up = imx6_pcie_link_up, }; +#ifdef CONFIG_PM_SLEEP +static void imx6_pcie_ltssm_disable(struct device *dev) +{ + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + + switch (imx6_pcie->variant) { + case IMX6SX: + case IMX6QP: + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, + IMX6Q_GPR12_PCIE_CTL_2, 0); + break; + case IMX7D: + reset_control_assert(imx6_pcie->apps_reset); + break; + default: + dev_err(dev, "ltssm_disable not supported\n"); + } +} + +static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) +{ + clk_disable_unprepare(imx6_pcie->pcie); + clk_disable_unprepare(imx6_pcie->pcie_phy); + clk_disable_unprepare(imx6_pcie->pcie_bus); + + if (imx6_pcie->variant == IMX7D) { + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, + IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, + IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); + } +} + +static int imx6_pcie_suspend_noirq(struct device *dev) +{ + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + + if (imx6_pcie->variant != IMX7D) + return 0; + + imx6_pcie_clk_disable(imx6_pcie); + imx6_pcie_ltssm_disable(dev); + + return 0; +} + +static int imx6_pcie_resume_noirq(struct device *dev) +{ + int ret; + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + struct pcie_port *pp = &imx6_pcie->pci->pp; + + if (imx6_pcie->variant != IMX7D) + return 0; + + imx6_pcie_assert_core_reset(imx6_pcie); + imx6_pcie_init_phy(imx6_pcie); + imx6_pcie_deassert_core_reset(imx6_pcie); + dw_pcie_setup_rc(pp); + + ret = imx6_pcie_establish_link(imx6_pcie); + if (ret < 0) + dev_info(dev, "pcie link is down after resume.\n"); + + return 0; +} +#endif + +static const struct dev_pm_ops imx6_pcie_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend_noirq, + imx6_pcie_resume_noirq) +}; + static int imx6_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct dw_pcie *pci; struct imx6_pcie *imx6_pcie; @@ -846,10 +932,11 @@ static const struct of_device_id imx6_pcie_of_match[] = { static struct platform_driver imx6_pcie_driver = { .driver = { .name = "imx6q-pcie", .of_match_table = imx6_pcie_of_match, .suppress_bind_attrs = true, + .pm = &imx6_pcie_pm_ops, }, .probe = imx6_pcie_probe, .shutdown = imx6_pcie_shutdown, };