From 97e873e5c8ad8711ce4cca080cff4eb5d21b3aeb Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 1 May 2007 16:26:07 +1000 Subject: Start split out of common open firmware code This creates drivers/of/base.c (depending on CONFIG_OF) and puts the first trivially common bits from the prom.c files into it. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/Kconfig | 3 +++ arch/powerpc/kernel/prom.c | 41 ----------------------------------------- arch/sparc/Kconfig | 3 +++ arch/sparc/kernel/prom.c | 42 ------------------------------------------ arch/sparc64/Kconfig | 3 +++ arch/sparc64/kernel/prom.c | 42 ------------------------------------------ 6 files changed, 9 insertions(+), 125 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d860b640a140..853c282da22e 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -92,6 +92,9 @@ config ARCH_MAY_HAVE_PC_FDC config PPC_OF def_bool y +config OF + def_bool y + config PPC_UDBG_16550 bool default n diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 37ff99bd98b4..6c9419a4d70a 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -1056,35 +1056,6 @@ void __init early_init_devtree(void *params) DBG(" <- early_init_devtree()\n"); } -int of_n_addr_cells(struct device_node* np) -{ - const int *ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#address-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #address-cells property for the root node, default to 1 */ - return 1; -} -EXPORT_SYMBOL(of_n_addr_cells); - -int of_n_size_cells(struct device_node* np) -{ - const int* ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#size-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #size-cells property for the root node, default to 1 */ - return 1; -} -EXPORT_SYMBOL(of_n_size_cells); /** Checks if the given "compat" string matches one of the strings in * the device's "compatible" property @@ -1562,18 +1533,6 @@ struct property *of_find_property(const struct device_node *np, } EXPORT_SYMBOL(of_find_property); -/* - * Find a property with a given name for a given node - * and return the value. - */ -const void *of_get_property(const struct device_node *np, const char *name, - int *lenp) -{ - struct property *pp = of_find_property(np,name,lenp); - return pp ? pp->value : NULL; -} -EXPORT_SYMBOL(of_get_property); - /* * Add a property to a node */ diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig index 603d83ad65c8..9d327ec59759 100644 --- a/arch/sparc/Kconfig +++ b/arch/sparc/Kconfig @@ -24,6 +24,9 @@ config GENERIC_ISA_DMA config ARCH_NO_VIRT_TO_BUS def_bool y +config OF + def_bool y + source "init/Kconfig" menu "General machine setup" diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index eed140b3c739..ac3f3c29b174 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -168,18 +168,6 @@ struct property *of_find_property(const struct device_node *np, } EXPORT_SYMBOL(of_find_property); -/* - * Find a property with a given name for a given node - * and return the value. - */ -const void *of_get_property(const struct device_node *np, const char *name, - int *lenp) -{ - struct property *pp = of_find_property(np,name,lenp); - return pp ? pp->value : NULL; -} -EXPORT_SYMBOL(of_get_property); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; @@ -193,36 +181,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def) } EXPORT_SYMBOL(of_getintprop_default); -int of_n_addr_cells(struct device_node *np) -{ - const int* ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#address-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #address-cells property for the root node, default to 2 */ - return 2; -} -EXPORT_SYMBOL(of_n_addr_cells); - -int of_n_size_cells(struct device_node *np) -{ - const int* ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#size-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #size-cells property for the root node, default to 1 */ - return 1; -} -EXPORT_SYMBOL(of_n_size_cells); - int of_set_property(struct device_node *dp, const char *name, void *val, int len) { struct property **prevp; diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig index df6ee71894d1..f1cc55677ff2 100644 --- a/arch/sparc64/Kconfig +++ b/arch/sparc64/Kconfig @@ -65,6 +65,9 @@ config AUDIT_ARCH config ARCH_NO_VIRT_TO_BUS def_bool y +config OF + def_bool y + choice prompt "Kernel page size" default SPARC64_PAGE_SIZE_8KB diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 5d220302cd50..8f926d439c0f 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -173,18 +173,6 @@ struct property *of_find_property(const struct device_node *np, } EXPORT_SYMBOL(of_find_property); -/* - * Find a property with a given name for a given node - * and return the value. - */ -const void *of_get_property(const struct device_node *np, const char *name, - int *lenp) -{ - struct property *pp = of_find_property(np,name,lenp); - return pp ? pp->value : NULL; -} -EXPORT_SYMBOL(of_get_property); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; @@ -198,36 +186,6 @@ int of_getintprop_default(struct device_node *np, const char *name, int def) } EXPORT_SYMBOL(of_getintprop_default); -int of_n_addr_cells(struct device_node *np) -{ - const int* ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#address-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #address-cells property for the root node, default to 2 */ - return 2; -} -EXPORT_SYMBOL(of_n_addr_cells); - -int of_n_size_cells(struct device_node *np) -{ - const int* ip; - do { - if (np->parent) - np = np->parent; - ip = of_get_property(np, "#size-cells", NULL); - if (ip != NULL) - return *ip; - } while (np->parent); - /* No #size-cells property for the root node, default to 1 */ - return 1; -} -EXPORT_SYMBOL(of_n_size_cells); - int of_set_property(struct device_node *dp, const char *name, void *val, int len) { struct property **prevp; -- cgit v1.2.1 From 0081cbc3731de8ad4744ba433af51f17bf27eb9c Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 1 May 2007 16:29:19 +1000 Subject: Consolidate of_device_is_compatible The only difference here is that Sparc uses strncmp to match compatibility names while PowerPC uses strncasecmp. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/prom.c | 25 ------------------------- arch/sparc/kernel/prom.c | 21 --------------------- arch/sparc64/kernel/prom.c | 21 --------------------- 3 files changed, 67 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 6c9419a4d70a..c009d2155f9c 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -1057,31 +1057,6 @@ void __init early_init_devtree(void *params) } -/** Checks if the given "compat" string matches one of the strings in - * the device's "compatible" property - */ -int of_device_is_compatible(const struct device_node *device, - const char *compat) -{ - const char* cp; - int cplen, l; - - cp = of_get_property(device, "compatible", &cplen); - if (cp == NULL) - return 0; - while (cplen > 0) { - if (strncasecmp(cp, compat, strlen(compat)) == 0) - return 1; - l = strlen(cp) + 1; - cp += l; - cplen -= l; - } - - return 0; -} -EXPORT_SYMBOL(of_device_is_compatible); - - /** * Indicates whether the root node has a given value in its * compatible property. diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index ac3f3c29b174..f2ce0d48e102 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -32,27 +32,6 @@ static struct device_node *allnodes; */ static DEFINE_RWLOCK(devtree_lock); -int of_device_is_compatible(const struct device_node *device, - const char *compat) -{ - const char* cp; - int cplen, l; - - cp = of_get_property(device, "compatible", &cplen); - if (cp == NULL) - return 0; - while (cplen > 0) { - if (strncmp(cp, compat, strlen(compat)) == 0) - return 1; - l = strlen(cp) + 1; - cp += l; - cplen -= l; - } - - return 0; -} -EXPORT_SYMBOL(of_device_is_compatible); - struct device_node *of_get_parent(const struct device_node *node) { struct device_node *np; diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 8f926d439c0f..4d6fb07f047f 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -37,27 +37,6 @@ static struct device_node *allnodes; */ static DEFINE_RWLOCK(devtree_lock); -int of_device_is_compatible(const struct device_node *device, - const char *compat) -{ - const char* cp; - int cplen, l; - - cp = of_get_property(device, "compatible", &cplen); - if (cp == NULL) - return 0; - while (cplen > 0) { - if (strncmp(cp, compat, strlen(compat)) == 0) - return 1; - l = strlen(cp) + 1; - cp += l; - cplen -= l; - } - - return 0; -} -EXPORT_SYMBOL(of_device_is_compatible); - struct device_node *of_get_parent(const struct device_node *node) { struct device_node *np; -- cgit v1.2.1 From 581b605a83ec241a2aff8ef780e08b9414c8dfd8 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 24 Apr 2007 16:46:53 +1000 Subject: Consolidate of_find_property The only change here is that a readlock is taken while the property list is being traversed on Sparc where it was not taken previously. Also, Sparc uses strcasecmp to compare property names while PowerPC uses strcmp. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/prom.c | 24 +----------------------- arch/sparc/kernel/prom.c | 22 +--------------------- arch/sparc64/kernel/prom.c | 22 +--------------------- 3 files changed, 3 insertions(+), 65 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index c009d2155f9c..3f6238d96a5d 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -80,10 +80,7 @@ struct boot_param_header *initial_boot_params; static struct device_node *allnodes = NULL; -/* use when traversing tree through the allnext, child, sibling, - * or parent members of struct device_node. - */ -static DEFINE_RWLOCK(devtree_lock); +extern rwlock_t devtree_lock; /* temporary while merging */ /* export that to outside world */ struct device_node *of_chosen; @@ -1489,25 +1486,6 @@ static int __init prom_reconfig_setup(void) __initcall(prom_reconfig_setup); #endif -struct property *of_find_property(const struct device_node *np, - const char *name, - int *lenp) -{ - struct property *pp; - - read_lock(&devtree_lock); - for (pp = np->properties; pp != 0; pp = pp->next) - if (strcmp(pp->name, name) == 0) { - if (lenp != 0) - *lenp = pp->length; - break; - } - read_unlock(&devtree_lock); - - return pp; -} -EXPORT_SYMBOL(of_find_property); - /* * Add a property to a node */ diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index f2ce0d48e102..0f5aab4326b3 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -27,10 +27,7 @@ static struct device_node *allnodes; -/* use when traversing tree through the allnext, child, sibling, - * or parent members of struct device_node. - */ -static DEFINE_RWLOCK(devtree_lock); +extern rwlock_t devtree_lock; /* temporary while merging */ struct device_node *of_get_parent(const struct device_node *node) { @@ -130,23 +127,6 @@ struct device_node *of_find_compatible_node(struct device_node *from, } EXPORT_SYMBOL(of_find_compatible_node); -struct property *of_find_property(const struct device_node *np, - const char *name, - int *lenp) -{ - struct property *pp; - - for (pp = np->properties; pp != 0; pp = pp->next) { - if (strcasecmp(pp->name, name) == 0) { - if (lenp != 0) - *lenp = pp->length; - break; - } - } - return pp; -} -EXPORT_SYMBOL(of_find_property); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 4d6fb07f047f..a1ccc00c7958 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -32,10 +32,7 @@ static struct device_node *allnodes; -/* use when traversing tree through the allnext, child, sibling, - * or parent members of struct device_node. - */ -static DEFINE_RWLOCK(devtree_lock); +extern rwlock_t devtree_lock; /* temporary while merging */ struct device_node *of_get_parent(const struct device_node *node) { @@ -135,23 +132,6 @@ struct device_node *of_find_compatible_node(struct device_node *from, } EXPORT_SYMBOL(of_find_compatible_node); -struct property *of_find_property(const struct device_node *np, - const char *name, - int *lenp) -{ - struct property *pp; - - for (pp = np->properties; pp != 0; pp = pp->next) { - if (strcasecmp(pp->name, name) == 0) { - if (lenp != 0) - *lenp = pp->length; - break; - } - } - return pp; -} -EXPORT_SYMBOL(of_find_property); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; -- cgit v1.2.1 From e679c5f445fe142940e0962de9c5c82f10d9357c Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 24 Apr 2007 17:16:16 +1000 Subject: Consolidate of_get_parent This requires creating dummy of_node_{get,put} routines for sparc and sparc64. It also adds a read_lock around the parent accesses. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/prom.c | 21 --------------------- arch/sparc/kernel/prom.c | 13 ------------- arch/sparc64/kernel/prom.c | 13 ------------- 3 files changed, 47 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 3f6238d96a5d..1ad56d3c6061 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -1240,27 +1240,6 @@ struct device_node *of_find_all_nodes(struct device_node *prev) } EXPORT_SYMBOL(of_find_all_nodes); -/** - * of_get_parent - Get a node's parent if any - * @node: Node to get parent - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_get_parent(const struct device_node *node) -{ - struct device_node *np; - - if (!node) - return NULL; - - read_lock(&devtree_lock); - np = of_node_get(node->parent); - read_unlock(&devtree_lock); - return np; -} -EXPORT_SYMBOL(of_get_parent); - /** * of_get_next_child - Iterate a node childs * @node: parent node diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index 0f5aab4326b3..b37871578087 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -29,19 +29,6 @@ static struct device_node *allnodes; extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_get_parent(const struct device_node *node) -{ - struct device_node *np; - - if (!node) - return NULL; - - np = node->parent; - - return np; -} -EXPORT_SYMBOL(of_get_parent); - struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev) { diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index a1ccc00c7958..2462731ac1a3 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -34,19 +34,6 @@ static struct device_node *allnodes; extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_get_parent(const struct device_node *node) -{ - struct device_node *np; - - if (!node) - return NULL; - - np = node->parent; - - return np; -} -EXPORT_SYMBOL(of_get_parent); - struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev) { -- cgit v1.2.1 From d1cd355a5e44dfe993efc0c0458ca9f99a28a9a3 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 24 Apr 2007 17:21:29 +1000 Subject: Consolidate of_get_next_child This adds a read_lock around the child/next accesses on Sparc. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/prom.c | 24 ------------------------ arch/sparc/kernel/prom.c | 14 -------------- arch/sparc64/kernel/prom.c | 14 -------------- 3 files changed, 52 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 1ad56d3c6061..5fa221ce8714 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -1240,30 +1240,6 @@ struct device_node *of_find_all_nodes(struct device_node *prev) } EXPORT_SYMBOL(of_find_all_nodes); -/** - * of_get_next_child - Iterate a node childs - * @node: parent node - * @prev: previous child of the parent node, or NULL to get first - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_get_next_child(const struct device_node *node, - struct device_node *prev) -{ - struct device_node *next; - - read_lock(&devtree_lock); - next = prev ? prev->sibling : node->child; - for (; next != 0; next = next->sibling) - if (of_node_get(next)) - break; - of_node_put(prev); - read_unlock(&devtree_lock); - return next; -} -EXPORT_SYMBOL(of_get_next_child); - /** * of_node_get - Increment refcount of a node * @node: Node to inc refcount, NULL is supported to diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index b37871578087..3f8ccfad2e01 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -29,20 +29,6 @@ static struct device_node *allnodes; extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_get_next_child(const struct device_node *node, - struct device_node *prev) -{ - struct device_node *next; - - next = prev ? prev->sibling : node->child; - for (; next != 0; next = next->sibling) { - break; - } - - return next; -} -EXPORT_SYMBOL(of_get_next_child); - struct device_node *of_find_node_by_path(const char *path) { struct device_node *np = allnodes; diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index 2462731ac1a3..ee96ef61bc99 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -34,20 +34,6 @@ static struct device_node *allnodes; extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_get_next_child(const struct device_node *node, - struct device_node *prev) -{ - struct device_node *next; - - next = prev ? prev->sibling : node->child; - for (; next != 0; next = next->sibling) { - break; - } - - return next; -} -EXPORT_SYMBOL(of_get_next_child); - struct device_node *of_find_node_by_path(const char *path) { struct device_node *np = allnodes; -- cgit v1.2.1 From 1ef4d4242d9c494c49ae1ae66dc938fce0272816 Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 24 Apr 2007 17:57:33 +1000 Subject: Consolidate of_find_node_by routines This consolidates the routines of_find_node_by_path, of_find_node_by_name, of_find_node_by_type and of_find_compatible_device. Again, the comparison of strings are done differently by Sparc and PowerPC and also these add read_locks around the iterations. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/prom.c | 115 +-------------------------------------------- arch/sparc/kernel/prom.c | 61 +----------------------- arch/sparc64/kernel/prom.c | 61 +----------------------- 3 files changed, 3 insertions(+), 234 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 5fa221ce8714..bdcd23d8d8b9 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c @@ -78,7 +78,7 @@ static struct boot_param_header *initial_boot_params __initdata; struct boot_param_header *initial_boot_params; #endif -static struct device_node *allnodes = NULL; +extern struct device_node *allnodes; /* temporary while merging */ extern rwlock_t devtree_lock; /* temporary while merging */ @@ -1083,119 +1083,6 @@ EXPORT_SYMBOL(machine_is_compatible); * *******/ -/** - * of_find_node_by_name - Find a node by its "name" property - * @from: The node to start searching from or NULL, the node - * you pass will not be searched, only the next one - * will; typically, you pass what the previous call - * returned. of_node_put() will be called on it - * @name: The name string to match against - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_find_node_by_name(struct device_node *from, - const char *name) -{ - struct device_node *np; - - read_lock(&devtree_lock); - np = from ? from->allnext : allnodes; - for (; np != NULL; np = np->allnext) - if (np->name != NULL && strcasecmp(np->name, name) == 0 - && of_node_get(np)) - break; - of_node_put(from); - read_unlock(&devtree_lock); - return np; -} -EXPORT_SYMBOL(of_find_node_by_name); - -/** - * of_find_node_by_type - Find a node by its "device_type" property - * @from: The node to start searching from, or NULL to start searching - * the entire device tree. The node you pass will not be - * searched, only the next one will; typically, you pass - * what the previous call returned. of_node_put() will be - * called on from for you. - * @type: The type string to match against - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_find_node_by_type(struct device_node *from, - const char *type) -{ - struct device_node *np; - - read_lock(&devtree_lock); - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) - if (np->type != 0 && strcasecmp(np->type, type) == 0 - && of_node_get(np)) - break; - of_node_put(from); - read_unlock(&devtree_lock); - return np; -} -EXPORT_SYMBOL(of_find_node_by_type); - -/** - * of_find_compatible_node - Find a node based on type and one of the - * tokens in its "compatible" property - * @from: The node to start searching from or NULL, the node - * you pass will not be searched, only the next one - * will; typically, you pass what the previous call - * returned. of_node_put() will be called on it - * @type: The type string to match "device_type" or NULL to ignore - * @compatible: The string to match to one of the tokens in the device - * "compatible" list. - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_find_compatible_node(struct device_node *from, - const char *type, const char *compatible) -{ - struct device_node *np; - - read_lock(&devtree_lock); - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) { - if (type != NULL - && !(np->type != 0 && strcasecmp(np->type, type) == 0)) - continue; - if (of_device_is_compatible(np, compatible) && of_node_get(np)) - break; - } - of_node_put(from); - read_unlock(&devtree_lock); - return np; -} -EXPORT_SYMBOL(of_find_compatible_node); - -/** - * of_find_node_by_path - Find a node matching a full OF path - * @path: The full path to match - * - * Returns a node pointer with refcount incremented, use - * of_node_put() on it when done. - */ -struct device_node *of_find_node_by_path(const char *path) -{ - struct device_node *np = allnodes; - - read_lock(&devtree_lock); - for (; np != 0; np = np->allnext) { - if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0 - && of_node_get(np)) - break; - } - read_unlock(&devtree_lock); - return np; -} -EXPORT_SYMBOL(of_find_node_by_path); - /** * of_find_node_by_phandle - Find a node given a phandle * @handle: phandle of the node to find diff --git a/arch/sparc/kernel/prom.c b/arch/sparc/kernel/prom.c index 3f8ccfad2e01..012f98346bcd 100644 --- a/arch/sparc/kernel/prom.c +++ b/arch/sparc/kernel/prom.c @@ -25,23 +25,10 @@ #include #include -static struct device_node *allnodes; +extern struct device_node *allnodes; /* temporary while merging */ extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_find_node_by_path(const char *path) -{ - struct device_node *np = allnodes; - - for (; np != 0; np = np->allnext) { - if (np->full_name != 0 && strcmp(np->full_name, path) == 0) - break; - } - - return np; -} -EXPORT_SYMBOL(of_find_node_by_path); - struct device_node *of_find_node_by_phandle(phandle handle) { struct device_node *np; @@ -54,52 +41,6 @@ struct device_node *of_find_node_by_phandle(phandle handle) } EXPORT_SYMBOL(of_find_node_by_phandle); -struct device_node *of_find_node_by_name(struct device_node *from, - const char *name) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != NULL; np = np->allnext) - if (np->name != NULL && strcmp(np->name, name) == 0) - break; - - return np; -} -EXPORT_SYMBOL(of_find_node_by_name); - -struct device_node *of_find_node_by_type(struct device_node *from, - const char *type) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) - if (np->type != 0 && strcmp(np->type, type) == 0) - break; - - return np; -} -EXPORT_SYMBOL(of_find_node_by_type); - -struct device_node *of_find_compatible_node(struct device_node *from, - const char *type, const char *compatible) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) { - if (type != NULL - && !(np->type != 0 && strcmp(np->type, type) == 0)) - continue; - if (of_device_is_compatible(np, compatible)) - break; - } - - return np; -} -EXPORT_SYMBOL(of_find_compatible_node); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c index ee96ef61bc99..2b2017ce2267 100644 --- a/arch/sparc64/kernel/prom.c +++ b/arch/sparc64/kernel/prom.c @@ -30,23 +30,10 @@ #include #include -static struct device_node *allnodes; +extern struct device_node *allnodes; /* temporary while merging */ extern rwlock_t devtree_lock; /* temporary while merging */ -struct device_node *of_find_node_by_path(const char *path) -{ - struct device_node *np = allnodes; - - for (; np != 0; np = np->allnext) { - if (np->full_name != 0 && strcmp(np->full_name, path) == 0) - break; - } - - return np; -} -EXPORT_SYMBOL(of_find_node_by_path); - struct device_node *of_find_node_by_phandle(phandle handle) { struct device_node *np; @@ -59,52 +46,6 @@ struct device_node *of_find_node_by_phandle(phandle handle) } EXPORT_SYMBOL(of_find_node_by_phandle); -struct device_node *of_find_node_by_name(struct device_node *from, - const char *name) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != NULL; np = np->allnext) - if (np->name != NULL && strcmp(np->name, name) == 0) - break; - - return np; -} -EXPORT_SYMBOL(of_find_node_by_name); - -struct device_node *of_find_node_by_type(struct device_node *from, - const char *type) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) - if (np->type != 0 && strcmp(np->type, type) == 0) - break; - - return np; -} -EXPORT_SYMBOL(of_find_node_by_type); - -struct device_node *of_find_compatible_node(struct device_node *from, - const char *type, const char *compatible) -{ - struct device_node *np; - - np = from ? from->allnext : allnodes; - for (; np != 0; np = np->allnext) { - if (type != NULL - && !(np->type != 0 && strcmp(np->type, type) == 0)) - continue; - if (of_device_is_compatible(np, compatible)) - break; - } - - return np; -} -EXPORT_SYMBOL(of_find_compatible_node); - int of_getintprop_default(struct device_node *np, const char *name, int def) { struct property *prop; -- cgit v1.2.1 From f85ff3056cefdf4635ebf98b30e9a7d86521567f Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Tue, 1 May 2007 16:40:36 +1000 Subject: Begin to consolidate of_device.c This moves all the common parts for the Sparc, Sparc64 and PowerPC of_device.c files into drivers/of/device.c. Apart from the simple move, Sparc gains of_match_node() and a call to of_node_put in of_release_dev(). PowerPC gains better recovery if device_create_file() fails in of_device_register(). Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/of_device.c | 122 +--------------------------------------- arch/sparc/kernel/of_device.c | 109 +---------------------------------- arch/sparc64/kernel/of_device.c | 114 +------------------------------------ 3 files changed, 5 insertions(+), 340 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c index a464d67248df..89b911e83c04 100644 --- a/arch/powerpc/kernel/of_device.c +++ b/arch/powerpc/kernel/of_device.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -8,118 +9,6 @@ #include #include -/** - * of_match_node - Tell if an device_node has a matching of_match structure - * @ids: array of of device match structures to search in - * @node: the of device structure to match against - * - * Low level utility function used by device matching. - */ -const struct of_device_id *of_match_node(const struct of_device_id *matches, - const struct device_node *node) -{ - while (matches->name[0] || matches->type[0] || matches->compatible[0]) { - int match = 1; - if (matches->name[0]) - match &= node->name - && !strcmp(matches->name, node->name); - if (matches->type[0]) - match &= node->type - && !strcmp(matches->type, node->type); - if (matches->compatible[0]) - match &= of_device_is_compatible(node, - matches->compatible); - if (match) - return matches; - matches++; - } - return NULL; -} - -/** - * of_match_device - Tell if an of_device structure has a matching - * of_match structure - * @ids: array of of device match structures to search in - * @dev: the of device structure to match against - * - * Used by a driver to check whether an of_device present in the - * system is in its list of supported devices. - */ -const struct of_device_id *of_match_device(const struct of_device_id *matches, - const struct of_device *dev) -{ - if (!dev->node) - return NULL; - return of_match_node(matches, dev->node); -} - -struct of_device *of_dev_get(struct of_device *dev) -{ - struct device *tmp; - - if (!dev) - return NULL; - tmp = get_device(&dev->dev); - if (tmp) - return to_of_device(tmp); - else - return NULL; -} - -void of_dev_put(struct of_device *dev) -{ - if (dev) - put_device(&dev->dev); -} - -static ssize_t dev_show_devspec(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - return sprintf(buf, "%s", ofdev->node->full_name); -} - -static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); - -/** - * of_release_dev - free an of device structure when all users of it are finished. - * @dev: device that's been disconnected - * - * Will be called only by the device core when all users of this of device are - * done. - */ -void of_release_dev(struct device *dev) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - of_node_put(ofdev->node); - kfree(ofdev); -} - -int of_device_register(struct of_device *ofdev) -{ - int rc; - - BUG_ON(ofdev->node == NULL); - - rc = device_register(&ofdev->dev); - if (rc) - return rc; - - return device_create_file(&ofdev->dev, &dev_attr_devspec); -} - -void of_device_unregister(struct of_device *ofdev) -{ - device_remove_file(&ofdev->dev, &dev_attr_devspec); - - device_unregister(&ofdev->dev); -} - - ssize_t of_device_get_modalias(struct of_device *ofdev, char *str, ssize_t len) { @@ -229,14 +118,5 @@ int of_device_uevent(struct device *dev, return 0; } - - -EXPORT_SYMBOL(of_match_node); -EXPORT_SYMBOL(of_match_device); -EXPORT_SYMBOL(of_device_register); -EXPORT_SYMBOL(of_device_unregister); -EXPORT_SYMBOL(of_dev_get); -EXPORT_SYMBOL(of_dev_put); -EXPORT_SYMBOL(of_release_dev); EXPORT_SYMBOL(of_device_uevent); EXPORT_SYMBOL(of_device_get_modalias); diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c index fd7f8cb668a3..0760b8157847 100644 --- a/arch/sparc/kernel/of_device.c +++ b/arch/sparc/kernel/of_device.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -8,38 +9,6 @@ #include #include -/** - * of_match_device - Tell if an of_device structure has a matching - * of_match structure - * @ids: array of of device match structures to search in - * @dev: the of device structure to match against - * - * Used by a driver to check whether an of_device present in the - * system is in its list of supported devices. - */ -const struct of_device_id *of_match_device(const struct of_device_id *matches, - const struct of_device *dev) -{ - if (!dev->node) - return NULL; - while (matches->name[0] || matches->type[0] || matches->compatible[0]) { - int match = 1; - if (matches->name[0]) - match &= dev->node->name - && !strcmp(matches->name, dev->node->name); - if (matches->type[0]) - match &= dev->node->type - && !strcmp(matches->type, dev->node->type); - if (matches->compatible[0]) - match &= of_device_is_compatible(dev->node, - matches->compatible); - if (match) - return matches; - matches++; - } - return NULL; -} - static int of_platform_bus_match(struct device *dev, struct device_driver *drv) { struct of_device * of_dev = to_of_device(dev); @@ -52,26 +21,6 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) return of_match_device(matches, of_dev) != NULL; } -struct of_device *of_dev_get(struct of_device *dev) -{ - struct device *tmp; - - if (!dev) - return NULL; - tmp = get_device(&dev->dev); - if (tmp) - return to_of_device(tmp); - else - return NULL; -} - -void of_dev_put(struct of_device *dev) -{ - if (dev) - put_device(&dev->dev); -} - - static int of_device_probe(struct device *dev) { int error = -ENODEV; @@ -735,56 +684,6 @@ void of_unregister_driver(struct of_platform_driver *drv) driver_unregister(&drv->driver); } - -static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - return sprintf(buf, "%s", ofdev->node->full_name); -} - -static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); - -/** - * of_release_dev - free an of device structure when all users of it are finished. - * @dev: device that's been disconnected - * - * Will be called only by the device core when all users of this of device are - * done. - */ -void of_release_dev(struct device *dev) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - - kfree(ofdev); -} - -int of_device_register(struct of_device *ofdev) -{ - int rc; - - BUG_ON(ofdev->node == NULL); - - rc = device_register(&ofdev->dev); - if (rc) - return rc; - - rc = device_create_file(&ofdev->dev, &dev_attr_devspec); - if (rc) - device_unregister(&ofdev->dev); - - return rc; -} - -void of_device_unregister(struct of_device *ofdev) -{ - device_remove_file(&ofdev->dev, &dev_attr_devspec); - device_unregister(&ofdev->dev); -} - struct of_device* of_platform_device_create(struct device_node *np, const char *bus_id, struct device *parent, @@ -810,12 +709,6 @@ struct of_device* of_platform_device_create(struct device_node *np, return dev; } -EXPORT_SYMBOL(of_match_device); EXPORT_SYMBOL(of_register_driver); EXPORT_SYMBOL(of_unregister_driver); -EXPORT_SYMBOL(of_device_register); -EXPORT_SYMBOL(of_device_unregister); -EXPORT_SYMBOL(of_dev_get); -EXPORT_SYMBOL(of_dev_put); EXPORT_SYMBOL(of_platform_device_create); -EXPORT_SYMBOL(of_release_dev); diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c index 6676b93219dc..68927bc3d3a9 100644 --- a/arch/sparc64/kernel/of_device.c +++ b/arch/sparc64/kernel/of_device.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -8,38 +9,6 @@ #include #include -/** - * of_match_device - Tell if an of_device structure has a matching - * of_match structure - * @ids: array of of device match structures to search in - * @dev: the of device structure to match against - * - * Used by a driver to check whether an of_device present in the - * system is in its list of supported devices. - */ -const struct of_device_id *of_match_device(const struct of_device_id *matches, - const struct of_device *dev) -{ - if (!dev->node) - return NULL; - while (matches->name[0] || matches->type[0] || matches->compatible[0]) { - int match = 1; - if (matches->name[0]) - match &= dev->node->name - && !strcmp(matches->name, dev->node->name); - if (matches->type[0]) - match &= dev->node->type - && !strcmp(matches->type, dev->node->type); - if (matches->compatible[0]) - match &= of_device_is_compatible(dev->node, - matches->compatible); - if (match) - return matches; - matches++; - } - return NULL; -} - static int of_platform_bus_match(struct device *dev, struct device_driver *drv) { struct of_device * of_dev = to_of_device(dev); @@ -52,26 +21,6 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) return of_match_device(matches, of_dev) != NULL; } -struct of_device *of_dev_get(struct of_device *dev) -{ - struct device *tmp; - - if (!dev) - return NULL; - tmp = get_device(&dev->dev); - if (tmp) - return to_of_device(tmp); - else - return NULL; -} - -void of_dev_put(struct of_device *dev) -{ - if (dev) - put_device(&dev->dev); -} - - static int of_device_probe(struct device *dev) { int error = -ENODEV; @@ -1020,61 +969,13 @@ int of_register_driver(struct of_platform_driver *drv, struct bus_type *bus) /* register with core */ return driver_register(&drv->driver); } +EXPORT_SYMBOL(of_register_driver); void of_unregister_driver(struct of_platform_driver *drv) { driver_unregister(&drv->driver); } - - -static ssize_t dev_show_devspec(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - return sprintf(buf, "%s", ofdev->node->full_name); -} - -static DEVICE_ATTR(devspec, S_IRUGO, dev_show_devspec, NULL); - -/** - * of_release_dev - free an of device structure when all users of it are finished. - * @dev: device that's been disconnected - * - * Will be called only by the device core when all users of this of device are - * done. - */ -void of_release_dev(struct device *dev) -{ - struct of_device *ofdev; - - ofdev = to_of_device(dev); - - kfree(ofdev); -} - -int of_device_register(struct of_device *ofdev) -{ - int rc; - - BUG_ON(ofdev->node == NULL); - - rc = device_register(&ofdev->dev); - if (rc) - return rc; - - rc = device_create_file(&ofdev->dev, &dev_attr_devspec); - if (rc) - device_unregister(&ofdev->dev); - - return rc; -} - -void of_device_unregister(struct of_device *ofdev) -{ - device_remove_file(&ofdev->dev, &dev_attr_devspec); - device_unregister(&ofdev->dev); -} +EXPORT_SYMBOL(of_unregister_driver); struct of_device* of_platform_device_create(struct device_node *np, const char *bus_id, @@ -1100,13 +1001,4 @@ struct of_device* of_platform_device_create(struct device_node *np, return dev; } - -EXPORT_SYMBOL(of_match_device); -EXPORT_SYMBOL(of_register_driver); -EXPORT_SYMBOL(of_unregister_driver); -EXPORT_SYMBOL(of_device_register); -EXPORT_SYMBOL(of_device_unregister); -EXPORT_SYMBOL(of_dev_get); -EXPORT_SYMBOL(of_dev_put); EXPORT_SYMBOL(of_platform_device_create); -EXPORT_SYMBOL(of_release_dev); -- cgit v1.2.1 From 37b7754aab9a6ad7ecbba45c87f8d8a1f81b3bcc Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Mon, 30 Apr 2007 17:43:56 +1000 Subject: [SPARC/64] Rename some functions like PowerPC This is to make the of merge easier. Also rename of_bus_type. Signed-off-by: Stephen Rothwell Acked-by: David S. Miller --- arch/sparc/kernel/of_device.c | 42 +++++++++++++++++----------------- arch/sparc/kernel/time.c | 2 +- arch/sparc64/kernel/auxio.c | 2 +- arch/sparc64/kernel/of_device.c | 50 ++++++++++++++++++++--------------------- arch/sparc64/kernel/power.c | 2 +- arch/sparc64/kernel/time.c | 2 +- 6 files changed, 50 insertions(+), 50 deletions(-) (limited to 'arch') diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c index 0760b8157847..cb21983cff9f 100644 --- a/arch/sparc/kernel/of_device.c +++ b/arch/sparc/kernel/of_device.c @@ -21,7 +21,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) return of_match_device(matches, of_dev) != NULL; } -static int of_device_probe(struct device *dev) +static int of_platform_device_probe(struct device *dev) { int error = -ENODEV; struct of_platform_driver *drv; @@ -45,7 +45,7 @@ static int of_device_probe(struct device *dev) return error; } -static int of_device_remove(struct device *dev) +static int of_platform_device_remove(struct device *dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -55,7 +55,7 @@ static int of_device_remove(struct device *dev) return 0; } -static int of_device_suspend(struct device *dev, pm_message_t state) +static int of_platform_device_suspend(struct device *dev, pm_message_t state) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -66,7 +66,7 @@ static int of_device_suspend(struct device *dev, pm_message_t state) return error; } -static int of_device_resume(struct device * dev) +static int of_platform_device_resume(struct device * dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -87,7 +87,7 @@ static int node_match(struct device *dev, void *data) struct of_device *of_find_device_by_node(struct device_node *dp) { - struct device *dev = bus_find_device(&of_bus_type, NULL, + struct device *dev = bus_find_device(&of_platform_bus_type, NULL, dp, node_match); if (dev) @@ -101,10 +101,10 @@ EXPORT_SYMBOL(of_find_device_by_node); struct bus_type ebus_bus_type = { .name = "ebus", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; EXPORT_SYMBOL(ebus_bus_type); #endif @@ -113,23 +113,23 @@ EXPORT_SYMBOL(ebus_bus_type); struct bus_type sbus_bus_type = { .name = "sbus", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; EXPORT_SYMBOL(sbus_bus_type); #endif -struct bus_type of_bus_type = { +struct bus_type of_platform_bus_type = { .name = "of", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; -EXPORT_SYMBOL(of_bus_type); +EXPORT_SYMBOL(of_platform_bus_type); static inline u64 of_read_addr(const u32 *cell, int size) { @@ -595,7 +595,7 @@ build_resources: build_device_resources(op, parent); op->dev.parent = parent; - op->dev.bus = &of_bus_type; + op->dev.bus = &of_platform_bus_type; if (!parent) strcpy(op->dev.bus_id, "root"); else @@ -639,7 +639,7 @@ static int __init of_bus_driver_init(void) { int err; - err = bus_register(&of_bus_type); + err = bus_register(&of_platform_bus_type); #ifdef CONFIG_PCI if (!err) err = bus_register(&ebus_bus_type); diff --git a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c index 7b4612da74a6..f2fdbb3664d3 100644 --- a/arch/sparc/kernel/time.c +++ b/arch/sparc/kernel/time.c @@ -354,7 +354,7 @@ static struct of_platform_driver clock_driver = { /* Probe for the mostek real time clock chip. */ static int __init clock_init(void) { - return of_register_driver(&clock_driver, &of_bus_type); + return of_register_driver(&clock_driver, &of_platform_bus_type); } /* Must be after subsys_initcall() so that busses are probed. Must diff --git a/arch/sparc64/kernel/auxio.c b/arch/sparc64/kernel/auxio.c index 826118ee53d5..7b379761e9f8 100644 --- a/arch/sparc64/kernel/auxio.c +++ b/arch/sparc64/kernel/auxio.c @@ -155,7 +155,7 @@ static struct of_platform_driver auxio_driver = { static int __init auxio_init(void) { - return of_register_driver(&auxio_driver, &of_bus_type); + return of_register_driver(&auxio_driver, &of_platform_bus_type); } /* Must be after subsys_initcall() so that busses are probed. Must diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c index 68927bc3d3a9..485f8579899a 100644 --- a/arch/sparc64/kernel/of_device.c +++ b/arch/sparc64/kernel/of_device.c @@ -21,7 +21,7 @@ static int of_platform_bus_match(struct device *dev, struct device_driver *drv) return of_match_device(matches, of_dev) != NULL; } -static int of_device_probe(struct device *dev) +static int of_platform_device_probe(struct device *dev) { int error = -ENODEV; struct of_platform_driver *drv; @@ -45,7 +45,7 @@ static int of_device_probe(struct device *dev) return error; } -static int of_device_remove(struct device *dev) +static int of_platform_device_remove(struct device *dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -55,7 +55,7 @@ static int of_device_remove(struct device *dev) return 0; } -static int of_device_suspend(struct device *dev, pm_message_t state) +static int of_platform_device_suspend(struct device *dev, pm_message_t state) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -66,7 +66,7 @@ static int of_device_suspend(struct device *dev, pm_message_t state) return error; } -static int of_device_resume(struct device * dev) +static int of_platform_device_resume(struct device * dev) { struct of_device * of_dev = to_of_device(dev); struct of_platform_driver * drv = to_of_platform_driver(dev->driver); @@ -112,7 +112,7 @@ static int node_match(struct device *dev, void *data) struct of_device *of_find_device_by_node(struct device_node *dp) { - struct device *dev = bus_find_device(&of_bus_type, NULL, + struct device *dev = bus_find_device(&of_platform_bus_type, NULL, dp, node_match); if (dev) @@ -126,20 +126,20 @@ EXPORT_SYMBOL(of_find_device_by_node); struct bus_type isa_bus_type = { .name = "isa", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; EXPORT_SYMBOL(isa_bus_type); struct bus_type ebus_bus_type = { .name = "ebus", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; EXPORT_SYMBOL(ebus_bus_type); #endif @@ -148,23 +148,23 @@ EXPORT_SYMBOL(ebus_bus_type); struct bus_type sbus_bus_type = { .name = "sbus", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; EXPORT_SYMBOL(sbus_bus_type); #endif -struct bus_type of_bus_type = { +struct bus_type of_platform_bus_type = { .name = "of", .match = of_platform_bus_match, - .probe = of_device_probe, - .remove = of_device_remove, - .suspend = of_device_suspend, - .resume = of_device_resume, + .probe = of_platform_device_probe, + .remove = of_platform_device_remove, + .suspend = of_platform_device_suspend, + .resume = of_platform_device_resume, }; -EXPORT_SYMBOL(of_bus_type); +EXPORT_SYMBOL(of_platform_bus_type); static inline u64 of_read_addr(const u32 *cell, int size) { @@ -882,7 +882,7 @@ static struct of_device * __init scan_one_device(struct device_node *dp, op->irqs[i] = build_one_device_irq(op, parent, op->irqs[i]); op->dev.parent = parent; - op->dev.bus = &of_bus_type; + op->dev.bus = &of_platform_bus_type; if (!parent) strcpy(op->dev.bus_id, "root"); else @@ -926,7 +926,7 @@ static int __init of_bus_driver_init(void) { int err; - err = bus_register(&of_bus_type); + err = bus_register(&of_platform_bus_type); #ifdef CONFIG_PCI if (!err) err = bus_register(&isa_bus_type); diff --git a/arch/sparc64/kernel/power.c b/arch/sparc64/kernel/power.c index 8dd4294ad21e..fdc0d0b5a910 100644 --- a/arch/sparc64/kernel/power.c +++ b/arch/sparc64/kernel/power.c @@ -170,6 +170,6 @@ static struct of_platform_driver power_driver = { void __init power_init(void) { - of_register_driver(&power_driver, &of_bus_type); + of_register_driver(&power_driver, &of_platform_bus_type); return; } diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c index 62e316ab1339..592ffcd57605 100644 --- a/arch/sparc64/kernel/time.c +++ b/arch/sparc64/kernel/time.c @@ -835,7 +835,7 @@ static int __init clock_init(void) return 0; } - return of_register_driver(&clock_driver, &of_bus_type); + return of_register_driver(&clock_driver, &of_platform_bus_type); } /* Must be after subsys_initcall() so that busses are probed. Must -- cgit v1.2.1 From 3f23de10f283819bcdc0d2282e8b5b14c2e96d3b Mon Sep 17 00:00:00 2001 From: Stephen Rothwell Date: Thu, 3 May 2007 02:38:57 +1000 Subject: Create drivers/of/platform.c and populate it with the common parts from PowerPC and Sparc[64]. Signed-off-by: Stephen Rothwell Acked-by: Paul Mackerras Acked-by: David S. Miller --- arch/powerpc/kernel/of_platform.c | 82 +------------------------- arch/sparc/kernel/of_device.c | 107 +++------------------------------- arch/sparc64/kernel/of_device.c | 118 ++++---------------------------------- 3 files changed, 21 insertions(+), 286 deletions(-) (limited to 'arch') diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c index 8ded4e7dc87e..f70e787d556f 100644 --- a/arch/powerpc/kernel/of_platform.c +++ b/arch/powerpc/kernel/of_platform.c @@ -55,94 +55,14 @@ static struct of_device_id of_default_bus_ids[] = { static atomic_t bus_no_reg_magic; -/* - * - * OF platform device type definition & base infrastructure - * - */ - -static int of_platform_bus_match(struct device *dev, struct device_driver *drv) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * of_drv = to_of_platform_driver(drv); - const struct of_device_id * matches = of_drv->match_table; - - if (!matches) - return 0; - - return of_match_device(matches, of_dev) != NULL; -} - -static int of_platform_device_probe(struct device *dev) -{ - int error = -ENODEV; - struct of_platform_driver *drv; - struct of_device *of_dev; - const struct of_device_id *match; - - drv = to_of_platform_driver(dev->driver); - of_dev = to_of_device(dev); - - if (!drv->probe) - return error; - - of_dev_get(of_dev); - - match = of_match_device(drv->match_table, of_dev); - if (match) - error = drv->probe(of_dev, match); - if (error) - of_dev_put(of_dev); - - return error; -} - -static int of_platform_device_remove(struct device *dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - - if (dev->driver && drv->remove) - drv->remove(of_dev); - return 0; -} - -static int of_platform_device_suspend(struct device *dev, pm_message_t state) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->suspend) - error = drv->suspend(of_dev, state); - return error; -} - -static int of_platform_device_resume(struct device * dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->resume) - error = drv->resume(of_dev); - return error; -} - struct bus_type of_platform_bus_type = { - .name = "of_platform", - .match = of_platform_bus_match, .uevent = of_device_uevent, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, }; EXPORT_SYMBOL(of_platform_bus_type); static int __init of_bus_driver_init(void) { - return bus_register(&of_platform_bus_type); + return of_bus_type_init(&of_platform_bus_type, "of_platform"); } postcore_initcall(of_bus_driver_init); diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c index cb21983cff9f..7176040caba0 100644 --- a/arch/sparc/kernel/of_device.c +++ b/arch/sparc/kernel/of_device.c @@ -5,77 +5,9 @@ #include #include #include - -#include -#include - -static int of_platform_bus_match(struct device *dev, struct device_driver *drv) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * of_drv = to_of_platform_driver(drv); - const struct of_device_id * matches = of_drv->match_table; - - if (!matches) - return 0; - - return of_match_device(matches, of_dev) != NULL; -} - -static int of_platform_device_probe(struct device *dev) -{ - int error = -ENODEV; - struct of_platform_driver *drv; - struct of_device *of_dev; - const struct of_device_id *match; - - drv = to_of_platform_driver(dev->driver); - of_dev = to_of_device(dev); - - if (!drv->probe) - return error; - - of_dev_get(of_dev); - - match = of_match_device(drv->match_table, of_dev); - if (match) - error = drv->probe(of_dev, match); - if (error) - of_dev_put(of_dev); - - return error; -} - -static int of_platform_device_remove(struct device *dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - - if (dev->driver && drv->remove) - drv->remove(of_dev); - return 0; -} - -static int of_platform_device_suspend(struct device *dev, pm_message_t state) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->suspend) - error = drv->suspend(of_dev, state); - return error; -} - -static int of_platform_device_resume(struct device * dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->resume) - error = drv->resume(of_dev); - return error; -} +#include +#include +#include static int node_match(struct device *dev, void *data) { @@ -98,37 +30,16 @@ struct of_device *of_find_device_by_node(struct device_node *dp) EXPORT_SYMBOL(of_find_device_by_node); #ifdef CONFIG_PCI -struct bus_type ebus_bus_type = { - .name = "ebus", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type ebus_bus_type; EXPORT_SYMBOL(ebus_bus_type); #endif #ifdef CONFIG_SBUS -struct bus_type sbus_bus_type = { - .name = "sbus", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type sbus_bus_type; EXPORT_SYMBOL(sbus_bus_type); #endif -struct bus_type of_platform_bus_type = { - .name = "of", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type of_platform_bus_type; EXPORT_SYMBOL(of_platform_bus_type); static inline u64 of_read_addr(const u32 *cell, int size) @@ -639,14 +550,14 @@ static int __init of_bus_driver_init(void) { int err; - err = bus_register(&of_platform_bus_type); + err = of_bus_type_init(&of_platform_bus_type, "of"); #ifdef CONFIG_PCI if (!err) - err = bus_register(&ebus_bus_type); + err = of_bus_type_init(&ebus_bus_type, "ebus"); #endif #ifdef CONFIG_SBUS if (!err) - err = bus_register(&sbus_bus_type); + err = of_bus_type_init(&sbus_bus_type, "sbus"); #endif if (!err) diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c index 485f8579899a..7b0dce9604ee 100644 --- a/arch/sparc64/kernel/of_device.c +++ b/arch/sparc64/kernel/of_device.c @@ -5,77 +5,9 @@ #include #include #include - -#include -#include - -static int of_platform_bus_match(struct device *dev, struct device_driver *drv) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * of_drv = to_of_platform_driver(drv); - const struct of_device_id * matches = of_drv->match_table; - - if (!matches) - return 0; - - return of_match_device(matches, of_dev) != NULL; -} - -static int of_platform_device_probe(struct device *dev) -{ - int error = -ENODEV; - struct of_platform_driver *drv; - struct of_device *of_dev; - const struct of_device_id *match; - - drv = to_of_platform_driver(dev->driver); - of_dev = to_of_device(dev); - - if (!drv->probe) - return error; - - of_dev_get(of_dev); - - match = of_match_device(drv->match_table, of_dev); - if (match) - error = drv->probe(of_dev, match); - if (error) - of_dev_put(of_dev); - - return error; -} - -static int of_platform_device_remove(struct device *dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - - if (dev->driver && drv->remove) - drv->remove(of_dev); - return 0; -} - -static int of_platform_device_suspend(struct device *dev, pm_message_t state) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->suspend) - error = drv->suspend(of_dev, state); - return error; -} - -static int of_platform_device_resume(struct device * dev) -{ - struct of_device * of_dev = to_of_device(dev); - struct of_platform_driver * drv = to_of_platform_driver(dev->driver); - int error = 0; - - if (dev->driver && drv->resume) - error = drv->resume(of_dev); - return error; -} +#include +#include +#include void __iomem *of_ioremap(struct resource *res, unsigned long offset, unsigned long size, char *name) { @@ -123,47 +55,19 @@ struct of_device *of_find_device_by_node(struct device_node *dp) EXPORT_SYMBOL(of_find_device_by_node); #ifdef CONFIG_PCI -struct bus_type isa_bus_type = { - .name = "isa", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type isa_bus_type; EXPORT_SYMBOL(isa_bus_type); -struct bus_type ebus_bus_type = { - .name = "ebus", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type ebus_bus_type; EXPORT_SYMBOL(ebus_bus_type); #endif #ifdef CONFIG_SBUS -struct bus_type sbus_bus_type = { - .name = "sbus", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type sbus_bus_type; EXPORT_SYMBOL(sbus_bus_type); #endif -struct bus_type of_platform_bus_type = { - .name = "of", - .match = of_platform_bus_match, - .probe = of_platform_device_probe, - .remove = of_platform_device_remove, - .suspend = of_platform_device_suspend, - .resume = of_platform_device_resume, -}; +struct bus_type of_platform_bus_type; EXPORT_SYMBOL(of_platform_bus_type); static inline u64 of_read_addr(const u32 *cell, int size) @@ -926,16 +830,16 @@ static int __init of_bus_driver_init(void) { int err; - err = bus_register(&of_platform_bus_type); + err = of_bus_type_init(&of_platform_bus_type, "of"); #ifdef CONFIG_PCI if (!err) - err = bus_register(&isa_bus_type); + err = of_bus_type_init(&isa_bus_type, "isa"); if (!err) - err = bus_register(&ebus_bus_type); + err = of_bus_type_init(&ebus_bus_type, "ebus"); #endif #ifdef CONFIG_SBUS if (!err) - err = bus_register(&sbus_bus_type); + err = of_bus_type_init(&sbus_bus_type, "sbus"); #endif if (!err) -- cgit v1.2.1