xref: /linux/drivers/gpu/drm/omapdrm/dss/output.c (revision 20bed0d6ff62d985fe8222958825504b8aad4e88)
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 
16 #include "dss.h"
17 #include "omapdss.h"
18 
19 int omapdss_device_init_output(struct omap_dss_device *out,
20 			       struct drm_bridge *local_bridge)
21 {
22 	struct drm_bridge *bridge;
23 	int ret;
24 
25 	bridge = of_drm_get_bridge_by_endpoint(out->dev->of_node, out->of_port, 0);
26 	if (IS_ERR(bridge)) {
27 		dev_dbg(out->dev, "failed to find video sink\n");
28 		return 0;
29 	}
30 
31 	out->bridge = bridge;
32 
33 	if (local_bridge) {
34 		if (!out->bridge) {
35 			ret = -EPROBE_DEFER;
36 			goto error;
37 		}
38 
39 		out->next_bridge = out->bridge;
40 		out->bridge = drm_bridge_get(local_bridge);
41 	}
42 
43 	return 0;
44 
45 error:
46 	omapdss_device_cleanup_output(out);
47 	return ret;
48 }
49 
50 void omapdss_device_cleanup_output(struct omap_dss_device *out)
51 {
52 	drm_bridge_put(out->next_bridge);
53 	drm_bridge_put(out->bridge);
54 }
55 
56 void dss_mgr_set_timings(struct omap_dss_device *dssdev,
57 			 const struct videomode *vm)
58 {
59 	omap_crtc_dss_set_timings(dssdev->dss->mgr_ops_priv,
60 					  dssdev->dispc_channel, vm);
61 }
62 
63 void dss_mgr_set_lcd_config(struct omap_dss_device *dssdev,
64 		const struct dss_lcd_mgr_config *config)
65 {
66 	omap_crtc_dss_set_lcd_config(dssdev->dss->mgr_ops_priv,
67 					     dssdev->dispc_channel, config);
68 }
69 
70 int dss_mgr_enable(struct omap_dss_device *dssdev)
71 {
72 	return omap_crtc_dss_enable(dssdev->dss->mgr_ops_priv,
73 					    dssdev->dispc_channel);
74 }
75 
76 void dss_mgr_disable(struct omap_dss_device *dssdev)
77 {
78 	omap_crtc_dss_disable(dssdev->dss->mgr_ops_priv,
79 				      dssdev->dispc_channel);
80 }
81 
82 void dss_mgr_start_update(struct omap_dss_device *dssdev)
83 {
84 	omap_crtc_dss_start_update(dssdev->dss->mgr_ops_priv,
85 					   dssdev->dispc_channel);
86 }
87 
88 int dss_mgr_register_framedone_handler(struct omap_dss_device *dssdev,
89 		void (*handler)(void *), void *data)
90 {
91 	struct dss_device *dss = dssdev->dss;
92 
93 	return omap_crtc_dss_register_framedone(dss->mgr_ops_priv,
94 							dssdev->dispc_channel,
95 							handler, data);
96 }
97 
98 void dss_mgr_unregister_framedone_handler(struct omap_dss_device *dssdev,
99 		void (*handler)(void *), void *data)
100 {
101 	struct dss_device *dss = dssdev->dss;
102 
103 	omap_crtc_dss_unregister_framedone(dss->mgr_ops_priv,
104 						   dssdev->dispc_channel,
105 						   handler, data);
106 }
107