Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 * Copyright (C) 2014 Texas Instruments
  3 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  4 *
  5 * This program is free software; you can redistribute it and/or modify it
  6 * under the terms of the GNU General Public License version 2 as published by
  7 * the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it will be useful, but WITHOUT
 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 12 * more details.
 13 *
 14 * You should have received a copy of the GNU General Public License along with
 15 * this program.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17
 18/*
 19 * As omapdss panel drivers are omapdss specific, but we want to define the
 20 * DT-data in generic manner, we convert the compatible strings of the panel and
 21 * encoder nodes from "panel-foo" to "omapdss,panel-foo". This way we can have
 22 * both correct DT data and omapdss specific drivers.
 23 *
 24 * When we get generic panel drivers to the kernel, this file will be removed.
 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/* prepend compatible property strings with "omapdss," */
 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	/* is it already prefixed? */
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(struct dss_conv_node),
123		GFP_KERNEL);
124	if (n) {
125		n->node = node;
126		n->root = root;
127		list_add(&n->list, &dss_conv_list);
128	}
129}
130
131static bool __init omapdss_list_contains(const struct device_node *node)
132{
133	struct dss_conv_node *n;
134
135	list_for_each_entry(n, &dss_conv_list, list) {
136		if (n->node == node)
137			return true;
138	}
139
140	return false;
141}
142
143static void __init omapdss_walk_device(struct device_node *node, bool root)
144{
145	struct device_node *n;
146
147	omapdss_add_to_list(node, root);
148
149	/*
150	 * of_graph_get_remote_port_parent() prints an error if there is no
151	 * port/ports node. To avoid that, check first that there's the node.
152	 */
153	n = of_get_child_by_name(node, "ports");
154	if (!n)
155		n = of_get_child_by_name(node, "port");
156	if (!n)
157		return;
158
159	of_node_put(n);
160
161	n = NULL;
162	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
163		struct device_node *pn;
164
165		pn = of_graph_get_remote_port_parent(n);
166
167		if (!pn)
168			continue;
169
170		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
171			of_node_put(pn);
172			continue;
173		}
174
175		omapdss_walk_device(pn, false);
176	}
177}
178
179static const struct of_device_id omapdss_of_match[] __initconst = {
180	{ .compatible = "ti,omap2-dss", },
181	{ .compatible = "ti,omap3-dss", },
182	{ .compatible = "ti,omap4-dss", },
183	{ .compatible = "ti,omap5-dss", },
184	{ .compatible = "ti,dra7-dss", },
185	{},
186};
187
 
 
 
 
 
 
 
 
 
 
188static int __init omapdss_boot_init(void)
189{
190	struct device_node *dss, *child;
191
192	INIT_LIST_HEAD(&dss_conv_list);
193
194	dss = of_find_matching_node(NULL, omapdss_of_match);
195
196	if (dss == NULL || !of_device_is_available(dss))
197		return 0;
198
199	omapdss_walk_device(dss, true);
200
201	for_each_available_child_of_node(dss, child) {
202		if (!of_find_property(child, "compatible", NULL))
203			continue;
204
205		omapdss_walk_device(child, true);
206	}
207
208	while (!list_empty(&dss_conv_list)) {
209		struct dss_conv_node *n;
210
211		n = list_first_entry(&dss_conv_list, struct dss_conv_node,
212			list);
213
214		if (!n->root)
215			omapdss_omapify_node(n->node);
216
217		list_del(&n->list);
218		of_node_put(n->node);
219		kfree(n);
220	}
221
222	return 0;
223}
224
225subsys_initcall(omapdss_boot_init);
v5.4
  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 */
  6
  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.
 12 *
 13 * When we get generic panel drivers to the kernel, this file will be removed.
 14 */
 15
 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>
 21
 22static struct list_head dss_conv_list __initdata;
 23
 24static const char prefix[] __initconst = "omapdss,";
 25
 26struct dss_conv_node {
 27	struct list_head list;
 28	struct device_node *node;
 29	bool root;
 30};
 31
 32static int __init omapdss_count_strings(const struct property *prop)
 33{
 34	const char *p = prop->value;
 35	int l = 0, total = 0;
 36	int i;
 37
 38	for (i = 0; total < prop->length; total += l, p += l, i++)
 39		l = strlen(p) + 1;
 40
 41	return i;
 42}
 43
 44static void __init omapdss_update_prop(struct device_node *node, char *compat,
 45	int len)
 46{
 47	struct property *prop;
 48
 49	prop = kzalloc(sizeof(*prop), GFP_KERNEL);
 50	if (!prop)
 51		return;
 52
 53	prop->name = "compatible";
 54	prop->value = compat;
 55	prop->length = len;
 56
 57	of_update_property(node, prop);
 58}
 59
 60static void __init omapdss_prefix_strcpy(char *dst, int dst_len,
 61	const char *src, int src_len)
 62{
 63	size_t total = 0;
 64
 65	while (total < src_len) {
 66		size_t l = strlen(src) + 1;
 67
 68		strcpy(dst, prefix);
 69		dst += strlen(prefix);
 70
 71		strcpy(dst, src);
 72		dst += l;
 73
 74		src += l;
 75		total += l;
 76	}
 77}
 78
 79/* prepend compatible property strings with "omapdss," */
 80static void __init omapdss_omapify_node(struct device_node *node)
 81{
 82	struct property *prop;
 83	char *new_compat;
 84	int num_strs;
 85	int new_len;
 86
 87	prop = of_find_property(node, "compatible", NULL);
 88
 89	if (!prop || !prop->value)
 90		return;
 91
 92	if (strnlen(prop->value, prop->length) >= prop->length)
 93		return;
 94
 95	/* is it already prefixed? */
 96	if (strncmp(prefix, prop->value, strlen(prefix)) == 0)
 97		return;
 98
 99	num_strs = omapdss_count_strings(prop);
100
101	new_len = prop->length + strlen(prefix) * num_strs;
102	new_compat = kmalloc(new_len, GFP_KERNEL);
103
104	omapdss_prefix_strcpy(new_compat, new_len, prop->value, prop->length);
105
106	omapdss_update_prop(node, new_compat, new_len);
107}
108
109static void __init omapdss_add_to_list(struct device_node *node, bool root)
110{
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);
116	}
117}
118
119static bool __init omapdss_list_contains(const struct device_node *node)
120{
121	struct dss_conv_node *n;
122
123	list_for_each_entry(n, &dss_conv_list, list) {
124		if (n->node == node)
125			return true;
126	}
127
128	return false;
129}
130
131static void __init omapdss_walk_device(struct device_node *node, bool root)
132{
133	struct device_node *n;
134
135	omapdss_add_to_list(node, root);
136
137	/*
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.
140	 */
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;
146
147	of_node_put(n);
148
149	n = NULL;
150	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
151		struct device_node *pn;
152
153		pn = of_graph_get_remote_port_parent(n);
154
155		if (!pn)
156			continue;
157
158		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
159			of_node_put(pn);
160			continue;
161		}
162
163		omapdss_walk_device(pn, false);
164	}
165}
166
167static 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", },
173	{},
174};
175
176static 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" },
183	{},
184};
185
186static int __init omapdss_boot_init(void)
187{
188	struct device_node *dss, *child;
189
190	INIT_LIST_HEAD(&dss_conv_list);
191
192	dss = of_find_matching_node(NULL, omapdss_of_match);
193
194	if (dss == NULL || !of_device_is_available(dss))
195		return 0;
196
197	omapdss_walk_device(dss, true);
198
199	for_each_available_child_of_node(dss, child) {
200		if (!of_find_property(child, "compatible", NULL))
201			continue;
202
203		omapdss_walk_device(child, true);
204	}
205
206	while (!list_empty(&dss_conv_list)) {
207		struct dss_conv_node *n;
208
209		n = list_first_entry(&dss_conv_list, struct dss_conv_node,
210			list);
211
212		if (of_match_node(omapdss_of_fixups_whitelist, n->node))
213			omapdss_omapify_node(n->node);
214
215		list_del(&n->list);
216		of_node_put(n->node);
217		kfree(n);
218	}
219
220	return 0;
221}
222
223subsys_initcall(omapdss_boot_init);