omapfb: Create new header file for omapfb DSS implementation
[linux-2.6/btrfs-unstable.git] / drivers / video / fbdev / omap2 / omapfb / dss / output.c
blobbed9a978269df9d0b3bf80d5691fc4b204e4a292
1 /*
2 * Copyright (C) 2012 Texas Instruments Ltd
3 * Author: Archit Taneja <archit@ti.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
22 #include <linux/of.h>
24 #include <video/omapfb_dss.h>
26 #include "dss.h"
28 static LIST_HEAD(output_list);
29 static DEFINE_MUTEX(output_lock);
31 int omapdss_output_set_device(struct omap_dss_device *out,
32 struct omap_dss_device *dssdev)
34 int r;
36 mutex_lock(&output_lock);
38 if (out->dst) {
39 DSSERR("output already has device %s connected to it\n",
40 out->dst->name);
41 r = -EINVAL;
42 goto err;
45 if (out->output_type != dssdev->type) {
46 DSSERR("output type and display type don't match\n");
47 r = -EINVAL;
48 goto err;
51 out->dst = dssdev;
52 dssdev->src = out;
54 mutex_unlock(&output_lock);
56 return 0;
57 err:
58 mutex_unlock(&output_lock);
60 return r;
62 EXPORT_SYMBOL(omapdss_output_set_device);
64 int omapdss_output_unset_device(struct omap_dss_device *out)
66 int r;
68 mutex_lock(&output_lock);
70 if (!out->dst) {
71 DSSERR("output doesn't have a device connected to it\n");
72 r = -EINVAL;
73 goto err;
76 if (out->dst->state != OMAP_DSS_DISPLAY_DISABLED) {
77 DSSERR("device %s is not disabled, cannot unset device\n",
78 out->dst->name);
79 r = -EINVAL;
80 goto err;
83 out->dst->src = NULL;
84 out->dst = NULL;
86 mutex_unlock(&output_lock);
88 return 0;
89 err:
90 mutex_unlock(&output_lock);
92 return r;
94 EXPORT_SYMBOL(omapdss_output_unset_device);
96 int omapdss_register_output(struct omap_dss_device *out)
98 list_add_tail(&out->list, &output_list);
99 return 0;
101 EXPORT_SYMBOL(omapdss_register_output);
103 void omapdss_unregister_output(struct omap_dss_device *out)
105 list_del(&out->list);
107 EXPORT_SYMBOL(omapdss_unregister_output);
109 struct omap_dss_device *omap_dss_get_output(enum omap_dss_output_id id)
111 struct omap_dss_device *out;
113 list_for_each_entry(out, &output_list, list) {
114 if (out->id == id)
115 return out;
118 return NULL;
120 EXPORT_SYMBOL(omap_dss_get_output);
122 struct omap_dss_device *omap_dss_find_output(const char *name)
124 struct omap_dss_device *out;
126 list_for_each_entry(out, &output_list, list) {
127 if (strcmp(out->name, name) == 0)
128 return omap_dss_get_device(out);
131 return NULL;
133 EXPORT_SYMBOL(omap_dss_find_output);
135 struct omap_dss_device *omap_dss_find_output_by_port_node(struct device_node *port)
137 struct device_node *src_node;
138 struct omap_dss_device *out;
139 u32 reg;
141 src_node = dss_of_port_get_parent_device(port);
142 if (!src_node)
143 return NULL;
145 reg = dss_of_port_get_port_number(port);
147 list_for_each_entry(out, &output_list, list) {
148 if (out->dev->of_node == src_node && out->port_num == reg) {
149 of_node_put(src_node);
150 return omap_dss_get_device(out);
154 of_node_put(src_node);
156 return NULL;
158 EXPORT_SYMBOL(omap_dss_find_output_by_port_node);
160 struct omap_dss_device *omapdss_find_output_from_display(struct omap_dss_device *dssdev)
162 while (dssdev->src)
163 dssdev = dssdev->src;
165 if (dssdev->id != 0)
166 return omap_dss_get_device(dssdev);
168 return NULL;
170 EXPORT_SYMBOL(omapdss_find_output_from_display);
172 struct omap_overlay_manager *omapdss_find_mgr_from_display(struct omap_dss_device *dssdev)
174 struct omap_dss_device *out;
175 struct omap_overlay_manager *mgr;
177 out = omapdss_find_output_from_display(dssdev);
179 if (out == NULL)
180 return NULL;
182 mgr = out->manager;
184 omap_dss_put_device(out);
186 return mgr;
188 EXPORT_SYMBOL(omapdss_find_mgr_from_display);
190 static const struct dss_mgr_ops *dss_mgr_ops;
192 int dss_install_mgr_ops(const struct dss_mgr_ops *mgr_ops)
194 if (dss_mgr_ops)
195 return -EBUSY;
197 dss_mgr_ops = mgr_ops;
199 return 0;
201 EXPORT_SYMBOL(dss_install_mgr_ops);
203 void dss_uninstall_mgr_ops(void)
205 dss_mgr_ops = NULL;
207 EXPORT_SYMBOL(dss_uninstall_mgr_ops);
209 int dss_mgr_connect(struct omap_overlay_manager *mgr,
210 struct omap_dss_device *dst)
212 return dss_mgr_ops->connect(mgr, dst);
214 EXPORT_SYMBOL(dss_mgr_connect);
216 void dss_mgr_disconnect(struct omap_overlay_manager *mgr,
217 struct omap_dss_device *dst)
219 dss_mgr_ops->disconnect(mgr, dst);
221 EXPORT_SYMBOL(dss_mgr_disconnect);
223 void dss_mgr_set_timings(struct omap_overlay_manager *mgr,
224 const struct omap_video_timings *timings)
226 dss_mgr_ops->set_timings(mgr, timings);
228 EXPORT_SYMBOL(dss_mgr_set_timings);
230 void dss_mgr_set_lcd_config(struct omap_overlay_manager *mgr,
231 const struct dss_lcd_mgr_config *config)
233 dss_mgr_ops->set_lcd_config(mgr, config);
235 EXPORT_SYMBOL(dss_mgr_set_lcd_config);
237 int dss_mgr_enable(struct omap_overlay_manager *mgr)
239 return dss_mgr_ops->enable(mgr);
241 EXPORT_SYMBOL(dss_mgr_enable);
243 void dss_mgr_disable(struct omap_overlay_manager *mgr)
245 dss_mgr_ops->disable(mgr);
247 EXPORT_SYMBOL(dss_mgr_disable);
249 void dss_mgr_start_update(struct omap_overlay_manager *mgr)
251 dss_mgr_ops->start_update(mgr);
253 EXPORT_SYMBOL(dss_mgr_start_update);
255 int dss_mgr_register_framedone_handler(struct omap_overlay_manager *mgr,
256 void (*handler)(void *), void *data)
258 return dss_mgr_ops->register_framedone_handler(mgr, handler, data);
260 EXPORT_SYMBOL(dss_mgr_register_framedone_handler);
262 void dss_mgr_unregister_framedone_handler(struct omap_overlay_manager *mgr,
263 void (*handler)(void *), void *data)
265 dss_mgr_ops->unregister_framedone_handler(mgr, handler, data);
267 EXPORT_SYMBOL(dss_mgr_unregister_framedone_handler);