Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp645326rdb; Fri, 26 Jan 2024 06:42:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IE95HIEG3pjYsD9YTn4vT1SLmnms7AVNgcfxLIqUlYHFl7/cy6aaisRjryfyYQxyOOTBAnP X-Received: by 2002:a05:622a:ca:b0:42a:607d:7349 with SMTP id p10-20020a05622a00ca00b0042a607d7349mr1670517qtw.6.1706280172201; Fri, 26 Jan 2024 06:42:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706280172; cv=pass; d=google.com; s=arc-20160816; b=K0RmmbTTX6tuYseL+47+OTjzgGouzAct1vBL+sEwJCoBYa4hBLvMym3aSQylBUhT4T uXFSNvtZSUTH4abZuQ4A5WUm6JLz7ZOTwbQ1j2/KQ4JOd+pQ1k5ZGfpWI+4dorXDrs5b ddrSGDjZ4sJV0ATMgmryr60jqBKT/9r2Z+4eLiuqSWZT5pqgZO0SX2Gtjb905dg9HJGE 12ExdAdcd6fW35X3Gb0ZBLHZJlZnLtowQZ3iSYWwkOEyZsnkLq2Win8huYy6sBlCB4P0 wxDMWy+Dj/7XrJcxZfLSmk62HLDfJNOBpHyrVOzAol6R7a35U5wF43cFF99580K2vd9r aDiA== 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=DV+PfVFG+B6uq9zkwyO5cQW010WYXqAyimrtCyB36hg=; fh=ihwxVJW8DyodhmdJo1IfhLUDNDWeXh+49SpWXYbpL2Y=; b=b1wSoTt9KN6UBv33KN3LiBX0CZHyhudshUn7Bk4gPJGmg0ONxSXqFV7kmdw5c9ajHs E70HCInYFgl/AOoa04dVpKp3TLVFgNQUT4CpMs0nXo9tK4kZvVbqteEr5hEeuSzPmBTx lxj4X82d8+GUt3r8g0BBVAoufLJPgPXIwKItr1NLmVRquPYTuddg1h2U0TMmW4AmDoiY BYxl8djzgPs2/NsBvx3ux5zG89fNVTTJYQEkoNBgTY33WbXkvLWS6n8H2gMPUswrXd2x T1kTCSmNhrKECScA247AKWrmN3SDa91Ax1wJfRAesJB4rsB1O8nBsNSE70aQg7Y6HDr2 x42g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=PIftpjT+; 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-40214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40214-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d20-20020a05622a101400b0042a275916a1si1328246qte.461.2024.01.26.06.42.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:42:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=PIftpjT+; 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-40214-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40214-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F1A611C21FEC for ; Fri, 26 Jan 2024 14:42:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 204342208B; Fri, 26 Jan 2024 14:38:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PIftpjT+" 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 A1DBE21369; Fri, 26 Jan 2024 14:38:15 +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=1706279898; cv=none; b=FW/eFu37UmbV7c+ixQjwWvtQgogmOc944Kk9xbuJ6Hw+E7fEbh1df0HcUNUot2oxstP0JixL62iGz4J3AlTr8RNgTUpA9RZDXKFOEauZj2nPANFAB2VtQbj/RLllaie6rEmG3rran+0/MTtH6jJMxvku+c5WguFmG6ylDlOLyF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706279898; c=relaxed/simple; bh=+4QRRan8kQ4zTpCiivOHj6X/CEPO4nHKmYIF+D/aqtU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hR3TpZsQTzaipX1YItB2FkDFUVeeDw2n7Qr3B9/003+5Bx1qqqWMlVYlF9aQVqJvR27Btdx4KnZh+ANwSMJhXmT+vJHll7Dhj4WBVPvQDJXPpwnXim8Y3ngXTzmGjJs1qJToZs98Dlum9jMgDyb3Z7p+fFBwy3KVyTuAPxYIhS4= 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=PIftpjT+; 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 5B40B40004; Fri, 26 Jan 2024 14:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1706279894; 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=DV+PfVFG+B6uq9zkwyO5cQW010WYXqAyimrtCyB36hg=; b=PIftpjT+y/RyuehPANnuJOuPqUqHRnH5Lr5aRuer/H/+YHouEsFoSxIGW5TWrtVINGTxRH ChZoIqNqYtEejdsgdQDaQBhOsPDmi8m7+UmpihImWXSHTxs6GPuPV32pJUEc28Ji89R6Pw AF2EBRI5o4O0X3EJsmmgWpKjbrgCOMX4AuoNn/OCclmaTI/TQG1oHoss+CWbXQDpW/e6V2 j1y/BQ8thUsJHI/aTN0KtaboXeccHA3gnDhzBsY7ymkiXVUvJ111h3MTOKGtLjpMZ/mgve pLY3jvhniQLLuvFL3rGXn7K3DVX1QS0fUJgc5pNGiRG1Hv0yRpbfa6mc6pYefw== From: Thomas Richard Date: Fri, 26 Jan 2024 15:36:57 +0100 Subject: [PATCH v2 15/15] 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-v2-15-8e4f7d228ec2@bootlin.com> References: <20240102-j7200-pcie-s2r-v2-0-8e4f7d228ec2@bootlin.com> In-Reply-To: <20240102-j7200-pcie-s2r-v2-0-8e4f7d228ec2@bootlin.com> To: Linus Walleij , Bartosz Golaszewski , Andy Shevchenko , Tony Lindgren , Haojian Zhuang , Vignesh R , Aaro Koskinen , Janusz Krzysztofik , Andi Shyti , Peter Rosin , Vinod Koul , Kishon Vijay Abraham I , Philipp Zabel , Tom Joseph , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Rob Herring , Bjorn Helgaas Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-i2c@vger.kernel.org, linux-phy@lists.infradead.org, linux-pci@vger.kernel.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 Signed-off-by: Thomas Richard --- drivers/pci/controller/cadence/pci-j721e.c | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c index 477275d72257..668d98422c4d 100644 --- a/drivers/pci/controller/cadence/pci-j721e.c +++ b/drivers/pci/controller/cadence/pci-j721e.c @@ -6,6 +6,7 @@ * Author: Kishon Vijay Abraham I */ +#include #include #include #include @@ -18,10 +19,13 @@ #include #include #include +#include #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 @@ -554,6 +558,80 @@ 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) { + dev_err(dev, "j721e_pcie_ctrl_init failed\n"); + 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) { + dev_err(dev, "cdns_pcie_enable_phy failed\n"); + return -ENODEV; + } + + 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) { + dev_err(dev, "clk_prepare_enable failed\n"); + return -ENODEV; + } + + /* + * "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. + */ + if (pcie->reset_gpio) { + usleep_range(100, 200); + gpiod_set_value_cansleep(pcie->reset_gpio, 1); + } + + ret = cdns_pcie_host_setup(rc, false); + if (ret < 0) { + 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, @@ -561,6 +639,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