| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * U300 GPIO module. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007-2012 ST-Ericsson AB |
|---|
| 5 | | - * License terms: GNU General Public License (GPL) version 2 |
|---|
| 6 | 6 | * COH 901 571/3 - Used in DB3210 (U365 2.0) and DB3350 (U335 1.0) |
|---|
| 7 | 7 | * Author: Linus Walleij <linus.walleij@linaro.org> |
|---|
| 8 | 8 | * Author: Jonas Aaberg <jonas.aberg@stericsson.com> |
|---|
| .. | .. |
|---|
| 15 | 15 | #include <linux/clk.h> |
|---|
| 16 | 16 | #include <linux/err.h> |
|---|
| 17 | 17 | #include <linux/platform_device.h> |
|---|
| 18 | | -#include <linux/gpio.h> |
|---|
| 18 | +#include <linux/gpio/driver.h> |
|---|
| 19 | 19 | #include <linux/slab.h> |
|---|
| 20 | 20 | #include <linux/pinctrl/consumer.h> |
|---|
| 21 | 21 | #include <linux/pinctrl/pinconf-generic.h> |
|---|
| .. | .. |
|---|
| 615 | 615 | static int __init u300_gpio_probe(struct platform_device *pdev) |
|---|
| 616 | 616 | { |
|---|
| 617 | 617 | struct u300_gpio *gpio; |
|---|
| 618 | | - struct resource *memres; |
|---|
| 618 | + struct gpio_irq_chip *girq; |
|---|
| 619 | 619 | int err = 0; |
|---|
| 620 | 620 | int portno; |
|---|
| 621 | 621 | u32 val; |
|---|
| .. | .. |
|---|
| 632 | 632 | gpio->chip.base = 0; |
|---|
| 633 | 633 | gpio->dev = &pdev->dev; |
|---|
| 634 | 634 | |
|---|
| 635 | | - memres = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 636 | | - gpio->base = devm_ioremap_resource(&pdev->dev, memres); |
|---|
| 635 | + gpio->base = devm_platform_ioremap_resource(pdev, 0); |
|---|
| 637 | 636 | if (IS_ERR(gpio->base)) |
|---|
| 638 | 637 | return PTR_ERR(gpio->base); |
|---|
| 639 | 638 | |
|---|
| .. | .. |
|---|
| 672 | 671 | gpio->base + U300_GPIO_CR); |
|---|
| 673 | 672 | u300_gpio_init_coh901571(gpio); |
|---|
| 674 | 673 | |
|---|
| 675 | | -#ifdef CONFIG_OF_GPIO |
|---|
| 676 | | - gpio->chip.of_node = pdev->dev.of_node; |
|---|
| 677 | | -#endif |
|---|
| 678 | | - err = gpiochip_add_data(&gpio->chip, gpio); |
|---|
| 679 | | - if (err) { |
|---|
| 680 | | - dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); |
|---|
| 681 | | - goto err_no_chip; |
|---|
| 674 | + girq = &gpio->chip.irq; |
|---|
| 675 | + girq->chip = &u300_gpio_irqchip; |
|---|
| 676 | + girq->parent_handler = u300_gpio_irq_handler; |
|---|
| 677 | + girq->num_parents = U300_GPIO_NUM_PORTS; |
|---|
| 678 | + girq->parents = devm_kcalloc(gpio->dev, U300_GPIO_NUM_PORTS, |
|---|
| 679 | + sizeof(*girq->parents), |
|---|
| 680 | + GFP_KERNEL); |
|---|
| 681 | + if (!girq->parents) { |
|---|
| 682 | + err = -ENOMEM; |
|---|
| 683 | + goto err_dis_clk; |
|---|
| 682 | 684 | } |
|---|
| 683 | | - |
|---|
| 684 | | - err = gpiochip_irqchip_add(&gpio->chip, |
|---|
| 685 | | - &u300_gpio_irqchip, |
|---|
| 686 | | - 0, |
|---|
| 687 | | - handle_simple_irq, |
|---|
| 688 | | - IRQ_TYPE_EDGE_FALLING); |
|---|
| 689 | | - if (err) { |
|---|
| 690 | | - dev_err(gpio->dev, "no GPIO irqchip\n"); |
|---|
| 691 | | - goto err_no_irqchip; |
|---|
| 692 | | - } |
|---|
| 693 | | - |
|---|
| 694 | | - /* Add each port with its IRQ separately */ |
|---|
| 695 | 685 | for (portno = 0 ; portno < U300_GPIO_NUM_PORTS; portno++) { |
|---|
| 696 | 686 | struct u300_gpio_port *port = &gpio->ports[portno]; |
|---|
| 697 | 687 | |
|---|
| .. | .. |
|---|
| 700 | 690 | port->gpio = gpio; |
|---|
| 701 | 691 | |
|---|
| 702 | 692 | port->irq = platform_get_irq(pdev, portno); |
|---|
| 703 | | - |
|---|
| 704 | | - gpiochip_set_chained_irqchip(&gpio->chip, |
|---|
| 705 | | - &u300_gpio_irqchip, |
|---|
| 706 | | - port->irq, |
|---|
| 707 | | - u300_gpio_irq_handler); |
|---|
| 693 | + girq->parents[portno] = port->irq; |
|---|
| 708 | 694 | |
|---|
| 709 | 695 | /* Turns off irq force (test register) for this port */ |
|---|
| 710 | 696 | writel(0x0, gpio->base + portno * gpio->stride + ifr); |
|---|
| 711 | 697 | } |
|---|
| 712 | | - dev_dbg(gpio->dev, "initialized %d GPIO ports\n", portno); |
|---|
| 698 | + girq->default_type = IRQ_TYPE_EDGE_FALLING; |
|---|
| 699 | + girq->handler = handle_simple_irq; |
|---|
| 700 | +#ifdef CONFIG_OF_GPIO |
|---|
| 701 | + gpio->chip.of_node = pdev->dev.of_node; |
|---|
| 702 | +#endif |
|---|
| 703 | + err = gpiochip_add_data(&gpio->chip, gpio); |
|---|
| 704 | + if (err) { |
|---|
| 705 | + dev_err(gpio->dev, "unable to add gpiochip: %d\n", err); |
|---|
| 706 | + goto err_dis_clk; |
|---|
| 707 | + } |
|---|
| 713 | 708 | |
|---|
| 714 | 709 | /* |
|---|
| 715 | 710 | * Add pinctrl pin ranges, the pin controller must be registered |
|---|
| .. | .. |
|---|
| 729 | 724 | return 0; |
|---|
| 730 | 725 | |
|---|
| 731 | 726 | err_no_range: |
|---|
| 732 | | -err_no_irqchip: |
|---|
| 733 | 727 | gpiochip_remove(&gpio->chip); |
|---|
| 734 | | -err_no_chip: |
|---|
| 728 | +err_dis_clk: |
|---|
| 735 | 729 | clk_disable_unprepare(gpio->clk); |
|---|
| 736 | 730 | dev_err(&pdev->dev, "module ERROR:%d\n", err); |
|---|
| 737 | 731 | return err; |
|---|