diff options
-rw-r--r-- | arch/arm/mach-pxa/gpio.c | 346 | ||||
-rw-r--r-- | arch/arm/mach-pxa/include/mach/gpio.h | 1 | ||||
-rw-r--r-- | arch/arm/mach-pxa/mfp-pxa2xx.c | 2 |
3 files changed, 179 insertions, 170 deletions
diff --git a/arch/arm/mach-pxa/gpio.c b/arch/arm/mach-pxa/gpio.c index 41935590e990..7c2267036bf1 100644 --- a/arch/arm/mach-pxa/gpio.c +++ b/arch/arm/mach-pxa/gpio.c | |||
@@ -13,19 +13,34 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/module.h> | ||
17 | #include <linux/irq.h> | 16 | #include <linux/irq.h> |
18 | #include <linux/sysdev.h> | ||
19 | #include <linux/io.h> | 17 | #include <linux/io.h> |
18 | #include <linux/sysdev.h> | ||
19 | #include <linux/bootmem.h> | ||
20 | 20 | ||
21 | #include <mach/gpio.h> | 21 | #include <mach/gpio.h> |
22 | 22 | ||
23 | int pxa_last_gpio; | 23 | int pxa_last_gpio; |
24 | 24 | ||
25 | #define GPIO0_BASE (GPIO_REGS_VIRT + 0x0000) | 25 | /* |
26 | #define GPIO1_BASE (GPIO_REGS_VIRT + 0x0004) | 26 | * We handle the GPIOs by banks, each bank covers up to 32 GPIOs with |
27 | #define GPIO2_BASE (GPIO_REGS_VIRT + 0x0008) | 27 | * one set of registers. The register offsets are organized below: |
28 | #define GPIO3_BASE (GPIO_REGS_VIRT + 0x0100) | 28 | * |
29 | * GPLR GPDR GPSR GPCR GRER GFER GEDR | ||
30 | * BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x0048 | ||
31 | * BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C | ||
32 | * BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x0050 | ||
33 | * | ||
34 | * BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x0148 | ||
35 | * BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C | ||
36 | * BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150 | ||
37 | * | ||
38 | * NOTE: | ||
39 | * BANK 3 is only available on PXA27x and later processors. | ||
40 | * BANK 4 and 5 are only available on PXA935 | ||
41 | */ | ||
42 | |||
43 | #define GPIO_BANK(n) (GPIO_REGS_VIRT + BANK_OFF(n)) | ||
29 | 44 | ||
30 | #define GPLR_OFFSET 0x00 | 45 | #define GPLR_OFFSET 0x00 |
31 | #define GPDR_OFFSET 0x0C | 46 | #define GPDR_OFFSET 0x0C |
@@ -37,144 +52,138 @@ int pxa_last_gpio; | |||
37 | 52 | ||
38 | struct pxa_gpio_chip { | 53 | struct pxa_gpio_chip { |
39 | struct gpio_chip chip; | 54 | struct gpio_chip chip; |
40 | void __iomem *regbase; | 55 | void __iomem *regbase; |
56 | char label[10]; | ||
57 | |||
58 | unsigned long irq_mask; | ||
59 | unsigned long irq_edge_rise; | ||
60 | unsigned long irq_edge_fall; | ||
61 | |||
62 | #ifdef CONFIG_PM | ||
63 | unsigned long saved_gplr; | ||
64 | unsigned long saved_gpdr; | ||
65 | unsigned long saved_grer; | ||
66 | unsigned long saved_gfer; | ||
67 | #endif | ||
41 | }; | 68 | }; |
42 | 69 | ||
70 | static DEFINE_SPINLOCK(gpio_lock); | ||
71 | static struct pxa_gpio_chip *pxa_gpio_chips; | ||
72 | |||
73 | #define for_each_gpio_chip(i, c) \ | ||
74 | for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) | ||
75 | |||
76 | static inline void __iomem *gpio_chip_base(struct gpio_chip *c) | ||
77 | { | ||
78 | return container_of(c, struct pxa_gpio_chip, chip)->regbase; | ||
79 | } | ||
80 | |||
81 | static inline struct pxa_gpio_chip *gpio_to_chip(unsigned gpio) | ||
82 | { | ||
83 | return &pxa_gpio_chips[gpio_to_bank(gpio)]; | ||
84 | } | ||
85 | |||
43 | static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) | 86 | static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) |
44 | { | 87 | { |
45 | unsigned long flags; | 88 | void __iomem *base = gpio_chip_base(chip); |
46 | u32 mask = 1 << offset; | 89 | uint32_t value, mask = 1 << offset; |
47 | u32 value; | 90 | unsigned long flags; |
48 | struct pxa_gpio_chip *pxa; | 91 | |
49 | void __iomem *gpdr; | 92 | spin_lock_irqsave(&gpio_lock, flags); |
50 | 93 | ||
51 | pxa = container_of(chip, struct pxa_gpio_chip, chip); | 94 | value = __raw_readl(base + GPDR_OFFSET); |
52 | gpdr = pxa->regbase + GPDR_OFFSET; | ||
53 | local_irq_save(flags); | ||
54 | value = __raw_readl(gpdr); | ||
55 | if (__gpio_is_inverted(chip->base + offset)) | 95 | if (__gpio_is_inverted(chip->base + offset)) |
56 | value |= mask; | 96 | value |= mask; |
57 | else | 97 | else |
58 | value &= ~mask; | 98 | value &= ~mask; |
59 | __raw_writel(value, gpdr); | 99 | __raw_writel(value, base + GPDR_OFFSET); |
60 | local_irq_restore(flags); | ||
61 | 100 | ||
101 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
62 | return 0; | 102 | return 0; |
63 | } | 103 | } |
64 | 104 | ||
65 | static int pxa_gpio_direction_output(struct gpio_chip *chip, | 105 | static int pxa_gpio_direction_output(struct gpio_chip *chip, |
66 | unsigned offset, int value) | 106 | unsigned offset, int value) |
67 | { | 107 | { |
68 | unsigned long flags; | 108 | void __iomem *base = gpio_chip_base(chip); |
69 | u32 mask = 1 << offset; | 109 | uint32_t tmp, mask = 1 << offset; |
70 | u32 tmp; | 110 | unsigned long flags; |
71 | struct pxa_gpio_chip *pxa; | 111 | |
72 | void __iomem *gpdr; | 112 | __raw_writel(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); |
73 | 113 | ||
74 | pxa = container_of(chip, struct pxa_gpio_chip, chip); | 114 | spin_lock_irqsave(&gpio_lock, flags); |
75 | __raw_writel(mask, | 115 | |
76 | pxa->regbase + (value ? GPSR_OFFSET : GPCR_OFFSET)); | 116 | tmp = __raw_readl(base + GPDR_OFFSET); |
77 | gpdr = pxa->regbase + GPDR_OFFSET; | ||
78 | local_irq_save(flags); | ||
79 | tmp = __raw_readl(gpdr); | ||
80 | if (__gpio_is_inverted(chip->base + offset)) | 117 | if (__gpio_is_inverted(chip->base + offset)) |
81 | tmp &= ~mask; | 118 | tmp &= ~mask; |
82 | else | 119 | else |
83 | tmp |= mask; | 120 | tmp |= mask; |
84 | __raw_writel(tmp, gpdr); | 121 | __raw_writel(tmp, base + GPDR_OFFSET); |
85 | local_irq_restore(flags); | ||
86 | 122 | ||
123 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
87 | return 0; | 124 | return 0; |
88 | } | 125 | } |
89 | 126 | ||
90 | /* | ||
91 | * Return GPIO level | ||
92 | */ | ||
93 | static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) | 127 | static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) |
94 | { | 128 | { |
95 | u32 mask = 1 << offset; | 129 | return __raw_readl(gpio_chip_base(chip) + GPLR_OFFSET) & (1 << offset); |
96 | struct pxa_gpio_chip *pxa; | ||
97 | |||
98 | pxa = container_of(chip, struct pxa_gpio_chip, chip); | ||
99 | return __raw_readl(pxa->regbase + GPLR_OFFSET) & mask; | ||
100 | } | 130 | } |
101 | 131 | ||
102 | /* | ||
103 | * Set output GPIO level | ||
104 | */ | ||
105 | static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 132 | static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
106 | { | 133 | { |
107 | u32 mask = 1 << offset; | 134 | __raw_writel(1 << offset, gpio_chip_base(chip) + |
108 | struct pxa_gpio_chip *pxa; | 135 | (value ? GPSR_OFFSET : GPCR_OFFSET)); |
109 | |||
110 | pxa = container_of(chip, struct pxa_gpio_chip, chip); | ||
111 | |||
112 | if (value) | ||
113 | __raw_writel(mask, pxa->regbase + GPSR_OFFSET); | ||
114 | else | ||
115 | __raw_writel(mask, pxa->regbase + GPCR_OFFSET); | ||
116 | } | 136 | } |
117 | 137 | ||
118 | #define GPIO_CHIP(_n) \ | 138 | static int __init pxa_init_gpio_chip(int gpio_end) |
119 | [_n] = { \ | ||
120 | .regbase = GPIO##_n##_BASE, \ | ||
121 | .chip = { \ | ||
122 | .label = "gpio-" #_n, \ | ||
123 | .direction_input = pxa_gpio_direction_input, \ | ||
124 | .direction_output = pxa_gpio_direction_output, \ | ||
125 | .get = pxa_gpio_get, \ | ||
126 | .set = pxa_gpio_set, \ | ||
127 | .base = (_n) * 32, \ | ||
128 | .ngpio = 32, \ | ||
129 | }, \ | ||
130 | } | ||
131 | |||
132 | static struct pxa_gpio_chip pxa_gpio_chip[] = { | ||
133 | GPIO_CHIP(0), | ||
134 | GPIO_CHIP(1), | ||
135 | GPIO_CHIP(2), | ||
136 | #if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx) | ||
137 | GPIO_CHIP(3), | ||
138 | #endif | ||
139 | }; | ||
140 | |||
141 | static void __init pxa_init_gpio_chip(int gpio_nr) | ||
142 | { | 139 | { |
143 | int i, gpio; | 140 | int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; |
141 | struct pxa_gpio_chip *chips; | ||
144 | 142 | ||
145 | /* add a GPIO chip for each register bank. | 143 | /* this is early, we have to use bootmem allocator, and we really |
146 | * the last PXA25x register only contains 21 GPIOs | 144 | * want this to be allocated dynamically for different 'gpio_end' |
147 | */ | 145 | */ |
148 | for (gpio = 0, i = 0; gpio < gpio_nr; gpio += 32, i++) { | 146 | chips = alloc_bootmem_low(nbanks * sizeof(struct pxa_gpio_chip)); |
149 | if (gpio + 32 > gpio_nr) | 147 | if (chips == NULL) { |
150 | pxa_gpio_chip[i].chip.ngpio = gpio_nr - gpio; | 148 | pr_err("%s: failed to allocate GPIO chips\n", __func__); |
151 | gpiochip_add(&pxa_gpio_chip[i].chip); | 149 | return -ENOMEM; |
152 | } | 150 | } |
153 | } | ||
154 | 151 | ||
155 | /* | 152 | for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { |
156 | * PXA GPIO edge detection for IRQs: | 153 | struct gpio_chip *c = &chips[i].chip; |
157 | * IRQs are generated on Falling-Edge, Rising-Edge, or both. | ||
158 | * Use this instead of directly setting GRER/GFER. | ||
159 | */ | ||
160 | 154 | ||
161 | static unsigned long GPIO_IRQ_rising_edge[4]; | 155 | sprintf(chips[i].label, "gpio-%d", i); |
162 | static unsigned long GPIO_IRQ_falling_edge[4]; | 156 | chips[i].regbase = (void __iomem *)GPIO_BANK(i); |
163 | static unsigned long GPIO_IRQ_mask[4]; | 157 | |
158 | c->base = gpio; | ||
159 | c->label = chips[i].label; | ||
160 | |||
161 | c->direction_input = pxa_gpio_direction_input; | ||
162 | c->direction_output = pxa_gpio_direction_output; | ||
163 | c->get = pxa_gpio_get; | ||
164 | c->set = pxa_gpio_set; | ||
165 | |||
166 | /* number of GPIOs on last bank may be less than 32 */ | ||
167 | c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; | ||
168 | gpiochip_add(c); | ||
169 | } | ||
170 | pxa_gpio_chips = chips; | ||
171 | return 0; | ||
172 | } | ||
164 | 173 | ||
165 | static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) | 174 | static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) |
166 | { | 175 | { |
167 | int gpio, idx; | 176 | struct pxa_gpio_chip *c; |
177 | int gpio = irq_to_gpio(irq); | ||
178 | unsigned long gpdr, mask = GPIO_bit(gpio); | ||
168 | 179 | ||
169 | gpio = IRQ_TO_GPIO(irq); | 180 | c = gpio_to_chip(gpio); |
170 | idx = gpio >> 5; | ||
171 | 181 | ||
172 | if (type == IRQ_TYPE_PROBE) { | 182 | if (type == IRQ_TYPE_PROBE) { |
173 | /* Don't mess with enabled GPIOs using preconfigured edges or | 183 | /* Don't mess with enabled GPIOs using preconfigured edges or |
174 | * GPIOs set to alternate function or to output during probe | 184 | * GPIOs set to alternate function or to output during probe |
175 | */ | 185 | */ |
176 | if ((GPIO_IRQ_rising_edge[idx] & GPIO_bit(gpio)) || | 186 | if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio)) |
177 | (GPIO_IRQ_falling_edge[idx] & GPIO_bit(gpio))) | ||
178 | return 0; | 187 | return 0; |
179 | 188 | ||
180 | if (__gpio_is_occupied(gpio)) | 189 | if (__gpio_is_occupied(gpio)) |
@@ -183,23 +192,25 @@ static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) | |||
183 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; | 192 | type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; |
184 | } | 193 | } |
185 | 194 | ||
195 | gpdr = __raw_readl(c->regbase + GPDR_OFFSET); | ||
196 | |||
186 | if (__gpio_is_inverted(gpio)) | 197 | if (__gpio_is_inverted(gpio)) |
187 | GPDR(gpio) |= GPIO_bit(gpio); | 198 | __raw_writel(gpdr | mask, c->regbase + GPDR_OFFSET); |
188 | else | 199 | else |
189 | GPDR(gpio) &= ~GPIO_bit(gpio); | 200 | __raw_writel(gpdr & ~mask, c->regbase + GPDR_OFFSET); |
190 | 201 | ||
191 | if (type & IRQ_TYPE_EDGE_RISING) | 202 | if (type & IRQ_TYPE_EDGE_RISING) |
192 | __set_bit(gpio, GPIO_IRQ_rising_edge); | 203 | c->irq_edge_rise |= mask; |
193 | else | 204 | else |
194 | __clear_bit(gpio, GPIO_IRQ_rising_edge); | 205 | c->irq_edge_rise &= ~mask; |
195 | 206 | ||
196 | if (type & IRQ_TYPE_EDGE_FALLING) | 207 | if (type & IRQ_TYPE_EDGE_FALLING) |
197 | __set_bit(gpio, GPIO_IRQ_falling_edge); | 208 | c->irq_edge_fall |= mask; |
198 | else | 209 | else |
199 | __clear_bit(gpio, GPIO_IRQ_falling_edge); | 210 | c->irq_edge_fall &= ~mask; |
200 | 211 | ||
201 | GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx]; | 212 | __raw_writel(c->irq_edge_rise & c->irq_mask, c->regbase + GRER_OFFSET); |
202 | GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx]; | 213 | __raw_writel(c->irq_edge_fall & c->irq_mask, c->regbase + GFER_OFFSET); |
203 | 214 | ||
204 | pr_debug("%s: IRQ%d (GPIO%d) - edge%s%s\n", __func__, irq, gpio, | 215 | pr_debug("%s: IRQ%d (GPIO%d) - edge%s%s\n", __func__, irq, gpio, |
205 | ((type & IRQ_TYPE_EDGE_RISING) ? " rising" : ""), | 216 | ((type & IRQ_TYPE_EDGE_RISING) ? " rising" : ""), |
@@ -207,60 +218,62 @@ static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) | |||
207 | return 0; | 218 | return 0; |
208 | } | 219 | } |
209 | 220 | ||
210 | /* | ||
211 | * Demux handler for GPIO>=2 edge detect interrupts | ||
212 | */ | ||
213 | |||
214 | #define GEDR_BITS (sizeof(gedr) * BITS_PER_BYTE) | ||
215 | |||
216 | static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) | 221 | static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) |
217 | { | 222 | { |
218 | int loop, bit, n; | 223 | struct pxa_gpio_chip *c; |
219 | unsigned long gedr[4]; | 224 | int loop, gpio, gpio_base, n; |
225 | unsigned long gedr; | ||
220 | 226 | ||
221 | do { | 227 | do { |
222 | gedr[0] = GEDR0 & GPIO_IRQ_mask[0] & ~3; | ||
223 | gedr[1] = GEDR1 & GPIO_IRQ_mask[1]; | ||
224 | gedr[2] = GEDR2 & GPIO_IRQ_mask[2]; | ||
225 | gedr[3] = GEDR3 & GPIO_IRQ_mask[3]; | ||
226 | |||
227 | GEDR0 = gedr[0]; GEDR1 = gedr[1]; | ||
228 | GEDR2 = gedr[2]; GEDR3 = gedr[3]; | ||
229 | |||
230 | loop = 0; | 228 | loop = 0; |
231 | bit = find_first_bit(gedr, GEDR_BITS); | 229 | for_each_gpio_chip(gpio, c) { |
232 | while (bit < GEDR_BITS) { | 230 | gpio_base = c->chip.base; |
233 | loop = 1; | 231 | |
232 | gedr = __raw_readl(c->regbase + GEDR_OFFSET); | ||
233 | gedr = gedr & c->irq_mask; | ||
234 | __raw_writel(gedr, c->regbase + GEDR_OFFSET); | ||
234 | 235 | ||
235 | n = PXA_GPIO_IRQ_BASE + bit; | 236 | n = find_first_bit(&gedr, BITS_PER_LONG); |
236 | generic_handle_irq(n); | 237 | while (n < BITS_PER_LONG) { |
238 | loop = 1; | ||
237 | 239 | ||
238 | bit = find_next_bit(gedr, GEDR_BITS, bit + 1); | 240 | generic_handle_irq(gpio_to_irq(gpio_base + n)); |
241 | n = find_next_bit(&gedr, BITS_PER_LONG, n + 1); | ||
242 | } | ||
239 | } | 243 | } |
240 | } while (loop); | 244 | } while (loop); |
241 | } | 245 | } |
242 | 246 | ||
243 | static void pxa_ack_muxed_gpio(unsigned int irq) | 247 | static void pxa_ack_muxed_gpio(unsigned int irq) |
244 | { | 248 | { |
245 | int gpio = irq - IRQ_GPIO(2) + 2; | 249 | int gpio = irq_to_gpio(irq); |
246 | GEDR(gpio) = GPIO_bit(gpio); | 250 | struct pxa_gpio_chip *c = gpio_to_chip(gpio); |
251 | |||
252 | __raw_writel(GPIO_bit(gpio), c->regbase + GEDR_OFFSET); | ||
247 | } | 253 | } |
248 | 254 | ||
249 | static void pxa_mask_muxed_gpio(unsigned int irq) | 255 | static void pxa_mask_muxed_gpio(unsigned int irq) |
250 | { | 256 | { |
251 | int gpio = irq - IRQ_GPIO(2) + 2; | 257 | int gpio = irq_to_gpio(irq); |
252 | __clear_bit(gpio, GPIO_IRQ_mask); | 258 | struct pxa_gpio_chip *c = gpio_to_chip(gpio); |
253 | GRER(gpio) &= ~GPIO_bit(gpio); | 259 | uint32_t grer, gfer; |
254 | GFER(gpio) &= ~GPIO_bit(gpio); | 260 | |
261 | c->irq_mask &= ~GPIO_bit(gpio); | ||
262 | |||
263 | grer = __raw_readl(c->regbase + GRER_OFFSET) & ~GPIO_bit(gpio); | ||
264 | gfer = __raw_readl(c->regbase + GFER_OFFSET) & ~GPIO_bit(gpio); | ||
265 | __raw_writel(grer, c->regbase + GRER_OFFSET); | ||
266 | __raw_writel(gfer, c->regbase + GFER_OFFSET); | ||
255 | } | 267 | } |
256 | 268 | ||
257 | static void pxa_unmask_muxed_gpio(unsigned int irq) | 269 | static void pxa_unmask_muxed_gpio(unsigned int irq) |
258 | { | 270 | { |
259 | int gpio = irq - IRQ_GPIO(2) + 2; | 271 | int gpio = irq_to_gpio(irq); |
260 | int idx = gpio >> 5; | 272 | struct pxa_gpio_chip *c = gpio_to_chip(gpio); |
261 | __set_bit(gpio, GPIO_IRQ_mask); | 273 | |
262 | GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx]; | 274 | c->irq_mask |= GPIO_bit(gpio); |
263 | GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx]; | 275 | __raw_writel(c->irq_edge_rise & c->irq_mask, c->regbase + GRER_OFFSET); |
276 | __raw_writel(c->irq_edge_fall & c->irq_mask, c->regbase + GFER_OFFSET); | ||
264 | } | 277 | } |
265 | 278 | ||
266 | static struct irq_chip pxa_muxed_gpio_chip = { | 279 | static struct irq_chip pxa_muxed_gpio_chip = { |
@@ -273,15 +286,19 @@ static struct irq_chip pxa_muxed_gpio_chip = { | |||
273 | 286 | ||
274 | void __init pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn) | 287 | void __init pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn) |
275 | { | 288 | { |
276 | int irq, i; | 289 | struct pxa_gpio_chip *c; |
290 | int gpio, irq; | ||
277 | 291 | ||
278 | pxa_last_gpio = end; | 292 | pxa_last_gpio = end; |
279 | 293 | ||
294 | /* Initialize GPIO chips */ | ||
295 | pxa_init_gpio_chip(end); | ||
296 | |||
280 | /* clear all GPIO edge detects */ | 297 | /* clear all GPIO edge detects */ |
281 | for (i = start; i <= end; i += 32) { | 298 | for_each_gpio_chip(gpio, c) { |
282 | GFER(i) &= ~GPIO_IRQ_mask[i]; | 299 | __raw_writel(0, c->regbase + GFER_OFFSET); |
283 | GRER(i) &= ~GPIO_IRQ_mask[i]; | 300 | __raw_writel(0, c->regbase + GRER_OFFSET); |
284 | GEDR(i) = GPIO_IRQ_mask[i]; | 301 | __raw_writel(~0,c->regbase + GEDR_OFFSET); |
285 | } | 302 | } |
286 | 303 | ||
287 | for (irq = gpio_to_irq(start); irq <= gpio_to_irq(end); irq++) { | 304 | for (irq = gpio_to_irq(start); irq <= gpio_to_irq(end); irq++) { |
@@ -293,46 +310,39 @@ void __init pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn) | |||
293 | /* Install handler for GPIO>=2 edge detect interrupts */ | 310 | /* Install handler for GPIO>=2 edge detect interrupts */ |
294 | set_irq_chained_handler(mux_irq, pxa_gpio_demux_handler); | 311 | set_irq_chained_handler(mux_irq, pxa_gpio_demux_handler); |
295 | pxa_muxed_gpio_chip.set_wake = fn; | 312 | pxa_muxed_gpio_chip.set_wake = fn; |
296 | |||
297 | /* Initialize GPIO chips */ | ||
298 | pxa_init_gpio_chip(end + 1); | ||
299 | } | 313 | } |
300 | 314 | ||
301 | #ifdef CONFIG_PM | 315 | #ifdef CONFIG_PM |
302 | |||
303 | static unsigned long saved_gplr[4]; | ||
304 | static unsigned long saved_gpdr[4]; | ||
305 | static unsigned long saved_grer[4]; | ||
306 | static unsigned long saved_gfer[4]; | ||
307 | |||
308 | static int pxa_gpio_suspend(struct sys_device *dev, pm_message_t state) | 316 | static int pxa_gpio_suspend(struct sys_device *dev, pm_message_t state) |
309 | { | 317 | { |
310 | int i, gpio; | 318 | struct pxa_gpio_chip *c; |
319 | int gpio; | ||
311 | 320 | ||
312 | for (gpio = 0, i = 0; gpio < pxa_last_gpio; gpio += 32, i++) { | 321 | for_each_gpio_chip(gpio, c) { |
313 | saved_gplr[i] = GPLR(gpio); | 322 | c->saved_gplr = __raw_readl(c->regbase + GPLR_OFFSET); |
314 | saved_gpdr[i] = GPDR(gpio); | 323 | c->saved_gpdr = __raw_readl(c->regbase + GPDR_OFFSET); |
315 | saved_grer[i] = GRER(gpio); | 324 | c->saved_grer = __raw_readl(c->regbase + GRER_OFFSET); |
316 | saved_gfer[i] = GFER(gpio); | 325 | c->saved_gfer = __raw_readl(c->regbase + GFER_OFFSET); |
317 | 326 | ||
318 | /* Clear GPIO transition detect bits */ | 327 | /* Clear GPIO transition detect bits */ |
319 | GEDR(gpio) = GEDR(gpio); | 328 | __raw_writel(0xffffffff, c->regbase + GEDR_OFFSET); |
320 | } | 329 | } |
321 | return 0; | 330 | return 0; |
322 | } | 331 | } |
323 | 332 | ||
324 | static int pxa_gpio_resume(struct sys_device *dev) | 333 | static int pxa_gpio_resume(struct sys_device *dev) |
325 | { | 334 | { |
326 | int i, gpio; | 335 | struct pxa_gpio_chip *c; |
336 | int gpio; | ||
327 | 337 | ||
328 | for (gpio = 0, i = 0; gpio < pxa_last_gpio; gpio += 32, i++) { | 338 | for_each_gpio_chip(gpio, c) { |
329 | /* restore level with set/clear */ | 339 | /* restore level with set/clear */ |
330 | GPSR(gpio) = saved_gplr[i]; | 340 | __raw_writel( c->saved_gplr, c->regbase + GPSR_OFFSET); |
331 | GPCR(gpio) = ~saved_gplr[i]; | 341 | __raw_writel(~c->saved_gplr, c->regbase + GPCR_OFFSET); |
332 | 342 | ||
333 | GRER(gpio) = saved_grer[i]; | 343 | __raw_writel(c->saved_grer, c->regbase + GRER_OFFSET); |
334 | GFER(gpio) = saved_gfer[i]; | 344 | __raw_writel(c->saved_gfer, c->regbase + GFER_OFFSET); |
335 | GPDR(gpio) = saved_gpdr[i]; | 345 | __raw_writel(c->saved_gpdr, c->regbase + GPDR_OFFSET); |
336 | } | 346 | } |
337 | return 0; | 347 | return 0; |
338 | } | 348 | } |
diff --git a/arch/arm/mach-pxa/include/mach/gpio.h b/arch/arm/mach-pxa/include/mach/gpio.h index 4049b234eda3..406fa102cb40 100644 --- a/arch/arm/mach-pxa/include/mach/gpio.h +++ b/arch/arm/mach-pxa/include/mach/gpio.h | |||
@@ -128,6 +128,7 @@ static inline void gpio_set_value(unsigned gpio, int value) | |||
128 | } | 128 | } |
129 | 129 | ||
130 | #define gpio_cansleep __gpio_cansleep | 130 | #define gpio_cansleep __gpio_cansleep |
131 | #define gpio_to_bank(gpio) ((gpio) >> 5) | ||
131 | #define gpio_to_irq(gpio) IRQ_GPIO(gpio) | 132 | #define gpio_to_irq(gpio) IRQ_GPIO(gpio) |
132 | #define irq_to_gpio(irq) IRQ_TO_GPIO(irq) | 133 | #define irq_to_gpio(irq) IRQ_TO_GPIO(irq) |
133 | 134 | ||
diff --git a/arch/arm/mach-pxa/mfp-pxa2xx.c b/arch/arm/mach-pxa/mfp-pxa2xx.c index 9d23b731d39b..7ffb91d64c39 100644 --- a/arch/arm/mach-pxa/mfp-pxa2xx.c +++ b/arch/arm/mach-pxa/mfp-pxa2xx.c | |||
@@ -24,8 +24,6 @@ | |||
24 | 24 | ||
25 | #include "generic.h" | 25 | #include "generic.h" |
26 | 26 | ||
27 | #define gpio_to_bank(gpio) ((gpio) >> 5) | ||
28 | |||
29 | #define PGSR(x) __REG2(0x40F00020, (x) << 2) | 27 | #define PGSR(x) __REG2(0x40F00020, (x) << 2) |
30 | #define __GAFR(u, x) __REG2((u) ? 0x40E00058 : 0x40E00054, (x) << 3) | 28 | #define __GAFR(u, x) __REG2((u) ? 0x40E00058 : 0x40E00054, (x) << 3) |
31 | #define GAFR_L(x) __GAFR(0, x) | 29 | #define GAFR_L(x) __GAFR(0, x) |