1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2013 Texas Instruments 4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com> 5 */ 6 7 #include <linux/device.h> 8 #include <linux/err.h> 9 #include <linux/module.h> 10 #include <linux/of.h> 11 #include <linux/of_graph.h> 12 #include <linux/seq_file.h> 13 14 #include <video/omapfb_dss.h> 15 16 #include "dss.h" 17 18 struct device_node *dss_of_port_get_parent_device(struct device_node *port) 19 { 20 struct device_node *np; 21 int i; 22 23 if (!port) 24 return NULL; 25 26 np = of_get_parent(port); 27 28 for (i = 0; i < 2 && np; ++i) { 29 struct property *prop; 30 31 prop = of_find_property(np, "compatible", NULL); 32 33 if (prop) 34 return np; 35 36 np = of_get_next_parent(np); 37 } 38 39 return NULL; 40 } 41 42 u32 dss_of_port_get_port_number(struct device_node *port) 43 { 44 int r; 45 u32 reg; 46 47 r = of_property_read_u32(port, "reg", ®); 48 if (r) 49 reg = 0; 50 51 return reg; 52 } 53 54 struct omap_dss_device * 55 omapdss_of_find_source_for_first_ep(struct device_node *node) 56 { 57 struct device_node *ep; 58 struct device_node *src_port; 59 struct omap_dss_device *src; 60 61 ep = of_graph_get_endpoint_by_regs(node, 0, -1); 62 if (!ep) 63 return ERR_PTR(-EINVAL); 64 65 src_port = of_graph_get_remote_port(ep); 66 of_node_put(ep); 67 if (!src_port) 68 return ERR_PTR(-EINVAL); 69 70 src = omap_dss_find_output_by_port_node(src_port); 71 72 of_node_put(src_port); 73 74 return src ? src : ERR_PTR(-EPROBE_DEFER); 75 } 76 EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep); 77