Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6
[sfrench/cifs-2.6.git] / arch / arm / mach-lh7a40x / irq-lh7a404.c
1 /* arch/arm/mach-lh7a40x/irq-lh7a404.c
2  *
3  *  Copyright (C) 2004 Logic Product Development
4  *
5  *  This program is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU General Public License
7  *  version 2 as published by the Free Software Foundation.
8  *
9  */
10
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/interrupt.h>
14 #include <linux/ptrace.h>
15
16 #include <asm/hardware.h>
17 #include <asm/irq.h>
18 #include <asm/mach/irq.h>
19 #include <asm/arch/irqs.h>
20
21 #include "common.h"
22
23 #define USE_PRIORITIES
24
25 /* See Documentation/arm/Sharp-LH/VectoredInterruptController for more
26  * information on using the vectored interrupt controller's
27  * prioritizing feature. */
28
29 static unsigned char irq_pri_vic1[] = {
30 #if defined (USE_PRIORITIES)
31         IRQ_GPIO3INTR,                  /* CPLD */
32         IRQ_DMAM2P4, IRQ_DMAM2P5,       /* AC97 */
33 #endif
34 };
35 static unsigned char irq_pri_vic2[] = {
36 #if defined (USE_PRIORITIES)
37         IRQ_T3UI,                       /* Timer */
38         IRQ_GPIO7INTR,                  /* CPLD */
39         IRQ_UART1INTR, IRQ_UART2INTR, IRQ_UART3INTR,
40         IRQ_LCDINTR,                    /* LCD */
41         IRQ_TSCINTR,                    /* ADC/Touchscreen */
42 #endif
43 };
44
45   /* CPU IRQ handling */
46
47 static void lh7a404_vic1_mask_irq (u32 irq)
48 {
49         VIC1_INTENCLR = (1 << irq);
50 }
51
52 static void lh7a404_vic1_unmask_irq (u32 irq)
53 {
54         VIC1_INTEN = (1 << irq);
55 }
56
57 static void lh7a404_vic2_mask_irq (u32 irq)
58 {
59         VIC2_INTENCLR = (1 << (irq - 32));
60 }
61
62 static void lh7a404_vic2_unmask_irq (u32 irq)
63 {
64         VIC2_INTEN = (1 << (irq - 32));
65 }
66
67 static void lh7a404_vic1_ack_gpio_irq (u32 irq)
68 {
69         GPIO_GPIOFEOI = (1 << IRQ_TO_GPIO (irq));
70         VIC1_INTENCLR = (1 << irq);
71 }
72
73 static void lh7a404_vic2_ack_gpio_irq (u32 irq)
74 {
75         GPIO_GPIOFEOI = (1 << IRQ_TO_GPIO (irq));
76         VIC2_INTENCLR = (1 << irq);
77 }
78
79 static struct irq_chip lh7a404_vic1_chip = {
80         .name   = "VIC1",
81         .ack    = lh7a404_vic1_mask_irq, /* Because level-triggered */
82         .mask   = lh7a404_vic1_mask_irq,
83         .unmask = lh7a404_vic1_unmask_irq,
84 };
85
86 static struct irq_chip lh7a404_vic2_chip = {
87         .name   = "VIC2",
88         .ack    = lh7a404_vic2_mask_irq, /* Because level-triggered */
89         .mask   = lh7a404_vic2_mask_irq,
90         .unmask = lh7a404_vic2_unmask_irq,
91 };
92
93 static struct irq_chip lh7a404_gpio_vic1_chip = {
94         .name   = "GPIO-VIC1",
95         .ack    = lh7a404_vic1_ack_gpio_irq,
96         .mask   = lh7a404_vic1_mask_irq,
97         .unmask = lh7a404_vic1_unmask_irq,
98 };
99
100 static struct irq_chip lh7a404_gpio_vic2_chip = {
101         .name   = "GPIO-VIC2",
102         .ack    = lh7a404_vic2_ack_gpio_irq,
103         .mask   = lh7a404_vic2_mask_irq,
104         .unmask = lh7a404_vic2_unmask_irq,
105 };
106
107   /* IRQ initialization */
108
109 #if defined (CONFIG_ARCH_LH7A400) && defined (CONFIG_ARCH_LH7A404)
110 extern void* branch_irq_lh7a400;
111 #endif
112
113 void __init lh7a404_init_irq (void)
114 {
115         int irq;
116
117 #if defined (CONFIG_ARCH_LH7A400) && defined (CONFIG_ARCH_LH7A404)
118 #define NOP 0xe1a00000                  /* mov r0, r0 */
119         branch_irq_lh7a400 = NOP;
120 #endif
121
122         VIC1_INTENCLR = 0xffffffff;
123         VIC2_INTENCLR = 0xffffffff;
124         VIC1_INTSEL = 0;                /* All IRQs */
125         VIC2_INTSEL = 0;                /* All IRQs */
126         VIC1_NVADDR = VA_VIC1DEFAULT;
127         VIC2_NVADDR = VA_VIC2DEFAULT;
128         VIC1_VECTADDR = 0;
129         VIC2_VECTADDR = 0;
130
131         GPIO_GPIOFINTEN = 0x00;         /* Disable all GPIOF interrupts */
132         barrier ();
133
134                 /* Install prioritized interrupts, if there are any. */
135                 /* The | 0x20*/
136         for (irq = 0; irq < 16; ++irq) {
137                 (&VIC1_VAD0)[irq]
138                         = (irq < ARRAY_SIZE (irq_pri_vic1))
139                         ? (irq_pri_vic1[irq] | VA_VECTORED) : 0;
140                 (&VIC1_VECTCNTL0)[irq]
141                         = (irq < ARRAY_SIZE (irq_pri_vic1))
142                         ? (irq_pri_vic1[irq] | VIC_CNTL_ENABLE) : 0;
143                 (&VIC2_VAD0)[irq]
144                         = (irq < ARRAY_SIZE (irq_pri_vic2))
145                         ? (irq_pri_vic2[irq] | VA_VECTORED) : 0;
146                 (&VIC2_VECTCNTL0)[irq]
147                         = (irq < ARRAY_SIZE (irq_pri_vic2))
148                         ? (irq_pri_vic2[irq] | VIC_CNTL_ENABLE) : 0;
149         }
150
151         for (irq = 0; irq < NR_IRQS; ++irq) {
152                 switch (irq) {
153                 case IRQ_GPIO0INTR:
154                 case IRQ_GPIO1INTR:
155                 case IRQ_GPIO2INTR:
156                 case IRQ_GPIO3INTR:
157                 case IRQ_GPIO4INTR:
158                 case IRQ_GPIO5INTR:
159                 case IRQ_GPIO6INTR:
160                 case IRQ_GPIO7INTR:
161                         set_irq_chip (irq, irq < 32
162                                       ? &lh7a404_gpio_vic1_chip
163                                       : &lh7a404_gpio_vic2_chip);
164                         set_irq_handler (irq, handle_level_irq); /* OK default */
165                         break;
166                 default:
167                         set_irq_chip (irq, irq < 32
168                                       ? &lh7a404_vic1_chip
169                                       : &lh7a404_vic2_chip);
170                         set_irq_handler (irq, handle_level_irq);
171                 }
172                 set_irq_flags (irq, IRQF_VALID);
173         }
174
175         lh7a40x_init_board_irq ();
176 }