From patchwork Wed Jul 22 17:07:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6845421 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 D27299F1D4 for ; Wed, 22 Jul 2015 17:10:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 68609206C5 for ; Wed, 22 Jul 2015 17:10:58 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8D5D206B2 for ; Wed, 22 Jul 2015 17:10:56 +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 1ZHxVa-00056K-Hq; Wed, 22 Jul 2015 17:08:42 +0000 Received: from mail-bl2on0118.outbound.protection.outlook.com ([65.55.169.118] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZHxVP-0004z0-H6 for linux-arm-kernel@lists.infradead.org; Wed, 22 Jul 2015 17:08:33 +0000 Received: from BY2PR03CA004.namprd03.prod.outlook.com (10.255.93.21) by BY1PR03MB1369.namprd03.prod.outlook.com (10.162.109.27) with Microsoft SMTP Server (TLS) id 15.1.225.19; Wed, 22 Jul 2015 17:08:08 +0000 Received: from BY2FFO11FD025.protection.gbl (10.255.93.4) by BY2PR03CA004.outlook.office365.com (10.255.93.21) with Microsoft SMTP Server (TLS) id 15.1.219.17 via Frontend Transport; Wed, 22 Jul 2015 17:08:08 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; 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 BY2FFO11FD025.mail.protection.outlook.com (10.1.15.214) with Microsoft SMTP Server (TLS) id 15.1.225.13 via Frontend Transport; Wed, 22 Jul 2015 17:08:08 +0000 Received: from [az84smr01.freescale.net (B38339-11.am.freescale.net [10.81.93.199]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t6MH7l0f024332; Wed, 22 Jul 2015 10:08:07 -0700 From: Shenwei Wang To: , , Subject: [PATCH v6 1/2] irqchip: imx-gpcv2: IMX GPCv2 driver for wakeup sources Date: Wed, 22 Jul 2015 12:07:38 -0500 Message-ID: <1437584859-64203-2-git-send-email-shenwei.wang@freescale.com> X-Mailer: git-send-email 2.5.0.rc2 In-Reply-To: <1437584859-64203-1-git-send-email-shenwei.wang@freescale.com> References: <1437584859-64203-1-git-send-email-shenwei.wang@freescale.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD025; 1:V5f8w2lF0+xwgyh1DZE70SfGI9rgcgkLlkYJXmbo3pjBokqGU14g4EXSo2Ig+FDVJb4iT7hAMhEyWjtTOKCmRyT/GkBM/63FSy6li8N4HepiNvwplE0vlBv6p9LBA19TUur+aw8+roevgwLkl5QHX4HDtNsGQg/uv89yBi4qQ7kNhVh1MYmVWagxJsf/wHPf9D4cpXNQUxsr2ACoXExLGYzfLMqucife1Ob5cK8nUj4eTdYDaFhSR97DEjLd24FriVvrkjq9HPq6GF46ugh984YNkBLcsXnw6zV17dbYk7L15+iBhU/UvDR3DG42gJ02UFE7pPFRAn/nyjrzNKLSrA== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(50986999)(104016003)(47776003)(33646002)(105606002)(2201001)(106466001)(2950100001)(46102003)(62966003)(229853001)(85426001)(87936001)(77156002)(189998001)(5003940100001)(76176999)(50226001)(6806004)(107886002)(5001960100002)(77096005)(5001770100001)(48376002)(50466002)(92566002)(36756003)(86362001)(19580405001)(19580395003)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR03MB1369; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1369; 2:OP3n05AubuGpFb+eHeBuOOw0jUe6cvYlTktWCR7MBsILND+oKLUi00l0OjmjTag+XDU0RL19/VJLJV8FwXoXZ0OWUQTNW8RPP3HOChNYfZpp6ra9/8cMDKIQSwaPr1OBCDMpBF0e87mTf3BbkayGkD3llBEjpJgfC/GYqDI04d4=; 3:LnuSuRbPa3H9QoOTW3nUddZCUobcWaK5xAIIpQw9tpGa+BdCS+saURO+LCXPZJgiqx2e083a7l7W/s33SWuq6VktgdFGWFanYtQVd80qFkTVLAYSI4nxXESCK2ZCsh1Goi2P6qcBL1ipRpZhdL2Hi/GS+v7Sh48X+uxG6HjiOODF93JM7q3wT38sk4FLrs221R/6Y47euenYZhWbE2qWPY0YkJ+XeYE00PJRfUVA8Ic=; 25:MeQ8u46Uqxe6ZJPl/YZpFrehZDJh7+R8XxV+m60sCljjukbTnhhTuQT5DsJBnBuCNiChWNrcDib6ODl6VV9q0PjEhGE7WSNffD6NC9VgWq5qL08a/Oqkbq8vP7aQ+1NwEVnXq9WlLtg4ydWc8Rf/HPKnSQ+paunNtF/8SChQcVJIbezjD0k0qH/fuM0+x/AcOOxy9Ox6rwR9Jk11YeXdQJ2yNjTNCbiM7ZTUqd9AiKgFf50A3s9eWYGLXXPkaBIP X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1369; X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1369; 20:wDM0n2j9tq7ke/nt/VANzCiVTxtPSOhklTb7M1UxiOGSsvd98jmz3ejXQCPRNtZi7wHR1eck6Op/rVeDVB4vjVyXfziiM4RXqRZd3ffYGDJs38i6jmKw2d8PyRlYswV4PG1yHgTLA8r093p4IFHcKGzj+66fwr/FDi2n3IM1l1HuRa2H8QDj+m4I3xwd9qDYrQnIHXM/mJcpYF9RCNvtCE7uhLWJ7l1p+LeV7XDhvo5V+lWMPqXKygHrmlorQd0xDz1M6b8LyY8FOEQP+0DBR7NdPEUoCF1Ppc677lgMOOpjizIsjMu1eNf4E8wHepP2K0srbOBavEMDrjFZZp07mKpr00PuP8Ze1bn4sTRZuyQ=; 4:+nExh3yyhvtgcSwvq0YbfbxxKW/RvXv7Ei1M0Wxib+jyn+O3StVwUO1f3DSKqyi8an7ZYkYL5xQMUcB7vHYQodTUaHqSVM52MDq+z9bmTztT6JBz1On9SCRof/HG1SB93e5DUfIj5b5fVV+l+QmRwuSzlACxDBFlAIPOadsueWALR5UUKlOidmW8G/hdTXvBqVcIUIRSb+pAu9lVuncQhT1r8GNKrxmGbCmiLBsxhv9v5vj6Lpgf5BrBADT9G5MBiOwiU4YCNcUjn0aocChSTH/I8dddmBuC6RMvdj0nins= BY1PR03MB1369: X-MS-Exchange-Organization-RulesExecuted X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BY1PR03MB1369; BCL:0; PCL:0; RULEID:; SRVR:BY1PR03MB1369; X-Forefront-PRVS: 0645BEB7AA X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY1PR03MB1369; 23:Bx+Uj/5+JOVBtq7YNE/V2paSkrd7+CtRKtM4U9AmA?= =?us-ascii?Q?yBYr8A61OcTO624jr+PoHEExCQ930lym9qczu1R+P7//fjbCA6+cmQHWTB3Z?= =?us-ascii?Q?SO5px1aQI7NvMkGTV6utGxUm0Kr3r3YNuWX63Ex9BAwK/xqWsVDRN6pcI+IG?= =?us-ascii?Q?nmaYIdv3N3N1a7+O4TcXEputns67B8ZeMl+X4oalV/zV6X0d2ZZSeWkMHPsI?= =?us-ascii?Q?gbAy8klfHUfOxkeMT5SKwD+kx+5r1Mnkj3gIxsOWC1vCeppe5ST3tFsxJA7r?= =?us-ascii?Q?D3x9z4evxLc6bcTqswX3XMGjw8AlCnhdi/9h4Fr7qic9KBAjpUSRkdMzI4DX?= =?us-ascii?Q?uRa3o6cDhhr9lY/tgHzHOYzc8U5E+olhHpdQOf4W8sMWiyNHTyyMVH52UV8C?= =?us-ascii?Q?bfkT83oGKtBreYesKUIMjRnYk2RP+Xn6KscHrvwAT6Evn/HMbUxzKP/NoaB5?= =?us-ascii?Q?gni6ZJ/OLUOJpahouuRWDivusrnROPukMy35wpGlL18VAhT8pnyvVJlPqeUK?= =?us-ascii?Q?m2Ts3K8lO453PbyIeTfn0rokOz1pqIBCfmxiSXLQq1GEpzwoVqsSJLzFOatS?= =?us-ascii?Q?YHIkNQwoWE79uvabPT0dHwP1FzEQjYmg3jJt8W6wo/X8Y6Hee0gPjHOanIdf?= =?us-ascii?Q?AtkzJMol2cjfBJ8UN1CoeCR6BTa1kKsLYz3N1GYktdGFcie8Z7TD9Ik2WDcg?= =?us-ascii?Q?iaoftmPC69srI/8zQUtPdzboIFYYRLxwP/ZTipEYiUy6yvbQPVgyT2yCxSPp?= =?us-ascii?Q?Vte7Jlp0jFxeqSpvuAoDzJ/jBXYA6XRyIPEv2V6qqXX9YPLMKw7kzwnxfzUO?= =?us-ascii?Q?N/wsu6DF/8q62WPzL5ld1z/72gHPaGqaAyMpZ5kqOZQa/akoLbI+hT7PCDxv?= =?us-ascii?Q?p1f92cdAPY8TNQsdG31j81If0p/KyP2Z7fpSbLp3JL+2kn0zc0AfD5kXx/0B?= =?us-ascii?Q?pzC20Jve6Zpbp+aQ9Kgu7Bk3+tW2kDXwIHMyg6NYA=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1369; 5:IMrGIVvnxys29+1EvkzCT++u+vw523qDsevY/+VccyBTbu+RN9r+8wZT2oKTBnM8poTUbaCY8Uc8fPubcZ8BVdmJk1hynhoEOQMRdo69yhzQDoGRJzPgRxVZAVhAI3o0CovFbN8TlG5VjjTCMxuEAw==; 24:J9Ti/UX3q8TZCKNhs9su6IaMlKnkTZr8cAncNzUyqiAj57F1pWETnyLg1rgzdZVwXBn/AqkOulN4AyE20kDeyBYOrP9bWz4hDC1LvUggyk4=; 20:mv61F+llYtG/BVsGTJPn0w5Xk7G7cVmHdcEQ8rR8kLloly+7OUsqE9iy56a2wxRRvjth6QUjI2aHG5GyZ1damA== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2015 17:08:08.4307 (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: BY1PR03MB1369 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150722_100831_929146_9B35DF88 X-CRM114-Status: GOOD ( 33.18 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: b20788@freescale.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED, 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 activated and signaled. 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 Signed-off-by: Anson Huang --- drivers/irqchip/Kconfig | 7 ++ drivers/irqchip/Makefile | 1 + drivers/irqchip/irq-imx-gpcv2.c | 263 ++++++++++++++++++++++++++++++++++++++++ include/soc/imx/gpcv2.h | 163 +++++++++++++++++++++++++ 4 files changed, 434 insertions(+) create mode 100644 drivers/irqchip/irq-imx-gpcv2.c create mode 100644 include/soc/imx/gpcv2.h 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..107c313 --- /dev/null +++ b/drivers/irqchip/irq-imx-gpcv2.c @@ -0,0 +1,263 @@ + +/* + * 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 + +struct imx_gpcv2_irq *gpcv2_irq_instance; + +static int gpcv2_wakeup_source_save(void) +{ + struct imx_gpcv2_irq *cd; + void __iomem *reg; + int i; + + cd = gpcv2_irq_instance; + 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); + } + + return 0; +} + +static void gpcv2_wakeup_source_restore(void) +{ + struct imx_gpcv2_irq *cd; + void __iomem *reg; + int i; + + cd = gpcv2_irq_instance; + 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); + cd->wakeup_sources[i] = ~0; + } +} + +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) +{ + struct imx_gpcv2_irq *cd = d->chip_data; + unsigned int idx = d->hwirq / 32; + unsigned long flags; + void __iomem *reg; + u32 mask, val; + + raw_spin_lock_irqsave(&cd->lock.rlock, 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); + raw_spin_unlock_irqrestore(&cd->lock.rlock, 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) +{ + struct imx_gpcv2_irq *cd = d->chip_data; + void __iomem *reg; + u32 val; + + raw_spin_lock(&cd->lock.rlock); + reg = cd->gpc_base + cd->cpu2wakeup + d->hwirq / 32 * 4; + val = readl_relaxed(reg); + val &= ~(1 << d->hwirq % 32); + writel_relaxed(val, reg); + raw_spin_unlock(&cd->lock.rlock); + + irq_chip_unmask_parent(d); +} + +static void imx_gpcv2_irq_mask(struct irq_data *d) +{ + struct imx_gpcv2_irq *cd = d->chip_data; + void __iomem *reg; + u32 val; + + raw_spin_lock(&cd->lock.rlock); + reg = cd->gpc_base + cd->cpu2wakeup + d->hwirq / 32 * 4; + val = readl_relaxed(reg); + val |= 1 << (d->hwirq % 32); + writel_relaxed(val, reg); + raw_spin_unlock(&cd->lock.rlock); + + irq_chip_mask_parent(d); +} + + +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_set_wake = imx_gpcv2_irq_set_wake, + .irq_retrigger = irq_chip_retrigger_hierarchy, +#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) +{ + /* Shouldn't happen, really... */ + if (domain->of_node != controller) + return -EINVAL; + + /* Not GIC compliant */ + if (intsize != 3) + return -EINVAL; + + /* No PPI should point to this domain */ + if (intspec[0] != 0) + return -EINVAL; + + *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; + + /* Not GIC compliant */ + if (args->args_count != 3) + return -EINVAL; + + /* No PPI should point to this domain */ + if (args->args[0] != 0) + return -EINVAL; + + /* Can't deal with this */ + hwirq = args->args[1]; + if (hwirq >= GPC_MAX_IRQS) + return -EINVAL; + + 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_irqchip_init(struct device_node *node, + struct device_node *parent) +{ + struct irq_domain *parent_domain, *domain; + struct imx_gpcv2_irq *cd; + int i, val; + + 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 get parent domain\n", node->full_name); + return -ENXIO; + } + + cd = kzalloc(sizeof(struct imx_gpcv2_irq), GFP_KERNEL); + + cd->gpc_base = of_iomap(node, 0); + if (!cd->gpc_base) { + pr_err("fsl-gpcv2: unable to map gpc registers\n"); + kfree(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); + kfree(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); + cd->wakeup_sources[i] = ~0; + } + + /* Let CORE0 as the default CPU to wake up by GPC */ + cd->cpu2wakeup = GPC_IMR1_CORE0; + + /* 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); + + gpcv2_irq_instance = cd; + + register_syscore_ops(&imx_gpcv2_syscore_ops); + + return 0; +} + + +IRQCHIP_DECLARE(imx_gpcv2, "fsl,imx7d-gpc", imx_gpcv2_irqchip_init); + + diff --git a/include/soc/imx/gpcv2.h b/include/soc/imx/gpcv2.h new file mode 100644 index 0000000..73d6e75 --- /dev/null +++ b/include/soc/imx/gpcv2.h @@ -0,0 +1,163 @@ +/* + * 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. + */ + +#ifndef __SOC_IMX_GPCV2_H__ +#define __SOC_IMX_GPCV2_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 + + +#define GPC_LPCR_A7_AD 0x4 +#define GPC_SLPCR 0x14 +#define GPC_PGC_ACK_SEL_A7 0x24 + +#define GPC_SLOT0_CFG 0xb0 + +#define GPC_PGC_C0 0x800 +#define GPC_PGC_SCU_TIMING 0x890 +#define GPC_PGC_C1 0x840 +#define GPC_PGC_SCU 0x880 +#define GPC_PGC_FM 0xa00 + +#define BM_LPCR_A7_BSC_CPU_CLK_ON_LPM 0x4000 +#define BM_LPCR_A7_BSC_LPM1 0xc +#define BM_LPCR_A7_BSC_LPM0 0x3 +#define BP_LPCR_A7_BSC_LPM1 2 +#define BP_LPCR_A7_BSC_LPM0 0 + +#define BM_SLPCR_EN_DSM 0x80000000 +#define BM_SLPCR_RBC_EN 0x40000000 +#define BM_SLPCR_VSTBY 0x4 +#define BM_SLPCR_SBYOS 0x2 +#define BM_SLPCR_BYPASS_PMIC_READY 0x1 + + +#define BM_LPCR_A7_AD_L2PGE 0x10000 +#define BM_LPCR_A7_AD_EN_C1_PUP 0x800 +#define BM_LPCR_A7_AD_EN_C1_IRQ_PUP 0x400 +#define BM_LPCR_A7_AD_EN_C0_PUP 0x200 +#define BM_LPCR_A7_AD_EN_C0_IRQ_PUP 0x100 +#define BM_LPCR_A7_AD_EN_PLAT_PDN 0x10 +#define BM_LPCR_A7_AD_EN_C1_PDN 0x8 +#define BM_LPCR_A7_AD_EN_C1_WFI_PDN 0x4 +#define BM_LPCR_A7_AD_EN_C0_PDN 0x2 +#define BM_LPCR_A7_AD_EN_C0_WFI_PDN 0x1 + +#define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PUP_ACK 0x80000000 +#define BM_GPC_PGC_ACK_SEL_A7_DUMMY_PDN_ACK 0x8000 + +#define MAX_SLOT_NUMBER 10 +#define A7_LPM_WAIT 0x5 +#define A7_LPM_STOP 0xa + + +#define REG_SET 0x4 +#define REG_CLR 0x8 + +#define ANADIG_ARM_PLL 0x60 +#define ANADIG_DDR_PLL 0x70 +#define ANADIG_SYS_PLL 0xb0 +#define ANADIG_ENET_PLL 0xe0 +#define ANADIG_AUDIO_PLL 0xf0 +#define ANADIG_VIDEO_PLL 0x130 + + +enum gpcv2_mode { + WAIT_CLOCKED, + WAIT_UNCLOCKED, + WAIT_UNCLOCKED_POWER_OFF, + STOP_POWER_ON, + STOP_POWER_OFF, +}; + + +/* GPCv2 has the following power domains, and each domain can be power-up + * and power-down via GPC settings. + * + * Core 0 of A7 power domain + * Core1 of A7 power domain + * SCU/L2 cache RAM of A7 power domain + * Fastmix and megamix power domain + * USB OTG1 PHY power domain + * USB OTG2 PHY power domain + * PCIE PHY power domain + * USB HSIC PHY power domain + * Core 0 of M4 power domain + */ +enum gpcv2_slot { + CORE0_A7, + CORE1_A7, + SCU_A7, + FAST_MEGA_MIX, + MIPI_PHY, + PCIE_PHY, + USB_OTG1_PHY, + USB_OTG2_PHY, + USB_HSIC_PHY, + CORE0_M4, +}; + +struct imx_gpcv2; + +struct imx_gpcv2_irq { + spinlock_t lock; + void __iomem *gpc_base; + u32 wakeup_sources[IMR_NUM]; + u32 enabled_irqs[IMR_NUM]; + u32 cpu2wakeup; +}; + +struct imx_gpcv2_suspend { + struct regmap *anatop; + struct regmap *imx_src; + u32 mfmix_mask[IMR_NUM]; + u32 wakeupmix_mask[IMR_NUM]; + u32 lpsrmix_mask[IMR_NUM]; + + void (*set_mode)(struct imx_gpcv2 *, enum gpcv2_mode mode); + void (*lpm_cpu_power_gate)(struct imx_gpcv2 *, u32, bool); + void (*lpm_plat_power_gate)(struct imx_gpcv2 *, bool); + void (*lpm_env_setup)(struct imx_gpcv2 *); + void (*lpm_env_clean)(struct imx_gpcv2 *); + + void (*set_slot)(struct imx_gpcv2 *cd, u32 index, + enum gpcv2_slot m_core, bool mode, bool ack); + void (*clear_slots)(struct imx_gpcv2 *); + void (*lpm_enable_core)(struct imx_gpcv2 *, + bool enable, u32 offset); + + void (*standby)(struct imx_gpcv2 *); + void (*suspend)(struct imx_gpcv2 *); + + void (*suspend_fn_in_ocram)(void __iomem *ocram_vbase); + void __iomem *ocram_vbase; +}; + +struct imx_gpcv2 { + struct imx_gpcv2_irq *irqchip; + struct imx_gpcv2_suspend *pm; +}; + +void ca7_cpu_resume(void); +void imx7_suspend(void __iomem *ocram_vbase); + +#endif /* __SOC_IMX_GPCV2_H__ */