]> git.karo-electronics.de Git - linux-beck.git/commitdiff
of: Output devicetree alias names in uevent
authorStepan Moskovchenko <stepanm@codeaurora.org>
Thu, 6 Dec 2012 22:55:41 +0000 (14:55 -0800)
committerGrant Likely <grant.likely@secretlab.ca>
Wed, 6 Feb 2013 11:06:35 +0000 (11:06 +0000)
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>
drivers/of/base.c
drivers/of/device.c
drivers/of/of_private.h [new file with mode: 0644]

index 2390ddb22d6094d5b39809aa8f6a7510b7c25c7f..d1bb50719ed7aa16ca57647d2745976c79c2f087 100644 (file)
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
 
-/**
- * struct alias_prop - Alias property in 'aliases' node
- * @link:      List node to link the structure in aliases_lookup list
- * @alias:     Alias property name
- * @np:                Pointer to device_node that the alias stands for
- * @id:                Index value from end of alias name
- * @stem:      Alias string without the index
- *
- * The structure represents one alias property of 'aliases' node as
- * an entry in aliases_lookup list.
- */
-struct alias_prop {
-       struct list_head link;
-       const char *alias;
-       struct device_node *np;
-       int id;
-       char stem[0];
-};
+#include "of_private.h"
 
-static LIST_HEAD(aliases_lookup);
+LIST_HEAD(aliases_lookup);
 
 struct device_node *of_allnodes;
 EXPORT_SYMBOL(of_allnodes);
 struct device_node *of_chosen;
 struct device_node *of_aliases;
 
-static DEFINE_MUTEX(of_aliases_mutex);
+DEFINE_MUTEX(of_aliases_mutex);
 
 /* use when traversing tree through the allnext, child, sibling,
  * or parent members of struct device_node.
index 4c74e4fc5a5190857be5eaa749b82284ee8a2fb1..f685e55e0717f611bf479f95d790675d6bb77bf5 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/slab.h>
 
 #include <asm/errno.h>
+#include "of_private.h"
 
 /**
  * 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)
 void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
        const char *compat;
+       struct alias_prop *app;
        int seen = 0, cplen, sl;
 
        if ((!dev) || (!dev->of_node))
@@ -153,6 +155,17 @@ void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
                seen++;
        }
        add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen);
+
+       seen = 0;
+       mutex_lock(&of_aliases_mutex);
+       list_for_each_entry(app, &aliases_lookup, link) {
+               if (dev->of_node == app->np) {
+                       add_uevent_var(env, "OF_ALIAS_%d=%s", seen,
+                                      app->alias);
+                       seen++;
+               }
+       }
+       mutex_unlock(&of_aliases_mutex);
 }
 
 int 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 (file)
index 0000000..ff350c8
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef _LINUX_OF_PRIVATE_H
+#define _LINUX_OF_PRIVATE_H
+/*
+ * Private symbols used by OF support code
+ *
+ * Paul Mackerras      August 1996.
+ * Copyright (C) 1996-2005 Paul Mackerras.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+/**
+ * struct alias_prop - Alias property in 'aliases' node
+ * @link:      List node to link the structure in aliases_lookup list
+ * @alias:     Alias property name
+ * @np:                Pointer to device_node that the alias stands for
+ * @id:                Index value from end of alias name
+ * @stem:      Alias string without the index
+ *
+ * The structure represents one alias property of 'aliases' node as
+ * an entry in aliases_lookup list.
+ */
+struct alias_prop {
+       struct list_head link;
+       const char *alias;
+       struct device_node *np;
+       int id;
+       char stem[0];
+};
+
+extern struct mutex of_aliases_mutex;
+extern struct list_head aliases_lookup;
+#endif /* _LINUX_OF_PRIVATE_H */