aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2011-08-04 05:27:32 -0400
committerGrant Likely <grant.likely@secretlab.ca>2011-08-04 06:26:24 -0400
commitfe55c1844a1c106e9d9d3dd27cbfcf8caeb9e77e (patch)
tree85bbcd23d3f5fcc6b19abfc29d5ffea9608a6fcb /drivers/of
parent9e191b22c91873c09c722d7f956ab9f3276f9a37 (diff)
Revert "dt: add of_alias_scan and of_alias_get_id"
This reverts commit 750f463a749e28464151ad26938d11b07b1c43cb. of_alias_* still needs work to be generalized for 'promtree' dt platforms, and to no implicitly create entries for available ids. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c130
-rw-r--r--drivers/of/fdt.c4
2 files changed, 1 insertions, 133 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index fb28b5af733b..3ff22e32b602 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -17,39 +17,14 @@
17 * as published by the Free Software Foundation; either version 17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version. 18 * 2 of the License, or (at your option) any later version.
19 */ 19 */
20#include <linux/ctype.h>
21#include <linux/module.h> 20#include <linux/module.h>
22#include <linux/of.h> 21#include <linux/of.h>
23#include <linux/spinlock.h> 22#include <linux/spinlock.h>
24#include <linux/slab.h> 23#include <linux/slab.h>
25#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
26 25
27/**
28 * struct alias_prop - Alias property in 'aliases' node
29 * @link: List node to link the structure in aliases_lookup list
30 * @alias: Alias property name
31 * @np: Pointer to device_node that the alias stands for
32 * @id: Index value from end of alias name
33 * @stem: Alias string without the index
34 *
35 * The structure represents one alias property of 'aliases' node as
36 * an entry in aliases_lookup list.
37 */
38struct alias_prop {
39 struct list_head link;
40 const char *alias;
41 struct device_node *np;
42 int id;
43 char stem[0];
44};
45
46static LIST_HEAD(aliases_lookup);
47
48struct device_node *allnodes; 26struct device_node *allnodes;
49struct device_node *of_chosen; 27struct device_node *of_chosen;
50struct device_node *of_aliases;
51
52static DEFINE_MUTEX(of_aliases_mutex);
53 28
54/* use when traversing tree through the allnext, child, sibling, 29/* use when traversing tree through the allnext, child, sibling,
55 * or parent members of struct device_node. 30 * or parent members of struct device_node.
@@ -1013,108 +988,3 @@ out_unlock:
1013} 988}
1014#endif /* defined(CONFIG_OF_DYNAMIC) */ 989#endif /* defined(CONFIG_OF_DYNAMIC) */
1015 990
1016static void of_alias_add(struct alias_prop *ap, struct device_node *np,
1017 int id, const char *stem, int stem_len)
1018{
1019 ap->id = id;
1020 ap->np = np;
1021 strncpy(ap->stem, stem, stem_len);
1022 ap->stem[stem_len] = 0;
1023 list_add_tail(&ap->link, &aliases_lookup);
1024 pr_debug("adding DT alias:%s: stem=%s id=%i node=%s\n",
1025 ap->alias, ap->stem, ap->id, np ? np->full_name : NULL);
1026}
1027
1028/**
1029 * of_alias_scan() - Scan all properties of 'aliases' node
1030 *
1031 * The function scans all the properties of 'aliases' node and populate
1032 * the global lookup table with the properties. It returns the
1033 * number of alias_prop found, or error code in error case.
1034 */
1035__init void of_alias_scan(void)
1036{
1037 struct property *pp;
1038
1039 if (!of_aliases)
1040 return;
1041
1042 for_each_property(pp, of_aliases->properties) {
1043 const char *start = pp->name;
1044 const char *end = start + strlen(start);
1045 struct device_node *np;
1046 struct alias_prop *ap;
1047 int id, len;
1048
1049 /* Skip those we do not want to proceed */
1050 if (!strcmp(pp->name, "name") ||
1051 !strcmp(pp->name, "phandle") ||
1052 !strcmp(pp->name, "linux,phandle"))
1053 continue;
1054
1055 np = of_find_node_by_path(pp->value);
1056 if (!np)
1057 continue;
1058
1059 /* walk alias backwards to extract the id and 'stem' string */
1060 while (isdigit(*(end-1)) && end > start)
1061 end--;
1062 len = end - start;
1063 id = strlen(end) ? simple_strtoul(end, NULL, 10) : -1;
1064
1065 /* Allocate an alias_prop with enough space for the stem */
1066 ap = early_init_dt_alloc_memory_arch(sizeof(*ap) + len + 1, 4);
1067 if (!ap)
1068 continue;
1069 ap->alias = start;
1070 of_alias_add(ap, np, id, start, len);
1071 }
1072}
1073
1074/**
1075 * of_alias_get_id() - Get alias id for the given device_node
1076 * @np: Pointer to the given device_node
1077 * @stem: Alias stem of the given device_node
1078 *
1079 * The function travels the lookup table to get alias id for the given
1080 * device_node and alias stem. It returns the alias id if find it.
1081 * If not, dynamically creates one in the lookup table and returns it,
1082 * or returns error code if fail to create.
1083 */
1084int of_alias_get_id(struct device_node *np, const char *stem)
1085{
1086 struct alias_prop *app;
1087 int id = 0;
1088 bool found = false;
1089
1090 mutex_lock(&of_aliases_mutex);
1091 list_for_each_entry(app, &aliases_lookup, link) {
1092 if (strcmp(app->stem, stem) != 0)
1093 continue;
1094
1095 if (np == app->np) {
1096 found = true;
1097 id = app->id;
1098 break;
1099 }
1100
1101 if (id <= app->id)
1102 id = app->id + 1;
1103 }
1104
1105 /* If an id is not found, then allocate a new one */
1106 if (!found) {
1107 app = kzalloc(sizeof(*app) + strlen(stem) + 1, 4);
1108 if (!app) {
1109 id = -ENODEV;
1110 goto out;
1111 }
1112 of_alias_add(app, np, id, stem, strlen(stem));
1113 }
1114
1115 out:
1116 mutex_unlock(&of_aliases_mutex);
1117
1118 return id;
1119}
1120EXPORT_SYMBOL_GPL(of_alias_get_id);
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 13d6d3a96b31..65200af29c52 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -707,12 +707,10 @@ void __init unflatten_device_tree(void)
707 __unflatten_device_tree(initial_boot_params, &allnodes, 707 __unflatten_device_tree(initial_boot_params, &allnodes,
708 early_init_dt_alloc_memory_arch); 708 early_init_dt_alloc_memory_arch);
709 709
710 /* Get pointer to "/chosen" and "/aliasas" nodes for use everywhere */ 710 /* Get pointer to OF "/chosen" node for use everywhere */
711 of_chosen = of_find_node_by_path("/chosen"); 711 of_chosen = of_find_node_by_path("/chosen");
712 if (of_chosen == NULL) 712 if (of_chosen == NULL)
713 of_chosen = of_find_node_by_path("/chosen@0"); 713 of_chosen = of_find_node_by_path("/chosen@0");
714 of_aliases = of_find_node_by_path("/aliases");
715 of_alias_scan();
716} 714}
717 715
718#endif /* CONFIG_OF_EARLY_FLATTREE */ 716#endif /* CONFIG_OF_EARLY_FLATTREE */