1 #include <linux/string.h>
2 #include <linux/kernel.h>
4 #include <linux/init.h>
5 #include <linux/module.h>
6 #include <linux/mod_devicetable.h>
7 #include <linux/slab.h>
8 #include <linux/of_device.h>
10 #include <asm/errno.h>
13 static void of_device_make_bus_id(struct of_device *dev)
15 static atomic_t bus_no_reg_magic;
16 struct device_node *node = dev->dev.of_node;
22 * If it's a DCR based device, use 'd' for native DCRs
23 * and 'D' for MMIO DCRs.
26 reg = of_get_property(node, "dcr-reg", NULL);
28 #ifdef CONFIG_PPC_DCR_NATIVE
29 dev_set_name(&dev->dev, "d%x.%s", *reg, node->name);
30 #else /* CONFIG_PPC_DCR_NATIVE */
31 addr = of_translate_dcr_address(node, *reg, NULL);
32 if (addr != OF_BAD_ADDR) {
33 dev_set_name(&dev->dev, "D%llx.%s",
34 (unsigned long long)addr, node->name);
37 #endif /* !CONFIG_PPC_DCR_NATIVE */
39 #endif /* CONFIG_PPC_DCR */
42 * For MMIO, get the physical address
44 reg = of_get_property(node, "reg", NULL);
46 addr = of_translate_address(node, reg);
47 if (addr != OF_BAD_ADDR) {
48 dev_set_name(&dev->dev, "%llx.%s",
49 (unsigned long long)addr, node->name);
55 * No BusID, use the node name and add a globally incremented
56 * counter (and pray...)
58 magic = atomic_add_return(1, &bus_no_reg_magic);
59 dev_set_name(&dev->dev, "%s.%d", node->name, magic - 1);
62 struct of_device *of_device_alloc(struct device_node *np,
64 struct device *parent)
66 struct of_device *dev;
68 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
72 dev->dev.of_node = of_node_get(np);
73 dev->dev.dma_mask = &dev->archdata.dma_mask;
74 dev->dev.parent = parent;
75 dev->dev.release = of_release_dev;
78 dev_set_name(&dev->dev, "%s", bus_id);
80 of_device_make_bus_id(dev);
84 EXPORT_SYMBOL(of_device_alloc);