Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3788486imm; Tue, 17 Jul 2018 10:15:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd/PjkGzCfHEahXUaMz4iiy3jR/2zoh9omGgHWYCVmChB2v9yPMFAlpo2KMAQ0n7B6jAzxA X-Received: by 2002:a63:e145:: with SMTP id h5-v6mr2375187pgk.286.1531847732298; Tue, 17 Jul 2018 10:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531847732; cv=none; d=google.com; s=arc-20160816; b=EeUASngF/GUOnJHqHDUnEhkLvKHUWFd7zfJG5aH4LlA3x93sq7hmAPAzBFN9uoj668 qyNmyGZPPH3FqqtiVfkewEKWYy2b4Dbt9xFUyWfkOSz6ZW+DVhPcWURZPFUQG1iDphV1 MTLh8VPCijbkQSbGoQeJhYElCu0hUH2ZGWUoau/FLsDpW72kgUwyCqFydPC48dMZJYne ZO7C2ZsbgwzjQoarQx9MANIjBA2K0z+yXEyMKN4HOOvOKVUwkIJLAkquM7ALJJr8obmh czbiIpyB28LeLAQC0Z9UjYqSxK9nHT4cvwjdKNjYIaT+GuayQKyP/9Uu+Y/MVTHzUX53 3s1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=txru1XCfQFE8X0KduP3ls+oEo7XHh3Ps+m887BnOIEs=; b=aiB7Ya8/G3SfG09MbGttvyH+gP7x7WEjAyyiz2R6J6TEd517CiR2nDJNbU5tMeIFAU dZ4u0hGf8kU0b/gzotofoTzQDDtX6EW1FhVgiWpFulJEhQ8r2/5eCCwAVra3zMHicttP lJNbebfMAHiXjW+QPAqaefb00XTjTon01a8h5HQ+AjZ7o138bPirSDPE/A3u0o2V/trE h6OtrlxaM4M5VWMeun7ZLpwagP2Wb9ijpEJT8AYpp2+1tMluHpJnCEMI3j3JYSwDttFb DPNbk8xen4s6rOc4lcSmquu8iRyL68efg+BImvW20IiRf44nODCqmHouN1i0vyaSOZ7h Cy5A== 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 31-v6si1316799plc.173.2018.07.17.10.15.17; Tue, 17 Jul 2018 10:15:32 -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 S1730172AbeGQRrY (ORCPT + 99 others); Tue, 17 Jul 2018 13:47:24 -0400 Received: from foss.arm.com ([217.140.101.70]:50344 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729717AbeGQRrY (ORCPT ); Tue, 17 Jul 2018 13:47:24 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D2B827A9; Tue, 17 Jul 2018 10:13:47 -0700 (PDT) Received: from red-moon (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 752003F5A0; Tue, 17 Jul 2018 10:13:44 -0700 (PDT) Date: Tue, 17 Jul 2018 18:15:43 +0100 From: Lorenzo Pieralisi To: honghui.zhang@mediatek.com Cc: marc.zyngier@arm.com, bhelgaas@google.com, matthias.bgg@gmail.com, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, yingjoe.chen@mediatek.com, eddie.huang@mediatek.com, ryder.lee@mediatek.com, hongkun.cao@mediatek.com, youlin.pei@mediatek.com, yong.wu@mediatek.com, yt.shen@mediatek.com, sean.wang@mediatek.com, rjw@rjwysocki.net, khilman@kernel.org, ulf.hansson@linaro.org Subject: Re: [PATCH v3 3/4] PCI: mediatek: Add system pm support for MT2712 and MT7622 Message-ID: <20180717171543.GA20991@red-moon> References: <1530518264-6125-1-git-send-email-honghui.zhang@mediatek.com> <1530518264-6125-4-git-send-email-honghui.zhang@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1530518264-6125-4-git-send-email-honghui.zhang@mediatek.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+Rafael, Kevin, Ulf] On Mon, Jul 02, 2018 at 03:57:43PM +0800, honghui.zhang@mediatek.com wrote: > 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 > Acked-by: Ryder Lee > --- > drivers/pci/controller/pcie-mediatek.c | 67 ++++++++++++++++++++++++++++++++++ > 1 file changed, 67 insertions(+) > > diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c > index 86918d4..175d7b6 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,75 @@ 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); > + } > + > + mtk_pcie_subsys_powerdown(pcie); > + > + 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; > + > + if (dev->pm_domain) { > + pm_runtime_enable(dev); > + pm_runtime_get_sync(dev); > + } Are these runtime PM calls needed/abused here ? Mind explaining the logic ? There is certainly an asymmetry with the suspend callback which made me suspicious, I am pretty certain Rafael/Kevin/Ulf can help me clarify so that we can make progress with this patch. Lorenzo > + > + 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)) > + mtk_pcie_subsys_powerdown(pcie); > + > + 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 +1275,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 +1295,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 >