drm/rockchip: Don't change hdmi reference clock rate
[drm/drm-misc.git] / drivers / video / fbdev / omap2 / omapfb / dss / output.c
blob4e2992a0ce50ea4c56c76ac2505040878c8832b1
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2012 Texas Instruments Ltd
4 * Author: Archit Taneja <archit@ti.com>
5 */
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>
13 #include <video/omapfb_dss.h>
15 #include "dss.h"
17 static LIST_HEAD(output_list);
18 static DEFINE_MUTEX(output_lock);
20 int omapdss_output_set_device(struct omap_dss_device *out,
21 struct omap_dss_device *dssdev)
23 int r;
25 mutex_lock(&output_lock);
27 if (out->dst) {
28 DSSERR("output already has device %s connected to it\n",
29 out->dst->name);
30 r = -EINVAL;
31 goto err;
34 if (out->output_type != dssdev->type) {
35 DSSERR("output type and display type don't match\n");
36 r = -EINVAL;
37 goto err;
40 out->dst = dssdev;
41 dssdev->src = out;
43 mutex_unlock(&output_lock);
45 return 0;
46 err:
47 mutex_unlock(&output_lock);
49 return r;
51 EXPORT_SYMBOL(omapdss_output_set_device);
53 int omapdss_output_unset_device(struct omap_dss_device *out)
55 int r;
57 mutex_lock(&output_lock);
59 if (!out->dst) {
60 DSSERR("output doesn't have a device connected to it\n");
61 r = -EINVAL;
62 goto err;
65 if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
66 DSSERR("device %s is not disabled, cannot unset device\n",
67 out->dst->name);
68 r = -EINVAL;
69 goto err;
72 out->dst->src = NULL;
73 out->dst = NULL;
75 mutex_unlock(&output_lock);
77 return 0;
78 err:
79 mutex_unlock(&output_lock);
81 return r;
83 EXPORT_SYMBOL(omapdss_output_unset_device);
85 int omapdss_register_output(struct omap_dss_device *out)
87 list_add_tail(&out->list, &output_list);
88 return 0;
90 EXPORT_SYMBOL(omapdss_register_output);
92 void omapdss_unregister_output(struct omap_dss_device *out)
94 list_del(&out->list);
96 EXPORT_SYMBOL(omapdss_unregister_output);
98 struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
100 struct omap_dss_device *out;
102 list_for_each_entry(out, &output_list, list) {
103 if (out->id == id)
104 return out;
107 return NULL;
109 EXPORT_SYMBOL(omap_dss_get_output);
111 struct omap_dss_device *omap_dss_find_output(const char *name)
113 struct omap_dss_device *out;
115 list_for_each_entry(out, &output_list, list) {
116 if (strcmp(out->name, name) == 0)
117 return omap_dss_get_device(out);
120 return NULL;
122 EXPORT_SYMBOL(omap_dss_find_output);
124 struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
126 struct device_node *src_node;
127 struct omap_dss_device *out;
128 u32 reg;
130 src_node = dss_of_port_get_parent_device(port);
131 if (!src_node)
132 return NULL;
134 reg = dss_of_port_get_port_number(port);
136 list_for_each_entry(out, &output_list, list) {
137 if (out->dev->of_node == src_node && out->port_num == reg) {
138 of_node_put(src_node);
139 return omap_dss_get_device(out);
143 of_node_put(src_node);
145 return NULL;
147 EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
149 struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
151 while (dssdev->src)
152 dssdev = dssdev->src;
154 if (dssdev->id != 0)
155 return omap_dss_get_device(dssdev);
157 return NULL;
159 EXPORT_SYMBOL(omapdss_find_output_from_display);
161 struct omap_overlay_manager *omapdss_find_mgr_from_display(struct omap_dss_device *dssdev)
163 struct omap_dss_device *out;
164 struct omap_overlay_manager *mgr;
166 out = omapdss_find_output_from_display(dssdev);
168 if (out == NULL)
169 return NULL;
171 mgr = out->manager;
173 omap_dss_put_device(out);
175 return mgr;
177 EXPORT_SYMBOL(omapdss_find_mgr_from_display);
179 static const struct dss_mgr_ops *dss_mgr_ops;
181 int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
183 if (dss_mgr_ops)
184 return -EBUSY;
186 dss_mgr_ops = mgr_ops;
188 return 0;
190 EXPORT_SYMBOL(dss_install_mgr_ops);
192 void dss_uninstall_mgr_ops(void)
194 dss_mgr_ops = NULL;
196 EXPORT_SYMBOL(dss_uninstall_mgr_ops);
198 int dss_mgr_connect(struct omap_overlay_manager *mgr,
199 struct omap_dss_device *dst)
201 return dss_mgr_ops->connect(mgr, dst);
203 EXPORT_SYMBOL(dss_mgr_connect);
205 void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
206 struct omap_dss_device *dst)
208 dss_mgr_ops->disconnect(mgr, dst);
210 EXPORT_SYMBOL(dss_mgr_disconnect);
212 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
213 const struct omap_video_timings *timings)
215 dss_mgr_ops->set_timings(mgr, timings);
217 EXPORT_SYMBOL(dss_mgr_set_timings);
219 void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
220 const struct dss_lcd_mgr_config *config)
222 dss_mgr_ops->set_lcd_config(mgr, config);
224 EXPORT_SYMBOL(dss_mgr_set_lcd_config);
226 int dss_mgr_enable(struct omap_overlay_manager *mgr)
228 return dss_mgr_ops->enable(mgr);
230 EXPORT_SYMBOL(dss_mgr_enable);
232 void dss_mgr_disable(struct omap_overlay_manager *mgr)
234 dss_mgr_ops->disable(mgr);
236 EXPORT_SYMBOL(dss_mgr_disable);
238 void dss_mgr_start_update(struct omap_overlay_manager *mgr)
240 dss_mgr_ops->start_update(mgr);
242 EXPORT_SYMBOL(dss_mgr_start_update);
244 int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
245 void (*handler)(void *), void *data)
247 return dss_mgr_ops->register_framedone_handler(mgr, handler, data);
249 EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
251 void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
252 void (*handler)(void *), void *data)
254 dss_mgr_ops->unregister_framedone_handler(mgr, handler, data);
256 EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);