aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Jarzmik <robert.jarzmik@free.fr>2015-11-28 16:37:42 -0500
committerLinus Walleij <linus.walleij@linaro.org>2015-12-10 10:02:54 -0500
commitfc0589ca64786a2ade9f916fc9c7ca95d375c182 (patch)
tree3fa1d09df9cca6d16024452a277d2a495f165600
parentc2369d3f8cad978dae54fe2149c055a851c32a02 (diff)
gpio: pxa: convert to one gpiochip
The pxa gpio IP is provided by one chip, which holds multiple banks. Another reason the driver should register only one gpiochip instead of multiple gpiochips (ie. 1 per each bank) is that for pincontrol and devicetree integration (think gpio-ranges), it's impossible to have the contiguous pin range 0..127 mapped to gpios 0..127. This patch, amongst other thinks, paves the path to loosen the bond with the global structure variable pxa_gpio_chip. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--drivers/gpio/gpio-pxa.c221
1 files changed, 120 insertions, 101 deletions
diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index bce99182578b..540b2115f741 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -69,15 +69,11 @@ static struct irq_domain *domain;
69static struct device_node *pxa_gpio_of_node; 69static struct device_node *pxa_gpio_of_node;
70#endif 70#endif
71 71
72struct pxa_gpio_chip { 72struct pxa_gpio_bank {
73 struct gpio_chip chip;
74 void __iomem *regbase; 73 void __iomem *regbase;
75 char label[10];
76
77 unsigned long irq_mask; 74 unsigned long irq_mask;
78 unsigned long irq_edge_rise; 75 unsigned long irq_edge_rise;
79 unsigned long irq_edge_fall; 76 unsigned long irq_edge_fall;
80 int (*set_wake)(unsigned int gpio, unsigned int on);
81 77
82#ifdef CONFIG_PM 78#ifdef CONFIG_PM
83 unsigned long saved_gplr; 79 unsigned long saved_gplr;
@@ -87,6 +83,16 @@ struct pxa_gpio_chip {
87#endif 83#endif
88}; 84};
89 85
86struct pxa_gpio_chip {
87 struct device *dev;
88 struct gpio_chip chip;
89 struct pxa_gpio_bank *banks;
90
91 int irq0;
92 int irq1;
93 int (*set_wake)(unsigned int gpio, unsigned int on);
94};
95
90enum pxa_gpio_type { 96enum pxa_gpio_type {
91 PXA25X_GPIO = 0, 97 PXA25X_GPIO = 0,
92 PXA26X_GPIO, 98 PXA26X_GPIO,
@@ -104,9 +110,8 @@ struct pxa_gpio_id {
104}; 110};
105 111
106static DEFINE_SPINLOCK(gpio_lock); 112static DEFINE_SPINLOCK(gpio_lock);
107static struct pxa_gpio_chip *pxa_gpio_chips; 113static struct pxa_gpio_chip *pxa_gpio_chip;
108static enum pxa_gpio_type gpio_type; 114static enum pxa_gpio_type gpio_type;
109static void __iomem *gpio_reg_base;
110 115
111static struct pxa_gpio_id pxa25x_id = { 116static struct pxa_gpio_id pxa25x_id = {
112 .type = PXA25X_GPIO, 117 .type = PXA25X_GPIO,
@@ -148,17 +153,27 @@ static struct pxa_gpio_id pxa1928_id = {
148 .gpio_nums = 224, 153 .gpio_nums = 224,
149}; 154};
150 155
151#define for_each_gpio_chip(i, c) \ 156#define for_each_gpio_bank(i, b, pc) \
152 for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) 157 for (i = 0, b = pc->banks; i <= pxa_last_gpio; i += 32, b++)
153 158
154static inline void __iomem *gpio_chip_base(struct gpio_chip *c) 159static inline struct pxa_gpio_chip *chip_to_pxachip(struct gpio_chip *c)
155{ 160{
156 return container_of(c, struct pxa_gpio_chip, chip)->regbase; 161 struct pxa_gpio_chip *pxa_chip =
162 container_of(c, struct pxa_gpio_chip, chip);
163
164 return pxa_chip;
157} 165}
166static inline void __iomem *gpio_bank_base(struct gpio_chip *c, int gpio)
167{
168 struct pxa_gpio_bank *bank = chip_to_pxachip(c)->banks + (gpio / 32);
158 169
159static inline struct pxa_gpio_chip *gpio_to_pxachip(unsigned gpio) 170 return bank->regbase;
171}
172
173static inline struct pxa_gpio_bank *gpio_to_pxabank(struct gpio_chip *c,
174 unsigned gpio)
160{ 175{
161 return &pxa_gpio_chips[gpio_to_bank(gpio)]; 176 return chip_to_pxachip(c)->banks + gpio / 32;
162} 177}
163 178
164static inline int gpio_is_pxa_type(int type) 179static inline int gpio_is_pxa_type(int type)
@@ -187,15 +202,13 @@ static inline int __gpio_is_inverted(int gpio)
187 * is attributed as "occupied" here (I know this terminology isn't 202 * is attributed as "occupied" here (I know this terminology isn't
188 * accurate, you are welcome to propose a better one :-) 203 * accurate, you are welcome to propose a better one :-)
189 */ 204 */
190static inline int __gpio_is_occupied(unsigned gpio) 205static inline int __gpio_is_occupied(struct pxa_gpio_chip *pchip, unsigned gpio)
191{ 206{
192 struct pxa_gpio_chip *pxachip;
193 void __iomem *base; 207 void __iomem *base;
194 unsigned long gafr = 0, gpdr = 0; 208 unsigned long gafr = 0, gpdr = 0;
195 int ret, af = 0, dir = 0; 209 int ret, af = 0, dir = 0;
196 210
197 pxachip = gpio_to_pxachip(gpio); 211 base = gpio_bank_base(&pchip->chip, gpio);
198 base = gpio_chip_base(&pxachip->chip);
199 gpdr = readl_relaxed(base + GPDR_OFFSET); 212 gpdr = readl_relaxed(base + GPDR_OFFSET);
200 213
201 switch (gpio_type) { 214 switch (gpio_type) {
@@ -220,7 +233,7 @@ static inline int __gpio_is_occupied(unsigned gpio)
220 233
221static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) 234static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
222{ 235{
223 return chip->base + offset + irq_base; 236 return offset + irq_base;
224} 237}
225 238
226int pxa_irq_to_gpio(int irq) 239int pxa_irq_to_gpio(int irq)
@@ -230,8 +243,8 @@ int pxa_irq_to_gpio(int irq)
230 243
231static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) 244static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
232{ 245{
233 void __iomem *base = gpio_chip_base(chip); 246 void __iomem *base = gpio_bank_base(chip, offset);
234 uint32_t value, mask = 1 << offset; 247 uint32_t value, mask = GPIO_bit(offset);
235 unsigned long flags; 248 unsigned long flags;
236 249
237 spin_lock_irqsave(&gpio_lock, flags); 250 spin_lock_irqsave(&gpio_lock, flags);
@@ -250,8 +263,8 @@ static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
250static int pxa_gpio_direction_output(struct gpio_chip *chip, 263static int pxa_gpio_direction_output(struct gpio_chip *chip,
251 unsigned offset, int value) 264 unsigned offset, int value)
252{ 265{
253 void __iomem *base = gpio_chip_base(chip); 266 void __iomem *base = gpio_bank_base(chip, offset);
254 uint32_t tmp, mask = 1 << offset; 267 uint32_t tmp, mask = GPIO_bit(offset);
255 unsigned long flags; 268 unsigned long flags;
256 269
257 writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET)); 270 writel_relaxed(mask, base + (value ? GPSR_OFFSET : GPCR_OFFSET));
@@ -271,14 +284,18 @@ static int pxa_gpio_direction_output(struct gpio_chip *chip,
271 284
272static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) 285static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset)
273{ 286{
274 u32 gplr = readl_relaxed(gpio_chip_base(chip) + GPLR_OFFSET); 287 void __iomem *base = gpio_bank_base(chip, offset);
275 return !!(gplr & (1 << offset)); 288 u32 gplr = readl_relaxed(base + GPLR_OFFSET);
289
290 return !!(gplr & GPIO_bit(offset));
276} 291}
277 292
278static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 293static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
279{ 294{
280 writel_relaxed(1 << offset, gpio_chip_base(chip) + 295 void __iomem *base = gpio_bank_base(chip, offset);
281 (value ? GPSR_OFFSET : GPCR_OFFSET)); 296
297 writel_relaxed(GPIO_bit(offset),
298 base + (value ? GPSR_OFFSET : GPCR_OFFSET));
282} 299}
283 300
284#ifdef CONFIG_OF_GPIO 301#ifdef CONFIG_OF_GPIO
@@ -289,61 +306,49 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc,
289 if (gpiospec->args[0] > pxa_last_gpio) 306 if (gpiospec->args[0] > pxa_last_gpio)
290 return -EINVAL; 307 return -EINVAL;
291 308
292 if (gc != &pxa_gpio_chips[gpiospec->args[0] / 32].chip)
293 return -EINVAL;
294
295 if (flags) 309 if (flags)
296 *flags = gpiospec->args[1]; 310 *flags = gpiospec->args[1];
297 311
298 return gpiospec->args[0] % 32; 312 return gpiospec->args[0];
299} 313}
300#endif 314#endif
301 315
302static int pxa_init_gpio_chip(int gpio_end, 316static int pxa_init_gpio_chip(struct pxa_gpio_chip *pchip, int ngpio,
303 int (*set_wake)(unsigned int, unsigned int)) 317 void __iomem *regbase)
304{ 318{
305 int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; 319 int i, gpio, nbanks = DIV_ROUND_UP(ngpio, 32);
306 struct pxa_gpio_chip *chips; 320 struct pxa_gpio_bank *bank;
307 321
308 chips = kzalloc(nbanks * sizeof(struct pxa_gpio_chip), GFP_KERNEL); 322 pchip->banks = devm_kcalloc(pchip->dev, nbanks, sizeof(*pchip->banks),
309 if (chips == NULL) { 323 GFP_KERNEL);
310 pr_err("%s: failed to allocate GPIO chips\n", __func__); 324 if (!pchip->banks)
311 return -ENOMEM; 325 return -ENOMEM;
312 }
313 326
314 for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { 327 pchip->chip.label = "gpio-pxa";
315 struct gpio_chip *c = &chips[i].chip; 328 pchip->chip.direction_input = pxa_gpio_direction_input;
316 329 pchip->chip.direction_output = pxa_gpio_direction_output;
317 sprintf(chips[i].label, "gpio-%d", i); 330 pchip->chip.get = pxa_gpio_get;
318 chips[i].regbase = gpio_reg_base + BANK_OFF(i); 331 pchip->chip.set = pxa_gpio_set;
319 chips[i].set_wake = set_wake; 332 pchip->chip.to_irq = pxa_gpio_to_irq;
320 333 pchip->chip.ngpio = ngpio;
321 c->base = gpio;
322 c->label = chips[i].label;
323
324 c->direction_input = pxa_gpio_direction_input;
325 c->direction_output = pxa_gpio_direction_output;
326 c->get = pxa_gpio_get;
327 c->set = pxa_gpio_set;
328 c->to_irq = pxa_gpio_to_irq;
329#ifdef CONFIG_OF_GPIO 334#ifdef CONFIG_OF_GPIO
330 c->of_node = pxa_gpio_of_node; 335 pchip->chip.of_node = pxa_gpio_of_node;
331 c->of_xlate = pxa_gpio_of_xlate; 336 pchip->chip.of_xlate = pxa_gpio_of_xlate;
332 c->of_gpio_n_cells = 2; 337 pchip->chip.of_gpio_n_cells = 2;
333#endif 338#endif
334 339
335 /* number of GPIOs on last bank may be less than 32 */ 340 for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) {
336 c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; 341 bank = pchip->banks + i;
337 gpiochip_add(c); 342 bank->regbase = regbase + BANK_OFF(i);
338 } 343 }
339 pxa_gpio_chips = chips; 344
340 return 0; 345 return gpiochip_add(&pchip->chip);
341} 346}
342 347
343/* Update only those GRERx and GFERx edge detection register bits if those 348/* Update only those GRERx and GFERx edge detection register bits if those
344 * bits are set in c->irq_mask 349 * bits are set in c->irq_mask
345 */ 350 */
346static inline void update_edge_detect(struct pxa_gpio_chip *c) 351static inline void update_edge_detect(struct pxa_gpio_bank *c)
347{ 352{
348 uint32_t grer, gfer; 353 uint32_t grer, gfer;
349 354
@@ -357,12 +362,11 @@ static inline void update_edge_detect(struct pxa_gpio_chip *c)
357 362
358static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type) 363static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
359{ 364{
360 struct pxa_gpio_chip *c; 365 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
361 int gpio = pxa_irq_to_gpio(d->irq); 366 int gpio = pxa_irq_to_gpio(d->irq);
367 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio);
362 unsigned long gpdr, mask = GPIO_bit(gpio); 368 unsigned long gpdr, mask = GPIO_bit(gpio);
363 369
364 c = gpio_to_pxachip(gpio);
365
366 if (type == IRQ_TYPE_PROBE) { 370 if (type == IRQ_TYPE_PROBE) {
367 /* Don't mess with enabled GPIOs using preconfigured edges or 371 /* Don't mess with enabled GPIOs using preconfigured edges or
368 * GPIOs set to alternate function or to output during probe 372 * GPIOs set to alternate function or to output during probe
@@ -370,7 +374,7 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
370 if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio)) 374 if ((c->irq_edge_rise | c->irq_edge_fall) & GPIO_bit(gpio))
371 return 0; 375 return 0;
372 376
373 if (__gpio_is_occupied(gpio)) 377 if (__gpio_is_occupied(pchip, gpio))
374 return 0; 378 return 0;
375 379
376 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING; 380 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
@@ -403,18 +407,17 @@ static int pxa_gpio_irq_type(struct irq_data *d, unsigned int type)
403 407
404static void pxa_gpio_demux_handler(struct irq_desc *desc) 408static void pxa_gpio_demux_handler(struct irq_desc *desc)
405{ 409{
406 struct pxa_gpio_chip *c; 410 int loop, gpio, n, handled = 0;
407 int loop, gpio, gpio_base, n;
408 unsigned long gedr; 411 unsigned long gedr;
409 struct irq_chip *chip = irq_desc_get_chip(desc); 412 struct irq_chip *chip = irq_desc_get_chip(desc);
413 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
414 struct pxa_gpio_bank *c;
410 415
411 chained_irq_enter(chip, desc); 416 chained_irq_enter(chip, desc);
412 417
413 do { 418 do {
414 loop = 0; 419 loop = 0;
415 for_each_gpio_chip(gpio, c) { 420 for_each_gpio_bank(gpio, c, pchip) {
416 gpio_base = c->chip.base;
417
418 gedr = readl_relaxed(c->regbase + GEDR_OFFSET); 421 gedr = readl_relaxed(c->regbase + GEDR_OFFSET);
419 gedr = gedr & c->irq_mask; 422 gedr = gedr & c->irq_mask;
420 writel_relaxed(gedr, c->regbase + GEDR_OFFSET); 423 writel_relaxed(gedr, c->regbase + GEDR_OFFSET);
@@ -422,7 +425,7 @@ static void pxa_gpio_demux_handler(struct irq_desc *desc)
422 for_each_set_bit(n, &gedr, BITS_PER_LONG) { 425 for_each_set_bit(n, &gedr, BITS_PER_LONG) {
423 loop = 1; 426 loop = 1;
424 427
425 generic_handle_irq(gpio_to_irq(gpio_base + n)); 428 generic_handle_irq(gpio_to_irq(gpio + n));
426 } 429 }
427 } 430 }
428 } while (loop); 431 } while (loop);
@@ -432,41 +435,45 @@ static void pxa_gpio_demux_handler(struct irq_desc *desc)
432 435
433static void pxa_ack_muxed_gpio(struct irq_data *d) 436static void pxa_ack_muxed_gpio(struct irq_data *d)
434{ 437{
438 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
435 int gpio = pxa_irq_to_gpio(d->irq); 439 int gpio = pxa_irq_to_gpio(d->irq);
436 struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 440 void __iomem *base = gpio_bank_base(&pchip->chip, gpio);
437 441
438 writel_relaxed(GPIO_bit(gpio), c->regbase + GEDR_OFFSET); 442 writel_relaxed(GPIO_bit(gpio), base + GEDR_OFFSET);
439} 443}
440 444
441static void pxa_mask_muxed_gpio(struct irq_data *d) 445static void pxa_mask_muxed_gpio(struct irq_data *d)
442{ 446{
447 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
443 int gpio = pxa_irq_to_gpio(d->irq); 448 int gpio = pxa_irq_to_gpio(d->irq);
444 struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 449 struct pxa_gpio_bank *b = gpio_to_pxabank(&pchip->chip, gpio);
450 void __iomem *base = gpio_bank_base(&pchip->chip, gpio);
445 uint32_t grer, gfer; 451 uint32_t grer, gfer;
446 452
447 c->irq_mask &= ~GPIO_bit(gpio); 453 b->irq_mask &= ~GPIO_bit(gpio);
448 454
449 grer = readl_relaxed(c->regbase + GRER_OFFSET) & ~GPIO_bit(gpio); 455 grer = readl_relaxed(base + GRER_OFFSET) & ~GPIO_bit(gpio);
450 gfer = readl_relaxed(c->regbase + GFER_OFFSET) & ~GPIO_bit(gpio); 456 gfer = readl_relaxed(base + GFER_OFFSET) & ~GPIO_bit(gpio);
451 writel_relaxed(grer, c->regbase + GRER_OFFSET); 457 writel_relaxed(grer, base + GRER_OFFSET);
452 writel_relaxed(gfer, c->regbase + GFER_OFFSET); 458 writel_relaxed(gfer, base + GFER_OFFSET);
453} 459}
454 460
455static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on) 461static int pxa_gpio_set_wake(struct irq_data *d, unsigned int on)
456{ 462{
457 int gpio = pxa_irq_to_gpio(d->irq); 463 int gpio = pxa_irq_to_gpio(d->irq);
458 struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 464 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
459 465
460 if (c->set_wake) 466 if (pchip->set_wake)
461 return c->set_wake(gpio, on); 467 return pchip->set_wake(gpio, on);
462 else 468 else
463 return 0; 469 return 0;
464} 470}
465 471
466static void pxa_unmask_muxed_gpio(struct irq_data *d) 472static void pxa_unmask_muxed_gpio(struct irq_data *d)
467{ 473{
474 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
468 int gpio = pxa_irq_to_gpio(d->irq); 475 int gpio = pxa_irq_to_gpio(d->irq);
469 struct pxa_gpio_chip *c = gpio_to_pxachip(gpio); 476 struct pxa_gpio_bank *c = gpio_to_pxabank(&pchip->chip, gpio);
470 477
471 c->irq_mask |= GPIO_bit(gpio); 478 c->irq_mask |= GPIO_bit(gpio);
472 update_edge_detect(c); 479 update_edge_detect(c);
@@ -533,9 +540,10 @@ const struct irq_domain_ops pxa_irq_domain_ops = {
533 .xlate = irq_domain_xlate_twocell, 540 .xlate = irq_domain_xlate_twocell,
534}; 541};
535 542
536static int pxa_gpio_probe_dt(struct platform_device *pdev) 543static int pxa_gpio_probe_dt(struct platform_device *pdev,
544 struct pxa_gpio_chip *pchip)
537{ 545{
538 int ret = 0, nr_gpios; 546 int nr_gpios;
539 struct device_node *np = pdev->dev.of_node; 547 struct device_node *np = pdev->dev.of_node;
540 const struct of_device_id *of_id = 548 const struct of_device_id *of_id =
541 of_match_device(pxa_gpio_dt_ids, &pdev->dev); 549 of_match_device(pxa_gpio_dt_ids, &pdev->dev);
@@ -554,40 +562,44 @@ static int pxa_gpio_probe_dt(struct platform_device *pdev)
554 irq_base = irq_alloc_descs(-1, 0, nr_gpios, 0); 562 irq_base = irq_alloc_descs(-1, 0, nr_gpios, 0);
555 if (irq_base < 0) { 563 if (irq_base < 0) {
556 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n"); 564 dev_err(&pdev->dev, "Failed to allocate IRQ numbers\n");
557 ret = irq_base; 565 return irq_base;
558 goto err;
559 } 566 }
560 domain = irq_domain_add_legacy(np, nr_gpios, irq_base, 0, 567 domain = irq_domain_add_legacy(np, nr_gpios, irq_base, 0,
561 &pxa_irq_domain_ops, NULL); 568 &pxa_irq_domain_ops, pchip);
562 pxa_gpio_of_node = np; 569 pxa_gpio_of_node = np;
563 return 0; 570 return 0;
564err:
565 iounmap(gpio_reg_base);
566 return ret;
567} 571}
568#else 572#else
569#define pxa_gpio_probe_dt(pdev) (-1) 573#define pxa_gpio_probe_dt(pdev, pchip) (-1)
570#endif 574#endif
571 575
572static int pxa_gpio_probe(struct platform_device *pdev) 576static int pxa_gpio_probe(struct platform_device *pdev)
573{ 577{
574 struct pxa_gpio_chip *c; 578 struct pxa_gpio_chip *pchip;
579 struct pxa_gpio_bank *c;
575 struct resource *res; 580 struct resource *res;
576 struct clk *clk; 581 struct clk *clk;
577 struct pxa_gpio_platform_data *info; 582 struct pxa_gpio_platform_data *info;
583 void __iomem *gpio_reg_base;
578 int gpio, irq, ret, use_of = 0; 584 int gpio, irq, ret, use_of = 0;
579 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0; 585 int irq0 = 0, irq1 = 0, irq_mux, gpio_offset = 0;
580 586
587 pchip = devm_kzalloc(&pdev->dev, sizeof(*pchip), GFP_KERNEL);
588 if (!pchip)
589 return -ENOMEM;
590 pchip->dev = &pdev->dev;
591
581 info = dev_get_platdata(&pdev->dev); 592 info = dev_get_platdata(&pdev->dev);
582 if (info) { 593 if (info) {
583 irq_base = info->irq_base; 594 irq_base = info->irq_base;
584 if (irq_base <= 0) 595 if (irq_base <= 0)
585 return -EINVAL; 596 return -EINVAL;
586 pxa_last_gpio = pxa_gpio_nums(pdev); 597 pxa_last_gpio = pxa_gpio_nums(pdev);
598 pchip->set_wake = info->gpio_set_wake;
587 } else { 599 } else {
588 irq_base = 0; 600 irq_base = 0;
589 use_of = 1; 601 use_of = 1;
590 ret = pxa_gpio_probe_dt(pdev); 602 ret = pxa_gpio_probe_dt(pdev, pchip);
591 if (ret < 0) 603 if (ret < 0)
592 return -EINVAL; 604 return -EINVAL;
593 } 605 }
@@ -626,10 +638,14 @@ static int pxa_gpio_probe(struct platform_device *pdev)
626 } 638 }
627 639
628 /* Initialize GPIO chips */ 640 /* Initialize GPIO chips */
629 pxa_init_gpio_chip(pxa_last_gpio, info ? info->gpio_set_wake : NULL); 641 ret = pxa_init_gpio_chip(pchip, pxa_last_gpio + 1, gpio_reg_base);
642 if (ret) {
643 clk_put(clk);
644 return ret;
645 }
630 646
631 /* clear all GPIO edge detects */ 647 /* clear all GPIO edge detects */
632 for_each_gpio_chip(gpio, c) { 648 for_each_gpio_bank(gpio, c, pchip) {
633 writel_relaxed(0, c->regbase + GFER_OFFSET); 649 writel_relaxed(0, c->regbase + GFER_OFFSET);
634 writel_relaxed(0, c->regbase + GRER_OFFSET); 650 writel_relaxed(0, c->regbase + GRER_OFFSET);
635 writel_relaxed(~0, c->regbase + GEDR_OFFSET); 651 writel_relaxed(~0, c->regbase + GEDR_OFFSET);
@@ -664,6 +680,7 @@ static int pxa_gpio_probe(struct platform_device *pdev)
664 irq_set_chained_handler(irq0, pxa_gpio_demux_handler); 680 irq_set_chained_handler(irq0, pxa_gpio_demux_handler);
665 if (irq1 > 0) 681 if (irq1 > 0)
666 irq_set_chained_handler(irq1, pxa_gpio_demux_handler); 682 irq_set_chained_handler(irq1, pxa_gpio_demux_handler);
683 pxa_gpio_chip = pchip;
667 684
668 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler); 685 irq_set_chained_handler(irq_mux, pxa_gpio_demux_handler);
669 return 0; 686 return 0;
@@ -711,10 +728,11 @@ device_initcall(pxa_gpio_dt_init);
711#ifdef CONFIG_PM 728#ifdef CONFIG_PM
712static int pxa_gpio_suspend(void) 729static int pxa_gpio_suspend(void)
713{ 730{
714 struct pxa_gpio_chip *c; 731 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
732 struct pxa_gpio_bank *c;
715 int gpio; 733 int gpio;
716 734
717 for_each_gpio_chip(gpio, c) { 735 for_each_gpio_bank(gpio, c, pchip) {
718 c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET); 736 c->saved_gplr = readl_relaxed(c->regbase + GPLR_OFFSET);
719 c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET); 737 c->saved_gpdr = readl_relaxed(c->regbase + GPDR_OFFSET);
720 c->saved_grer = readl_relaxed(c->regbase + GRER_OFFSET); 738 c->saved_grer = readl_relaxed(c->regbase + GRER_OFFSET);
@@ -728,10 +746,11 @@ static int pxa_gpio_suspend(void)
728 746
729static void pxa_gpio_resume(void) 747static void pxa_gpio_resume(void)
730{ 748{
731 struct pxa_gpio_chip *c; 749 struct pxa_gpio_chip *pchip = pxa_gpio_chip;
750 struct pxa_gpio_bank *c;
732 int gpio; 751 int gpio;
733 752
734 for_each_gpio_chip(gpio, c) { 753 for_each_gpio_bank(gpio, c, pchip) {
735 /* restore level with set/clear */ 754 /* restore level with set/clear */
736 writel_relaxed(c->saved_gplr, c->regbase + GPSR_OFFSET); 755 writel_relaxed(c->saved_gplr, c->regbase + GPSR_OFFSET);
737 writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET); 756 writel_relaxed(~c->saved_gplr, c->regbase + GPCR_OFFSET);