diff options
| -rw-r--r-- | arch/powerpc/kernel/of_device.c | 48 | ||||
| -rw-r--r-- | drivers/of/device.c | 48 | ||||
| -rw-r--r-- | include/asm-powerpc/of_device.h | 2 | ||||
| -rw-r--r-- | include/linux/of_device.h | 3 |
4 files changed, 51 insertions, 50 deletions
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c index 5748ddb47d9f..e9be908f199b 100644 --- a/arch/powerpc/kernel/of_device.c +++ b/arch/powerpc/kernel/of_device.c | |||
| @@ -89,54 +89,6 @@ struct of_device *of_device_alloc(struct device_node *np, | |||
| 89 | } | 89 | } |
| 90 | EXPORT_SYMBOL(of_device_alloc); | 90 | EXPORT_SYMBOL(of_device_alloc); |
| 91 | 91 | ||
| 92 | ssize_t of_device_get_modalias(struct of_device *ofdev, | ||
| 93 | char *str, ssize_t len) | ||
| 94 | { | ||
| 95 | const char *compat; | ||
| 96 | int cplen, i; | ||
| 97 | ssize_t tsize, csize, repend; | ||
| 98 | |||
| 99 | /* Name & Type */ | ||
| 100 | csize = snprintf(str, len, "of:N%sT%s", | ||
| 101 | ofdev->node->name, ofdev->node->type); | ||
| 102 | |||
| 103 | /* Get compatible property if any */ | ||
| 104 | compat = of_get_property(ofdev->node, "compatible", &cplen); | ||
| 105 | if (!compat) | ||
| 106 | return csize; | ||
| 107 | |||
| 108 | /* Find true end (we tolerate multiple \0 at the end */ | ||
| 109 | for (i=(cplen-1); i>=0 && !compat[i]; i--) | ||
| 110 | cplen--; | ||
| 111 | if (!cplen) | ||
| 112 | return csize; | ||
| 113 | cplen++; | ||
| 114 | |||
| 115 | /* Check space (need cplen+1 chars including final \0) */ | ||
| 116 | tsize = csize + cplen; | ||
| 117 | repend = tsize; | ||
| 118 | |||
| 119 | if (csize>=len) /* @ the limit, all is already filled */ | ||
| 120 | return tsize; | ||
| 121 | |||
| 122 | if (tsize>=len) { /* limit compat list */ | ||
| 123 | cplen = len-csize-1; | ||
| 124 | repend = len; | ||
| 125 | } | ||
| 126 | |||
| 127 | /* Copy and do char replacement */ | ||
| 128 | memcpy(&str[csize+1], compat, cplen); | ||
| 129 | for (i=csize; i<repend; i++) { | ||
| 130 | char c = str[i]; | ||
| 131 | if (c=='\0') | ||
| 132 | str[i] = 'C'; | ||
| 133 | else if (c==' ') | ||
| 134 | str[i] = '_'; | ||
| 135 | } | ||
| 136 | |||
| 137 | return tsize; | ||
| 138 | } | ||
| 139 | |||
| 140 | int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) | 92 | int of_device_uevent(struct device *dev, struct kobj_uevent_env *env) |
| 141 | { | 93 | { |
| 142 | struct of_device *ofdev; | 94 | struct of_device *ofdev; |
diff --git a/drivers/of/device.c b/drivers/of/device.c index 8fbfeee53c1e..8a1d93a2bb81 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c | |||
| @@ -104,3 +104,51 @@ void of_device_unregister(struct of_device *ofdev) | |||
| 104 | device_unregister(&ofdev->dev); | 104 | device_unregister(&ofdev->dev); |
| 105 | } | 105 | } |
| 106 | EXPORT_SYMBOL(of_device_unregister); | 106 | EXPORT_SYMBOL(of_device_unregister); |
| 107 | |||
| 108 | ssize_t of_device_get_modalias(struct of_device *ofdev, | ||
| 109 | char *str, ssize_t len) | ||
| 110 | { | ||
| 111 | const char *compat; | ||
| 112 | int cplen, i; | ||
| 113 | ssize_t tsize, csize, repend; | ||
| 114 | |||
| 115 | /* Name & Type */ | ||
| 116 | csize = snprintf(str, len, "of:N%sT%s", | ||
| 117 | ofdev->node->name, ofdev->node->type); | ||
| 118 | |||
| 119 | /* Get compatible property if any */ | ||
| 120 | compat = of_get_property(ofdev->node, "compatible", &cplen); | ||
| 121 | if (!compat) | ||
| 122 | return csize; | ||
| 123 | |||
| 124 | /* Find true end (we tolerate multiple \0 at the end */ | ||
| 125 | for (i = (cplen - 1); i >= 0 && !compat[i]; i--) | ||
| 126 | cplen--; | ||
| 127 | if (!cplen) | ||
| 128 | return csize; | ||
| 129 | cplen++; | ||
| 130 | |||
| 131 | /* Check space (need cplen+1 chars including final \0) */ | ||
| 132 | tsize = csize + cplen; | ||
| 133 | repend = tsize; | ||
| 134 | |||
| 135 | if (csize >= len) /* @ the limit, all is already filled */ | ||
| 136 | return tsize; | ||
| 137 | |||
| 138 | if (tsize >= len) { /* limit compat list */ | ||
| 139 | cplen = len - csize - 1; | ||
| 140 | repend = len; | ||
| 141 | } | ||
| 142 | |||
| 143 | /* Copy and do char replacement */ | ||
| 144 | memcpy(&str[csize + 1], compat, cplen); | ||
| 145 | for (i = csize; i < repend; i++) { | ||
| 146 | char c = str[i]; | ||
| 147 | if (c == '\0') | ||
| 148 | str[i] = 'C'; | ||
| 149 | else if (c == ' ') | ||
| 150 | str[i] = '_'; | ||
| 151 | } | ||
| 152 | |||
| 153 | return tsize; | ||
| 154 | } | ||
diff --git a/include/asm-powerpc/of_device.h b/include/asm-powerpc/of_device.h index 6526e139a463..3c123990ca2e 100644 --- a/include/asm-powerpc/of_device.h +++ b/include/asm-powerpc/of_device.h | |||
| @@ -21,8 +21,6 @@ extern struct of_device *of_device_alloc(struct device_node *np, | |||
| 21 | const char *bus_id, | 21 | const char *bus_id, |
| 22 | struct device *parent); | 22 | struct device *parent); |
| 23 | 23 | ||
| 24 | extern ssize_t of_device_get_modalias(struct of_device *ofdev, | ||
| 25 | char *str, ssize_t len); | ||
| 26 | extern int of_device_uevent(struct device *dev, | 24 | extern int of_device_uevent(struct device *dev, |
| 27 | struct kobj_uevent_env *env); | 25 | struct kobj_uevent_env *env); |
| 28 | 26 | ||
diff --git a/include/linux/of_device.h b/include/linux/of_device.h index afe338217d91..d3a74e00a3e1 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h | |||
| @@ -24,4 +24,7 @@ static inline void of_device_free(struct of_device *dev) | |||
| 24 | of_release_dev(&dev->dev); | 24 | of_release_dev(&dev->dev); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | extern ssize_t of_device_get_modalias(struct of_device *ofdev, | ||
| 28 | char *str, ssize_t len); | ||
| 29 | |||
| 27 | #endif /* _LINUX_OF_DEVICE_H */ | 30 | #endif /* _LINUX_OF_DEVICE_H */ |
