aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-orion/irq.c
diff options
context:
space:
mode:
authorTzachi Perelstein <tzachi@marvell.com>2007-11-15 03:57:48 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2008-01-26 10:03:48 -0500
commitf00666140cb84cd80276c9a874198874890d5733 (patch)
tree286e67e14efbde6374f57a8997af674d7ebc6d4b /arch/arm/mach-orion/irq.c
parent3085de6a82821e3d227e8fae7403dc7a5dc27932 (diff)
[ARM] Orion edge GPIO IRQ support
This patch adds support for Orion edge sensitive GPIO IRQs. Signed-off-by: Tzachi Perelstein <tzachi@marvell.com> Signed-off-by: Nicolas Pitre <nico@marvell.com> CC: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/arm/mach-orion/irq.c')
-rw-r--r--arch/arm/mach-orion/irq.c119
1 files changed, 100 insertions, 19 deletions
diff --git a/arch/arm/mach-orion/irq.c b/arch/arm/mach-orion/irq.c
index 585a0fb06262..df7e12ad378b 100644
--- a/arch/arm/mach-orion/irq.c
+++ b/arch/arm/mach-orion/irq.c
@@ -19,22 +19,66 @@
19 19
20/***************************************************************************** 20/*****************************************************************************
21 * Orion GPIO IRQ 21 * Orion GPIO IRQ
22 *
23 * GPIO_IN_POL register controlls whether GPIO_DATA_IN will hold the same
24 * value of the line or the opposite value.
25 *
26 * Level IRQ handlers: DATA_IN is used directly as cause register.
27 * Interrupt are masked by LEVEL_MASK registers.
28 * Edge IRQ handlers: Change in DATA_IN are latched in EDGE_CAUSE.
29 * Interrupt are masked by EDGE_MASK registers.
30 * Both-edge handlers: Similar to regular Edge handlers, but also swaps
31 * the polarity to catch the next line transaction.
32 * This is a race condition that might not perfectly
33 * work on some use cases.
34 *
35 * Every eight GPIO lines are grouped (OR'ed) before going up to main
36 * cause register.
37 *
38 * EDGE cause mask
39 * data-in /--------| |-----| |----\
40 * -----| |----- ---- to main cause reg
41 * X \----------------| |----/
42 * polarity LEVEL mask
43 *
22 ****************************************************************************/ 44 ****************************************************************************/
45static void orion_gpio_irq_ack(u32 irq)
46{
47 int pin = irq_to_gpio(irq);
48 if (irq_desc[irq].status & IRQ_LEVEL)
49 /*
50 * Mask bit for level interrupt
51 */
52 orion_clrbits(GPIO_LEVEL_MASK, 1 << pin);
53 else
54 /*
55 * Clear casue bit for egde interrupt
56 */
57 orion_clrbits(GPIO_EDGE_CAUSE, 1 << pin);
58}
59
23static void orion_gpio_irq_mask(u32 irq) 60static void orion_gpio_irq_mask(u32 irq)
24{ 61{
25 int pin = irq_to_gpio(irq); 62 int pin = irq_to_gpio(irq);
26 orion_clrbits(GPIO_LEVEL_MASK, 1 << pin); 63 if (irq_desc[irq].status & IRQ_LEVEL)
64 orion_clrbits(GPIO_LEVEL_MASK, 1 << pin);
65 else
66 orion_clrbits(GPIO_EDGE_MASK, 1 << pin);
27} 67}
28 68
29static void orion_gpio_irq_unmask(u32 irq) 69static void orion_gpio_irq_unmask(u32 irq)
30{ 70{
31 int pin = irq_to_gpio(irq); 71 int pin = irq_to_gpio(irq);
32 orion_setbits(GPIO_LEVEL_MASK, 1 << pin); 72 if (irq_desc[irq].status & IRQ_LEVEL)
73 orion_setbits(GPIO_LEVEL_MASK, 1 << pin);
74 else
75 orion_setbits(GPIO_EDGE_MASK, 1 << pin);
33} 76}
34 77
35static int orion_gpio_set_irq_type(u32 irq, u32 type) 78static int orion_gpio_set_irq_type(u32 irq, u32 type)
36{ 79{
37 int pin = irq_to_gpio(irq); 80 int pin = irq_to_gpio(irq);
81 struct irq_desc *desc;
38 82
39 if ((orion_read(GPIO_IO_CONF) & (1 << pin)) == 0) { 83 if ((orion_read(GPIO_IO_CONF) & (1 << pin)) == 0) {
40 printk(KERN_ERR "orion_gpio_set_irq_type failed " 84 printk(KERN_ERR "orion_gpio_set_irq_type failed "
@@ -42,24 +86,56 @@ static int orion_gpio_set_irq_type(u32 irq, u32 type)
42 return -EINVAL; 86 return -EINVAL;
43 } 87 }
44 88
89 desc = irq_desc + irq;
90
45 switch (type) { 91 switch (type) {
46 case IRQT_HIGH: 92 case IRQT_HIGH:
93 desc->handle_irq = handle_level_irq;
94 desc->status |= IRQ_LEVEL;
47 orion_clrbits(GPIO_IN_POL, (1 << pin)); 95 orion_clrbits(GPIO_IN_POL, (1 << pin));
48 break; 96 break;
49 case IRQT_LOW: 97 case IRQT_LOW:
98 desc->handle_irq = handle_level_irq;
99 desc->status |= IRQ_LEVEL;
100 orion_setbits(GPIO_IN_POL, (1 << pin));
101 break;
102 case IRQT_RISING:
103 desc->handle_irq = handle_edge_irq;
104 desc->status &= ~IRQ_LEVEL;
105 orion_clrbits(GPIO_IN_POL, (1 << pin));
106 break;
107 case IRQT_FALLING:
108 desc->handle_irq = handle_edge_irq;
109 desc->status &= ~IRQ_LEVEL;
50 orion_setbits(GPIO_IN_POL, (1 << pin)); 110 orion_setbits(GPIO_IN_POL, (1 << pin));
51 break; 111 break;
112 case IRQT_BOTHEDGE:
113 desc->handle_irq = handle_edge_irq;
114 desc->status &= ~IRQ_LEVEL;
115 /*
116 * set initial polarity based on current input level
117 */
118 if ((orion_read(GPIO_IN_POL) ^ orion_read(GPIO_DATA_IN))
119 & (1 << pin))
120 orion_setbits(GPIO_IN_POL, (1 << pin)); /* falling */
121 else
122 orion_clrbits(GPIO_IN_POL, (1 << pin)); /* rising */
123
124 break;
52 default: 125 default:
53 printk(KERN_ERR "failed to set irq=%d (type=%d)\n", irq, type); 126 printk(KERN_ERR "failed to set irq=%d (type=%d)\n", irq, type);
54 return -EINVAL; 127 return -EINVAL;
55 } 128 }
56 129
130 desc->status &= ~IRQ_TYPE_SENSE_MASK;
131 desc->status |= type & IRQ_TYPE_SENSE_MASK;
132
57 return 0; 133 return 0;
58} 134}
59 135
60static struct irq_chip orion_gpio_irq_chip = { 136static struct irq_chip orion_gpio_irq_chip = {
61 .name = "Orion-IRQ-GPIO", 137 .name = "Orion-IRQ-GPIO",
62 .ack = orion_gpio_irq_mask, 138 .ack = orion_gpio_irq_ack,
63 .mask = orion_gpio_irq_mask, 139 .mask = orion_gpio_irq_mask,
64 .unmask = orion_gpio_irq_unmask, 140 .unmask = orion_gpio_irq_unmask,
65 .set_type = orion_gpio_set_irq_type, 141 .set_type = orion_gpio_set_irq_type,
@@ -67,24 +143,24 @@ static struct irq_chip orion_gpio_irq_chip = {
67 143
68static void orion_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) 144static void orion_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
69{ 145{
70 int i; 146 u32 cause, offs, pin;
71 u32 cause, shift;
72 147
73 BUG_ON(irq < IRQ_ORION_GPIO_0_7 || irq > IRQ_ORION_GPIO_24_31); 148 BUG_ON(irq < IRQ_ORION_GPIO_0_7 || irq > IRQ_ORION_GPIO_24_31);
74 shift = (irq - IRQ_ORION_GPIO_0_7) * 8; 149 offs = (irq - IRQ_ORION_GPIO_0_7) * 8;
75 cause = orion_read(GPIO_EDGE_CAUSE) & orion_read(GPIO_LEVEL_MASK); 150 cause = (orion_read(GPIO_DATA_IN) & orion_read(GPIO_LEVEL_MASK)) |
76 cause &= (0xff << shift); 151 (orion_read(GPIO_EDGE_CAUSE) & orion_read(GPIO_EDGE_MASK));
77 152
78 for (i = shift; i < shift + 8; i++) { 153 for (pin = offs; pin < offs + 8; pin++) {
79 if (cause & (1 << i)) { 154 if (cause & (1 << pin)) {
80 int gpio_irq = i + IRQ_ORION_GPIO_START; 155 irq = gpio_to_irq(pin);
81 if (gpio_irq > 0) { 156 desc = irq_desc + irq;
82 desc = irq_desc + gpio_irq; 157 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQT_BOTHEDGE) {
83 desc_handle_irq(gpio_irq, desc); 158 /* Swap polarity (race with GPIO line) */
84 } else { 159 u32 polarity = orion_read(GPIO_IN_POL);
85 printk(KERN_ERR "orion_gpio_irq_handler error, " 160 polarity ^= 1 << pin;
86 "invalid irq %d\n", gpio_irq); 161 orion_write(GPIO_IN_POL, polarity);
87 } 162 }
163 desc_handle_irq(irq, desc);
88 } 164 }
89 } 165 }
90} 166}
@@ -92,19 +168,24 @@ static void orion_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
92static void __init orion_init_gpio_irq(void) 168static void __init orion_init_gpio_irq(void)
93{ 169{
94 int i; 170 int i;
171 struct irq_desc *desc;
95 172
96 /* 173 /*
97 * Mask and clear GPIO IRQ interrupts 174 * Mask and clear GPIO IRQ interrupts
98 */ 175 */
99 orion_write(GPIO_LEVEL_MASK, 0x0); 176 orion_write(GPIO_LEVEL_MASK, 0x0);
177 orion_write(GPIO_EDGE_MASK, 0x0);
100 orion_write(GPIO_EDGE_CAUSE, 0x0); 178 orion_write(GPIO_EDGE_CAUSE, 0x0);
101 179
102 /* 180 /*
103 * Register chained level handlers for GPIO IRQs 181 * Register chained level handlers for GPIO IRQs by default.
182 * User can use set_type() if he wants to use edge types handlers.
104 */ 183 */
105 for (i = IRQ_ORION_GPIO_START; i < NR_IRQS; i++) { 184 for (i = IRQ_ORION_GPIO_START; i < NR_IRQS; i++) {
106 set_irq_chip(i, &orion_gpio_irq_chip); 185 set_irq_chip(i, &orion_gpio_irq_chip);
107 set_irq_handler(i, handle_level_irq); 186 set_irq_handler(i, handle_level_irq);
187 desc = irq_desc + i;
188 desc->status |= IRQ_LEVEL;
108 set_irq_flags(i, IRQF_VALID); 189 set_irq_flags(i, IRQF_VALID);
109 } 190 }
110 set_irq_chained_handler(IRQ_ORION_GPIO_0_7, orion_gpio_irq_handler); 191 set_irq_chained_handler(IRQ_ORION_GPIO_0_7, orion_gpio_irq_handler);