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 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}
106EXPORT_SYMBOL(of_device_unregister); 106EXPORT_SYMBOL(of_device_unregister);
107
108ssize_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}