aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kernel/of_device.c
diff options
context:
space:
mode:
authorJoachim Fenkes <fenkes@de.ibm.com>2007-09-26 05:44:12 -0400
committerPaul Mackerras <paulus@samba.org>2007-10-17 08:30:07 -0400
commitfec738dd48bd33743c12cebe1bf954e487756231 (patch)
treead0423ca2db3cd22d161c117096337d9c3e2ccf4 /arch/powerpc/kernel/of_device.c
parentebb3e820b83e426ee331bae6d8fb0e54f472a25d (diff)
[POWERPC] Move of_device allocation into of_device.[ch]
Extract generic of_device allocation code from of_platform_device_create() and move it into of_device.[ch], called of_device_alloc(). Also, there's now of_device_free() which puts the device node. This way, bus drivers that build on of_platform (like ibmebus will) can build upon this code instead of reinventing the wheel. Signed-off-by: Joachim Fenkes <fenkes@de.ibm.com> Acked-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/kernel/of_device.c')
-rw-r--r--arch/powerpc/kernel/of_device.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
index 8f3db32fac8b..3388ad619996 100644
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -7,8 +7,88 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8 8
9#include <asm/errno.h> 9#include <asm/errno.h>
10#include <asm/dcr.h>
10#include <asm/of_device.h> 11#include <asm/of_device.h>
11 12
13static void of_device_make_bus_id(struct of_device *dev)
14{
15 static atomic_t bus_no_reg_magic;
16 struct device_node *node = dev->node;
17 char *name = dev->dev.bus_id;
18 const u32 *reg;
19 u64 addr;
20 int magic;
21
22 /*
23 * If it's a DCR based device, use 'd' for native DCRs
24 * and 'D' for MMIO DCRs.
25 */
26#ifdef CONFIG_PPC_DCR
27 reg = of_get_property(node, "dcr-reg", NULL);
28 if (reg) {
29#ifdef CONFIG_PPC_DCR_NATIVE
30 snprintf(name, BUS_ID_SIZE, "d%x.%s",
31 *reg, node->name);
32#else /* CONFIG_PPC_DCR_NATIVE */
33 addr = of_translate_dcr_address(node, *reg, NULL);
34 if (addr != OF_BAD_ADDR) {
35 snprintf(name, BUS_ID_SIZE,
36 "D%llx.%s", (unsigned long long)addr,
37 node->name);
38 return;
39 }
40#endif /* !CONFIG_PPC_DCR_NATIVE */
41 }
42#endif /* CONFIG_PPC_DCR */
43
44 /*
45 * For MMIO, get the physical address
46 */
47 reg = of_get_property(node, "reg", NULL);
48 if (reg) {
49 addr = of_translate_address(node, reg);
50 if (addr != OF_BAD_ADDR) {
51 snprintf(name, BUS_ID_SIZE,
52 "%llx.%s", (unsigned long long)addr,
53 node->name);
54 return;
55 }
56 }
57
58 /*
59 * No BusID, use the node name and add a globally incremented
60 * counter (and pray...)
61 */
62 magic = atomic_add_return(1, &bus_no_reg_magic);
63 snprintf(name, BUS_ID_SIZE, "%s.%d", node->name, magic - 1);
64}
65
66struct of_device *of_device_alloc(struct device_node *np,
67 const char *bus_id,
68 struct device *parent)
69{
70 struct of_device *dev;
71
72 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
73 if (!dev)
74 return NULL;
75
76 dev->node = of_node_get(np);
77 dev->dev.dma_mask = &dev->dma_mask;
78 dev->dev.parent = parent;
79 dev->dev.release = of_release_dev;
80 dev->dev.archdata.of_node = np;
81 dev->dev.archdata.numa_node = of_node_to_nid(np);
82
83 if (bus_id)
84 strlcpy(dev->dev.bus_id, bus_id, BUS_ID_SIZE);
85 else
86 of_device_make_bus_id(dev);
87
88 return dev;
89}
90EXPORT_SYMBOL(of_device_alloc);
91
12ssize_t of_device_get_modalias(struct of_device *ofdev, 92ssize_t of_device_get_modalias(struct of_device *ofdev,
13 char *str, ssize_t len) 93 char *str, ssize_t len)
14{ 94{