aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorStepan Moskovchenko <stepanm@codeaurora.org>2012-12-06 17:55:41 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-02-06 06:06:35 -0500
commitced4eec900850627409d7ff566b009471162b56b (patch)
treeeaa6551cbc421108d049e65855cdf618baa02117 /drivers/of
parent88b62b915b0b7e25870eb0604ed9a92ba4bfc9f7 (diff)
of: Output devicetree alias names in uevent
In some situations, userspace may want to resolve a device by function and logical number (ie, "serial0") rather than by the base address or full device path. Being able to resolve a device by alias frees userspace from the burden of otherwise having to maintain a mapping between device addresses and their logical assignments on each platform when multiple instances of the same hardware block are present in the system. Although the uevent device attribute contains devicetree compatible information and the full device path, the uevent does not list the alises that may have been defined for the device. Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org> [grant.likely: Removed OF_ALIAS_N field; I don't think it's needed] [grant.likely: Added #ifndef _LINUX_OF_PRIVATE_H wrapper] Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c23
-rw-r--r--drivers/of/device.c13
-rw-r--r--drivers/of/of_private.h36
3 files changed, 52 insertions, 20 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2390ddb22d60..d1bb50719ed7 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -24,33 +24,16 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/proc_fs.h> 25#include <linux/proc_fs.h>
26 26
27/** 27#include "of_private.h"
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 28
46static LIST_HEAD(aliases_lookup); 29LIST_HEAD(aliases_lookup);
47 30
48struct device_node *of_allnodes; 31struct device_node *of_allnodes;
49EXPORT_SYMBOL(of_allnodes); 32EXPORT_SYMBOL(of_allnodes);
50struct device_node *of_chosen; 33struct device_node *of_chosen;
51struct device_node *of_aliases; 34struct device_node *of_aliases;
52 35
53static DEFINE_MUTEX(of_aliases_mutex); 36DEFINE_MUTEX(of_aliases_mutex);
54 37
55/* use when traversing tree through the allnext, child, sibling, 38/* use when traversing tree through the allnext, child, sibling,
56 * or parent members of struct device_node. 39 * or parent members of struct device_node.
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 4c74e4fc5a51..f685e55e0717 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -8,6 +8,7 @@
8#include <linux/slab.h> 8#include <linux/slab.h>
9 9
10#include <asm/errno.h> 10#include <asm/errno.h>
11#include "of_private.h"
11 12
12/** 13/**
13 * of_match_device - Tell if a struct device matches an of_device_id list 14 * of_match_device - Tell if a struct device matches an of_device_id list
@@ -131,6 +132,7 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
131void of_device_uevent(struct device *dev, struct kobj_uevent_env *env) 132void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
132{ 133{
133 const char *compat; 134 const char *compat;
135 struct alias_prop *app;
134 int seen = 0, cplen, sl; 136 int seen = 0, cplen, sl;
135 137
136 if ((!dev) || (!dev->of_node)) 138 if ((!dev) || (!dev->of_node))
@@ -153,6 +155,17 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
153 seen++; 155 seen++;
154 } 156 }
155 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen); 157 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen);
158
159 seen = 0;
160 mutex_lock(&of_aliases_mutex);
161 list_for_each_entry(app, &aliases_lookup, link) {
162 if (dev->of_node == app->np) {
163 add_uevent_var(env, "OF_ALIAS_%d=%s", seen,
164 app->alias);
165 seen++;
166 }
167 }
168 mutex_unlock(&of_aliases_mutex);
156} 169}
157 170
158int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env) 171int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h
new file mode 100644
index 000000000000..ff350c8fa7ac
--- /dev/null
+++ b/drivers/of/of_private.h
@@ -0,0 +1,36 @@
1#ifndef _LINUX_OF_PRIVATE_H
2#define _LINUX_OF_PRIVATE_H
3/*
4 * Private symbols used by OF support code
5 *
6 * Paul Mackerras August 1996.
7 * Copyright (C) 1996-2005 Paul Mackerras.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15/**
16 * struct alias_prop - Alias property in 'aliases' node
17 * @link: List node to link the structure in aliases_lookup list
18 * @alias: Alias property name
19 * @np: Pointer to device_node that the alias stands for
20 * @id: Index value from end of alias name
21 * @stem: Alias string without the index
22 *
23 * The structure represents one alias property of 'aliases' node as
24 * an entry in aliases_lookup list.
25 */
26struct alias_prop {
27 struct list_head link;
28 const char *alias;
29 struct device_node *np;
30 int id;
31 char stem[0];
32};
33
34extern struct mutex of_aliases_mutex;
35extern struct list_head aliases_lookup;
36#endif /* _LINUX_OF_PRIVATE_H */