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

pinctrl: bcm: nsp: use gpiolib infrastructure for interrupts

Use more of the gpiolib infrastructure for handling interrupts. The
root interrupt still needs to be handled manually as it is shared with
other peripherals on the SoC.

This will allow multiple instances of this driver to be supported and
will clean up gracefully on failure thanks to the device managed APIs.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Link: https://lore.kernel.org/r/20191104001819.2300-2-chris.packham@alliedtelesis.co.nz
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Chris Packham and committed by
Linus Walleij
8298d18a 10ff58aa

+46 -67
+46 -67
drivers/pinctrl/bcm/pinctrl-nsp-gpio.c
··· 64 64 * @gc: GPIO chip 65 65 * @pctl: pointer to pinctrl_dev 66 66 * @pctldesc: pinctrl descriptor 67 - * @irq_domain: pointer to irq domain 68 67 * @lock: lock to protect access to I/O registers 69 68 */ 70 69 struct nsp_gpio { 71 70 struct device *dev; 72 71 void __iomem *base; 73 72 void __iomem *io_ctrl; 73 + struct irq_chip irqchip; 74 74 struct gpio_chip gc; 75 75 struct pinctrl_dev *pctl; 76 76 struct pinctrl_desc pctldesc; 77 - struct irq_domain *irq_domain; 78 77 raw_spinlock_t lock; 79 78 }; 80 79 ··· 135 136 136 137 static irqreturn_t nsp_gpio_irq_handler(int irq, void *data) 137 138 { 138 - struct nsp_gpio *chip = (struct nsp_gpio *)data; 139 - struct gpio_chip gc = chip->gc; 139 + struct gpio_chip *gc = (struct gpio_chip *)data; 140 + struct nsp_gpio *chip = gpiochip_get_data(gc); 140 141 int bit; 141 142 unsigned long int_bits = 0; 142 143 u32 int_status; ··· 154 155 level &= readl(chip->base + NSP_GPIO_INT_MASK); 155 156 int_bits = level | event; 156 157 157 - for_each_set_bit(bit, &int_bits, gc.ngpio) { 158 + for_each_set_bit(bit, &int_bits, gc->ngpio) { 158 159 /* 159 160 * Clear the interrupt before invoking the 160 161 * handler, so we do not leave any window 161 162 */ 162 163 writel(BIT(bit), chip->base + NSP_GPIO_EVENT); 163 164 generic_handle_irq( 164 - irq_linear_revmap(chip->irq_domain, bit)); 165 + irq_linear_revmap(gc->irq.domain, bit)); 165 166 } 166 167 } 167 168 ··· 170 171 171 172 static void nsp_gpio_irq_ack(struct irq_data *d) 172 173 { 173 - struct nsp_gpio *chip = irq_data_get_irq_chip_data(d); 174 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 175 + struct nsp_gpio *chip = gpiochip_get_data(gc); 174 176 unsigned gpio = d->hwirq; 175 177 u32 val = BIT(gpio); 176 178 u32 trigger_type; ··· 189 189 */ 190 190 static void nsp_gpio_irq_set_mask(struct irq_data *d, bool unmask) 191 191 { 192 - struct nsp_gpio *chip = irq_data_get_irq_chip_data(d); 192 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 193 + struct nsp_gpio *chip = gpiochip_get_data(gc); 193 194 unsigned gpio = d->hwirq; 194 195 u32 trigger_type; 195 196 ··· 203 202 204 203 static void nsp_gpio_irq_mask(struct irq_data *d) 205 204 { 206 - struct nsp_gpio *chip = irq_data_get_irq_chip_data(d); 205 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 206 + struct nsp_gpio *chip = gpiochip_get_data(gc); 207 207 unsigned long flags; 208 208 209 209 raw_spin_lock_irqsave(&chip->lock, flags); ··· 214 212 215 213 static void nsp_gpio_irq_unmask(struct irq_data *d) 216 214 { 217 - struct nsp_gpio *chip = irq_data_get_irq_chip_data(d); 215 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 216 + struct nsp_gpio *chip = gpiochip_get_data(gc); 218 217 unsigned long flags; 219 218 220 219 raw_spin_lock_irqsave(&chip->lock, flags); ··· 225 222 226 223 static int nsp_gpio_irq_set_type(struct irq_data *d, unsigned int type) 227 224 { 228 - struct nsp_gpio *chip = irq_data_get_irq_chip_data(d); 225 + struct gpio_chip *gc = irq_data_get_irq_chip_data(d); 226 + struct nsp_gpio *chip = gpiochip_get_data(gc); 229 227 unsigned gpio = d->hwirq; 230 228 bool level_low; 231 229 bool falling; ··· 268 264 level_low ? "true" : "false", falling ? "true" : "false"); 269 265 return 0; 270 266 } 271 - 272 - static struct irq_chip nsp_gpio_irq_chip = { 273 - .name = "gpio-a", 274 - .irq_enable = nsp_gpio_irq_unmask, 275 - .irq_disable = nsp_gpio_irq_mask, 276 - .irq_ack = nsp_gpio_irq_ack, 277 - .irq_mask = nsp_gpio_irq_mask, 278 - .irq_unmask = nsp_gpio_irq_unmask, 279 - .irq_set_type = nsp_gpio_irq_set_type, 280 - }; 281 267 282 268 static int nsp_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) 283 269 { ··· 314 320 struct nsp_gpio *chip = gpiochip_get_data(gc); 315 321 316 322 return !!(readl(chip->base + NSP_GPIO_DATA_IN) & BIT(gpio)); 317 - } 318 - 319 - static int nsp_gpio_to_irq(struct gpio_chip *gc, unsigned offset) 320 - { 321 - struct nsp_gpio *chip = gpiochip_get_data(gc); 322 - 323 - return irq_linear_revmap(chip->irq_domain, offset); 324 323 } 325 324 326 325 static int nsp_get_groups_count(struct pinctrl_dev *pctldev) ··· 600 613 static int nsp_gpio_probe(struct platform_device *pdev) 601 614 { 602 615 struct device *dev = &pdev->dev; 603 - struct resource *res; 604 616 struct nsp_gpio *chip; 605 617 struct gpio_chip *gc; 606 - u32 val, count; 618 + u32 val; 607 619 int irq, ret; 608 620 609 621 if (of_property_read_u32(pdev->dev.of_node, "ngpios", &val)) { ··· 617 631 chip->dev = dev; 618 632 platform_set_drvdata(pdev, chip); 619 633 620 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 621 - chip->base = devm_ioremap_resource(dev, res); 634 + chip->base = devm_platform_ioremap_resource(pdev, 0); 622 635 if (IS_ERR(chip->base)) { 623 636 dev_err(dev, "unable to map I/O memory\n"); 624 637 return PTR_ERR(chip->base); 625 638 } 626 639 627 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 628 - chip->io_ctrl = devm_ioremap_resource(dev, res); 640 + chip->io_ctrl = devm_platform_ioremap_resource(pdev, 1); 629 641 if (IS_ERR(chip->io_ctrl)) { 630 642 dev_err(dev, "unable to map I/O memory\n"); 631 643 return PTR_ERR(chip->io_ctrl); ··· 643 659 gc->direction_output = nsp_gpio_direction_output; 644 660 gc->set = nsp_gpio_set; 645 661 gc->get = nsp_gpio_get; 646 - gc->to_irq = nsp_gpio_to_irq; 647 662 648 663 /* optional GPIO interrupt support */ 649 664 irq = platform_get_irq(pdev, 0); 650 665 if (irq > 0) { 651 - /* Create irq domain so that each pin can be assigned an IRQ.*/ 652 - chip->irq_domain = irq_domain_add_linear(gc->of_node, gc->ngpio, 653 - &irq_domain_simple_ops, 654 - chip); 655 - if (!chip->irq_domain) { 656 - dev_err(&pdev->dev, "Couldn't allocate IRQ domain\n"); 657 - return -ENXIO; 658 - } 666 + struct gpio_irq_chip *girq; 667 + struct irq_chip *irqc; 659 668 660 - /* Map each gpio to an IRQ and set the handler for gpiolib. */ 661 - for (count = 0; count < gc->ngpio; count++) { 662 - int irq = irq_create_mapping(chip->irq_domain, count); 663 - 664 - irq_set_chip_and_handler(irq, &nsp_gpio_irq_chip, 665 - handle_simple_irq); 666 - irq_set_chip_data(irq, chip); 667 - } 668 - 669 - /* Install ISR for this GPIO controller. */ 670 - ret = devm_request_irq(&pdev->dev, irq, nsp_gpio_irq_handler, 671 - IRQF_SHARED, "gpio-a", chip); 672 - if (ret) { 673 - dev_err(&pdev->dev, "Unable to request IRQ%d: %d\n", 674 - irq, ret); 675 - goto err_rm_gpiochip; 676 - } 669 + irqc = &chip->irqchip; 670 + irqc->name = "gpio-a"; 671 + irqc->irq_ack = nsp_gpio_irq_ack; 672 + irqc->irq_mask = nsp_gpio_irq_mask; 673 + irqc->irq_unmask = nsp_gpio_irq_unmask; 674 + irqc->irq_set_type = nsp_gpio_irq_set_type; 677 675 678 676 val = readl(chip->base + NSP_CHIP_A_INT_MASK); 679 677 val = val | NSP_CHIP_A_GPIO_INT_BIT; 680 678 writel(val, (chip->base + NSP_CHIP_A_INT_MASK)); 679 + 680 + /* Install ISR for this GPIO controller. */ 681 + ret = devm_request_irq(dev, irq, nsp_gpio_irq_handler, 682 + IRQF_SHARED, "gpio-a", &chip->gc); 683 + if (ret) { 684 + dev_err(&pdev->dev, "Unable to request IRQ%d: %d\n", 685 + irq, ret); 686 + return ret; 687 + } 688 + 689 + girq = &chip->gc.irq; 690 + girq->chip = irqc; 691 + /* This will let us handle the parent IRQ in the driver */ 692 + girq->parent_handler = NULL; 693 + girq->num_parents = 0; 694 + girq->parents = NULL; 695 + girq->default_type = IRQ_TYPE_NONE; 696 + girq->handler = handle_simple_irq; 681 697 } 682 698 683 - ret = gpiochip_add_data(gc, chip); 699 + ret = devm_gpiochip_add_data(dev, gc, chip); 684 700 if (ret < 0) { 685 701 dev_err(dev, "unable to add GPIO chip\n"); 686 702 return ret; ··· 689 705 ret = nsp_gpio_register_pinconf(chip); 690 706 if (ret) { 691 707 dev_err(dev, "unable to register pinconf\n"); 692 - goto err_rm_gpiochip; 708 + return ret; 693 709 } 694 710 695 711 return 0; 696 - 697 - err_rm_gpiochip: 698 - gpiochip_remove(gc); 699 - 700 - return ret; 701 712 } 702 713 703 714 static struct platform_driver nsp_gpio_driver = {