Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2545605imm; Mon, 10 Sep 2018 02:53:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYZZObS5m+3XeZi3qZEVytSCZWIpk8ZH1CChosE+x4LCiUbjX/I+LMi25tK00VRm34mpr8d X-Received: by 2002:a17:902:6b83:: with SMTP id p3-v6mr21182485plk.133.1536573182113; Mon, 10 Sep 2018 02:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536573182; cv=none; d=google.com; s=arc-20160816; b=l0tAfVeKIKjUyncP2kTPDjiP01KzeAONl7/QglBlgq5kIK9iueAhtc8mvBvyy+fE87 /PA/Yzb1zmFxxVAo7y6Z2VPV2cHzmT56xtQn6CnW3cpp0U2UwrIgNC/c//X0lQWJDEBx g65miQr+qh4mXx3FkOFZ+tG3vWt5Jknszm2ycmENd0AjRoVcIUcPa+FegPFscr3DjmRp VokThZTOVfNN/tR/erKffbYvhURMc3Ds+P7NEAfhPcCZ6A1+tn+Zlv4TeEfgcM/ulVm+ MSVluZn91wDiC2kmgSVszTqPBg3kN+7g7yqMTzJHVlPimsdcnFvKKvTicytUU6yWWsIB 1CZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=jJdD9JC1fU8lp38UXmIWzPTmYWNn8i8jcOltAg5lymw=; b=XN6YeL9snWpz7a/WygtGooZcO28d+HPIPhZLSlT1qx84NRe+T2/FpLLS4zv3d+5uJB kYu1tPTdlmz2imCpkvpNjeBOqxqG4cma272Ki/nRqgZGfRF/aEyFPy294NwEbosAbeNK WQ0SMrKnP/JqAXUCLL/dZah1CZpsuIF6vKuJSrP9xRNLETDxFgpYjSWGIQz+BUtkXBqQ hsrwPdqWldawunDnftvTbMBfJ67PkWIqMRaRUOgWQ30d39r/i6gr1Ago1ydt5poQMJVJ wP8ImHrMrSMETe7qB40mloQ4pfyGdzZfv9uUISShrxeRi6t3BLmoHo5R+3qXyHevdPxE pyQA== 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 v7-v6si16888770pgn.431.2018.09.10.02.52.47; Mon, 10 Sep 2018 02:53:02 -0700 (PDT) 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 S1728140AbeIJOnu (ORCPT + 99 others); Mon, 10 Sep 2018 10:43:50 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:24439 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727411AbeIJOnu (ORCPT ); Mon, 10 Sep 2018 10:43:50 -0400 X-UUID: ccdcdcc550b341218c928a1ed67fc547-20180910 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 519913622; Mon, 10 Sep 2018 17:50:31 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 10 Sep 2018 17:50:29 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Mon, 10 Sep 2018 17:50:28 +0800 From: To: , , , , , , , , , , , CC: , , , , , , , Subject: [PATCH v4 3/4] PCI: mediatek: Add system pm support for MT2712 and MT7622 Date: Mon, 10 Sep 2018 17:50:22 +0800 Message-ID: <1536573023-6720-4-git-send-email-honghui.zhang@mediatek.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1536573023-6720-1-git-send-email-honghui.zhang@mediatek.com> References: <1536573023-6720-1-git-send-email-honghui.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Honghui Zhang The MTCMOS of PCIe Host for MT2712 and MT7622 will be off when system suspend, and all the internal control register will be reset after system resume. The PCIe link should be re-established and the related control register values should be re-set after system resume. Signed-off-by: Honghui Zhang --- drivers/pci/controller/pcie-mediatek.c | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index 5aba43a..bcc77bc 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -134,12 +134,14 @@ struct mtk_pcie_port; /** * struct mtk_pcie_soc - differentiate between host generations * @need_fix_class_id: whether this host's class ID needed to be fixed or not + * @pm_support: whether the host's MTCMOS will be off when suspend * @ops: pointer to configuration access functions * @startup: pointer to controller setting functions * @setup_irq: pointer to initialize IRQ functions */ struct mtk_pcie_soc { bool need_fix_class_id; + bool pm_support; struct pci_ops *ops; int (*startup)(struct mtk_pcie_port *port); int (*setup_irq)(struct mtk_pcie_port *port, struct device_node *node); @@ -1197,12 +1199,70 @@ static int mtk_pcie_probe(struct platform_device *pdev) return err; } +static int __maybe_unused mtk_pcie_suspend_noirq(struct device *dev) +{ + struct mtk_pcie *pcie = dev_get_drvdata(dev); + const struct mtk_pcie_soc *soc = pcie->soc; + struct mtk_pcie_port *port; + + if (!soc->pm_support) + return 0; + + if (list_empty(&pcie->ports)) + return 0; + + list_for_each_entry(port, &pcie->ports, list) { + clk_disable_unprepare(port->pipe_ck); + clk_disable_unprepare(port->obff_ck); + clk_disable_unprepare(port->axi_ck); + clk_disable_unprepare(port->aux_ck); + clk_disable_unprepare(port->ahb_ck); + clk_disable_unprepare(port->sys_ck); + phy_power_off(port->phy); + phy_exit(port->phy); + } + + clk_disable_unprepare(pcie->free_ck); + + return 0; +} + +static int __maybe_unused mtk_pcie_resume_noirq(struct device *dev) +{ + struct mtk_pcie *pcie = dev_get_drvdata(dev); + const struct mtk_pcie_soc *soc = pcie->soc; + struct mtk_pcie_port *port, *tmp; + + if (!soc->pm_support) + return 0; + + if (list_empty(&pcie->ports)) + return 0; + + clk_prepare_enable(pcie->free_ck); + + list_for_each_entry_safe(port, tmp, &pcie->ports, list) + mtk_pcie_enable_port(port); + + /* In case of EP was removed while system suspend. */ + if (list_empty(&pcie->ports)) + clk_disable_unprepare(pcie->free_ck); + + return 0; +} + +static const struct dev_pm_ops mtk_pcie_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mtk_pcie_suspend_noirq, + mtk_pcie_resume_noirq) +}; + static const struct mtk_pcie_soc mtk_pcie_soc_v1 = { .ops = &mtk_pcie_ops, .startup = mtk_pcie_startup_port, }; static const struct mtk_pcie_soc mtk_pcie_soc_mt2712 = { + .pm_support = true, .ops = &mtk_pcie_ops_v2, .startup = mtk_pcie_startup_port_v2, .setup_irq = mtk_pcie_setup_irq, @@ -1210,6 +1270,7 @@ static const struct mtk_pcie_soc mtk_pcie_soc_mt2712 = { static const struct mtk_pcie_soc mtk_pcie_soc_mt7622 = { .need_fix_class_id = true, + .pm_support = true, .ops = &mtk_pcie_ops_v2, .startup = mtk_pcie_startup_port_v2, .setup_irq = mtk_pcie_setup_irq, @@ -1229,6 +1290,7 @@ static struct platform_driver mtk_pcie_driver = { .name = "mtk-pcie", .of_match_table = mtk_pcie_ids, .suppress_bind_attrs = true, + .pm = &mtk_pcie_pm_ops, }, }; builtin_platform_driver(mtk_pcie_driver); -- 2.6.4