From patchwork Fri Dec 8 09:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sherry Sun X-Patchwork-Id: 13485103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33ED2C4167B for ; Fri, 8 Dec 2023 09:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VA/G02V3Ik+edU6fxoFy9dNn+IDhKQ4TwFF2BfXuRoY=; b=giTsFNy7NPAoOk tz2meulDlnEuCLCMaha0Co7kCDpb2QyLKbFmx7ElIerIGeq7R63IgLUupYFcd8nrR9SoPzpnXt0YO s+bnPLQUUVe7Cnq9k/tmWzcEOVYrj71H9g8+zMUnPzp/h7pAsRJl9qnmnfJQzJCYtfKThdbz6V0Af BhF2IJObO/LYTgTv7nAPhIgEhyzFUvAGsw2GZuFoKiRaxV9X5RVu/aciQwoqyGDbwCAwTBLbVlIQV 635ClWJ7r/sAG3Pe8Wetw+B2NCtLZUuOrbU2LnD2NZepDeqBUqcrjTCe9ZX9BNTWP+BhQMcbKRRsW zzHgX8sAGgnIioMH8guA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBXAR-00F86A-0i; Fri, 08 Dec 2023 09:29:07 +0000 Received: from mail-db5eur01on061b.outbound.protection.outlook.com ([2a01:111:f400:fe02::61b] helo=EUR01-DB5-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBXAO-00F85e-0A for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2023 09:29:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dfQ3XCknOvbmhB5emox5i242wv3oCRO1FlBibqlFxA2VFwq3CF+jzDsVULeImms8Pau13KR4+OFz+XEsd3lSlNq/hohYVTTWjTKtNktt2nwreyOtnYPopylfxMLlBdVrjc6CsrisgGNiV5d862cAVH/L1kEUwN9afHkJM0CvUEqrZ8Uw3R7QyPLZ1e1m22lVQeGQpvkTdqXiiey6nXkUFJnkyrfzVetun74r8t7oDdsTOWh5pbpb4l0RWpLxZi6BAbJ0FSVVn8uEnXPmkW5Kp7jZvbyOjT3bq7/eyXz6PaLf+hm/zdvJVOjbnGPll9dG8IlUlk6H7k4hGQFflHwU/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3PQVaZlvZBjuhXe6cmiM9DNsp0BqsyeiNKzoHxw8N3A=; b=SuEKBxjtIfvFkboJ/HNQfUpj0+ALlYSnQhljlV1p460lNa7DNfDNVlDyB+FnX5+skmE+d4sVgkcs9OwStCsJFv22zpq6fbndNhwdTFR8u4VOU2juOGeIu0QRErLU3Wd5It0zLsi/vFjN82DjfRi6XBE/ofRs7/rb/80pY87/0NYmYNHi375mIIrHpqQ3mwwso6U2p+vJqV8SD2VViNqAun3fIqq0/1cCtRHVzI56b2hesAGSNxYMoshqclDjskGAmMuDbWG4jrn9OaIkqFI9rsyLiJnP11T1G/WUM6FCdDqOMIze7pKqTjNvFszE7n0DQgjvACdvjCs8aeIxFSb0fw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3PQVaZlvZBjuhXe6cmiM9DNsp0BqsyeiNKzoHxw8N3A=; b=pQHpt5WNOn2fuK1Se9+9TlIMkA28p1t7lTn8PhekPUdYgxKR81xM+YvJrp549VnEdhxD97K8mlIMNCn7GiCCSerpbFLDIuRCC9yBBZNPI/9Z2KgKew5UaUwRYOCQZqu0yfoV110fQTSQ2tOUkEK94b0J7DYneO/OvWG+uAtQuYU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) by AM8PR04MB7284.eurprd04.prod.outlook.com (2603:10a6:20b:1dc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.28; Fri, 8 Dec 2023 09:14:20 +0000 Received: from AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3627:208e:4d62:1e2a]) by AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3627:208e:4d62:1e2a%6]) with mapi id 15.20.7068.028; Fri, 8 Dec 2023 09:14:20 +0000 From: Sherry Sun To: hongxing.zhu@nxp.com, l.stach@pengutronix.de, lpieralisi@kernel.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com Cc: linux-imx@nxp.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] PCI: imx6: Add pci host wakeup support on imx platforms. Date: Fri, 8 Dec 2023 17:13:52 +0800 Message-Id: <20231208091355.1417292-2-sherry.sun@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208091355.1417292-1-sherry.sun@nxp.com> References: <20231208091355.1417292-1-sherry.sun@nxp.com> X-ClientProxiedBy: SI2PR06CA0006.apcprd06.prod.outlook.com (2603:1096:4:186::19) To AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8404:EE_|AM8PR04MB7284:EE_ X-MS-Office365-Filtering-Correlation-Id: 32004baa-9b53-45a5-6a94-08dbf7ce0f95 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +oa+0PiOWNUTHnyHZN3c/Kz/FovlTtwUSIH2RgqASC8Wy0hgbQwJbVhIF0P/qfM2WnyFY3NlfniQ95jYZEkq/qJ6P8XVysO7eNrRnxGH0xXhPs2mdvCj8bA4qW0lZBZMrDnrrAhROAfs2yIRKWiGzZhiI0ZjJjC4ii7vyayVdt8q/wB3HeE3M10RrB/8dvBMHoAFpSpFBz7EL7s2o7F2DI1rr3Itad2fQ7CHv0ldDUhidmZqfDgYMD1foBD/lzDKnW5Qb1DhDr2xPJdx0bPR+GBkPc2uMlfZL5PKGhy8bMtY7Cl5AKPCZWWmPfLjjlv3xVPHRPY1yOvnV+k+fZtm7YL8AjQ3ktAyhCnaFvWGExxw3xt/IXMIJkQkDtm8b6TdlYD/scoXAF/s3cTdatuZ73Q3p4J2ZwBUdEa6wkSPjAccqhWJECQN3FqGyxNNPJJGJi6kGwFS/P36LGasWWHkhwCUL83seMSKSpLGSw7IzaJ5Y2jm91pHR1eB4AUU86KO6qsjaMkAkZjQA160IngoqcRtKO/BblVfr4GB+c8vSIyU5g/y+j58TYLXt64yL1XH6W/V9V0jK7kcfvIjTucBKmrTBhpCikl1mt95Cwl7lAYfKO0V1MVHtlbbLRbaHo2Jl++/8lR3mrL9zHXpoFspJw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8404.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(376002)(396003)(136003)(366004)(230922051799003)(1800799012)(451199024)(64100799003)(186009)(8936002)(1076003)(26005)(83380400001)(2616005)(52116002)(6506007)(6512007)(5660300002)(6666004)(4326008)(44832011)(41300700001)(2906002)(7416002)(6486002)(478600001)(316002)(66946007)(66476007)(66556008)(8676002)(86362001)(36756003)(38100700002)(38350700005)(921008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D7Jhw+M5bVqDb/Wmj8Ogayp65eJZie9P5uXqXGZI5OPPOH2AQ/DsLJUsLqF0fz6c4z0IxBX87ELlR2WiZkp1YITYp+9QDIUuFq2s88/YXnowBjVqAejglDhlTpgClhGL+4LdYQ0GPAtyF0D2Id+1D93K4TL1RhYEStgRWgneMSyXZKzMviClPbasPlkgTcbIbyKePil/p1PKxn5k6QkQlGfRcNxYbUCFLw/kjrvLOehdmhtoVf1tO1lZnh6qVtvBs70tcxEwLxpCB4XCMLHmw+BjYLeHW50eOyxsxN/6WlAHc9vXPsWxZ4HPIFQ5lL9Ieux3Zl2XCcdWdZ/eY5L/Trn2/TUGqJcex5NKWom+qZGuEQ0RGaA0GnDFjqOaGMXyjcklqagfiv6MHwLMGRc0vkKS+LzLtI2BsdLLcS82DcOC34GFoBB2+PPHyxwqIjIWW5womzHvvlNtqF7Err2ON4jvZ1ULSban6S121HL2wLKSBzlQZ/y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yXdCyAKYxHPUq4a1TDg X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32004baa-9b53-45a5-6a94-08dbf7ce0f95 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8404.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2023 09:14:20.1766 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +JZnlcWFAURhcvmOoM7KpZXAF/XzI9+3uEZMKpITwJWlXN9QWpgtaso6E/sE79bnLSbST02MEVQkiCgYzQgNGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7284 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231208_012904_093591_FD3FBEB0 X-CRM114-Status: GOOD ( 14.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add pci host wakeup feature for imx platforms. Example of configuring the corresponding dts property under the PCI node: host-wake-gpio = <&gpio5 21 GPIO_ACTIVE_LOW>; Signed-off-by: Sherry Sun Reviewed-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 74703362aeec..050c9140f4a3 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -72,6 +72,7 @@ struct imx6_pcie_drvdata { struct imx6_pcie { struct dw_pcie *pci; int reset_gpio; + int host_wake_irq; bool gpio_active_high; bool link_is_up; struct clk *pcie_bus; @@ -1237,11 +1238,46 @@ static int imx6_pcie_resume_noirq(struct device *dev) return 0; } +static int imx6_pcie_suspend(struct device *dev) +{ + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + + if (imx6_pcie->host_wake_irq >= 0) + enable_irq_wake(imx6_pcie->host_wake_irq); + + return 0; +} + +static int imx6_pcie_resume(struct device *dev) +{ + struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); + + if (imx6_pcie->host_wake_irq >= 0) + disable_irq_wake(imx6_pcie->host_wake_irq); + + return 0; +} + static const struct dev_pm_ops imx6_pcie_pm_ops = { NOIRQ_SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend_noirq, imx6_pcie_resume_noirq) + SYSTEM_SLEEP_PM_OPS(imx6_pcie_suspend, imx6_pcie_resume) }; +irqreturn_t host_wake_irq_handler(int irq, void *priv) +{ + struct imx6_pcie *imx6_pcie = priv; + struct device *dev = imx6_pcie->pci->dev; + + dev_dbg(dev, "%s: host wakeup by pcie", __func__); + + /* Notify PM core we are wakeup source */ + pm_wakeup_event(dev, 0); + pm_system_wakeup(); + + return IRQ_HANDLED; +} + static int imx6_pcie_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -1250,6 +1286,7 @@ static int imx6_pcie_probe(struct platform_device *pdev) struct device_node *np; struct resource *dbi_base; struct device_node *node = dev->of_node; + struct gpio_desc *host_wake_gpio; int ret; u16 val; @@ -1457,6 +1494,32 @@ static int imx6_pcie_probe(struct platform_device *pdev) val |= PCI_MSI_FLAGS_ENABLE; dw_pcie_writew_dbi(pci, offset + PCI_MSI_FLAGS, val); } + + /* host wakeup support */ + imx6_pcie->host_wake_irq = -1; + host_wake_gpio = devm_gpiod_get_optional(dev, "host-wake", GPIOD_IN); + if (IS_ERR(host_wake_gpio)) + return PTR_ERR(host_wake_gpio); + + if (host_wake_gpio != NULL) { + imx6_pcie->host_wake_irq = gpiod_to_irq(host_wake_gpio); + ret = devm_request_threaded_irq(dev, imx6_pcie->host_wake_irq, NULL, + host_wake_irq_handler, + IRQF_ONESHOT | IRQF_TRIGGER_FALLING, + "host_wake", imx6_pcie); + if (ret) { + dev_err(dev, "Failed to request host_wake_irq %d (%d)\n", + imx6_pcie->host_wake_irq, ret); + imx6_pcie->host_wake_irq = -1; + return ret; + } + + if (device_init_wakeup(dev, true)) { + dev_err(dev, "fail to init host_wake_irq\n"); + imx6_pcie->host_wake_irq = -1; + return ret; + } + } } return 0; @@ -1466,6 +1529,12 @@ static void imx6_pcie_shutdown(struct platform_device *pdev) { struct imx6_pcie *imx6_pcie = platform_get_drvdata(pdev); + if (imx6_pcie->host_wake_irq >= 0) { + device_init_wakeup(&pdev->dev, false); + disable_irq(imx6_pcie->host_wake_irq); + imx6_pcie->host_wake_irq = -1; + } + /* bring down link, so bootloader gets clean state in case of reboot */ imx6_pcie_assert_core_reset(imx6_pcie); }