Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1681407imu; Wed, 12 Dec 2018 02:24:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/UDKwrvtMXF5O2HfDJrrD7SWFr4FlxOa9W4J+ShHhoy/aXkiqcVTJ/GrELWc3s43aECsG48 X-Received: by 2002:a62:6408:: with SMTP id y8mr19569808pfb.202.1544610247879; Wed, 12 Dec 2018 02:24:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544610247; cv=none; d=google.com; s=arc-20160816; b=CJqYEvQAPT3ODfRbjxDtDMItt407FUgz78o2pH6si2cLTIfXWSyALjoruwVVy8MSeR EF1WPZNtB1U9cd5+EXhAmDIUVhv6yQjDZi1RuFtqmpNs9k8NzbsttQpGo006kkTta6ly bURr7PbIVJkmkYUrCb05AJ2heB5t5VnaZd5AHpWAKl85mSfJngF0mIURtvs6YHtf9b3h sO5BJ/1027A2tHb/RlsDz951CoQa4ViSylHMQRIYWJsvhjvN+0J4QnfuvNHKQ/lqNfSe JN0bvMa4HaUxjzA5L5YWD6DWifp9DJ2Bi00/xjYsRzVgI6K40tIzyAyeGtPCD1zKIcNs pPWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Guy9Vy8kHWcVPy0a6RxK7xB4+i1M14Zuu6tyS4F3Weg=; b=Urcx0gWoeeMpa1EAmLOAtMs5mchdgLE4TlVPV5+Kbkn5INsxzum6/i1RjPwRZme+MO U7XDyRuoIpqVPGw0jcw0uySdQBtjZ4izKc2CRSyFGRjXP4R6/6XupF0V1nA8Al9p3TbI jX6Wcj7CNMNgXYGERrsxfqpgJZwHn7kUFvb9CJ1HxhbuJllJ9Qx6L1JvIxztHBVNxE5f /jjFWEMGwiaDouJPaCOtqOwSo//QwxK68b5xczEP1eLVEbHrp/QvTUoB71sU25kjG2O7 g/v/s0tHC+vfZdngixNRA8+O5lU63Cbd+MCJZDMyatHxajdQrw/NXrO5CUOEkhJlKuHa Xu+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z136si15122388pgz.28.2018.12.12.02.23.52; Wed, 12 Dec 2018 02:24:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727188AbeLLKWI (ORCPT + 99 others); Wed, 12 Dec 2018 05:22:08 -0500 Received: from mail.bootlin.com ([62.4.15.54]:57491 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727019AbeLLKWH (ORCPT ); Wed, 12 Dec 2018 05:22:07 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id BF18F2082C; Wed, 12 Dec 2018 11:22:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from localhost.localdomain (aaubervilliers-681-1-89-7.w90-88.abo.wanadoo.fr [90.88.30.7]) by mail.bootlin.com (Postfix) with ESMTPSA id AC2E9208E3; Wed, 12 Dec 2018 11:21:45 +0100 (CET) From: Miquel Raynal To: Gregory Clement , Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , Thomas Petazzoni , Bjorn Helgaas Cc: , Rob Herring , Mark Rutland , Lorenzo Pieralisi , linux-pci@vger.kernel.org, , , Antoine Tenart , Maxime Chevallier , Nadav Haklai , Miquel Raynal Subject: [PATCH v2 05/12] PCI: aardvark: Add suspend to RAM support Date: Wed, 12 Dec 2018 11:21:35 +0100 Message-Id: <20181212102142.16053-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181212102142.16053-1-miquel.raynal@bootlin.com> References: <20181212102142.16053-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add suspend and resume callbacks. The priority of these are "_noirq()", to workaround early access to the registers done by the PCI core through the ->read()/->write() callbacks at resume time. Signed-off-by: Miquel Raynal --- drivers/pci/controller/pci-aardvark.c | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 108b3f15c410..7ecf1ac4036b 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -1108,6 +1108,55 @@ static int advk_pcie_setup_clk(struct advk_pcie *pcie) return ret; } +static int __maybe_unused advk_pcie_suspend(struct device *dev) +{ + struct advk_pcie *pcie = dev_get_drvdata(dev); + + advk_pcie_disable_phy(pcie); + + clk_disable_unprepare(pcie->clk); + + return 0; +} + +static int __maybe_unused advk_pcie_resume(struct device *dev) +{ + struct advk_pcie *pcie = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(pcie->clk); + if (ret) + return ret; + + /* + * Empirical delay needed after enabling the clock and before + * accessing any register. + */ + msleep(10); + + ret = advk_pcie_enable_phy(pcie); + if (ret) + return ret; + + advk_pcie_hard_reset(pcie); + + advk_pcie_setup_hw(pcie); + + advk_sw_pci_bridge_init(pcie); + + return 0; +} + +/* + * The PCI core will try to reconfigure the bus quite early in the resume path. + * We must use the _noirq() alternatives to ensure the controller is ready when + * the core uses the ->read()/->write() callbacks. + */ +static const struct dev_pm_ops advk_pcie_dev_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(advk_pcie_suspend, + advk_pcie_resume) +}; + static int advk_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1188,6 +1237,8 @@ static int advk_pcie_probe(struct platform_device *pdev) return ret; } + dev_set_drvdata(dev, pcie); + return 0; } @@ -1200,6 +1251,7 @@ static struct platform_driver advk_pcie_driver = { .driver = { .name = "advk-pcie", .of_match_table = advk_pcie_of_match_table, + .pm = &advk_pcie_dev_pm_ops, /* Driver unloading/unbinding currently not supported */ .suppress_bind_attrs = true, }, -- 2.19.1