From patchwork Tue Jun 2 16:20:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6529751 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BFF6D9F326 for ; Tue, 2 Jun 2015 16:23:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6778A2052D for ; Tue, 2 Jun 2015 16:23:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CFE8420444 for ; Tue, 2 Jun 2015 16:23:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzowT-0006jE-6e; Tue, 02 Jun 2015 16:21:29 +0000 Received: from mail-bl2on0146.outbound.protection.outlook.com ([65.55.169.146] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YzowN-0006Qo-Gf for linux-arm-kernel@lists.infradead.org; Tue, 02 Jun 2015 16:21:25 +0000 Received: from BLUPR0301CA0018.namprd03.prod.outlook.com (10.162.113.156) by BY2PR03MB609.namprd03.prod.outlook.com (10.255.93.40) with Microsoft SMTP Server (TLS) id 15.1.172.22; Tue, 2 Jun 2015 16:20:59 +0000 Received: from BY2FFO11FD054.protection.gbl (2a01:111:f400:7c0c::169) by BLUPR0301CA0018.outlook.office365.com (2a01:111:e400:5259::28) with Microsoft SMTP Server (TLS) id 15.1.172.22 via Frontend Transport; Tue, 2 Jun 2015 16:20:58 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD054.mail.protection.outlook.com (10.1.15.191) with Microsoft SMTP Server (TLS) id 15.1.172.14 via Frontend Transport; Tue, 2 Jun 2015 16:20:58 +0000 Received: from [az84smr01.freescale.net (B38339-11.am.freescale.net [10.81.93.183]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t52GKman031274; Tue, 2 Jun 2015 09:20:56 -0700 From: Shenwei Wang To: , , Subject: [PATCH 1/1] irqchip: imx-gpcv2: IMX GPCv2 driver for wakeup sources Date: Tue, 2 Jun 2015 11:20:20 -0500 Message-ID: <1433262020-25821-1-git-send-email-shenwei.wang@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD054; 1:xNz0sB1rxGSvRfD7ne64lvpO4NePg9iDFtksWk3nNDEnNpZGceVwbvsNCUj5ygkGl8vzNj7sm2Rfj3SqQgaQ49bURjMJOfco8pH75PemrkSeWmb00jhwqW1bsPa3fOgf7Z9S3UwyK/zc6C1AIiYu4fEWawkY35h88zcluB4QJRUn/Gie6mXdDZNZl76HHsPWbOzyBsxPcpkw7EvpBitMRnSIaqYJ00W+SIOJsJVt1VN9B+GyzHh7E8xRbgMt1iHKwHZKLX+TIfVAxR+Xep/DNqkhObH210aZMDYUMzIoKs9J7/sTy1BDqnC/hHsozE58 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(104016003)(5001830100001)(33646002)(81156007)(5001860100001)(5001960100002)(85426001)(48376002)(50986999)(19580405001)(92566002)(50466002)(86362001)(189998001)(105606002)(4001540100001)(5001770100001)(97736004)(36756003)(68736005)(77156002)(62966003)(77096005)(87936001)(2201001)(106466001)(64706001)(47776003)(6806004)(19580395003)(229853001)(46102003)(50226001)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR03MB609; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB609; 2:GNFcZaeSi7J0XIH939eiBkGgi/XwZfP3G0wzo3qp7FmhygzwUW8StAFr89Ra5AMH; 2:j137YY4mrA/qS3/R0yUHx1F9MrcCDmYJkMOP6H+D0dYI0YWM1oqsgyUlL4WfUwD+QFbFVw3yq3uPO5MjeH7IP4LGpzwJ1BF7LgdceriNN5tpEbCNsLTOCl6fcePBkzRDJ72i3LmEZ7fJ5jdLt5E99e3eVjde8UUVxT+z+NC+hyvMMTZfO4o20xvYpowv14JcNwJVMDv/MdIaxCpu45MNG8VnUUzYK+DM6zc4U1+DaZI=; 6:mbycd7TpMUiRiIOtZIH/8RS79dDLO4mBZFJQnDJKxVRhaMIuRNtcjMXZgIrPdw/x5mX8VfB6QIcTMPRw2iqvP6bc9/PiDIe+eOyX/wGAjETnl2dullGLpZh8YC0GHFUYpcysr2VM2C1MkpTcq0CIPuq1BSmT8IZ2EoiVC2Pc4JAfkI8mxqagFOoAqyPKqNn7PfE3dZ0a1OPa/gFl1LZMJqSX+/lw2pMKkKctT+Qylud4a0IOszskLWVS7Rj+8IDHDXNy9UMWwc436TjNmlBktuurnMe13oRj2CVkMIp2S3X1i+aWyYy+JC+l2VyXwuGILgn3RMD9iASWz/4Sn6VfOA==; 3:obO/VcVNUEjBsuZkShyl0WnnQpBAmsBDemyOr7/T9kk8iN6yVUus/f2b4CeKuzOma4E3IYxZm6z80Yf3VBcUaCPmrK7sM5BLJ3yoaC46AMN3E+9q31aY1deMFAqldUP+DIkPd5caAqEA0wwGEXEONwk6zqTfLTXt1RpRiiBUQBzwxuRSAVyd34fqtJzJmkmQCchNGGl438FvHEUB15uhhUNd1roOU5kzJFam91x5jnokQfvKsac9Qsg/qysJp/EUragVVsra7nqd3c/1ljTp5OSUTUscxsrVlcm1/at44Gf6vhksZQCdMfYOdqgl7W1y X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB609; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(520003)(3002001); SRVR:BY2PR03MB609; BCL:0; PCL:0; RULEID:; SRVR:BY2PR03MB609; X-Forefront-PRVS: 05954A7C45 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR03MB609; 9:o5r3nWh81J6GlhKKdkQifTvQ6TPAadwCIhh+jU/2jbc?= =?us-ascii?Q?Bg04c/cipqyLouzq9wZPr21XP5Tu+/PhFxkIcYPInWSyLCOWCmVQ4uQ69B88?= =?us-ascii?Q?5NJ+GCrP9q/UFtOKWoHBM1YcutkmbqZq6MLfLfa2Zl8eSm73r0dBeixtyqo9?= =?us-ascii?Q?JprnDYV/espvkoPTEhrRuFB7chDwStnqC9gBAWzCTpUzwDkG4bkuhePeL7Y+?= =?us-ascii?Q?cY012GLC4XhFWqp3LotQ3l19/Oa6Ql1iGtxxaXNd3U1UcNzhlr47PlfEt+6+?= =?us-ascii?Q?Jhg44fEHHsvGEXYBc5znRvNkdvrOnUa/yBPKRr//EOrYz8gk7YJN5WUFANbz?= =?us-ascii?Q?xQc+GeihG77feH33vG3MER+S0porKBN5rmQnswvGZMPUXDjMU6TWzdTd07UE?= =?us-ascii?Q?7tRp1atvZHSnV8T/AklcQMVkkaXjncduZvAgVgWh6lMc3pkn5cufRenirIwz?= =?us-ascii?Q?JSPWbkVqzppKBLn8R0qc6DyOsIWJ62oSWvK+Tbr/Y+Zau0njCybB8EV8WQmS?= =?us-ascii?Q?m7T9GU886OILdCbiw7dmN9Gmcw5Py9uvmaK13Nfg3P4DpSLsJ3R7pqUySgKd?= =?us-ascii?Q?cmAda/3PJL+D8nNR9azoRy+9/RHP+WDVgmAq+GOupMRett0T5WriEqrqTv2R?= =?us-ascii?Q?6CPUAz515p0MAAY/KO5K3CcGGqRl/xTAicTzb+gs230a3OlQs7xaisDjHg/p?= =?us-ascii?Q?cibnBzrPxZVUypBbCd3Qlg8G8odMrIBD42qHVUbfEEPm7ME5qHfAdvpL1l38?= =?us-ascii?Q?67iS7Z01XTsitGeooPEqZb4SyllgpSqwBs+T1qsGVchpXnl7P9eb8MdrxsXX?= =?us-ascii?Q?ck7LuK5QY5myaBsb0+j0kJKr/GeaIL7aDKz+HZ+oeQHKls8rLjEq7JEzKHQy?= =?us-ascii?Q?XT71yvRF2Pq23UR/Z9xonM9pQB3/fXSBxAhgd6S6p2LJhEWK7ac6NrXiPCGY?= =?us-ascii?Q?97pTTf+QdhwJXkfY8exBKQ736vcFOBOsvMynHAAv+LRt5mzWsSnXdXEq9ihe?= =?us-ascii?Q?183DDjZuXKdkeXab/+Vvo?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB609; 3:wGqnQ85qP4nPiYmX6Mbrekga9WuCICZ9ecHzOZIPnVl/zNUDzxofL317g8pLhO7WJ37S3J87ez1SfV8UYVfv44GuhZLsCsBqDkdkescixP7qX2p7DEH4KQJi0k+kGL+Ra1pXCMDOiND0CDr5dz8J2A==; 10:taGftpUp5ZcYgWpnFkPhvP1QD5juIKNVG9lJcd9VXvE9TwWFIGf7Rcz0/s05+CHGFQh+xTrvlhH0EyycOw6r8v1k+il6mZ1jUtUaULePwGE=; 6:U2E/hzPkiAr1RVwR+bc+8Ly5fynx5PjoxH5LK0DHrKKrGszKXSJmAdihJoR56PlP X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2015 16:20:58.3267 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB609 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150602_092123_846820_BB1ACA8A X-CRM114-Status: GOOD ( 19.24 ) X-Spam-Score: -1.1 (-) Cc: linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP IMX7D contains a new version of GPC IP block (GPCv2). It has two major functions: power management and wakeup source management. This patch adds a new irqchip driver to manage the interrupt wakeup sources on IMX7D. When the system is in WFI (wait for interrupt) mode, this GPC block will be the first block on the platform to be triggered. Under normal wait mode during cpu idle, the system can be woke up by any enabled interrupts. Under standby or suspend mode, the system can only be woke up by the pre-defined wakeup sources. Signed-off-by: Shenwei Wang --- arch/arm/mach-imx/Kconfig | 1 + drivers/irqchip/Kconfig | 7 + drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-imx-gpcv2.c | 329 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 338 insertions(+) create mode 100644 drivers/irqchip/irq-imx-gpcv2.c diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 5ccc9ea..4269c1e 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -552,6 +552,7 @@ config SOC_IMX7D bool "i.MX7 Dual support" select PINCTRL_IMX7D select ARM_GIC + select IMX_GPCV2 select HAVE_IMX_ANATOP select HAVE_IMX_MMDC help diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index 6de62a9..6a68cd5 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -158,3 +158,10 @@ config KEYSTONE_IRQ config MIPS_GIC bool select MIPS_CM + +config IMX_GPCV2 + bool + select IRQ_DOMAIN + help + Enables the wakeup IRQs for IMX platforms with GPCv2 block + diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile index dda4927..e6f4495 100644 --- a/drivers/irqchip/Makefile +++ b/drivers/irqchip/Makefile @@ -47,3 +47,4 @@ obj-$(CONFIG_KEYSTONE_IRQ) += irq-keystone.o obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o obj-$(CONFIG_ARCH_MEDIATEK) += irq-mtk-sysirq.o obj-$(CONFIG_ARCH_DIGICOLOR) += irq-digicolor.o +obj-$(CONFIG_IMX_GPCV2) += irq-imx-gpcv2.o diff --git a/drivers/irqchip/irq-imx-gpcv2.c b/drivers/irqchip/irq-imx-gpcv2.c new file mode 100644 index 0000000..ee043be --- /dev/null +++ b/drivers/irqchip/irq-imx-gpcv2.c @@ -0,0 +1,329 @@ + +/* + * Copyright (C) 2015 Freescale Semiconductor, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "irqchip.h" + + +#define IMR_NUM 4 +#define GPC_MAX_IRQS (IMR_NUM * 32) + +#define GPC_LPCR_A7_BSC 0x0 +#define GPC_LPCR_M4 0x8 + +#define GPC_IMR1_CORE0 0x30 +#define GPC_IMR1_CORE1 0x40 + +#define GPC_PGC_CPU_MAPPING 0xec +#define GPC_PGC_SCU_TIMING 0x890 + +#define BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP 0x70000000 +#define BM_LPCR_M4_MASK_DSM_TRIGGER 0x80000000 + +struct imx_irq_gpcv2 { + spinlock_t lock; + void __iomem *gpc_base; + u32 wakeup_sources[IMR_NUM]; + u32 enabled_irqs[IMR_NUM]; + u32 mfmix_mask[IMR_NUM]; + u32 wakeupmix_mask[IMR_NUM]; + u32 lpsrmix_mask[IMR_NUM]; + u32 cpu2wakeup; +}; + +static struct imx_irq_gpcv2 *gpcv2_get_chip_data(void) +{ + struct irq_data *data; + + /* Since GPCv2 is the root IRQ domain, its private data can + * be gotten from any irq descriptor. + */ + data = irq_get_irq_data(22); + if (!data) + return 0; + + return (struct imx_irq_gpcv2 *)data->chip_data; +} + +static int gpcv2_wakeup_source_save(void) +{ + struct imx_irq_gpcv2 *cd; + void __iomem *reg; + int i; + + cd = gpcv2_get_chip_data(); + if (!cd) + return 0; + + for (i = 0; i < IMR_NUM; i++) { + reg = cd->gpc_base + cd->cpu2wakeup + i * 4; + cd->enabled_irqs[i] = readl_relaxed(reg); + writel_relaxed(cd->wakeup_sources[i], reg); + } + + pr_devel("%s ----\r\n", __func__); + pr_devel("Enabled IRQ: %08X %08X %08X %08X\r\n", + cd->enabled_irqs[0], + cd->enabled_irqs[1], + cd->enabled_irqs[2], + cd->enabled_irqs[3]); + pr_devel("Wakeup Sources: %08X %08X %08X %08X\r\n", + cd->wakeup_sources[0], + cd->wakeup_sources[1], + cd->wakeup_sources[2], + cd->wakeup_sources[3]); + return 0; +} + +static void gpcv2_wakeup_source_restore(void) +{ + struct imx_irq_gpcv2 *cd; + void __iomem *reg; + int i; + + cd = gpcv2_get_chip_data(); + if (!cd) + return; + + for (i = 0; i < IMR_NUM; i++) { + reg = cd->gpc_base + cd->cpu2wakeup + i * 4; + writel_relaxed(cd->enabled_irqs[i], reg); + } + + pr_devel("%s ----\r\n", __func__); + pr_devel("Enabled IRQ: %08X %08X %08X %08X\r\n", + cd->enabled_irqs[0], + cd->enabled_irqs[1], + cd->enabled_irqs[2], + cd->enabled_irqs[3]); + pr_devel("Wakeup Sources: %08X %08X %08X %08X\r\n", + cd->wakeup_sources[0], + cd->wakeup_sources[1], + cd->wakeup_sources[2], + cd->wakeup_sources[3]); +} + +static struct syscore_ops imx_gpcv2_syscore_ops = { + .suspend = gpcv2_wakeup_source_save, + .resume = gpcv2_wakeup_source_restore, +}; + +static int imx_gpcv2_irq_set_wake(struct irq_data *d, unsigned int on) +{ + unsigned int idx = d->hwirq / 32; + struct imx_irq_gpcv2 *cd = d->chip_data; + u32 mask, val; + unsigned long flags; + void __iomem *reg; + + spin_lock_irqsave(&cd->lock, flags); + reg = cd->gpc_base + cd->cpu2wakeup + idx * 4; + mask = 1 << d->hwirq % 32; + val = cd->wakeup_sources[idx]; + + cd->wakeup_sources[idx] = on ? (val | mask) : (val & ~mask); + spin_unlock_irqrestore(&cd->lock, flags); + + /* + * Do *not* call into the parent, as the GIC doesn't have any + * wake-up facility... + */ + + return 0; +} + + +static void imx_gpcv2_irq_unmask(struct irq_data *d) +{ + void __iomem *reg; + struct imx_irq_gpcv2 *cd = d->chip_data; + u32 val; + unsigned long flags; + + spin_lock_irqsave(&cd->lock, flags); + reg = cd->gpc_base + cd->cpu2wakeup + d->hwirq / 32 * 4; + val = readl_relaxed(reg); + val &= ~(1 << d->hwirq % 32); + writel_relaxed(val, reg); + irq_chip_unmask_parent(d); + spin_unlock_irqrestore(&cd->lock, flags); +} + +static void imx_gpcv2_irq_mask(struct irq_data *d) +{ + void __iomem *reg; + struct imx_irq_gpcv2 *cd = d->chip_data; + u32 val; + unsigned long flags; + + spin_lock_irqsave(&cd->lock, flags); + reg = cd->gpc_base + cd->cpu2wakeup + d->hwirq / 32 * 4; + val = readl_relaxed(reg); + val |= 1 << (d->hwirq % 32); + writel_relaxed(val, reg); + + irq_chip_mask_parent(d); + spin_unlock_irqrestore(&cd->lock, flags); +} + +static struct irq_chip imx_gpcv2_irq_chip = { + .name = "GPCv2", + .irq_eoi = irq_chip_eoi_parent, + .irq_mask = imx_gpcv2_irq_mask, + .irq_unmask = imx_gpcv2_irq_unmask, + .irq_retrigger = irq_chip_retrigger_hierarchy, + .irq_set_wake = imx_gpcv2_irq_set_wake, +#ifdef CONFIG_SMP + .irq_set_affinity = irq_chip_set_affinity_parent, +#endif +}; + +static int imx_gpcv2_domain_xlate(struct irq_domain *domain, + struct device_node *controller, + const u32 *intspec, + unsigned int intsize, + unsigned long *out_hwirq, + unsigned int *out_type) +{ + if (domain->of_node != controller) + return -EINVAL; /* Shouldn't happen, really... */ + if (intsize != 3) + return -EINVAL; /* Not GIC compliant */ + if (intspec[0] != 0) + return -EINVAL; /* No PPI should point to this domain */ + + *out_hwirq = intspec[1]; + *out_type = intspec[2]; + return 0; +} + +static int imx_gpcv2_domain_alloc(struct irq_domain *domain, + unsigned int irq, + unsigned int nr_irqs, void *data) +{ + struct of_phandle_args *args = data; + struct of_phandle_args parent_args; + irq_hw_number_t hwirq; + int i; + + if (args->args_count != 3) + return -EINVAL; /* Not GIC compliant */ + if (args->args[0] != 0) + return -EINVAL; /* No PPI should point to this domain */ + + hwirq = args->args[1]; + if (hwirq >= GPC_MAX_IRQS) + return -EINVAL; /* Can't deal with this */ + + for (i = 0; i < nr_irqs; i++) { + irq_domain_set_hwirq_and_chip(domain, irq + i, hwirq + i, + &imx_gpcv2_irq_chip, domain->host_data); + + } + parent_args = *args; + parent_args.np = domain->parent->of_node; + return irq_domain_alloc_irqs_parent(domain, irq, nr_irqs, &parent_args); +} + +static struct irq_domain_ops imx_gpcv2_irq_domain_ops = { + .xlate = imx_gpcv2_domain_xlate, + .alloc = imx_gpcv2_domain_alloc, + .free = irq_domain_free_irqs_common, +}; + +static int __init imx_gpcv2_init(struct device_node *node, + struct device_node *parent) +{ + struct irq_domain *parent_domain, *domain; + int i, val; + struct imx_irq_gpcv2 *cd; + + if (!parent) { + pr_err("%s: no parent, giving up\n", node->full_name); + return -ENODEV; + } + + parent_domain = irq_find_host(parent); + if (!parent_domain) { + pr_err("%s: unable to obtain parent domain\n", node->full_name); + return -ENXIO; + } + + cd = kzalloc(sizeof(struct imx_irq_gpcv2), GFP_KERNEL); + BUG_ON(!cd); + + cd->gpc_base = of_iomap(node, 0); + if (!cd->gpc_base) { + pr_err("fsl-gpcv2: unable to map gpc registers\n"); + kzfree(cd); + return -ENOMEM; + } + + domain = irq_domain_add_hierarchy(parent_domain, 0, GPC_MAX_IRQS, + node, &imx_gpcv2_irq_domain_ops, cd); + if (!domain) { + iounmap(cd->gpc_base); + kzfree(cd); + return -ENOMEM; + } + irq_set_default_host(domain); + + /* Initially mask all interrupts */ + for (i = 0; i < IMR_NUM; i++) { + writel_relaxed(~0, cd->gpc_base + GPC_IMR1_CORE0 + i * 4); + writel_relaxed(~0, cd->gpc_base + GPC_IMR1_CORE1 + i * 4); + } + + /* Let CORE0 as the default CPU to wake up by GPC */ + cd->cpu2wakeup = GPC_IMR1_CORE0; + + /* + * Due to hardware design requirement, need to make sure GPR + * interrupt(#32) is unmasked during RUN mode to avoid entering + * DSM by mistake. + */ + writel_relaxed(~0x1, cd->gpc_base + cd->cpu2wakeup); + + /* Read supported wakeup source in M/F power domain */ + of_property_read_u32_index(node, "fsl,mf-mix-wakeup-irq", 0, + &cd->mfmix_mask[0]); + of_property_read_u32_index(node, "fsl,mf-mix-wakeup-irq", 1, + &cd->mfmix_mask[1]); + of_property_read_u32_index(node, "fsl,mf-mix-wakeup-irq", 2, + &cd->mfmix_mask[2]); + of_property_read_u32_index(node, "fsl,mf-mix-wakeup-irq", 3, + &cd->mfmix_mask[3]); + + /* only external IRQs to wake up LPM and core 0/1 */ + val = readl_relaxed(cd->gpc_base + GPC_LPCR_A7_BSC); + val |= BM_LPCR_A7_BSC_IRQ_SRC_A7_WAKEUP; + writel_relaxed(val, cd->gpc_base + GPC_LPCR_A7_BSC); + /* mask m4 dsm trigger */ + writel_relaxed(readl_relaxed(cd->gpc_base + GPC_LPCR_M4) | + BM_LPCR_M4_MASK_DSM_TRIGGER, cd->gpc_base + GPC_LPCR_M4); + /* set mega/fast mix in A7 domain */ + writel_relaxed(0x1, cd->gpc_base + GPC_PGC_CPU_MAPPING); + /* set SCU timing */ + writel_relaxed((0x59 << 10) | 0x5B | (0x51 << 20), + cd->gpc_base + GPC_PGC_SCU_TIMING); + + register_syscore_ops(&imx_gpcv2_syscore_ops); + + return 0; +} + + +IRQCHIP_DECLARE(imx_gpcv2, "fsl,imx7d-gpc", imx_gpcv2_init); +