From 611cad720148c899db5a383c1c676fd820df7023 Mon Sep 17 00:00:00 2001 From: Shawn Guo Date: Mon, 15 Aug 2011 15:28:14 +0800 Subject: dt: add of_alias_scan and of_alias_get_id The patch adds function of_alias_scan to populate a global lookup table with the properties of 'aliases' node and function of_alias_get_id for drivers to find alias id from the lookup table. v3: Split out automatic addition of aliases on id lookup so that it can be debated separately from the core functionality. v2: - Add of_chosen/of_aliases populating and of_alias_scan() invocation for OF_PROMTREE. - Add locking - rework parse loop Signed-off-by: Shawn Guo Acked-by: David S. Miller Signed-off-by: Grant Likely --- include/linux/of.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 9180dc5cb00..8b6383d876c 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -68,6 +68,7 @@ struct device_node { /* Pointer for first entry in chain of all nodes. */ extern struct device_node *allnodes; extern struct device_node *of_chosen; +extern struct device_node *of_aliases; extern rwlock_t devtree_lock; static inline bool of_have_populated_dt(void) @@ -209,6 +210,9 @@ extern int of_device_is_available(const struct device_node *device); extern const void *of_get_property(const struct device_node *node, const char *name, int *lenp); +#define for_each_property(pp, properties) \ + for (pp = properties; pp != NULL; pp = pp->next) + extern int of_n_addr_cells(struct device_node *np); extern int of_n_size_cells(struct device_node *np); extern const struct of_device_id *of_match_node( @@ -221,6 +225,9 @@ extern int of_parse_phandles_with_args(struct device_node *np, const char *list_name, const char *cells_name, int index, struct device_node **out_node, const void **out_args); +extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); +extern int of_alias_get_id(struct device_node *np, const char *stem); + extern int of_machine_is_compatible(const char *compat); extern int prom_add_property(struct device_node* np, struct property* prop); -- cgit v1.2.3 From aba3dfff9a75eb272c4f47994f16eb5d548a5af1 Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Wed, 21 Sep 2011 13:23:10 -0600 Subject: dt: add empty for_each_child_of_node, of_find_property The patch adds a couple empty functions for non-dt build, so that drivers migrating to dt can save some '#ifdef CONFIG_OF'. Signed-off-by: Stephen Warren Signed-off-by: Grant Likely --- include/linux/of.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 8b6383d876c..83a61f3b443 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -249,6 +249,16 @@ static inline bool of_have_populated_dt(void) return false; } +#define for_each_child_of_node(parent, child) \ + while (0) + +static inline struct property *of_find_property(const struct device_node *np, + const char *name, + int *lenp) +{ + return NULL; +} + static inline int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz) -- cgit v1.2.3 From 3a1e362e3f3cd571b3974b8d44b8e358ec7a098c Mon Sep 17 00:00:00 2001 From: Ben Dooks Date: Wed, 3 Aug 2011 10:11:42 +0100 Subject: OF: Add of_match_ptr() macro Add a macro of_match_ptr() that allows the .of_match_table entry in the driver structures to be assigned without having an #ifdef xxx NULL for the case that OF is not enabled Signed-off-by: Ben Dooks Signed-off-by: Grant Likely --- include/linux/of.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 83a61f3b443..53107b09cbd 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -242,6 +242,7 @@ extern void of_attach_node(struct device_node *); extern void of_detach_node(struct device_node *); #endif +#define of_match_ptr(_ptr) (_ptr) #else /* CONFIG_OF */ static inline bool of_have_populated_dt(void) @@ -280,6 +281,7 @@ static inline const void *of_get_property(const struct device_node *node, return NULL; } +#define of_match_ptr(_ptr) NULL #endif /* CONFIG_OF */ static inline int of_property_read_u32(const struct device_node *np, -- cgit v1.2.3 From 4cd7f7a31178ff8a15ad2bc1258b9b2bf2cf51a4 Mon Sep 17 00:00:00 2001 From: Jamie Iles Date: Wed, 14 Sep 2011 20:49:59 +0100 Subject: dt: add helper to read 64-bit integers Add a helper similar to of_property_read_u32() that handles 64-bit integers. v2/v3: constify device node and property name parameters. Cc: Grant Likely Reviewed-by: Rob Herring Signed-off-by: Jamie Iles Signed-off-by: Grant Likely --- drivers/of/base.c | 29 +++++++++++++++++++++++++++++ include/linux/of.h | 8 ++++++++ 2 files changed, 37 insertions(+) (limited to 'include') diff --git a/drivers/of/base.c b/drivers/of/base.c index 8abde58cbe8..b970562e011 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -656,6 +656,35 @@ int of_property_read_u32_array(const struct device_node *np, } EXPORT_SYMBOL_GPL(of_property_read_u32_array); +/** + * of_property_read_u64 - Find and read a 64 bit integer from a property + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_value: pointer to return value, modified only if return value is 0. + * + * Search for a property in a device node and read a 64-bit value from + * it. Returns 0 on success, -EINVAL if the property does not exist, + * -ENODATA if property does not have a value, and -EOVERFLOW if the + * property data isn't large enough. + * + * The out_value is modified only if a valid u64 value can be decoded. + */ +int of_property_read_u64(const struct device_node *np, const char *propname, + u64 *out_value) +{ + struct property *prop = of_find_property(np, propname, NULL); + + if (!prop) + return -EINVAL; + if (!prop->value) + return -ENODATA; + if (sizeof(*out_value) > prop->length) + return -EOVERFLOW; + *out_value = of_read_number(prop->value, 2); + return 0; +} +EXPORT_SYMBOL_GPL(of_property_read_u64); + /** * of_property_read_string - Find and read a string from a property * @np: device node from which the property value is to be read. diff --git a/include/linux/of.h b/include/linux/of.h index 53107b09cbd..1cc9930ba06 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -200,6 +200,8 @@ extern int of_property_read_u32_array(const struct device_node *np, const char *propname, u32 *out_values, size_t sz); +extern int of_property_read_u64(const struct device_node *np, + const char *propname, u64 *out_value); extern int of_property_read_string(struct device_node *np, const char *propname, @@ -281,6 +283,12 @@ static inline const void *of_get_property(const struct device_node *node, return NULL; } +static inline int of_property_read_u64(const struct device_node *np, + const char *propname, u64 *out_value) +{ + return -ENOSYS; +} + #define of_match_ptr(_ptr) NULL #endif /* CONFIG_OF */ -- cgit v1.2.3 From 36a0904ea0a657567122edebb95eab5f1620a5eb Mon Sep 17 00:00:00 2001 From: Rajendra Nayak Date: Mon, 10 Oct 2011 21:49:35 +0530 Subject: dt: add empty dt helpers for non-dt build Add empty of_device_is_compatible() and of_parse_phandle() for non-dt builds to work. Signed-off-by: Rajendra Nayak Signed-off-by: Grant Likely --- include/linux/of.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 1cc9930ba06..736b7477beb 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -255,6 +255,12 @@ static inline bool of_have_populated_dt(void) #define for_each_child_of_node(parent, child) \ while (0) +static inline int of_device_is_compatible(const struct device_node *device, + const char *name) +{ + return 0; +} + static inline struct property *of_find_property(const struct device_node *np, const char *name, int *lenp) @@ -289,6 +295,13 @@ static inline int of_property_read_u64(const struct device_node *np, return -ENOSYS; } +static inline struct device_node *of_parse_phandle(struct device_node *np, + const char *phandle_name, + int index) +{ + return NULL; +} + #define of_match_ptr(_ptr) NULL #endif /* CONFIG_OF */ -- cgit v1.2.3 From 5762c20593b6b959f1470dc6f1ff4ca4d9570f8d Mon Sep 17 00:00:00 2001 From: Nicolas Ferre Date: Mon, 24 Oct 2011 11:53:32 +0200 Subject: dt: Add empty of_match_node() macro Add an empty macro for of_match_node() that will save some '#ifdef CONFIG_OF' for non-dt builds. I have chosen to use a macro instead of a function to be able to avoid defining the first parameter. In fact, this "struct of_device_id *" first parameter is usualy not defined as well on non-dt builds. Signed-off-by: Nicolas Ferre Acked-by: Grant Likely --- include/linux/of.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/linux/of.h b/include/linux/of.h index 736b7477beb..92c40a14224 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -303,6 +303,7 @@ static inline struct device_node *of_parse_phandle(struct device_node *np, } #define of_match_ptr(_ptr) NULL +#define of_match_node(_matches, _node) NULL #endif /* CONFIG_OF */ static inline int of_property_read_u32(const struct device_node *np, -- cgit v1.2.3