aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of/device.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2012-02-01 13:22:22 -0500
committerGrant Likely <grant.likely@secretlab.ca>2012-02-01 16:26:30 -0500
commit07d57a32fb6eb2da017796e038682f817a4f685e (patch)
tree4c7bb83cbda8db99ed91f575d8355c5b45b16cfb /drivers/of/device.c
parent7aff0fe33033fc75b61446ba29d38b1b1354af9f (diff)
drivercore: Output common devicetree information in uevent
When userspace needs to find a specific device, it currently isn't easy to resolve a /sys/devices/ path from a specific device tree node. Nor is it easy to obtain the compatible list for devices. This patch generalizes the code that inserts OF_* values into the uevent device attribute so that any device that is attached to an OF node will have that information exported to userspace. Without this patch only platform devices and some powerpc-specific busses have access to this data. The original function also creates a MODALIAS property for the compatible list, but that code has not been generalized into the common case because it has the potential to break module loading on a lot of bus types. Bus types are still responsible for their own MODALIAS properties. Boot tested on ARM and compile tested on PowerPC and SPARC. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Tobias Klauser <tklauser@distanz.ch> Cc: Frederic Lambert <frdrc66@gmail.com> Cc: Rob Herring <rob.herring@calxeda.com> Cc: Mark Brown <broonie@sirena.org.uk> Cc: "David S. Miller" <davem@davemloft.net> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/of/device.c')
-rw-r--r--drivers/of/device.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 62b4b32ac887..4c74e4fc5a51 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -128,39 +128,41 @@ ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len)
128/** 128/**
129 * of_device_uevent - Display OF related uevent information 129 * of_device_uevent - Display OF related uevent information
130 */ 130 */
131int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) 131void of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
132{ 132{
133 const char *compat; 133 const char *compat;
134 int seen = 0, cplen, sl; 134 int seen = 0, cplen, sl;
135 135
136 if ((!dev) || (!dev->of_node)) 136 if ((!dev) || (!dev->of_node))
137 return -ENODEV; 137 return;
138
139 if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name))
140 return -ENOMEM;
141 138
142 if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type)) 139 add_uevent_var(env, "OF_NAME=%s", dev->of_node->name);
143 return -ENOMEM; 140 add_uevent_var(env, "OF_FULLNAME=%s", dev->of_node->full_name);
141 if (dev->of_node->type && strcmp("<NULL>", dev->of_node->type) != 0)
142 add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type);
144 143
145 /* Since the compatible field can contain pretty much anything 144 /* Since the compatible field can contain pretty much anything
146 * it's not really legal to split it out with commas. We split it 145 * it's not really legal to split it out with commas. We split it
147 * up using a number of environment variables instead. */ 146 * up using a number of environment variables instead. */
148
149 compat = of_get_property(dev->of_node, "compatible", &cplen); 147 compat = of_get_property(dev->of_node, "compatible", &cplen);
150 while (compat && *compat && cplen > 0) { 148 while (compat && *compat && cplen > 0) {
151 if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat)) 149 add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat);
152 return -ENOMEM;
153
154 sl = strlen(compat) + 1; 150 sl = strlen(compat) + 1;
155 compat += sl; 151 compat += sl;
156 cplen -= sl; 152 cplen -= sl;
157 seen++; 153 seen++;
158 } 154 }
155 add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen);
156}
159 157
160 if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen)) 158int of_device_uevent_modalias(struct device *dev, struct kobj_uevent_env *env)
161 return -ENOMEM; 159{
160 int sl;
161
162 if ((!dev) || (!dev->of_node))
163 return -ENODEV;
162 164
163 /* modalias is trickier, we add it in 2 steps */ 165 /* Devicetree modalias is tricky, we add it in 2 steps */
164 if (add_uevent_var(env, "MODALIAS=")) 166 if (add_uevent_var(env, "MODALIAS="))
165 return -ENOMEM; 167 return -ENOMEM;
166 168