aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
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}