2 * linux/drivers/video/omap2/dss/manager.c
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
7 * Some code and ideas taken from drivers/video/omap/ driver
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DSS_SUBSYS_NAME "MANAGER"
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/module.h>
28 #include <linux/platform_device.h>
29 #include <linux/jiffies.h>
31 #include <video/omapdss.h>
34 #include "dss_features.h"
36 static int num_managers;
37 static struct omap_overlay_manager *managers;
39 static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
41 unsigned long timeout = msecs_to_jiffies(500);
45 r = dispc_runtime_get();
49 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC)
50 irq = DISPC_IRQ_EVSYNC_ODD;
51 else if (mgr->device->type == OMAP_DISPLAY_TYPE_HDMI)
52 irq = DISPC_IRQ_EVSYNC_EVEN;
54 irq = dispc_mgr_get_vsync_irq(mgr->id);
56 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
63 int dss_init_overlay_managers(struct platform_device *pdev)
67 num_managers = dss_feat_get_num_mgrs();
69 managers = kzalloc(sizeof(struct omap_overlay_manager) * num_managers,
72 BUG_ON(managers == NULL);
74 for (i = 0; i < num_managers; ++i) {
75 struct omap_overlay_manager *mgr = &managers[i];
80 mgr->id = OMAP_DSS_CHANNEL_LCD;
84 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
88 mgr->id = OMAP_DSS_CHANNEL_LCD2;
92 mgr->id = OMAP_DSS_CHANNEL_LCD3;
96 mgr->set_device = &dss_mgr_set_device;
97 mgr->unset_device = &dss_mgr_unset_device;
98 mgr->apply = &omap_dss_mgr_apply;
99 mgr->set_manager_info = &dss_mgr_set_info;
100 mgr->get_manager_info = &dss_mgr_get_info;
101 mgr->wait_for_go = &dss_mgr_wait_for_go;
102 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
105 mgr->supported_displays =
106 dss_feat_get_supported_displays(mgr->id);
108 INIT_LIST_HEAD(&mgr->overlays);
110 r = dss_manager_kobj_init(mgr, pdev);
112 DSSERR("failed to create sysfs file\n");
118 void dss_uninit_overlay_managers(struct platform_device *pdev)
122 for (i = 0; i < num_managers; ++i) {
123 struct omap_overlay_manager *mgr = &managers[i];
124 dss_manager_kobj_uninit(mgr);
132 int omap_dss_get_num_overlay_managers(void)
136 EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
138 struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
140 if (num >= num_managers)
143 return &managers[num];
145 EXPORT_SYMBOL(omap_dss_get_overlay_manager);
147 int dss_mgr_simple_check(struct omap_overlay_manager *mgr,
148 const struct omap_overlay_manager_info *info)
150 if (dss_has_feature(FEAT_ALPHA_FIXED_ZORDER)) {
152 * OMAP3 supports only graphics source transparency color key
153 * and alpha blending simultaneously. See TRM 15.4.2.4.2.2
156 if (info->partial_alpha_enabled && info->trans_enabled
157 && info->trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST) {
158 DSSERR("check_manager: illegal transparency key\n");
166 static int dss_mgr_check_zorder(struct omap_overlay_manager *mgr,
167 struct omap_overlay_info **overlay_infos)
169 struct omap_overlay *ovl1, *ovl2;
170 struct omap_overlay_info *info1, *info2;
172 list_for_each_entry(ovl1, &mgr->overlays, list) {
173 info1 = overlay_infos[ovl1->id];
178 list_for_each_entry(ovl2, &mgr->overlays, list) {
182 info2 = overlay_infos[ovl2->id];
187 if (info1->zorder == info2->zorder) {
188 DSSERR("overlays %d and %d have the same "
190 ovl1->id, ovl2->id, info1->zorder);
199 int dss_mgr_check_timings(struct omap_overlay_manager *mgr,
200 const struct omap_video_timings *timings)
202 if (!dispc_mgr_timings_ok(mgr->id, timings)) {
203 DSSERR("check_manager: invalid timings\n");
210 static int dss_mgr_check_lcd_config(struct omap_overlay_manager *mgr,
211 const struct dss_lcd_mgr_config *config)
213 struct dispc_clock_info cinfo = config->clock_info;
214 int dl = config->video_port_width;
215 bool stallmode = config->stallmode;
216 bool fifohandcheck = config->fifohandcheck;
218 if (cinfo.lck_div < 1 || cinfo.lck_div > 255)
221 if (cinfo.pck_div < 1 || cinfo.pck_div > 255)
224 if (dl != 12 && dl != 16 && dl != 18 && dl != 24)
227 /* fifohandcheck should be used only with stallmode */
228 if (stallmode == false && fifohandcheck == true)
232 * io pad mode can be only checked by using dssdev connected to the
233 * manager. Ignore checking these for now, add checks when manager
234 * is capable of holding information related to the connected interface
240 int dss_mgr_check(struct omap_overlay_manager *mgr,
241 struct omap_overlay_manager_info *info,
242 const struct omap_video_timings *mgr_timings,
243 const struct dss_lcd_mgr_config *lcd_config,
244 struct omap_overlay_info **overlay_infos)
246 struct omap_overlay *ovl;
249 if (dss_has_feature(FEAT_ALPHA_FREE_ZORDER)) {
250 r = dss_mgr_check_zorder(mgr, overlay_infos);
255 r = dss_mgr_check_timings(mgr, mgr_timings);
259 r = dss_mgr_check_lcd_config(mgr, lcd_config);
263 list_for_each_entry(ovl, &mgr->overlays, list) {
264 struct omap_overlay_info *oi;
267 oi = overlay_infos[ovl->id];
272 r = dss_ovl_check(ovl, oi, mgr_timings);