]> Git Repo - linux.git/blob - drivers/gpu/drm/omapdrm/dss/dss-of.c
Merge tag 'char-misc-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
[linux.git] / drivers / gpu / drm / omapdrm / dss / dss-of.c
1 /*
2  * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
3  * Author: Tomi Valkeinen <[email protected]>
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
24 static struct device_node *
25 dss_of_port_get_parent_device(struct device_node *port)
26 {
27         struct device_node *np;
28         int i;
29
30         if (!port)
31                 return NULL;
32
33         np = of_get_parent(port);
34
35         for (i = 0; i < 2 && np; ++i) {
36                 struct property *prop;
37
38                 prop = of_find_property(np, "compatible", NULL);
39
40                 if (prop)
41                         return np;
42
43                 np = of_get_next_parent(np);
44         }
45
46         return NULL;
47 }
48
49 struct omap_dss_device *
50 omapdss_of_find_connected_device(struct device_node *node, unsigned int port)
51 {
52         struct device_node *src_node;
53         struct device_node *src_port;
54         struct device_node *ep;
55         struct omap_dss_device *src;
56         u32 port_number = 0;
57
58         /* Get the endpoint... */
59         ep = of_graph_get_endpoint_by_regs(node, port, 0);
60         if (!ep)
61                 return NULL;
62
63         /* ... and its remote port... */
64         src_port = of_graph_get_remote_port(ep);
65         of_node_put(ep);
66         if (!src_port)
67                 return NULL;
68
69         /* ... and the remote port's number and parent... */
70         of_property_read_u32(src_port, "reg", &port_number);
71         src_node = dss_of_port_get_parent_device(src_port);
72         of_node_put(src_port);
73         if (!src_node)
74                 return ERR_PTR(-EINVAL);
75
76         /* ... and finally the connected device. */
77         src = omapdss_find_device_by_port(src_node, port_number);
78         of_node_put(src_node);
79
80         return src ? src : ERR_PTR(-EPROBE_DEFER);
81 }
82 EXPORT_SYMBOL_GPL(omapdss_of_find_connected_device);
This page took 0.040552 seconds and 4 git commands to generate.