diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2019-06-25 13:57:33 +0200 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2019-06-27 17:41:33 +0100 |
commit | aee5cec5bb27d8d3c2c13f371d156e5879309d0e (patch) | |
tree | e760e1a28459c32804b9824bc6bcb84eeb37d255 | |
parent | a4de43049a1d0e2ed2a1d95e18e74b82cd9ca058 (diff) |
gpio: ath79: Pass irqchip when adding gpiochip
We need to convert all old gpio irqchips to pass the irqchip
setup along when adding the gpio_chip.
For chained irqchips this is a pretty straight-forward
conversion.
Take this opportunity to add a local dev pointer and
use devm_gpiochip_add() so we can get rid of the remove()
callback altogether.
Cc: linux-mips@linux-mips.org
Acked-by: Alban Bedel <albeu@free.fr>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r-- | drivers/gpio/gpio-ath79.c | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/drivers/gpio/gpio-ath79.c b/drivers/gpio/gpio-ath79.c index 0a553d676042..190839b69dc0 100644 --- a/drivers/gpio/gpio-ath79.c +++ b/drivers/gpio/gpio-ath79.c @@ -225,14 +225,16 @@ MODULE_DEVICE_TABLE(of, ath79_gpio_of_match); static int ath79_gpio_probe(struct platform_device *pdev) { struct ath79_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); - struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; struct ath79_gpio_ctrl *ctrl; + struct gpio_irq_chip *girq; struct resource *res; u32 ath79_gpio_count; bool oe_inverted; int err; - ctrl = devm_kzalloc(&pdev->dev, sizeof(*ctrl), GFP_KERNEL); + ctrl = devm_kzalloc(dev, sizeof(*ctrl), GFP_KERNEL); if (!ctrl) return -ENOMEM; platform_set_drvdata(pdev, ctrl); @@ -240,7 +242,7 @@ static int ath79_gpio_probe(struct platform_device *pdev) if (np) { err = of_property_read_u32(np, "ngpios", &ath79_gpio_count); if (err) { - dev_err(&pdev->dev, "ngpios property is not valid\n"); + dev_err(dev, "ngpios property is not valid\n"); return err; } oe_inverted = of_device_is_compatible(np, "qca,ar9340-gpio"); @@ -248,25 +250,24 @@ static int ath79_gpio_probe(struct platform_device *pdev) ath79_gpio_count = pdata->ngpios; oe_inverted = pdata->oe_inverted; } else { - dev_err(&pdev->dev, "No DT node or platform data found\n"); + dev_err(dev, "No DT node or platform data found\n"); return -EINVAL; } if (ath79_gpio_count >= 32) { - dev_err(&pdev->dev, "ngpios must be less than 32\n"); + dev_err(dev, "ngpios must be less than 32\n"); return -EINVAL; } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) return -EINVAL; - ctrl->base = devm_ioremap_nocache( - &pdev->dev, res->start, resource_size(res)); + ctrl->base = devm_ioremap_nocache(dev, res->start, resource_size(res)); if (!ctrl->base) return -ENOMEM; raw_spin_lock_init(&ctrl->lock); - err = bgpio_init(&ctrl->gc, &pdev->dev, 4, + err = bgpio_init(&ctrl->gc, dev, 4, ctrl->base + AR71XX_GPIO_REG_IN, ctrl->base + AR71XX_GPIO_REG_SET, ctrl->base + AR71XX_GPIO_REG_CLEAR, @@ -274,45 +275,33 @@ static int ath79_gpio_probe(struct platform_device *pdev) oe_inverted ? ctrl->base + AR71XX_GPIO_REG_OE : NULL, 0); if (err) { - dev_err(&pdev->dev, "bgpio_init failed\n"); + dev_err(dev, "bgpio_init failed\n"); return err; } /* Use base 0 to stay compatible with legacy platforms */ ctrl->gc.base = 0; - err = gpiochip_add_data(&ctrl->gc, ctrl); - if (err) { - dev_err(&pdev->dev, - "cannot add AR71xx GPIO chip, error=%d", err); - return err; + /* Optional interrupt setup */ + if (!np || of_property_read_bool(np, "interrupt-controller")) { + girq = &ctrl->gc.irq; + girq->chip = &ath79_gpio_irqchip; + girq->parent_handler = ath79_gpio_irq_handler; + girq->num_parents = 1; + girq->parents = devm_kcalloc(dev, 1, sizeof(*girq->parents), + GFP_KERNEL); + if (!girq->parents) + return -ENOMEM; + girq->parents[0] = platform_get_irq(pdev, 0); + girq->default_type = IRQ_TYPE_NONE; + girq->handler = handle_simple_irq; } - if (np && !of_property_read_bool(np, "interrupt-controller")) - return 0; - - err = gpiochip_irqchip_add(&ctrl->gc, &ath79_gpio_irqchip, 0, - handle_simple_irq, IRQ_TYPE_NONE); + err = devm_gpiochip_add_data(dev, &ctrl->gc, ctrl); if (err) { - dev_err(&pdev->dev, "failed to add gpiochip_irqchip\n"); - goto gpiochip_remove; + dev_err(dev, + "cannot add AR71xx GPIO chip, error=%d", err); + return err; } - - gpiochip_set_chained_irqchip(&ctrl->gc, &ath79_gpio_irqchip, - platform_get_irq(pdev, 0), - ath79_gpio_irq_handler); - - return 0; - -gpiochip_remove: - gpiochip_remove(&ctrl->gc); - return err; -} - -static int ath79_gpio_remove(struct platform_device *pdev) -{ - struct ath79_gpio_ctrl *ctrl = platform_get_drvdata(pdev); - - gpiochip_remove(&ctrl->gc); return 0; } @@ -322,7 +311,6 @@ static struct platform_driver ath79_gpio_driver = { .of_match_table = ath79_gpio_of_match, }, .probe = ath79_gpio_probe, - .remove = ath79_gpio_remove, }; module_platform_driver(ath79_gpio_driver); |