treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / omapdrm / dss / omapdss-boot-init.c
blob31502857f013d2129b5db24e0bf2a8da6679dc2e
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
5 */
7 /*
8 * As omapdss panel drivers are omapdss specific, but we want to define the
9 * DT-data in generic manner, we convert the compatible strings of the panel and
10 * encoder nodes from "panel-foo" to "omapdss,panel-foo". This way we can have
11 * both correct DT data and omapdss specific drivers.
13 * When we get generic panel drivers to the kernel, this file will be removed.
16 #include <linux/kernel.h>
17 #include <linux/of.h>
18 #include <linux/of_graph.h>
19 #include <linux/slab.h>
20 #include <linux/list.h>
22 static struct list_head dss_conv_list __initdata;
24 static const char prefix[] __initconst = "omapdss,";
26 struct dss_conv_node {
27 struct list_head list;
28 struct device_node *node;
29 bool root;
32 static int __init omapdss_count_strings(const struct property *prop)
34 const char *p = prop->value;
35 int l = 0, total = 0;
36 int i;
38 for (i = 0; total < prop->length; total += l, p += l, i++)
39 l = strlen(p) + 1;
41 return i;
44 static void __init omapdss_update_prop(struct device_node *node, char *compat,
45 int len)
47 struct property *prop;
49 prop = kzalloc(sizeof(*prop), GFP_KERNEL);
50 if (!prop)
51 return;
53 prop->name = "compatible";
54 prop->value = compat;
55 prop->length = len;
57 of_update_property(node, prop);
60 static void __init omapdss_prefix_strcpy(char *dst, int dst_len,
61 const char *src, int src_len)
63 size_t total = 0;
65 while (total < src_len) {
66 size_t l = strlen(src) + 1;
68 strcpy(dst, prefix);
69 dst += strlen(prefix);
71 strcpy(dst, src);
72 dst += l;
74 src += l;
75 total += l;
79 /* prepend compatible property strings with "omapdss," */
80 static void __init omapdss_omapify_node(struct device_node *node)
82 struct property *prop;
83 char *new_compat;
84 int num_strs;
85 int new_len;
87 prop = of_find_property(node, "compatible", NULL);
89 if (!prop || !prop->value)
90 return;
92 if (strnlen(prop->value, prop->length) >= prop->length)
93 return;
95 /* is it already prefixed? */
96 if (strncmp(prefix, prop->value, strlen(prefix)) == 0)
97 return;
99 num_strs = omapdss_count_strings(prop);
101 new_len = prop->length + strlen(prefix) * num_strs;
102 new_compat = kmalloc(new_len, GFP_KERNEL);
104 omapdss_prefix_strcpy(new_compat, new_len, prop->value, prop->length);
106 omapdss_update_prop(node, new_compat, new_len);
109 static void __init omapdss_add_to_list(struct device_node *node, bool root)
111 struct dss_conv_node *n = kmalloc(sizeof(*n), GFP_KERNEL);
112 if (n) {
113 n->node = node;
114 n->root = root;
115 list_add(&n->list, &dss_conv_list);
119 static bool __init omapdss_list_contains(const struct device_node *node)
121 struct dss_conv_node *n;
123 list_for_each_entry(n, &dss_conv_list, list) {
124 if (n->node == node)
125 return true;
128 return false;
131 static void __init omapdss_walk_device(struct device_node *node, bool root)
133 struct device_node *n;
135 omapdss_add_to_list(node, root);
138 * of_graph_get_remote_port_parent() prints an error if there is no
139 * port/ports node. To avoid that, check first that there's the node.
141 n = of_get_child_by_name(node, "ports");
142 if (!n)
143 n = of_get_child_by_name(node, "port");
144 if (!n)
145 return;
147 of_node_put(n);
149 n = NULL;
150 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
151 struct device_node *pn;
153 pn = of_graph_get_remote_port_parent(n);
155 if (!pn)
156 continue;
158 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
159 of_node_put(pn);
160 continue;
163 omapdss_walk_device(pn, false);
167 static const struct of_device_id omapdss_of_match[] __initconst = {
168 { .compatible = "ti,omap2-dss", },
169 { .compatible = "ti,omap3-dss", },
170 { .compatible = "ti,omap4-dss", },
171 { .compatible = "ti,omap5-dss", },
172 { .compatible = "ti,dra7-dss", },
176 static const struct of_device_id omapdss_of_fixups_whitelist[] __initconst = {
177 { .compatible = "composite-video-connector" },
178 { .compatible = "hdmi-connector" },
179 { .compatible = "panel-dsi-cm" },
180 { .compatible = "svideo-connector" },
181 { .compatible = "ti,opa362" },
182 { .compatible = "ti,tpd12s015" },
186 static int __init omapdss_boot_init(void)
188 struct device_node *dss, *child;
190 INIT_LIST_HEAD(&dss_conv_list);
192 dss = of_find_matching_node(NULL, omapdss_of_match);
194 if (dss == NULL || !of_device_is_available(dss))
195 return 0;
197 omapdss_walk_device(dss, true);
199 for_each_available_child_of_node(dss, child) {
200 if (!of_find_property(child, "compatible", NULL))
201 continue;
203 omapdss_walk_device(child, true);
206 while (!list_empty(&dss_conv_list)) {
207 struct dss_conv_node *n;
209 n = list_first_entry(&dss_conv_list, struct dss_conv_node,
210 list);
212 if (of_match_node(omapdss_of_fixups_whitelist, n->node))
213 omapdss_omapify_node(n->node);
215 list_del(&n->list);
216 of_node_put(n->node);
217 kfree(n);
220 return 0;
223 subsys_initcall(omapdss_boot_init);