Skip to content

Commit 94c0931

Browse files
committed
of: Merge of_device_alloc() and of_device_make_bus_id()
This patch merges the common routines of_device_alloc() and of_device_make_bus_id() from powerpc and microblaze. 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
1 parent 5fd200f commit 94c0931

8 files changed

Lines changed: 92 additions & 175 deletions

File tree

‎arch/microblaze/include/asm/of_device.h‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,4 @@
1010

1111
#ifndef _ASM_MICROBLAZE_OF_DEVICE_H
1212
#define _ASM_MICROBLAZE_OF_DEVICE_H
13-
#ifdef __KERNEL__
14-
15-
#include <linux/device.h>
16-
#include <linux/of.h>
17-
18-
extern struct of_device *of_device_alloc(struct device_node *np,
19-
const char *bus_id,
20-
struct device *parent);
21-
22-
extern void of_device_make_bus_id(struct of_device *dev);
23-
24-
/* This is just here during the transition */
25-
#include <linux/of_device.h>
26-
27-
#endif /* __KERNEL__ */
2813
#endif /* _ASM_MICROBLAZE_OF_DEVICE_H */

‎arch/microblaze/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif
1515
extra-y := head.o vmlinux.lds
1616

1717
obj-y += dma.o exceptions.o \
18-
hw_exception_handler.o init_task.o intc.o irq.o of_device.o \
18+
hw_exception_handler.o init_task.o intc.o irq.o \
1919
of_platform.o process.o prom.o prom_parse.o ptrace.o \
2020
setup.o signal.o sys_microblaze.o timer.o traps.o reset.o
2121

‎arch/microblaze/kernel/of_device.c‎

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
11
#ifndef _ASM_POWERPC_OF_DEVICE_H
22
#define _ASM_POWERPC_OF_DEVICE_H
3-
#ifdef __KERNEL__
4-
5-
#include <linux/device.h>
6-
#include <linux/of.h>
7-
8-
extern struct of_device *of_device_alloc(struct device_node *np,
9-
const char *bus_id,
10-
struct device *parent);
11-
12-
#endif /* __KERNEL__ */
133
#endif /* _ASM_POWERPC_OF_DEVICE_H */

‎arch/powerpc/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ obj-$(CONFIG_PPC_BOOK3E_64) += exceptions-64e.o
4040
obj-$(CONFIG_PPC64) += vdso64/
4141
obj-$(CONFIG_ALTIVEC) += vecemu.o
4242
obj-$(CONFIG_PPC_970_NAP) += idle_power4.o
43-
obj-$(CONFIG_PPC_OF) += of_device.o of_platform.o prom_parse.o
43+
obj-$(CONFIG_PPC_OF) += of_platform.o prom_parse.o
4444
obj-$(CONFIG_PPC_CLOCK) += clock.o
4545
procfs-y := proc_powerpc.o
4646
obj-$(CONFIG_PROC_FS) += $(procfs-y)

‎arch/powerpc/kernel/of_device.c‎

Lines changed: 0 additions & 84 deletions
This file was deleted.

‎drivers/of/platform.c‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,93 @@ EXPORT_SYMBOL(of_unregister_driver);
407407
* mechanism for creating devices from device tree nodes.
408408
*/
409409

410+
/**
411+
* of_device_make_bus_id - Use the device node data to assign a unique name
412+
* @dev: pointer to device structure that is linked to a device tree node
413+
*
414+
* This routine will first try using either the dcr-reg or the reg property
415+
* value to derive a unique name. As a last resort it will use the node
416+
* name followed by a unique number.
417+
*/
418+
static void of_device_make_bus_id(struct device *dev)
419+
{
420+
static atomic_t bus_no_reg_magic;
421+
struct device_node *node = dev->of_node;
422+
const u32 *reg;
423+
u64 addr;
424+
int magic;
425+
426+
#ifdef CONFIG_PPC_DCR
427+
/*
428+
* If it's a DCR based device, use 'd' for native DCRs
429+
* and 'D' for MMIO DCRs.
430+
*/
431+
reg = of_get_property(node, "dcr-reg", NULL);
432+
if (reg) {
433+
#ifdef CONFIG_PPC_DCR_NATIVE
434+
dev_set_name(dev, "d%x.%s", *reg, node->name);
435+
#else /* CONFIG_PPC_DCR_NATIVE */
436+
u64 addr = of_translate_dcr_address(node, *reg, NULL);
437+
if (addr != OF_BAD_ADDR) {
438+
dev_set_name(dev, "D%llx.%s",
439+
(unsigned long long)addr, node->name);
440+
return;
441+
}
442+
#endif /* !CONFIG_PPC_DCR_NATIVE */
443+
}
444+
#endif /* CONFIG_PPC_DCR */
445+
446+
/*
447+
* For MMIO, get the physical address
448+
*/
449+
reg = of_get_property(node, "reg", NULL);
450+
if (reg) {
451+
addr = of_translate_address(node, reg);
452+
if (addr != OF_BAD_ADDR) {
453+
dev_set_name(dev, "%llx.%s",
454+
(unsigned long long)addr, node->name);
455+
return;
456+
}
457+
}
458+
459+
/*
460+
* No BusID, use the node name and add a globally incremented
461+
* counter (and pray...)
462+
*/
463+
magic = atomic_add_return(1, &bus_no_reg_magic);
464+
dev_set_name(dev, "%s.%d", node->name, magic - 1);
465+
}
466+
467+
/**
468+
* of_device_alloc - Allocate and initialize an of_device
469+
* @np: device node to assign to device
470+
* @bus_id: Name to assign to the device. May be null to use default name.
471+
* @parent: Parent device.
472+
*/
473+
struct of_device *of_device_alloc(struct device_node *np,
474+
const char *bus_id,
475+
struct device *parent)
476+
{
477+
struct of_device *dev;
478+
479+
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
480+
if (!dev)
481+
return NULL;
482+
483+
dev->dev.of_node = of_node_get(np);
484+
dev->dev.dma_mask = &dev->archdata.dma_mask;
485+
dev->dev.parent = parent;
486+
dev->dev.release = of_release_dev;
487+
488+
if (bus_id)
489+
dev_set_name(&dev->dev, "%s", bus_id);
490+
else
491+
of_device_make_bus_id(&dev->dev);
492+
493+
return dev;
494+
}
495+
EXPORT_SYMBOL(of_device_alloc);
496+
410497
/**
411498
* of_platform_device_create - Alloc, initialize and register an of_device
412499
* @np: pointer to node to create device for

‎include/linux/of_platform.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ static inline void of_unregister_platform_driver(struct of_platform_driver *drv)
6060
of_unregister_driver(drv);
6161
}
6262

63+
extern struct of_device *of_device_alloc(struct device_node *np,
64+
const char *bus_id,
65+
struct device *parent);
6366
#include <asm/of_platform.h>
6467

6568
extern struct of_device *of_find_device_by_node(struct device_node *np);

0 commit comments

Comments
 (0)