aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/of/irq.c39
-rw-r--r--drivers/of/platform.c10
-rw-r--r--include/linux/of_irq.h3
3 files changed, 45 insertions, 7 deletions
diff --git a/drivers/of/irq.c b/drivers/of/irq.c
index 6e595e5a3977..75b0d3cb7676 100644
--- a/drivers/of/irq.c
+++ b/drivers/of/irq.c
@@ -24,6 +24,11 @@
24#include <linux/of_irq.h> 24#include <linux/of_irq.h>
25#include <linux/string.h> 25#include <linux/string.h>
26 26
27/* For archs that don't support NO_IRQ (such as x86), provide a dummy value */
28#ifndef NO_IRQ
29#define NO_IRQ 0
30#endif
31
27/** 32/**
28 * irq_of_parse_and_map - Parse and map an interrupt into linux virq space 33 * irq_of_parse_and_map - Parse and map an interrupt into linux virq space
29 * @device: Device node of the device whose interrupt is to be mapped 34 * @device: Device node of the device whose interrupt is to be mapped
@@ -347,3 +352,37 @@ int of_irq_to_resource(struct device_node *dev, int index, struct resource *r)
347 return irq; 352 return irq;
348} 353}
349EXPORT_SYMBOL_GPL(of_irq_to_resource); 354EXPORT_SYMBOL_GPL(of_irq_to_resource);
355
356/**
357 * of_irq_count - Count the number of IRQs a node uses
358 * @dev: pointer to device tree node
359 */
360int of_irq_count(struct device_node *dev)
361{
362 int nr = 0;
363
364 while (of_irq_to_resource(dev, nr, NULL) != NO_IRQ)
365 nr++;
366
367 return nr;
368}
369
370/**
371 * of_irq_to_resource_table - Fill in resource table with node's IRQ info
372 * @dev: pointer to device tree node
373 * @res: array of resources to fill in
374 * @nr_irqs: the number of IRQs (and upper bound for num of @res elements)
375 *
376 * Returns the size of the filled in table (up to @nr_irqs).
377 */
378int of_irq_to_resource_table(struct device_node *dev, struct resource *res,
379 int nr_irqs)
380{
381 int i;
382
383 for (i = 0; i < nr_irqs; i++, res++)
384 if (of_irq_to_resource(dev, i, res) == NO_IRQ)
385 break;
386
387 return i;
388}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index bb72223c22ae..30726c8b0693 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -584,14 +584,13 @@ struct platform_device *of_device_alloc(struct device_node *np,
584 struct device *parent) 584 struct device *parent)
585{ 585{
586 struct platform_device *dev; 586 struct platform_device *dev;
587 int rc, i, num_reg = 0, num_irq = 0; 587 int rc, i, num_reg = 0, num_irq;
588 struct resource *res, temp_res; 588 struct resource *res, temp_res;
589 589
590 /* First count how many resources are needed */ 590 /* First count how many resources are needed */
591 while (of_address_to_resource(np, num_reg, &temp_res) == 0) 591 while (of_address_to_resource(np, num_reg, &temp_res) == 0)
592 num_reg++; 592 num_reg++;
593 while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ) 593 num_irq = of_irq_count(np);
594 num_irq++;
595 594
596 /* Allocate memory for both the struct device and the resource table */ 595 /* Allocate memory for both the struct device and the resource table */
597 dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), 596 dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)),
@@ -608,10 +607,7 @@ struct platform_device *of_device_alloc(struct device_node *np,
608 rc = of_address_to_resource(np, i, res); 607 rc = of_address_to_resource(np, i, res);
609 WARN_ON(rc); 608 WARN_ON(rc);
610 } 609 }
611 for (i = 0; i < num_irq; i++, res++) { 610 WARN_ON(of_irq_to_resource_table(np, res, num_irq) != num_irq);
612 rc = of_irq_to_resource(np, i, res);
613 WARN_ON(rc == NO_IRQ);
614 }
615 } 611 }
616 612
617 dev->dev.of_node = of_node_get(np); 613 dev->dev.of_node = of_node_get(np);
diff --git a/include/linux/of_irq.h b/include/linux/of_irq.h
index 5929781c104d..090cbaa4bd36 100644
--- a/include/linux/of_irq.h
+++ b/include/linux/of_irq.h
@@ -64,6 +64,9 @@ extern unsigned int irq_create_of_mapping(struct device_node *controller,
64 unsigned int intsize); 64 unsigned int intsize);
65extern int of_irq_to_resource(struct device_node *dev, int index, 65extern int of_irq_to_resource(struct device_node *dev, int index,
66 struct resource *r); 66 struct resource *r);
67extern int of_irq_count(struct device_node *dev);
68extern int of_irq_to_resource_table(struct device_node *dev,
69 struct resource *res, int nr_irqs);
67 70
68#endif /* CONFIG_OF_IRQ */ 71#endif /* CONFIG_OF_IRQ */
69#endif /* CONFIG_OF */ 72#endif /* CONFIG_OF */