2 * Copyright (C) 2011 Google, Inc.
5 * Colin Cross <ccross@android.com>
7 * Copyright (C) 2010,2013, NVIDIA Corporation
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <linux/kernel.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
25 #include <linux/irqchip/arm-gic.h>
26 #include <linux/syscore_ops.h>
31 #define ICTLR_CPU_IEP_VFIQ 0x08
32 #define ICTLR_CPU_IEP_FIR 0x14
33 #define ICTLR_CPU_IEP_FIR_SET 0x18
34 #define ICTLR_CPU_IEP_FIR_CLR 0x1c
36 #define ICTLR_CPU_IER 0x20
37 #define ICTLR_CPU_IER_SET 0x24
38 #define ICTLR_CPU_IER_CLR 0x28
39 #define ICTLR_CPU_IEP_CLASS 0x2C
41 #define ICTLR_COP_IER 0x30
42 #define ICTLR_COP_IER_SET 0x34
43 #define ICTLR_COP_IER_CLR 0x38
44 #define ICTLR_COP_IEP_CLASS 0x3c
46 #define FIRST_LEGACY_IRQ 32
47 #define TEGRA_MAX_NUM_ICTLRS 5
49 #define SGI_MASK 0xFFFF
51 static int num_ictlrs
;
53 static void __iomem
*ictlr_reg_base
[] = {
54 IO_ADDRESS(TEGRA_PRIMARY_ICTLR_BASE
),
55 IO_ADDRESS(TEGRA_SECONDARY_ICTLR_BASE
),
56 IO_ADDRESS(TEGRA_TERTIARY_ICTLR_BASE
),
57 IO_ADDRESS(TEGRA_QUATERNARY_ICTLR_BASE
),
58 IO_ADDRESS(TEGRA_QUINARY_ICTLR_BASE
),
61 #ifdef CONFIG_PM_SLEEP
62 static u32 cop_ier
[TEGRA_MAX_NUM_ICTLRS
];
63 static u32 cop_iep
[TEGRA_MAX_NUM_ICTLRS
];
64 static u32 cpu_ier
[TEGRA_MAX_NUM_ICTLRS
];
65 static u32 cpu_iep
[TEGRA_MAX_NUM_ICTLRS
];
67 static u32 ictlr_wake_mask
[TEGRA_MAX_NUM_ICTLRS
];
70 bool tegra_pending_sgi(void)
73 void __iomem
*distbase
= IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE
);
75 pending_set
= readl_relaxed(distbase
+ GIC_DIST_PENDING_SET
);
77 if (pending_set
& SGI_MASK
)
83 static inline void tegra_irq_write_mask(unsigned int irq
, unsigned long reg
)
88 BUG_ON(irq
< FIRST_LEGACY_IRQ
||
89 irq
>= FIRST_LEGACY_IRQ
+ num_ictlrs
* 32);
91 base
= ictlr_reg_base
[(irq
- FIRST_LEGACY_IRQ
) / 32];
92 mask
= BIT((irq
- FIRST_LEGACY_IRQ
) % 32);
94 __raw_writel(mask
, base
+ reg
);
97 static void tegra_mask(struct irq_data
*d
)
99 if (d
->irq
< FIRST_LEGACY_IRQ
)
102 tegra_irq_write_mask(d
->irq
, ICTLR_CPU_IER_CLR
);
105 static void tegra_unmask(struct irq_data
*d
)
107 if (d
->irq
< FIRST_LEGACY_IRQ
)
110 tegra_irq_write_mask(d
->irq
, ICTLR_CPU_IER_SET
);
113 static void tegra_ack(struct irq_data
*d
)
115 if (d
->irq
< FIRST_LEGACY_IRQ
)
118 tegra_irq_write_mask(d
->irq
, ICTLR_CPU_IEP_FIR_CLR
);
121 static void tegra_eoi(struct irq_data
*d
)
123 if (d
->irq
< FIRST_LEGACY_IRQ
)
126 tegra_irq_write_mask(d
->irq
, ICTLR_CPU_IEP_FIR_CLR
);
129 static int tegra_retrigger(struct irq_data
*d
)
131 if (d
->irq
< FIRST_LEGACY_IRQ
)
134 tegra_irq_write_mask(d
->irq
, ICTLR_CPU_IEP_FIR_SET
);
139 #ifdef CONFIG_PM_SLEEP
140 static int tegra_set_wake(struct irq_data
*d
, unsigned int enable
)
145 if (irq
< FIRST_LEGACY_IRQ
||
146 irq
>= FIRST_LEGACY_IRQ
+ num_ictlrs
* 32)
149 index
= ((irq
- FIRST_LEGACY_IRQ
) / 32);
150 mask
= BIT((irq
- FIRST_LEGACY_IRQ
) % 32);
152 ictlr_wake_mask
[index
] |= mask
;
154 ictlr_wake_mask
[index
] &= ~mask
;
159 static int tegra_legacy_irq_suspend(void)
164 local_irq_save(flags
);
165 for (i
= 0; i
< num_ictlrs
; i
++) {
166 void __iomem
*ictlr
= ictlr_reg_base
[i
];
167 /* Save interrupt state */
168 cpu_ier
[i
] = readl_relaxed(ictlr
+ ICTLR_CPU_IER
);
169 cpu_iep
[i
] = readl_relaxed(ictlr
+ ICTLR_CPU_IEP_CLASS
);
170 cop_ier
[i
] = readl_relaxed(ictlr
+ ICTLR_COP_IER
);
171 cop_iep
[i
] = readl_relaxed(ictlr
+ ICTLR_COP_IEP_CLASS
);
173 /* Disable COP interrupts */
174 writel_relaxed(~0ul, ictlr
+ ICTLR_COP_IER_CLR
);
176 /* Disable CPU interrupts */
177 writel_relaxed(~0ul, ictlr
+ ICTLR_CPU_IER_CLR
);
179 /* Enable the wakeup sources of ictlr */
180 writel_relaxed(ictlr_wake_mask
[i
], ictlr
+ ICTLR_CPU_IER_SET
);
182 local_irq_restore(flags
);
187 static void tegra_legacy_irq_resume(void)
192 local_irq_save(flags
);
193 for (i
= 0; i
< num_ictlrs
; i
++) {
194 void __iomem
*ictlr
= ictlr_reg_base
[i
];
195 writel_relaxed(cpu_iep
[i
], ictlr
+ ICTLR_CPU_IEP_CLASS
);
196 writel_relaxed(~0ul, ictlr
+ ICTLR_CPU_IER_CLR
);
197 writel_relaxed(cpu_ier
[i
], ictlr
+ ICTLR_CPU_IER_SET
);
198 writel_relaxed(cop_iep
[i
], ictlr
+ ICTLR_COP_IEP_CLASS
);
199 writel_relaxed(~0ul, ictlr
+ ICTLR_COP_IER_CLR
);
200 writel_relaxed(cop_ier
[i
], ictlr
+ ICTLR_COP_IER_SET
);
202 local_irq_restore(flags
);
205 static struct syscore_ops tegra_legacy_irq_syscore_ops
= {
206 .suspend
= tegra_legacy_irq_suspend
,
207 .resume
= tegra_legacy_irq_resume
,
210 int tegra_legacy_irq_syscore_init(void)
212 register_syscore_ops(&tegra_legacy_irq_syscore_ops
);
217 #define tegra_set_wake NULL
220 void __init
tegra_init_irq(void)
223 void __iomem
*distbase
;
225 distbase
= IO_ADDRESS(TEGRA_ARM_INT_DIST_BASE
);
226 num_ictlrs
= readl_relaxed(distbase
+ GIC_DIST_CTR
) & 0x1f;
228 if (num_ictlrs
> ARRAY_SIZE(ictlr_reg_base
)) {
229 WARN(1, "Too many (%d) interrupt controllers found. Maximum is %d.",
230 num_ictlrs
, ARRAY_SIZE(ictlr_reg_base
));
231 num_ictlrs
= ARRAY_SIZE(ictlr_reg_base
);
234 for (i
= 0; i
< num_ictlrs
; i
++) {
235 void __iomem
*ictlr
= ictlr_reg_base
[i
];
236 writel(~0, ictlr
+ ICTLR_CPU_IER_CLR
);
237 writel(0, ictlr
+ ICTLR_CPU_IEP_CLASS
);
240 gic_arch_extn
.irq_ack
= tegra_ack
;
241 gic_arch_extn
.irq_eoi
= tegra_eoi
;
242 gic_arch_extn
.irq_mask
= tegra_mask
;
243 gic_arch_extn
.irq_unmask
= tegra_unmask
;
244 gic_arch_extn
.irq_retrigger
= tegra_retrigger
;
245 gic_arch_extn
.irq_set_wake
= tegra_set_wake
;
246 gic_arch_extn
.flags
= IRQCHIP_MASK_ON_SUSPEND
;
249 * Check if there is a devicetree present, since the GIC will be
250 * initialized elsewhere under DT.
252 if (!of_have_populated_dt())
253 gic_init(0, 29, distbase
,
254 IO_ADDRESS(TEGRA_ARM_PERIF_BASE
+ 0x100));