aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2010-06-08 09:48:12 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:28 -0400
commitdd27dcda37f0b1a3b674760fb411abc5c8fe309c (patch)
treef6b582fabc8b4f723f8209102665442fcba53364 /drivers/of
parentd3571c3acfabb6f3a93b517b75d9b30eb7e8692e (diff)
of/device: merge of_device_uevent
Merge common code between powerpc and microblaze Signed-off-by: Grant Likely <grant.likely@secretlab.ca> CC: Michal Simek <monstr@monstr.eu> CC: Wolfram Sang <w.sang@pengutronix.de> CC: Stephen Rothwell <sfr@canb.auug.org.au> CC: Benjamin Herrenschmidt <benh@kernel.crashing.org> CC: microblaze-uclinux@itee.uq.edu.au CC: linuxppc-dev@ozlabs.org
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/device.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/drivers/of/device.c b/drivers/of/device.c
index 7d18f8e0b013..275cc9cee14c 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -170,3 +170,51 @@ ssize_t of_device_get_modalias(struct of_device *ofdev,
170 170
171 return tsize; 171 return tsize;
172} 172}
173
174/**
175 * of_device_uevent - Display OF related uevent information
176 */
177int of_device_uevent(struct device *dev, struct kobj_uevent_env *env)
178{
179 const char *compat;
180 int seen = 0, cplen, sl;
181
182 if ((!dev) || (!dev->of_node))
183 return -ENODEV;
184
185 if (add_uevent_var(env, "OF_NAME=%s", dev->of_node->name))
186 return -ENOMEM;
187
188 if (add_uevent_var(env, "OF_TYPE=%s", dev->of_node->type))
189 return -ENOMEM;
190
191 /* Since the compatible field can contain pretty much anything
192 * it's not really legal to split it out with commas. We split it
193 * up using a number of environment variables instead. */
194
195 compat = of_get_property(dev->of_node, "compatible", &cplen);
196 while (compat && *compat && cplen > 0) {
197 if (add_uevent_var(env, "OF_COMPATIBLE_%d=%s", seen, compat))
198 return -ENOMEM;
199
200 sl = strlen(compat) + 1;
201 compat += sl;
202 cplen -= sl;
203 seen++;
204 }
205
206 if (add_uevent_var(env, "OF_COMPATIBLE_N=%d", seen))
207 return -ENOMEM;
208
209 /* modalias is trickier, we add it in 2 steps */
210 if (add_uevent_var(env, "MODALIAS="))
211 return -ENOMEM;
212
213 sl = of_device_get_modalias(to_of_device(dev), &env->buf[env->buflen-1],
214 sizeof(env->buf) - env->buflen);
215 if (sl >= (sizeof(env->buf) - env->buflen))
216 return -ENOMEM;
217 env->buflen += sl;
218
219 return 0;
220}