xref: /linux/arch/arm/mach-tegra/irq.c (revision 460907bc26f5565aced3cf35a10e3579c671ef50)
15ad36c5fSErik Gilling /*
25ad36c5fSErik Gilling  * Copyright (C) 2010 Google, Inc.
35ad36c5fSErik Gilling  *
45ad36c5fSErik Gilling  * Author:
55ad36c5fSErik Gilling  *	Colin Cross <ccross@google.com>
65ad36c5fSErik Gilling  *
7*460907bcSGary King  * Copyright (C) 2010, NVIDIA Corporation
8*460907bcSGary King  *
95ad36c5fSErik Gilling  * This software is licensed under the terms of the GNU General Public
105ad36c5fSErik Gilling  * License version 2, as published by the Free Software Foundation, and
115ad36c5fSErik Gilling  * may be copied, distributed, and modified under those terms.
125ad36c5fSErik Gilling  *
135ad36c5fSErik Gilling  * This program is distributed in the hope that it will be useful,
145ad36c5fSErik Gilling  * but WITHOUT ANY WARRANTY; without even the implied warranty of
155ad36c5fSErik Gilling  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165ad36c5fSErik Gilling  * GNU General Public License for more details.
175ad36c5fSErik Gilling  *
185ad36c5fSErik Gilling  */
195ad36c5fSErik Gilling 
205ad36c5fSErik Gilling #include <linux/kernel.h>
215ad36c5fSErik Gilling #include <linux/init.h>
225ad36c5fSErik Gilling #include <linux/interrupt.h>
235ad36c5fSErik Gilling #include <linux/irq.h>
245ad36c5fSErik Gilling #include <linux/io.h>
255ad36c5fSErik Gilling 
265ad36c5fSErik Gilling #include <asm/hardware/gic.h>
275ad36c5fSErik Gilling 
285ad36c5fSErik Gilling #include <mach/iomap.h>
295ad36c5fSErik Gilling 
305ad36c5fSErik Gilling #include "board.h"
315ad36c5fSErik Gilling 
32*460907bcSGary King #define INT_SYS_NR	(INT_GPIO_BASE - INT_PRI_BASE)
33*460907bcSGary King #define INT_SYS_SZ	(INT_SEC_BASE - INT_PRI_BASE)
34*460907bcSGary King #define PPI_NR		((INT_SYS_NR+INT_SYS_SZ-1)/INT_SYS_SZ)
35*460907bcSGary King 
36*460907bcSGary King #define APBDMA_IRQ_STA_CPU  0x14
37*460907bcSGary King #define APBDMA_IRQ_MASK_SET 0x20
38*460907bcSGary King #define APBDMA_IRQ_MASK_CLR 0x24
39*460907bcSGary King 
40*460907bcSGary King #define ICTLR_CPU_IER		0x20
41*460907bcSGary King #define ICTLR_CPU_IER_SET	0x24
42*460907bcSGary King #define ICTLR_CPU_IER_CLR	0x28
43*460907bcSGary King #define ICTLR_CPU_IEP_CLASS	0x2c
44*460907bcSGary King #define ICTLR_COP_IER		0x30
45*460907bcSGary King #define ICTLR_COP_IER_SET	0x34
46*460907bcSGary King #define ICTLR_COP_IER_CLR	0x38
47*460907bcSGary King #define ICTLR_COP_IEP_CLASS	0x3c
48*460907bcSGary King 
49*460907bcSGary King static void (*gic_mask_irq)(unsigned int irq);
50*460907bcSGary King static void (*gic_unmask_irq)(unsigned int irq);
51*460907bcSGary King 
52*460907bcSGary King #define irq_to_ictlr(irq) (((irq)-32) >> 5)
53*460907bcSGary King static void __iomem *tegra_ictlr_base = IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE);
54*460907bcSGary King #define ictlr_to_virt(ictlr) (tegra_ictlr_base + (ictlr)*0x100)
55*460907bcSGary King 
56*460907bcSGary King static void tegra_mask(unsigned int irq)
57*460907bcSGary King {
58*460907bcSGary King 	void __iomem *addr = ictlr_to_virt(irq_to_ictlr(irq));
59*460907bcSGary King 	gic_mask_irq(irq);
60*460907bcSGary King 	writel(1<<(irq&31), addr+ICTLR_CPU_IER_CLR);
61*460907bcSGary King }
62*460907bcSGary King 
63*460907bcSGary King static void tegra_unmask(unsigned int irq)
64*460907bcSGary King {
65*460907bcSGary King 	void __iomem *addr = ictlr_to_virt(irq_to_ictlr(irq));
66*460907bcSGary King 	gic_unmask_irq(irq);
67*460907bcSGary King 	writel(1<<(irq&31), addr+ICTLR_CPU_IER_SET);
68*460907bcSGary King }
69*460907bcSGary King 
70*460907bcSGary King #ifdef CONFIG_PM
71*460907bcSGary King 
72*460907bcSGary King static int tegra_set_wake(unsigned int irq, unsigned int on)
73*460907bcSGary King {
74*460907bcSGary King 	return 0;
75*460907bcSGary King }
76*460907bcSGary King #endif
77*460907bcSGary King 
78*460907bcSGary King static struct irq_chip tegra_irq = {
79*460907bcSGary King 	.name		= "PPI",
80*460907bcSGary King 	.mask		= tegra_mask,
81*460907bcSGary King 	.unmask		= tegra_unmask,
82*460907bcSGary King #ifdef CONFIG_PM
83*460907bcSGary King 	.set_wake	= tegra_set_wake,
84*460907bcSGary King #endif
85*460907bcSGary King };
86*460907bcSGary King 
875ad36c5fSErik Gilling void __init tegra_init_irq(void)
885ad36c5fSErik Gilling {
89*460907bcSGary King 	struct irq_chip *gic;
90*460907bcSGary King 	unsigned int i;
91*460907bcSGary King 
92*460907bcSGary King 	for (i = 0; i < PPI_NR; i++) {
93*460907bcSGary King 		writel(~0, ictlr_to_virt(i) + ICTLR_CPU_IER_CLR);
94*460907bcSGary King 		writel(0, ictlr_to_virt(i) + ICTLR_CPU_IEP_CLASS);
95*460907bcSGary King 	}
96*460907bcSGary King 
975ad36c5fSErik Gilling 	gic_dist_init(0, IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE), 29);
985ad36c5fSErik Gilling 	gic_cpu_init(0, IO_ADDRESS(TEGRA_ARM_PERIF_BASE + 0x100));
99*460907bcSGary King 
100*460907bcSGary King 	gic = get_irq_chip(29);
101*460907bcSGary King 	gic_unmask_irq = gic->unmask;
102*460907bcSGary King 	gic_mask_irq = gic->mask;
103*460907bcSGary King 	tegra_irq.ack = gic->ack;
104*460907bcSGary King #ifdef CONFIG_SMP
105*460907bcSGary King 	tegra_irq.set_affinity = gic->set_affinity;
106*460907bcSGary King #endif
107*460907bcSGary King 
108*460907bcSGary King 	for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
109*460907bcSGary King 		set_irq_chip(i, &tegra_irq);
110*460907bcSGary King 		set_irq_handler(i, handle_level_irq);
111*460907bcSGary King 		set_irq_flags(i, IRQF_VALID);
1125ad36c5fSErik Gilling 	}
113*460907bcSGary King }
114*460907bcSGary King 
115*460907bcSGary King #ifdef CONFIG_PM
116*460907bcSGary King static u32 cop_ier[PPI_NR];
117*460907bcSGary King static u32 cpu_ier[PPI_NR];
118*460907bcSGary King static u32 cpu_iep[PPI_NR];
119*460907bcSGary King 
120*460907bcSGary King void tegra_irq_suspend(void)
121*460907bcSGary King {
122*460907bcSGary King 	unsigned long flags;
123*460907bcSGary King 	int i;
124*460907bcSGary King 
125*460907bcSGary King 	for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
126*460907bcSGary King 		struct irq_desc *desc = irq_to_desc(i);
127*460907bcSGary King 		if (!desc)
128*460907bcSGary King 			continue;
129*460907bcSGary King 		if (desc->status & IRQ_WAKEUP) {
130*460907bcSGary King 			pr_debug("irq %d is wakeup\n", i);
131*460907bcSGary King 			continue;
132*460907bcSGary King 		}
133*460907bcSGary King 		disable_irq(i);
134*460907bcSGary King 	}
135*460907bcSGary King 
136*460907bcSGary King 	local_irq_save(flags);
137*460907bcSGary King 	for (i = 0; i < PPI_NR; i++) {
138*460907bcSGary King 		void __iomem *ictlr = ictlr_to_virt(i);
139*460907bcSGary King 		cpu_ier[i] = readl(ictlr + ICTLR_CPU_IER);
140*460907bcSGary King 		cpu_iep[i] = readl(ictlr + ICTLR_CPU_IEP_CLASS);
141*460907bcSGary King 		cop_ier[i] = readl(ictlr + ICTLR_COP_IER);
142*460907bcSGary King 		writel(~0, ictlr + ICTLR_COP_IER_CLR);
143*460907bcSGary King 	}
144*460907bcSGary King 	local_irq_restore(flags);
145*460907bcSGary King }
146*460907bcSGary King 
147*460907bcSGary King void tegra_irq_resume(void)
148*460907bcSGary King {
149*460907bcSGary King 	unsigned long flags;
150*460907bcSGary King 	int i;
151*460907bcSGary King 
152*460907bcSGary King 	local_irq_save(flags);
153*460907bcSGary King 	for (i = 0; i < PPI_NR; i++) {
154*460907bcSGary King 		void __iomem *ictlr = ictlr_to_virt(i);
155*460907bcSGary King 		writel(cpu_iep[i], ictlr + ICTLR_CPU_IEP_CLASS);
156*460907bcSGary King 		writel(~0ul, ictlr + ICTLR_CPU_IER_CLR);
157*460907bcSGary King 		writel(cpu_ier[i], ictlr + ICTLR_CPU_IER_SET);
158*460907bcSGary King 		writel(0, ictlr + ICTLR_COP_IEP_CLASS);
159*460907bcSGary King 		writel(~0ul, ictlr + ICTLR_COP_IER_CLR);
160*460907bcSGary King 		writel(cop_ier[i], ictlr + ICTLR_COP_IER_SET);
161*460907bcSGary King 	}
162*460907bcSGary King 	local_irq_restore(flags);
163*460907bcSGary King 
164*460907bcSGary King 	for (i = INT_PRI_BASE; i < INT_GPIO_BASE; i++) {
165*460907bcSGary King 		struct irq_desc *desc = irq_to_desc(i);
166*460907bcSGary King 		if (!desc || (desc->status & IRQ_WAKEUP))
167*460907bcSGary King 			continue;
168*460907bcSGary King 		enable_irq(i);
169*460907bcSGary King 	}
170*460907bcSGary King }
171*460907bcSGary King #endif
172