From: Luis R. Rodriguez Date: Sat, 27 Jul 2013 20:47:22 +0000 (-0700) Subject: backports: backport of_get_child_by_name() support X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=add3f1786bb17a801c0fb87489cb8e0dd671bbd6;p=openwrt%2Fstaging%2Fblogic.git backports: backport of_get_child_by_name() support This was added via 9c19761a. While at it clean up the backported header a bit to make backporting more OF stuff more manageable. mcgrof@frijol ~/linux-stable (git::master)$ git describe --contains 9c19761a v3.7-rc1~123^2~4 commit 9c19761a7ecdc86abb2fba0feb81e8952eccc1f1 Author: Srinivas Kandagatla Date: Tue Sep 18 08:10:28 2012 +0100 dt: introduce of_get_child_by_name to get child node by name This patch introduces of_get_child_by_name function to get a child node by its name in a given parent node. Without this patch each driver code has to iterate the parent and do a string compare, However having of_get_child_by_name libary function would avoid code duplication, errors and is more convenient. Signed-off-by: Srinivas Kandagatla Signed-off-by: Rob Herring Signed-off-by: Luis R. Rodriguez --- diff --git a/backport/backport-include/linux/of.h b/backport/backport-include/linux/of.h index c5dc87c2ef64..93e91dd9a2bb 100644 --- a/backport/backport-include/linux/of.h +++ b/backport/backport-include/linux/of.h @@ -4,13 +4,30 @@ #include #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) -#include_next -#else +#define KERNEL_HAS_OF_SUPPORT 1 +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) */ #ifdef CONFIG_OF +#define KERNEL_HAS_OF_SUPPORT 1 +#endif /* CONFIG_OF */ + +#ifdef KERNEL_HAS_OF_SUPPORT #include_next + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) +#ifdef CONFIG_OF +extern struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name); +#else +static inline struct device_node *of_get_child_by_name( + const struct device_node *node, + const char *name) +{ + return NULL; +} #endif /* CONFIG_OF */ +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) */ -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) */ +#endif /* KERNEL_HAS_OF_SUPPORT */ #endif /* _COMPAT_LINUX_OF_H */ diff --git a/backport/compat/compat-3.7.c b/backport/compat/compat-3.7.c index 0f2d33258279..8f5a56cfffba 100644 --- a/backport/compat/compat-3.7.c +++ b/backport/compat/compat-3.7.c @@ -251,3 +251,32 @@ int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos, return ret; } EXPORT_SYMBOL_GPL(pcie_capability_clear_and_set_dword); + +#ifdef KERNEL_HAS_OF_SUPPORT +#ifdef CONFIG_OF +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) +/** + * of_get_child_by_name - Find the child node by name for a given parent + * @node: parent node + * @name: child name to look for. + * + * This function looks for child node for given matching name + * + * Returns a node pointer if found, with refcount incremented, use + * of_node_put() on it when done. + * Returns NULL if node is not found. + */ +struct device_node *of_get_child_by_name(const struct device_node *node, + const char *name) +{ + struct device_node *child; + + for_each_child_of_node(node, child) + if (child->name && (of_node_cmp(child->name, name) == 0)) + break; + return child; +} +EXPORT_SYMBOL_GPL(of_get_child_by_name); +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) */ +#endif /* CONFIG_OF */ +#endif /* KERNEL_HAS_OF_SUPPORT */