diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-05-22 11:30:22 -0400 |
---|---|---|
committer | Dong Aisheng <b29396@freescale.com> | 2014-06-24 02:11:52 -0400 |
commit | c819acf447205b1040d21606271899e19f9ade05 (patch) | |
tree | 2b9b51ea327479defaec1c6c1887bdc18f26b4dc | |
parent | 9f82045316a36af3a4ea9a666f367de416a2237a (diff) |
of: Add helper for getting the maximum alias index for a stem
of_alias_max_index will return the maximum number for which an
alias of a given stem exists. This is useful for frameworks
whishing to reserve a number of device slots from dynamic
allocation.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
(cherry picked from commit 18ae7362e9822993436c1a544e49cfd58fa175b2)
-rw-r--r-- | drivers/of/base.c | 29 | ||||
-rw-r--r-- | include/linux/of.h | 6 |
2 files changed, 35 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index c258df42b002..5e713b42621f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -1588,6 +1588,35 @@ static void of_alias_add(struct alias_prop *ap, struct device_node *np, | |||
1588 | ap->alias, ap->stem, ap->id, of_node_full_name(np)); | 1588 | ap->alias, ap->stem, ap->id, of_node_full_name(np)); |
1589 | } | 1589 | } |
1590 | 1590 | ||
1591 | /* | ||
1592 | * of_alias_max_index() - get the maximum index for a given alias stem | ||
1593 | * @stem: The alias stem for which the maximum index is searched for | ||
1594 | * | ||
1595 | * Given an alias stem (the alias without the number) this function | ||
1596 | * returns the maximum number for which an alias exists. | ||
1597 | * | ||
1598 | * Return: The maximum existing alias index or -ENODEV if no alias | ||
1599 | * exists for this stem. | ||
1600 | */ | ||
1601 | int of_alias_max_index(const char *stem) | ||
1602 | { | ||
1603 | struct alias_prop *app; | ||
1604 | int max = -ENODEV; | ||
1605 | |||
1606 | mutex_lock(&of_aliases_mutex); | ||
1607 | |||
1608 | list_for_each_entry(app, &aliases_lookup, link) { | ||
1609 | if (strcmp(app->stem, stem)) | ||
1610 | continue; | ||
1611 | if (app->id > max) | ||
1612 | max = app->id; | ||
1613 | } | ||
1614 | |||
1615 | mutex_unlock(&of_aliases_mutex); | ||
1616 | |||
1617 | return max; | ||
1618 | } | ||
1619 | |||
1591 | /** | 1620 | /** |
1592 | * of_alias_scan - Scan all properties of 'aliases' node | 1621 | * of_alias_scan - Scan all properties of 'aliases' node |
1593 | * | 1622 | * |
diff --git a/include/linux/of.h b/include/linux/of.h index 668e12322dd4..7a07fa495bc7 100644 --- a/include/linux/of.h +++ b/include/linux/of.h | |||
@@ -286,6 +286,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, | |||
286 | 286 | ||
287 | extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); | 287 | extern void of_alias_scan(void * (*dt_alloc)(u64 size, u64 align)); |
288 | extern int of_alias_get_id(struct device_node *np, const char *stem); | 288 | extern int of_alias_get_id(struct device_node *np, const char *stem); |
289 | extern int of_alias_max_index(const char *stem); | ||
289 | 290 | ||
290 | extern int of_machine_is_compatible(const char *compat); | 291 | extern int of_machine_is_compatible(const char *compat); |
291 | 292 | ||
@@ -503,6 +504,11 @@ static inline int of_alias_get_id(struct device_node *np, const char *stem) | |||
503 | return -ENOSYS; | 504 | return -ENOSYS; |
504 | } | 505 | } |
505 | 506 | ||
507 | static inline int of_alias_max_index(const char *stem) | ||
508 | { | ||
509 | return -ENODEV; | ||
510 | } | ||
511 | |||
506 | static inline int of_machine_is_compatible(const char *compat) | 512 | static inline int of_machine_is_compatible(const char *compat) |
507 | { | 513 | { |
508 | return 0; | 514 | return 0; |