blob: 6e821810deec092324a0f1013fbb3cb32bba72dd [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
2 * linux/drivers/video/omap2/dss/overlay.c
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
6 *
7 * Some code and ideas taken from drivers/video/omap/ driver
8 * by Imre Deak.
9 *
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.
13 *
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
17 * more details.
18 *
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/>.
21 */
22
23#define DSS_SUBSYS_NAME "OVERLAY"
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/err.h>
28#include <linux/sysfs.h>
29#include <linux/kobject.h>
30#include <linux/platform_device.h>
31#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030033
Tomi Valkeinena0b38cc2011-05-11 14:05:07 +030034#include <video/omapdss.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030035#include <plat/cpu.h>
36
37#include "dss.h"
Archit Tanejaa0acb552010-09-15 19:20:00 +053038#include "dss_features.h"
Tomi Valkeineneed07e02009-08-07 13:43:20 +030039
40static int num_overlays;
Tomi Valkeinen58452342011-11-05 10:39:59 +020041static struct omap_overlay *overlays;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030042
43static ssize_t overlay_name_show(struct omap_overlay *ovl, char *buf)
44{
45 return snprintf(buf, PAGE_SIZE, "%s\n", ovl->name);
46}
47
48static ssize_t overlay_manager_show(struct omap_overlay *ovl, char *buf)
49{
50 return snprintf(buf, PAGE_SIZE, "%s\n",
51 ovl->manager ? ovl->manager->name : "<none>");
52}
53
54static ssize_t overlay_manager_store(struct omap_overlay *ovl, const char *buf,
55 size_t size)
56{
57 int i, r;
58 struct omap_overlay_manager *mgr = NULL;
59 struct omap_overlay_manager *old_mgr;
60 int len = size;
61
62 if (buf[size-1] == '\n')
63 --len;
64
65 if (len > 0) {
66 for (i = 0; i < omap_dss_get_num_overlay_managers(); ++i) {
67 mgr = omap_dss_get_overlay_manager(i);
68
Archit Tanejaf3c77d62010-08-02 15:14:11 +020069 if (sysfs_streq(buf, mgr->name))
Tomi Valkeineneed07e02009-08-07 13:43:20 +030070 break;
71
72 mgr = NULL;
73 }
74 }
75
76 if (len > 0 && mgr == NULL)
77 return -EINVAL;
78
79 if (mgr)
80 DSSDBG("manager %s found\n", mgr->name);
81
82 if (mgr == ovl->manager)
83 return size;
84
85 old_mgr = ovl->manager;
86
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030087 r = dispc_runtime_get();
88 if (r)
89 return r;
90
Tomi Valkeineneed07e02009-08-07 13:43:20 +030091 /* detach old manager */
92 if (old_mgr) {
93 r = ovl->unset_manager(ovl);
94 if (r) {
95 DSSERR("detach failed\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +030096 goto err;
Tomi Valkeineneed07e02009-08-07 13:43:20 +030097 }
98
99 r = old_mgr->apply(old_mgr);
100 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300101 goto err;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300102 }
103
104 if (mgr) {
105 r = ovl->set_manager(ovl, mgr);
106 if (r) {
107 DSSERR("Failed to attach overlay\n");
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300108 goto err;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300109 }
110
111 r = mgr->apply(mgr);
112 if (r)
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300113 goto err;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300114 }
115
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300116 dispc_runtime_put();
117
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300118 return size;
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300119
120err:
121 dispc_runtime_put();
122 return r;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300123}
124
125static ssize_t overlay_input_size_show(struct omap_overlay *ovl, char *buf)
126{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200127 struct omap_overlay_info info;
128
129 ovl->get_overlay_info(ovl, &info);
130
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300131 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200132 info.width, info.height);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300133}
134
135static ssize_t overlay_screen_width_show(struct omap_overlay *ovl, char *buf)
136{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200137 struct omap_overlay_info info;
138
139 ovl->get_overlay_info(ovl, &info);
140
141 return snprintf(buf, PAGE_SIZE, "%d\n", info.screen_width);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300142}
143
144static ssize_t overlay_position_show(struct omap_overlay *ovl, char *buf)
145{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200146 struct omap_overlay_info info;
147
148 ovl->get_overlay_info(ovl, &info);
149
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300150 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200151 info.pos_x, info.pos_y);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300152}
153
154static ssize_t overlay_position_store(struct omap_overlay *ovl,
155 const char *buf, size_t size)
156{
157 int r;
158 char *last;
159 struct omap_overlay_info info;
160
161 ovl->get_overlay_info(ovl, &info);
162
163 info.pos_x = simple_strtoul(buf, &last, 10);
164 ++last;
165 if (last - buf >= size)
166 return -EINVAL;
167
168 info.pos_y = simple_strtoul(last, &last, 10);
169
170 r = ovl->set_overlay_info(ovl, &info);
171 if (r)
172 return r;
173
174 if (ovl->manager) {
175 r = ovl->manager->apply(ovl->manager);
176 if (r)
177 return r;
178 }
179
180 return size;
181}
182
183static ssize_t overlay_output_size_show(struct omap_overlay *ovl, char *buf)
184{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200185 struct omap_overlay_info info;
186
187 ovl->get_overlay_info(ovl, &info);
188
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300189 return snprintf(buf, PAGE_SIZE, "%d,%d\n",
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200190 info.out_width, info.out_height);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300191}
192
193static ssize_t overlay_output_size_store(struct omap_overlay *ovl,
194 const char *buf, size_t size)
195{
196 int r;
197 char *last;
198 struct omap_overlay_info info;
199
200 ovl->get_overlay_info(ovl, &info);
201
202 info.out_width = simple_strtoul(buf, &last, 10);
203 ++last;
204 if (last - buf >= size)
205 return -EINVAL;
206
207 info.out_height = simple_strtoul(last, &last, 10);
208
209 r = ovl->set_overlay_info(ovl, &info);
210 if (r)
211 return r;
212
213 if (ovl->manager) {
214 r = ovl->manager->apply(ovl->manager);
215 if (r)
216 return r;
217 }
218
219 return size;
220}
221
222static ssize_t overlay_enabled_show(struct omap_overlay *ovl, char *buf)
223{
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200224 return snprintf(buf, PAGE_SIZE, "%d\n", ovl->is_enabled(ovl));
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300225}
226
227static ssize_t overlay_enabled_store(struct omap_overlay *ovl, const char *buf,
228 size_t size)
229{
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300230 int r;
231 bool enable;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300232
Tomi Valkeinene3a26ae2011-08-15 15:55:55 +0300233 r = strtobool(buf, &enable);
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300234 if (r)
235 return r;
236
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200237 if (enable)
238 r = ovl->enable(ovl);
239 else
240 r = ovl->disable(ovl);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300241
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300242 if (r)
243 return r;
244
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300245 return size;
246}
247
248static ssize_t overlay_global_alpha_show(struct omap_overlay *ovl, char *buf)
249{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200250 struct omap_overlay_info info;
251
252 ovl->get_overlay_info(ovl, &info);
253
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300254 return snprintf(buf, PAGE_SIZE, "%d\n",
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200255 info.global_alpha);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300256}
257
258static ssize_t overlay_global_alpha_store(struct omap_overlay *ovl,
259 const char *buf, size_t size)
260{
261 int r;
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300262 u8 alpha;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300263 struct omap_overlay_info info;
264
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300265 if ((ovl->caps & OMAP_DSS_OVL_CAP_GLOBAL_ALPHA) == 0)
Tomi Valkeinen332e9d72011-05-27 14:22:16 +0300266 return -ENODEV;
267
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300268 r = kstrtou8(buf, 0, &alpha);
269 if (r)
270 return r;
271
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300272 ovl->get_overlay_info(ovl, &info);
273
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300274 info.global_alpha = alpha;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300275
276 r = ovl->set_overlay_info(ovl, &info);
277 if (r)
278 return r;
279
280 if (ovl->manager) {
281 r = ovl->manager->apply(ovl->manager);
282 if (r)
283 return r;
284 }
285
286 return size;
287}
288
Rajkumar Nfd28a392010-11-04 12:28:42 +0100289static ssize_t overlay_pre_mult_alpha_show(struct omap_overlay *ovl,
290 char *buf)
291{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200292 struct omap_overlay_info info;
293
294 ovl->get_overlay_info(ovl, &info);
295
Rajkumar Nfd28a392010-11-04 12:28:42 +0100296 return snprintf(buf, PAGE_SIZE, "%d\n",
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200297 info.pre_mult_alpha);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100298}
299
300static ssize_t overlay_pre_mult_alpha_store(struct omap_overlay *ovl,
301 const char *buf, size_t size)
302{
303 int r;
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300304 u8 alpha;
Rajkumar Nfd28a392010-11-04 12:28:42 +0100305 struct omap_overlay_info info;
306
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300307 if ((ovl->caps & OMAP_DSS_OVL_CAP_PRE_MULT_ALPHA) == 0)
308 return -ENODEV;
309
Tomi Valkeinene3502ce2011-04-04 15:40:23 +0300310 r = kstrtou8(buf, 0, &alpha);
311 if (r)
312 return r;
313
Rajkumar Nfd28a392010-11-04 12:28:42 +0100314 ovl->get_overlay_info(ovl, &info);
315
Tomi Valkeinenf6dc8152011-08-15 15:18:20 +0300316 info.pre_mult_alpha = alpha;
Rajkumar Nfd28a392010-11-04 12:28:42 +0100317
318 r = ovl->set_overlay_info(ovl, &info);
319 if (r)
320 return r;
321
322 if (ovl->manager) {
323 r = ovl->manager->apply(ovl->manager);
324 if (r)
325 return r;
326 }
327
328 return size;
329}
330
Archit Taneja54128702011-09-08 11:29:17 +0530331static ssize_t overlay_zorder_show(struct omap_overlay *ovl, char *buf)
332{
Tomi Valkeinenc1a9feb2011-11-16 14:11:56 +0200333 struct omap_overlay_info info;
334
335 ovl->get_overlay_info(ovl, &info);
336
337 return snprintf(buf, PAGE_SIZE, "%d\n", info.zorder);
Archit Taneja54128702011-09-08 11:29:17 +0530338}
339
340static ssize_t overlay_zorder_store(struct omap_overlay *ovl,
341 const char *buf, size_t size)
342{
343 int r;
344 u8 zorder;
345 struct omap_overlay_info info;
346
347 if ((ovl->caps & OMAP_DSS_OVL_CAP_ZORDER) == 0)
348 return -ENODEV;
349
350 r = kstrtou8(buf, 0, &zorder);
351 if (r)
352 return r;
353
354 ovl->get_overlay_info(ovl, &info);
355
356 info.zorder = zorder;
357
358 r = ovl->set_overlay_info(ovl, &info);
359 if (r)
360 return r;
361
362 if (ovl->manager) {
363 r = ovl->manager->apply(ovl->manager);
364 if (r)
365 return r;
366 }
367
368 return size;
369}
370
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300371struct overlay_attribute {
372 struct attribute attr;
373 ssize_t (*show)(struct omap_overlay *, char *);
374 ssize_t (*store)(struct omap_overlay *, const char *, size_t);
375};
376
377#define OVERLAY_ATTR(_name, _mode, _show, _store) \
378 struct overlay_attribute overlay_attr_##_name = \
379 __ATTR(_name, _mode, _show, _store)
380
381static OVERLAY_ATTR(name, S_IRUGO, overlay_name_show, NULL);
382static OVERLAY_ATTR(manager, S_IRUGO|S_IWUSR,
383 overlay_manager_show, overlay_manager_store);
384static OVERLAY_ATTR(input_size, S_IRUGO, overlay_input_size_show, NULL);
385static OVERLAY_ATTR(screen_width, S_IRUGO, overlay_screen_width_show, NULL);
386static OVERLAY_ATTR(position, S_IRUGO|S_IWUSR,
387 overlay_position_show, overlay_position_store);
388static OVERLAY_ATTR(output_size, S_IRUGO|S_IWUSR,
389 overlay_output_size_show, overlay_output_size_store);
390static OVERLAY_ATTR(enabled, S_IRUGO|S_IWUSR,
391 overlay_enabled_show, overlay_enabled_store);
392static OVERLAY_ATTR(global_alpha, S_IRUGO|S_IWUSR,
393 overlay_global_alpha_show, overlay_global_alpha_store);
Rajkumar Nfd28a392010-11-04 12:28:42 +0100394static OVERLAY_ATTR(pre_mult_alpha, S_IRUGO|S_IWUSR,
395 overlay_pre_mult_alpha_show,
396 overlay_pre_mult_alpha_store);
Archit Taneja54128702011-09-08 11:29:17 +0530397static OVERLAY_ATTR(zorder, S_IRUGO|S_IWUSR,
398 overlay_zorder_show, overlay_zorder_store);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300399
400static struct attribute *overlay_sysfs_attrs[] = {
401 &overlay_attr_name.attr,
402 &overlay_attr_manager.attr,
403 &overlay_attr_input_size.attr,
404 &overlay_attr_screen_width.attr,
405 &overlay_attr_position.attr,
406 &overlay_attr_output_size.attr,
407 &overlay_attr_enabled.attr,
408 &overlay_attr_global_alpha.attr,
Rajkumar Nfd28a392010-11-04 12:28:42 +0100409 &overlay_attr_pre_mult_alpha.attr,
Archit Taneja54128702011-09-08 11:29:17 +0530410 &overlay_attr_zorder.attr,
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300411 NULL
412};
413
414static ssize_t overlay_attr_show(struct kobject *kobj, struct attribute *attr,
415 char *buf)
416{
417 struct omap_overlay *overlay;
418 struct overlay_attribute *overlay_attr;
419
420 overlay = container_of(kobj, struct omap_overlay, kobj);
421 overlay_attr = container_of(attr, struct overlay_attribute, attr);
422
423 if (!overlay_attr->show)
424 return -ENOENT;
425
426 return overlay_attr->show(overlay, buf);
427}
428
429static ssize_t overlay_attr_store(struct kobject *kobj, struct attribute *attr,
430 const char *buf, size_t size)
431{
432 struct omap_overlay *overlay;
433 struct overlay_attribute *overlay_attr;
434
435 overlay = container_of(kobj, struct omap_overlay, kobj);
436 overlay_attr = container_of(attr, struct overlay_attribute, attr);
437
438 if (!overlay_attr->store)
439 return -ENOENT;
440
441 return overlay_attr->store(overlay, buf, size);
442}
443
Emese Revfy52cf25d2010-01-19 02:58:23 +0100444static const struct sysfs_ops overlay_sysfs_ops = {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300445 .show = overlay_attr_show,
446 .store = overlay_attr_store,
447};
448
449static struct kobj_type overlay_ktype = {
450 .sysfs_ops = &overlay_sysfs_ops,
451 .default_attrs = overlay_sysfs_attrs,
452};
453
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300454int omap_dss_get_num_overlays(void)
455{
456 return num_overlays;
457}
458EXPORT_SYMBOL(omap_dss_get_num_overlays);
459
460struct omap_overlay *omap_dss_get_overlay(int num)
461{
Tomi Valkeinen58452342011-11-05 10:39:59 +0200462 if (num >= num_overlays)
463 return NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300464
Tomi Valkeinen58452342011-11-05 10:39:59 +0200465 return &overlays[num];
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300466}
467EXPORT_SYMBOL(omap_dss_get_overlay);
468
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300469void dss_init_overlays(struct platform_device *pdev)
470{
471 int i, r;
472
Tomi Valkeinen58452342011-11-05 10:39:59 +0200473 num_overlays = dss_feat_get_num_ovls();
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300474
Tomi Valkeinen58452342011-11-05 10:39:59 +0200475 overlays = kzalloc(sizeof(struct omap_overlay) * num_overlays,
476 GFP_KERNEL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300477
Tomi Valkeinen58452342011-11-05 10:39:59 +0200478 BUG_ON(overlays == NULL);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300479
Tomi Valkeinen58452342011-11-05 10:39:59 +0200480 for (i = 0; i < num_overlays; ++i) {
481 struct omap_overlay *ovl = &overlays[i];
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300482
483 switch (i) {
484 case 0:
485 ovl->name = "gfx";
486 ovl->id = OMAP_DSS_GFX;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300487 break;
488 case 1:
489 ovl->name = "vid1";
490 ovl->id = OMAP_DSS_VIDEO1;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300491 break;
492 case 2:
493 ovl->name = "vid2";
494 ovl->id = OMAP_DSS_VIDEO2;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300495 break;
Archit Tanejab8c095b2011-09-13 18:20:33 +0530496 case 3:
497 ovl->name = "vid3";
498 ovl->id = OMAP_DSS_VIDEO3;
Archit Tanejab8c095b2011-09-13 18:20:33 +0530499 break;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300500 }
501
Tomi Valkeinenaaa874a2011-11-15 16:37:53 +0200502 ovl->is_enabled = &dss_ovl_is_enabled;
503 ovl->enable = &dss_ovl_enable;
504 ovl->disable = &dss_ovl_disable;
Tomi Valkeinenf77b3072011-11-15 12:11:11 +0200505 ovl->set_manager = &dss_ovl_set_manager;
506 ovl->unset_manager = &dss_ovl_unset_manager;
507 ovl->set_overlay_info = &dss_ovl_set_info;
508 ovl->get_overlay_info = &dss_ovl_get_info;
Tomi Valkeinen550a8f62011-11-04 13:00:10 +0200509 ovl->wait_for_go = &dss_mgr_wait_for_go_ovl;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300510
Tomi Valkeinen67019db2011-08-15 15:18:15 +0300511 ovl->caps = dss_feat_get_overlay_caps(ovl->id);
Archit Tanejaa0acb552010-09-15 19:20:00 +0530512 ovl->supported_modes =
513 dss_feat_get_supported_color_modes(ovl->id);
514
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300515 r = kobject_init_and_add(&ovl->kobj, &overlay_ktype,
516 &pdev->dev.kobj, "overlay%d", i);
517
Tomi Valkeinen58452342011-11-05 10:39:59 +0200518 if (r)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300519 DSSERR("failed to create sysfs file\n");
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300520 }
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300521}
522
523/* connect overlays to the new device, if not already connected. if force
524 * selected, connect always. */
525void dss_recheck_connections(struct omap_dss_device *dssdev, bool force)
526{
527 int i;
528 struct omap_overlay_manager *lcd_mgr;
529 struct omap_overlay_manager *tv_mgr;
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000530 struct omap_overlay_manager *lcd2_mgr = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300531 struct omap_overlay_manager *mgr = NULL;
532
533 lcd_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD);
534 tv_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_TV);
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000535 if (dss_has_feature(FEAT_MGR_LCD2))
536 lcd2_mgr = omap_dss_get_overlay_manager(OMAP_DSS_OVL_MGR_LCD2);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300537
Sumit Semwal18faa1b2010-12-02 11:27:14 +0000538 if (dssdev->channel == OMAP_DSS_CHANNEL_LCD2) {
539 if (!lcd2_mgr->device || force) {
540 if (lcd2_mgr->device)
541 lcd2_mgr->unset_device(lcd2_mgr);
542 lcd2_mgr->set_device(lcd2_mgr, dssdev);
543 mgr = lcd2_mgr;
544 }
Mythri P Kb1196012011-03-08 17:15:54 +0530545 } else if (dssdev->type != OMAP_DISPLAY_TYPE_VENC
546 && dssdev->type != OMAP_DISPLAY_TYPE_HDMI) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300547 if (!lcd_mgr->device || force) {
548 if (lcd_mgr->device)
549 lcd_mgr->unset_device(lcd_mgr);
550 lcd_mgr->set_device(lcd_mgr, dssdev);
551 mgr = lcd_mgr;
552 }
553 }
554
Mythri P Kb1196012011-03-08 17:15:54 +0530555 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC
556 || dssdev->type == OMAP_DISPLAY_TYPE_HDMI) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300557 if (!tv_mgr->device || force) {
558 if (tv_mgr->device)
559 tv_mgr->unset_device(tv_mgr);
560 tv_mgr->set_device(tv_mgr, dssdev);
561 mgr = tv_mgr;
562 }
563 }
564
565 if (mgr) {
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300566 dispc_runtime_get();
567
Archit Tanejaa0acb552010-09-15 19:20:00 +0530568 for (i = 0; i < dss_feat_get_num_ovls(); i++) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300569 struct omap_overlay *ovl;
570 ovl = omap_dss_get_overlay(i);
571 if (!ovl->manager || force) {
572 if (ovl->manager)
Tomi Valkeinenf77b3072011-11-15 12:11:11 +0200573 ovl->unset_manager(ovl);
574 ovl->set_manager(ovl, mgr);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300575 }
576 }
Tomi Valkeinen4fbafaf2011-05-27 10:52:19 +0300577
578 dispc_runtime_put();
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300579 }
580}
581
582void dss_uninit_overlays(struct platform_device *pdev)
583{
Tomi Valkeinen58452342011-11-05 10:39:59 +0200584 int i;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300585
Tomi Valkeinen58452342011-11-05 10:39:59 +0200586 for (i = 0; i < num_overlays; ++i) {
587 struct omap_overlay *ovl = &overlays[i];
588
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300589 kobject_del(&ovl->kobj);
590 kobject_put(&ovl->kobj);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300591 }
592
Tomi Valkeinen58452342011-11-05 10:39:59 +0200593 kfree(overlays);
594 overlays = NULL;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300595 num_overlays = 0;
596}
597
Tomi Valkeinen54540d42011-12-13 13:18:52 +0200598int dss_ovl_simple_check(struct omap_overlay *ovl,
599 const struct omap_overlay_info *info)
600{
601 if (info->paddr == 0) {
602 DSSERR("check_overlay: paddr cannot be 0\n");
603 return -EINVAL;
604 }
605
606 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
607 if (info->out_width != 0 && info->width != info->out_width) {
608 DSSERR("check_overlay: overlay %d doesn't support "
609 "scaling\n", ovl->id);
610 return -EINVAL;
611 }
612
613 if (info->out_height != 0 && info->height != info->out_height) {
614 DSSERR("check_overlay: overlay %d doesn't support "
615 "scaling\n", ovl->id);
616 return -EINVAL;
617 }
618 }
619
620 if ((ovl->supported_modes & info->color_mode) == 0) {
621 DSSERR("check_overlay: overlay %d doesn't support mode %d\n",
622 ovl->id, info->color_mode);
623 return -EINVAL;
624 }
625
626 if (info->zorder >= omap_dss_get_num_overlays()) {
627 DSSERR("check_overlay: zorder %d too high\n", info->zorder);
628 return -EINVAL;
629 }
630
631 return 0;
632}
633
Tomi Valkeinen6ac48d12011-12-08 10:32:37 +0200634int dss_ovl_check(struct omap_overlay *ovl,
635 struct omap_overlay_info *info, struct omap_dss_device *dssdev)
636{
637 u16 outw, outh;
638 u16 dw, dh;
639
640 if (dssdev == NULL)
641 return 0;
642
643 dssdev->driver->get_resolution(dssdev, &dw, &dh);
644
645 if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0) {
646 outw = info->width;
647 outh = info->height;
648 } else {
649 if (info->out_width == 0)
650 outw = info->width;
651 else
652 outw = info->out_width;
653
654 if (info->out_height == 0)
655 outh = info->height;
656 else
657 outh = info->out_height;
658 }
659
660 if (dw < info->pos_x + outw) {
661 DSSERR("overlay %d horizontally not inside the display area "
662 "(%d + %d >= %d)\n",
663 ovl->id, info->pos_x, outw, dw);
664 return -EINVAL;
665 }
666
667 if (dh < info->pos_y + outh) {
668 DSSERR("overlay %d vertically not inside the display area "
669 "(%d + %d >= %d)\n",
670 ovl->id, info->pos_y, outh, dh);
671 return -EINVAL;
672 }
673
674 return 0;
675}