aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-pxa/gpio.c
diff options
context:
space:
mode:
authorEric Miao <eric.miao@marvell.com>2009-01-07 05:01:51 -0500
committerEric Miao <eric.miao@marvell.com>2009-03-09 09:22:38 -0400
commit0807da5938b2d64fef7f1109fb4014de6392cbf7 (patch)
tree0f7f39e83fc5c93b240419025b68edf32dcb78fa /arch/arm/mach-pxa/gpio.c
parent3b8e285c21d12082a85a142ef73a1648d41cae46 (diff)
[ARM] pxa: access GPIO registers by chip so to make it further generic
Let's handle GPIOs by banks, each bank covers up to 32 GPIOs with one set of registers, and each set of registers start from different offsets. GPLR GPDR GPSR GPCR GRER GFER GEDR BANK 0 - 0x0000 0x000C 0x0018 0x0024 0x0030 0x003C 0x0048 BANK 1 - 0x0004 0x0010 0x001C 0x0028 0x0034 0x0040 0x004C BANK 2 - 0x0008 0x0014 0x0020 0x002C 0x0038 0x0044 0x0050 BANK 3 - 0x0100 0x010C 0x0118 0x0124 0x0130 0x013C 0x0148 BANK 4 - 0x0104 0x0110 0x011C 0x0128 0x0134 0x0140 0x014C BANK 5 - 0x0108 0x0114 0x0120 0x012C 0x0138 0x0144 0x0150 NOTE: BANK 3 is only available on PXA27x and later processors. BANK 4 and 5 are only available on PXA935 1. introduce GPIO_BANK(n) for the offset base of each bank 2. 'struct pxa_gpio_chip' is expanded to include IRQ edge and mask setings, and saved register values as well, and is dynamically allocated due to possible bank number ranging from 3 to 6 3. all accesses to GPIO registers are made through 'regbase' within 'pxa_gpio_chip', and register offset 4. introduce several inline functions to simplify the code a bit 5. change IRQ demux handler to base on gpio chips Signed-off-by: Mike Rapoport <mike@compulab.co.il> Signed-off-by: Eric Miao <eric.miao@marvell.com>
Diffstat (limited to 'arch/arm/mach-pxa/gpio.c')
-rw-r--r--arch/arm/mach-pxa/gpio.c346
1 files changed, 178 insertions, 168 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
23int pxa_last_gpio; 23int 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
38struct pxa_gpio_chip { 53struct 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
70static DEFINE_SPINLOCK(gpio_lock);
71static 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
76static inline void __iomem *gpio_chip_base(struct gpio_chip *c)
77{
78 return container_of(c, struct pxa_gpio_chip, chip)->regbase;
79}
80
81static inline struct pxa_gpio_chip *gpio_to_chip(unsigned gpio)
82{
83 return &pxa_gpio_chips[gpio_to_bank(gpio)];
84}
85
43static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 86static 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
65static int pxa_gpio_direction_output(struct gpio_chip *chip, 105static 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 */
93static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) 127static 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 */
105static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 132static 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) \ 138static 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
132static 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
141static 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
161static unsigned long GPIO_IRQ_rising_edge[4]; 155 sprintf(chips[i].label, "gpio-%d", i);
162static unsigned long GPIO_IRQ_falling_edge[4]; 156 chips[i].regbase = (void __iomem *)GPIO_BANK(i);
163static 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
165static int pxa_gpio_irq_type(unsigned int irq, unsigned int type) 174static 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
216static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) 221static 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
243static void pxa_ack_muxed_gpio(unsigned int irq) 247static 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
249static void pxa_mask_muxed_gpio(unsigned int irq) 255static 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
257static void pxa_unmask_muxed_gpio(unsigned int irq) 269static 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
266static struct irq_chip pxa_muxed_gpio_chip = { 279static struct irq_chip pxa_muxed_gpio_chip = {
@@ -273,15 +286,19 @@ static struct irq_chip pxa_muxed_gpio_chip = {
273 286
274void __init pxa_init_gpio(int mux_irq, int start, int end, set_wake_t fn) 287void __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
303static unsigned long saved_gplr[4];
304static unsigned long saved_gpdr[4];
305static unsigned long saved_grer[4];
306static unsigned long saved_gfer[4];
307
308static int pxa_gpio_suspend(struct sys_device *dev, pm_message_t state) 316static 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
324static int pxa_gpio_resume(struct sys_device *dev) 333static 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}