Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp2065994lqp; Tue, 16 Apr 2024 06:34:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0s6DeXSEilVWjvPz+1tzJswwRizak6wMi4Yn0zuT4mHFWAFeo9PsVtm3nE2FhEuxnLRSsy0yP46fW68ZcSCxdRACJajBPVjQiQg3fqw== X-Google-Smtp-Source: AGHT+IFN0wkIpPCx2JlJL24giltoBjUtzm+grztVdMcrl4UpxHqlI6tjeudxws0IXJA/BOkyxO1E X-Received: by 2002:a17:907:868d:b0:a52:33ef:4d9e with SMTP id qa13-20020a170907868d00b00a5233ef4d9emr10264481ejc.77.1713274494757; Tue, 16 Apr 2024 06:34:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713274494; cv=pass; d=google.com; s=arc-20160816; b=XK5MIIHfnrMeMinO0IGoX/6jb55k6LN/Rg7Y72uc7HlwdNquYLlTaeorGOsI1BnGSF hdehyEK00B7mpnjgr+/mqsvudrGRRIz019HuX+kYUf6lRf+PIGXuLpl/ddsDT3XVIt24 AkAplG3nAAaBrC1XZXc/w1UUJpRFIqw4bKbw6b4YNZ+G74zbWMVhvB8STB4d4ip5N/k6 bRnfibswjqCpjH/BhVJJi+16U16kc4ntB7y1nbqI5b6H/TnWVK/eTnkKpaBn+idATsOV vWn0h81zNoUCnskVpvcOPXT8u3QQqvye49RkU3DOQre25K58R6wlV2J9MwNb/ZotDNNS lumA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=M72jZYyV65DqxQX89BNQFEE+r0wyDWzohfJY2wWVXuo=; fh=+6o6d2KGt2ZTSidIuE8uz1q8yt3pK0TjTqozrmclSIs=; b=PEKmhCNHxgMawiGY3DODcHLjbW8TJivhkuq8+L42/XQjU26RXIXlXs+wseEi5Fie9E FjKS1q47ihYrVvwg1RGMOBvkfJZ8WzhZD0p+gpmE6fVxTk4U6uIEYaVeck07c3S+AK1t SfpLsPBXh4uIOBnmOfv7O/QWhhwtyOqJlZ5XEZR8L1HstbMvoybl5XYlmFu0LbIgzHtt FCU8NhxpCRq8181BMkHtfOOBDVNIVS0DqY0cDsAFcELqsrqFZsdIS3Yxmxr/sU44NyhG 6VzZuULqfLMiK4jsAIZcTE9Fxp7zIqlXfVbtOvVF4grwWW51svVfMkwfR1AM/xvOE8qR RrTA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ly3tUPHV; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-146892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id s9-20020a1709062ec900b00a519c8c69a4si5797263eji.713.2024.04.16.06.34.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 06:34:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-146892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ly3tUPHV; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-146892-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-146892-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5013F1F217E2 for ; Tue, 16 Apr 2024 13:34:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B4D5C132C0E; Tue, 16 Apr 2024 13:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Ly3tUPHV" Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70E50132470; Tue, 16 Apr 2024 13:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713274237; cv=none; b=txzF4TN4mPVYWqtQSBfD2ilpSkTy6ho2QPrvnB+xGB7lG1WpSMGR7vHoeoIzsp9btV5QZKjTInNnOwBSRHKdz+FRX2XJutQza5iFUWP4R0RSkiP0Nc+mwZVG/yJaHgmDdN4/4JX0gtpYsf0csqEBSqd1Lejh5gBni3zOl2EuBOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713274237; c=relaxed/simple; bh=lpcRI6pbJ32meL/VjTzpGOcoWSJTYnk21moIdV1Kpxk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sX74VLvrXQgZHsa3UZzRrzx8za03yzPOqtUx/fQh2BJPLvpMWj60a4tlDTga5Be2kPzfW/MVu+2dPLJ0XOo0+n/viCrnWWN9Nu3qIlqrNrpoz/E27Ui6s4FZ+OPkS5JbufBMeuiGlzzSLsgZbjM7RcT3gZIoOC2LFGxEyIKDZDI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Ly3tUPHV; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 37A8840003; Tue, 16 Apr 2024 13:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713274229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M72jZYyV65DqxQX89BNQFEE+r0wyDWzohfJY2wWVXuo=; b=Ly3tUPHVPHxGu2QGf1SReurnXyVT6yZJ2fK77RoLnNLB4XnongqrymoRROo2eNs32VwIjH +kgILqGY2ooadU4CkFnaTAV1+r2G2DkEkFvsCCIm4oy/QhaXoum08Xx7YhTHSHNkFPv/Yb W/0ql6ngJTtsiaPSjw09Gec9DUYqcWAfwuGEooptvqlQBQw2OVZekcGbDLyIGJmFhj4op/ bmOecvZaw56s/5WJg5aNLren0s3uanD+/Vn8mZMLNmtlTlWzVZ43UwX6ZIHDOpIHcPcG+m 5AYr47/tmI4N25ASXbJG9ncJNe1tkj82DN/+JJWexW0f8Xv3sUqANYfpeLqCPw== From: Thomas Richard Date: Tue, 16 Apr 2024 15:30:00 +0200 Subject: [PATCH v5 11/11] PCI: j721e: Add suspend and resume support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240102-j7200-pcie-s2r-v5-11-4b8c46711ded@bootlin.com> References: <20240102-j7200-pcie-s2r-v5-0-4b8c46711ded@bootlin.com> In-Reply-To: <20240102-j7200-pcie-s2r-v5-0-4b8c46711ded@bootlin.com> To: Linus Walleij , Bartosz Golaszewski , Tony Lindgren , Aaro Koskinen , Janusz Krzysztofik , Vignesh R , Andi Shyti , Peter Rosin , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas , Siddharth Vadapalli Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, gregory.clement@bootlin.com, theo.lebrun@bootlin.com, thomas.petazzoni@bootlin.com, u-kumar1@ti.com, Thomas Richard X-Mailer: b4 0.12.0 X-GND-Sasl: thomas.richard@bootlin.com From: Théo Lebrun Add suspend and resume support. Only the rc mode is supported. During the suspend stage PERST# is asserted, then deasserted during the resume stage. Signed-off-by: Théo Lebrun Reviewed-by: Siddharth Vadapalli Signed-off-by: Thomas Richard --- drivers/pci/controller/cadence/pci-j721e.c | 98 ++++++++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c index 967a5bf38e26..96316a79ab8a 100644 --- a/drivers/pci/controller/cadence/pci-j721e.c +++ b/drivers/pci/controller/cadence/pci-j721e.c @@ -7,6 +7,8 @@ */ #include +#include +#include #include #include #include @@ -22,6 +24,8 @@ #include "../../pci.h" #include "pcie-cadence.h" +#define cdns_pcie_to_rc(p) container_of(p, struct cdns_pcie_rc, pcie) + #define ENABLE_REG_SYS_2 0x108 #define STATUS_REG_SYS_2 0x508 #define STATUS_CLR_REG_SYS_2 0x708 @@ -531,12 +535,12 @@ static int j721e_pcie_probe(struct platform_device *pdev) pcie->refclk = clk; /* - * "Power Sequencing and Reset Signal Timings" table in - * PCI EXPRESS CARD ELECTROMECHANICAL SPECIFICATION, REV. 3.0 - * indicates PERST# should be deasserted after minimum of 100us - * once REFCLK is stable. The REFCLK to the connector in RC - * mode is selected while enabling the PHY. So deassert PERST# - * after 100 us. + * "Power Sequencing and Reset Signal Timings" table (section + * 2.9.2) in PCI EXPRESS CARD ELECTROMECHANICAL SPECIFICATION, + * REV. 5.1 indicates PERST# should be deasserted after minimum + * of 100us once REFCLK is stable (symbol T_PERST-CLK). + * The REFCLK to the connector in RC mode is selected while + * enabling the PHY. So deassert PERST# after 100 us. */ if (gpiod) { fsleep(PCIE_T_PERST_CLK_US); @@ -588,6 +592,87 @@ static void j721e_pcie_remove(struct platform_device *pdev) pm_runtime_disable(dev); } +static int j721e_pcie_suspend_noirq(struct device *dev) +{ + struct j721e_pcie *pcie = dev_get_drvdata(dev); + + if (pcie->mode == PCI_MODE_RC) { + gpiod_set_value_cansleep(pcie->reset_gpio, 0); + clk_disable_unprepare(pcie->refclk); + } + + cdns_pcie_disable_phy(pcie->cdns_pcie); + + return 0; +} + +static int j721e_pcie_resume_noirq(struct device *dev) +{ + struct j721e_pcie *pcie = dev_get_drvdata(dev); + struct cdns_pcie *cdns_pcie = pcie->cdns_pcie; + int ret; + + ret = j721e_pcie_ctrl_init(pcie); + if (ret < 0) + return ret; + + j721e_pcie_config_link_irq(pcie); + + /* + * This is not called explicitly in the probe, it is called by + * cdns_pcie_init_phy(). + */ + ret = cdns_pcie_enable_phy(pcie->cdns_pcie); + if (ret < 0) + return ret; + + if (pcie->mode == PCI_MODE_RC) { + struct cdns_pcie_rc *rc = cdns_pcie_to_rc(cdns_pcie); + + ret = clk_prepare_enable(pcie->refclk); + if (ret < 0) + return ret; + + /* + * "Power Sequencing and Reset Signal Timings" table (section + * 2.9.2) in PCI EXPRESS CARD ELECTROMECHANICAL SPECIFICATION, + * REV. 5.1 indicates PERST# should be deasserted after minimum + * of 100us once REFCLK is stable (symbol T_PERST-CLK). + * The REFCLK to the connector in RC mode is selected while + * enabling the PHY. So deassert PERST# after 100 us. + */ + if (pcie->reset_gpio) { + fsleep(PCIE_T_PERST_CLK_US); + gpiod_set_value_cansleep(pcie->reset_gpio, 1); + } + + ret = cdns_pcie_host_link_setup(rc); + if (ret < 0) { + clk_disable_unprepare(pcie->refclk); + return ret; + } + + /* + * Reset internal status of BARs to force reinitialization in + * cdns_pcie_host_init(). + */ + for (enum cdns_pcie_rp_bar bar = RP_BAR0; bar <= RP_NO_BAR; bar++) + rc->avail_ib_bar[bar] = true; + + ret = cdns_pcie_host_init(rc); + if (ret) { + clk_disable_unprepare(pcie->refclk); + return ret; + } + } + + return 0; +} + +static DEFINE_NOIRQ_DEV_PM_OPS(j721e_pcie_pm_ops, + j721e_pcie_suspend_noirq, + j721e_pcie_resume_noirq); + static struct platform_driver j721e_pcie_driver = { .probe = j721e_pcie_probe, .remove_new = j721e_pcie_remove, @@ -595,6 +680,7 @@ static struct platform_driver j721e_pcie_driver = { .name = "j721e-pcie", .of_match_table = of_j721e_pcie_match, .suppress_bind_attrs = true, + .pm = pm_sleep_ptr(&j721e_pcie_pm_ops), }, }; builtin_platform_driver(j721e_pcie_driver); -- 2.39.2