xref: /linux/drivers/gpu/drm/omapdrm/dss/output.c (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2012 Texas Instruments Incorporated - https://www.ti.com/
4  * Author: Archit Taneja <archit@ti.com>
5  */
6 
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/slab.h>
11 #include <linux/of.h>
12 #include <linux/of_graph.h>
13 
14 #include <drm/drm_bridge.h>
15 #include <drm/drm_panel.h>
16 
17 #include "dss.h"
18 #include "omapdss.h"
19 
20 int omapdss_device_init_output(struct omap_dss_device *out,
21 			       struct drm_bridge *local_bridge)
22 {
23 	struct device_node *remote_node;
24 	int ret;
25 
26 	remote_node = of_graph_get_remote_node(out->dev->of_node,
27 					       out->of_port, 0);
28 	if (!remote_node) {
29 		dev_dbg(out->dev, "failed to find video sink\n");
30 		return 0;
31 	}
32 
33 	out->panel = of_drm_find_panel(remote_node);
34 	if (IS_ERR(out->panel))
35 		out->panel = NULL;
36 
37 	if (!out->panel)
38 		out->bridge = of_drm_find_and_get_bridge(remote_node);
39 
40 	of_node_put(remote_node);
41 
42 	if (out->panel) {
43 		struct drm_bridge *bridge;
44 
45 		bridge = drm_panel_bridge_add(out->panel);
46 		drm_panel_put(out->panel);
47 		if (IS_ERR(bridge)) {
48 			dev_err(out->dev,
49 				"unable to create panel bridge (%ld)\n",
50 				PTR_ERR(bridge));
51 			ret = PTR_ERR(bridge);
52 			goto error;
53 		}
54 
55 		out->bridge = drm_bridge_get(bridge);
56 	}
57 
58 	if (local_bridge) {
59 		if (!out->bridge) {
60 			ret = -EPROBE_DEFER;
61 			goto error;
62 		}
63 
64 		out->next_bridge = out->bridge;
65 		out->bridge = drm_bridge_get(local_bridge);
66 	}
67 
68 	if (!out->bridge) {
69 		ret = -EPROBE_DEFER;
70 		goto error;
71 	}
72 
73 	return 0;
74 
75 error:
76 	omapdss_device_cleanup_output(out);
77 	return ret;
78 }
79 
80 void omapdss_device_cleanup_output(struct omap_dss_device *out)
81 {
82 	if (out->bridge && out->panel)
83 		drm_panel_bridge_remove(out->next_bridge ?
84 					out->next_bridge : out->bridge);
85 
86 	drm_bridge_put(out->next_bridge);
87 	drm_bridge_put(out->bridge);
88 }
89 
90 void dss_mgr_set_timings(struct omap_dss_device *dssdev,
91 			 const struct videomode *vm)
92 {
93 	omap_crtc_dss_set_timings(dssdev->dss->mgr_ops_priv,
94 					  dssdev->dispc_channel, vm);
95 }
96 
97 void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev,
98 		const struct dss_lcd_mgr_config *config)
99 {
100 	omap_crtc_dss_set_lcd_config(dssdev->dss->mgr_ops_priv,
101 					     dssdev->dispc_channel, config);
102 }
103 
104 int dss_mgr_enable(struct omap_dss_device *dssdev)
105 {
106 	return omap_crtc_dss_enable(dssdev->dss->mgr_ops_priv,
107 					    dssdev->dispc_channel);
108 }
109 
110 void dss_mgr_disable(struct omap_dss_device *dssdev)
111 {
112 	omap_crtc_dss_disable(dssdev->dss->mgr_ops_priv,
113 				      dssdev->dispc_channel);
114 }
115 
116 void dss_mgr_start_update(struct omap_dss_device *dssdev)
117 {
118 	omap_crtc_dss_start_update(dssdev->dss->mgr_ops_priv,
119 					   dssdev->dispc_channel);
120 }
121 
122 int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev,
123 		void (*handler)(void *), void *data)
124 {
125 	struct dss_device *dss = dssdev->dss;
126 
127 	return omap_crtc_dss_register_framedone(dss->mgr_ops_priv,
128 							dssdev->dispc_channel,
129 							handler, data);
130 }
131 
132 void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev,
133 		void (*handler)(void *), void *data)
134 {
135 	struct dss_device *dss = dssdev->dss;
136 
137 	omap_crtc_dss_unregister_framedone(dss->mgr_ops_priv,
138 						   dssdev->dispc_channel,
139 						   handler, data);
140 }
141