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>
26 #include <asm/mach/irq.h>
27 #include <asm/hardware/vic.h>
29 static void vic_ack_irq(unsigned int irq
)
31 void __iomem
*base
= get_irq_chip_data(irq
);
33 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
34 /* moreover, clear the soft-triggered, in case it was the reason */
35 writel(1 << irq
, base
+ VIC_INT_SOFT_CLEAR
);
38 static void vic_mask_irq(unsigned int irq
)
40 void __iomem
*base
= get_irq_chip_data(irq
);
42 writel(1 << irq
, base
+ VIC_INT_ENABLE_CLEAR
);
45 static void vic_unmask_irq(unsigned int irq
)
47 void __iomem
*base
= get_irq_chip_data(irq
);
49 writel(1 << irq
, base
+ VIC_INT_ENABLE
);
53 * vic_init2 - common initialisation code
54 * @base: Base of the VIC.
56 * Common initialisation code for registeration
59 static void vic_init2(void __iomem
*base
)
63 for (i
= 0; i
< 16; i
++) {
64 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
65 writel(VIC_VECT_CNTL_ENABLE
| i
, reg
);
68 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
71 #if defined(CONFIG_PM)
73 * struct vic_device - VIC PM device
74 * @sysdev: The system device which is registered.
75 * @irq: The IRQ number for the base of the VIC.
76 * @base: The register base for the VIC.
77 * @resume_sources: A bitmask of interrupts for resume.
78 * @resume_irqs: The IRQs enabled for resume.
79 * @int_select: Save for VIC_INT_SELECT.
80 * @int_enable: Save for VIC_INT_ENABLE.
81 * @soft_int: Save for VIC_INT_SOFT.
82 * @protect: Save for VIC_PROTECT.
85 struct sys_device sysdev
;
97 /* we cannot allocate memory when VICs are initially registered */
98 static struct vic_device vic_devices
[CONFIG_ARM_VIC_NR
];
100 static inline struct vic_device
*to_vic(struct sys_device
*sys
)
102 return container_of(sys
, struct vic_device
, sysdev
);
107 static int vic_class_resume(struct sys_device
*dev
)
109 struct vic_device
*vic
= to_vic(dev
);
110 void __iomem
*base
= vic
->base
;
112 printk(KERN_DEBUG
"%s: resuming vic at %p\n", __func__
, base
);
114 /* re-initialise static settings */
117 writel(vic
->int_select
, base
+ VIC_INT_SELECT
);
118 writel(vic
->protect
, base
+ VIC_PROTECT
);
120 /* set the enabled ints and then clear the non-enabled */
121 writel(vic
->int_enable
, base
+ VIC_INT_ENABLE
);
122 writel(~vic
->int_enable
, base
+ VIC_INT_ENABLE_CLEAR
);
124 /* and the same for the soft-int register */
126 writel(vic
->soft_int
, base
+ VIC_INT_SOFT
);
127 writel(~vic
->soft_int
, base
+ VIC_INT_SOFT_CLEAR
);
132 static int vic_class_suspend(struct sys_device
*dev
, pm_message_t state
)
134 struct vic_device
*vic
= to_vic(dev
);
135 void __iomem
*base
= vic
->base
;
137 printk(KERN_DEBUG
"%s: suspending vic at %p\n", __func__
, base
);
139 vic
->int_select
= readl(base
+ VIC_INT_SELECT
);
140 vic
->int_enable
= readl(base
+ VIC_INT_ENABLE
);
141 vic
->soft_int
= readl(base
+ VIC_INT_SOFT
);
142 vic
->protect
= readl(base
+ VIC_PROTECT
);
144 /* set the interrupts (if any) that are used for
145 * resuming the system */
147 writel(vic
->resume_irqs
, base
+ VIC_INT_ENABLE
);
148 writel(~vic
->resume_irqs
, base
+ VIC_INT_ENABLE_CLEAR
);
153 struct sysdev_class vic_class
= {
155 .suspend
= vic_class_suspend
,
156 .resume
= vic_class_resume
,
160 * vic_pm_register - Register a VIC for later power management control
161 * @base: The base address of the VIC.
162 * @irq: The base IRQ for the VIC.
163 * @resume_sources: bitmask of interrupts allowed for resume sources.
165 * Register the VIC with the system device tree so that it can be notified
166 * of suspend and resume requests and ensure that the correct actions are
167 * taken to re-instate the settings on resume.
169 static void __init
vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 resume_sources
)
171 struct vic_device
*v
;
173 if (vic_id
>= ARRAY_SIZE(vic_devices
))
174 printk(KERN_ERR
"%s: too few VICs, increase CONFIG_ARM_VIC_NR\n", __func__
);
176 v
= &vic_devices
[vic_id
];
178 v
->resume_sources
= resume_sources
;
185 * vic_pm_init - initicall to register VIC pm
187 * This is called via late_initcall() to register
188 * the resources for the VICs due to the early
189 * nature of the VIC's registration.
191 static int __init
vic_pm_init(void)
193 struct vic_device
*dev
= vic_devices
;
200 err
= sysdev_class_register(&vic_class
);
202 printk(KERN_ERR
"%s: cannot register class\n", __func__
);
206 for (id
= 0; id
< vic_id
; id
++, dev
++) {
208 dev
->sysdev
.cls
= &vic_class
;
210 err
= sysdev_register(&dev
->sysdev
);
212 printk(KERN_ERR
"%s: failed to register device\n",
221 late_initcall(vic_pm_init
);
223 static struct vic_device
*vic_from_irq(unsigned int irq
)
225 struct vic_device
*v
= vic_devices
;
226 unsigned int base_irq
= irq
& ~31;
229 for (id
= 0; id
< vic_id
; id
++, v
++) {
230 if (v
->irq
== base_irq
)
237 static int vic_set_wake(unsigned int irq
, unsigned int on
)
239 struct vic_device
*v
= vic_from_irq(irq
);
240 unsigned int off
= irq
& 31;
246 if (!(bit
& v
->resume_sources
))
250 v
->resume_irqs
|= bit
;
252 v
->resume_irqs
&= ~bit
;
258 static inline void vic_pm_register(void __iomem
*base
, unsigned int irq
, u32 arg1
) { }
260 #define vic_set_wake NULL
261 #endif /* CONFIG_PM */
263 static struct irq_chip vic_chip
= {
266 .mask
= vic_mask_irq
,
267 .unmask
= vic_unmask_irq
,
268 .set_wake
= vic_set_wake
,
271 /* The PL190 cell from ARM has been modified by ST, so handle both here */
272 static void vik_init_st(void __iomem
*base
, unsigned int irq_start
,
281 * vic_init - initialise a vectored interrupt controller
282 * @base: iomem base address
283 * @irq_start: starting interrupt number, must be muliple of 32
284 * @vic_sources: bitmask of interrupt sources to allow
285 * @resume_sources: bitmask of interrupt sources to allow for resume
287 void __init
vic_init(void __iomem
*base
, unsigned int irq_start
,
288 u32 vic_sources
, u32 resume_sources
)
292 enum vic_vendor vendor
;
294 /* Identify which VIC cell this one is, by reading the ID */
295 for (i
= 0; i
< 4; i
++) {
296 u32 addr
= ((u32
)base
& PAGE_MASK
) + 0xfe0 + (i
* 4);
297 cellid
|= (readl(addr
) & 0xff) << (8 * i
);
299 vendor
= (cellid
>> 12) & 0xff;
300 printk(KERN_INFO
"VIC @%p: id 0x%08x, vendor 0x%02x\n",
301 base
, cellid
, vendor
);
305 vik_init_st(base
, irq_start
, vic_sources
);
308 printk(KERN_WARNING
"VIC: unknown vendor, continuing anyways\n");
314 /* Disable all interrupts initially. */
316 writel(0, base
+ VIC_INT_SELECT
);
317 writel(0, base
+ VIC_INT_ENABLE
);
318 writel(~0, base
+ VIC_INT_ENABLE_CLEAR
);
319 writel(0, base
+ VIC_IRQ_STATUS
);
320 writel(0, base
+ VIC_ITCR
);
321 writel(~0, base
+ VIC_INT_SOFT_CLEAR
);
324 * Make sure we clear all existing interrupts
326 writel(0, base
+ VIC_PL190_VECT_ADDR
);
327 for (i
= 0; i
< 19; i
++) {
330 value
= readl(base
+ VIC_PL190_VECT_ADDR
);
331 writel(value
, base
+ VIC_PL190_VECT_ADDR
);
336 for (i
= 0; i
< 32; i
++) {
337 if (vic_sources
& (1 << i
)) {
338 unsigned int irq
= irq_start
+ i
;
340 set_irq_chip(irq
, &vic_chip
);
341 set_irq_chip_data(irq
, base
);
342 set_irq_handler(irq
, handle_level_irq
);
343 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
347 vic_pm_register(base
, irq_start
, resume_sources
);
351 * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
352 * The original cell has 32 interrupts, while the modified one has 64,
353 * replocating two blocks 0x00..0x1f in 0x20..0x3f. In that case
354 * the probe function is called twice, with base set to offset 000
355 * and 020 within the page. We call this "second block".
357 static void __init
vik_init_st(void __iomem
*base
, unsigned int irq_start
,
361 int vic_2nd_block
= ((unsigned long)base
& ~PAGE_MASK
) != 0;
363 /* Disable all interrupts initially. */
365 writel(0, base
+ VIC_INT_SELECT
);
366 writel(0, base
+ VIC_INT_ENABLE
);
367 writel(~0, base
+ VIC_INT_ENABLE_CLEAR
);
368 writel(0, base
+ VIC_IRQ_STATUS
);
369 writel(0, base
+ VIC_ITCR
);
370 writel(~0, base
+ VIC_INT_SOFT_CLEAR
);
373 * Make sure we clear all existing interrupts. The vector registers
374 * in this cell are after the second block of general registers,
375 * so we can address them using standard offsets, but only from
376 * the second base address, which is 0x20 in the page
379 writel(0, base
+ VIC_PL190_VECT_ADDR
);
380 for (i
= 0; i
< 19; i
++) {
383 value
= readl(base
+ VIC_PL190_VECT_ADDR
);
384 writel(value
, base
+ VIC_PL190_VECT_ADDR
);
386 /* ST has 16 vectors as well, but we don't enable them by now */
387 for (i
= 0; i
< 16; i
++) {
388 void __iomem
*reg
= base
+ VIC_VECT_CNTL0
+ (i
* 4);
392 writel(32, base
+ VIC_PL190_DEF_VECT_ADDR
);
395 for (i
= 0; i
< 32; i
++) {
396 if (vic_sources
& (1 << i
)) {
397 unsigned int irq
= irq_start
+ i
;
399 set_irq_chip(irq
, &vic_chip
);
400 set_irq_chip_data(irq
, base
);
401 set_irq_handler(irq
, handle_level_irq
);
402 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
This page took 0.056726 seconds and 5 git commands to generate.