diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-25 11:19:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-25 11:19:14 -0400 |
commit | 51f00a471ce8f359627dd99aeac322947a0e491b (patch) | |
tree | de3f0c26359d7846fc5d6d0fdd147e225d979add /drivers/of/platform.c | |
parent | a7f505c6b15fb35c0de8136e370d2927ce29452c (diff) | |
parent | 97ff46cb69da22037346670ae515217c658ace02 (diff) |
Merge branch 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6
* 'next-devicetree' of git://git.secretlab.ca/git/linux-2.6:
mtd/m25p80: add support to parse the partitions by OF node
of/irq: of_irq.c needs to include linux/irq.h
of/mips: Cleanup some include directives/files.
of/mips: Add device tree support to MIPS
of/flattree: Eliminate need to provide early_init_dt_scan_chosen_arch
of/device: Rework to use common platform_device_alloc() for allocating devices
of/xsysace: Fix OF probing on little-endian systems
of: use __be32 types for big-endian device tree data
of/irq: remove references to NO_IRQ in drivers/of/platform.c
of/promtree: add package-to-path support to pdt
of/promtree: add of_pdt namespace to pdt code
of/promtree: no longer call prom_ functions directly; use an ops structure
of/promtree: make drivers/of/pdt.c no longer sparc-only
sparc: break out some PROM device-tree building code out into drivers/of
of/sparc: convert various prom_* functions to use phandle
sparc: stop exporting openprom.h header
powerpc, of_serial: Endianness issues setting up the serial ports
of: MTD: Fix OF probing on little-endian systems
of: GPIO: Fix OF probing on little-endian systems
Diffstat (limited to 'drivers/of/platform.c')
-rw-r--r-- | drivers/of/platform.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index bb72223c22ae..5b4a07f1220e 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -584,34 +584,33 @@ 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 | dev = platform_device_alloc("", -1); |
591 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
592 | num_reg++; | ||
593 | while (of_irq_to_resource(np, num_irq, &temp_res) != NO_IRQ) | ||
594 | num_irq++; | ||
595 | |||
596 | /* Allocate memory for both the struct device and the resource table */ | ||
597 | dev = kzalloc(sizeof(*dev) + (sizeof(*res) * (num_reg + num_irq)), | ||
598 | GFP_KERNEL); | ||
599 | if (!dev) | 591 | if (!dev) |
600 | return NULL; | 592 | return NULL; |
601 | res = (struct resource *) &dev[1]; | 593 | |
594 | /* count the io and irq resources */ | ||
595 | while (of_address_to_resource(np, num_reg, &temp_res) == 0) | ||
596 | num_reg++; | ||
597 | num_irq = of_irq_count(np); | ||
602 | 598 | ||
603 | /* Populate the resource table */ | 599 | /* Populate the resource table */ |
604 | if (num_irq || num_reg) { | 600 | if (num_irq || num_reg) { |
601 | res = kzalloc(sizeof(*res) * (num_irq + num_reg), GFP_KERNEL); | ||
602 | if (!res) { | ||
603 | platform_device_put(dev); | ||
604 | return NULL; | ||
605 | } | ||
606 | |||
605 | dev->num_resources = num_reg + num_irq; | 607 | dev->num_resources = num_reg + num_irq; |
606 | dev->resource = res; | 608 | dev->resource = res; |
607 | for (i = 0; i < num_reg; i++, res++) { | 609 | for (i = 0; i < num_reg; i++, res++) { |
608 | rc = of_address_to_resource(np, i, res); | 610 | rc = of_address_to_resource(np, i, res); |
609 | WARN_ON(rc); | 611 | WARN_ON(rc); |
610 | } | 612 | } |
611 | for (i = 0; i < num_irq; i++, res++) { | 613 | 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 | } | 614 | } |
616 | 615 | ||
617 | dev->dev.of_node = of_node_get(np); | 616 | dev->dev.of_node = of_node_get(np); |
@@ -619,7 +618,6 @@ struct platform_device *of_device_alloc(struct device_node *np, | |||
619 | dev->dev.dma_mask = &dev->archdata.dma_mask; | 618 | dev->dev.dma_mask = &dev->archdata.dma_mask; |
620 | #endif | 619 | #endif |
621 | dev->dev.parent = parent; | 620 | dev->dev.parent = parent; |
622 | dev->dev.release = of_release_dev; | ||
623 | 621 | ||
624 | if (bus_id) | 622 | if (bus_id) |
625 | dev_set_name(&dev->dev, "%s", bus_id); | 623 | dev_set_name(&dev->dev, "%s", bus_id); |
@@ -657,8 +655,8 @@ struct platform_device *of_platform_device_create(struct device_node *np, | |||
657 | * to do such, possibly using a device notifier | 655 | * to do such, possibly using a device notifier |
658 | */ | 656 | */ |
659 | 657 | ||
660 | if (of_device_register(dev) != 0) { | 658 | if (of_device_add(dev) != 0) { |
661 | of_device_free(dev); | 659 | platform_device_put(dev); |
662 | return NULL; | 660 | return NULL; |
663 | } | 661 | } |
664 | 662 | ||