blob: 967d9e1b34e5b6464d7db304d956d75636b34fb5 [file] [log] [blame]
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +02001/*
Andrew F. Davisbb5cdf82017-12-05 14:29:31 -06002 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +02003 * 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>
Rob Herring09bffa62017-03-22 08:26:08 -050019#include <linux/of_graph.h>
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020020#include <linux/seq_file.h>
21
Peter Ujfalusi32043da2016-05-27 14:40:49 +030022#include "omapdss.h"
Archit Tanejaef691ff2014-04-22 17:43:48 +053023
Archit Tanejaef691ff2014-04-22 17:43:48 +053024struct device_node *dss_of_port_get_parent_device(struct device_node *port)
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020025{
26 struct device_node *np;
27 int i;
28
Archit Tanejaef691ff2014-04-22 17:43:48 +053029 if (!port)
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020030 return NULL;
31
Jyri Sarha6266f4b2015-08-07 14:04:30 +030032 np = of_get_parent(port);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020033
Archit Tanejaef691ff2014-04-22 17:43:48 +053034 for (i = 0; i < 2 && np; ++i) {
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020035 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}
Tomi Valkeinen82e83f62015-11-05 17:26:18 +020047EXPORT_SYMBOL_GPL(dss_of_port_get_parent_device);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020048
Archit Tanejaef691ff2014-04-22 17:43:48 +053049u32 dss_of_port_get_port_number(struct device_node *port)
50{
51 int r;
52 u32 reg;
53
54 r = of_property_read_u32(port, "reg", &reg);
55 if (r)
56 reg = 0;
57
58 return reg;
59}
Tomi Valkeinen82e83f62015-11-05 17:26:18 +020060EXPORT_SYMBOL_GPL(dss_of_port_get_port_number);
Archit Tanejaef691ff2014-04-22 17:43:48 +053061
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020062struct omap_dss_device *
63omapdss_of_find_source_for_first_ep(struct device_node *node)
64{
65 struct device_node *ep;
Archit Tanejaef691ff2014-04-22 17:43:48 +053066 struct device_node *src_port;
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020067 struct omap_dss_device *src;
68
Rob Herring09bffa62017-03-22 08:26:08 -050069 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020070 if (!ep)
71 return ERR_PTR(-EINVAL);
72
Rob Herring09bffa62017-03-22 08:26:08 -050073 src_port = of_graph_get_remote_port(ep);
Archit Tanejaef691ff2014-04-22 17:43:48 +053074 if (!src_port) {
75 of_node_put(ep);
76 return ERR_PTR(-EINVAL);
77 }
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020078
79 of_node_put(ep);
80
Archit Tanejaef691ff2014-04-22 17:43:48 +053081 src = omap_dss_find_output_by_port_node(src_port);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020082
Archit Tanejaef691ff2014-04-22 17:43:48 +053083 of_node_put(src_port);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020084
Archit Tanejaef691ff2014-04-22 17:43:48 +053085 return src ? src : ERR_PTR(-EPROBE_DEFER);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020086}
87EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);