Linux Audio

Check our new training course

Loading...
v4.17
 1/*
 2 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
 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
15#include <linux/device.h>
16#include <linux/err.h>
17#include <linux/module.h>
18#include <linux/of.h>
19#include <linux/of_graph.h>
20#include <linux/seq_file.h>
21
22#include "omapdss.h"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
24struct device_node *dss_of_port_get_parent_device(struct device_node *port)
25{
26	struct device_node *np;
27	int i;
28
29	if (!port)
30		return NULL;
31
32	np = of_get_parent(port);
33
34	for (i = 0; i < 2 && np; ++i) {
35		struct property *prop;
36
37		prop = of_find_property(np, "compatible", NULL);
38
39		if (prop)
40			return np;
41
42		np = of_get_next_parent(np);
43	}
44
45	return NULL;
46}
47
48u32 dss_of_port_get_port_number(struct device_node *port)
49{
50	int r;
51	u32 reg;
52
53	r = of_property_read_u32(port, "reg", &reg);
54	if (r)
55		reg = 0;
56
57	return reg;
58}
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60struct omap_dss_device *
61omapdss_of_find_source_for_first_ep(struct device_node *node)
62{
63	struct device_node *ep;
64	struct device_node *src_port;
65	struct omap_dss_device *src;
66
67	ep = of_graph_get_endpoint_by_regs(node, 0, 0);
68	if (!ep)
69		return ERR_PTR(-EINVAL);
70
71	src_port = of_graph_get_remote_port(ep);
72	if (!src_port) {
73		of_node_put(ep);
74		return ERR_PTR(-EINVAL);
75	}
76
77	of_node_put(ep);
78
79	src = omap_dss_find_output_by_port_node(src_port);
80
81	of_node_put(src_port);
82
83	return src ? src : ERR_PTR(-EPROBE_DEFER);
84}
85EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);
v4.10.11
  1/*
  2 * Copyright (C) 2013 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
 15#include <linux/device.h>
 16#include <linux/err.h>
 17#include <linux/module.h>
 18#include <linux/of.h>
 
 19#include <linux/seq_file.h>
 20
 21#include "omapdss.h"
 22#include "dss.h"
 23
 24struct device_node *
 25omapdss_of_get_next_port(const struct device_node *parent,
 26			 struct device_node *prev)
 27{
 28	struct device_node *port = NULL;
 29
 30	if (!parent)
 31		return NULL;
 32
 33	if (!prev) {
 34		struct device_node *ports;
 35		/*
 36		 * It's the first call, we have to find a port subnode
 37		 * within this node or within an optional 'ports' node.
 38		 */
 39		ports = of_get_child_by_name(parent, "ports");
 40		if (ports)
 41			parent = ports;
 42
 43		port = of_get_child_by_name(parent, "port");
 44
 45		/* release the 'ports' node */
 46		of_node_put(ports);
 47	} else {
 48		struct device_node *ports;
 49
 50		ports = of_get_parent(prev);
 51		if (!ports)
 52			return NULL;
 53
 54		do {
 55			port = of_get_next_child(ports, prev);
 56			if (!port) {
 57				of_node_put(ports);
 58				return NULL;
 59			}
 60			prev = port;
 61		} while (of_node_cmp(port->name, "port") != 0);
 62
 63		of_node_put(ports);
 64	}
 65
 66	return port;
 67}
 68EXPORT_SYMBOL_GPL(omapdss_of_get_next_port);
 69
 70struct device_node *
 71omapdss_of_get_next_endpoint(const struct device_node *parent,
 72			     struct device_node *prev)
 73{
 74	struct device_node *ep = NULL;
 75
 76	if (!parent)
 77		return NULL;
 78
 79	do {
 80		ep = of_get_next_child(parent, prev);
 81		if (!ep)
 82			return NULL;
 83		prev = ep;
 84	} while (of_node_cmp(ep->name, "endpoint") != 0);
 85
 86	return ep;
 87}
 88EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint);
 89
 90struct device_node *dss_of_port_get_parent_device(struct device_node *port)
 91{
 92	struct device_node *np;
 93	int i;
 94
 95	if (!port)
 96		return NULL;
 97
 98	np = of_get_parent(port);
 99
100	for (i = 0; i < 2 && np; ++i) {
101		struct property *prop;
102
103		prop = of_find_property(np, "compatible", NULL);
104
105		if (prop)
106			return np;
107
108		np = of_get_next_parent(np);
109	}
110
111	return NULL;
112}
113
114u32 dss_of_port_get_port_number(struct device_node *port)
115{
116	int r;
117	u32 reg;
118
119	r = of_property_read_u32(port, "reg", &reg);
120	if (r)
121		reg = 0;
122
123	return reg;
124}
125
126static struct device_node *omapdss_of_get_remote_port(const struct device_node *node)
127{
128	struct device_node *np;
129
130	np = of_parse_phandle(node, "remote-endpoint", 0);
131	if (!np)
132		return NULL;
133
134	np = of_get_next_parent(np);
135
136	return np;
137}
138
139struct device_node *
140omapdss_of_get_first_endpoint(const struct device_node *parent)
141{
142	struct device_node *port, *ep;
143
144	port = omapdss_of_get_next_port(parent, NULL);
145
146	if (!port)
147		return NULL;
148
149	ep = omapdss_of_get_next_endpoint(port, NULL);
150
151	of_node_put(port);
152
153	return ep;
154}
155EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint);
156
157struct omap_dss_device *
158omapdss_of_find_source_for_first_ep(struct device_node *node)
159{
160	struct device_node *ep;
161	struct device_node *src_port;
162	struct omap_dss_device *src;
163
164	ep = omapdss_of_get_first_endpoint(node);
165	if (!ep)
166		return ERR_PTR(-EINVAL);
167
168	src_port = omapdss_of_get_remote_port(ep);
169	if (!src_port) {
170		of_node_put(ep);
171		return ERR_PTR(-EINVAL);
172	}
173
174	of_node_put(ep);
175
176	src = omap_dss_find_output_by_port_node(src_port);
177
178	of_node_put(src_port);
179
180	return src ? src : ERR_PTR(-EPROBE_DEFER);
181}
182EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);