From patchwork Thu Oct 27 13:08:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 13022122 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 03DCFFA3740 for ; Thu, 27 Oct 2022 13:15:42 +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=bddJJs1zX4/JjKGkgDIYr1pG5UgVnPC7lbq0o9qXS28=; b=NNVa37dn5Tes30 +TPE7F7CA3drmnyZ5/201UZRBOW51O12h3pvgyh94Xc/suquHmHCloAZ4RF61h9TacQBO+9s7RTyG pBM0QOCR/dfi4yA8ZRI3fgzj2y5PCbUkhFvo+4ew9ygzIa/GjAR5ep0Eh+5brK6TciQEs8EX/mTBo 4UttCEEsODA3wNsH2g/xQyrk0stnNIME3ectQku/gTjyokOJS1JSAH8my2ITS9fg4G8Vrclj/amiM djQoPZYgTHqR6cSmqI9fiiKeUPjgJIH8neUJTmL9JZCmhY6dsq4Wtge9iazJ/f9y9NpO1fBUixK6c i0KWtGiGtqmSFRJmDE/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2hz-00DO4e-2B; Thu, 27 Oct 2022 13:14:07 +0000 Received: from mail-am7eur03on2054.outbound.protection.outlook.com ([40.107.105.54] helo=EUR03-AM7-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oo2eL-00DMda-UL for linux-arm-kernel@lists.infradead.org; Thu, 27 Oct 2022 13:10:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V+si1J4+E+DlttlP2F8QMtW85bLSZKeMIt4Jc1b/CCryI0fAQXdvAdHxEYQbcxv9TasFBvrJ6UPPdqL9q244VYhWGDRlYNXZuei1Pri1fY2kMwrgWxW7WXGpe2yUXYAO+gvACfGuud7hibBJB1Y80/etA4qyhYKSM+0U9JdIEIr8+fQpo70nGPSSC3UpFr16rcmhysWmHjGwzHfhm8FKfSq2XfKJi2qjU9FizgIjcxWbnYtFgXn6I7Vkf6bRp3p7JYKpYXWqlj4kQJMI58CeculKXPObxpvGPteuaqI0wmh0Su6fN0ftTRviVMnKnAVV/sj415CikDrcyC/XrRFy9A== 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=RQZfuvJnXI/eFijRUp7QGqWSIetSaEZLmeIl9T5qHUQ=; b=SXmYizy2/71YoR+w0R7xKG7ywFsndbHvzaml6Hx5jHXgcGw2lUObQWxR/+WAC3AsmEGw+WWJq4mIoXIQXVBre6byj7BcaxOsqdOmo1eVzg0elZuhdv4wbkR7XQcxw8rr2X4i1eSALJzSgGTaUqAAG2DanonSj4LnNh5HrI09BYC3jz8MffypZUWMvDU0m+8A0rNLVCIM5R7JxRF6aU1e/qVhalSit3YR90DcqothrsMJLxA0UvQ4pPEcgyZqsmxbjAAkAQoBumR/hm4VKlc94ImXdSArKaVXdzVdnt97SbIfkdhcFpDrf3yxgOtDvF8N10oQK7yq/VBl8ZvZiiYaRQ== 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=RQZfuvJnXI/eFijRUp7QGqWSIetSaEZLmeIl9T5qHUQ=; b=Zwsu+sAgzcMOJsfqSk/IgJ4xksg03Oi7Z7fFfQb0YAVgNlDMtPMLHYsaTMt1IuGRAHXIRxPcggJUUPBW2ngpo1z5Qm9ie6sOn1bzFrn8kBip6w5bINS4V6xJfS3SVrLIKdXz8NzEXYLeJKwO+HLd2bQNPuu3EStNrBDjiBHJ7Tk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) by AM7PR04MB6807.eurprd04.prod.outlook.com (2603:10a6:20b:104::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.21; Thu, 27 Oct 2022 13:10:18 +0000 Received: from PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::b1ab:dd4f:9237:d9f8]) by PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::b1ab:dd4f:9237:d9f8%3]) with mapi id 15.20.5769.014; Thu, 27 Oct 2022 13:10:18 +0000 From: Shenwei Wang To: Rob Herring , Krzysztof Kozlowski , Shawn Guo , Sascha Hauer , Linus Walleij , Bartosz Golaszewski , Dong Aisheng , Jacky Bai Cc: Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Shenwei Wang , Peng Fan , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH v4 5/5] gpio: mxc: enable pad wakeup on i.MX8x platforms Date: Thu, 27 Oct 2022 08:08:59 -0500 Message-Id: <20221027130859.1444412-6-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027130859.1444412-1-shenwei.wang@nxp.com> References: <20221027130859.1444412-1-shenwei.wang@nxp.com> X-ClientProxiedBy: SJ0PR05CA0044.namprd05.prod.outlook.com (2603:10b6:a03:33f::19) To PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9185:EE_|AM7PR04MB6807:EE_ X-MS-Office365-Filtering-Correlation-Id: bbe4d484-b5b5-4daf-9c43-08dab81c980e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZoKjo7GUdyH/MN7V9NB08SogM3y8M45pXZqqqInG5i3kzezRHKDYST4uci+oWCJFdcoini8tpnKqbqWFasyHxL5CrWwDgp8Rb3dSSQ8hE1Ww7p7Kx4HtPcdD8VvsEmdAikcFIqbpG/c+OzW/TJn0rwHMg2zs6Rtz34NJ7TW/d2LQ3aDNHRng/MD7ND+o092s/6M0gr2qrEoUuwz+C2nT0JUjp3QRHLcrG1Y3TjukWrWKMxX7B8zSXbtLxKs+wWJAC4fpDURv2hxxz1ZlY8LYEBOC20iVgwdIzb1znWz293ExmjW8xHNsuxvwPXiYg9u8xKlNsHmlDf9F8wLe1P2yLXcaLBFG6aVKLUzmy7My5dbXacL1hWXL3C1dDQyQdoyPTV0kCoXn6Xo7vzM7nhg+05C+iShJ0PyruLBAzzaAKHrQn6nPTswvorw1bKF/kIOHOPZmLC8RCqYtukPmsCcSXxvxi91G1dSEMD/fcAiPKtQgGOCdgH5JHXP+NpMYN6EreZhzh/PCi4cz44ZMKD3fLChTKQ+Re1TOOFlYjCwethRezlATQHp252xPffH2xF3n5ZTle9ZgggLfAK+xIwEXxjUBX3+dBJLPAUa8NWDozh1DTeWhC0O3n4GyuycEGUnXBy2N8aUpsckrZmdg/dXIaBlVeLT8MN8zcq4XdK0Gx/0rHY/Yb+SIz8e6QtKD04XwdRdPG/hMYoGgI3/7tMcWHYX6n2VR7Mr4j3NsC3h9kRS7z8ugw0aq14vOOGkPj6Hoam9Cw+jZDlIjROlwpNc1VA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9185.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(136003)(376002)(396003)(39860400002)(366004)(346002)(451199015)(55236004)(1076003)(6512007)(26005)(52116002)(6666004)(83380400001)(6506007)(478600001)(186003)(2616005)(44832011)(2906002)(6636002)(5660300002)(54906003)(8676002)(110136005)(6486002)(316002)(41300700001)(66556008)(7416002)(66946007)(66476007)(4326008)(8936002)(36756003)(86362001)(38350700002)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YgIj2yHyuQttUD4ER99SAf2r8yK37aMz2NAtDPwWH1XUrUfdH00azFHh/GTsWSFghLGywVecVp+hK+ho8vT6vqpSwhDErMYS3skT6VMSIwmtJR4VqMyOcqXLWhUrfg1FMzjvS2ZdzhW9NsGeaL85m7VeOmpiRsOPR32c8/DTeWbZAljlIMwZLgoDqi1HllTRvCZoDLfNI2eB0BZjBqykk4g4+oA2Arm9SxxzWQUjHB6BrEv5R5iBf69WRyo0gCTg97aAmAtC+4oP7vRU6kXd6buT8dszfSexnotHQjiS2Jycx3M0pHm+0WLfUTq4ouIIi+6np4ZqtAdz+WcgF8p2wUsLjkvhJC5r2VGTRZlV2YU87GkuPZHrj2lrIycI394tnuzccqNRXQpYQp07XbqXzTlpEegf2FRgAY6S9m0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Qq6SHfhqtk8uiMDp4JVVgSOD0tliBRFnSEdNKKoblPluMZjsWr82vz2+25rKFBbzYlEMsktfiln/8mb7g4YTsp1ueQh9RZGrmMkhL5QqilI8avy0hfkIXAmPpPeppzociHebCw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbe4d484-b5b5-4daf-9c43-08dab81c980e X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9185.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2022 13:10:17.9333 (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: 0SRmzfqxWFSgKVcXQb0836FvTV6k9/ii7Cr3FsI9Ex0HgQ8m22+VL5lauidzW9/BQJVmLwRTqOb6TLGMFMYtJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR04MB6807 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221027_061022_028961_2C62AF5E X-CRM114-Status: GOOD ( 24.73 ) 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 On i.MX8QM/QXP/DXL SoCs, even a GPIO is selected as the wakeup source, the GPIO block will be powered off when system enters into suspend state. This can greatly reduce the power consumption of suspend state because the whole partition can be shutdown. This is called PAD wakeup feature on i.MX8x platform. This patch adds the noirq suspend/resume hooks and uses the pad wakeup feature as the default wakeup method for GPIO modules on i.MX8QM/QXP/DXL platforms. Signed-off-by: Shenwei Wang Reviewed-by: Peng Fan Acked-by: Bartosz Golaszewski --- drivers/gpio/gpio-mxc.c | 92 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c index c871602fc5ba..d5626c572d24 100644 --- a/drivers/gpio/gpio-mxc.c +++ b/drivers/gpio/gpio-mxc.c @@ -24,6 +24,12 @@ #include #include +#define IMX_SCU_WAKEUP_OFF 0 +#define IMX_SCU_WAKEUP_LOW_LVL 4 +#define IMX_SCU_WAKEUP_FALL_EDGE 5 +#define IMX_SCU_WAKEUP_RISE_EDGE 6 +#define IMX_SCU_WAKEUP_HIGH_LVL 7 + /* device type dependent stuff */ struct mxc_gpio_hwdata { unsigned dr_reg; @@ -61,6 +67,9 @@ struct mxc_gpio_port { u32 both_edges; struct mxc_gpio_reg_saved gpio_saved_reg; bool power_off; + u32 wakeup_pads; + bool is_pad_wakeup; + u32 pad_type[32]; const struct mxc_gpio_hwdata *hwdata; }; @@ -130,6 +139,9 @@ static const struct of_device_id mxc_gpio_dt_ids[] = { { .compatible = "fsl,imx31-gpio", .data = &imx31_gpio_hwdata }, { .compatible = "fsl,imx35-gpio", .data = &imx35_gpio_hwdata }, { .compatible = "fsl,imx7d-gpio", .data = &imx35_gpio_hwdata }, + { .compatible = "fsl,imx8dxl-gpio", .data = &imx35_gpio_hwdata }, + { .compatible = "fsl,imx8qm-gpio", .data = &imx35_gpio_hwdata }, + { .compatible = "fsl,imx8qxp-gpio", .data = &imx35_gpio_hwdata }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, mxc_gpio_dt_ids); @@ -203,6 +215,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type) } writel(1 << gpio_idx, port->base + GPIO_ISR); + port->pad_type[gpio_idx] = type; return 0; } @@ -254,6 +267,9 @@ static void mx3_gpio_irq_handler(struct irq_desc *desc) struct mxc_gpio_port *port = irq_desc_get_handler_data(desc); struct irq_chip *chip = irq_desc_get_chip(desc); + if (port->is_pad_wakeup) + return; + chained_irq_enter(chip, desc); irq_stat = readl(port->base + GPIO_ISR) & readl(port->base + GPIO_IMR); @@ -306,11 +322,13 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable) ret = enable_irq_wake(port->irq_high); else ret = enable_irq_wake(port->irq); + port->wakeup_pads |= (1 << gpio_idx); } else { if (port->irq_high && (gpio_idx >= 16)) ret = disable_irq_wake(port->irq_high); else ret = disable_irq_wake(port->irq); + port->wakeup_pads &= ~(1 << gpio_idx); } return ret; @@ -365,7 +383,6 @@ static int mxc_gpio_probe(struct platform_device *pdev) return -ENOMEM; port->dev = &pdev->dev; - port->hwdata = device_get_match_data(&pdev->dev); port->base = devm_platform_ioremap_resource(pdev, 0); @@ -498,6 +515,78 @@ static void mxc_gpio_restore_regs(struct mxc_gpio_port *port) writel(port->gpio_saved_reg.dr, port->base + GPIO_DR); } +static bool mxc_gpio_generic_config(struct mxc_gpio_port *port, + unsigned int offset, unsigned long conf) +{ + struct device_node *np = port->dev->of_node; + + if (of_device_is_compatible(np, "fsl,imx8dxl-gpio") || + of_device_is_compatible(np, "fsl,imx8qxp-gpio") || + of_device_is_compatible(np, "fsl,imx8qm-gpio")) + return (gpiochip_generic_config(&port->gc, offset, conf) == 0); + + return false; +} + +static bool mxc_gpio_set_pad_wakeup(struct mxc_gpio_port *port, bool enable) +{ + unsigned long config; + bool ret = false; + int i, type; + + static const u32 pad_type_map[] = { + IMX_SCU_WAKEUP_OFF, /* 0 */ + IMX_SCU_WAKEUP_RISE_EDGE, /* IRQ_TYPE_EDGE_RISING */ + IMX_SCU_WAKEUP_FALL_EDGE, /* IRQ_TYPE_EDGE_FALLING */ + IMX_SCU_WAKEUP_FALL_EDGE, /* IRQ_TYPE_EDGE_BOTH */ + IMX_SCU_WAKEUP_HIGH_LVL, /* IRQ_TYPE_LEVEL_HIGH */ + IMX_SCU_WAKEUP_OFF, /* 5 */ + IMX_SCU_WAKEUP_OFF, /* 6 */ + IMX_SCU_WAKEUP_OFF, /* 7 */ + IMX_SCU_WAKEUP_LOW_LVL, /* IRQ_TYPE_LEVEL_LOW */ + }; + + for (i = 0; i < 32; i++) { + if ((port->wakeup_pads & (1 << i))) { + type = port->pad_type[i]; + if (enable) + config = pad_type_map[type]; + else + config = IMX_SCU_WAKEUP_OFF; + ret |= mxc_gpio_generic_config(port, i, config); + } + } + + return ret; +} + +static int __maybe_unused mxc_gpio_noirq_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct mxc_gpio_port *port = platform_get_drvdata(pdev); + + if (port->wakeup_pads > 0) + port->is_pad_wakeup = mxc_gpio_set_pad_wakeup(port, true); + + return 0; +} + +static int __maybe_unused mxc_gpio_noirq_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct mxc_gpio_port *port = platform_get_drvdata(pdev); + + if (port->wakeup_pads > 0) + mxc_gpio_set_pad_wakeup(port, false); + port->is_pad_wakeup = false; + + return 0; +} + +static const struct dev_pm_ops mxc_gpio_dev_pm_ops = { + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mxc_gpio_noirq_suspend, mxc_gpio_noirq_resume) +}; + static int mxc_gpio_syscore_suspend(void) { struct mxc_gpio_port *port; @@ -537,6 +626,7 @@ static struct platform_driver mxc_gpio_driver = { .name = "gpio-mxc", .of_match_table = mxc_gpio_dt_ids, .suppress_bind_attrs = true, + .pm = &mxc_gpio_dev_pm_ops, }, .probe = mxc_gpio_probe, };