1 From 90dc591d4c897c7a49191888c1e4d413cc08b8b7 Mon Sep 17 00:00:00 2001
2 From: Sylvain Munaut <tnt@246tNt.com>
3 Date: Sat, 23 Dec 2006 23:08:56 +0100
4 Subject: [PATCH] [PATCH] powerpc: Add a unified uevent handler for bus based on of_device
6 This common uevent handler allow the several bus types based on
7 of_device to generate the uevent properly and avoiding
10 This handlers take a struct device as argument and can therefore
11 be used as the uevent call directly if no special treatment is
14 Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
16 arch/powerpc/kernel/of_device.c | 66 +++++++++++++++++++++++++++++++++++++++
17 include/asm-powerpc/of_device.h | 3 ++
18 2 files changed, 69 insertions(+), 0 deletions(-)
20 diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
21 index e921514..ac024ad 100644
22 --- a/arch/powerpc/kernel/of_device.c
23 +++ b/arch/powerpc/kernel/of_device.c
24 @@ -120,6 +120,71 @@ void of_device_unregister(struct of_device *ofdev)
28 +int of_device_uevent(struct device *dev,
29 + char **envp, int num_envp, char *buffer, int buffer_size)
31 + struct of_device *ofdev;
34 + char compat_buf[128]; /* need to be size of 'compatible' */
35 + int i = 0, length = 0, seen = 0, cplen, sl;
40 + ofdev = to_of_device(dev);
42 + if (add_uevent_var(envp, num_envp, &i,
43 + buffer, buffer_size, &length,
44 + "OF_NAME=%s", ofdev->node->name))
47 + if (add_uevent_var(envp, num_envp, &i,
48 + buffer, buffer_size, &length,
49 + "OF_TYPE=%s", ofdev->node->type))
52 + /* Since the compatible field can contain pretty much anything
53 + * it's not really legal to split it out with commas. We split it
54 + * up using a number of environment variables instead. */
56 + compat = get_property(ofdev->node, "compatible", &cplen);
57 + compat2 = compat_buf;
59 + memcpy(compat2, compat, cplen);
60 + while (compat && *compat && cplen > 0) {
61 + if (add_uevent_var(envp, num_envp, &i,
62 + buffer, buffer_size, &length,
63 + "OF_COMPATIBLE_%d=%s", seen, compat))
66 + sl = strlen (compat) + 1;
73 + compat2[seen?-1:0] = 0;
75 + if (add_uevent_var(envp, num_envp, &i,
76 + buffer, buffer_size, &length,
77 + "OF_COMPATIBLE_N=%d", seen))
80 + if (add_uevent_var(envp, num_envp, &i,
81 + buffer, buffer_size, &length,
82 + "MODALIAS=of:N%sT%sC%s",
83 + ofdev->node->name, ofdev->node->type,
93 EXPORT_SYMBOL(of_match_node);
94 EXPORT_SYMBOL(of_match_device);
95 EXPORT_SYMBOL(of_device_register);
96 @@ -127,3 +192,4 @@ EXPORT_SYMBOL(of_device_unregister);
97 EXPORT_SYMBOL(of_dev_get);
98 EXPORT_SYMBOL(of_dev_put);
99 EXPORT_SYMBOL(of_release_dev);
100 +EXPORT_SYMBOL(of_device_uevent);
101 diff --git a/include/asm-powerpc/of_device.h b/include/asm-powerpc/of_device.h
102 index a889b20..4f1aabe 100644
103 --- a/include/asm-powerpc/of_device.h
104 +++ b/include/asm-powerpc/of_device.h
105 @@ -32,5 +32,8 @@ extern int of_device_register(struct of_device *ofdev);
106 extern void of_device_unregister(struct of_device *ofdev);
107 extern void of_release_dev(struct device *dev);
109 +extern int of_device_uevent(struct device *dev,
110 + char **envp, int num_envp, char *buffer, int buffer_size);
112 #endif /* __KERNEL__ */
113 #endif /* _ASM_POWERPC_OF_DEVICE_H */