aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-ixp4xx/common.c
diff options
context:
space:
mode:
authorDeepak Saxena <dsaxena@plexity.net>2005-08-29 17:46:30 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2005-08-29 17:46:30 -0400
commitbdf82b59c5dcf04bbdbd1938eefca14dd9cb44d3 (patch)
tree68983f484e96c737cd504ecd08e7bf669a925cec /arch/arm/mach-ixp4xx/common.c
parente605ecd7c8a38f65759c938a235a1b84f41a744e (diff)
[ARM] 2836/1: Cleanup IXP4xx GPIO code
Patch from Deepak Saxena This patch implements the set_irq_type() hooks for configuring GPIO IRQ type and updates all the platforms to use it instead of the gpio_line_config() function which is now used to configure input vs. output on the pins. Signed-off-by: Deepak Saxena <dsaxena@plexity.net> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mach-ixp4xx/common.c')
-rw-r--r--arch/arm/mach-ixp4xx/common.c155
1 files changed, 65 insertions, 90 deletions
diff --git a/arch/arm/mach-ixp4xx/common.c b/arch/arm/mach-ixp4xx/common.c
index 04490a9f8f6e..0422e906cc9a 100644
--- a/arch/arm/mach-ixp4xx/common.c
+++ b/arch/arm/mach-ixp4xx/common.c
@@ -38,90 +38,6 @@
38#include <asm/mach/irq.h> 38#include <asm/mach/irq.h>
39#include <asm/mach/time.h> 39#include <asm/mach/time.h>
40 40
41enum ixp4xx_irq_type {
42 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
43};
44static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type);
45
46/*************************************************************************
47 * GPIO acces functions
48 *************************************************************************/
49
50/*
51 * Configure GPIO line for input, interrupt, or output operation
52 *
53 * TODO: Enable/disable the irq_desc based on interrupt or output mode.
54 * TODO: Should these be named ixp4xx_gpio_?
55 */
56void gpio_line_config(u8 line, u32 style)
57{
58 static const int gpio2irq[] = {
59 6, 7, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
60 };
61 u32 enable;
62 volatile u32 *int_reg;
63 u32 int_style;
64 enum ixp4xx_irq_type irq_type;
65
66 enable = *IXP4XX_GPIO_GPOER;
67
68 if (style & IXP4XX_GPIO_OUT) {
69 enable &= ~((1) << line);
70 } else if (style & IXP4XX_GPIO_IN) {
71 enable |= ((1) << line);
72
73 switch (style & IXP4XX_GPIO_INTSTYLE_MASK)
74 {
75 case (IXP4XX_GPIO_ACTIVE_HIGH):
76 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
77 irq_type = IXP4XX_IRQ_LEVEL;
78 break;
79 case (IXP4XX_GPIO_ACTIVE_LOW):
80 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
81 irq_type = IXP4XX_IRQ_LEVEL;
82 break;
83 case (IXP4XX_GPIO_RISING_EDGE):
84 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
85 irq_type = IXP4XX_IRQ_EDGE;
86 break;
87 case (IXP4XX_GPIO_FALLING_EDGE):
88 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
89 irq_type = IXP4XX_IRQ_EDGE;
90 break;
91 case (IXP4XX_GPIO_TRANSITIONAL):
92 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
93 irq_type = IXP4XX_IRQ_EDGE;
94 break;
95 default:
96 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
97 irq_type = IXP4XX_IRQ_LEVEL;
98 break;
99 }
100
101 if (style & IXP4XX_GPIO_INTSTYLE_MASK)
102 ixp4xx_config_irq(gpio2irq[line], irq_type);
103
104 if (line >= 8) { /* pins 8-15 */
105 line -= 8;
106 int_reg = IXP4XX_GPIO_GPIT2R;
107 }
108 else { /* pins 0-7 */
109 int_reg = IXP4XX_GPIO_GPIT1R;
110 }
111
112 /* Clear the style for the appropriate pin */
113 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
114 (line * IXP4XX_GPIO_STYLE_SIZE));
115
116 /* Set the new style */
117 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
118 }
119
120 *IXP4XX_GPIO_GPOER = enable;
121}
122
123EXPORT_SYMBOL(gpio_line_config);
124
125/************************************************************************* 41/*************************************************************************
126 * IXP4xx chipset I/O mapping 42 * IXP4xx chipset I/O mapping
127 *************************************************************************/ 43 *************************************************************************/
@@ -165,6 +81,69 @@ void __init ixp4xx_map_io(void)
165 * (be it PCI or something else) configures that GPIO line 81 * (be it PCI or something else) configures that GPIO line
166 * as an IRQ. 82 * as an IRQ.
167 **************************************************************************/ 83 **************************************************************************/
84enum ixp4xx_irq_type {
85 IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
86};
87
88static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type);
89
90/*
91 * IRQ -> GPIO mapping table
92 */
93static int irq2gpio[32] = {
94 -1, -1, -1, -1, -1, -1, 0, 1,
95 -1, -1, -1, -1, -1, -1, -1, -1,
96 -1, -1, -1, 2, 3, 4, 5, 6,
97 7, 8, 9, 10, 11, 12, -1, -1,
98};
99
100static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
101{
102 int line = irq2gpio[irq];
103 u32 int_style;
104 enum ixp4xx_irq_type irq_type;
105 volatile u32 *int_reg;
106
107 /*
108 * Only for GPIO IRQs
109 */
110 if (line < 0)
111 return -EINVAL;
112
113 if (type & IRQT_BOTHEDGE) {
114 int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
115 irq_type = IXP4XX_IRQ_EDGE;
116 } else if (type & IRQT_RISING) {
117 int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
118 irq_type = IXP4XX_IRQ_EDGE;
119 } else if (type & IRQT_FALLING) {
120 int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
121 irq_type = IXP4XX_IRQ_EDGE;
122 } else if (type & IRQT_HIGH) {
123 int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
124 irq_type = IXP4XX_IRQ_LEVEL;
125 } else if (type & IRQT_LOW) {
126 int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
127 irq_type = IXP4XX_IRQ_LEVEL;
128 }
129
130 ixp4xx_config_irq(irq, irq_type);
131
132 if (line >= 8) { /* pins 8-15 */
133 line -= 8;
134 int_reg = IXP4XX_GPIO_GPIT2R;
135 } else { /* pins 0-7 */
136 int_reg = IXP4XX_GPIO_GPIT1R;
137 }
138
139 /* Clear the style for the appropriate pin */
140 *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
141 (line * IXP4XX_GPIO_STYLE_SIZE));
142
143 /* Set the new style */
144 *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
145}
146
168static void ixp4xx_irq_mask(unsigned int irq) 147static void ixp4xx_irq_mask(unsigned int irq)
169{ 148{
170 if (cpu_is_ixp46x() && irq >= 32) 149 if (cpu_is_ixp46x() && irq >= 32)
@@ -183,12 +162,6 @@ static void ixp4xx_irq_unmask(unsigned int irq)
183 162
184static void ixp4xx_irq_ack(unsigned int irq) 163static void ixp4xx_irq_ack(unsigned int irq)
185{ 164{
186 static int irq2gpio[32] = {
187 -1, -1, -1, -1, -1, -1, 0, 1,
188 -1, -1, -1, -1, -1, -1, -1, -1,
189 -1, -1, -1, 2, 3, 4, 5, 6,
190 7, 8, 9, 10, 11, 12, -1, -1,
191 };
192 int line = (irq < 32) ? irq2gpio[irq] : -1; 165 int line = (irq < 32) ? irq2gpio[irq] : -1;
193 166
194 if (line >= 0) 167 if (line >= 0)
@@ -209,12 +182,14 @@ static struct irqchip ixp4xx_irq_level_chip = {
209 .ack = ixp4xx_irq_mask, 182 .ack = ixp4xx_irq_mask,
210 .mask = ixp4xx_irq_mask, 183 .mask = ixp4xx_irq_mask,
211 .unmask = ixp4xx_irq_level_unmask, 184 .unmask = ixp4xx_irq_level_unmask,
185 .type = ixp4xx_set_irq_type
212}; 186};
213 187
214static struct irqchip ixp4xx_irq_edge_chip = { 188static struct irqchip ixp4xx_irq_edge_chip = {
215 .ack = ixp4xx_irq_ack, 189 .ack = ixp4xx_irq_ack,
216 .mask = ixp4xx_irq_mask, 190 .mask = ixp4xx_irq_mask,
217 .unmask = ixp4xx_irq_unmask, 191 .unmask = ixp4xx_irq_unmask,
192 .type = ixp4xx_set_irq_type
218}; 193};
219 194
220static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type) 195static void ixp4xx_config_irq(unsigned irq, enum ixp4xx_irq_type type)