Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pinctrl: spear: switch plgpio to irqchip helpers

This switches the SPEAr PLGPIO driver over to using the irqchip
helpers.

As part of this effort, also get rid of the strange irq_base
calculation and failure to use d->hwirq for obtaining a local
irqchip offset.

Cc: Viresh Kumar <viresh.linux@gmail.com>
Cc: Shiraz Hashim <shiraz.linux.kernel@gmail.com>
Cc: spear-devel@list.st.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+31 -51
+1
drivers/pinctrl/spear/Kconfig
··· 48 48 config PINCTRL_SPEAR_PLGPIO 49 49 bool "SPEAr SoC PLGPIO Controller" 50 50 depends on GPIOLIB && PINCTRL_SPEAR 51 + select GPIOLIB_IRQCHIP 51 52 help 52 53 Say yes here to support PLGPIO controller on ST Microelectronics SPEAr 53 54 SoCs.
+30 -51
drivers/pinctrl/spear/pinctrl-plgpio.c
··· 11 11 12 12 #include <linux/clk.h> 13 13 #include <linux/err.h> 14 - #include <linux/gpio.h> 14 + #include <linux/gpio/driver.h> 15 15 #include <linux/io.h> 16 - #include <linux/irq.h> 17 - #include <linux/irqdomain.h> 18 - #include <linux/irqchip/chained_irq.h> 19 16 #include <linux/module.h> 17 + #include <linux/of.h> 18 + #include <linux/of_platform.h> 20 19 #include <linux/pinctrl/consumer.h> 21 20 #include <linux/platform_device.h> 22 21 #include <linux/pm.h> ··· 53 54 * 54 55 * lock: lock for guarding gpio registers 55 56 * base: base address of plgpio block 56 - * irq_base: irq number of plgpio0 57 57 * chip: gpio framework specific chip information structure 58 58 * p2o: function ptr for pin to offset conversion. This is required only for 59 59 * machines where mapping b/w pin and offset is not 1-to-1. ··· 66 68 spinlock_t lock; 67 69 void __iomem *base; 68 70 struct clk *clk; 69 - unsigned irq_base; 70 - struct irq_domain *irq_domain; 71 71 struct gpio_chip chip; 72 72 int (*p2o)(int pin); /* pin_to_offset */ 73 73 int (*o2p)(int offset); /* offset_to_pin */ ··· 276 280 pinctrl_free_gpio(gpio); 277 281 } 278 282 279 - static int plgpio_to_irq(struct gpio_chip *chip, unsigned offset) 280 - { 281 - struct plgpio *plgpio = container_of(chip, struct plgpio, chip); 282 - 283 - if (IS_ERR_VALUE(plgpio->irq_base)) 284 - return -EINVAL; 285 - 286 - return irq_find_mapping(plgpio->irq_domain, offset); 287 - } 288 - 289 283 /* PLGPIO IRQ */ 290 284 static void plgpio_irq_disable(struct irq_data *d) 291 285 { 292 - struct plgpio *plgpio = irq_data_get_irq_chip_data(d); 293 - int offset = d->irq - plgpio->irq_base; 286 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 287 + struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 288 + int offset = d->hwirq; 294 289 unsigned long flags; 295 290 296 291 /* get correct offset for "offset" pin */ ··· 298 311 299 312 static void plgpio_irq_enable(struct irq_data *d) 300 313 { 301 - struct plgpio *plgpio = irq_data_get_irq_chip_data(d); 302 - int offset = d->irq - plgpio->irq_base; 314 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 315 + struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 316 + int offset = d->hwirq; 303 317 unsigned long flags; 304 318 305 319 /* get correct offset for "offset" pin */ ··· 317 329 318 330 static int plgpio_irq_set_type(struct irq_data *d, unsigned trigger) 319 331 { 320 - struct plgpio *plgpio = irq_data_get_irq_chip_data(d); 321 - int offset = d->irq - plgpio->irq_base; 332 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 333 + struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 334 + int offset = d->hwirq; 322 335 void __iomem *reg_off; 323 336 unsigned int supported_type = 0, val; 324 337 ··· 358 369 359 370 static void plgpio_irq_handler(unsigned irq, struct irq_desc *desc) 360 371 { 361 - struct plgpio *plgpio = irq_get_handler_data(irq); 372 + struct gpio_chip *gc = irq_desc_get_handler_data(desc); 373 + struct plgpio *plgpio = container_of(gc, struct plgpio, chip); 362 374 struct irq_chip *irqchip = irq_desc_get_chip(desc); 363 375 int regs_count, count, pin, offset, i = 0; 364 376 unsigned long pending; ··· 400 410 401 411 /* get correct irq line number */ 402 412 pin = i * MAX_GPIO_PER_REG + pin; 403 - generic_handle_irq(plgpio_to_irq(&plgpio->chip, pin)); 413 + generic_handle_irq( 414 + irq_find_mapping(gc->irqdomain, pin)); 404 415 } 405 416 } 406 417 chained_irq_exit(irqchip, desc); ··· 514 523 } 515 524 static int plgpio_probe(struct platform_device *pdev) 516 525 { 517 - struct device_node *np = pdev->dev.of_node; 518 526 struct plgpio *plgpio; 519 527 struct resource *res; 520 - int ret, irq, i; 528 + int ret, irq; 521 529 522 530 plgpio = devm_kzalloc(&pdev->dev, sizeof(*plgpio), GFP_KERNEL); 523 531 if (!plgpio) { ··· 553 563 platform_set_drvdata(pdev, plgpio); 554 564 spin_lock_init(&plgpio->lock); 555 565 556 - plgpio->irq_base = -1; 557 566 plgpio->chip.base = -1; 558 567 plgpio->chip.request = plgpio_request; 559 568 plgpio->chip.free = plgpio_free; ··· 560 571 plgpio->chip.direction_output = plgpio_direction_output; 561 572 plgpio->chip.get = plgpio_get_value; 562 573 plgpio->chip.set = plgpio_set_value; 563 - plgpio->chip.to_irq = plgpio_to_irq; 564 574 plgpio->chip.label = dev_name(&pdev->dev); 565 575 plgpio->chip.dev = &pdev->dev; 566 576 plgpio->chip.owner = THIS_MODULE; 577 + plgpio->chip.of_node = pdev->dev.of_node; 567 578 568 579 if (!IS_ERR(plgpio->clk)) { 569 580 ret = clk_prepare(plgpio->clk); ··· 581 592 582 593 irq = platform_get_irq(pdev, 0); 583 594 if (irq < 0) { 584 - dev_info(&pdev->dev, "irqs not supported\n"); 595 + dev_info(&pdev->dev, "PLGPIO registered without IRQs\n"); 585 596 return 0; 586 597 } 587 598 588 - plgpio->irq_base = irq_alloc_descs(-1, 0, plgpio->chip.ngpio, 0); 589 - if (IS_ERR_VALUE(plgpio->irq_base)) { 590 - /* we would not support irq for gpio */ 591 - dev_warn(&pdev->dev, "couldn't allocate irq base\n"); 592 - return 0; 593 - } 594 - 595 - plgpio->irq_domain = irq_domain_add_legacy(np, plgpio->chip.ngpio, 596 - plgpio->irq_base, 0, &irq_domain_simple_ops, NULL); 597 - if (WARN_ON(!plgpio->irq_domain)) { 598 - dev_err(&pdev->dev, "irq domain init failed\n"); 599 - irq_free_descs(plgpio->irq_base, plgpio->chip.ngpio); 600 - ret = -ENXIO; 599 + ret = gpiochip_irqchip_add(&plgpio->chip, 600 + &plgpio_irqchip, 601 + 0, 602 + handle_simple_irq, 603 + IRQ_TYPE_NONE); 604 + if (ret) { 605 + dev_err(&pdev->dev, "failed to add irqchip to gpiochip\n"); 601 606 goto remove_gpiochip; 602 607 } 603 608 604 - irq_set_chained_handler(irq, plgpio_irq_handler); 605 - for (i = 0; i < plgpio->chip.ngpio; i++) { 606 - irq_set_chip_and_handler(i + plgpio->irq_base, &plgpio_irqchip, 607 - handle_simple_irq); 608 - set_irq_flags(i + plgpio->irq_base, IRQF_VALID); 609 - irq_set_chip_data(i + plgpio->irq_base, plgpio); 610 - } 609 + gpiochip_set_chained_irqchip(&plgpio->chip, 610 + &plgpio_irqchip, 611 + irq, 612 + plgpio_irq_handler); 611 613 612 - irq_set_handler_data(irq, plgpio); 613 614 dev_info(&pdev->dev, "PLGPIO registered with IRQs\n"); 614 615 615 616 return 0;