Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5195584rdb; Wed, 13 Dec 2023 01:28:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdkkzAHKmqFwxPOFYrW+0EjltvaWxUMpau4iAZf4Vv0P+Wo9Lj/FMmZdP2fU1W9PzX7c6X X-Received: by 2002:a17:90a:6e42:b0:286:6cc1:2cb1 with SMTP id s2-20020a17090a6e4200b002866cc12cb1mr3568688pjm.59.1702459733328; Wed, 13 Dec 2023 01:28:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702459733; cv=pass; d=google.com; s=arc-20160816; b=CwseTrR5Dz+EKXJSpJadjhq9sgEO2knYdTFP7MVPzQkGkT2+yHCZjO62W2ybCT7Z6n ibb2xzJiqLj6hOIxQfqMyi8dxm3dFJDgT2JDySuHm3aKKxhffE38OxHZkBpKCJVYykCg vmnPOTqHn58ytQxqfEyKxATPJuI1+6whGZzWk3/UKbJlkVhWfR2QcdP54XboqaqcWVck OassZ8/2ToSW8TQNePyPXxMo9wYc9e9YG7aqGgqKrJtLjGAPc/zgr7kkFRkAbE8Ugaf4 YfgAagnLmWmn33tslABBDZHj3PuEhLl33Llm5omLN1IdAv/NzmgTLNPsH22vNliHZDN1 IizA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Bfo3Il/zbDFJeMBYIHXKhuAvgRW/0s7JtCZyKPAnJrk=; fh=l1iWo58bMGw3cZiqltecNTFFfZhXvAIg92WGskXbVMI=; b=ujR9e41awn43hi7TBVZ9JWPEM/URAc7o0Sv6PsxCoeXyHh9THhCnpBNrp2vllSR4jI NzlY8A6ZK2G0NybpYYmNg7b9x8b7GZ+QSSK4hMHLwHwWXb8Vg5OvpRgKD3lpo+gK2g+S zhPgRz8XGlbK+Mfhvo6cM5RyXpQHIYGHU25skuKvKUEOpjNUOtSKz369iHqFwek9qEku 3Rk9YmqkZAjvmxVFP81cYt7sUwbClQJ1YjkyjYSmemqnRFWQyMPe6bqO91WEDat+Djnj P7uy/IR6hzz3xgzOv4ftGKT9g9H/F1LAme+2tOY+06qPR6w9liNf15OvYdjc92AMNfKq /Pnw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=fpJZTNjj; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u14-20020a17090a400e00b00286ac37da16si10464439pjc.181.2023.12.13.01.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 01:28:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=fpJZTNjj; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CF13F81EA5E8; Wed, 13 Dec 2023 01:28:50 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232777AbjLMJ2g (ORCPT + 99 others); Wed, 13 Dec 2023 04:28:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232707AbjLMJ2e (ORCPT ); Wed, 13 Dec 2023 04:28:34 -0500 Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2050.outbound.protection.outlook.com [40.107.247.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7954FDB; Wed, 13 Dec 2023 01:28:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b+b5dwIR/F9y3M00MIR/UGfcQqvJKYJCseJVr01p3cfOTBXbZVLuenGTZJr5RdfnP/S67WeI/YfpUIPyu2v8d2WAlQdIVQDXQdq7U1hT1TE4S8794nA4CTFWKUYVam20TIQTWKg3mWUpnvLn9+qJiQNP3JJjcA0aJD7vLl9BiZK+yLqUe1qBHJHzmR9Bmk5fwFr0S7SJJ8wdF0qIkpEsfN5Bo5rUhSX++71GJVqOoj8lzmLsl83zDemzygIUrRaVP1FZxZnFICbotn7RmP688763THuur83ZO0lQdAhSjFX1faG0OUqwAdSbVdoiDTdedp8pp4fOzXKYhe2fJJUE0g== 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=Bfo3Il/zbDFJeMBYIHXKhuAvgRW/0s7JtCZyKPAnJrk=; b=BjK9mCZ7viFfZWHMr0Ak4euVcRjQ9/klKdjDE+UXGjTdMwuAZiRgXKvmKZgp6fvXXnCXddZZNMMmPBJXD1SS9aMHRA5WYisPCl8J0R3kkx6Ql+vWSfF3or1xe07m1lErVzxTuhM9jdNzRmV0RmaMtY553gdvy4D07MchNbh5k3yHctSeH0CuOCHL/xMG4rULSEiOHfDngYpjs3IBUU2E/l7p/CiYouu+0j6yu7BU75CP4txgUNYQtVikQApa7imogK1wuU+2O3X4zgRT5wTGlG/v6GYxLUl/e5C5+b4W+enKJ/++3j7V0nb/n3SDoRjHU+Tf3M+f1fn/p6AM5vUVVQ== 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=Bfo3Il/zbDFJeMBYIHXKhuAvgRW/0s7JtCZyKPAnJrk=; b=fpJZTNjjE68tRW72Cy03iVyrMpRT0v5mithvlIMMlnal7dN5oL5aD8UFRfA+JNmZgOo0EusPE8KXO4TWoVwN3CnkQ1NrLd9W0IJsjbJS5sRPI8mE6Lh4SAnNL8pfU7vJwOjrOmxN9iOVLBEWt9Apo28ya4rh+HLoSsE8d/yZQ0I= 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 PA4PR04MB7933.eurprd04.prod.outlook.com (2603:10a6:102:b9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Wed, 13 Dec 2023 09:28:38 +0000 Received: from AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3627:208e:4d62:1e2a]) by AS8PR04MB8404.eurprd04.prod.outlook.com ([fe80::3627:208e:4d62:1e2a%7]) with mapi id 15.20.7091.022; Wed, 13 Dec 2023 09:28:38 +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 V2 1/4] PCI: imx6: Add pci host wakeup support on imx platforms. Date: Wed, 13 Dec 2023 17:28:47 +0800 Message-Id: <20231213092850.1706042-2-sherry.sun@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213092850.1706042-1-sherry.sun@nxp.com> References: <20231213092850.1706042-1-sherry.sun@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2P153CA0021.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::8) To AS8PR04MB8404.eurprd04.prod.outlook.com (2603:10a6:20b:3f8::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8404:EE_|PA4PR04MB7933:EE_ X-MS-Office365-Filtering-Correlation-Id: f766eb8d-8c2f-453e-45e4-08dbfbbde2e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j/gBudOqbMs0pGh9WRd27zREg5zCM4d6VXf4VKrx/CNMZu2VbR98bX3AVZ7q9o8nNEveobJwhXOW566k0zWsSr1LScuUokqZsgXFukCrj7T7sAECOzVkPKnJTha3RCCPOR6jpwhEspgdcQwRy0Qw68E6QtTflzx+pw34QX4/xcllgZ2e7h3PdPEC2VU+sQel0qRxkh2VIt01cTWMKsRpM13VwI/DDS0cBOIbiot2erzq7Y5CJjBmo9GRFtjTwvm9ciyvLbz4+H9ZRUCR6LqSDcl4xasIrSlseJOg+nmBXF4MvO4bZW8yyh+AjwhUVAk9DnVqXH1XYbnIhlt11LIfqaGT5jbal448yX6lxuDK02zFojlR3i1ilIDOYDCZxvhggsO0m+YBWOT6hmVniI4hSbvx22zK/yuTTJm/3V1yUPhf78/FmwBaFMspGIsPhCGypFzIzYzJqLFFyLed9384OPSH7JChIYf0QnllkP31mblEfWUGu9cyv5IQMFpBEkzLB3l8isW1E2BASnliPlki46VGyylqS2X4fPlWDEVswX6OtD2iUR9/OTSP234B9yTJXC1//ieozmhPOxZKWfEka/RtGFc3F5wfL9ZROto/J6tOlIaXcfhpr5B/cFKEfTWizOd1BwkX1s88rzRbUpgOdQ== 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)(396003)(39860400002)(366004)(346002)(136003)(376002)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(41300700001)(2906002)(316002)(7416002)(5660300002)(8676002)(44832011)(4326008)(83380400001)(66946007)(66476007)(66556008)(36756003)(921008)(86362001)(38350700005)(8936002)(6486002)(38100700002)(2616005)(6506007)(6512007)(478600001)(52116002)(6666004)(1076003)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?P46MDMxYEbef2CWUPhC+tNT+FAaecM60y0f8sYAPn7EQZStkF2yZBnz7j1qj?= =?us-ascii?Q?7TcVjHT04jW++9FkxustH8/QXfPxVp9Gr8Y+u+MLa/6br78qa4SljOnBSy2a?= =?us-ascii?Q?17wJJPUsgyeL21uXIDzMcDGqAgHbymBAaeaLRU5rQHzRdOSce5gg42i+30QS?= =?us-ascii?Q?VoJrSCD6wugQLdqewKWcEoEEw3XJOPYp8b49tOe02qMj1MWqrHZRzVOzPr4z?= =?us-ascii?Q?CApb1/eOPpGEMGdzDUVvS78ms9bcFTZwSZk/9X8Hb6frCyI5yxeU6b/gesHE?= =?us-asc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MwwG4QQxyK07Au5vmP0PDfh3hU+?= =?us-ascii?Q?y4tBTY1tLn9PmM3PVE63qoB3XNlko4m1ACCzd2kptN+UC5Mrrw7xmXdyzuGh?= =?us-ascii?Q?EbBz5EweLHf4JMdBsn/NcnYZXY7kam0arWC/Cux+1T2+pg4aZ87juwOYCE8t?= =?us-ascii?Q?8ctEyK+tOHuhBktmD0EtxzI84WfrbSbfC/D45nguo40SXLq8vxp02TIc0qyq?= =?us-ascii?Q?FMUUwRBzp+ey/z46kWjYYycKv9XKBQNX61m+1e5500aRbfYYZbYz/P38T3Ex?= =?us-ascii?Q?KZU7Uhtwa+sPCR2bHznQA4Qjbtn/llRFsUW9/h0Dakp6tZQDfqWfwrXALlt2?= =?us-ascii?Q?4nT2NvYsNWWhwYSI+l28+l60hn0XSEjTOLXu1pkL9seifFcSr/i2hpOS145u?= =?us-ascii?Q?wURLzQm7thhJB95ru+lWOka8wmDxkDBWsQRca0Ke?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f766eb8d-8c2f-453e-45e4-08dbfbbde2e8 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8404.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2023 09:28:37.9793 (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: JOw9fbRAimNMhEpokUdgQ2C3kkVvPvSvjkH6vNYPs3umdGTKyssmD+qdVubtu1OqFGqi03SFXE+EphnuFVlRXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7933 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 01:28:51 -0800 (PST) Add pci host wakeup feature for imx platforms. Example of configuring the corresponding dts property under the PCI node: wake-gpios = <&gpio5 21 GPIO_ACTIVE_LOW>; Signed-off-by: Sherry Sun Reviewed-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 74703362aeec..0cf7f21adff8 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,44 @@ 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; + + /* 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 +1284,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 +1492,26 @@ 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, "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) + return dev_err_probe(dev, ret, "Failed to request host_wake_irq\n"); + + ret = device_init_wakeup(dev, true); + if (ret) + return dev_err_probe(dev, ret, "Failed to init host_wake_irq\n"); + } } return 0; @@ -1466,6 +1521,11 @@ 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); + } + /* bring down link, so bootloader gets clean state in case of reboot */ imx6_pcie_assert_core_reset(imx6_pcie); } -- 2.34.1