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
21 #include <linux/init.h>
22 #include <linux/list.h>
24 #include <linux/sysdev.h>
25 #include <linux/device.h>
26 #include <linux/amba/bus.h>
28 #include <asm/mach/irq.h>
29 #include <asm/hardware/vic.h>
31 static void vic_ack_irq(unsigned int irq
)
33 void __iomem
*base
= get_irq_chip_data(irq
);
35 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
36 /* moreover, clear the soft-triggered, in case it was the reason */
37 writel(1 << irq
, base
+ VIC_INT_SOFT_CLEAR
);
40 static void vic_mask_irq(unsigned int irq
)
42 void __iomem
*base
= get_irq_chip_data(irq
);
44 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
47 static void vic_unmask_irq(unsigned int irq
)
49 void __iomem
*base
= get_irq_chip_data(irq
);
51 writel(1 << irq
, base
+ VIC_INT_ENABLE
);
55 * vic_init2 - common initialisation code
56 * @base: Base of the VIC.
58 * Common initialisation code for registeration
61 static void vic_init2(void __iomem
*base
)
65 for (i
= 0; i
< 16; i
++) {
66 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
67 writel(VIC_VECT_CNTL_ENABLE
| i
, reg
);
70 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
73 #if defined(CONFIG_PM)
75 * struct vic_device - VIC PM device
76 * @sysdev: The system device which is registered.
77 * @irq: The IRQ number for the base of the VIC.
78 * @base: The register base for the VIC.
79 * @resume_sources: A bitmask of interrupts for resume.
80 * @resume_irqs: The IRQs enabled for resume.
81 * @int_select: Save for VIC_INT_SELECT.
82 * @int_enable: Save for VIC_INT_ENABLE.
83 * @soft_int: Save for VIC_INT_SOFT.
84 * @protect: Save for VIC_PROTECT.
87 struct sys_device sysdev
;
99 /* we cannot allocate memory when VICs are initially registered */
100 static struct vic_device vic_devices
[CONFIG_ARM_VIC_NR
];
102 static inline struct vic_device
*to_vic(struct sys_device
*sys
)
104 return container_of(sys
, struct vic_device
, sysdev
);
109 static int vic_class_resume(struct sys_device
*dev
)
111 struct vic_device
*vic
= to_vic(dev
);
112 void __iomem
*base
= vic
->base
;
114 printk(KERN_DEBUG
"%s: resuming vic at %p\n", __func__
, base
);
116 /* re-initialise static settings */
119 writel(vic
->int_select
, base
+ VIC_INT_SELECT
);
120 writel(vic
->protect
, base
+ VIC_PROTECT
);
122 /* set the enabled ints and then clear the non-enabled */
123 writel(vic
->int_enable
, base
+ VIC_INT_ENABLE
);
124 writel(~vic
->int_enable
, base
+ VIC_INT_ENABLE_CLEAR
);
126 /* and the same for the soft-int register */
128 writel(vic
->soft_int
, base
+ VIC_INT_SOFT
);
129 writel(~vic
->soft_int
, base
+ VIC_INT_SOFT_CLEAR
);
134 static int vic_class_suspend(struct sys_device
*dev
, pm_message_t state
)
136 struct vic_device
*vic
= to_vic(dev
);
137 void __iomem
*base
= vic
->base
;
139 printk(KERN_DEBUG
"%s: suspending vic at %p\n", __func__
, base
);
141 vic
->int_select
= readl(base
+ VIC_INT_SELECT
);
142 vic
->int_enable
= readl(base
+ VIC_INT_ENABLE
);
143 vic
->soft_int
= readl(base
+ VIC_INT_SOFT
);
144 vic
->protect
= readl(base
+ VIC_PROTECT
);
146 /* set the interrupts (if any) that are used for
147 * resuming the system */
149 writel(vic
->resume_irqs
, base
+ VIC_INT_ENABLE
);
150 writel(~vic
->resume_irqs
, base
+ VIC_INT_ENABLE_CLEAR
);
155 struct sysdev_class vic_class
= {
157 .suspend
= vic_class_suspend
,
158 .resume
= vic_class_resume
,
162 * vic_pm_register - Register a VIC for later power management control
163 * @base: The base address of the VIC.
164 * @irq: The base IRQ for the VIC.
165 * @resume_sources: bitmask of interrupts allowed for resume sources.
167 * Register the VIC with the system device tree so that it can be notified
168 * of suspend and resume requests and ensure that the correct actions are
169 * taken to re-instate the settings on resume.
171 static void __init
vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 resume_sources
)
173 struct vic_device
*v
;
175 if (vic_id
>= ARRAY_SIZE(vic_devices
))
176 printk(KERN_ERR
"%s: too few VICs, increase CONFIG_ARM_VIC_NR\n", __func__
);
178 v
= &vic_devices
[vic_id
];
180 v
->resume_sources
= resume_sources
;
187 * vic_pm_init - initicall to register VIC pm
189 * This is called via late_initcall() to register
190 * the resources for the VICs due to the early
191 * nature of the VIC's registration.
193 static int __init
vic_pm_init(void)
195 struct vic_device
*dev
= vic_devices
;
202 err
= sysdev_class_register(&vic_class
);
204 printk(KERN_ERR
"%s: cannot register class\n", __func__
);
208 for (id
= 0; id
< vic_id
; id
++, dev
++) {
210 dev
->sysdev
.cls
= &vic_class
;
212 err
= sysdev_register(&dev
->sysdev
);
214 printk(KERN_ERR
"%s: failed to register device\n",
223 late_initcall(vic_pm_init
);
225 static struct vic_device
*vic_from_irq(unsigned int irq
)
227 struct vic_device
*v
= vic_devices
;
228 unsigned int base_irq
= irq
& ~31;
231 for (id
= 0; id
< vic_id
; id
++, v
++) {
232 if (v
->irq
== base_irq
)
239 static int vic_set_wake(unsigned int irq
, unsigned int on
)
241 struct vic_device
*v
= vic_from_irq(irq
);
242 unsigned int off
= irq
& 31;
248 if (!(bit
& v
->resume_sources
))
252 v
->resume_irqs
|= bit
;
254 v
->resume_irqs
&= ~bit
;
260 static inline void vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 arg1
) { }
262 #define vic_set_wake NULL
263 #endif /* CONFIG_PM */
265 static struct irq_chip vic_chip
= {
268 .mask
= vic_mask_irq
,
269 .unmask
= vic_unmask_irq
,
270 .set_wake
= vic_set_wake
,
273 /* The PL190 cell from ARM has been modified by ST, so handle both here */
274 static void vik_init_st(void __iomem
*base
, unsigned int irq_start
,
278 * vic_init - initialise a vectored interrupt controller
279 * @base: iomem base address
280 * @irq_start: starting interrupt number, must be muliple of 32
281 * @vic_sources: bitmask of interrupt sources to allow
282 * @resume_sources: bitmask of interrupt sources to allow for resume
284 void __init
vic_init(void __iomem
*base
, unsigned int irq_start
,
285 u32 vic_sources
, u32 resume_sources
)
289 enum amba_vendor vendor
;
291 /* Identify which VIC cell this one is, by reading the ID */
292 for (i
= 0; i
< 4; i
++) {
293 u32 addr
= ((u32
)base
& PAGE_MASK
) + 0xfe0 + (i
* 4);
294 cellid
|= (readl(addr
) & 0xff) << (8 * i
);
296 vendor
= (cellid
>> 12) & 0xff;
297 printk(KERN_INFO
"VIC @%p: id 0x%08x, vendor 0x%02x\n",
298 base
, cellid
, vendor
);
302 vik_init_st(base
, irq_start
, vic_sources
);
305 printk(KERN_WARNING
"VIC: unknown vendor, continuing anyways\n");
307 case AMBA_VENDOR_ARM
:
311 /* Disable all interrupts initially. */
313 writel(0, base
+ VIC_INT_SELECT
);
314 writel(0, base
+ VIC_INT_ENABLE
);
315 writel(~0, base
+ VIC_INT_ENABLE_CLEAR
);
316 writel(0, base
+ VIC_IRQ_STATUS
);
317 writel(0, base
+ VIC_ITCR
);
318 writel(~0, base
+ VIC_INT_SOFT_CLEAR
);
321 * Make sure we clear all existing interrupts
323 writel(0, base
+ VIC_PL190_VECT_ADDR
);
324 for (i
= 0; i
< 19; i
++) {
327 value
= readl(base
+ VIC_PL190_VECT_ADDR
);
328 writel(value
, base
+ VIC_PL190_VECT_ADDR
);
333 for (i
= 0; i
< 32; i
++) {
334 if (vic_sources
& (1 << i
)) {
335 unsigned int irq
= irq_start
+ i
;
337 set_irq_chip(irq
, &vic_chip
);
338 set_irq_chip_data(irq
, base
);
339 set_irq_handler(irq
, handle_level_irq
);
340 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
344 vic_pm_register(base
, irq_start
, resume_sources
);
348 * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
349 * The original cell has 32 interrupts, while the modified one has 64,
350 * replocating two blocks 0x00..0x1f in 0x20..0x3f. In that case
351 * the probe function is called twice, with base set to offset 000
352 * and 020 within the page. We call this "second block".
354 static void __init
vik_init_st(void __iomem
*base
, unsigned int irq_start
,
358 int vic_2nd_block
= ((unsigned long)base
& ~PAGE_MASK
) != 0;
360 /* Disable all interrupts initially. */
362 writel(0, base
+ VIC_INT_SELECT
);
363 writel(0, base
+ VIC_INT_ENABLE
);
364 writel(~0, base
+ VIC_INT_ENABLE_CLEAR
);
365 writel(0, base
+ VIC_IRQ_STATUS
);
366 writel(0, base
+ VIC_ITCR
);
367 writel(~0, base
+ VIC_INT_SOFT_CLEAR
);
370 * Make sure we clear all existing interrupts. The vector registers
371 * in this cell are after the second block of general registers,
372 * so we can address them using standard offsets, but only from
373 * the second base address, which is 0x20 in the page
376 writel(0, base
+ VIC_PL190_VECT_ADDR
);
377 for (i
= 0; i
< 19; i
++) {
380 value
= readl(base
+ VIC_PL190_VECT_ADDR
);
381 writel(value
, base
+ VIC_PL190_VECT_ADDR
);
383 /* ST has 16 vectors as well, but we don't enable them by now */
384 for (i
= 0; i
< 16; i
++) {
385 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
389 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
392 for (i
= 0; i
< 32; i
++) {
393 if (vic_sources
& (1 << i
)) {
394 unsigned int irq
= irq_start
+ i
;
396 set_irq_chip(irq
, &vic_chip
);
397 set_irq_chip_data(irq
, base
);
398 set_irq_handler(irq
, handle_level_irq
);
399 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);