blob: 4b09fcb432b3de140c8bf6b0416010283e9ba478 [file] [log] [blame]
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001/*
2 * linux/drivers/video/omap2/dss/manager.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 "MANAGER"
24
25#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Tomi Valkeineneed07e02009-08-07 13:43:20 +030027#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/spinlock.h>
30#include <linux/jiffies.h>
31
32#include <plat/display.h>
33#include <plat/cpu.h>
34
35#include "dss.h"
36
37static int num_managers;
38static struct list_head manager_list;
39
40static ssize_t manager_name_show(struct omap_overlay_manager *mgr, char *buf)
41{
42 return snprintf(buf, PAGE_SIZE, "%s\n", mgr->name);
43}
44
45static ssize_t manager_display_show(struct omap_overlay_manager *mgr, char *buf)
46{
47 return snprintf(buf, PAGE_SIZE, "%s\n",
48 mgr->device ? mgr->device->name : "<none>");
49}
50
51static ssize_t manager_display_store(struct omap_overlay_manager *mgr,
52 const char *buf, size_t size)
53{
54 int r = 0;
55 size_t len = size;
56 struct omap_dss_device *dssdev = NULL;
57
58 int match(struct omap_dss_device *dssdev, void *data)
59 {
60 const char *str = data;
61 return sysfs_streq(dssdev->name, str);
62 }
63
64 if (buf[size-1] == '\n')
65 --len;
66
67 if (len > 0)
68 dssdev = omap_dss_find_device((void *)buf, match);
69
70 if (len > 0 && dssdev == NULL)
71 return -EINVAL;
72
73 if (dssdev)
74 DSSDBG("display %s found\n", dssdev->name);
75
76 if (mgr->device) {
77 r = mgr->unset_device(mgr);
78 if (r) {
79 DSSERR("failed to unset display\n");
80 goto put_device;
81 }
82 }
83
84 if (dssdev) {
85 r = mgr->set_device(mgr, dssdev);
86 if (r) {
87 DSSERR("failed to set manager\n");
88 goto put_device;
89 }
90
91 r = mgr->apply(mgr);
92 if (r) {
93 DSSERR("failed to apply dispc config\n");
94 goto put_device;
95 }
96 }
97
98put_device:
99 if (dssdev)
100 omap_dss_put_device(dssdev);
101
102 return r ? r : size;
103}
104
105static ssize_t manager_default_color_show(struct omap_overlay_manager *mgr,
106 char *buf)
107{
108 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.default_color);
109}
110
111static ssize_t manager_default_color_store(struct omap_overlay_manager *mgr,
112 const char *buf, size_t size)
113{
114 struct omap_overlay_manager_info info;
115 u32 color;
116 int r;
117
118 if (sscanf(buf, "%d", &color) != 1)
119 return -EINVAL;
120
121 mgr->get_manager_info(mgr, &info);
122
123 info.default_color = color;
124
125 r = mgr->set_manager_info(mgr, &info);
126 if (r)
127 return r;
128
129 r = mgr->apply(mgr);
130 if (r)
131 return r;
132
133 return size;
134}
135
136static const char *trans_key_type_str[] = {
137 "gfx-destination",
138 "video-source",
139};
140
141static ssize_t manager_trans_key_type_show(struct omap_overlay_manager *mgr,
142 char *buf)
143{
144 enum omap_dss_trans_key_type key_type;
145
146 key_type = mgr->info.trans_key_type;
147 BUG_ON(key_type >= ARRAY_SIZE(trans_key_type_str));
148
149 return snprintf(buf, PAGE_SIZE, "%s\n", trans_key_type_str[key_type]);
150}
151
152static ssize_t manager_trans_key_type_store(struct omap_overlay_manager *mgr,
153 const char *buf, size_t size)
154{
155 enum omap_dss_trans_key_type key_type;
156 struct omap_overlay_manager_info info;
157 int r;
158
159 for (key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
160 key_type < ARRAY_SIZE(trans_key_type_str); key_type++) {
161 if (sysfs_streq(buf, trans_key_type_str[key_type]))
162 break;
163 }
164
165 if (key_type == ARRAY_SIZE(trans_key_type_str))
166 return -EINVAL;
167
168 mgr->get_manager_info(mgr, &info);
169
170 info.trans_key_type = key_type;
171
172 r = mgr->set_manager_info(mgr, &info);
173 if (r)
174 return r;
175
176 r = mgr->apply(mgr);
177 if (r)
178 return r;
179
180 return size;
181}
182
183static ssize_t manager_trans_key_value_show(struct omap_overlay_manager *mgr,
184 char *buf)
185{
186 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_key);
187}
188
189static ssize_t manager_trans_key_value_store(struct omap_overlay_manager *mgr,
190 const char *buf, size_t size)
191{
192 struct omap_overlay_manager_info info;
193 u32 key_value;
194 int r;
195
196 if (sscanf(buf, "%d", &key_value) != 1)
197 return -EINVAL;
198
199 mgr->get_manager_info(mgr, &info);
200
201 info.trans_key = key_value;
202
203 r = mgr->set_manager_info(mgr, &info);
204 if (r)
205 return r;
206
207 r = mgr->apply(mgr);
208 if (r)
209 return r;
210
211 return size;
212}
213
214static ssize_t manager_trans_key_enabled_show(struct omap_overlay_manager *mgr,
215 char *buf)
216{
217 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.trans_enabled);
218}
219
220static ssize_t manager_trans_key_enabled_store(struct omap_overlay_manager *mgr,
221 const char *buf, size_t size)
222{
223 struct omap_overlay_manager_info info;
224 int enable;
225 int r;
226
227 if (sscanf(buf, "%d", &enable) != 1)
228 return -EINVAL;
229
230 mgr->get_manager_info(mgr, &info);
231
232 info.trans_enabled = enable ? true : false;
233
234 r = mgr->set_manager_info(mgr, &info);
235 if (r)
236 return r;
237
238 r = mgr->apply(mgr);
239 if (r)
240 return r;
241
242 return size;
243}
244
245static ssize_t manager_alpha_blending_enabled_show(
246 struct omap_overlay_manager *mgr, char *buf)
247{
248 return snprintf(buf, PAGE_SIZE, "%d\n", mgr->info.alpha_enabled);
249}
250
251static ssize_t manager_alpha_blending_enabled_store(
252 struct omap_overlay_manager *mgr,
253 const char *buf, size_t size)
254{
255 struct omap_overlay_manager_info info;
256 int enable;
257 int r;
258
259 if (sscanf(buf, "%d", &enable) != 1)
260 return -EINVAL;
261
262 mgr->get_manager_info(mgr, &info);
263
264 info.alpha_enabled = enable ? true : false;
265
266 r = mgr->set_manager_info(mgr, &info);
267 if (r)
268 return r;
269
270 r = mgr->apply(mgr);
271 if (r)
272 return r;
273
274 return size;
275}
276
277struct manager_attribute {
278 struct attribute attr;
279 ssize_t (*show)(struct omap_overlay_manager *, char *);
280 ssize_t (*store)(struct omap_overlay_manager *, const char *, size_t);
281};
282
283#define MANAGER_ATTR(_name, _mode, _show, _store) \
284 struct manager_attribute manager_attr_##_name = \
285 __ATTR(_name, _mode, _show, _store)
286
287static MANAGER_ATTR(name, S_IRUGO, manager_name_show, NULL);
288static MANAGER_ATTR(display, S_IRUGO|S_IWUSR,
289 manager_display_show, manager_display_store);
290static MANAGER_ATTR(default_color, S_IRUGO|S_IWUSR,
291 manager_default_color_show, manager_default_color_store);
292static MANAGER_ATTR(trans_key_type, S_IRUGO|S_IWUSR,
293 manager_trans_key_type_show, manager_trans_key_type_store);
294static MANAGER_ATTR(trans_key_value, S_IRUGO|S_IWUSR,
295 manager_trans_key_value_show, manager_trans_key_value_store);
296static MANAGER_ATTR(trans_key_enabled, S_IRUGO|S_IWUSR,
297 manager_trans_key_enabled_show,
298 manager_trans_key_enabled_store);
299static MANAGER_ATTR(alpha_blending_enabled, S_IRUGO|S_IWUSR,
300 manager_alpha_blending_enabled_show,
301 manager_alpha_blending_enabled_store);
302
303
304static struct attribute *manager_sysfs_attrs[] = {
305 &manager_attr_name.attr,
306 &manager_attr_display.attr,
307 &manager_attr_default_color.attr,
308 &manager_attr_trans_key_type.attr,
309 &manager_attr_trans_key_value.attr,
310 &manager_attr_trans_key_enabled.attr,
311 &manager_attr_alpha_blending_enabled.attr,
312 NULL
313};
314
315static ssize_t manager_attr_show(struct kobject *kobj, struct attribute *attr,
316 char *buf)
317{
318 struct omap_overlay_manager *manager;
319 struct manager_attribute *manager_attr;
320
321 manager = container_of(kobj, struct omap_overlay_manager, kobj);
322 manager_attr = container_of(attr, struct manager_attribute, attr);
323
324 if (!manager_attr->show)
325 return -ENOENT;
326
327 return manager_attr->show(manager, buf);
328}
329
330static ssize_t manager_attr_store(struct kobject *kobj, struct attribute *attr,
331 const char *buf, size_t size)
332{
333 struct omap_overlay_manager *manager;
334 struct manager_attribute *manager_attr;
335
336 manager = container_of(kobj, struct omap_overlay_manager, kobj);
337 manager_attr = container_of(attr, struct manager_attribute, attr);
338
339 if (!manager_attr->store)
340 return -ENOENT;
341
342 return manager_attr->store(manager, buf, size);
343}
344
Emese Revfy52cf25d2010-01-19 02:58:23 +0100345static const struct sysfs_ops manager_sysfs_ops = {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300346 .show = manager_attr_show,
347 .store = manager_attr_store,
348};
349
350static struct kobj_type manager_ktype = {
351 .sysfs_ops = &manager_sysfs_ops,
352 .default_attrs = manager_sysfs_attrs,
353};
354
355/*
356 * We have 4 levels of cache for the dispc settings. First two are in SW and
357 * the latter two in HW.
358 *
359 * +--------------------+
360 * |overlay/manager_info|
361 * +--------------------+
362 * v
363 * apply()
364 * v
365 * +--------------------+
366 * | dss_cache |
367 * +--------------------+
368 * v
369 * configure()
370 * v
371 * +--------------------+
372 * | shadow registers |
373 * +--------------------+
374 * v
375 * VFP or lcd/digit_enable
376 * v
377 * +--------------------+
378 * | registers |
379 * +--------------------+
380 */
381
382struct overlay_cache_data {
383 /* If true, cache changed, but not written to shadow registers. Set
384 * in apply(), cleared when registers written. */
385 bool dirty;
386 /* If true, shadow registers contain changed values not yet in real
387 * registers. Set when writing to shadow registers, cleared at
388 * VSYNC/EVSYNC */
389 bool shadow_dirty;
390
391 bool enabled;
392
393 u32 paddr;
394 void __iomem *vaddr;
395 u16 screen_width;
396 u16 width;
397 u16 height;
398 enum omap_color_mode color_mode;
399 u8 rotation;
400 enum omap_dss_rotation_type rotation_type;
401 bool mirror;
402
403 u16 pos_x;
404 u16 pos_y;
405 u16 out_width; /* if 0, out_width == width */
406 u16 out_height; /* if 0, out_height == height */
407 u8 global_alpha;
408
409 enum omap_channel channel;
410 bool replication;
411 bool ilace;
412
413 enum omap_burst_size burst_size;
414 u32 fifo_low;
415 u32 fifo_high;
416
417 bool manual_update;
418};
419
420struct manager_cache_data {
421 /* If true, cache changed, but not written to shadow registers. Set
422 * in apply(), cleared when registers written. */
423 bool dirty;
424 /* If true, shadow registers contain changed values not yet in real
425 * registers. Set when writing to shadow registers, cleared at
426 * VSYNC/EVSYNC */
427 bool shadow_dirty;
428
429 u32 default_color;
430
431 enum omap_dss_trans_key_type trans_key_type;
432 u32 trans_key;
433 bool trans_enabled;
434
435 bool alpha_enabled;
436
437 bool manual_upd_display;
438 bool manual_update;
439 bool do_manual_update;
440
441 /* manual update region */
442 u16 x, y, w, h;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300443
444 /* enlarge the update area if the update area contains scaled
445 * overlays */
446 bool enlarge_update_area;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300447};
448
449static struct {
450 spinlock_t lock;
451 struct overlay_cache_data overlay_cache[3];
452 struct manager_cache_data manager_cache[2];
453
454 bool irq_enabled;
455} dss_cache;
456
457
458
459static int omap_dss_set_device(struct omap_overlay_manager *mgr,
460 struct omap_dss_device *dssdev)
461{
462 int i;
463 int r;
464
465 if (dssdev->manager) {
466 DSSERR("display '%s' already has a manager '%s'\n",
467 dssdev->name, dssdev->manager->name);
468 return -EINVAL;
469 }
470
471 if ((mgr->supported_displays & dssdev->type) == 0) {
472 DSSERR("display '%s' does not support manager '%s'\n",
473 dssdev->name, mgr->name);
474 return -EINVAL;
475 }
476
477 for (i = 0; i < mgr->num_overlays; i++) {
478 struct omap_overlay *ovl = mgr->overlays[i];
479
480 if (ovl->manager != mgr || !ovl->info.enabled)
481 continue;
482
483 r = dss_check_overlay(ovl, dssdev);
484 if (r)
485 return r;
486 }
487
488 dssdev->manager = mgr;
489 mgr->device = dssdev;
490 mgr->device_changed = true;
491
492 return 0;
493}
494
495static int omap_dss_unset_device(struct omap_overlay_manager *mgr)
496{
497 if (!mgr->device) {
498 DSSERR("failed to unset display, display not set.\n");
499 return -EINVAL;
500 }
501
502 mgr->device->manager = NULL;
503 mgr->device = NULL;
504 mgr->device_changed = true;
505
506 return 0;
507}
508
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +0200509static int dss_mgr_wait_for_vsync(struct omap_overlay_manager *mgr)
510{
511 unsigned long timeout = msecs_to_jiffies(500);
512 u32 irq;
513
514 if (mgr->device->type == OMAP_DISPLAY_TYPE_VENC)
515 irq = DISPC_IRQ_EVSYNC_ODD;
516 else
517 irq = DISPC_IRQ_VSYNC;
518
519 return omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
520}
521
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300522static int dss_mgr_wait_for_go(struct omap_overlay_manager *mgr)
523{
524 unsigned long timeout = msecs_to_jiffies(500);
525 struct manager_cache_data *mc;
526 enum omap_channel channel;
527 u32 irq;
528 int r;
529 int i;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200530 struct omap_dss_device *dssdev = mgr->device;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300531
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200532 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300533 return 0;
534
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200535 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300536 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
537 channel = OMAP_DSS_CHANNEL_DIGIT;
538 } else {
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200539 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300540 enum omap_dss_update_mode mode;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200541 mode = dssdev->driver->get_update_mode(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300542 if (mode != OMAP_DSS_UPDATE_AUTO)
543 return 0;
544
545 irq = DISPC_IRQ_FRAMEDONE;
546 } else {
547 irq = DISPC_IRQ_VSYNC;
548 }
549 channel = OMAP_DSS_CHANNEL_LCD;
550 }
551
552 mc = &dss_cache.manager_cache[mgr->id];
553 i = 0;
554 while (1) {
555 unsigned long flags;
556 bool shadow_dirty, dirty;
557
558 spin_lock_irqsave(&dss_cache.lock, flags);
559 dirty = mc->dirty;
560 shadow_dirty = mc->shadow_dirty;
561 spin_unlock_irqrestore(&dss_cache.lock, flags);
562
563 if (!dirty && !shadow_dirty) {
564 r = 0;
565 break;
566 }
567
568 /* 4 iterations is the worst case:
569 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
570 * 2 - first VSYNC, dirty = true
571 * 3 - dirty = false, shadow_dirty = true
572 * 4 - shadow_dirty = false */
573 if (i++ == 3) {
574 DSSERR("mgr(%d)->wait_for_go() not finishing\n",
575 mgr->id);
576 r = 0;
577 break;
578 }
579
580 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
581 if (r == -ERESTARTSYS)
582 break;
583
584 if (r) {
585 DSSERR("mgr(%d)->wait_for_go() timeout\n", mgr->id);
586 break;
587 }
588 }
589
590 return r;
591}
592
593int dss_mgr_wait_for_go_ovl(struct omap_overlay *ovl)
594{
595 unsigned long timeout = msecs_to_jiffies(500);
596 enum omap_channel channel;
597 struct overlay_cache_data *oc;
598 struct omap_dss_device *dssdev;
599 u32 irq;
600 int r;
601 int i;
602
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200603 if (!ovl->manager)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300604 return 0;
605
606 dssdev = ovl->manager->device;
607
Ville Syrjäläa74b2602010-03-04 16:03:56 +0200608 if (!dssdev || dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
609 return 0;
610
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300611 if (dssdev->type == OMAP_DISPLAY_TYPE_VENC) {
612 irq = DISPC_IRQ_EVSYNC_ODD | DISPC_IRQ_EVSYNC_EVEN;
613 channel = OMAP_DSS_CHANNEL_DIGIT;
614 } else {
615 if (dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
616 enum omap_dss_update_mode mode;
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +0200617 mode = dssdev->driver->get_update_mode(dssdev);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300618 if (mode != OMAP_DSS_UPDATE_AUTO)
619 return 0;
620
621 irq = DISPC_IRQ_FRAMEDONE;
622 } else {
623 irq = DISPC_IRQ_VSYNC;
624 }
625 channel = OMAP_DSS_CHANNEL_LCD;
626 }
627
628 oc = &dss_cache.overlay_cache[ovl->id];
629 i = 0;
630 while (1) {
631 unsigned long flags;
632 bool shadow_dirty, dirty;
633
634 spin_lock_irqsave(&dss_cache.lock, flags);
635 dirty = oc->dirty;
636 shadow_dirty = oc->shadow_dirty;
637 spin_unlock_irqrestore(&dss_cache.lock, flags);
638
639 if (!dirty && !shadow_dirty) {
640 r = 0;
641 break;
642 }
643
644 /* 4 iterations is the worst case:
645 * 1 - initial iteration, dirty = true (between VFP and VSYNC)
646 * 2 - first VSYNC, dirty = true
647 * 3 - dirty = false, shadow_dirty = true
648 * 4 - shadow_dirty = false */
649 if (i++ == 3) {
650 DSSERR("ovl(%d)->wait_for_go() not finishing\n",
651 ovl->id);
652 r = 0;
653 break;
654 }
655
656 r = omap_dispc_wait_for_irq_interruptible_timeout(irq, timeout);
657 if (r == -ERESTARTSYS)
658 break;
659
660 if (r) {
661 DSSERR("ovl(%d)->wait_for_go() timeout\n", ovl->id);
662 break;
663 }
664 }
665
666 return r;
667}
668
669static int overlay_enabled(struct omap_overlay *ovl)
670{
671 return ovl->info.enabled && ovl->manager && ovl->manager->device;
672}
673
674/* Is rect1 a subset of rect2? */
675static bool rectangle_subset(int x1, int y1, int w1, int h1,
676 int x2, int y2, int w2, int h2)
677{
678 if (x1 < x2 || y1 < y2)
679 return false;
680
681 if (x1 + w1 > x2 + w2)
682 return false;
683
684 if (y1 + h1 > y2 + h2)
685 return false;
686
687 return true;
688}
689
690/* Do rect1 and rect2 overlap? */
691static bool rectangle_intersects(int x1, int y1, int w1, int h1,
692 int x2, int y2, int w2, int h2)
693{
694 if (x1 >= x2 + w2)
695 return false;
696
697 if (x2 >= x1 + w1)
698 return false;
699
700 if (y1 >= y2 + h2)
701 return false;
702
703 if (y2 >= y1 + h1)
704 return false;
705
706 return true;
707}
708
709static bool dispc_is_overlay_scaled(struct overlay_cache_data *oc)
710{
711 if (oc->out_width != 0 && oc->width != oc->out_width)
712 return true;
713
714 if (oc->out_height != 0 && oc->height != oc->out_height)
715 return true;
716
717 return false;
718}
719
720static int configure_overlay(enum omap_plane plane)
721{
722 struct overlay_cache_data *c;
723 struct manager_cache_data *mc;
724 u16 outw, outh;
725 u16 x, y, w, h;
726 u32 paddr;
727 int r;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300728 u16 orig_w, orig_h, orig_outw, orig_outh;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300729
730 DSSDBGF("%d", plane);
731
732 c = &dss_cache.overlay_cache[plane];
733
734 if (!c->enabled) {
735 dispc_enable_plane(plane, 0);
736 return 0;
737 }
738
739 mc = &dss_cache.manager_cache[c->channel];
740
741 x = c->pos_x;
742 y = c->pos_y;
743 w = c->width;
744 h = c->height;
745 outw = c->out_width == 0 ? c->width : c->out_width;
746 outh = c->out_height == 0 ? c->height : c->out_height;
747 paddr = c->paddr;
748
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300749 orig_w = w;
750 orig_h = h;
751 orig_outw = outw;
752 orig_outh = outh;
753
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300754 if (c->manual_update && mc->do_manual_update) {
755 unsigned bpp;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300756 unsigned scale_x_m = w, scale_x_d = outw;
757 unsigned scale_y_m = h, scale_y_d = outh;
758
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300759 /* If the overlay is outside the update region, disable it */
760 if (!rectangle_intersects(mc->x, mc->y, mc->w, mc->h,
761 x, y, outw, outh)) {
762 dispc_enable_plane(plane, 0);
763 return 0;
764 }
765
766 switch (c->color_mode) {
767 case OMAP_DSS_COLOR_RGB16:
768 case OMAP_DSS_COLOR_ARGB16:
769 case OMAP_DSS_COLOR_YUV2:
770 case OMAP_DSS_COLOR_UYVY:
771 bpp = 16;
772 break;
773
774 case OMAP_DSS_COLOR_RGB24P:
775 bpp = 24;
776 break;
777
778 case OMAP_DSS_COLOR_RGB24U:
779 case OMAP_DSS_COLOR_ARGB32:
780 case OMAP_DSS_COLOR_RGBA32:
781 case OMAP_DSS_COLOR_RGBX32:
782 bpp = 32;
783 break;
784
785 default:
786 BUG();
787 }
788
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300789 if (mc->x > c->pos_x) {
790 x = 0;
791 outw -= (mc->x - c->pos_x);
792 paddr += (mc->x - c->pos_x) *
793 scale_x_m / scale_x_d * bpp / 8;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300794 } else {
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300795 x = c->pos_x - mc->x;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300796 }
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300797
798 if (mc->y > c->pos_y) {
799 y = 0;
800 outh -= (mc->y - c->pos_y);
801 paddr += (mc->y - c->pos_y) *
802 scale_y_m / scale_y_d *
803 c->screen_width * bpp / 8;
804 } else {
805 y = c->pos_y - mc->y;
806 }
807
808 if (mc->w < (x + outw))
809 outw -= (x + outw) - (mc->w);
810
811 if (mc->h < (y + outh))
812 outh -= (y + outh) - (mc->h);
813
814 w = w * outw / orig_outw;
815 h = h * outh / orig_outh;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300816 }
817
818 r = dispc_setup_plane(plane,
819 paddr,
820 c->screen_width,
821 x, y,
822 w, h,
823 outw, outh,
824 c->color_mode,
825 c->ilace,
826 c->rotation_type,
827 c->rotation,
828 c->mirror,
829 c->global_alpha);
830
831 if (r) {
832 /* this shouldn't happen */
833 DSSERR("dispc_setup_plane failed for ovl %d\n", plane);
834 dispc_enable_plane(plane, 0);
835 return r;
836 }
837
838 dispc_enable_replication(plane, c->replication);
839
840 dispc_set_burst_size(plane, c->burst_size);
841 dispc_setup_plane_fifo(plane, c->fifo_low, c->fifo_high);
842
843 dispc_enable_plane(plane, 1);
844
845 return 0;
846}
847
848static void configure_manager(enum omap_channel channel)
849{
850 struct manager_cache_data *c;
851
852 DSSDBGF("%d", channel);
853
854 c = &dss_cache.manager_cache[channel];
855
Carlos Lopeza3bb67a2010-04-25 12:53:35 +0200856 dispc_set_default_color(channel, c->default_color);
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300857 dispc_set_trans_key(channel, c->trans_key_type, c->trans_key);
858 dispc_enable_trans_key(channel, c->trans_enabled);
859 dispc_enable_alpha_blending(channel, c->alpha_enabled);
860}
861
862/* configure_dispc() tries to write values from cache to shadow registers.
863 * It writes only to those managers/overlays that are not busy.
864 * returns 0 if everything could be written to shadow registers.
865 * returns 1 if not everything could be written to shadow registers. */
866static int configure_dispc(void)
867{
868 struct overlay_cache_data *oc;
869 struct manager_cache_data *mc;
870 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
871 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
872 int i;
873 int r;
874 bool mgr_busy[2];
875 bool mgr_go[2];
876 bool busy;
877
878 r = 0;
879 busy = false;
880
881 mgr_busy[0] = dispc_go_busy(0);
882 mgr_busy[1] = dispc_go_busy(1);
883 mgr_go[0] = false;
884 mgr_go[1] = false;
885
886 /* Commit overlay settings */
887 for (i = 0; i < num_ovls; ++i) {
888 oc = &dss_cache.overlay_cache[i];
889 mc = &dss_cache.manager_cache[oc->channel];
890
891 if (!oc->dirty)
892 continue;
893
894 if (oc->manual_update && !mc->do_manual_update)
895 continue;
896
897 if (mgr_busy[oc->channel]) {
898 busy = true;
899 continue;
900 }
901
902 r = configure_overlay(i);
903 if (r)
904 DSSERR("configure_overlay %d failed\n", i);
905
906 oc->dirty = false;
907 oc->shadow_dirty = true;
908 mgr_go[oc->channel] = true;
909 }
910
911 /* Commit manager settings */
912 for (i = 0; i < num_mgrs; ++i) {
913 mc = &dss_cache.manager_cache[i];
914
915 if (!mc->dirty)
916 continue;
917
918 if (mc->manual_update && !mc->do_manual_update)
919 continue;
920
921 if (mgr_busy[i]) {
922 busy = true;
923 continue;
924 }
925
926 configure_manager(i);
927 mc->dirty = false;
928 mc->shadow_dirty = true;
929 mgr_go[i] = true;
930 }
931
932 /* set GO */
933 for (i = 0; i < num_mgrs; ++i) {
934 mc = &dss_cache.manager_cache[i];
935
936 if (!mgr_go[i])
937 continue;
938
939 /* We don't need GO with manual update display. LCD iface will
940 * always be turned off after frame, and new settings will be
941 * taken in to use at next update */
942 if (!mc->manual_upd_display)
943 dispc_go(i);
944 }
945
946 if (busy)
947 r = 1;
948 else
949 r = 0;
950
951 return r;
952}
953
Tomi Valkeinenf49a9512010-03-26 16:26:37 +0200954/* Make the coordinates even. There are some strange problems with OMAP and
955 * partial DSI update when the update widths are odd. */
956static void make_even(u16 *x, u16 *w)
957{
958 u16 x1, x2;
959
960 x1 = *x;
961 x2 = *x + *w;
962
963 x1 &= ~1;
964 x2 = ALIGN(x2, 2);
965
966 *x = x1;
967 *w = x2 - x1;
968}
969
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300970/* Configure dispc for partial update. Return possibly modified update
971 * area */
972void dss_setup_partial_planes(struct omap_dss_device *dssdev,
Tomi Valkeinen26a8c252010-06-09 15:31:34 +0300973 u16 *xi, u16 *yi, u16 *wi, u16 *hi, bool enlarge_update_area)
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300974{
975 struct overlay_cache_data *oc;
976 struct manager_cache_data *mc;
977 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
978 struct omap_overlay_manager *mgr;
979 int i;
980 u16 x, y, w, h;
981 unsigned long flags;
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +0300982 bool area_changed;
Tomi Valkeineneed07e02009-08-07 13:43:20 +0300983
984 x = *xi;
985 y = *yi;
986 w = *wi;
987 h = *hi;
988
989 DSSDBG("dispc_setup_partial_planes %d,%d %dx%d\n",
990 *xi, *yi, *wi, *hi);
991
992 mgr = dssdev->manager;
993
994 if (!mgr) {
995 DSSDBG("no manager\n");
996 return;
997 }
998
Tomi Valkeinenf49a9512010-03-26 16:26:37 +0200999 make_even(&x, &w);
1000
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001001 spin_lock_irqsave(&dss_cache.lock, flags);
1002
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001003 /*
1004 * Execute the outer loop until the inner loop has completed
1005 * once without increasing the update area. This will ensure that
1006 * all scaled overlays end up completely within the update area.
1007 */
1008 do {
1009 area_changed = false;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001010
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001011 /* We need to show the whole overlay if it is scaled. So look
1012 * for those, and make the update area larger if found.
1013 * Also mark the overlay cache dirty */
1014 for (i = 0; i < num_ovls; ++i) {
1015 unsigned x1, y1, x2, y2;
1016 unsigned outw, outh;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001017
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001018 oc = &dss_cache.overlay_cache[i];
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001019
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001020 if (oc->channel != mgr->id)
1021 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001022
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001023 oc->dirty = true;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001024
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001025 if (!enlarge_update_area)
1026 continue;
1027
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001028 if (!oc->enabled)
1029 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001030
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001031 if (!dispc_is_overlay_scaled(oc))
1032 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001033
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001034 outw = oc->out_width == 0 ?
1035 oc->width : oc->out_width;
1036 outh = oc->out_height == 0 ?
1037 oc->height : oc->out_height;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001038
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001039 /* is the overlay outside the update region? */
1040 if (!rectangle_intersects(x, y, w, h,
1041 oc->pos_x, oc->pos_y,
1042 outw, outh))
1043 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001044
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001045 /* if the overlay totally inside the update region? */
1046 if (rectangle_subset(oc->pos_x, oc->pos_y, outw, outh,
1047 x, y, w, h))
1048 continue;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001049
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001050 if (x > oc->pos_x)
1051 x1 = oc->pos_x;
1052 else
1053 x1 = x;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001054
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001055 if (y > oc->pos_y)
1056 y1 = oc->pos_y;
1057 else
1058 y1 = y;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001059
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001060 if ((x + w) < (oc->pos_x + outw))
1061 x2 = oc->pos_x + outw;
1062 else
1063 x2 = x + w;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001064
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001065 if ((y + h) < (oc->pos_y + outh))
1066 y2 = oc->pos_y + outh;
1067 else
1068 y2 = y + h;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001069
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001070 x = x1;
1071 y = y1;
1072 w = x2 - x1;
1073 h = y2 - y1;
Tomi Valkeinenf49a9512010-03-26 16:26:37 +02001074
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001075 make_even(&x, &w);
1076
1077 DSSDBG("changing upd area due to ovl(%d) "
1078 "scaling %d,%d %dx%d\n",
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001079 i, x, y, w, h);
Tomi Valkeinen8cab90f2010-06-09 15:09:30 +03001080
1081 area_changed = true;
1082 }
1083 } while (area_changed);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001084
1085 mc = &dss_cache.manager_cache[mgr->id];
1086 mc->do_manual_update = true;
Tomi Valkeinen26a8c252010-06-09 15:31:34 +03001087 mc->enlarge_update_area = enlarge_update_area;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001088 mc->x = x;
1089 mc->y = y;
1090 mc->w = w;
1091 mc->h = h;
1092
1093 configure_dispc();
1094
1095 mc->do_manual_update = false;
1096
1097 spin_unlock_irqrestore(&dss_cache.lock, flags);
1098
1099 *xi = x;
1100 *yi = y;
1101 *wi = w;
1102 *hi = h;
1103}
1104
1105void dss_start_update(struct omap_dss_device *dssdev)
1106{
1107 struct manager_cache_data *mc;
1108 struct overlay_cache_data *oc;
1109 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1110 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1111 struct omap_overlay_manager *mgr;
1112 int i;
1113
1114 mgr = dssdev->manager;
1115
1116 for (i = 0; i < num_ovls; ++i) {
1117 oc = &dss_cache.overlay_cache[i];
1118 if (oc->channel != mgr->id)
1119 continue;
1120
1121 oc->shadow_dirty = false;
1122 }
1123
1124 for (i = 0; i < num_mgrs; ++i) {
1125 mc = &dss_cache.manager_cache[i];
1126 if (mgr->id != i)
1127 continue;
1128
1129 mc->shadow_dirty = false;
1130 }
1131
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001132 dssdev->manager->enable(dssdev->manager);
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001133}
1134
1135static void dss_apply_irq_handler(void *data, u32 mask)
1136{
1137 struct manager_cache_data *mc;
1138 struct overlay_cache_data *oc;
1139 const int num_ovls = ARRAY_SIZE(dss_cache.overlay_cache);
1140 const int num_mgrs = ARRAY_SIZE(dss_cache.manager_cache);
1141 int i, r;
1142 bool mgr_busy[2];
1143
1144 mgr_busy[0] = dispc_go_busy(0);
1145 mgr_busy[1] = dispc_go_busy(1);
1146
1147 spin_lock(&dss_cache.lock);
1148
1149 for (i = 0; i < num_ovls; ++i) {
1150 oc = &dss_cache.overlay_cache[i];
1151 if (!mgr_busy[oc->channel])
1152 oc->shadow_dirty = false;
1153 }
1154
1155 for (i = 0; i < num_mgrs; ++i) {
1156 mc = &dss_cache.manager_cache[i];
1157 if (!mgr_busy[i])
1158 mc->shadow_dirty = false;
1159 }
1160
1161 r = configure_dispc();
1162 if (r == 1)
1163 goto end;
1164
1165 /* re-read busy flags */
1166 mgr_busy[0] = dispc_go_busy(0);
1167 mgr_busy[1] = dispc_go_busy(1);
1168
1169 /* keep running as long as there are busy managers, so that
1170 * we can collect overlay-applied information */
1171 for (i = 0; i < num_mgrs; ++i) {
1172 if (mgr_busy[i])
1173 goto end;
1174 }
1175
1176 omap_dispc_unregister_isr(dss_apply_irq_handler, NULL,
1177 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1178 DISPC_IRQ_EVSYNC_EVEN);
1179 dss_cache.irq_enabled = false;
1180
1181end:
1182 spin_unlock(&dss_cache.lock);
1183}
1184
1185static int omap_dss_mgr_apply(struct omap_overlay_manager *mgr)
1186{
1187 struct overlay_cache_data *oc;
1188 struct manager_cache_data *mc;
1189 int i;
1190 struct omap_overlay *ovl;
1191 int num_planes_enabled = 0;
1192 bool use_fifomerge;
1193 unsigned long flags;
1194 int r;
1195
1196 DSSDBG("omap_dss_mgr_apply(%s)\n", mgr->name);
1197
1198 spin_lock_irqsave(&dss_cache.lock, flags);
1199
1200 /* Configure overlays */
1201 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1202 struct omap_dss_device *dssdev;
1203
1204 ovl = omap_dss_get_overlay(i);
1205
1206 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1207 continue;
1208
1209 oc = &dss_cache.overlay_cache[ovl->id];
1210
1211 if (!overlay_enabled(ovl)) {
1212 if (oc->enabled) {
1213 oc->enabled = false;
1214 oc->dirty = true;
1215 }
1216 continue;
1217 }
1218
1219 if (!ovl->info_dirty) {
1220 if (oc->enabled)
1221 ++num_planes_enabled;
1222 continue;
1223 }
1224
1225 dssdev = ovl->manager->device;
1226
1227 if (dss_check_overlay(ovl, dssdev)) {
1228 if (oc->enabled) {
1229 oc->enabled = false;
1230 oc->dirty = true;
1231 }
1232 continue;
1233 }
1234
1235 ovl->info_dirty = false;
1236 oc->dirty = true;
1237
1238 oc->paddr = ovl->info.paddr;
1239 oc->vaddr = ovl->info.vaddr;
1240 oc->screen_width = ovl->info.screen_width;
1241 oc->width = ovl->info.width;
1242 oc->height = ovl->info.height;
1243 oc->color_mode = ovl->info.color_mode;
1244 oc->rotation = ovl->info.rotation;
1245 oc->rotation_type = ovl->info.rotation_type;
1246 oc->mirror = ovl->info.mirror;
1247 oc->pos_x = ovl->info.pos_x;
1248 oc->pos_y = ovl->info.pos_y;
1249 oc->out_width = ovl->info.out_width;
1250 oc->out_height = ovl->info.out_height;
1251 oc->global_alpha = ovl->info.global_alpha;
1252
1253 oc->replication =
1254 dss_use_replication(dssdev, ovl->info.color_mode);
1255
1256 oc->ilace = dssdev->type == OMAP_DISPLAY_TYPE_VENC;
1257
1258 oc->channel = ovl->manager->id;
1259
1260 oc->enabled = true;
1261
1262 oc->manual_update =
1263 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001264 dssdev->driver->get_update_mode(dssdev) !=
1265 OMAP_DSS_UPDATE_AUTO;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001266
1267 ++num_planes_enabled;
1268 }
1269
1270 /* Configure managers */
1271 list_for_each_entry(mgr, &manager_list, list) {
1272 struct omap_dss_device *dssdev;
1273
1274 if (!(mgr->caps & OMAP_DSS_OVL_MGR_CAP_DISPC))
1275 continue;
1276
1277 mc = &dss_cache.manager_cache[mgr->id];
1278
1279 if (mgr->device_changed) {
1280 mgr->device_changed = false;
1281 mgr->info_dirty = true;
1282 }
1283
1284 if (!mgr->info_dirty)
1285 continue;
1286
1287 if (!mgr->device)
1288 continue;
1289
1290 dssdev = mgr->device;
1291
1292 mgr->info_dirty = false;
1293 mc->dirty = true;
1294
1295 mc->default_color = mgr->info.default_color;
1296 mc->trans_key_type = mgr->info.trans_key_type;
1297 mc->trans_key = mgr->info.trans_key;
1298 mc->trans_enabled = mgr->info.trans_enabled;
1299 mc->alpha_enabled = mgr->info.alpha_enabled;
1300
1301 mc->manual_upd_display =
1302 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE;
1303
1304 mc->manual_update =
1305 dssdev->caps & OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE &&
Tomi Valkeinen446f7bf2010-01-11 16:12:31 +02001306 dssdev->driver->get_update_mode(dssdev) !=
1307 OMAP_DSS_UPDATE_AUTO;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001308 }
1309
1310 /* XXX TODO: Try to get fifomerge working. The problem is that it
1311 * affects both managers, not individually but at the same time. This
1312 * means the change has to be well synchronized. I guess the proper way
1313 * is to have a two step process for fifo merge:
1314 * fifomerge enable:
1315 * 1. disable other planes, leaving one plane enabled
1316 * 2. wait until the planes are disabled on HW
1317 * 3. config merged fifo thresholds, enable fifomerge
1318 * fifomerge disable:
1319 * 1. config unmerged fifo thresholds, disable fifomerge
1320 * 2. wait until fifo changes are in HW
1321 * 3. enable planes
1322 */
1323 use_fifomerge = false;
1324
1325 /* Configure overlay fifos */
1326 for (i = 0; i < omap_dss_get_num_overlays(); ++i) {
1327 struct omap_dss_device *dssdev;
1328 u32 size;
1329
1330 ovl = omap_dss_get_overlay(i);
1331
1332 if (!(ovl->caps & OMAP_DSS_OVL_CAP_DISPC))
1333 continue;
1334
1335 oc = &dss_cache.overlay_cache[ovl->id];
1336
1337 if (!oc->enabled)
1338 continue;
1339
1340 dssdev = ovl->manager->device;
1341
1342 size = dispc_get_plane_fifo_size(ovl->id);
1343 if (use_fifomerge)
1344 size *= 3;
1345
1346 switch (dssdev->type) {
1347 case OMAP_DISPLAY_TYPE_DPI:
1348 case OMAP_DISPLAY_TYPE_DBI:
1349 case OMAP_DISPLAY_TYPE_SDI:
1350 case OMAP_DISPLAY_TYPE_VENC:
1351 default_get_overlay_fifo_thresholds(ovl->id, size,
1352 &oc->burst_size, &oc->fifo_low,
1353 &oc->fifo_high);
1354 break;
1355#ifdef CONFIG_OMAP2_DSS_DSI
1356 case OMAP_DISPLAY_TYPE_DSI:
1357 dsi_get_overlay_fifo_thresholds(ovl->id, size,
1358 &oc->burst_size, &oc->fifo_low,
1359 &oc->fifo_high);
1360 break;
1361#endif
1362 default:
1363 BUG();
1364 }
1365 }
1366
1367 r = 0;
1368 dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK1);
1369 if (!dss_cache.irq_enabled) {
1370 r = omap_dispc_register_isr(dss_apply_irq_handler, NULL,
1371 DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_ODD |
1372 DISPC_IRQ_EVSYNC_EVEN);
1373 dss_cache.irq_enabled = true;
1374 }
1375 configure_dispc();
1376 dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK1);
1377
1378 spin_unlock_irqrestore(&dss_cache.lock, flags);
1379
1380 return r;
1381}
1382
1383static int dss_check_manager(struct omap_overlay_manager *mgr)
1384{
1385 /* OMAP supports only graphics source transparency color key and alpha
1386 * blending simultaneously. See TRM 15.4.2.4.2.2 Alpha Mode */
1387
1388 if (mgr->info.alpha_enabled && mgr->info.trans_enabled &&
1389 mgr->info.trans_key_type != OMAP_DSS_COLOR_KEY_GFX_DST)
1390 return -EINVAL;
1391
1392 return 0;
1393}
1394
1395static int omap_dss_mgr_set_info(struct omap_overlay_manager *mgr,
1396 struct omap_overlay_manager_info *info)
1397{
1398 int r;
1399 struct omap_overlay_manager_info old_info;
1400
1401 old_info = mgr->info;
1402 mgr->info = *info;
1403
1404 r = dss_check_manager(mgr);
1405 if (r) {
1406 mgr->info = old_info;
1407 return r;
1408 }
1409
1410 mgr->info_dirty = true;
1411
1412 return 0;
1413}
1414
1415static void omap_dss_mgr_get_info(struct omap_overlay_manager *mgr,
1416 struct omap_overlay_manager_info *info)
1417{
1418 *info = mgr->info;
1419}
1420
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001421static int dss_mgr_enable(struct omap_overlay_manager *mgr)
1422{
1423 dispc_enable_channel(mgr->id, 1);
1424 return 0;
1425}
1426
1427static int dss_mgr_disable(struct omap_overlay_manager *mgr)
1428{
1429 dispc_enable_channel(mgr->id, 0);
1430 return 0;
1431}
1432
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001433static void omap_dss_add_overlay_manager(struct omap_overlay_manager *manager)
1434{
1435 ++num_managers;
1436 list_add_tail(&manager->list, &manager_list);
1437}
1438
1439int dss_init_overlay_managers(struct platform_device *pdev)
1440{
1441 int i, r;
1442
1443 spin_lock_init(&dss_cache.lock);
1444
1445 INIT_LIST_HEAD(&manager_list);
1446
1447 num_managers = 0;
1448
1449 for (i = 0; i < 2; ++i) {
1450 struct omap_overlay_manager *mgr;
1451 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1452
1453 BUG_ON(mgr == NULL);
1454
1455 switch (i) {
1456 case 0:
1457 mgr->name = "lcd";
1458 mgr->id = OMAP_DSS_CHANNEL_LCD;
1459 mgr->supported_displays =
1460 OMAP_DISPLAY_TYPE_DPI | OMAP_DISPLAY_TYPE_DBI |
1461 OMAP_DISPLAY_TYPE_SDI | OMAP_DISPLAY_TYPE_DSI;
1462 break;
1463 case 1:
1464 mgr->name = "tv";
1465 mgr->id = OMAP_DSS_CHANNEL_DIGIT;
1466 mgr->supported_displays = OMAP_DISPLAY_TYPE_VENC;
1467 break;
1468 }
1469
1470 mgr->set_device = &omap_dss_set_device;
1471 mgr->unset_device = &omap_dss_unset_device;
1472 mgr->apply = &omap_dss_mgr_apply;
1473 mgr->set_manager_info = &omap_dss_mgr_set_info;
1474 mgr->get_manager_info = &omap_dss_mgr_get_info;
1475 mgr->wait_for_go = &dss_mgr_wait_for_go;
Tomi Valkeinen3f71cbe2010-01-08 17:06:04 +02001476 mgr->wait_for_vsync = &dss_mgr_wait_for_vsync;
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001477
Tomi Valkeinena2faee82010-01-08 17:14:53 +02001478 mgr->enable = &dss_mgr_enable;
1479 mgr->disable = &dss_mgr_disable;
1480
Tomi Valkeineneed07e02009-08-07 13:43:20 +03001481 mgr->caps = OMAP_DSS_OVL_MGR_CAP_DISPC;
1482
1483 dss_overlay_setup_dispc_manager(mgr);
1484
1485 omap_dss_add_overlay_manager(mgr);
1486
1487 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1488 &pdev->dev.kobj, "manager%d", i);
1489
1490 if (r) {
1491 DSSERR("failed to create sysfs file\n");
1492 continue;
1493 }
1494 }
1495
1496#ifdef L4_EXAMPLE
1497 {
1498 int omap_dss_mgr_apply_l4(struct omap_overlay_manager *mgr)
1499 {
1500 DSSDBG("omap_dss_mgr_apply_l4(%s)\n", mgr->name);
1501
1502 return 0;
1503 }
1504
1505 struct omap_overlay_manager *mgr;
1506 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
1507
1508 BUG_ON(mgr == NULL);
1509
1510 mgr->name = "l4";
1511 mgr->supported_displays =
1512 OMAP_DISPLAY_TYPE_DBI | OMAP_DISPLAY_TYPE_DSI;
1513
1514 mgr->set_device = &omap_dss_set_device;
1515 mgr->unset_device = &omap_dss_unset_device;
1516 mgr->apply = &omap_dss_mgr_apply_l4;
1517 mgr->set_manager_info = &omap_dss_mgr_set_info;
1518 mgr->get_manager_info = &omap_dss_mgr_get_info;
1519
1520 dss_overlay_setup_l4_manager(mgr);
1521
1522 omap_dss_add_overlay_manager(mgr);
1523
1524 r = kobject_init_and_add(&mgr->kobj, &manager_ktype,
1525 &pdev->dev.kobj, "managerl4");
1526
1527 if (r)
1528 DSSERR("failed to create sysfs file\n");
1529 }
1530#endif
1531
1532 return 0;
1533}
1534
1535void dss_uninit_overlay_managers(struct platform_device *pdev)
1536{
1537 struct omap_overlay_manager *mgr;
1538
1539 while (!list_empty(&manager_list)) {
1540 mgr = list_first_entry(&manager_list,
1541 struct omap_overlay_manager, list);
1542 list_del(&mgr->list);
1543 kobject_del(&mgr->kobj);
1544 kobject_put(&mgr->kobj);
1545 kfree(mgr);
1546 }
1547
1548 num_managers = 0;
1549}
1550
1551int omap_dss_get_num_overlay_managers(void)
1552{
1553 return num_managers;
1554}
1555EXPORT_SYMBOL(omap_dss_get_num_overlay_managers);
1556
1557struct omap_overlay_manager *omap_dss_get_overlay_manager(int num)
1558{
1559 int i = 0;
1560 struct omap_overlay_manager *mgr;
1561
1562 list_for_each_entry(mgr, &manager_list, list) {
1563 if (i++ == num)
1564 return mgr;
1565 }
1566
1567 return NULL;
1568}
1569EXPORT_SYMBOL(omap_dss_get_overlay_manager);
1570