Commit e4bfb0ff authored by Linus Walleij's avatar Linus Walleij

gpio: ixp4xx: Add OF probing support

This adds device tree probe and registration support for
the IXP4xx GPIO driver.

Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent e8e2f565
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/irqdomain.h> #include <linux/irqdomain.h>
#include <linux/irqchip.h> #include <linux/irqchip.h>
#include <linux/of_irq.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/bitops.h> #include <linux/bitops.h>
/* Include that go away with DT transition */ /* Include that go away with DT transition */
...@@ -306,6 +307,7 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) ...@@ -306,6 +307,7 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
{ {
unsigned long flags; unsigned long flags;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
struct irq_domain *parent; struct irq_domain *parent;
struct resource *res; struct resource *res;
struct ixp4xx_gpio *g; struct ixp4xx_gpio *g;
...@@ -382,11 +384,27 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) ...@@ -382,11 +384,27 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
* from IRQCHIP_DECLARE(), then use of_node_to_fwnode() to get * from IRQCHIP_DECLARE(), then use of_node_to_fwnode() to get
* the fwnode. For now we need this boardfile style code. * the fwnode. For now we need this boardfile style code.
*/ */
parent = ixp4xx_get_irq_domain(); if (np) {
g->fwnode = irq_domain_alloc_fwnode(g->base); struct device_node *irq_parent;
if (!g->fwnode) {
dev_err(dev, "no domain base\n"); irq_parent = of_irq_find_parent(np);
return -ENODEV; if (!irq_parent) {
dev_err(dev, "no IRQ parent node\n");
return -ENODEV;
}
parent = irq_find_host(irq_parent);
if (!parent) {
dev_err(dev, "no IRQ parent domain\n");
return -ENODEV;
}
g->fwnode = of_node_to_fwnode(np);
} else {
parent = ixp4xx_get_irq_domain();
g->fwnode = irq_domain_alloc_fwnode(g->base);
if (!g->fwnode) {
dev_err(dev, "no domain base\n");
return -ENODEV;
}
} }
g->domain = irq_domain_create_hierarchy(parent, g->domain = irq_domain_create_hierarchy(parent,
IRQ_DOMAIN_FLAG_HIERARCHY, IRQ_DOMAIN_FLAG_HIERARCHY,
...@@ -404,28 +422,31 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) ...@@ -404,28 +422,31 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
* After adding OF support, this is no longer needed: irqs * After adding OF support, this is no longer needed: irqs
* will be allocated for the respective fwnodes. * will be allocated for the respective fwnodes.
*/ */
for (i = 0; i < ARRAY_SIZE(ixp4xx_gpiomap); i++) { if (!np) {
const struct ixp4xx_gpio_map *map = &ixp4xx_gpiomap[i]; for (i = 0; i < ARRAY_SIZE(ixp4xx_gpiomap); i++) {
struct irq_fwspec fwspec; const struct ixp4xx_gpio_map *map = &ixp4xx_gpiomap[i];
struct irq_fwspec fwspec;
fwspec.fwnode = g->fwnode;
/* This is the hwirq for the GPIO line side of things */ fwspec.fwnode = g->fwnode;
fwspec.param[0] = map->gpio_offset; /* This is the hwirq for the GPIO line side of things */
fwspec.param[1] = IRQ_TYPE_EDGE_RISING; fwspec.param[0] = map->gpio_offset;
fwspec.param_count = 2; fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
ret = __irq_domain_alloc_irqs(g->domain, fwspec.param_count = 2;
-1, /* just pick something */ ret = __irq_domain_alloc_irqs(g->domain,
1, -1, /* just pick something */
NUMA_NO_NODE, 1,
&fwspec, NUMA_NO_NODE,
false, &fwspec,
NULL); false,
if (ret < 0) { NULL);
irq_domain_free_fwnode(g->fwnode); if (ret < 0) {
dev_err(dev, irq_domain_free_fwnode(g->fwnode);
"can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n", dev_err(dev,
map->gpio_offset, map->parent_hwirq, ret); "can not allocate irq for GPIO line %d parent hwirq %d in hierarchy domain: %d\n",
return ret; map->gpio_offset, map->parent_hwirq,
ret);
return ret;
}
} }
} }
...@@ -435,9 +456,18 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev) ...@@ -435,9 +456,18 @@ static int ixp4xx_gpio_probe(struct platform_device *pdev)
return 0; return 0;
} }
static const struct of_device_id ixp4xx_gpio_of_match[] = {
{
.compatible = "intel,ixp4xx-gpio",
},
{},
};
static struct platform_driver ixp4xx_gpio_driver = { static struct platform_driver ixp4xx_gpio_driver = {
.driver = { .driver = {
.name = "ixp4xx-gpio", .name = "ixp4xx-gpio",
.of_match_table = of_match_ptr(ixp4xx_gpio_of_match),
}, },
.probe = ixp4xx_gpio_probe, .probe = ixp4xx_gpio_probe,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment