aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:15 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:29 -0400
commitac80a51e2ce5c431de9997085f33cb6093218b1f (patch)
tree4f0137a0a5848cb20de5621b098bcfc44d82707c /drivers/of
parent94c0931983ee9d1cd96c32d52ac64c17464f0bbd (diff)
of/device: populate platform_device (of_device) resource table on allocation
When allocating a platform_device to represent an OF node, also allocate space for the resource table and populate it with IRQ and reg property information. This change is in preparation for merging the of_platform_bus_type with the platform_bus_type so that existing platform_driver code can retrieve base addresses and IRQs data. Background: a previous commit removed struct of_device and made it a #define alias for platform_device. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> CC: Michal Simek <monstr@monstr.eu> CC: Grant Likely <grant.likely@secretlab.ca> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: Stephen Rothwell <sfr@canb.auug.org.au> CC: microblaze-uclinux@itee.uq.edu.au CC: linuxppc-dev@ozlabs.org CC: devicetree-discuss@lists.ozlabs.org
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/platform.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ea87a3cf7860..5cc9a8e91be5 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -475,10 +475,35 @@ struct of_device *of_device_alloc(struct device_node *np,
475 struct device *parent) 475 struct device *parent)
476{ 476{
477 struct of_device *dev; 477 struct of_device *dev;
478 478 int rc, i, num_reg = 0, num_irq = 0;
479 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 479 struct resource *res, temp_res;
480
481 /* First count how many resources are needed */
482 while (of_address_to_resource(np, num_reg, &temp_res) == 0)
483 num_reg++;
484 while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ)
485 num_irq++;
486
487 /* Allocate memory for both the struct device and the resource table */
488 dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)),
489 GFP_KERNEL);
480 if (!dev) 490 if (!dev)
481 return NULL; 491 return NULL;
492 res = (struct resource *) &dev[1];
493
494 /* Populate the resource table */
495 if (num_irq || num_reg) {
496 dev->num_resources = num_reg + num_irq;
497 dev->resource = res;
498 for (i = 0; i < num_reg; i++, res++) {
499 rc = of_address_to_resource(np, i, res);
500 WARN_ON(rc);
501 }
502 for (i = 0; i < num_irq; i++, res++) {
503 rc = of_irq_to_resource(np, i, res);
504 WARN_ON(rc == NO_IRQ);
505 }
506 }
482 507
483 dev->dev.of_node = of_node_get(np); 508 dev->dev.of_node = of_node_get(np);
484 dev->dev.dma_mask = &dev->archdata.dma_mask; 509 dev->dev.dma_mask = &dev->archdata.dma_mask;