blob: 4602a79c6c446de19672c968e7f4ec8fd6319168 [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}
47
Archit Tanejaef691ff2014-04-22 17:43:48 +053048u32 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
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020060struct omap_dss_device *
61omapdss_of_find_source_for_first_ep(struct device_node *node)
62{
63 struct device_node *ep;
Archit Tanejaef691ff2014-04-22 17:43:48 +053064 struct device_node *src_port;
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020065 struct omap_dss_device *src;
66
Rob Herring09bffa62017-03-22 08:26:08 -050067 ep = of_graph_get_endpoint_by_regs(node, 0, 0);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020068 if (!ep)
69 return ERR_PTR(-EINVAL);
70
Rob Herring09bffa62017-03-22 08:26:08 -050071 src_port = of_graph_get_remote_port(ep);
Archit Tanejaef691ff2014-04-22 17:43:48 +053072 if (!src_port) {
73 of_node_put(ep);
74 return ERR_PTR(-EINVAL);
75 }
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020076
77 of_node_put(ep);
78
Archit Tanejaef691ff2014-04-22 17:43:48 +053079 src = omap_dss_find_output_by_port_node(src_port);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020080
Archit Tanejaef691ff2014-04-22 17:43:48 +053081 of_node_put(src_port);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020082
Archit Tanejaef691ff2014-04-22 17:43:48 +053083 return src ? src : ERR_PTR(-EPROBE_DEFER);
Tomi Valkeinen4e7470d2013-12-03 16:57:40 +020084}
85EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);