xref: /OK3568_Linux_fs/kernel/drivers/video/fbdev/omap2/omapfb/dss/output.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) 2012 Texas Instruments Ltd
4*4882a593Smuzhiyun  * Author: Archit Taneja <archit@ti.com>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/kernel.h>
8*4882a593Smuzhiyun #include <linux/module.h>
9*4882a593Smuzhiyun #include <linux/platform_device.h>
10*4882a593Smuzhiyun #include <linux/slab.h>
11*4882a593Smuzhiyun #include <linux/of.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <video/omapfb_dss.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include "dss.h"
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun static LIST_HEAD(output_list);
18*4882a593Smuzhiyun static DEFINE_MUTEX(output_lock);
19*4882a593Smuzhiyun 
omapdss_output_set_device(struct omap_dss_device * out,struct omap_dss_device * dssdev)20*4882a593Smuzhiyun int omapdss_output_set_device(struct omap_dss_device *out,
21*4882a593Smuzhiyun 		struct omap_dss_device *dssdev)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	int r;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	mutex_lock(&output_lock);
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 	if (out->dst) {
28*4882a593Smuzhiyun 		DSSERR("output already has device %s connected to it\n",
29*4882a593Smuzhiyun 			out->dst->name);
30*4882a593Smuzhiyun 		r = -EINVAL;
31*4882a593Smuzhiyun 		goto err;
32*4882a593Smuzhiyun 	}
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	if (out->output_type != dssdev->type) {
35*4882a593Smuzhiyun 		DSSERR("output type and display type don't match\n");
36*4882a593Smuzhiyun 		r = -EINVAL;
37*4882a593Smuzhiyun 		goto err;
38*4882a593Smuzhiyun 	}
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 	out->dst = dssdev;
41*4882a593Smuzhiyun 	dssdev->src = out;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	mutex_unlock(&output_lock);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	return 0;
46*4882a593Smuzhiyun err:
47*4882a593Smuzhiyun 	mutex_unlock(&output_lock);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	return r;
50*4882a593Smuzhiyun }
51*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_output_set_device);
52*4882a593Smuzhiyun 
omapdss_output_unset_device(struct omap_dss_device * out)53*4882a593Smuzhiyun int omapdss_output_unset_device(struct omap_dss_device *out)
54*4882a593Smuzhiyun {
55*4882a593Smuzhiyun 	int r;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	mutex_lock(&output_lock);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	if (!out->dst) {
60*4882a593Smuzhiyun 		DSSERR("output doesn't have a device connected to it\n");
61*4882a593Smuzhiyun 		r = -EINVAL;
62*4882a593Smuzhiyun 		goto err;
63*4882a593Smuzhiyun 	}
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
66*4882a593Smuzhiyun 		DSSERR("device %s is not disabled, cannot unset device\n",
67*4882a593Smuzhiyun 				out->dst->name);
68*4882a593Smuzhiyun 		r = -EINVAL;
69*4882a593Smuzhiyun 		goto err;
70*4882a593Smuzhiyun 	}
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	out->dst->src = NULL;
73*4882a593Smuzhiyun 	out->dst = NULL;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	mutex_unlock(&output_lock);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	return 0;
78*4882a593Smuzhiyun err:
79*4882a593Smuzhiyun 	mutex_unlock(&output_lock);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	return r;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_output_unset_device);
84*4882a593Smuzhiyun 
omapdss_register_output(struct omap_dss_device * out)85*4882a593Smuzhiyun int omapdss_register_output(struct omap_dss_device *out)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun 	list_add_tail(&out->list, &output_list);
88*4882a593Smuzhiyun 	return 0;
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_register_output);
91*4882a593Smuzhiyun 
omapdss_unregister_output(struct omap_dss_device * out)92*4882a593Smuzhiyun void omapdss_unregister_output(struct omap_dss_device *out)
93*4882a593Smuzhiyun {
94*4882a593Smuzhiyun 	list_del(&out->list);
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_unregister_output);
97*4882a593Smuzhiyun 
omap_dss_get_output(enum omap_dss_output_id id)98*4882a593Smuzhiyun struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	struct omap_dss_device *out;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	list_for_each_entry(out, &output_list, list) {
103*4882a593Smuzhiyun 		if (out->id == id)
104*4882a593Smuzhiyun 			return out;
105*4882a593Smuzhiyun 	}
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	return NULL;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun EXPORT_SYMBOL(omap_dss_get_output);
110*4882a593Smuzhiyun 
omap_dss_find_output(const char * name)111*4882a593Smuzhiyun struct omap_dss_device *omap_dss_find_output(const char *name)
112*4882a593Smuzhiyun {
113*4882a593Smuzhiyun 	struct omap_dss_device *out;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun 	list_for_each_entry(out, &output_list, list) {
116*4882a593Smuzhiyun 		if (strcmp(out->name, name) == 0)
117*4882a593Smuzhiyun 			return omap_dss_get_device(out);
118*4882a593Smuzhiyun 	}
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun 	return NULL;
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun EXPORT_SYMBOL(omap_dss_find_output);
123*4882a593Smuzhiyun 
omap_dss_find_output_by_port_node(struct device_node * port)124*4882a593Smuzhiyun struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
125*4882a593Smuzhiyun {
126*4882a593Smuzhiyun 	struct device_node *src_node;
127*4882a593Smuzhiyun 	struct omap_dss_device *out;
128*4882a593Smuzhiyun 	u32 reg;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	src_node = dss_of_port_get_parent_device(port);
131*4882a593Smuzhiyun 	if (!src_node)
132*4882a593Smuzhiyun 		return NULL;
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun 	reg = dss_of_port_get_port_number(port);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 	list_for_each_entry(out, &output_list, list) {
137*4882a593Smuzhiyun 		if (out->dev->of_node == src_node && out->port_num == reg) {
138*4882a593Smuzhiyun 			of_node_put(src_node);
139*4882a593Smuzhiyun 			return omap_dss_get_device(out);
140*4882a593Smuzhiyun 		}
141*4882a593Smuzhiyun 	}
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	of_node_put(src_node);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun 	return NULL;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
148*4882a593Smuzhiyun 
omapdss_find_output_from_display(struct omap_dss_device * dssdev)149*4882a593Smuzhiyun struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
150*4882a593Smuzhiyun {
151*4882a593Smuzhiyun 	while (dssdev->src)
152*4882a593Smuzhiyun 		dssdev = dssdev->src;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun 	if (dssdev->id != 0)
155*4882a593Smuzhiyun 		return omap_dss_get_device(dssdev);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	return NULL;
158*4882a593Smuzhiyun }
159*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_find_output_from_display);
160*4882a593Smuzhiyun 
omapdss_find_mgr_from_display(struct omap_dss_device * dssdev)161*4882a593Smuzhiyun struct omap_overlay_manager *omapdss_find_mgr_from_display(struct omap_dss_device *dssdev)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun 	struct omap_dss_device *out;
164*4882a593Smuzhiyun 	struct omap_overlay_manager *mgr;
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun 	out = omapdss_find_output_from_display(dssdev);
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	if (out == NULL)
169*4882a593Smuzhiyun 		return NULL;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	mgr = out->manager;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	omap_dss_put_device(out);
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	return mgr;
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun EXPORT_SYMBOL(omapdss_find_mgr_from_display);
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun static const struct dss_mgr_ops *dss_mgr_ops;
180*4882a593Smuzhiyun 
dss_install_mgr_ops(const struct dss_mgr_ops * mgr_ops)181*4882a593Smuzhiyun int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun 	if (dss_mgr_ops)
184*4882a593Smuzhiyun 		return -EBUSY;
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	dss_mgr_ops = mgr_ops;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	return 0;
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun EXPORT_SYMBOL(dss_install_mgr_ops);
191*4882a593Smuzhiyun 
dss_uninstall_mgr_ops(void)192*4882a593Smuzhiyun void dss_uninstall_mgr_ops(void)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun 	dss_mgr_ops = NULL;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun EXPORT_SYMBOL(dss_uninstall_mgr_ops);
197*4882a593Smuzhiyun 
dss_mgr_connect(struct omap_overlay_manager * mgr,struct omap_dss_device * dst)198*4882a593Smuzhiyun int dss_mgr_connect(struct omap_overlay_manager *mgr,
199*4882a593Smuzhiyun 		struct omap_dss_device *dst)
200*4882a593Smuzhiyun {
201*4882a593Smuzhiyun 	return dss_mgr_ops->connect(mgr, dst);
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_connect);
204*4882a593Smuzhiyun 
dss_mgr_disconnect(struct omap_overlay_manager * mgr,struct omap_dss_device * dst)205*4882a593Smuzhiyun void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
206*4882a593Smuzhiyun 		struct omap_dss_device *dst)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun 	dss_mgr_ops->disconnect(mgr, dst);
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_disconnect);
211*4882a593Smuzhiyun 
dss_mgr_set_timings(struct omap_overlay_manager * mgr,const struct omap_video_timings * timings)212*4882a593Smuzhiyun void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
213*4882a593Smuzhiyun 		const struct omap_video_timings *timings)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun 	dss_mgr_ops->set_timings(mgr, timings);
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_set_timings);
218*4882a593Smuzhiyun 
dss_mgr_set_lcd_config(struct omap_overlay_manager * mgr,const struct dss_lcd_mgr_config * config)219*4882a593Smuzhiyun void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
220*4882a593Smuzhiyun 		const struct dss_lcd_mgr_config *config)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun 	dss_mgr_ops->set_lcd_config(mgr, config);
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_set_lcd_config);
225*4882a593Smuzhiyun 
dss_mgr_enable(struct omap_overlay_manager * mgr)226*4882a593Smuzhiyun int dss_mgr_enable(struct omap_overlay_manager *mgr)
227*4882a593Smuzhiyun {
228*4882a593Smuzhiyun 	return dss_mgr_ops->enable(mgr);
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_enable);
231*4882a593Smuzhiyun 
dss_mgr_disable(struct omap_overlay_manager * mgr)232*4882a593Smuzhiyun void dss_mgr_disable(struct omap_overlay_manager *mgr)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun 	dss_mgr_ops->disable(mgr);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_disable);
237*4882a593Smuzhiyun 
dss_mgr_start_update(struct omap_overlay_manager * mgr)238*4882a593Smuzhiyun void dss_mgr_start_update(struct omap_overlay_manager *mgr)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun 	dss_mgr_ops->start_update(mgr);
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_start_update);
243*4882a593Smuzhiyun 
dss_mgr_register_framedone_handler(struct omap_overlay_manager * mgr,void (* handler)(void *),void * data)244*4882a593Smuzhiyun int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
245*4882a593Smuzhiyun 		void (*handler)(void *), void *data)
246*4882a593Smuzhiyun {
247*4882a593Smuzhiyun 	return dss_mgr_ops->register_framedone_handler(mgr, handler, data);
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
250*4882a593Smuzhiyun 
dss_mgr_unregister_framedone_handler(struct omap_overlay_manager * mgr,void (* handler)(void *),void * data)251*4882a593Smuzhiyun void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
252*4882a593Smuzhiyun 		void (*handler)(void *), void *data)
253*4882a593Smuzhiyun {
254*4882a593Smuzhiyun 	dss_mgr_ops->unregister_framedone_handler(mgr, handler, data);
255*4882a593Smuzhiyun }
256*4882a593Smuzhiyun EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);
257