2 * linux/arch/arm/common/vic.c
4 * Copyright (C) 1999 - 2003 ARM Limited
5 * Copyright (C) 2000 Deep Blue Solutions Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/list.h>
25 #include <linux/syscore_ops.h>
26 #include <linux/device.h>
27 #include <linux/amba/bus.h>
29 #include <asm/mach/irq.h>
30 #include <asm/hardware/vic.h>
34 * struct vic_device - VIC PM device
35 * @irq: The IRQ number for the base of the VIC.
36 * @base: The register base for the VIC.
37 * @resume_sources: A bitmask of interrupts for resume.
38 * @resume_irqs: The IRQs enabled for resume.
39 * @int_select: Save for VIC_INT_SELECT.
40 * @int_enable: Save for VIC_INT_ENABLE.
41 * @soft_int: Save for VIC_INT_SOFT.
42 * @protect: Save for VIC_PROTECT.
55 /* we cannot allocate memory when VICs are initially registered */
56 static struct vic_device vic_devices
[CONFIG_ARM_VIC_NR
];
59 #endif /* CONFIG_PM */
62 * vic_init2 - common initialisation code
63 * @base: Base of the VIC.
65 * Common initialisation code for registration
68 static void vic_init2(void __iomem
*base
)
72 for (i
= 0; i
< 16; i
++) {
73 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
74 writel(VIC_VECT_CNTL_ENABLE
| i
, reg
);
77 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
81 static void resume_one_vic(struct vic_device
*vic
)
83 void __iomem
*base
= vic
->base
;
85 printk(KERN_DEBUG
"%s: resuming vic at %p\n", __func__
, base
);
87 /* re-initialise static settings */
90 writel(vic
->int_select
, base
+ VIC_INT_SELECT
);
91 writel(vic
->protect
, base
+ VIC_PROTECT
);
93 /* set the enabled ints and then clear the non-enabled */
94 writel(vic
->int_enable
, base
+ VIC_INT_ENABLE
);
95 writel(~vic
->int_enable
, base
+ VIC_INT_ENABLE_CLEAR
);
97 /* and the same for the soft-int register */
99 writel(vic
->soft_int
, base
+ VIC_INT_SOFT
);
100 writel(~vic
->soft_int
, base
+ VIC_INT_SOFT_CLEAR
);
103 static void vic_resume(void)
107 for (id
= vic_id
- 1; id
>= 0; id
--)
108 resume_one_vic(vic_devices
+ id
);
111 static void suspend_one_vic(struct vic_device
*vic
)
113 void __iomem
*base
= vic
->base
;
115 printk(KERN_DEBUG
"%s: suspending vic at %p\n", __func__
, base
);
117 vic
->int_select
= readl(base
+ VIC_INT_SELECT
);
118 vic
->int_enable
= readl(base
+ VIC_INT_ENABLE
);
119 vic
->soft_int
= readl(base
+ VIC_INT_SOFT
);
120 vic
->protect
= readl(base
+ VIC_PROTECT
);
122 /* set the interrupts (if any) that are used for
123 * resuming the system */
125 writel(vic
->resume_irqs
, base
+ VIC_INT_ENABLE
);
126 writel(~vic
->resume_irqs
, base
+ VIC_INT_ENABLE_CLEAR
);
129 static int vic_suspend(void)
133 for (id
= 0; id
< vic_id
; id
++)
134 suspend_one_vic(vic_devices
+ id
);
139 struct syscore_ops vic_syscore_ops
= {
140 .suspend
= vic_suspend
,
141 .resume
= vic_resume
,
145 * vic_pm_init - initicall to register VIC pm
147 * This is called via late_initcall() to register
148 * the resources for the VICs due to the early
149 * nature of the VIC's registration.
151 static int __init
vic_pm_init(void)
154 register_syscore_ops(&vic_syscore_ops
);
158 late_initcall(vic_pm_init
);
161 * vic_pm_register - Register a VIC for later power management control
162 * @base: The base address of the VIC.
163 * @irq: The base IRQ for the VIC.
164 * @resume_sources: bitmask of interrupts allowed for resume sources.
166 * Register the VIC with the system device tree so that it can be notified
167 * of suspend and resume requests and ensure that the correct actions are
168 * taken to re-instate the settings on resume.
170 static void __init
vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 resume_sources
)
172 struct vic_device
*v
;
174 if (vic_id
>= ARRAY_SIZE(vic_devices
))
175 printk(KERN_ERR
"%s: too few VICs, increase CONFIG_ARM_VIC_NR\n", __func__
);
177 v
= &vic_devices
[vic_id
];
179 v
->resume_sources
= resume_sources
;
185 static inline void vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 arg1
) { }
186 #endif /* CONFIG_PM */
188 static void vic_ack_irq(struct irq_data
*d
)
190 void __iomem
*base
= irq_data_get_irq_chip_data(d
);
191 unsigned int irq
= d
->irq
& 31;
192 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
193 /* moreover, clear the soft-triggered, in case it was the reason */
194 writel(1 << irq
, base
+ VIC_INT_SOFT_CLEAR
);
197 static void vic_mask_irq(struct irq_data
*d
)
199 void __iomem
*base
= irq_data_get_irq_chip_data(d
);
200 unsigned int irq
= d
->irq
& 31;
201 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
204 static void vic_unmask_irq(struct irq_data
*d
)
206 void __iomem
*base
= irq_data_get_irq_chip_data(d
);
207 unsigned int irq
= d
->irq
& 31;
208 writel(1 << irq
, base
+ VIC_INT_ENABLE
);
211 #if defined(CONFIG_PM)
212 static struct vic_device
*vic_from_irq(unsigned int irq
)
214 struct vic_device
*v
= vic_devices
;
215 unsigned int base_irq
= irq
& ~31;
218 for (id
= 0; id
< vic_id
; id
++, v
++) {
219 if (v
->irq
== base_irq
)
226 static int vic_set_wake(struct irq_data
*d
, unsigned int on
)
228 struct vic_device
*v
= vic_from_irq(d
->irq
);
229 unsigned int off
= d
->irq
& 31;
235 if (!(bit
& v
->resume_sources
))
239 v
->resume_irqs
|= bit
;
241 v
->resume_irqs
&= ~bit
;
246 #define vic_set_wake NULL
247 #endif /* CONFIG_PM */
249 static struct irq_chip vic_chip
= {
251 .irq_ack
= vic_ack_irq
,
252 .irq_mask
= vic_mask_irq
,
253 .irq_unmask
= vic_unmask_irq
,
254 .irq_set_wake
= vic_set_wake
,
257 static void __init
vic_disable(void __iomem
*base
)
259 writel(0, base
+ VIC_INT_SELECT
);
260 writel(0, base
+ VIC_INT_ENABLE
);
261 writel(~0, base
+ VIC_INT_ENABLE_CLEAR
);
262 writel(0, base
+ VIC_IRQ_STATUS
);
263 writel(0, base
+ VIC_ITCR
);
264 writel(~0, base
+ VIC_INT_SOFT_CLEAR
);
267 static void __init
vic_clear_interrupts(void __iomem
*base
)
271 writel(0, base
+ VIC_PL190_VECT_ADDR
);
272 for (i
= 0; i
< 19; i
++) {
275 value
= readl(base
+ VIC_PL190_VECT_ADDR
);
276 writel(value
, base
+ VIC_PL190_VECT_ADDR
);
280 static void __init
vic_set_irq_sources(void __iomem
*base
,
281 unsigned int irq_start
, u32 vic_sources
)
285 for (i
= 0; i
< 32; i
++) {
286 if (vic_sources
& (1 << i
)) {
287 unsigned int irq
= irq_start
+ i
;
289 irq_set_chip_and_handler(irq
, &vic_chip
,
291 irq_set_chip_data(irq
, base
);
292 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
298 * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
299 * The original cell has 32 interrupts, while the modified one has 64,
300 * replocating two blocks 0x00..0x1f in 0x20..0x3f. In that case
301 * the probe function is called twice, with base set to offset 000
302 * and 020 within the page. We call this "second block".
304 static void __init
vic_init_st(void __iomem
*base
, unsigned int irq_start
,
308 int vic_2nd_block
= ((unsigned long)base
& ~PAGE_MASK
) != 0;
310 /* Disable all interrupts initially. */
314 * Make sure we clear all existing interrupts. The vector registers
315 * in this cell are after the second block of general registers,
316 * so we can address them using standard offsets, but only from
317 * the second base address, which is 0x20 in the page
320 vic_clear_interrupts(base
);
322 /* ST has 16 vectors as well, but we don't enable them by now */
323 for (i
= 0; i
< 16; i
++) {
324 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
328 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
331 vic_set_irq_sources(base
, irq_start
, vic_sources
);
335 * vic_init - initialise a vectored interrupt controller
336 * @base: iomem base address
337 * @irq_start: starting interrupt number, must be muliple of 32
338 * @vic_sources: bitmask of interrupt sources to allow
339 * @resume_sources: bitmask of interrupt sources to allow for resume
341 void __init
vic_init(void __iomem
*base
, unsigned int irq_start
,
342 u32 vic_sources
, u32 resume_sources
)
346 enum amba_vendor vendor
;
348 /* Identify which VIC cell this one is, by reading the ID */
349 for (i
= 0; i
< 4; i
++) {
350 u32 addr
= ((u32
)base
& PAGE_MASK
) + 0xfe0 + (i
* 4);
351 cellid
|= (readl(addr
) & 0xff) << (8 * i
);
353 vendor
= (cellid
>> 12) & 0xff;
354 printk(KERN_INFO
"VIC @%p: id 0x%08x, vendor 0x%02x\n",
355 base
, cellid
, vendor
);
359 vic_init_st(base
, irq_start
, vic_sources
);
362 printk(KERN_WARNING
"VIC: unknown vendor, continuing anyways\n");
364 case AMBA_VENDOR_ARM
:
368 /* Disable all interrupts initially. */
371 /* Make sure we clear all existing interrupts */
372 vic_clear_interrupts(base
);
376 vic_set_irq_sources(base
, irq_start
, vic_sources
);
378 vic_pm_register(base
, irq_start
, resume_sources
);