1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/kernel.h>
28#include <linux/of.h>
29#include <linux/of_graph.h>
30#include <linux/slab.h>
31#include <linux/list.h>
32
33static struct list_head dss_conv_list __initdata;
34
35static const char prefix[] __initconst = "omapdss,";
36
37struct dss_conv_node {
38 struct list_head list;
39 struct device_node *node;
40 bool root;
41};
42
43static int __init omapdss_count_strings(const struct property *prop)
44{
45 const char *p = prop->value;
46 int l = 0, total = 0;
47 int i;
48
49 for (i = 0; total < prop->length; total += l, p += l, i++)
50 l = strlen(p) + 1;
51
52 return i;
53}
54
55static void __init omapdss_update_prop(struct device_node *node, char *compat,
56 int len)
57{
58 struct property *prop;
59
60 prop = kzalloc(sizeof(*prop), GFP_KERNEL);
61 if (!prop)
62 return;
63
64 prop->name = "compatible";
65 prop->value = compat;
66 prop->length = len;
67
68 of_update_property(node, prop);
69}
70
71static void __init omapdss_prefix_strcpy(char *dst, int dst_len,
72 const char *src, int src_len)
73{
74 size_t total = 0;
75
76 while (total < src_len) {
77 size_t l = strlen(src) + 1;
78
79 strcpy(dst, prefix);
80 dst += strlen(prefix);
81
82 strcpy(dst, src);
83 dst += l;
84
85 src += l;
86 total += l;
87 }
88}
89
90
91static void __init omapdss_omapify_node(struct device_node *node)
92{
93 struct property *prop;
94 char *new_compat;
95 int num_strs;
96 int new_len;
97
98 prop = of_find_property(node, "compatible", NULL);
99
100 if (!prop || !prop->value)
101 return;
102
103 if (strnlen(prop->value, prop->length) >= prop->length)
104 return;
105
106
107 if (strncmp(prefix, prop->value, strlen(prefix)) == 0)
108 return;
109
110 num_strs = omapdss_count_strings(prop);
111
112 new_len = prop->length + strlen(prefix) * num_strs;
113 new_compat = kmalloc(new_len, GFP_KERNEL);
114
115 omapdss_prefix_strcpy(new_compat, new_len, prop->value, prop->length);
116
117 omapdss_update_prop(node, new_compat, new_len);
118}
119
120static void __init omapdss_add_to_list(struct device_node *node, bool root)
121{
122 struct dss_conv_node *n = kmalloc(sizeof(*n), GFP_KERNEL);
123 if (n) {
124 n->node = node;
125 n->root = root;
126 list_add(&n->list, &dss_conv_list);
127 }
128}
129
130static bool __init omapdss_list_contains(const struct device_node *node)
131{
132 struct dss_conv_node *n;
133
134 list_for_each_entry(n, &dss_conv_list, list) {
135 if (n->node == node)
136 return true;
137 }
138
139 return false;
140}
141
142static void __init omapdss_walk_device(struct device_node *node, bool root)
143{
144 struct device_node *n;
145
146 omapdss_add_to_list(node, root);
147
148
149
150
151
152 n = of_get_child_by_name(node, "ports");
153 if (!n)
154 n = of_get_child_by_name(node, "port");
155 if (!n)
156 return;
157
158 of_node_put(n);
159
160 n = NULL;
161 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
162 struct device_node *pn;
163
164 pn = of_graph_get_remote_port_parent(n);
165
166 if (!pn)
167 continue;
168
169 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
170 of_node_put(pn);
171 continue;
172 }
173
174 omapdss_walk_device(pn, false);
175 }
176}
177
178static const struct of_device_id omapdss_of_match[] __initconst = {
179 { .compatible = "ti,omap2-dss", },
180 { .compatible = "ti,omap3-dss", },
181 { .compatible = "ti,omap4-dss", },
182 { .compatible = "ti,omap5-dss", },
183 { .compatible = "ti,dra7-dss", },
184 {},
185};
186
187static int __init omapdss_boot_init(void)
188{
189 struct device_node *dss, *child;
190
191 INIT_LIST_HEAD(&dss_conv_list);
192
193 dss = of_find_matching_node(NULL, omapdss_of_match);
194
195 if (dss == NULL || !of_device_is_available(dss))
196 return 0;
197
198 omapdss_walk_device(dss, true);
199
200 for_each_available_child_of_node(dss, child) {
201 if (!of_find_property(child, "compatible", NULL))
202 continue;
203
204 omapdss_walk_device(child, true);
205 }
206
207 while (!list_empty(&dss_conv_list)) {
208 struct dss_conv_node *n;
209
210 n = list_first_entry(&dss_conv_list, struct dss_conv_node,
211 list);
212
213 if (!n->root)
214 omapdss_omapify_node(n->node);
215
216 list_del(&n->list);
217 of_node_put(n->node);
218 kfree(n);
219 }
220
221 return 0;
222}
223
224subsys_initcall(omapdss_boot_init);
225